BxDolStudioToolsAudit.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentStudio Trident Studio
  7. * @{
  8. */
  9. define('BX_DOL_AUDIT_FAIL', 'fail');
  10. define('BX_DOL_AUDIT_WARN', 'warn');
  11. define('BX_DOL_AUDIT_UNDEF', 'undef');
  12. define('BX_DOL_AUDIT_OK', 'ok');
  13. class BxDolStudioToolsAudit extends BxDol
  14. {
  15. protected $aType2ClassCSS;
  16. protected $aType2Title;
  17. protected $aLatestPhp;
  18. protected $sMinPhpVer;
  19. protected $aPhpSettings;
  20. protected $iPhpErrorReporting;
  21. protected $sMinMysqlVer;
  22. protected $aMysqlOptimizationSettings;
  23. protected $aOptimizationSettings;
  24. protected $aRequiredApacheModules;
  25. function __construct()
  26. {
  27. parent::__construct();
  28. $this->aType2ClassCSS = array (
  29. BX_DOL_AUDIT_FAIL => 'fail',
  30. BX_DOL_AUDIT_WARN => 'warn',
  31. BX_DOL_AUDIT_UNDEF => 'undef',
  32. BX_DOL_AUDIT_OK => 'ok',
  33. );
  34. $this->aType2Title = array (
  35. BX_DOL_AUDIT_FAIL => _t('_sys_audit_title_fail'),
  36. BX_DOL_AUDIT_WARN => _t('_sys_audit_title_warn'),
  37. BX_DOL_AUDIT_UNDEF => _t('_sys_audit_title_undef'),
  38. BX_DOL_AUDIT_OK => _t('_sys_audit_title_ok'),
  39. );
  40. $this->aLatestPhp = array(
  41. '5.3' => '5.3.29',
  42. '5.4' => '5.4.36',
  43. '5.5' => '5.5.20',
  44. );
  45. $this->sMinPhpVer = '5.3.0';
  46. $this->aPhpSettings = array (
  47. 'allow_url_fopen' => array('op' => '=', 'val' => true, 'type' => 'bool'),
  48. 'allow_url_include' => array('op' => '=', 'val' => false, 'type' => 'bool'),
  49. 'magic_quotes_gpc' => array('op' => '=', 'val' => false, 'type' => 'bool', 'warn' => 1),
  50. 'memory_limit' => array('op' => '>=', 'val' => 128*1024*1024, 'type' => 'bytes', 'unlimited' => -1),
  51. 'post_max_size' => array('op' => '>=', 'val' => 2*1024*1024, 'type' => 'bytes', 'warn' => 1),
  52. 'upload_max_filesize' => array('op' => '>=', 'val' => 2*1024*1024, 'type' => 'bytes', 'warn' => 1),
  53. 'register_globals' => array('op' => '=', 'val' => false, 'type' => 'bool'),
  54. 'safe_mode' => array('op' => '=', 'val' => false, 'type' => 'bool'),
  55. 'short_open_tag' => array('op' => '=', 'val' => true, 'type' => 'bool'),
  56. 'disable_functions' => array('op' => '=', 'val' => ''),
  57. 'php module: mysql' => array('op' => 'module', 'val' => 'mysql'),
  58. 'php module: curl' => array('op' => 'module', 'val' => 'curl'),
  59. 'php module: gd' => array('op' => 'module', 'val' => 'gd'),
  60. 'php module: mbstring' => array('op' => 'module', 'val' => 'mbstring'),
  61. 'php module: json' => array('op' => 'module', 'val' => 'json', 'warn' => 1),
  62. 'php module: openssl' => array('op' => 'module', 'val' => 'openssl', 'warn' => 1),
  63. 'php module: zip' => array('op' => 'module', 'val' => 'zip', 'warn' => 1),
  64. );
  65. $this->sMinMysqlVer = '4.1.2';
  66. $this->aMysqlOptimizationSettings = array (
  67. 'key_buffer_size' => array('op' => '>=', 'val' => 128*1024, 'type' => 'bytes'),
  68. 'query_cache_limit' => array('op' => '>=', 'val' => 1000000),
  69. 'query_cache_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  70. 'query_cache_type' => array('op' => 'strcasecmp', 'val' => 'on'),
  71. 'max_heap_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  72. 'tmp_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  73. 'thread_cache_size ' => array('op' => '>', 'val' => 0),
  74. );
  75. $this->aOptimizationSettings = array (
  76. 'DB cache' => array('enabled' => 'sys_db_cache_enable', 'cache_engine' => 'sys_db_cache_engine', 'check_accel' => true),
  77. 'Page blocks cache' => array('enabled' => 'sys_pb_cache_enable', 'cache_engine' => 'sys_pb_cache_engine', 'check_accel' => true),
  78. 'Member menu cache' => array('enabled' => 'always_on', 'cache_engine' => 'sys_mm_cache_engine', 'check_accel' => true),
  79. 'Templates Cache' => array('enabled' => 'sys_template_cache_enable', 'cache_engine' => 'sys_template_cache_engine', 'check_accel' => true),
  80. 'CSS files cache' => array('enabled' => 'sys_template_cache_css_enable', 'cache_engine' => '', 'check_accel' => false),
  81. 'JS files cache' => array('enabled' => 'sys_template_cache_js_enable', 'cache_engine' => '', 'check_accel' => false),
  82. 'Compression for CSS/JS cache' => array('enabled' => 'sys_template_cache_compress_enable', 'cache_engine' => '', 'check_accel' => false),
  83. );
  84. $this->aRequiredApacheModules = array (
  85. 'rewrite_module' => 'mod_rewrite',
  86. );
  87. if (isset($_GET['action'])) {
  88. $sOutput = null;
  89. switch ($_GET['action']) {
  90. case 'audit_send_test_email':
  91. $sOutput = $this->sendTestEmail();
  92. break;
  93. case 'phpinfo':
  94. ob_start();
  95. phpinfo();
  96. $sOutput = ob_get_clean();
  97. break;
  98. case 'phpinfo_popup':
  99. $sUrlSelf = bx_js_string($_SERVER['PHP_SELF'], BX_ESCAPE_STR_APOS);
  100. $sUrlSelf = bx_append_url_params($sUrlSelf, array('action' => 'phpinfo'));
  101. $sOutput = '<iframe width="640" height="480" src="' . $sUrlSelf . '"></iframe>';
  102. break;
  103. }
  104. if ($sOutput) {
  105. header('Content-type: text/html; charset=utf-8');
  106. echo $sOutput;
  107. exit;
  108. }
  109. }
  110. }
  111. public function generate()
  112. {
  113. ob_start();
  114. $this->setErrorReporting();
  115. $this->generateStyles();
  116. $this->generateJs();
  117. $this->requirements();
  118. if (!defined('BX_DOL_INSTALL'))
  119. $this->siteSetup();
  120. $this->optimization();
  121. $this->manualCheck();
  122. $this->restoreErrorReporting();
  123. return ob_get_clean();
  124. }
  125. public function generateStyles($bReturn = false)
  126. {
  127. ob_start();
  128. ?>
  129. <style>
  130. .ok {
  131. color:green;
  132. }
  133. .fail {
  134. color:red;
  135. }
  136. .warn {
  137. color:orange;
  138. }
  139. .undef {
  140. color:gray;
  141. }
  142. </style>
  143. <?php
  144. $sStyles = ob_get_clean();
  145. if($bReturn)
  146. return $sStyles;
  147. echo $sStyles;
  148. }
  149. public function generateJs()
  150. {
  151. $sUrlSelf = bx_js_string($_SERVER['PHP_SELF'], BX_ESCAPE_STR_APOS);
  152. ?>
  153. <script language="javascript">
  154. function bx_sys_adm_audit_test_email()
  155. {
  156. var sEmail = prompt('<?php echo _t('_Email'); ?>', '<?php echo class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : ''; ?>');
  157. if (null == sEmail || ('string' == (typeof sEmail) && !sEmail.length))
  158. return;
  159. $('#bx-sys-adm-audit-test-email').html('Sending...');
  160. $.post('<?php echo bx_append_url_params($sUrlSelf, array('action' => 'audit_send_test_email')); ?>&email=' + sEmail, function(data) {
  161. $('#bx-sys-adm-audit-test-email').html(data);
  162. });
  163. }
  164. function bx_sys_adm_audit_phpinfo()
  165. {
  166. $(window).dolPopupAjax({url: '<?php echo bx_append_url_params($sUrlSelf, array('action' => 'phpinfo_popup')); ?>'});
  167. }
  168. </script>
  169. <?php
  170. }
  171. /**
  172. * Check minimal requirements
  173. * @param $sType - BX_DOL_AUDIT_FAIL, BX_DOL_AUDIT_WARN, BX_DOL_AUDIT_UNDEF or BX_DOL_AUDIT_OK
  174. * @param $sFunc - requirementsPHP, requirementsMySQL or requirementsWebServer
  175. * @return array of FAIL, WARN, UNDEF or OK items, if array is empty then no specified items are found
  176. */
  177. public function checkRequirements($sType = BX_DOL_AUDIT_FAIL, $sFunc = 'requirementsPHP')
  178. {
  179. $this->setErrorReporting();
  180. $aRet = array ();
  181. $aMessages = array ();
  182. $this->$sFunc(false, $aMessages);
  183. foreach ($aMessages as $sName => $r)
  184. if ($sType == $r['type'])
  185. $aRet[] = "$sName = " . $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : '') . " - " . $this->getMsgHTML($sName, $r);
  186. $this->restoreErrorReporting();
  187. return $aRet;
  188. }
  189. public function typeToTitle ($sType)
  190. {
  191. return $this->aType2Title[$sType];
  192. }
  193. protected function requirements()
  194. {
  195. echo '<h1>' . _t('_sys_audit_header_requirements') . '</h1>';
  196. $this->requirementsPHP();
  197. if (!defined('BX_DOL_INSTALL'))
  198. $this->requirementsMySQL();
  199. $this->requirementsWebServer();
  200. $this->requirementsOS();
  201. $this->requirementsHardware();
  202. }
  203. protected function requirementsPHP($bEcho = true, &$aOutputMessages = null)
  204. {
  205. $a = unserialize(file_get_contents("http://www.php.net/releases/index.php?serialize=1"));
  206. $sLatestPhpVersion = $a[5]['version'];
  207. if (version_compare(phpversion(), "5.4", ">=") == 1)
  208. unset($this->aPhpSettings['short_open_tag']);
  209. $aMessages = array ();
  210. $sPhpVer = PHP_VERSION;
  211. if (empty($sLatestPhpVersion))
  212. $aVer = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'), 'params' => array ('real_val' => $sPhpVer));
  213. elseif (version_compare($sPhpVer, $this->sMinPhpVer, '<'))
  214. $aVer = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_version_is_incompatible', $this->sMinPhpVer), 'params' => array ('real_val' => $sPhpVer));
  215. elseif (version_compare($sPhpVer, '5.6.0', '>=') && version_compare($sPhpVer, '6.0.0', '<') && !version_compare($sPhpVer, $sLatestPhpVersion, '>='))
  216. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $sLatestPhpVersion), 'params' => array ('real_val' => $sPhpVer));
  217. elseif (version_compare($sPhpVer, '5.5.0', '>=') && version_compare($sPhpVer, '5.6.0', '<') && !version_compare($sPhpVer, $this->aLatestPhp['5.5'], '>='))
  218. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $this->aLatestPhp['5.5']), 'params' => array ('real_val' => $sPhpVer));
  219. elseif (version_compare($sPhpVer, '5.4.0', '>=') && version_compare($sPhpVer, '5.5.0', '<') && !version_compare($sPhpVer, $this->aLatestPhp['5.4'], '>='))
  220. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $this->aLatestPhp['5.4']), 'params' => array ('real_val' => $sPhpVer));
  221. elseif (version_compare($sPhpVer, '5.3.0', '>=') && version_compare($sPhpVer, '5.4.0', '<') && !version_compare($sPhpVer, $this->aLatestPhp['5.3'], '>='))
  222. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $this->aLatestPhp['5.3']), 'params' => array ('real_val' => $sPhpVer));
  223. else
  224. $aVer = array('type' => BX_DOL_AUDIT_OK, 'params' => array ('real_val' => $sPhpVer));
  225. $aMessages[_t('_sys_audit_version')] = $aVer;
  226. foreach ($this->aPhpSettings as $sName => $r) {
  227. $a = $this->checkPhpSetting($sName, $r);
  228. if ($a['res'])
  229. $aMessages[$sName] = array('type' => BX_DOL_AUDIT_OK, 'params' => $a);
  230. elseif (isset($r['warn']) && $r['warn'])
  231. $aMessages[$sName] = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_should_be', $r['op'], $this->format_output($r['val'], $r)), 'params' => $a);
  232. else
  233. $aMessages[$sName] = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_must_be', $r['op'], $this->format_output($r['val'], $r)), 'params' => $a);
  234. }
  235. if (null !== $aOutputMessages)
  236. $aOutputMessages = $aMessages;
  237. if ($bEcho) {
  238. $s = '';
  239. foreach ($aMessages as $sName => $r) {
  240. $s .= $this->getBlock($sName, $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : ''), $this->getMsgHTML($sName, $r));
  241. }
  242. echo $this->getSection('PHP', '', $s);
  243. }
  244. }
  245. protected function requirementsMySQL($bEcho = true, &$aOutputMessages = null)
  246. {
  247. $sMysqlVer = BxDolDb::getInstance()->getServerInfo();
  248. if (preg_match ('/^(\d+)\.(\d+)\.(\d+)/', $sMysqlVer, $m)) {
  249. $sMysqlVer = "{$m[1]}.{$m[2]}.{$m[3]}";
  250. if (version_compare($sMysqlVer, $this->sMinMysqlVer, '<'))
  251. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_version_is_incompatible', $this->sMinMysqlVer));
  252. else
  253. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  254. } else {
  255. $aMessage = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'));
  256. }
  257. if (null !== $aOutputMessages)
  258. $aOutputMessages['mysql'] = array($aMessage);
  259. if ($bEcho) {
  260. $s = $this->getBlock(_t('_sys_audit_version'), $sMysqlVer, $this->getMsgHTML(_t('_sys_audit_version'), $aMessage));
  261. echo $this->getSection('MySQL', '', $s);
  262. }
  263. }
  264. protected function requirementsWebServer($bEcho = true, &$aOutputMessages = null)
  265. {
  266. $aMessages = array();
  267. foreach ($this->aRequiredApacheModules as $sName => $sNameCompiledName)
  268. $aMessages[$sName] = $this->checkApacheModule($sName, $sNameCompiledName);
  269. if (null !== $aOutputMessages)
  270. $aOutputMessages = $aMessages;
  271. if ($bEcho) {
  272. $s = '';
  273. foreach ($aMessages as $sName => $r) {
  274. $s .= $this->getBlock($sName, '', $this->getBlock('', '', $this->getMsgHTML($sName, $r), false));
  275. }
  276. echo $this->getSection(_t('_sys_audit_section_webserver'), $_SERVER['SERVER_SOFTWARE'], $s);
  277. }
  278. }
  279. protected function requirementsOS()
  280. {
  281. $s = $this->getBlock(php_uname());
  282. echo $this->getSection(_t('_sys_audit_section_os'), '', $s);
  283. }
  284. protected function requirementsHardware()
  285. {
  286. $s = $this->getBlock(_t('_sys_audit_msg_hardware_requirements'));
  287. echo $this->getSection(_t('_sys_audit_section_hardware'), '', $s);
  288. }
  289. protected function siteSetup()
  290. {
  291. $sFfmpegPath = defined('BX_SYSTEM_FFMPEG') ? BX_SYSTEM_FFMPEG : BX_DIRECTORY_PATH_PLUGINS . 'ffmpeg/ffmpeg.exe';
  292. $sEmailToCkeckMailSending = class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : '';
  293. bx_import('BxDolUpgrader');
  294. $oUpgrader = new BxDolUpgrader();
  295. if (!($sLatestVer = $oUpgrader->getLatestVersionNumber()))
  296. $sLatestVer = 'undefined';
  297. $sVer = bx_get_ver();
  298. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  299. if (!version_compare($sVer, $sLatestVer, '>='))
  300. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $sLatestVer));
  301. $s = $this->getBlock(_t('_sys_audit_version_script'), $sVer, $this->getMsgHTML(_t('_sys_audit_version_script'), $aMessage));
  302. $s .= $this->getBlock(_t('_sys_audit_permissions'), '', _t('_sys_audit_msg_permissions'));
  303. $s .= $this->getBlock('ffmpeg', '', _t('_sys_audit_msg_ffmpeg', `{$sFfmpegPath} 2>&1`));
  304. $s .= $this->getBlock(_t('_sys_audit_mail_sending'), '', _t('_sys_audit_msg_mail_sending'));
  305. $s .= $this->getBlock(_t('_sys_audit_cron_jobs'), '', _t('_sys_audit_msg_cron_jobs', `crontab -l 2>&1`));
  306. echo '<h1>' . _t('_sys_audit_header_site_setup') . '</h1>';
  307. echo "<ul>$s</ul>";
  308. }
  309. protected function optimization()
  310. {
  311. echo '<h1>' . _t('_sys_audit_header_site_optimization') . '</h1>';
  312. $this->optimizationPhp();
  313. if (!defined('BX_DOL_INSTALL'))
  314. $this->optimizationMySQL();
  315. $this->optimizationWebServer();
  316. if (!defined('BX_DOL_INSTALL'))
  317. $this->optimizationScript();
  318. }
  319. protected function optimizationPhp()
  320. {
  321. $s = '';
  322. $aMessage = array();
  323. $sAccel = $this->getPhpAccelerator();
  324. if (!$sAccel)
  325. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_php_accelerator_missing'));
  326. else
  327. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  328. $s .= $this->getBlock(_t('_sys_audit_php_accelerator'), $sAccel, $this->getMsgHTML(_t('_sys_audit_php_accelerator'), $aMessage));
  329. $sSapi = php_sapi_name();
  330. if (0 == strcasecmp('cgi', $sSapi))
  331. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_php_setup_inefficient'));
  332. else
  333. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  334. $s .= $this->getBlock(_t('_sys_audit_php_setup'), $sSapi, $this->getMsgHTML(_t('_sys_audit_php_setup'), $aMessage));
  335. echo $this->getSection('PHP', '', $s);
  336. }
  337. protected function optimizationMySQL()
  338. {
  339. $s = '';
  340. $oDb = BxDolDb::getInstance();
  341. foreach ($this->aMysqlOptimizationSettings as $sName => $r) {
  342. $a = $this->checkMysqlSetting($sName, $r, $oDb);
  343. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  344. if (!$a['res'])
  345. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_must_be', $r['op'], $this->format_output($r['val'], $r)));
  346. $s .= $this->getBlock($sName, $this->format_output($a['real_val'], $r), $this->getMsgHTML($sName, $aMessage));
  347. }
  348. echo $this->getSection('MySQL', '', $s);
  349. }
  350. protected function optimizationWebServer()
  351. {
  352. $s = '';
  353. $sName = 'expires_module';
  354. $sApacheModuleChack = _t('_sys_audit_msg_optimization_apache_module', $sName, $this->checkApacheModule($sName));
  355. $s .= $this->getBlock(_t('_sys_audit_userside_caching'), '', _t('_sys_audit_msg_userside_caching', $this->getUrlForGooglePageSpeed('LeverageBrowserCaching'), $sApacheModuleChack));
  356. $sName = 'deflate_module';
  357. $sApacheModuleChack = _t('_sys_audit_msg_optimization_apache_module', $sName, $this->checkApacheModule($sName));
  358. $s .= $this->getBlock(_t('_sys_audit_serverside_compression'), '', _t('_sys_audit_msg_serverside_compression', $sApacheModuleChack));
  359. echo $this->getSection(_t('_sys_audit_section_webserver'), '', $s);
  360. }
  361. protected function optimizationScript()
  362. {
  363. $s = '';
  364. foreach ($this->aOptimizationSettings as $sName => $a) {
  365. $sVal = ('always_on' == $a['enabled'] || getParam($a['enabled'])) ? 'On' : 'Off';
  366. if ($a['cache_engine'])
  367. $sVal .= _t('_sys_audit_msg_x_based_cache_engine', getParam($a['cache_engine']));
  368. if ('always_on' != $a['enabled'] && !getParam($a['enabled']))
  369. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_optimization_fail'));
  370. elseif ($a['check_accel'] && !$this->getPhpAccelerator() && 'File' == getParam($a['cache_engine']))
  371. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_optimization_warn'));
  372. else
  373. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  374. $s .= $this->getBlock($sName, $sVal, $this->getMsgHTML($sName, $aMessage));
  375. }
  376. echo $this->getSection('Trident', '', $s);
  377. }
  378. protected function manualCheck()
  379. {
  380. echo '<a name="manual_audit"></a>';
  381. echo '<h1>' . _t('_sys_audit_header_manual_audit') . '</h1>';
  382. echo _t('_sys_audit_msg_manual_audit');
  383. }
  384. protected function checkPhpSetting($sName, $a)
  385. {
  386. $mixedVal = ini_get($sName);
  387. $mixedVal = $this->format_input ($mixedVal, $a);
  388. switch ($a['op']) {
  389. case 'module':
  390. $bResult = extension_loaded($a['val']);
  391. $mixedVal = $bResult ? $a['val'] : '';
  392. break;
  393. case '>':
  394. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal > $a['val']);
  395. break;
  396. case '>=':
  397. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal >= $a['val']);
  398. break;
  399. case '=':
  400. default:
  401. $bResult = ($mixedVal == $a['val']);
  402. }
  403. return array ('res' => $bResult, 'real_val' => $mixedVal);
  404. }
  405. protected function checkMysqlSetting($sName, $a, $oDb)
  406. {
  407. $mixedVal = $oDb->getOption($sName);
  408. $mixedVal = $this->format_input ($mixedVal, $a);
  409. switch ($a['op']) {
  410. case '>':
  411. $bResult = ($mixedVal > $a['val']);
  412. break;
  413. case '>=':
  414. $bResult = ($mixedVal >= $a['val']);
  415. break;
  416. case 'strcasecmp':
  417. $bResult = 0 == strcasecmp($mixedVal, $a['val']);
  418. break;
  419. case '=':
  420. default:
  421. $bResult = ($mixedVal == $a['val']);
  422. }
  423. return array ('res' => $bResult, 'real_val' => $mixedVal);
  424. }
  425. protected function format_output ($mixedVal, $a)
  426. {
  427. if (isset($a['type']) && 'bool' == $a['type'])
  428. return $mixedVal ? 'On' : 'Off';
  429. else
  430. return $mixedVal;
  431. }
  432. protected function format_input ($mixedVal, $a)
  433. {
  434. if (isset($a['type']) && 'bytes' == $a['type'])
  435. return $this->format_bytes ($mixedVal);
  436. else
  437. return $mixedVal;
  438. }
  439. protected function format_bytes($val)
  440. {
  441. return return_bytes($val);
  442. }
  443. protected function checkApacheModule ($sModule, $sNameCompiledName = '')
  444. {
  445. $a = array (
  446. 'deflate_module' => 'mod_deflate',
  447. 'expires_module' => 'mod_expires',
  448. );
  449. if (!$sNameCompiledName && isset($a[$sModule]))
  450. $sNameCompiledName = $a[$sModule];
  451. if (function_exists('apache_get_modules')) {
  452. $aModules = apache_get_modules();
  453. $ret = in_array($sNameCompiledName, $aModules);
  454. } else {
  455. $sApachectlPath = trim(`which apachectl`);
  456. if (!$sApachectlPath)
  457. $sApachectlPath = trim(`which apache2ctl`);
  458. if (!$sApachectlPath)
  459. $sApachectlPath = trim(`which /usr/local/apache/bin/apachectl`);
  460. if (!$sApachectlPath)
  461. $sApachectlPath = trim(`which /usr/local/apache/bin/apache2ctl`);
  462. if (!$sApachectlPath) {
  463. return array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_apache_module_undef', $sModule));
  464. }
  465. $ret = (boolean)`$sApachectlPath -M 2>&1 | grep $sModule`;
  466. if (!$ret)
  467. $ret = (boolean)`$sApachectlPath -l 2>&1 | grep $sNameCompiledName`;
  468. }
  469. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  470. if (!$ret)
  471. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_apache_module_fail', $sModule));
  472. return $aMessage;
  473. }
  474. protected function getPhpAccelerator ()
  475. {
  476. $aAccelerators = array (
  477. 'eAccelerator' => array('op' => 'module', 'val' => 'eaccelerator'),
  478. 'APC' => array('op' => 'module', 'val' => 'apc'),
  479. 'XCache' => array('op' => 'module', 'val' => 'xcache'),
  480. );
  481. foreach ($aAccelerators as $sName => $r) {
  482. $a = $this->checkPhpSetting($sName, $r);
  483. if ($a['res'])
  484. return $sName;
  485. }
  486. return false;
  487. }
  488. protected function getUrlForGooglePageSpeed ($sRule)
  489. {
  490. $sUrl = urlencode(BX_DOL_URL_ROOT);
  491. return 'http://pagespeed.googlelabs.com/#url=' . $sUrl . '&mobile=false&rule=' . $sRule;
  492. }
  493. protected function sendTestEmail ()
  494. {
  495. $sEmailToCkeckMailSending = isset($_GET['email']) ? $_GET['email'] : getParam('site_email');
  496. $mixedRet = sendMail($sEmailToCkeckMailSending, 'Audit Test Email', 'Sample text for testing<br /><u><b>Sample text for testing</b></u>', '', array(), BX_EMAIL_SYSTEM);
  497. if (!$mixedRet) {
  498. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_mail_send_failed'));
  499. return $this->getBlock('', '', $this->getMsgHTML(_t('_sys_audit_mail_sending'), $aMessage), false);
  500. } else {
  501. return _t('_sys_audit_msg_mail_sent', $sEmailToCkeckMailSending);
  502. }
  503. }
  504. protected function setErrorReporting ()
  505. {
  506. if (version_compare(phpversion(), "5.3.0", ">=") == 1)
  507. $this->iPhpErrorReporting = error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT);
  508. else
  509. $this->iPhpErrorReporting = error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
  510. }
  511. protected function restoreErrorReporting ()
  512. {
  513. error_reporting($this->iPhpErrorReporting);
  514. }
  515. protected function getSection($sTitle, $sTitleAddon, $sContent)
  516. {
  517. $s = '<b>' . $sTitle . '</b>: ' . $sTitleAddon;
  518. $s .= '<ul>';
  519. $s .= $sContent;
  520. $s .= '</ul>';
  521. return $s;
  522. }
  523. protected function getBlock($sName, $sValue = '', $sMsg = '', $bWrapAsListItem = true)
  524. {
  525. $s = $bWrapAsListItem ? '<li>' : '';
  526. if ($sName !== '')
  527. $s .= "$sName ";
  528. if ($sValue !== '')
  529. $s .= " = $sValue ";
  530. if ($sMsg)
  531. $s .= ($s ? " - " : '') . $sMsg;
  532. return $s . ($bWrapAsListItem ? '</li>' : '') . "\n";
  533. }
  534. protected function getMsgHTML($sName, $a)
  535. {
  536. $s = '';
  537. $s .= '<b class="' . $this->aType2ClassCSS[$a['type']]. '">' . $this->aType2Title[$a['type']]. '</b> ';
  538. if (isset($a['msg']))
  539. $s .= '(' . $a['msg'] . ')';
  540. return $s;
  541. }
  542. }
  543. /** @} */