BxDolStudioToolsAudit.php 26 KB

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