BxDolStudioToolsAudit.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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.6.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,readfile,escapeshellcmd,fput,popen'),
  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. 'max_heap_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  64. 'tmp_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  65. 'thread_cache_size ' => array('op' => '>', 'val' => 0),
  66. );
  67. $this->aOptimizationSettings = array (
  68. 'DB cache' => array('enabled' => 'sys_db_cache_enable', 'cache_engine' => 'sys_db_cache_engine', 'check_accel' => true),
  69. 'Pages cache' => array('enabled' => 'sys_page_cache_enable', 'cache_engine' => 'sys_page_cache_engine', 'check_accel' => true),
  70. 'Page blocks cache' => array('enabled' => 'sys_pb_cache_enable', 'cache_engine' => 'sys_pb_cache_engine', 'check_accel' => true),
  71. 'Templates Cache' => array('enabled' => 'sys_template_cache_enable', 'cache_engine' => 'sys_template_cache_engine', 'check_accel' => true),
  72. 'CSS files cache' => array('enabled' => 'sys_template_cache_css_enable', 'cache_engine' => '', 'check_accel' => false),
  73. 'JS files cache' => array('enabled' => 'sys_template_cache_js_enable', 'cache_engine' => '', 'check_accel' => false),
  74. 'Compression for CSS/JS cache' => array('enabled' => 'sys_template_cache_compress_enable', 'cache_engine' => '', 'check_accel' => false),
  75. );
  76. $this->aRequiredApacheModules = array (
  77. 'rewrite_module' => 'mod_rewrite',
  78. );
  79. if (isset($_GET['action'])) {
  80. $sOutput = null;
  81. switch ($_GET['action']) {
  82. case 'audit_send_test_email':
  83. $sOutput = $this->sendTestEmail();
  84. break;
  85. case 'phpinfo':
  86. ob_start();
  87. phpinfo();
  88. $sOutput = ob_get_clean();
  89. break;
  90. case 'phpinfo_popup':
  91. $sUrlSelf = bx_js_string($_SERVER['PHP_SELF'], BX_ESCAPE_STR_APOS);
  92. $sUrlSelf = bx_append_url_params($sUrlSelf, array('action' => 'phpinfo'));
  93. $sOutput = '<iframe width="640" height="480" src="' . $sUrlSelf . '"></iframe>';
  94. break;
  95. }
  96. if ($sOutput) {
  97. header('Content-type: text/html; charset=utf-8');
  98. echo $sOutput;
  99. exit;
  100. }
  101. }
  102. }
  103. public function generate()
  104. {
  105. ob_start();
  106. $this->setErrorReporting();
  107. $this->generateStyles();
  108. $this->generateJs();
  109. $this->requirements();
  110. if (!defined('BX_DOL_INSTALL'))
  111. $this->siteSetup();
  112. $this->optimization();
  113. $this->manualCheck();
  114. $this->restoreErrorReporting();
  115. return ob_get_clean();
  116. }
  117. public function generateStyles($bReturn = false)
  118. {
  119. ob_start();
  120. ?>
  121. <style>
  122. .ok {
  123. color:green;
  124. }
  125. .fail {
  126. color:red;
  127. }
  128. .warn {
  129. color:orange;
  130. }
  131. .undef {
  132. color:gray;
  133. }
  134. </style>
  135. <?php
  136. $sStyles = ob_get_clean();
  137. if($bReturn)
  138. return $sStyles;
  139. echo $sStyles;
  140. }
  141. public function generateJs()
  142. {
  143. $sUrlSelf = bx_js_string($_SERVER['PHP_SELF'], BX_ESCAPE_STR_APOS);
  144. ?>
  145. <script language="javascript">
  146. function bx_sys_adm_audit_test_email()
  147. {
  148. bx_prompt('<?php echo _t('_Email'); ?>', '<?php echo class_exists('BxDolDb') && BxDolDb::getInstance() ? BxDolDb::getInstance()->getParam('site_email') : ''; ?>', function(oPopup) {
  149. var sEmail = oPopup.getValue();
  150. if (null == sEmail || ('string' == (typeof sEmail) && !sEmail.length))
  151. return;
  152. $('#bx-sys-adm-audit-test-email').html('Sending...');
  153. $.post('<?php echo bx_append_url_params($sUrlSelf, array('action' => 'audit_send_test_email')); ?>&email=' + sEmail, function(data) {
  154. $('#bx-sys-adm-audit-test-email').html(data);
  155. });
  156. });
  157. return false;
  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. $sHttpCode = null;
  201. $s = bx_file_get_contents('http://php.net/releases/index.php?serialize=1', array(), 'get', array(), $sHttpCode, array(), 20, array(CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4));
  202. $sLatestPhpVersion = $s && ($a = unserialize($s)) ? $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. $iCronTime = getParam('sys_cron_time');
  296. $s .= $this->getBlock(_t('_sys_audit_cron_jobs_exec_time'), '', !empty($iCronTime) ? bx_time_js($iCronTime, BX_FORMAT_DATE_TIME, true) : _t('_None'));
  297. echo '<h1>' . _t('_sys_audit_header_site_setup') . '</h1>';
  298. echo "<ul>$s</ul>";
  299. }
  300. protected function optimization()
  301. {
  302. echo '<h1>' . _t('_sys_audit_header_site_optimization') . '</h1>';
  303. $this->optimizationPhp();
  304. if (!defined('BX_DOL_INSTALL'))
  305. $this->optimizationMySQL();
  306. $this->optimizationWebServer();
  307. if (!defined('BX_DOL_INSTALL'))
  308. $this->optimizationScript();
  309. }
  310. protected function optimizationPhp()
  311. {
  312. $s = '';
  313. $aMessage = array();
  314. $sAccel = $this->getPhpAccelerator();
  315. if (!$sAccel)
  316. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_php_accelerator_missing'));
  317. else
  318. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  319. $s .= $this->getBlock(_t('_sys_audit_php_accelerator'), $sAccel, $this->getMsgHTML(_t('_sys_audit_php_accelerator'), $aMessage));
  320. $sSapi = php_sapi_name();
  321. if (0 === strcasecmp('cgi', $sSapi))
  322. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_php_setup_inefficient'));
  323. else
  324. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  325. $s .= $this->getBlock(_t('_sys_audit_php_setup'), $sSapi, $this->getMsgHTML(_t('_sys_audit_php_setup'), $aMessage));
  326. echo $this->getSection('PHP', '', $s);
  327. }
  328. protected function optimizationMySQL()
  329. {
  330. $s = '';
  331. $oDb = BxDolDb::getInstance();
  332. foreach ($this->aMysqlOptimizationSettings as $sName => $r) {
  333. $a = $this->checkMysqlSetting($sName, $r, $oDb);
  334. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  335. if (!$a['res'])
  336. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_must_be', $r['op'], $this->format_output($r['val'], $r)));
  337. $s .= $this->getBlock($sName, $this->format_output($a['real_val'], $r), $this->getMsgHTML($sName, $aMessage));
  338. }
  339. echo $this->getSection('MySQL', '', $s);
  340. }
  341. protected function optimizationWebServer()
  342. {
  343. $s = '';
  344. $sName = 'expires_module';
  345. $sApacheModuleChack = _t('_sys_audit_msg_optimization_apache_module', $sName, $this->getMsgHTML($sName, $this->checkApacheModule($sName)));
  346. $s .= $this->getBlock(_t('_sys_audit_userside_caching'), '', _t('_sys_audit_msg_userside_caching', $this->getUrlForGooglePageSpeed('LeverageBrowserCaching'), $sApacheModuleChack));
  347. $sName = 'deflate_module';
  348. $sApacheModuleChack = _t('_sys_audit_msg_optimization_apache_module', $sName, $this->getMsgHTML($sName, $this->checkApacheModule($sName)));
  349. $s .= $this->getBlock(_t('_sys_audit_serverside_compression'), '', _t('_sys_audit_msg_serverside_compression', $sApacheModuleChack));
  350. echo $this->getSection(_t('_sys_audit_section_webserver'), '', $s);
  351. }
  352. protected function optimizationScript()
  353. {
  354. $s = '';
  355. foreach ($this->aOptimizationSettings as $sName => $a) {
  356. $sVal = ('always_on' == $a['enabled'] || getParam($a['enabled'])) ? 'On' : 'Off';
  357. if ($a['cache_engine'])
  358. $sVal .= _t('_sys_audit_msg_x_based_cache_engine', getParam($a['cache_engine']));
  359. if ('always_on' != $a['enabled'] && !getParam($a['enabled']))
  360. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_optimization_fail'));
  361. elseif ($a['check_accel'] && !$this->getPhpAccelerator() && 'File' == getParam($a['cache_engine']))
  362. $aMessage = array('type' => BX_DOL_AUDIT_WARN, 'msg' => _t('_sys_audit_msg_optimization_warn'));
  363. else
  364. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  365. $s .= $this->getBlock($sName, $sVal, $this->getMsgHTML($sName, $aMessage));
  366. }
  367. echo $this->getSection('UNA', '', $s);
  368. }
  369. protected function manualCheck()
  370. {
  371. echo '<a name="manual_audit"></a>';
  372. echo '<h1>' . _t('_sys_audit_header_manual_audit') . '</h1>';
  373. echo _t('_sys_audit_msg_manual_audit');
  374. }
  375. protected function checkPhpSetting($sName, $a)
  376. {
  377. $mixedVal = ini_get($sName);
  378. $mixedVal = $this->format_input ($mixedVal, $a);
  379. switch ($a['op']) {
  380. case 'without':
  381. $aFuncsDisabled = explode(',', $mixedVal);
  382. array_walk($aFuncsDisabled, function (&$sVal, $sKey) {
  383. $sVal = trim($sVal);
  384. });
  385. $aFuncsMustBeEnabled = explode(',', $a['val']);
  386. $a = array_intersect($aFuncsDisabled, $aFuncsMustBeEnabled);
  387. $bResult = !$a;
  388. break;
  389. case 'module':
  390. $bResult = extension_loaded($a['val']);
  391. $mixedVal = $bResult ? $a['val'] : '';
  392. break;
  393. case '>':
  394. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal > $a['val']);
  395. break;
  396. case '>=':
  397. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal >= $a['val']);
  398. break;
  399. case '=':
  400. default:
  401. $bResult = ($mixedVal == $a['val']);
  402. }
  403. return array ('res' => $bResult, 'real_val' => $mixedVal);
  404. }
  405. protected function checkMysqlSetting($sName, $a, $oDb)
  406. {
  407. $mixedVal = $oDb->getOption($sName);
  408. $mixedVal = $this->format_input ($mixedVal, $a);
  409. switch ($a['op']) {
  410. case '>':
  411. $bResult = ($mixedVal > $a['val']);
  412. break;
  413. case '>=':
  414. $bResult = ($mixedVal >= $a['val']);
  415. break;
  416. case 'strcasecmp':
  417. $bResult = 0 === strcasecmp($mixedVal, $a['val']);
  418. break;
  419. case '=':
  420. default:
  421. $bResult = ($mixedVal == $a['val']);
  422. }
  423. return array ('res' => $bResult, 'real_val' => $mixedVal);
  424. }
  425. protected function format_output ($mixedVal, $a)
  426. {
  427. if (isset($a['type']) && 'bytes' == $a['type'])
  428. return function_exists('_t_format_size') ? _t_format_size($mixedVal) : $mixedVal;
  429. if (isset($a['type']) && 'bool' == $a['type'])
  430. return $mixedVal ? 'On' : 'Off';
  431. else
  432. return $mixedVal;
  433. }
  434. protected function format_input ($mixedVal, $a)
  435. {
  436. if (isset($a['type']) && 'bytes' == $a['type'])
  437. return $this->format_bytes ($mixedVal);
  438. else
  439. return $mixedVal;
  440. }
  441. protected function format_bytes($val)
  442. {
  443. return return_bytes($val);
  444. }
  445. protected function checkApacheModule ($sModule, $sNameCompiledName = '')
  446. {
  447. $a = array (
  448. 'deflate_module' => 'mod_deflate',
  449. 'expires_module' => 'mod_expires',
  450. );
  451. if (!$sNameCompiledName && isset($a[$sModule]))
  452. $sNameCompiledName = $a[$sModule];
  453. if (function_exists('apache_get_modules')) {
  454. $aModules = apache_get_modules();
  455. $ret = in_array($sNameCompiledName, $aModules);
  456. } else {
  457. $sApachectlPath = trim(`which apachectl`);
  458. if (!$sApachectlPath)
  459. $sApachectlPath = trim(`which apache2ctl`);
  460. if (!$sApachectlPath)
  461. $sApachectlPath = trim(`which /usr/local/apache/bin/apachectl`);
  462. if (!$sApachectlPath)
  463. $sApachectlPath = trim(`which /usr/local/apache/bin/apache2ctl`);
  464. if (!$sApachectlPath) {
  465. return array('type' => BX_DOL_AUDIT_UNDEF);
  466. }
  467. $ret = (boolean)`$sApachectlPath -M 2>&1 | grep $sModule`;
  468. if (!$ret)
  469. $ret = (boolean)`$sApachectlPath -l 2>&1 | grep $sNameCompiledName`;
  470. }
  471. $aMessage = array('type' => BX_DOL_AUDIT_OK);
  472. if (!$ret)
  473. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_apache_module_fail', $sModule));
  474. return $aMessage;
  475. }
  476. protected function getPhpAccelerator ()
  477. {
  478. $aAccelerators = array (
  479. 'APC' => array('op' => 'module', 'val' => 'apc'),
  480. 'XCache' => array('op' => 'module', 'val' => 'xcache'),
  481. 'ZendOPcache' => array('op' => 'module', 'val' => 'Zend OPcache'),
  482. );
  483. foreach ($aAccelerators as $sName => $r) {
  484. $a = $this->checkPhpSetting($sName, $r);
  485. if ($a['res'])
  486. return $sName;
  487. }
  488. return false;
  489. }
  490. protected function getUrlForGooglePageSpeed ($sRule)
  491. {
  492. $sUrl = urlencode(BX_DOL_URL_ROOT);
  493. return 'http://pagespeed.googlelabs.com/#url=' . $sUrl . '&mobile=false&rule=' . $sRule;
  494. }
  495. protected function sendTestEmail ()
  496. {
  497. $sEmailToCkeckMailSending = isset($_GET['email']) ? $_GET['email'] : getParam('site_email');
  498. $mixedRet = sendMail($sEmailToCkeckMailSending, 'Audit Test Email', 'Sample text for testing<br /><u><b>Sample text for testing</b></u>', '', array(), BX_EMAIL_SYSTEM);
  499. if (!$mixedRet) {
  500. $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_mail_send_failed'));
  501. return $this->getBlock('', '', $this->getMsgHTML(_t('_sys_audit_mail_sending'), $aMessage), false);
  502. } else {
  503. return _t('_sys_audit_msg_mail_sent', $sEmailToCkeckMailSending);
  504. }
  505. }
  506. protected function setErrorReporting ()
  507. {
  508. if (version_compare(phpversion(), "5.3.0", ">=") == 1)
  509. $this->iPhpErrorReporting = error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED & ~E_STRICT);
  510. else
  511. $this->iPhpErrorReporting = error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
  512. }
  513. protected function restoreErrorReporting ()
  514. {
  515. error_reporting($this->iPhpErrorReporting);
  516. }
  517. protected function getSection($sTitle, $sTitleAddon, $sContent)
  518. {
  519. $s = '<b>' . $sTitle . '</b>: ' . $sTitleAddon;
  520. $s .= '<ul>';
  521. $s .= $sContent;
  522. $s .= '</ul>';
  523. return $s;
  524. }
  525. protected function getBlock($sName, $sValue = '', $sMsg = '', $bWrapAsListItem = true)
  526. {
  527. $s = $bWrapAsListItem ? '<li>' : '';
  528. if ($sName !== '')
  529. $s .= "$sName ";
  530. if ($sValue !== '')
  531. $s .= " = $sValue ";
  532. if ($sMsg)
  533. $s .= ($s ? " - " : '') . $sMsg;
  534. return $s . ($bWrapAsListItem ? '</li>' : '') . "\n";
  535. }
  536. protected function getMsgHTML($sName, $a)
  537. {
  538. $s = '';
  539. $s .= '<b class="' . $this->aType2ClassCSS[$a['type']]. '">' . $this->aType2Title[$a['type']]. '</b> ';
  540. if (isset($a['msg']))
  541. $s .= '(' . $a['msg'] . ')';
  542. return $s;
  543. }
  544. }
  545. /** @} */