BxDolStudioTools.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. <?php defined('BX_DOL') 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. require_once('./../inc/classes/BxDolIO.php');
  10. // TODO: consider rewriting installer
  11. class BxDolAdminTools extends BxDolIO
  12. {
  13. protected $sTroubledElements;
  14. protected $aInstallDirs;
  15. protected $aInstallFiles;
  16. protected $aPostInstallPermDirs;
  17. protected $aPostInstallPermFiles;
  18. function __construct()
  19. {
  20. parent::__construct();
  21. $this->sTroubledElements = '';
  22. $this->aInstallDirs = array(
  23. 'cache',
  24. 'cache_public',
  25. 'tmp',
  26. 'plugins/htmlpurifier/standalone/HTMLPurifier/DefinitionCache/Serializer',
  27. );
  28. $this->aInstallFiles = array(
  29. );
  30. $this->aPostInstallPermDirs = array(
  31. );
  32. $this->aPostInstallPermFiles = array(
  33. );
  34. }
  35. function GenCommonCode()
  36. {
  37. $sAdditionDir = (isAdmin()==true) ? BX_DOL_URL_ROOT : '../';
  38. $sMasterSwPic = $sAdditionDir . 'media/images/master_nav.gif';
  39. $sRet = <<<EOF
  40. <style type="text/css">
  41. div.hidden {
  42. display:none;
  43. }
  44. .left_side_sw_caption {
  45. float:left;
  46. text-align:justify;
  47. width:515px;
  48. }
  49. .right_side_sw_caption {
  50. float:right;
  51. font-weight:normal;
  52. }
  53. tr.head td {
  54. background-color:#FFFFFF;
  55. font-weight:bold;
  56. height:17px;
  57. padding:5px;
  58. text-align:center;
  59. font-size:13px;
  60. border-color:silver;
  61. }
  62. tr.cont td {
  63. height:15px;
  64. padding:2px 5px;
  65. font-size:13px;
  66. border-color:silver;
  67. }
  68. .install_table {
  69. background-color: silver;
  70. border-width:0px;
  71. }
  72. span.unwritable {
  73. color:red;
  74. font-weight:bold;
  75. margin-right:5px;
  76. }
  77. span.writable {
  78. color:green;
  79. font-weight:bold;
  80. margin-right:5px;
  81. }
  82. span.desired {
  83. font-weight:bold;
  84. margin-right:5px;
  85. }
  86. .install_table tr.even {
  87. background-color:#EDE9E9;
  88. }
  89. .install_table tr.odd {
  90. background-color:#FFF;
  91. }
  92. .install_table tr:hover{
  93. background-color:#DDD;
  94. }
  95. #btn-alls-on {
  96. background:transparent url({$sMasterSwPic}) no-repeat scroll -0px -0px;
  97. width:25px;
  98. height:21px;
  99. }
  100. #btn-alls-off {
  101. background:transparent url({$sMasterSwPic}) no-repeat scroll -0px -20px;
  102. width:25px;
  103. height:21px;
  104. }
  105. #btn-troubled-on {
  106. background:transparent url({$sMasterSwPic}) no-repeat scroll -24px -20px;
  107. width:25px;
  108. height:21px;
  109. }
  110. #btn-troubled-off {
  111. background:transparent url({$sMasterSwPic}) no-repeat scroll -24px -0px;
  112. width:25px;
  113. height:21px;
  114. }
  115. tr.head td.left_aligned {
  116. text-align:left;
  117. font-weight:bold;
  118. }
  119. </style>
  120. EOF;
  121. return $sRet;
  122. }
  123. /**
  124. * Generate permissions table for modules
  125. * @param $iType - 1: folder, 2: file
  126. * @return HTML
  127. */
  128. function GenPermTableForModules($iType)
  129. {
  130. $aList = array ();
  131. bx_import('BxDolModuleDb');
  132. $oDbModules = new BxDolModuleDb();
  133. $aModules = $oDbModules->getModules();
  134. foreach ($aModules as $a) {
  135. if (empty($a['path']) || !include(BX_DIRECTORY_PATH_MODULES . $a['path'] . 'install/config.php'))
  136. continue;
  137. if (empty($aConfig['install_permissions']) || !is_array($aConfig['install_permissions']['writable']))
  138. continue;
  139. foreach ($aConfig['install_permissions']['writable'] as $sPath) {
  140. if (1 == $iType && is_dir(BX_DIRECTORY_PATH_MODULES . $a['path'] . $sPath))
  141. $aList[] = basename(BX_DIRECTORY_PATH_MODULES) . '/' . $a['path'] . $sPath;
  142. elseif (2 == $iType && is_file(BX_DIRECTORY_PATH_MODULES . $a['path'] . $sPath))
  143. $aList[] = basename(BX_DIRECTORY_PATH_MODULES) . '/' . $a['path'] . $sPath;
  144. }
  145. }
  146. return $this->GenArrElemPerm($aList, $iType);
  147. }
  148. function GenPermTable($isShowModules = false)
  149. {
  150. $sModulesDirsC = function_exists('_t') ? _t('_adm_admtools_modules_dirs') : 'Modules Directories';
  151. $sModulesFilesC = function_exists('_t') ? _t('_adm_admtools_modules_files') : 'Modules Files';
  152. $sDirsC = function_exists('_t') ? _t('_adm_admtools_Directories') : 'Directories';
  153. $sFilesC = function_exists('_t') ? _t('_adm_admtools_Files') : 'Files';
  154. $sElementsC = function_exists('_t') ? _t('_adm_admtools_Elements') : 'Elements';
  155. $sCurrentLevelC = function_exists('_t') ? _t('_adm_admtools_Current_level') : 'Current level';
  156. $sDesiredLevelC = function_exists('_t') ? _t('_adm_admtools_Desired_level') : 'Desired level';
  157. $sBadFilesC = function_exists('_t') ? _t('_adm_admtools_Bad_files') : 'The following files and directories have inappropriate permissions';
  158. $sShowOnlyBadC = function_exists('_t') ? _t('_adm_admtools_Only_bad_files') : 'Show only files and directories with inappropriate permissions';
  159. $sDescriptionC = function_exists('_t') ? _t('_adm_admtools_Perm_description') : 'Dolphin needs special access for certain files and directories. Please, change permissions as specified in the chart below. Helpful info about permissions is <a href="http://www.boonex.com/trac/dolphin/wiki/DetailedInstall#Permissions" target="_blank">available here</a>.';
  160. $this->sTroubledElements = '';
  161. $sInstallDirs = $this->GenArrElemPerm($this->aInstallDirs, 1);
  162. $sInstallFiles = $this->GenArrElemPerm($this->aInstallFiles, 2);
  163. if ($isShowModules) {
  164. $sModulesDirs = $this->GenPermTableForModules(1);
  165. $sModulesFiles = $this->GenPermTableForModules(2);
  166. if ($sModulesDirs)
  167. $sModulesDirs = "
  168. <tr class='head'>
  169. <td>{$sModulesDirsC}</td>
  170. <td>{$sCurrentLevelC}</td>
  171. <td>{$sDesiredLevelC}</td>
  172. </tr>" . $sModulesDirs;
  173. if ($sModulesFiles)
  174. $sModulesFiles = "
  175. <tr class='head'>
  176. <td>{$sModulesFilesC}</td>
  177. <td>{$sCurrentLevelC}</td>
  178. <td>{$sDesiredLevelC}</td>
  179. </tr>" . $sModulesFiles;
  180. }
  181. $sAdditionDir = (isAdmin()==true) ? BX_DOL_URL_ROOT : '../';
  182. $sLeftAddEl = (isAdmin()==true) ? '<div class="left_side_sw_caption">'.$sDescriptionC.'</div>' : '';
  183. $sSpacerPic = $sAdditionDir . 'media/images/spacer.gif';
  184. $sRet = <<<EOF
  185. <script type="text/javascript">
  186. <!--
  187. function callSwitcher()
  188. {
  189. $('table.install_table tr:not(.troubled)').toggle();
  190. }
  191. function switchToTroubled(e)
  192. {
  193. if (!e.checked) {
  194. $("#btn-alls-off").attr("id", "btn-alls-on");
  195. $("#btn-troubled-on").attr("id", "btn-troubled-off");
  196. $('table.install_table tr:not(.troubled)').show();
  197. } else {
  198. $("#btn-alls-on").attr("id", "btn-alls-off");
  199. $("#btn-troubled-off").attr("id", "btn-troubled-on");
  200. $('table.install_table tr:not(.troubled)').hide();
  201. }
  202. return false;
  203. }
  204. -->
  205. </script>
  206. <table width="100%" cellspacing="1" cellpadding="0" class="install_table">
  207. <tr class="head troubled">
  208. <td colspan="3" style="text-align:center;">
  209. {$sLeftAddEl}
  210. <div class="right_side_sw_caption">
  211. <input type="checkbox" id="bx-install-permissions-show-erros-only" onclick="switchToTroubled(this)" /> <label for="bx-install-permissions-show-erros-only">$sShowOnlyBadC</label>
  212. </div>
  213. <div class="clear_both"></div>
  214. </td>
  215. </tr>
  216. <tr class="head">
  217. <td colspan="3" style="text-align:center;" class="normal_td">{$sDirsC}</td>
  218. </tr>
  219. <tr class="head">
  220. <td>{$sDirsC}</td>
  221. <td>{$sCurrentLevelC}</td>
  222. <td>{$sDesiredLevelC}</td>
  223. </tr>
  224. {$sInstallDirs}
  225. {$sModulesDirs}
  226. <tr class="head">
  227. <td colspan="3" style="text-align:center;">{$sFilesC}</td>
  228. </tr>
  229. <tr class="head">
  230. <td>{$sFilesC}</td>
  231. <td>{$sCurrentLevelC}</td>
  232. <td>{$sDesiredLevelC}</td>
  233. </tr>
  234. {$sInstallFiles}
  235. {$sModulesFiles}
  236. <tr class="head troubled">
  237. <td colspan="3" style="text-align:center;">{$sBadFilesC}</td>
  238. </tr>
  239. <tr class="head troubled">
  240. <td>{$sElementsC}</td>
  241. <td>{$sCurrentLevelC}</td>
  242. <td>{$sDesiredLevelC}</td>
  243. </tr>
  244. {$this->sTroubledElements}
  245. </table>
  246. EOF;
  247. return $sRet;
  248. }
  249. //$iType: 1 - folder, 2 - file
  250. function GenArrElemPerm($aElements, $iType)
  251. {
  252. if (!is_array($aElements) || empty($aElements))
  253. return '';
  254. $sWritableC = function_exists('_t') ? _t('_adm_admtools_Writable') : 'Writable';
  255. $sNonWritableC = function_exists('_t') ? _t('_adm_admtools_Non_Writable') : 'Non-Writable';
  256. $sNotExistsC = function_exists('_t') ? _t('_adm_admtools_Not_Exists') : 'Not Exists';
  257. $sExecutableC = function_exists('_t') ? _t('_adm_admtools_Executable') : 'Executable';
  258. $sNonExecutableC = function_exists('_t') ? _t('_adm_admtools_Non_Executable') : 'Non-Executable';
  259. $iType = ($iType==1) ? 1 : 2;
  260. $sElements = '';
  261. $i = 0;
  262. foreach ($aElements as $sCurElement) {
  263. $iCurType = $iType;
  264. $sAwaitedPerm = ($iCurType==1) ? $sWritableC : $sWritableC;
  265. $sElemCntStyle = ($i%2==0) ? 'even' : 'odd' ;
  266. $bAccessible = ($iCurType==1) ? $this->isWritable($sCurElement) : $this->isWritable($sCurElement);
  267. if ($sCurElement == 'flash/modules/global/app/ffmpeg.exe') {
  268. $sAwaitedPerm = $sExecutableC;
  269. $bAccessible = $this->isExecutable($sCurElement);
  270. }
  271. if ($bAccessible) {
  272. $sResultPerm = ($iCurType==1) ? $sWritableC : $sWritableC;
  273. if ($sCurElement == 'flash/modules/global/app/ffmpeg.exe') {
  274. $sResultPerm = $sExecutableC;
  275. }
  276. $sElements .= <<<EOF
  277. <tr class="cont {$sElemCntStyle}">
  278. <td>{$sCurElement}</td>
  279. <td class="span">
  280. <span class="writable">{$sResultPerm}</span>
  281. </td>
  282. <td class="span">
  283. <span class="desired">{$sAwaitedPerm}</span>
  284. </td>
  285. </tr>
  286. EOF;
  287. } else {
  288. $sPerm = $this->getPermissions($sCurElement);
  289. $sResultPerm = '';
  290. if ($sPerm==false) {
  291. $sResultPerm = $sNotExistsC;
  292. } else {
  293. $sResultPerm = ($iCurType==1) ? $sNonWritableC : $sNonWritableC;
  294. }
  295. if ($sCurElement == 'flash/modules/global/app/ffmpeg.exe') {
  296. $sResultPerm = $sNonExecutableC;
  297. }
  298. $sPerm = '';
  299. $sElements .= <<<EOF
  300. <tr class="cont {$sElemCntStyle}">
  301. <td>{$sCurElement}</td>
  302. <td class="span">
  303. <span class="unwritable">{$sPerm} {$sResultPerm}</span>
  304. </td>
  305. <td class="span">
  306. <span class="desired">{$sAwaitedPerm}</span>
  307. </td>
  308. </tr>
  309. EOF;
  310. $this->sTroubledElements .= <<<EOF
  311. <tr class="cont {$sElemCntStyle} troubled">
  312. <td>{$sCurElement}</td>
  313. <td class="span">
  314. <span class="unwritable">{$sPerm} {$sResultPerm}</span>
  315. </td>
  316. <td class="span">
  317. <span class="desired">{$sAwaitedPerm}</span>
  318. </td>
  319. </tr>
  320. EOF;
  321. }
  322. $i++;
  323. }
  324. return $sElements;
  325. }
  326. //check requirements
  327. function performInstalCheck()
  328. {
  329. $aErrors = array();
  330. $aErrors[] = (ini_get('register_globals') == 0) ? '' : '<font color="red">register_globals is On (warning, you should have this param in Off state, or your site will unsafe)</font>';
  331. $aErrors[] = (ini_get('safe_mode') == 0) ? '' : '<font color="red">safe_mode is On, disable it</font>';
  332. $aErrors[] = (((int)phpversion()) < 4) ? '<font color="red">PHP version too old, update server please</font>' : '';
  333. $aErrors[] = (!extension_loaded( 'mbstring')) ? '<font color="red">mbstring extension not installed. <b>Warning!</b> Dolphin cannot work without <b>mbstring</b> extension.</font>' : '';
  334. $aErrors[] = (ini_get('short_open_tag') == 0 && version_compare(phpversion(), "5.4", "<") == 1) ? '<font color="red">short_open_tag is Off (must be On!)<b>Warning!</b> Dolphin cannot work without <b>short_open_tag</b>.</font>' : '';
  335. if (version_compare(phpversion(), "5.2", ">") == 1) {
  336. $aErrors[] = (ini_get('allow_url_include') == 0) ? '' : '<font color="red">allow_url_include is On (warning, you should have this param in Off state, or your site will unsafe)</font>';
  337. };
  338. $aErrors = array_diff($aErrors, array('')); //delete empty
  339. if (count($aErrors)) {
  340. $sErrors = implode(" <br /> ", $aErrors);
  341. echo <<<EOF
  342. {$sErrors} <br />
  343. Please go to the <br />
  344. <a href="http://www.boonex.com/trac/dolphin/wiki/GenDolTShooter">Dolphin Troubleshooter</a> <br />
  345. and solve the problem.
  346. EOF;
  347. exit;
  348. }
  349. }
  350. function GenCacheEnginesTable()
  351. {
  352. $sRet = '<table width="100%" cellspacing="1" cellpadding="0" class="install_table">';
  353. $sRet .= '
  354. <tr class="head troubled">
  355. <td></td>
  356. <td class="center_aligned">' . _t('_sys_adm_installed') . '</td>
  357. <td class="center_aligned">' . _t('_sys_adm_cache_support') . '</td>
  358. </tr>';
  359. $aEngines = array ('File', 'Memcache', 'APC', 'XCache');
  360. foreach ($aEngines as $sEngine) {
  361. $oCacheObject = @bx_instance ('BxDolCache' . $sEngine);
  362. $sRet .= '
  363. <tr class="head troubled">
  364. <td class="left_aligned">' . $sEngine . '</td>
  365. <td class="center_aligned">' . (@$oCacheObject->isInstalled() ? '<font color="green">' . _t('_Yes') . '</font>' : '<font color="red">' . _t('_No') . '</font>') . '</td>
  366. <td class="center_aligned">' . (@$oCacheObject->isAvailable() ? '<font color="green">' . _t('_Yes') . '</font>' : '<font color="red">' . _t('_No') . '</font>') . '</td>
  367. </tr>';
  368. }
  369. $sRet .= '</table>';
  370. return $sRet;
  371. }
  372. function GenTabbedPage($isShowModules = false)
  373. {
  374. $sTitleC = _t('_adm_admtools_title');
  375. $sAuditC = _t('');
  376. $sPermissionsC = _t('');
  377. $sCacheEnginesC = _t('');
  378. $sAuditTab = $this->GenAuditPage();
  379. $sPermissionsTab = $this->GenPermTable($isShowModules);
  380. $sCacheEnginesTab = $this->GenCacheEnginesTable();
  381. $sBoxContent = <<<EOF
  382. <script type="text/javascript">
  383. <!--
  384. function switchAdmPage(oLink)
  385. {
  386. var sType = $(oLink).attr('id').replace('main_menu', '');
  387. var sName = '#page' + sType;
  388. $(oLink).parent('.notActive').hide().siblings('.notActive:hidden').show().siblings('.active').hide().siblings('#' + $(oLink).attr('id') + '-act').show();
  389. $(sName).siblings('div:visible').bx_anim('hide', 'fade', 'slow', function(){
  390. $(sName).bx_anim('show', 'fade', 'slow');
  391. });
  392. return false;
  393. }
  394. -->
  395. </script>
  396. <div class="boxContent" id="adm_pages">
  397. <div id="page0" class="visible">{$sAuditTab}</div>
  398. <div id="page1" class="hidden">{$sPermissionsTab}</div>
  399. <div id="page2" class="hidden">
  400. <iframe frameborder="0" width="100%" height="800" scrolling="auto" src="host_tools.php?get_phpinfo=true"></iframe>
  401. </div>
  402. <div id="page3" class="hidden">{$sCacheEnginesTab}</div>
  403. </div>
  404. EOF;
  405. $aTopItems = array(
  406. 'main_menu0' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_admtools_Audit'), 'active' => 1),
  407. 'main_menu1' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_admtools_Permissions'), 'active' => 0),
  408. 'main_menu2' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_admtools_phpinfo'), 'active' => 0),
  409. );
  410. return DesignBoxAdmin($sTitleC, $sBoxContent, $aTopItems, '', 11);
  411. }
  412. //************
  413. function isFolderReadWrite($filename)
  414. {
  415. clearstatcache();
  416. $aPathInfo = pathinfo(__FILE__);
  417. $filename = $aPathInfo['dirname'] . '/../../' . $filename;
  418. return (@file_exists($filename . '/.') && is_readable( $filename ) && is_writable( $filename ) ) ? true : false;
  419. }
  420. function isFileReadWrite($filename)
  421. {
  422. clearstatcache();
  423. $aPathInfo = pathinfo(__FILE__);
  424. $filename = $aPathInfo['dirname'] . '/../../' . $filename;
  425. return (is_file($filename) && is_readable( $filename ) && is_writable( $filename ) ) ? true : false;
  426. }
  427. function isFileExecutable($filename)
  428. {
  429. clearstatcache();
  430. $aPathInfo = pathinfo(__FILE__);
  431. $filename = $aPathInfo['dirname'] . '/../../' . $filename;
  432. return (is_file($filename) && is_executable( $filename ) ) ? true : false;
  433. }
  434. //************
  435. function isAllowUrlInclude()
  436. {
  437. if (version_compare(phpversion(), "5.2", ">") == 1) {
  438. $sAllowUrlInclude = ini_get('allow_url_include');
  439. return !($sAllowUrlInclude == 0);
  440. };
  441. return false;
  442. }
  443. function GenAuditPage()
  444. {
  445. $sDolphinPath = BX_DIRECTORY_PATH_ROOT;
  446. $sEmailToCkeckMailSending = getParam('site_email');
  447. $sLatestDolphinVer = file_get_contents("http://rss.boonex.com/");
  448. if (preg_match ('#<dolphin>([\.0-9]+)</dolphin>#', $sLatestDolphinVer, $m))
  449. $sLatestDolphinVer = $m[1];
  450. else
  451. $sLatestDolphinVer = 'undefined';
  452. $sMinPhpVer = '5.2.0';
  453. $sMinMysqlVer = '4.1.2';
  454. $a = unserialize(file_get_contents("http://www.php.net/releases/index.php?serialize=1"));
  455. $sLatestPhpVersion = $a[5]['version'];
  456. $sLatestPhp53Version = '5.3.18';
  457. $aPhpSettings = array (
  458. 'allow_url_fopen' => array('op' => '=', 'val' => true, 'type' => 'bool'),
  459. 'allow_url_include' => array('op' => '=', 'val' => false, 'type' => 'bool'),
  460. 'magic_quotes_gpc' => array('op' => '=', 'val' => false, 'type' => 'bool', 'warn' => 1),
  461. 'memory_limit' => array('op' => '>=', 'val' => 128*1024*1024, 'type' => 'bytes', 'unlimited' => -1),
  462. 'post_max_size' => array('op' => '>=', 'val' => 50*1024*1024, 'type' => 'bytes', 'warn' => 1),
  463. 'upload_max_filesize' => array('op' => '>=', 'val' => 50*1024*1024, 'type' => 'bytes', 'warn' => 1),
  464. 'register_globals' => array('op' => '=', 'val' => false, 'type' => 'bool'),
  465. 'safe_mode' => array('op' => '=', 'val' => false, 'type' => 'bool'),
  466. 'short_open_tag' => array('op' => '=', 'val' => true, 'type' => 'bool'),
  467. 'disable_functions' => array('op' => '=', 'val' => ''),
  468. 'php module: curl' => array('op' => 'module', 'val' => 'curl'),
  469. 'php module: gd' => array('op' => 'module', 'val' => 'gd'),
  470. 'php module: mbstring' => array('op' => 'module', 'val' => 'mbstring'),
  471. 'php module: xsl' => array('op' => 'module', 'val' => 'xsl', 'warn' => 1),
  472. 'php module: json' => array('op' => 'module', 'val' => 'json', 'warn' => 1),
  473. 'php module: openssl' => array('op' => 'module', 'val' => 'openssl', 'warn' => 1),
  474. 'php module: zip' => array('op' => 'module', 'val' => 'zip', 'warn' => 1),
  475. 'php module: ftp' => array('op' => 'module', 'val' => 'ftp', 'warn' => 1),
  476. );
  477. if (version_compare(phpversion(), "5.4", ">=") == 1)
  478. unset($aPhpSettings['short_open_tag']);
  479. $aMysqlSettings = array (
  480. 'key_buffer_size' => array('op' => '>=', 'val' => 128*1024, 'type' => 'bytes'),
  481. 'query_cache_limit' => array('op' => '>=', 'val' => 1000000),
  482. 'query_cache_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  483. 'query_cache_type' => array('op' => 'strcasecmp', 'val' => 'on'),
  484. 'max_heap_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  485. 'tmp_table_size' => array('op' => '>=', 'val' => 16*1024*1024, 'type' => 'bytes'),
  486. 'thread_cache_size ' => array('op' => '>', 'val' => 0),
  487. );
  488. $aRequiredApacheModules = array (
  489. 'rewrite_module' => 'mod_rewrite',
  490. );
  491. $aDolphinOptimizationSettings = array (
  492. 'DB cache' => array('enabled' => 'sys_db_cache_enable', 'cache_engine' => 'sys_db_cache_engine', 'check_accel' => true),
  493. 'Page blocks cache' => array('enabled' => 'sys_pb_cache_enable', 'cache_engine' => 'sys_pb_cache_engine', 'check_accel' => true),
  494. 'Member menu cache' => array('enabled' => 'always_on', 'cache_engine' => 'sys_mm_cache_engine', 'check_accel' => true),
  495. 'Templates Cache' => array('enabled' => 'sys_template_cache_enable', 'cache_engine' => 'sys_template_cache_engine', 'check_accel' => true),
  496. 'CSS files cache' => array('enabled' => 'sys_template_cache_css_enable', 'cache_engine' => '', 'check_accel' => false),
  497. 'JS files cache' => array('enabled' => 'sys_template_cache_js_enable', 'cache_engine' => '', 'check_accel' => false),
  498. 'Compression for CSS/JS cache' => array('enabled' => 'sys_template_cache_compress_enable', 'cache_engine' => '', 'check_accel' => false),
  499. );
  500. ob_start();
  501. ?>
  502. <style>
  503. .ok {
  504. color:green;
  505. }
  506. .fail {
  507. color:red;
  508. }
  509. .warn {
  510. color:orange;
  511. }
  512. .undef {
  513. color:gray;
  514. }
  515. </style>
  516. <h2>Software requirements</h2>
  517. <ul>
  518. <li><b>PHP</b>:
  519. <?php
  520. $sPhpVer = PHP_VERSION;
  521. echo $sPhpVer . ' - ';
  522. if (version_compare($sPhpVer, $sMinPhpVer, '<'))
  523. echo '<b class="fail">FAIL</b> (your version is incompatible with Dolphin, must be at least ' . $sMinPhpVer . ')';
  524. elseif (version_compare($sPhpVer, '5.4.0', '>=') && version_compare($sPhpVer, '6.0.0', '<') && !version_compare($sPhpVer, $sLatestPhpVersion, '>='))
  525. echo '<b class="warn">WARNING</b> (your PHP version is probably outdated, upgrade to the latest ' . $sLatestPhpVersion . ' maybe required)';
  526. elseif (version_compare($sPhpVer, '5.2.0', '>=') && version_compare($sPhpVer, '5.4.0', '<') && !version_compare($sPhpVer, $sLatestPhp53Version, '>='))
  527. echo '<b class="warn">WARNING</b> (your PHP version is probably outdated, upgrade to the latest ' . $sLatestPhp53Version . ' maybe required)';
  528. else
  529. echo '<b class="ok">OK</b>';
  530. ?>
  531. <ul>
  532. <?php
  533. foreach ($aPhpSettings as $sName => $r) {
  534. $a = $this->checkPhpSetting($sName, $r);
  535. echo "<li>$sName = " . $this->format_output($a['real_val'], $r) ." - ";
  536. if ($a['res'])
  537. echo '<b class="ok">OK</b>';
  538. elseif ($r['warn'])
  539. echo "<b class='warn'>WARNING</b> (should be {$r['op']} " . $this->format_output($r['val'], $r) . ")";
  540. else
  541. echo "<b class='fail'>FAIL</b> (must be {$r['op']} " . $this->format_output($r['val'], $r) . ")";
  542. echo "</li>\n";
  543. }
  544. ?>
  545. </ul>
  546. </li>
  547. <li><b>MySQL</b>:
  548. <?php
  549. $sMysqlVer = mysql_get_server_info($GLOBALS['bx_db_link']);
  550. echo $sMysqlVer . ' - ';
  551. if (preg_match ('/^(\d+)\.(\d+)\.(\d+)/', $sMysqlVer, $m)) {
  552. $sMysqlVer = "{$m[1]}.{$m[2]}.{$m[3]}";
  553. if (version_compare($sMysqlVer, $sMinMysqlVer, '<'))
  554. echo '<b class="fail">FAIL</b> (your version is incompatible with Dolphin, must be at least ' . $sMinMysqlVer . ')';
  555. else
  556. echo '<b class="ok">OK</b>';
  557. } else {
  558. echo '<b class="undef">UNDEFINED</b>';
  559. }
  560. ?>
  561. </li>
  562. <li><b>Web-server</b>:
  563. <?php
  564. echo $_SERVER['SERVER_SOFTWARE'];
  565. ?>
  566. <ul>
  567. <?php
  568. foreach ($aRequiredApacheModules as $sName => $sNameCompiledName)
  569. echo '<li>' . $sName . ' - ' . $this->checkApacheModule($sName, $sNameCompiledName) . '</li>';
  570. ?>
  571. </ul>
  572. </li>
  573. <li><b>OS</b>:
  574. <?php
  575. echo php_uname();
  576. ?>
  577. </li>
  578. </ul>
  579. <h2>Hardware requirements</h2>
  580. <p>
  581. Hardware requirements can not be determined automatically - <a href="#manual_audit">manual server audit</a> may be reqired.
  582. </p>
  583. <h2>Site setup</h2>
  584. <ul>
  585. <li>
  586. <b>Dolphin version</b> =
  587. <?php
  588. $sDolphinVer = BX_DOL_VERSION . '.' . BX_DOL_BUILD;
  589. echo $sDolphinVer . ' - ';
  590. if (!version_compare($sDolphinVer, $sLatestDolphinVer, '>='))
  591. echo '<b class="warn">WARNING</b> (your Dolphin version is outdated please upgrade to the latest ' . $sLatestDolphinVer . ' version)';
  592. else
  593. echo '<b class="ok">OK</b>';
  594. ?>
  595. </li>
  596. <li>
  597. <b>files and folders permissions</b>
  598. <br />
  599. Please <a href="javascript:void(0);" onclick="switchAdmPage($('#main_menu1'));">click here</a> to find out if dolphin permissions are correct.
  600. </li>
  601. <li>
  602. <b>ffmpeg</b>
  603. <pre class="code"><?php echo `{$sDolphinPath}flash/modules/global/app/ffmpeg.exe 2>&1`;?></pre>
  604. if you don't know if output is correct then <a href="#manual_audit">manual server audit</a> may be reqired.
  605. </li>
  606. <li>
  607. <script language="javascript">
  608. function bx_sys_adm_audit_test_email()
  609. {
  610. $('#bx-sys-adm-audit-test-email').html('Sending...');
  611. $.post('<?php echo BX_DOL_URL_STUDIO; ?>host_tools.php?action=audit_send_test_email', function(data) {
  612. $('#bx-sys-adm-audit-test-email').html(data);
  613. });
  614. }
  615. </script>
  616. <b>mail sending - </b>
  617. <span id="bx-sys-adm-audit-test-email"><a href="javascript:void(0);" onclick="bx_sys_adm_audit_test_email()">click here</a> to send test email to <?php echo $sEmailToCkeckMailSending; ?></span>
  618. </li>
  619. <li>
  620. <b>cronjobs</b>
  621. <pre class="code"><?php echo `crontab -l 2>&1`;?></pre>
  622. if you are unsure if output is correct then <a href="#manual_audit">manual server audit</a> may be reqired.
  623. </li>
  624. </ul>
  625. <h2>Site optimization</h2>
  626. <ul>
  627. <li><b>PHP</b>:
  628. <ul>
  629. <li><b>PHP accelerator</b> =
  630. <?php
  631. $sAccel = $this->getPhpAccelerator();
  632. if (!$sAccel)
  633. echo 'NO - <b class="warn">WARNING</b> (Dolphin can be much faster if you install some PHP accelerator))';
  634. else
  635. echo $sAccel . ' - <b class="ok">OK</b>';
  636. ?>
  637. </li>
  638. <li><b>PHP setup</b> =
  639. <?php
  640. $sSapi = php_sapi_name();
  641. echo $sSapi . ' - ';
  642. if (0 == strcasecmp('cgi', $sSapi))
  643. echo '<b class="warn">WARNING</b> (your PHP setup maybe very inefficient, <a href="?action=phpinfo">please check it for sure</a> and try to switch to mod_php, apache dso module or FastCGI)';
  644. else
  645. echo '<b class="ok">OK</b>';
  646. ?>
  647. </li>
  648. </ul>
  649. </li>
  650. <li><b>MySQL</b>:
  651. <ul>
  652. <?php
  653. foreach ($aMysqlSettings as $sName => $r) {
  654. $a = $this->checkMysqlSetting($sName, $r, $l);
  655. echo "<li><b>$sName</b> = " . $this->format_output($a['real_val'], $r) ." - " . ($a['res'] ? '<b class="ok">OK</b>' : "<b class='fail'>FAIL</b> (must be {$r['op']} " . $this->format_output($r['val'], $r) . ")") . "</li>\n";
  656. }
  657. ?>
  658. </ul>
  659. </li>
  660. <li><b>Web-server</b>:
  661. <ul>
  662. <li>
  663. <b>User-side caching for static conten</b> =
  664. <a href="<?php echo $this->getUrlForGooglePageSpeed('LeverageBrowserCaching'); ?>">click here to check it in Google Page Speed</a>
  665. <br />
  666. If it is not enabled then please consider implement this optimization, since it improve perceived site speed and save the bandwidth, refer to <a target="_blank" href="http://www.boonex.com/trac/dolphin/wiki/HostingServerSetupRecommendations#Usersidecachingforstaticcontent">this tutorial</a> on how to do this.
  667. <br />
  668. <?php
  669. $sName = 'expires_module';
  670. echo 'To apply this optimization you need to have <b>' . $sName . '</b> Apache module - ' . $this->checkApacheModule($sName);
  671. ?>
  672. </li>
  673. <li>
  674. <b>Server-side content compression</b> = can be checked <a href="#manual_audit">manually</a> or in "Page Speed" tool build-in into browser.
  675. <br />
  676. If it is not enabled then please consider implement this optimization, since it improve perceived site speed and save the bandwidth, refer to <a href="http://www.boonex.com/trac/dolphin/wiki/HostingServerSetupRecommendations#Serversidecontentcompression">this tutorial</a> on how to do this.
  677. </textarea>
  678. <br />
  679. <?php
  680. $sName = 'deflate_module';
  681. echo 'To apply this optimization you need to have <b>' . $sName . '</b> Apache module - ' . $this->checkApacheModule($sName);
  682. ?>
  683. </li>
  684. </ul>
  685. </li>
  686. <li><b>Dolphin</b>:
  687. <ul>
  688. <?php
  689. foreach ($aDolphinOptimizationSettings as $sName => $a) {
  690. echo "<li><b>$sName</b> = ";
  691. echo ('always_on' == $a['enabled'] || getParam($a['enabled'])) ? 'On' : 'Off';
  692. if ($a['cache_engine'])
  693. echo " (" . getParam($a['cache_engine']) . ' based cache engine)';
  694. echo ' - ';
  695. if ('always_on' != $a['enabled'] && !getParam($a['enabled']))
  696. echo '<b class="fail">FAIL</b> (please enable this cache in Dolphin Admin Panel -> Settings -> Advanced Settings)';
  697. elseif ($a['check_accel'] && !$this->getPhpAccelerator() && 'File' == getParam($a['cache_engine']))
  698. echo '<b class="warn">WARNING</b> (installing PHP accelerator will speed-up file cache)';
  699. else
  700. echo '<b class="ok">OK</b>';
  701. echo "</li>\n";
  702. }
  703. ?>
  704. </ul>
  705. </li>
  706. </ul>
  707. <a name="manual_audit"></a>
  708. <h2>Manual Server Audit</h2>
  709. <p>
  710. Some things can not be determined automatically, manual server audit is required to check it. If you don't know how to do it by yourself you can submit <a target="_blank" href="http://www.boonex.com/help/tickets">BoonEx Server Audit Request</a>.
  711. </p>
  712. <?php
  713. return ob_get_clean();
  714. }
  715. function checkPhpSetting($sName, $a)
  716. {
  717. $mixedVal = ini_get($sName);
  718. $mixedVal = $this->format_input ($mixedVal, $a);
  719. switch ($a['op']) {
  720. case 'module':
  721. $bResult = extension_loaded($a['val']);
  722. $mixedVal = $bResult ? $a['val'] : '';
  723. break;
  724. case '>':
  725. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal > $a['val']);
  726. break;
  727. case '>=':
  728. $bResult = (isset($a['unlimited']) && $mixedVal == $a['unlimited']) ? true : ($mixedVal >= $a['val']);
  729. break;
  730. case '=':
  731. default:
  732. $bResult = ($mixedVal == $a['val']);
  733. }
  734. return array ('res' => $bResult, 'real_val' => $mixedVal);
  735. }
  736. function checkMysqlSetting($sName, $a, $l)
  737. {
  738. $mixedVal = $this->mysqlGetOption($sName, $l);
  739. $mixedVal = $this->format_input ($mixedVal, $a);
  740. switch ($a['op']) {
  741. case '>':
  742. $bResult = ($mixedVal > $a['val']);
  743. break;
  744. case '>=':
  745. $bResult = ($mixedVal >= $a['val']);
  746. break;
  747. case 'strcasecmp':
  748. $bResult = 0 == strcasecmp($mixedVal, $a['val']);
  749. break;
  750. case '=':
  751. default:
  752. $bResult = ($mixedVal == $a['val']);
  753. }
  754. return array ('res' => $bResult, 'real_val' => $mixedVal);
  755. }
  756. function format_output ($mixedVal, $a)
  757. {
  758. switch ($a['type']) {
  759. case 'bool':
  760. return $mixedVal ? 'On' : 'Off';
  761. default:
  762. return $mixedVal;
  763. }
  764. }
  765. function format_input ($mixedVal, $a)
  766. {
  767. switch ($a['type']) {
  768. case 'bytes':
  769. return $this->format_bytes ($mixedVal);
  770. default:
  771. return $mixedVal;
  772. }
  773. }
  774. function format_bytes($val)
  775. {
  776. return return_bytes($val);
  777. }
  778. function checkApacheModule ($sModule, $sNameCompiledName = '')
  779. {
  780. $a = array (
  781. 'deflate_module' => 'mod_deflate',
  782. 'expires_module' => 'mod_expires',
  783. );
  784. if (!$sNameCompiledName && isset($a[$sModule]))
  785. $sNameCompiledName = $a[$sModule];
  786. if (function_exists('apache_get_modules')) {
  787. $aModules = apache_get_modules();
  788. $ret = in_array($sNameCompiledName, $aModules);
  789. } else {
  790. $sApachectlPath = trim(`which apachectl`);
  791. if (!$sApachectlPath)
  792. $sApachectlPath = trim(`which apache2ctl`);
  793. if (!$sApachectlPath)
  794. $sApachectlPath = trim(`which /usr/local/apache/bin/apachectl`);
  795. if (!$sApachectlPath)
  796. $sApachectlPath = trim(`which /usr/local/apache/bin/apache2ctl`);
  797. if (!$sApachectlPath)
  798. return '<b class="undef">UNDEFINED</b> (try to check manually: apachectl -M 2>&1 | grep ' . $sModule . ')';
  799. $ret = (boolean)`$sApachectlPath -M 2>&1 | grep $sModule`;
  800. if (!$ret)
  801. $ret = (boolean)`$sApachectlPath -l 2>&1 | grep $sNameCompiledName`;
  802. }
  803. return $ret ? '<b class="ok">OK</b>' : '<b class="fail">FAIL</b> (You will need to install ' . $sModule . ' for Apache)';
  804. }
  805. function getPhpAccelerator ()
  806. {
  807. $aAccelerators = array (
  808. 'eAccelerator' => array('op' => 'module', 'val' => 'eaccelerator'),
  809. 'APC' => array('op' => 'module', 'val' => 'apc'),
  810. 'XCache' => array('op' => 'module', 'val' => 'xcache'),
  811. );
  812. foreach ($aAccelerators as $sName => $r) {
  813. $a = $this->checkPhpSetting($sName, $r);
  814. if ($a['res'])
  815. return $sName;
  816. }
  817. return false;
  818. }
  819. function mysqlGetOption ($s, $l)
  820. {
  821. return db_value("SELECT @@{$s}", $l);
  822. }
  823. function getUrlForGooglePageSpeed ($sRule)
  824. {
  825. $sUrl = urlencode(BX_DOL_URL_ROOT);
  826. return 'http://pagespeed.googlelabs.com/#url=' . $sUrl . '&mobile=false&rule=' . $sRule;
  827. }
  828. function sendTestEmail ()
  829. {
  830. $sEmailToCkeckMailSending = getParam('site_email');
  831. $mixedRet = sendMail($sEmailToCkeckMailSending, 'Audit Test Email', 'Sample text for testing<br /><u><b>Sample text for testing</b></u>', '', array(), BX_EMAIL_SYSTEM);
  832. if (!$mixedRet)
  833. return '<b class="fail">FAIL</b> (mail send failed)';
  834. else
  835. return 'test mail was send, please check ' . $sEmailToCkeckMailSending . ' mailbox';
  836. }
  837. }
  838. /** @} */