BxDolStudioToolsAudit.php 25 KB

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