BxDolStudioToolsAudit.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA 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.5.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.5.3';
  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. bx_prompt('<?php echo _t('_Email'); ?>', '<?php echo class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : ''; ?>', function(oPopup) {
  152. var sEmail = oPopup.getValue();
  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. return false;
  161. }
  162. function bx_sys_adm_audit_phpinfo()
  163. {
  164. $(window).dolPopupAjax({url: '<?php echo bx_append_url_params($sUrlSelf, array('action' => 'phpinfo_popup')); ?>'});
  165. }
  166. </script>
  167. <?php
  168. }
  169. /**
  170. * Check minimal requirements
  171. * @param $sType - BX_DOL_AUDIT_FAIL, BX_DOL_AUDIT_WARN, BX_DOL_AUDIT_UNDEF or BX_DOL_AUDIT_OK
  172. * @param $sFunc - requirementsPHP, requirementsMySQL or requirementsWebServer
  173. * @return array of FAIL, WARN, UNDEF or OK items, if array is empty then no specified items are found
  174. */
  175. public function checkRequirements($sType = BX_DOL_AUDIT_FAIL, $sFunc = 'requirementsPHP')
  176. {
  177. $this->setErrorReporting();
  178. $aRet = array ();
  179. $aMessages = array ();
  180. $this->$sFunc(false, $aMessages);
  181. foreach ($aMessages as $sName => $r)
  182. if ($sType == $r['type'])
  183. $aRet[] = "$sName = " . $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : '') . " - " . $this->getMsgHTML($sName, $r);
  184. $this->restoreErrorReporting();
  185. return $aRet;
  186. }
  187. public function typeToTitle ($sType)
  188. {
  189. return $this->aType2Title[$sType];
  190. }
  191. protected function requirements()
  192. {
  193. echo '<h1>' . _t('_sys_audit_header_requirements') . '</h1>';
  194. $this->requirementsPHP();
  195. if (!defined('BX_DOL_INSTALL'))
  196. $this->requirementsMySQL();
  197. $this->requirementsWebServer();
  198. $this->requirementsOS();
  199. $this->requirementsHardware();
  200. }
  201. protected function requirementsPHP($bEcho = true, &$aOutputMessages = null)
  202. {
  203. $a = unserialize(file_get_contents("http://www.php.net/releases/index.php?serialize=1"));
  204. $sLatestPhpVersion = $a[5]['version'];
  205. if (version_compare(phpversion(), "5.4", ">=") == 1)
  206. unset($this->aPhpSettings['short_open_tag']);
  207. $aMessages = array ();
  208. $sPhpVer = PHP_VERSION;
  209. if (empty($sLatestPhpVersion))
  210. $aVer = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'), 'params' => array ('real_val' => $sPhpVer));
  211. elseif (version_compare($sPhpVer, $this->sMinPhpVer, '<'))
  212. $aVer = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_version_is_incompatible', $this->sMinPhpVer), 'params' => array ('real_val' => $sPhpVer));
  213. elseif (version_compare($sPhpVer, '5.3.0', '>=') && version_compare($sPhpVer, '5.4.0', '<'))
  214. $aVer = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $sLatestPhpVersion), 'params' => array ('real_val' => $sPhpVer));
  215. else
  216. $aVer = array('type' => BX_DOL_AUDIT_OK, 'params' => array ('real_val' => $sPhpVer));
  217. $aMessages[_t('_sys_audit_version')] = $aVer;
  218. foreach ($this->aPhpSettings as $sName => $r) {
  219. $a = $this->checkPhpSetting($sName, $r);
  220. if ($a['res'])
  221. $aMessages[$sName] = array('type' => BX_DOL_AUDIT_OK, 'params' => $a);
  222. elseif (isset($r['warn']) && $r['warn'])
  223. $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);
  224. else
  225. $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);
  226. }
  227. if (null !== $aOutputMessages)
  228. $aOutputMessages = $aMessages;
  229. if ($bEcho) {
  230. $s = '';
  231. foreach ($aMessages as $sName => $r) {
  232. $s .= $this->getBlock($sName, $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : ''), $this->getMsgHTML($sName, $r));
  233. }
  234. echo $this->getSection('PHP', '', $s);
  235. }
  236. }
  237. protected function requirementsMySQL($bEcho = true, &$aOutputMessages = null)
  238. {
  239. $sMysqlVer = BxDolDb::getInstance()->getServerInfo();
  240. if (preg_match ('/^(\d+)\.(\d+)\.(\d+)/', $sMysqlVer, $m)) {
  241. $sMysqlVer = "{$m[1]}.{$m[2]}.{$m[3]}";
  242. if (version_compare($sMysqlVer, $this->sMinMysqlVer, '<'))
  243. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_version_is_incompatible', $this->sMinMysqlVer));
  244. else
  245. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  246. } else {
  247. $aMessage = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'));
  248. }
  249. if (null !== $aOutputMessages)
  250. $aOutputMessages['mysql'] = array($aMessage);
  251. if ($bEcho) {
  252. $s = $this->getBlock(_t('_sys_audit_version'), $sMysqlVer, $this->getMsgHTML(_t('_sys_audit_version'), $aMessage));
  253. echo $this->getSection('MySQL', '', $s);
  254. }
  255. }
  256. protected function requirementsWebServer($bEcho = true, &$aOutputMessages = null)
  257. {
  258. $aMessages = array();
  259. foreach ($this->aRequiredApacheModules as $sName => $sNameCompiledName)
  260. $aMessages[$sName] = $this->checkApacheModule($sName, $sNameCompiledName);
  261. if (null !== $aOutputMessages)
  262. $aOutputMessages = $aMessages;
  263. if ($bEcho) {
  264. $s = '';
  265. foreach ($aMessages as $sName => $r) {
  266. $s .= $this->getBlock($sName, '', $this->getBlock('', '', $this->getMsgHTML($sName, $r), false));
  267. }
  268. echo $this->getSection(_t('_sys_audit_section_webserver'), $_SERVER['SERVER_SOFTWARE'], $s);
  269. }
  270. }
  271. protected function requirementsOS()
  272. {
  273. $s = $this->getBlock(php_uname());
  274. echo $this->getSection(_t('_sys_audit_section_os'), '', $s);
  275. }
  276. protected function requirementsHardware()
  277. {
  278. $s = $this->getBlock(_t('_sys_audit_msg_hardware_requirements'));
  279. echo $this->getSection(_t('_sys_audit_section_hardware'), '', $s);
  280. }
  281. protected function siteSetup()
  282. {
  283. $sFfmpegPath = defined('BX_SYSTEM_FFMPEG') ? BX_SYSTEM_FFMPEG : BX_DIRECTORY_PATH_PLUGINS . 'ffmpeg/ffmpeg.exe';
  284. $sEmailToCkeckMailSending = class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : '';
  285. $oUpgrader = new BxDolUpgrader();
  286. if (!($sLatestVer = $oUpgrader->getLatestVersionNumber()))
  287. $sLatestVer = 'undefined';
  288. $sVer = bx_get_ver();
  289. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  290. if (!version_compare($sVer, $sLatestVer, '>='))
  291. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_version_is_outdated', $sLatestVer));
  292. $s = $this->getBlock(_t('_sys_audit_version_script'), $sVer, $this->getMsgHTML(_t('_sys_audit_version_script'), $aMessage));
  293. $s .= $this->getBlock(_t('_sys_audit_permissions'), '', _t('_sys_audit_msg_permissions'));
  294. $s .= $this->getBlock('ffmpeg', '', _t('_sys_audit_msg_ffmpeg', `{$sFfmpegPath} 2>&1`));
  295. $s .= $this->getBlock(_t('_sys_audit_mail_sending'), '', _t('_sys_audit_msg_mail_sending'));
  296. $s .= $this->getBlock(_t('_sys_audit_cron_jobs'), '', _t('_sys_audit_msg_cron_jobs', `crontab -l 2>&1`));
  297. $iCronTime = getParam('sys_cron_time');
  298. $s .= $this->getBlock(_t('_sys_audit_cron_jobs_exec_time'), '', !empty($iCronTime) ? bx_time_js($iCronTime, BX_FORMAT_DATE_TIME, true) : _t('_None'));
  299. echo '<h1>' . _t('_sys_audit_header_site_setup') . '</h1>';
  300. echo "<ul>$s</ul>";
  301. }
  302. protected function optimization()
  303. {
  304. echo '<h1>' . _t('_sys_audit_header_site_optimization') . '</h1>';
  305. $this->optimizationPhp();
  306. if (!defined('BX_DOL_INSTALL'))
  307. $this->optimizationMySQL();
  308. $this->optimizationWebServer();
  309. if (!defined('BX_DOL_INSTALL'))
  310. $this->optimizationScript();
  311. }
  312. protected function optimizationPhp()
  313. {
  314. $s = '';
  315. $aMessage = array();
  316. $sAccel = $this->getPhpAccelerator();
  317. if (!$sAccel)
  318. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_php_accelerator_missing'));
  319. else
  320. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  321. $s .= $this->getBlock(_t('_sys_audit_php_accelerator'), $sAccel, $this->getMsgHTML(_t('_sys_audit_php_accelerator'), $aMessage));
  322. $sSapi = php_sapi_name();
  323. if (0 === strcasecmp('cgi', $sSapi))
  324. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_php_setup_inefficient'));
  325. else
  326. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  327. $s .= $this->getBlock(_t('_sys_audit_php_setup'), $sSapi, $this->getMsgHTML(_t('_sys_audit_php_setup'), $aMessage));
  328. echo $this->getSection('PHP', '', $s);
  329. }
  330. protected function optimizationMySQL()
  331. {
  332. $s = '';
  333. $oDb = BxDolDb::getInstance();
  334. foreach ($this->aMysqlOptimizationSettings as $sName => $r) {
  335. $a = $this->checkMysqlSetting($sName, $r, $oDb);
  336. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  337. if (!$a['res'])
  338. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_must_be', $r['op'], $this->format_output($r['val'], $r)));
  339. $s .= $this->getBlock($sName, $this->format_output($a['real_val'], $r), $this->getMsgHTML($sName, $aMessage));
  340. }
  341. echo $this->getSection('MySQL', '', $s);
  342. }
  343. protected function optimizationWebServer()
  344. {
  345. $s = '';
  346. $sName = 'expires_module';
  347. $sApacheModuleChack = _t('_sys_audit_msg_optimization_apache_module', $sName, $this->checkApacheModule($sName));
  348. $s .= $this->getBlock(_t('_sys_audit_userside_caching'), '', _t('_sys_audit_msg_userside_caching', $this->getUrlForGooglePageSpeed('LeverageBrowserCaching'), $sApacheModuleChack));
  349. $sName = 'deflate_module';
  350. $sApacheModuleChack = _t('_sys_audit_msg_optimization_apache_module', $sName, $this->checkApacheModule($sName));
  351. $s .= $this->getBlock(_t('_sys_audit_serverside_compression'), '', _t('_sys_audit_msg_serverside_compression', $sApacheModuleChack));
  352. echo $this->getSection(_t('_sys_audit_section_webserver'), '', $s);
  353. }
  354. protected function optimizationScript()
  355. {
  356. $s = '';
  357. foreach ($this->aOptimizationSettings as $sName => $a) {
  358. $sVal = ('always_on' == $a['enabled'] || getParam($a['enabled'])) ? 'On' : 'Off';
  359. if ($a['cache_engine'])
  360. $sVal .= _t('_sys_audit_msg_x_based_cache_engine', getParam($a['cache_engine']));
  361. if ('always_on' != $a['enabled'] && !getParam($a['enabled']))
  362. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_optimization_fail'));
  363. elseif ($a['check_accel'] && !$this->getPhpAccelerator() && 'File' == getParam($a['cache_engine']))
  364. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_optimization_warn'));
  365. else
  366. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  367. $s .= $this->getBlock($sName, $sVal, $this->getMsgHTML($sName, $aMessage));
  368. }
  369. echo $this->getSection('UNA', '', $s);
  370. }
  371. protected function manualCheck()
  372. {
  373. echo '<a name="manual_audit"></a>';
  374. echo '<h1>' . _t('_sys_audit_header_manual_audit') . '</h1>';
  375. echo _t('_sys_audit_msg_manual_audit');
  376. }
  377. protected function checkPhpSetting($sName, $a)
  378. {
  379. $mixedVal = ini_get($sName);
  380. $mixedVal = $this->format_input ($mixedVal, $a);
  381. switch ($a['op']) {
  382. case 'without':
  383. $aFuncsDisabled = explode(',', $mixedVal);
  384. $aFuncsMustBeEnabled = explode(',', $a['val']);
  385. $a = array_intersect($aFuncsDisabled, $aFuncsMustBeEnabled);
  386. $bResult = !$a;
  387. break;
  388. case 'module':
  389. $bResult = extension_loaded($a['val']);
  390. $mixedVal = $bResult ? $a['val'] : '';
  391. break;
  392. case '>':
  393. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal > $a['val']);
  394. break;
  395. case '>=':
  396. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal >= $a['val']);
  397. break;
  398. case '=':
  399. default:
  400. $bResult = ($mixedVal == $a['val']);
  401. }
  402. return array ('res' => $bResult, 'real_val' => $mixedVal);
  403. }
  404. protected function checkMysqlSetting($sName, $a, $oDb)
  405. {
  406. $mixedVal = $oDb->getOption($sName);
  407. $mixedVal = $this->format_input ($mixedVal, $a);
  408. switch ($a['op']) {
  409. case '>':
  410. $bResult = ($mixedVal > $a['val']);
  411. break;
  412. case '>=':
  413. $bResult = ($mixedVal >= $a['val']);
  414. break;
  415. case 'strcasecmp':
  416. $bResult = 0 === strcasecmp($mixedVal, $a['val']);
  417. break;
  418. case '=':
  419. default:
  420. $bResult = ($mixedVal == $a['val']);
  421. }
  422. return array ('res' => $bResult, 'real_val' => $mixedVal);
  423. }
  424. protected function format_output ($mixedVal, $a)
  425. {
  426. if (isset($a['type']) && 'bool' == $a['type'])
  427. return $mixedVal ? 'On' : 'Off';
  428. else
  429. return $mixedVal;
  430. }
  431. protected function format_input ($mixedVal, $a)
  432. {
  433. if (isset($a['type']) && 'bytes' == $a['type'])
  434. return $this->format_bytes ($mixedVal);
  435. else
  436. return $mixedVal;
  437. }
  438. protected function format_bytes($val)
  439. {
  440. return return_bytes($val);
  441. }
  442. protected function checkApacheModule ($sModule, $sNameCompiledName = '')
  443. {
  444. $a = array (
  445. 'deflate_module' => 'mod_deflate',
  446. 'expires_module' => 'mod_expires',
  447. );
  448. if (!$sNameCompiledName && isset($a[$sModule]))
  449. $sNameCompiledName = $a[$sModule];
  450. if (function_exists('apache_get_modules')) {
  451. $aModules = apache_get_modules();
  452. $ret = in_array($sNameCompiledName, $aModules);
  453. } else {
  454. $sApachectlPath = trim(`which apachectl`);
  455. if (!$sApachectlPath)
  456. $sApachectlPath = trim(`which apache2ctl`);
  457. if (!$sApachectlPath)
  458. $sApachectlPath = trim(`which /usr/local/apache/bin/apachectl`);
  459. if (!$sApachectlPath)
  460. $sApachectlPath = trim(`which /usr/local/apache/bin/apache2ctl`);
  461. if (!$sApachectlPath) {
  462. return array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_apache_module_undef', $sModule));
  463. }
  464. $ret = (boolean)`$sApachectlPath -M 2>&1 | grep $sModule`;
  465. if (!$ret)
  466. $ret = (boolean)`$sApachectlPath -l 2>&1 | grep $sNameCompiledName`;
  467. }
  468. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  469. if (!$ret)
  470. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_apache_module_fail', $sModule));
  471. return $aMessage;
  472. }
  473. protected function getPhpAccelerator ()
  474. {
  475. $aAccelerators = array (
  476. 'APC' => array('op' => 'module', 'val' => 'apc'),
  477. 'XCache' => array('op' => 'module', 'val' => 'xcache'),
  478. 'ZendOPcache' => array('op' => 'module', 'val' => 'Zend OPcache'),
  479. );
  480. foreach ($aAccelerators as $sName => $r) {
  481. $a = $this->checkPhpSetting($sName, $r);
  482. if ($a['res'])
  483. return $sName;
  484. }
  485. return false;
  486. }
  487. protected function getUrlForGooglePageSpeed ($sRule)
  488. {
  489. $sUrl = urlencode(BX_DOL_URL_ROOT);
  490. return 'http://pagespeed.googlelabs.com/#url=' . $sUrl . '&mobile=false&rule=' . $sRule;
  491. }
  492. protected function sendTestEmail ()
  493. {
  494. $sEmailToCkeckMailSending = isset($_GET['email']) ? $_GET['email'] : getParam('site_email');
  495. $mixedRet = sendMail($sEmailToCkeckMailSending, 'Audit Test Email', 'Sample text for testing<br /><u><b>Sample text for testing</b></u>', '', array(), BX_EMAIL_SYSTEM);
  496. if (!$mixedRet) {
  497. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_mail_send_failed'));
  498. return $this->getBlock('', '', $this->getMsgHTML(_t('_sys_audit_mail_sending'), $aMessage), false);
  499. } else {
  500. return _t('_sys_audit_msg_mail_sent', $sEmailToCkeckMailSending);
  501. }
  502. }
  503. protected function setErrorReporting ()
  504. {
  505. if (version_compare(phpversion(), "5.3.0", ">=") == 1)
  506. $this->iPhpErrorReporting = error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT);
  507. else
  508. $this->iPhpErrorReporting = error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
  509. }
  510. protected function restoreErrorReporting ()
  511. {
  512. error_reporting($this->iPhpErrorReporting);
  513. }
  514. protected function getSection($sTitle, $sTitleAddon, $sContent)
  515. {
  516. $s = '<b>' . $sTitle . '</b>: ' . $sTitleAddon;
  517. $s .= '<ul>';
  518. $s .= $sContent;
  519. $s .= '</ul>';
  520. return $s;
  521. }
  522. protected function getBlock($sName, $sValue = '', $sMsg = '', $bWrapAsListItem = true)
  523. {
  524. $s = $bWrapAsListItem ? '<li>' : '';
  525. if ($sName !== '')
  526. $s .= "$sName ";
  527. if ($sValue !== '')
  528. $s .= " = $sValue ";
  529. if ($sMsg)
  530. $s .= ($s ? " - " : '') . $sMsg;
  531. return $s . ($bWrapAsListItem ? '</li>' : '') . "\n";
  532. }
  533. protected function getMsgHTML($sName, $a)
  534. {
  535. $s = '';
  536. $s .= '<b class="' . $this->aType2ClassCSS[$a['type']]. '">' . $this->aType2Title[$a['type']]. '</b> ';
  537. if (isset($a['msg']))
  538. $s .= '(' . $a['msg'] . ')';
  539. return $s;
  540. }
  541. }
  542. /** @} */