BxDolStudioDashboard.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. class BxDolStudioDashboard extends BxTemplStudioPage
  10. {
  11. protected $aBlocks;
  12. protected $aItemsCache;
  13. protected $aItemsHTools;
  14. function __construct()
  15. {
  16. parent::__construct('dashboard');
  17. $this->oDb = new BxDolStudioDashboardQuery();
  18. $this->aBlocks = array(
  19. 'space' => 'serviceGetBlockSpace',
  20. 'htools' => 'serviceGetBlockHostTools',
  21. );
  22. $this->aItemsCache = array (
  23. array('name' => 'all'),
  24. array('name' => 'db'),
  25. array('name' => 'template'),
  26. array('name' => 'css'),
  27. array('name' => 'js')
  28. );
  29. $this->aItemsHTools = array (
  30. 'PHP' => 'requirementsPHP',
  31. 'MySQL' => 'requirementsMySQL',
  32. 'Web Server' => 'requirementsWebServer',
  33. );
  34. //--- Check actions ---//
  35. if(($sAction = bx_get('dbd_action')) !== false) {
  36. $sAction = bx_process_input($sAction);
  37. $aResult = array('code' => 1, 'message' => _t('_adm_err_cannot_process_action'));
  38. switch($sAction) {
  39. case 'get_block':
  40. $sValue = bx_get('dbd_value');
  41. if($sValue === false)
  42. break;
  43. $sValue = bx_process_input($sValue);
  44. if(!isset($this->aBlocks[$sValue]))
  45. break;
  46. $aBlock = $this->{$this->aBlocks[$sValue]}(false);
  47. if(!empty($aBlock['content']))
  48. $aResult = array('code' => 0, 'data' => $aBlock['content']);
  49. break;
  50. case 'check_for_upgrade':
  51. $aResult = array('code' => 0, 'data' => $this->getPageCodeVersionAvailable());
  52. break;
  53. case 'perform_upgrade':
  54. $oUpgrader = bx_instance('BxDolUpgrader');
  55. if(!$oUpgrader->prepare())
  56. $aResult = array('code' => 1, 'message' => $oUpgrader->getError());
  57. else
  58. $aResult = array('code' => 0, 'message' => _t('_adm_dbd_msg_upgrade_started'));
  59. break;
  60. case 'clear_cache':
  61. $sValue = bx_get('dbd_value');
  62. if($sValue === false)
  63. break;
  64. $sValue = bx_process_input($sValue);
  65. $oCacheUtilities = BxDolCacheUtilities::getInstance();
  66. switch ($sValue) {
  67. case 'all':
  68. $aResult = false;
  69. foreach($this->aItemsCache as $aItem) {
  70. if($aItem['name'] == 'all')
  71. continue;
  72. $aResultClear = $oCacheUtilities->clear($aItem['name']);
  73. if($aResultClear === false)
  74. continue;
  75. $aResult = $aResultClear;
  76. if(isset($aResult['code']) && $aResult['code'] != 0)
  77. break;
  78. }
  79. break;
  80. case 'db':
  81. case 'template':
  82. case 'css':
  83. case 'js':
  84. $aResult = $oCacheUtilities->clear($sValue);
  85. break;
  86. default:
  87. $aResult = array('code' => 1, 'message' => _t('_Error Occured'));
  88. }
  89. if($aResult === false)
  90. $aResult['data'] = MsgBox(_t('_adm_dbd_msg_c_all_disabled'));
  91. else if(isset($aResult['code']) && $aResult['code'] == 0)
  92. $aResult['data'] = $this->getCacheChartData(false);
  93. break;
  94. case 'permissions':
  95. $oAdmTools = new BxDolStudioTools();
  96. header( 'Content-type: text/html; charset=utf-8' );
  97. echo $oAdmTools->generateStyles();
  98. $oAdmTools->checkPermissions();
  99. exit;
  100. case 'server_audit':
  101. $oAudit = new BxDolStudioToolsAudit();
  102. header( 'Content-type: text/html; charset=utf-8' );
  103. echo $oAudit->generate();
  104. exit;
  105. }
  106. if(!empty($aResult['message'])) {
  107. $aResult['message'] = BxDolStudioTemplate::getInstance()->parseHtmlByName('page_action_result.html', array('content' => $aResult['message']));
  108. $aResult['message'] = BxTemplStudioFunctions::getInstance()->transBox('', $aResult['message']);
  109. }
  110. echo json_encode($aResult);
  111. exit;
  112. }
  113. }
  114. protected function getDbSize()
  115. {
  116. $iTotalSize = 0;
  117. $oDb = BxDolDb::getInstance();
  118. $aTables = $oDb->getAll('SHOW TABLE STATUS');
  119. foreach($aTables as $aTable)
  120. $iTotalSize += $aTable['Data_length'] + $aTable['Index_length'];
  121. return $iTotalSize;
  122. }
  123. protected function getFolderSize($sPath)
  124. {
  125. $iTotalSize = 0;
  126. $aFiles = scandir($sPath);
  127. $sPath = rtrim($sPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
  128. foreach($aFiles as $sFile) {
  129. if(is_dir($sPath . $sFile))
  130. if($sFile != '.' && $sFile != '..')
  131. $iTotalSize += $this->getFolderSize($sPath . $sFile);
  132. else
  133. $iTotalSize += filesize($sPath . $sFile);
  134. }
  135. return $iTotalSize;
  136. }
  137. protected function getCacheChartData($bAsString = true)
  138. {
  139. $oCacheUtilities = BxDolCacheUtilities::getInstance();
  140. $aChartData = array();
  141. foreach($this->aItemsCache as $aItem) {
  142. if($aItem['name'] == 'all')
  143. continue;
  144. $iSize = $oCacheUtilities->size($aItem['name']);
  145. if($iSize === false)
  146. continue;
  147. $aChartData[] = array(bx_js_string(_t('_adm_dbd_txt_c_' . $aItem['name']), BX_ESCAPE_STR_APOS), array('v' => $iSize, 'f' => bx_js_string(_t_format_size($iSize))));
  148. }
  149. if(empty($aChartData))
  150. return false;
  151. return $bAsString ? json_encode($aChartData) : $aChartData;
  152. }
  153. }
  154. /** @} */