BxDolStudioToolsAudit.php 24 KB

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