BxDolStudioToolsAudit.php 25 KB

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