BxDolStudioToolsAudit.php 24 KB

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