BxDolStudioTools.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. bx_import('BxDolIO');
  10. define('BX_DOL_PERM_FILE', 'file');
  11. define('BX_DOL_PERM_DIR', 'dir');
  12. define('BX_DOL_PERM_EXE', 'exe');
  13. define('BX_DOL_PERM_FAIL', false);
  14. define('BX_DOL_PERM_OK', true);
  15. class BxDolStudioTools extends BxDolIO
  16. {
  17. protected $bInstallScript;
  18. protected $sRootPath;
  19. public $aInstallPermissions;
  20. public $aPostInstallPermissions;
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->aInstallPermissions = array(
  25. 'inc',
  26. 'cache',
  27. 'cache_public',
  28. 'logs',
  29. 'tmp',
  30. 'storage',
  31. );
  32. $this->aPostInstallPermissions = array(
  33. );
  34. if (defined('BX_DOL_INSTALL') && BX_DOL_INSTALL) {
  35. $this->bInstallScript = true;
  36. $this->sRootPath = BX_INSTALL_URL_ROOT;
  37. } else {
  38. $this->bInstallScript = false;
  39. $this->sRootPath = BX_DOL_URL_ROOT;
  40. }
  41. }
  42. public function generateStyles()
  43. {
  44. $sRet = <<<EOF
  45. <style type="text/css">
  46. .hidden {
  47. display:none;
  48. }
  49. .bx-permissions-table {
  50. border-collapse:collapse;
  51. }
  52. .bx-permissions-table thead td {
  53. font-weight:bold;
  54. }
  55. .bx-permissions-table td:not(:first-child) {
  56. text-align:center;
  57. }
  58. .bx-permissions-wrong {
  59. color:red;
  60. font-weight:bold;
  61. }
  62. .bx-permissions-ok {
  63. color:green;
  64. font-weight:bold;
  65. }
  66. </style>
  67. EOF;
  68. return $sRet;
  69. }
  70. public function checkPermissions($isShowModules = false, $bEcho = true, &$aOutputMessages = null)
  71. {
  72. $bRet = true;
  73. $aMessages = array ();
  74. foreach ($this->aInstallPermissions as $s) {
  75. $sType = $this->_getFileType($s);
  76. $isOk = BX_DOL_PERM_EXE == $sType ? $this->isExecutable($s) : $this->isWritable($s);
  77. $aMessages[$s] = array ('res' => $isOk ? BX_DOL_PERM_OK : BX_DOL_PERM_FAIL, 'type' => $sType);
  78. if (!$isOk && $bRet)
  79. $bRet = false;
  80. }
  81. if ($isShowModules && !$this->_checkPermissionsModules($aMessages) && $bRet)
  82. $bRet = false;
  83. if (null !== $aOutputMessages)
  84. $aOutputMessages = $aMessages;
  85. if ($bEcho) {
  86. $sHtml = '';
  87. foreach ($aMessages as $s => $r)
  88. $sHtml .= $this->_getHtmlPermissionRow($s, $r);
  89. echo $this->_getHtmlPermissionTable($sHtml);
  90. }
  91. return $bRet;
  92. }
  93. function GenCacheEnginesTable()
  94. {
  95. $sRet = '<table width="100%" cellspacing="1" cellpadding="0" class="install_table">';
  96. $sRet .= '
  97. <tr class="head troubled">
  98. <td></td>
  99. <td class="center_aligned">' . _t('_sys_adm_installed') . '</td>
  100. <td class="center_aligned">' . _t('_sys_adm_cache_support') . '</td>
  101. </tr>';
  102. $aEngines = array ('File', 'Memcache', 'APC', 'XCache');
  103. foreach ($aEngines as $sEngine) {
  104. $oCacheObject = @bx_instance ('BxDolCache' . $sEngine);
  105. $sRet .= '
  106. <tr class="head troubled">
  107. <td class="left_aligned">' . $sEngine . '</td>
  108. <td class="center_aligned">' . (@$oCacheObject->isInstalled() ? '<font color="green">' . _t('_Yes') . '</font>' : '<font color="red">' . _t('_No') . '</font>') . '</td>
  109. <td class="center_aligned">' . (@$oCacheObject->isAvailable() ? '<font color="green">' . _t('_Yes') . '</font>' : '<font color="red">' . _t('_No') . '</font>') . '</td>
  110. </tr>';
  111. }
  112. $sRet .= '</table>';
  113. return $sRet;
  114. }
  115. function GenTabbedPage($isShowModules = false)
  116. {
  117. $sTitleC = _t('_adm_admtools_title');
  118. $sAuditC = _t('');
  119. $sPermissionsC = _t('');
  120. $sCacheEnginesC = _t('');
  121. $sAuditTab = $this->GenAuditPage();
  122. $sPermissionsTab = $this->GenPermTable($isShowModules);
  123. $sCacheEnginesTab = $this->GenCacheEnginesTable();
  124. $sBoxContent = <<<EOF
  125. <script type="text/javascript">
  126. <!--
  127. function switchAdmPage(oLink)
  128. {
  129. var sType = $(oLink).attr('id').replace('main_menu', '');
  130. var sName = '#page' + sType;
  131. $(oLink).parent('.notActive').hide().siblings('.notActive:hidden').show().siblings('.active').hide().siblings('#' + $(oLink).attr('id') + '-act').show();
  132. $(sName).siblings('div:visible').bx_anim('hide', 'fade', 'slow', function(){
  133. $(sName).bx_anim('show', 'fade', 'slow');
  134. });
  135. return false;
  136. }
  137. -->
  138. </script>
  139. <div class="boxContent" id="adm_pages">
  140. <div id="page0" class="visible">{$sAuditTab}</div>
  141. <div id="page1" class="hidden">{$sPermissionsTab}</div>
  142. <div id="page2" class="hidden">
  143. <iframe frameborder="0" width="100%" height="800" scrolling="auto" src="host_tools.php?get_phpinfo=true"></iframe>
  144. </div>
  145. <div id="page3" class="hidden">{$sCacheEnginesTab}</div>
  146. </div>
  147. EOF;
  148. $aTopItems = array(
  149. 'main_menu0' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_admtools_Audit'), 'active' => 1),
  150. 'main_menu1' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_admtools_Permissions'), 'active' => 0),
  151. 'main_menu2' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:switchAdmPage(this)', 'title' => _t('_adm_admtools_phpinfo'), 'active' => 0),
  152. );
  153. return DesignBoxAdmin($sTitleC, $sBoxContent, $aTopItems, '', 11);
  154. }
  155. function GenAuditPage()
  156. {
  157. if (!class_exists('BxDolStudioToolsAudit'))
  158. bx_import('BxDolStudioToolsAudit');
  159. $oAudit = new BxDolStudioToolsAudit();
  160. return $oAudit->generate();
  161. }
  162. protected function _getHtmlPermissionRow($s, $r)
  163. {
  164. $sAwaitedPerm = BX_DOL_PERM_EXE == $r['type'] ? _t('_adm_admtools_Executable') : _t('_adm_admtools_Writable');
  165. $sResultPerm = $sAwaitedPerm;
  166. $sPerm = $this->getPermissions($s);
  167. $sClass = 'bx-permissions-ok';
  168. if (BX_DOL_PERM_FAIL == $r['res']) {
  169. $sClass = 'bx-permissions-wrong';
  170. if (false === $sPerm)
  171. $sResultPerm = _t('_adm_admtools_Not_Exists');
  172. else
  173. $sResultPerm = BX_DOL_PERM_EXE == $r['type'] ? _t('_adm_admtools_Non_Executable') : _t('_adm_admtools_Non_Writable');
  174. }
  175. return <<<EOF
  176. <tr class="bx-def-color-bg-hl-even">
  177. <td class="bx-def-padding-thd">{$s}</td>
  178. <td class="bx-def-padding-thd {$sClass}">{$sResultPerm}</td>
  179. <td class="bx-def-padding-thd">{$sAwaitedPerm}</td>
  180. </tr>
  181. EOF;
  182. }
  183. protected function _getHtmlPermissionTable($sRows)
  184. {
  185. $sDirsC = _t('_adm_admtools_Path');
  186. $sCurrentLevelC = _t('_adm_admtools_Current_level');
  187. $sDesiredLevelC = _t('_adm_admtools_Desired_level');
  188. return <<<EOF
  189. <table width="100%" class="bx-permissions-table">
  190. <thead class="bx-def-border-bottom bx-def-border-top">
  191. <tr>
  192. <td class="bx-def-padding-thd bx-def-font-h3">{$sDirsC}</td>
  193. <td class="bx-def-padding-thd bx-def-font-h3">{$sCurrentLevelC}</td>
  194. <td class="bx-def-padding-thd bx-def-font-h3">{$sDesiredLevelC}</td>
  195. </tr>
  196. </thead>
  197. <tbody>
  198. {$sRows}
  199. </tbody>
  200. </table>
  201. EOF;
  202. }
  203. protected function _getFileType($s)
  204. {
  205. $sType = BX_DOL_PERM_FILE;
  206. if (is_dir($this->sRootPath . $s))
  207. $sType = BX_DOL_PERM_DIR;
  208. elseif (substr($s, -4) === '.exe')
  209. $sType = BX_DOL_PERM_EXE;
  210. return $sType;
  211. }
  212. protected function _checkPermissionsModules(&$aMessages)
  213. {
  214. $bRet = true;
  215. bx_import('BxDolModuleDb');
  216. $oDbModules = new BxDolModuleDb();
  217. $aModules = $oDbModules->getModules();
  218. foreach ($aModules as $a) {
  219. if (empty($a['path']) || !include(BX_DIRECTORY_PATH_MODULES . $a['path'] . 'install/config.php'))
  220. continue;
  221. if (empty($aConfig['install_permissions']) || !is_array($aConfig['install_permissions']['writable']))
  222. continue;
  223. foreach ($aConfig['install_permissions']['writable'] as $sPath) {
  224. $s = basename(BX_DIRECTORY_PATH_MODULES) . '/' . $a['path'] . $sPath;
  225. $sType = $this->_getFileType($s);
  226. $isOk = BX_DOL_PERM_EXE ? $this->isExecutable($s) : $this->isWritable($s);
  227. $aMessages[$s] = array ('res' => $isOk ? BX_DOL_PERM_OK : BX_DOL_PERM_FAIL, 'type' => $sType);
  228. if (!$isOk && $bRet)
  229. $bRet = false;
  230. }
  231. }
  232. return $bRet;
  233. }
  234. }
  235. /** @} */