From ec1437ad8b565d71ee5b8f25d0ec40949c06ea94 Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Tue, 25 Oct 2011 12:44:47 +0000 Subject: [PATCH] // thanks to Julien Breux for AdminInformationController [*] BO : optimized ConfigurationTest class git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9625 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminInformation.php | 372 ------------------ .../themes/template/information/content.tpl | 119 ++++++ classes/ConfigurationTest.php | 72 +++- .../admin/AdminInformationController.php | 107 +++++ 4 files changed, 291 insertions(+), 379 deletions(-) delete mode 100644 admin-dev/tabs/AdminInformation.php create mode 100755 admin-dev/themes/template/information/content.tpl create mode 100644 controllers/admin/AdminInformationController.php diff --git a/admin-dev/tabs/AdminInformation.php b/admin-dev/tabs/AdminInformation.php deleted file mode 100644 index 7f5ca57b2..000000000 --- a/admin-dev/tabs/AdminInformation.php +++ /dev/null @@ -1,372 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6844 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -class AdminInformation extends AdminTab -{ - private function _getTestResultHtml() - { - $html = ''; - // Functions list to test with 'test_system' - $funcs = array('fopen', 'fclose', 'fread', 'fwrite', 'rename', 'file_exists', 'unlink', 'rmdir', 'mkdir', 'getcwd', 'chdir', 'chmod'); - - // Test list to execute (function/args) - $tests = array( - 'phpversion' => false, - 'upload' => false, - 'system' => $funcs, - 'gd' => false, - 'mysql_support' => false, - 'config_dir' => _PS_ADMIN_DIR_.'/../config/', - 'cache_dir' => _PS_CACHE_DIR_, - 'sitemap' => _PS_ADMIN_DIR_.'/../sitemap.xml', - 'img_dir' => _PS_ADMIN_DIR_.'/../img/', - 'mails_dir' => _PS_ADMIN_DIR_.'/../mails/', - 'module_dir' => _PS_ADMIN_DIR_.'/../modules/', - 'theme_lang_dir' => _PS_ADMIN_DIR_.'/../themes/'._THEME_NAME_.'/lang/', - 'translations_dir' => _PS_ADMIN_DIR_.'/../translations/', - 'customizable_products_dir' => _PS_ADMIN_DIR_.'/../upload/', - 'virtual_products_dir' => _PS_ADMIN_DIR_.'/../download/' - ); - - $tests_op = array( - 'fopen' => false, - 'register_globals' => false, - 'gz' => false - ); - - $testsErrors = array( - 'phpversion' => $this->l('Update your PHP version'), - 'upload' => $this->l('Configure your server to allow the upload file'), - 'system' => $this->l('Configure your server to allow the creation of directories and write to files'), - 'gd' => $this->l('Enable the GD library on your server'), - 'mysql_support' => $this->l('Enable the MySQL support on your server'), - 'config_dir' => $this->l('Set write permissions for config folder'), - 'cache_dir' => $this->l('Set write permissions for cache folder'), - 'sitemap' => $this->l('Set write permissions for sitemap.xml file'), - 'img_dir' => $this->l('Set write permissions for img folder and subfolders/recursively'), - 'mails_dir' => $this->l('Set write permissions for mails folder and subfolders/recursively'), - 'module_dir' => $this->l('Set write permissions for modules folder and subfolders/recursively'), - 'theme_lang_dir' => $this->l('Set write permissions for themes/')._THEME_NAME_.$this->l('/lang/ folder and subfolders/recursively'), - 'translations_dir' => $this->l('Set write permissions for translations folder and subfolders/recursively'), - 'customizable_products_dir' => $this->l('Set write permissions for upload folder and subfolders/recursively'), - 'virtual_products_dir' => $this->l('Set write permissions for download folder and subfolders/recursively'), - 'fopen' => $this->l('Enable fopen on your server'), - 'register_globals' => $this->l('Set PHP register global option to off'), - 'gz' => $this->l('Enable GZIP compression on your server') - ); - - $paramsRequiredResults = self::check($tests); - $paramsOptionalResults = self::check($tests_op); - - $html .= ' -

- '.$this->l('Required parameters').':'; - if (!in_array('fail', $paramsRequiredResults)) - $html .= ' OK -

- '; - else - { - $html .= ' '.$this->l('Please consult the following error(s)').' -

- '; - } - - $html .= ' -

- '.$this->l('Optional parameters').':'; - if (!in_array('fail', $paramsOptionalResults)) - $html .= ' OK -

- '; - else - { - $html .= ' '.$this->l('Please consult the following error(s)').' -

- '; - } - - return $html; - } - - public function display() - { - echo ' -

'.$this->l('Information').'

-
- '.$this->l('Help').' -

'.$this->l('This information must be indicated when you report a bug on our bug tracker or if you report a problem on our forum.').'

-
-
-
- '.$this->l('Information about your configuration').' -

'.$this->l('Server information').'

-

- '.$this->l('Prestashop Version').': - '._PS_VERSION_.' -

'; - - if (function_exists('php_uname')) - echo ' -

- '.$this->l('Server information').': - '.php_uname('s').' '.php_uname('v').' '.php_uname('m').' -

'; - - echo ' -

- '.$this->l('Server software Version').': - '.$_SERVER['SERVER_SOFTWARE'].' -

-

- '.$this->l('PHP Version').': - '.phpversion().' -

-

- '.$this->l('MySQL Version').': - '.Db::getInstance()->getVersion().' -

'; - if (function_exists('apache_get_modules') AND in_array('mod_instaweb', apache_get_modules())) - echo '

'.$this->l('PageSpeed module for Apache installed (mod_instaweb)').'

'; - echo ' -
-

'.$this->l('Store information').'

-

- '.$this->l('URL of your website').': - '.Tools::getHttpHost(true).__PS_BASE_URI__.' -

-

- '.$this->l('Theme name used').': - '._THEME_NAME_.' -

-
-

'.$this->l('Mail information').'

-

- '.$this->l('Mail method').': - '; - if (Configuration::get('PS_MAIL_METHOD') == 1) - echo $this->l('You use PHP mail() function.').'

'; - else - { - echo $this->l('You use your own SMTP parameters').'

'; - echo ' -

- '.$this->l('SMTP server').': - '.Configuration::get('PS_MAIL_SERVER').' -

-

- '.$this->l('SMTP user').': - '.(Configuration::get('PS_MAIL_USER') ? $this->l('Defined') : ''.$this->l('Not defined').'').' -

-

- '.$this->l('SMTP password').': - '.(Configuration::get('PS_MAIL_PASSWD') ? $this->l('Defined') : ''.$this->l('Not defined').'').' -

-

- '.$this->l('Encryption').': - '.Configuration::get('PS_MAIL_SMTP_ENCRYPTION').' -

-

- '.$this->l('Port').': - '.Configuration::get('PS_MAIL_SMTP_PORT').' -

- '; - } - echo ' -
-

'.$this->l('Your information').'

-

- '.$this->l('Information from you').': - '.$_SERVER["HTTP_USER_AGENT"].' -

-
-
-
- '.$this->l('Check your configuration').' - '.self::_getTestResultHtml().' -
- '; - } - - static private function check($tests) - { - $res = array(); - foreach ($tests AS $key => $test) - $res[$key] = self::run($key, $test); - return $res; - } - - static private function run($ptr, $arg = 0) - { - if (call_user_func(array('self', 'test_'.$ptr), $arg)) - return ('ok'); - return ('fail'); - } - - // Misc functions - static private function test_phpversion() - { - return PHP_VERSION_ID >= 50000; /* PHP version > 5.0 */ - } - - static private function test_mysql_support() - { - return function_exists('mysql_connect'); - } - - static private function test_upload() - { - return ini_get('file_uploads'); - } - - static private function test_fopen() - { - return ini_get('allow_url_fopen'); - } - - static private function test_system($funcs) - { - foreach ($funcs AS $func) - if (!function_exists($func)) - return false; - return true; - } - - static private function test_gd() - { - return function_exists('imagecreatetruecolor'); - } - - static private function test_register_globals() - { - return !ini_get('register_globals'); - } - - static private function test_gz() - { - if (function_exists('gzencode')) - return !(@gzencode('dd') === false); - return false; - } - - // is_writable dirs - static private function test_dir($dir, $recursive = false) - { - if (!is_writable($dir) OR !$dh = opendir($dir)) - return false; - if ($recursive) - { - while (($file = readdir($dh)) !== false) - if (is_dir($dir.$file) AND $file != '.' AND $file != '..') - if (!self::test_dir($dir.$file, true)) - return false; - } - closedir($dh); - return true; - } - - // is_writable files - static private function test_file($file) - { - return (file_exists($file) AND is_writable($file)); - } - - static private function test_config_dir($dir) - { - return self::test_dir($dir); - } - - static private function test_sitemap($dir) - { - return self::test_file($dir); - } - - static private function test_root_dir($dir) - { - return self::test_dir($dir); - } - - static private function test_admin_dir($dir) - { - return self::test_dir($dir); - } - - static private function test_img_dir($dir) - { - return self::test_dir($dir, true); - } - - static private function test_module_dir($dir) - { - return self::test_dir($dir, true); - } - - static function test_cache_dir($dir) - { - return self::test_dir($dir); - } - - static private function test_download_dir($dir) - { - return self::test_dir($dir); - } - - static private function test_mails_dir($dir) - { - return self::test_dir($dir, true); - } - - static private function test_translations_dir($dir) - { - return self::test_dir($dir, true); - } - - static private function test_theme_lang_dir($dir) - { - return self::test_dir($dir, true); - } - - static private function test_customizable_products_dir($dir) - { - return self::test_dir($dir); - } - - static private function test_virtual_products_dir($dir) - { - return self::test_dir($dir); - } -} diff --git a/admin-dev/themes/template/information/content.tpl b/admin-dev/themes/template/information/content.tpl new file mode 100755 index 000000000..946b652e6 --- /dev/null +++ b/admin-dev/themes/template/information/content.tpl @@ -0,0 +1,119 @@ +

{l s='Information'}

+
+ {l s='Help'} +

{l s='This information must be indicated when you report a bug on our bug tracker or if you report a problem on our forum.'}

+
+
+
+ {l s='Information about your configuration'} +

{l s='Server information'}

+

+ {l s='Prestashop Version'}: {$version.ps} +

+ + {if count($uname)} +

+ {l s='Server information'}: {$uname} +

+ {/if} + +

+ {l s='Server software Version'}: {$version.server} +

+

+ {l s='PHP Version'}: {$version.php} +

+

+ {l s='MySQL Version'}: {$version.mysql} +

+ {if $apache_instaweb} +

{l s='PageSpeed module for Apache installed (mod_instaweb)'}

+ {/if} + +
+

{l s='Store information'}

+

+ {l s='URL of your website'}: {$shop.url} +

+

+ {l s='Theme name used'}: {$shop.theme} +

+
+

{l s='Mail information'}

+

+ {l s='Mail method'}: + +{if $mail} + {l s='You use PHP mail() function.'}

+{else} + {l s='You use your own SMTP parameters'}

+

+ {l s='SMTP server'}: {$smtp.server} +

+

+ {l s='SMTP user'}: + {if $smtp.user neq ''} + {l s='Defined'} + {else} + {l s='Not defined'} + {/if} +

+

+ {l s='SMTP password'}: + {if $smtp.password neq ''} + {l s='Defined'} + {else} + {l s='Not defined'} + {/if} +

+

+ {l s='Encryption'}: {$smtp.encryption} +

+

+ {l s='Port'}: {$smtp.port} +

+{/if} +
+

{l s='Your information'}

+

+ {l s='Information from you'}: {$user_agent} +

+
+
+
+ {l s='Check your configuration'} +

+ {l s='Required parameters'}: + {if !$failRequired} + OK +

+ {else} + {l s='Please consult the following error(s)'} +

+ + {/if} + +

+ {l s='Optional parameters'}: + {if !$failOptional} + OK +

+ {else} + {l s='Please consult the following error(s)'} +

+ + {/if} + +
diff --git a/classes/ConfigurationTest.php b/classes/ConfigurationTest.php index ea3343811..8db378aef 100644 --- a/classes/ConfigurationTest.php +++ b/classes/ConfigurationTest.php @@ -27,6 +27,62 @@ class ConfigurationTestCore { + + /** + * getDefaultTests return an array of tests to executes. + * key are method name, value are parameters (false for no parameter) + * all path are _PS_ROOT_DIR_ related + * + * @return array + */ + public static function getDefaultTests() + { + return array( + 'system' => array( + 'fopen', 'fclose', 'fread', 'fwrite', + 'rename', 'file_exists', 'unlink', 'rmdir', 'mkdir', + 'getcwd', 'chdir', 'chmod' + ), + + 'phpversion' => false, + 'upload' => false, + 'gd' => false, + 'mysql_support' => false, + 'config_dir' => 'config', + 'cache_dir' => 'cache', + 'sitemap' => 'sitemap.xml', + 'img_dir' => 'img', + 'mails_dir' => 'mails', + 'module_dir' => 'modules', + 'theme_lang_dir' => 'themes/'._THEME_NAME_.'/lang/', + 'translations_dir' => 'translations', + 'customizable_products_dir' => 'upload', + 'virtual_products_dir' => 'download' + ); + } + + /** + * getDefaultTestsOp return an array of tests to executes. + * key are method name, value are parameters (false for no parameter) + * + * @return array + */ + public static function getDefaultTestsOp() + { + + return array( + 'fopen' => false, + 'register_globals' => false, + 'gz' => false + ); + } + + /** + * run all test defined in $tests + * + * @param array $tests + * @return array results of tests + */ public static function check($tests) { $res = array(); @@ -38,8 +94,8 @@ class ConfigurationTestCore public static function run($ptr, $arg = 0) { if (call_user_func(array('ConfigurationTest', 'test_'.$ptr), $arg)) - return ('ok'); - return ('fail'); + return 'ok'; + return 'fail'; } public static function test_phpversion() @@ -97,8 +153,9 @@ class ConfigurationTestCore return false; } - public static function test_dir($dir, $recursive = false) + public static function test_dir($relative_dir, $recursive = false) { + $dir = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.ltrim($relative_dir, '/'); if (!file_exists($dir) OR !$dh = opendir($dir)) return false; $dummy = rtrim($dir, '/').'/'.uniqid(); @@ -113,16 +170,17 @@ class ConfigurationTestCore if ($recursive) { while (($file = readdir($dh)) !== false) - if (is_dir($dir.$file) && $file != '.' && $file != '..') - if (!self::test_dir($dir.$file, true)) + if (is_dir($dir.DIRECTORY_SEPARATOR.$file) && $file != '.' && $file != '..' && $file != '.svn') + if (!self::test_dir($relative_dir.DIRECTORY_SEPARATOR.$file, true)) return false; } closedir($dh); return true; } - public static function test_file($file) + public static function test_file($file_relative) { + $file = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$file_relative; return (file_exists($file) AND is_writable($file)); } @@ -163,7 +221,7 @@ class ConfigurationTestCore public static function test_cache_dir($dir) { - return self::test_dir($dir); + return self::test_dir($dir, true); } public static function test_tools_v2_dir($dir) diff --git a/controllers/admin/AdminInformationController.php b/controllers/admin/AdminInformationController.php new file mode 100644 index 000000000..685727e11 --- /dev/null +++ b/controllers/admin/AdminInformationController.php @@ -0,0 +1,107 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminInformationControllerCore extends AdminController +{ + + + public function initContent() + { + parent::initContent(); + + $this->context->smarty->assign(array( + 'version' => array( + 'mysql' => Db::getInstance()->getVersion(), + 'php' => phpversion(), + 'ps' => _PS_VERSION_, + 'server' => $_SERVER['SERVER_SOFTWARE'], + ), + 'uname' => function_exists('php_uname') ? php_uname('s').' '.php_uname('v').' '.php_uname('m') : '', + 'apache_instaweb' => Tools::apacheModExists('mod_instaweb'), + 'shop' => array( + 'url' => Tools::getHttpHost(true).__PS_BASE_URI__, + 'theme' => _THEME_NAME_, + ), + 'mail' => Configuration::get('PS_MAIL_METHOD') == 1, + 'smtp' => array( + 'server' => Configuration::get('PS_MAIL_SERVER'), + 'user' => Configuration::get('PS_MAIL_USER'), + 'password' => Configuration::get('PS_MAIL_PASSWD'), + 'encryption' => Configuration::get('PS_MAIL_SMTP_ENCRYPTION'), + 'port' => Configuration::get('PS_MAIL_SMTP_PORT'), + ), + 'user_agent' => $_SERVER["HTTP_USER_AGENT"], + )); + + $this->context->smarty->assign($this->getTestResult()); + } + + /** + * get all tests + * + * @return array of test results + */ + public function getTestResult() + { + // Functions list to test with 'test_system' + // Test to execute (function/args) : lets uses the default test + $tests = ConfigurationTest::getDefaultTests(); + $tests_op = ConfigurationTest::getDefaultTestsOp(); + + $testsErrors = array( + 'phpversion' => $this->l('Update your PHP version'), + 'upload' => $this->l('Configure your server to allow the upload file'), + 'system' => $this->l('Configure your server to allow the creation of directories and write to files'), + 'gd' => $this->l('Enable the GD library on your server'), + 'mysql_support' => $this->l('Enable the MySQL support on your server'), + 'config_dir' => $this->l('Set write permissions for config folder'), + 'cache_dir' => $this->l('Set write permissions for cache folder'), + 'sitemap' => $this->l('Set write permissions for sitemap.xml file'), + 'img_dir' => $this->l('Set write permissions for img folder and subfolders/recursively'), + 'mails_dir' => $this->l('Set write permissions for mails folder and subfolders/recursively'), + 'module_dir' => $this->l('Set write permissions for modules folder and subfolders/recursively'), + 'theme_lang_dir' => $this->l('Set write permissions for themes/')._THEME_NAME_.$this->l('/lang/ folder and subfolders/recursively'), + 'translations_dir' => $this->l('Set write permissions for translations folder and subfolders/recursively'), + 'customizable_products_dir' => $this->l('Set write permissions for upload folder and subfolders/recursively'), + 'virtual_products_dir' => $this->l('Set write permissions for download folder and subfolders/recursively'), + 'fopen' => $this->l('Enable fopen on your server'), + 'register_globals' => $this->l('Set PHP register global option to off'), + 'gz' => $this->l('Enable GZIP compression on your server') + ); + + $paramsRequiredResults = ConfigurationTest::check($tests); + $paramsOptionalResults = ConfigurationTest::check($tests_op); + + return array( + 'failRequired' => in_array('fail', $paramsRequiredResults), + 'failOptional' => in_array('fail', $paramsOptionalResults), + 'testsErrors' => $testsErrors, + 'testsRequired' => $paramsRequiredResults, + 'testsOptional' => $paramsOptionalResults, + ); + } +}