diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/Commands/FixCommand.php b/Commands/FixCommand.php new file mode 100644 index 0000000..a061440 --- /dev/null +++ b/Commands/FixCommand.php @@ -0,0 +1,147 @@ +info('Fixing ownership, this may take a while ...'); + shell_exec('chown -R ' . $user . ':' . $group .' ' . $site_root); + + // Fix Directory Permissions + $this->info('Fixing directory permissions, this may take a while ...'); + shell_exec('find ' . $site_root . ' -type d -exec chmod ' . $folder_permissions . ' {} \;'); + + // Fix File Permissions + $this->info('Fixing file permissions, this may take a while ...'); + shell_exec('find ' . $site_root . ' -type f -exec chmod ' . $file_permissions . ' {} \;'); + + // Lock Statamic + if ($lock_statamic) { + $this->info('Securing git folder, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $locked_group .' ' . $site_root . '.git'); + shell_exec('chmod -R 770 ' . $site_root . '.git'); + + $this->info('Securing Statamic directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'statamic'); + shell_exec('find ' . $site_root . 'statamic -type d -exec chmod 755 {} \;'); + shell_exec('find ' . $site_root . 'statamic -type f -exec chmod 640 {} \;'); + shell_exec('find ' . $site_root . 'statamic/resources/dist -type f -exec chmod 644 {} \;'); + + $this->info('Securing addons directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'site/addons'); + shell_exec('find ' . $site_root . 'site/addons -type d -exec chmod 755 {} \;'); + shell_exec('find ' . $site_root . 'site/addons -type f -exec chmod 640 {} \;'); + shell_exec('find ' . $site_root . 'site/addons/*/resources/assets -type f -exec chmod 644 {} \;'); + + $this->info('Securing content directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'site/content'); + shell_exec('find ' . $site_root . 'site/content -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'site/content -type f -exec chmod 660 {} \;'); + + $this->info('Securing database directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $locked_group .' ' . $site_root . 'site/database'); + shell_exec('find ' . $site_root . 'site/database -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'site/database -type f -exec chmod 660 {} \;'); + + $this->info('Securing settings directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'site/settings'); + shell_exec('find ' . $site_root . 'site/settings -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'site/settings -type f -exec chmod 660 {} \;'); + + $this->info('Securing storage directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'site/storage'); + shell_exec('find ' . $site_root . 'site/storage -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'site/storage -type f -exec chmod 660 {} \;'); + + $this->info('Securing tests directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $locked_group .' ' . $site_root . 'site/tests'); + shell_exec('find ' . $site_root . 'site/tests -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'site/tests -type f -exec chmod 660 {} \;'); + + $this->info('Securing themes directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'site/themes'); + shell_exec('find ' . $site_root . 'site/themes -type d -exec chmod 755 {} \;'); + shell_exec('find ' . $site_root . 'site/themes -type f -exec chmod 640 {} \;'); + shell_exec('find ' . $site_root . 'site/themes/*/assets -type f -exec chmod 644 {} \;'); + shell_exec('find ' . $site_root . 'site/themes/*/dist -type f -exec chmod 644 {} \;'); + shell_exec('find ' . $site_root . 'site/themes/*/css -type f -exec chmod 644 {} \;'); + shell_exec('find ' . $site_root . 'site/themes/*/js -type f -exec chmod 644 {} \;'); + shell_exec('find ' . $site_root . 'site/themes/*/vendor -type f -exec chmod 644 {} \;'); + + $this->info('Securing users directory, this may take a while ...'); + shell_exec('chown -R ' . $locked_user . ':' . $group .' ' . $site_root . 'site/users'); + shell_exec('find ' . $site_root . 'site/users -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'site/users -type f -exec chmod 660 {} \;'); + + $this->info('Securing local directory, this may take a while ...'); + shell_exec('find ' . $site_root . 'local -type d -exec chmod 770 {} \;'); + shell_exec('find ' . $site_root . 'local -type f -exec chmod 660 {} \;'); + + $this->info('Securing base files, this may take a while ...'); + shell_exec('chown ' . $locked_user . ':' . $group .' ' . $site_root . '.env'); + shell_exec('chmod 640 ' . $site_root . '.env'); + shell_exec('chown ' . $locked_user . ':' . $locked_group .' ' . $site_root . '.gitignore'); + shell_exec('chmod 660 ' . $site_root . '.gitignore'); + shell_exec('chown ' . $locked_user . ':' . $group .' ' . $site_root . '.htaccess'); + shell_exec('chmod 754 ' . $site_root . '.htaccess'); + shell_exec('chown ' . $locked_user . ':' . $locked_group .' ' . $site_root . 'favicon.ico'); + shell_exec('chown ' . $locked_user . ':' . $group .' ' . $site_root . 'index.php'); + shell_exec('chmod 754 ' . $site_root . 'index.php'); + shell_exec('chown ' . $locked_user . ':' . $locked_group .' ' . $site_root . 'phpunit.xml'); + shell_exec('chmod 660 ' . $site_root . 'phpunit.xml'); + shell_exec('chown ' . $locked_user . ':' . $locked_group .' ' . $site_root . 'please'); + shell_exec('chmod 660 ' . $site_root . 'please'); + shell_exec('chown ' . $locked_user . ':' . $locked_group .' ' . $site_root . 'robots.txt'); + } + + // Display an All Clear Message :) + $this->info('All done! If the script reported any "Operation not permitted" errors, try running it again with sudo.'); + } +} diff --git a/license.md b/license.md new file mode 100644 index 0000000..af724f2 --- /dev/null +++ b/license.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2017 JRC9 Design Studio + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/meta.yaml b/meta.yaml new file mode 100644 index 0000000..b67532b --- /dev/null +++ b/meta.yaml @@ -0,0 +1,6 @@ +name: Permissions +version: 0.0.1 +description: Fix & Lock down your file & folder permissions +url: https://github.com/jrc9designstudio/statamic-permissions +developer: JRC9 Design Studio +developer_url: https://github.com/jrc9designstudio diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c888320 --- /dev/null +++ b/readme.md @@ -0,0 +1,20 @@ +# Permissions for Statamic 2 +*Requirement:* Statamic v2.x +*Version:* 0.0.1 Alpha + +## Caution +This project has not been widley tested, and only works for sites have not been moved above the web root. Only use this if you have a good understanding of file permissions as this could break your entire website, if the permissions are set wrong. + +### What is this? +A CLI tool to help correct & Secure file and folder permissions for Statamic + +### Installation +- Rename the folder `Permissions` and copy it to your `site/addons` folder + +### Usage +- Change the seetings in your enviroment file (samples found in sample.env) +- Use `sudo php please permissions:fix` from the command line. + +### Notes +- `PERMISSIONS_LOCKED_USER` and `PERMISSIONS_LOCKED_GROUP` should propaly be set to the user that you use to edit / deploy code. +- Using the `PERMISSIONS_LOCK_STATAMIC` option will break the web updater, but some of us want to only be able to update Statamic via the CLI. diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..9b9202e --- /dev/null +++ b/sample.env @@ -0,0 +1,8 @@ +PERMISSIONS_SHELL_PATH=/usr/bin +PERMISSIONS_USER=www-data +PERMISSIONS_GROUP=www-data +PERMISSIONS_FOLDERS=775 +PERMISSIONS_FILES=664 +PERMISSIONS_LOCK_STATAMIC=false +PERMISSIONS_LOCKED_USER=root +PERMISSIONS_LOCKED_GROUP=root