BxDolStudioToolsAudit.php 25 KB

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