BxDolStudioToolsAudit.php 26 KB

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