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.37',
  43. '5.5' => '5.5.21',
  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'),
  62. 'php module: fileinfo' => array('op' => 'module', 'val' => 'fileinfo'),
  63. 'php module: zip' => array('op' => 'module', 'val' => 'zip'),
  64. 'php module: openssl' => array('op' => 'module', 'val' => 'openssl'),
  65. );
  66. $this->sMinMysqlVer = '4.1.2';
  67. $this->aMysqlOptimizationSettings = array (
  68. 'key_buffer_size' => array('op' => '>=', 'val' => 128*1024, 'type' => 'bytes'),
  69. 'query_cache_limit' => array('op' => '>=', 'val' => 1000000),
  70. 'query_cache_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  71. 'query_cache_type' => array('op' => 'strcasecmp', 'val' => 'on'),
  72. 'max_heap_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  73. 'tmp_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  74. 'thread_cache_size ' => array('op' => '>', 'val' => 0),
  75. );
  76. $this->aOptimizationSettings = array (
  77. 'DB cache' => array('enabled' => 'sys_db_cache_enable', 'cache_engine' => 'sys_db_cache_engine', 'check_accel' => true),
  78. 'Page blocks cache' => array('enabled' => 'sys_pb_cache_enable', 'cache_engine' => 'sys_pb_cache_engine', 'check_accel' => true),
  79. 'Member menu cache' => array('enabled' => 'always_on', 'cache_engine' => 'sys_mm_cache_engine', 'check_accel' => true),
  80. 'Templates Cache' => array('enabled' => 'sys_template_cache_enable', 'cache_engine' => 'sys_template_cache_engine', 'check_accel' => true),
  81. 'CSS files cache' => array('enabled' => 'sys_template_cache_css_enable', 'cache_engine' => '', 'check_accel' => false),
  82. 'JS files cache' => array('enabled' => 'sys_template_cache_js_enable', 'cache_engine' => '', 'check_accel' => false),
  83. 'Compression for CSS/JS cache' => array('enabled' => 'sys_template_cache_compress_enable', 'cache_engine' => '', 'check_accel' => false),
  84. );
  85. $this->aRequiredApacheModules = array (
  86. 'rewrite_module' => 'mod_rewrite',
  87. );
  88. if (isset($_GET['action'])) {
  89. $sOutput = null;
  90. switch ($_GET['action']) {
  91. case 'audit_send_test_email':
  92. $sOutput = $this->sendTestEmail();
  93. break;
  94. case 'phpinfo':
  95. ob_start();
  96. phpinfo();
  97. $sOutput = ob_get_clean();
  98. break;
  99. case 'phpinfo_popup':
  100. $sUrlSelf = bx_js_string($_SERVER['PHP_SELF'], BX_ESCAPE_STR_APOS);
  101. $sUrlSelf = bx_append_url_params($sUrlSelf, array('action' => 'phpinfo'));
  102. $sOutput = '<iframe width="640" height="480" src="' . $sUrlSelf . '"></iframe>';
  103. break;
  104. }
  105. if ($sOutput) {
  106. header('Content-type: text/html; charset=utf-8');
  107. echo $sOutput;
  108. exit;
  109. }
  110. }
  111. }
  112. public function generate()
  113. {
  114. ob_start();
  115. $this->setErrorReporting();
  116. $this->generateStyles();
  117. $this->generateJs();
  118. $this->requirements();
  119. if (!defined('BX_DOL_INSTALL'))
  120. $this->siteSetup();
  121. $this->optimization();
  122. $this->manualCheck();
  123. $this->restoreErrorReporting();
  124. return ob_get_clean();
  125. }
  126. public function generateStyles($bReturn = false)
  127. {
  128. ob_start();
  129. ?>
  130. <style>
  131. .ok {
  132. color:green;
  133. }
  134. .fail {
  135. color:red;
  136. }
  137. .warn {
  138. color:orange;
  139. }
  140. .undef {
  141. color:gray;
  142. }
  143. </style>
  144. <?php
  145. $sStyles = ob_get_clean();
  146. if($bReturn)
  147. return $sStyles;
  148. echo $sStyles;
  149. }
  150. public function generateJs()
  151. {
  152. $sUrlSelf = bx_js_string($_SERVER['PHP_SELF'], BX_ESCAPE_STR_APOS);
  153. ?>
  154. <script language="javascript">
  155. function bx_sys_adm_audit_test_email()
  156. {
  157. var sEmail = prompt('<?php echo _t('_Email'); ?>', '<?php echo class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : ''; ?>');
  158. if (null == sEmail || ('string' == (typeof sEmail) && !sEmail.length))
  159. return;
  160. $('#bx-sys-adm-audit-test-email').html('Sending...');
  161. $.post('<?php echo bx_append_url_params($sUrlSelf, array('action' => 'audit_send_test_email')); ?>&email=' + sEmail, function(data) {
  162. $('#bx-sys-adm-audit-test-email').html(data);
  163. });
  164. }
  165. function bx_sys_adm_audit_phpinfo()
  166. {
  167. $(window).dolPopupAjax({url: '<?php echo bx_append_url_params($sUrlSelf, array('action' => 'phpinfo_popup')); ?>'});
  168. }
  169. </script>
  170. <?php
  171. }
  172. /**
  173. * Check minimal requirements
  174. * @param $sType - BX_DOL_AUDIT_FAIL, BX_DOL_AUDIT_WARN, BX_DOL_AUDIT_UNDEF or BX_DOL_AUDIT_OK
  175. * @param $sFunc - requirementsPHP, requirementsMySQL or requirementsWebServer
  176. * @return array of FAIL, WARN, UNDEF or OK items, if array is empty then no specified items are found
  177. */
  178. public function checkRequirements($sType = BX_DOL_AUDIT_FAIL, $sFunc = 'requirementsPHP')
  179. {
  180. $this->setErrorReporting();
  181. $aRet = array ();
  182. $aMessages = array ();
  183. $this->$sFunc(false, $aMessages);
  184. foreach ($aMessages as $sName => $r)
  185. if ($sType == $r['type'])
  186. $aRet[] = "$sName = " . $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : '') . " - " . $this->getMsgHTML($sName, $r);
  187. $this->restoreErrorReporting();
  188. return $aRet;
  189. }
  190. public function typeToTitle ($sType)
  191. {
  192. return $this->aType2Title[$sType];
  193. }
  194. protected function requirements()
  195. {
  196. echo '<h1>' . _t('_sys_audit_header_requirements') . '</h1>';
  197. $this->requirementsPHP();
  198. if (!defined('BX_DOL_INSTALL'))
  199. $this->requirementsMySQL();
  200. $this->requirementsWebServer();
  201. $this->requirementsOS();
  202. $this->requirementsHardware();
  203. }
  204. protected function requirementsPHP($bEcho = true, &$aOutputMessages = null)
  205. {
  206. $a = unserialize(file_get_contents("http://www.php.net/releases/index.php?serialize=1"));
  207. $sLatestPhpVersion = $a[5]['version'];
  208. if (version_compare(phpversion(), "5.4", ">=") == 1)
  209. unset($this->aPhpSettings['short_open_tag']);
  210. $aMessages = array ();
  211. $sPhpVer = PHP_VERSION;
  212. if (empty($sLatestPhpVersion))
  213. $aVer = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'), 'params' => array ('real_val' => $sPhpVer));
  214. elseif (version_compare($sPhpVer, $this->sMinPhpVer, '<'))
  215. $aVer = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_version_is_incompatible', $this->sMinPhpVer), 'params' => array ('real_val' => $sPhpVer));
  216. elseif (version_compare($sPhpVer, '5.6.0', '>=') && version_compare($sPhpVer, '6.0.0', '<') && !version_compare($sPhpVer, $sLatestPhpVersion, '>='))
  217. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $sLatestPhpVersion), 'params' => array ('real_val' => $sPhpVer));
  218. elseif (version_compare($sPhpVer, '5.5.0', '>=') && version_compare($sPhpVer, '5.6.0', '<') && !version_compare($sPhpVer, $this->aLatestPhp['5.5'], '>='))
  219. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $this->aLatestPhp['5.5']), 'params' => array ('real_val' => $sPhpVer));
  220. elseif (version_compare($sPhpVer, '5.4.0', '>=') && version_compare($sPhpVer, '5.5.0', '<') && !version_compare($sPhpVer, $this->aLatestPhp['5.4'], '>='))
  221. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $this->aLatestPhp['5.4']), 'params' => array ('real_val' => $sPhpVer));
  222. elseif (version_compare($sPhpVer, '5.3.0', '>=') && version_compare($sPhpVer, '5.4.0', '<') && !version_compare($sPhpVer, $this->aLatestPhp['5.3'], '>='))
  223. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $this->aLatestPhp['5.3']), 'params' => array ('real_val' => $sPhpVer));
  224. else
  225. $aVer = array('type' => BX_DOL_AUDIT_OK, 'params' => array ('real_val' => $sPhpVer));
  226. $aMessages[_t('_sys_audit_version')] = $aVer;
  227. foreach ($this->aPhpSettings as $sName => $r) {
  228. $a = $this->checkPhpSetting($sName, $r);
  229. if ($a['res'])
  230. $aMessages[$sName] = array('type' => BX_DOL_AUDIT_OK, 'params' => $a);
  231. elseif (isset($r['warn']) && $r['warn'])
  232. $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);
  233. else
  234. $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);
  235. }
  236. if (null !== $aOutputMessages)
  237. $aOutputMessages = $aMessages;
  238. if ($bEcho) {
  239. $s = '';
  240. foreach ($aMessages as $sName => $r) {
  241. $s .= $this->getBlock($sName, $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : ''), $this->getMsgHTML($sName, $r));
  242. }
  243. echo $this->getSection('PHP', '', $s);
  244. }
  245. }
  246. protected function requirementsMySQL($bEcho = true, &$aOutputMessages = null)
  247. {
  248. $sMysqlVer = BxDolDb::getInstance()->getServerInfo();
  249. if (preg_match ('/^(\d+)\.(\d+)\.(\d+)/', $sMysqlVer, $m)) {
  250. $sMysqlVer = "{$m[1]}.{$m[2]}.{$m[3]}";
  251. if (version_compare($sMysqlVer, $this->sMinMysqlVer, '<'))
  252. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_version_is_incompatible', $this->sMinMysqlVer));
  253. else
  254. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  255. } else {
  256. $aMessage = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'));
  257. }
  258. if (null !== $aOutputMessages)
  259. $aOutputMessages['mysql'] = array($aMessage);
  260. if ($bEcho) {
  261. $s = $this->getBlock(_t('_sys_audit_version'), $sMysqlVer, $this->getMsgHTML(_t('_sys_audit_version'), $aMessage));
  262. echo $this->getSection('MySQL', '', $s);
  263. }
  264. }
  265. protected function requirementsWebServer($bEcho = true, &$aOutputMessages = null)
  266. {
  267. $aMessages = array();
  268. foreach ($this->aRequiredApacheModules as $sName => $sNameCompiledName)
  269. $aMessages[$sName] = $this->checkApacheModule($sName, $sNameCompiledName);
  270. if (null !== $aOutputMessages)
  271. $aOutputMessages = $aMessages;
  272. if ($bEcho) {
  273. $s = '';
  274. foreach ($aMessages as $sName => $r) {
  275. $s .= $this->getBlock($sName, '', $this->getBlock('', '', $this->getMsgHTML($sName, $r), false));
  276. }
  277. echo $this->getSection(_t('_sys_audit_section_webserver'), $_SERVER['SERVER_SOFTWARE'], $s);
  278. }
  279. }
  280. protected function requirementsOS()
  281. {
  282. $s = $this->getBlock(php_uname());
  283. echo $this->getSection(_t('_sys_audit_section_os'), '', $s);
  284. }
  285. protected function requirementsHardware()
  286. {
  287. $s = $this->getBlock(_t('_sys_audit_msg_hardware_requirements'));
  288. echo $this->getSection(_t('_sys_audit_section_hardware'), '', $s);
  289. }
  290. protected function siteSetup()
  291. {
  292. $sFfmpegPath = defined('BX_SYSTEM_FFMPEG') ? BX_SYSTEM_FFMPEG : BX_DIRECTORY_PATH_PLUGINS . 'ffmpeg/ffmpeg.exe';
  293. $sEmailToCkeckMailSending = class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : '';
  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. /** @} */