BxDolStudioTools.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 BxDolStudioTools extends BxDolIO
  12. {
  13. protected $sTroubledElements;
  14. public $aInstallDirs;
  15. public $aInstallFiles;
  16. public $aPostInstallPermDirs;
  17. public $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. if (!class_exists('BxDolStudioToolsAudit'))
  446. bx_import('BxDolStudioToolsAudit');
  447. $oAudit = new BxDolStudioToolsAudit();
  448. return $oAudit->generate();
  449. }
  450. }
  451. /** @} */