From f4bff3fdc9017781d769ef19fa4094aa5958623e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 5 Oct 2013 10:51:32 +0200 Subject: [PATCH 1/8] send 403 response if clientdon't have trusted IP --- web/index_dev.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/index_dev.php b/web/index_dev.php index 0e9a229a8..f653270d6 100755 --- a/web/index_dev.php +++ b/web/index_dev.php @@ -42,11 +42,11 @@ $request = Request::createFromGlobals(); $thelia = new Thelia("dev", true); if ( false === in_array($request->getClientIp(), $trustedIp)) { - // Redirect 401 Unauthorized - $response = new Response('Unauthorized', 401); + $response = Response::create('Forbidden', 403)->send(); + $thelia->terminate($request, $response); +} else { + $response = $thelia->handle($request)->prepare($request)->send(); $thelia->terminate($request, $response); } -$response = $thelia->handle($request)->prepare($request)->send(); -$thelia->terminate($request, $response); \ No newline at end of file From 77a4faef0e7149d1fc01794c933d6e6c1ec3da32 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 14:33:17 +0200 Subject: [PATCH 2/8] complete installcli process --- core/lib/Thelia/Command/Install.php | 59 ++++++++++----------- core/lib/Thelia/Install/CheckPermission.php | 18 ++++--- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/core/lib/Thelia/Command/Install.php b/core/lib/Thelia/Command/Install.php index 03b7fda48..6423d861a 100755 --- a/core/lib/Thelia/Command/Install.php +++ b/core/lib/Thelia/Command/Install.php @@ -28,6 +28,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Thelia\Command\ContainerAwareCommand; +use Thelia\Install\CheckPermission; use Thelia\Install\Database; /** @@ -82,6 +83,9 @@ class Install extends ContainerAwareCommand '', 'Welcome to Thelia install process', 'You need information about your database configuration (host, username, password, database name, etc)', + '', + 'Caution : You are installing Thelia in cli mode, we verify some information, but this information are only available for the cli php sapi', + 'This informations can be different in your apache or cgi php.ini files', '' )); @@ -136,40 +140,35 @@ class Install extends ContainerAwareCommand "Checking some permissions" )); - $confDir = THELIA_ROOT . "local/config"; - $cacheDir = THELIA_ROOT . "cache"; - $logDir = THELIA_ROOT . "log"; + $permissions = new CheckPermission(false, $this->getContainer()->get('thelia.translator')); + $isValid = $permissions->exec(); - $conf = is_writable($confDir); - $cache = is_writable($cacheDir); - $log = is_writable($logDir); + foreach($permissions->getValidationMessages() as $item => $data) { + if($data['status']) { + $output->writeln(array( + sprintf("%s ... %s", + $data['text'], + "Ok") + ) + ); + } else { + $output->writeln(array( + sprintf("%s %s", + $data['text'], + sprintf("%s", $data["hint"]) + ) + )); + } - $output->writeln(array( - sprintf( - "config directory(%s)... %s", - $confDir, - $conf ? "Ok" : "Fail" - ), - sprintf( - "cache directory(%s)... %s" - ,$cacheDir, - $cache ? "Ok" : "Fail" - ), - sprintf( - "log directory(%s)... %s", - $logDir, - $log ? "Ok" : "Fail" - ), - )); - - if ($conf === false || $cache === false || $log === false) { - $output->writeln(array( - "", - "Please put correct permission and reload install process" - )); - exit; } + if(false === $isValid) { + $output->writeln(array( + "", + "Please put correct permissions and reload install process" + )); + exit; + } } /** diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index 15317211b..8b3d7d70b 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -56,7 +56,7 @@ class CheckPermission extends BaseInstall /** @var array Minimum server configuration necessary */ protected $minServerConfigurationNecessary = array( - 'memory_limit' => 134217728, + 'memory_limit' => 157286400, 'post_max_size' => 20971520, 'upload_max_filesize' => 2097152 ); @@ -216,7 +216,7 @@ class CheckPermission extends BaseInstall protected function getI18nDirectoryHint($directory) { if ($this->translator !== null) { - $sentence = 'chmod 777 %directory% on your server with admin rights could help'; + $sentence = 'chmod 777 %directory% on your server with admin rights could help'; $translatedText = $this->translator->trans( $sentence, array( @@ -246,9 +246,9 @@ class CheckPermission extends BaseInstall protected function getI18nConfigText($key, $expectedValue, $currentValue, $isValid) { if ($isValid) { - $sentence = 'Your %key% server configuration (currently %currentValue%) is well enough to run Thelia2 (%expectedValue% needed)'; + $sentence = 'Your %key% server configuration (currently %currentValue%) is well enough to run Thelia2 (%expectedValue% needed)'; } else { - $sentence = 'Your %key% server configuration (currently %currentValue%) is not sufficient enough in order to run Thelia2 (%expectedValue% needed)'; + $sentence = 'Your %key% server configuration (currently %currentValue%) is not sufficient enough in order to run Thelia2 (%expectedValue% needed)'; } $translatedText = $this->translator->trans( @@ -271,7 +271,7 @@ class CheckPermission extends BaseInstall */ protected function getI18nConfigHint() { - $sentence = 'Modifying this value on your server php.ini file with admin rights could help'; + $sentence = 'Modifying this value on your server php.ini file with admin rights could help'; $translatedText = $this->translator->trans( $sentence, array(), @@ -294,9 +294,9 @@ class CheckPermission extends BaseInstall { if ($this->translator !== null) { if ($isValid) { - $sentence = 'Your PHP version %currentValue% is well enough to run Thelia2 (%expectedValue% needed)'; + $sentence = 'Your PHP version %currentValue% is well enough to run Thelia2 (%expectedValue% needed)'; } else { - $sentence = 'Your PHP version %currentValue% is not sufficient enough to run Thelia2 (%expectedValue% needed)'; + $sentence = 'Your PHP version %currentValue% is not sufficient enough to run Thelia2 (%expectedValue% needed)'; } $translatedText = $this->translator->trans( @@ -343,6 +343,10 @@ class CheckPermission extends BaseInstall { $serverValueInBytes = $this->returnBytes(ini_get($key)); + if($serverValueInBytes == -1) { + return true; + } + return ($serverValueInBytes >= $necessaryValueInBytes); } From ac1a3ce143eca649baa6a06c8e8b66f704a163d0 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 14:33:47 +0200 Subject: [PATCH 3/8] indexes web/cache directory --- .gitignore | 1 - web/cache/.gitkeep | 0 2 files changed, 1 deletion(-) create mode 100644 web/cache/.gitkeep diff --git a/.gitignore b/.gitignore index 8cf78452c..094bfb177 100755 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ local/cache/* local/media/documents/* local/media/images/* web/assets/* -web/cache/* phpdoc*.log php-cs xhprof/ diff --git a/web/cache/.gitkeep b/web/cache/.gitkeep new file mode 100644 index 000000000..e69de29bb From 7f7bb595c5f69d9f6a4ea2481f0b5530252ce129 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 14:34:40 +0200 Subject: [PATCH 4/8] ignore new content in web/cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 094bfb177..8cf78452c 100755 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ local/cache/* local/media/documents/* local/media/images/* web/assets/* +web/cache/* phpdoc*.log php-cs xhprof/ From 5d1cd35c32b9395f59f38d3887069c6352a7bda8 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 14:36:48 +0200 Subject: [PATCH 5/8] check session directory permission in install process --- core/lib/Thelia/Install/CheckPermission.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index 8b3d7d70b..b8c4e9888 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -45,6 +45,7 @@ class CheckPermission extends BaseInstall const DIR_LOG = 'log'; const DIR_CACHE = 'cache'; const DIR_WEB = 'web'; + const DIR_SESSION = 'local/session'; /** @var array Directory needed to be writable */ protected $directoriesToBeWritable = array( @@ -52,6 +53,7 @@ class CheckPermission extends BaseInstall self::DIR_LOG, self::DIR_CACHE, self::DIR_WEB, + self::DIR_SESSION, ); /** @var array Minimum server configuration necessary */ @@ -187,9 +189,9 @@ class CheckPermission extends BaseInstall { if ($this->translator !== null) { if ($isValid) { - $sentence = 'Your directory %directory% is writable'; + $sentence = 'Your directory %directory% is writable'; } else { - $sentence = 'Your directory %directory% is not writable'; + $sentence = 'Your directory %directory% is not writable'; } $translatedText = $this->translator->trans( From cca7414f80fe9c506df16c17a1372ae259cc6106 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 14:38:38 +0200 Subject: [PATCH 6/8] remove unused directory --- .gitignore | 1 - local/cache/.gitkeep | 0 2 files changed, 1 deletion(-) delete mode 100755 local/cache/.gitkeep diff --git a/.gitignore b/.gitignore index 8cf78452c..be8430509 100755 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ coverage .buildpath .project .settings/ -local/cache/* local/media/documents/* local/media/images/* web/assets/* diff --git a/local/cache/.gitkeep b/local/cache/.gitkeep deleted file mode 100755 index e69de29bb..000000000 From 0b68d983b0ca79e595b9605d41af7da9a6c2dd2e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 14:57:32 +0200 Subject: [PATCH 7/8] try to fix travis conf --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 84e25866b..b7dd0a53c 100755 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: - DB_USER=root before_script: + - echo "post_max_size = 20M" >> `php --ini | grep "Loaded Configuration" | sed -e "/^post_max_size/d"` - composer self-update - composer install --prefer-dist --dev - sh -c "mysql -u$DB_USER -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS thelia;SET FOREIGN_KEY_CHECKS = 1;'; fi" From 180d3a948c6a41a78083ce9325077c95d326d3ec Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sun, 6 Oct 2013 15:05:35 +0200 Subject: [PATCH 8/8] add specifig php.ini file for travis --- .travis.yml | 2 +- travis.php.ini | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 travis.php.ini diff --git a/.travis.yml b/.travis.yml index b7dd0a53c..184a98fbe 100755 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ env: - DB_USER=root before_script: - - echo "post_max_size = 20M" >> `php --ini | grep "Loaded Configuration" | sed -e "/^post_max_size/d"` + - phpenv config-add travis.php.ini - composer self-update - composer install --prefer-dist --dev - sh -c "mysql -u$DB_USER -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS thelia;SET FOREIGN_KEY_CHECKS = 1;'; fi" diff --git a/travis.php.ini b/travis.php.ini new file mode 100644 index 000000000..86776429c --- /dev/null +++ b/travis.php.ini @@ -0,0 +1 @@ +post_max_size = 20M \ No newline at end of file