BxDolStudioTools.php 9.0 KB

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