From 979a86992cbc9dcd3ef3674f1c71ff766eca4708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 16:44:47 +0100 Subject: [PATCH] More generic way to retrieve web server user --- .../PermissionsWritableByApacheTask.php | 32 ----------- .../PermissionsWritableByWebServerTask.php | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 32 deletions(-) delete mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php create mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php deleted file mode 100644 index defd90e..0000000 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -class PermissionsWritableByApacheTask extends PermissionsTask -{ - public function init() - { - parent::init(); - - $this->setGroup('www-data') - ->setRights('g+w'); - } - - /** - * @return string - */ - public function getName() - { - return "Gives write permissions to Apache user for given paths [built-in]"; - } -} diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php new file mode 100644 index 0000000..69ad065 --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php @@ -0,0 +1,54 @@ + + */ +class PermissionsWritableByWebServerTask extends PermissionsTask +{ + /** + * Set group with web server user and give group write permissions. + */ + public function init() + { + parent::init(); + + $this->setGroup($this->getParameter('group', $this->getWebServerUser())) + ->setRights('g+w'); + } + + /** + * @return string + */ + public function getName() + { + return "Gives write permissions to web server user for given paths [built-in]"; + } + + /** + * Tries to guess the web server user by going thru the running processes. + * + * @return string + * @throws SkipException + */ + protected function getWebServerUser() + { + $this->runCommand("ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1", $webServerUser); + + if (empty($webServerUser)) { + throw new SkipException("Can't guess web server user. Please check if it is running or force it by setting the group parameter"); + } + + return $webServerUser; + } +}