BxDolStudioTools.php 8.8 KB

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