PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/gui/public/admin/domain_details.php

https://bitbucket.org/droidzone/i-mscp
PHP | 230 lines | 140 code | 32 blank | 58 comment | 25 complexity | 4b60a30ddf6098f63605915dc28a307f MD5 | raw file
  1. <?php
  2. /**
  3. * i-MSCP - internet Multi Server Control Panel
  4. *
  5. * The contents of this file are subject to the Mozilla Public License
  6. * Version 1.1 (the "License"); you may not use this file except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS"
  11. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  12. * License for the specific language governing rights and limitations
  13. * under the License.
  14. *
  15. * The Original Code is "VHCS - Virtual Hosting Control System".
  16. *
  17. * The Initial Developer of the Original Code is moleSoftware GmbH.
  18. * Portions created by Initial Developer are Copyright (C) 2001-2006
  19. * by moleSoftware GmbH. All Rights Reserved.
  20. *
  21. * Portions created by the ispCP Team are Copyright (C) 2006-2010 by
  22. * isp Control Panel. All Rights Reserved.
  23. *
  24. * Portions created by the i-MSCP Team are Copyright (C) 2010-2013 by
  25. * i-MSCP - internet Multi Server Control Panel. All Rights Reserved.
  26. *
  27. * @category i-MSCP
  28. * @package iMSCP_Core
  29. * @subpackage Admin
  30. * @copyright 2001-2006 by moleSoftware GmbH
  31. * @copyright 2006-2010 by ispCP | http://isp-control.net
  32. * @copyright 2010-2013 by i-MSCP | http://i-mscp.net
  33. * @author ispCP Team
  34. * @author i-MSCP Team
  35. * @link http://i-mscp.net
  36. */
  37. /*****************************************************************
  38. * Script functions
  39. */
  40. /**
  41. * Generates page
  42. *
  43. * @param iMSCP_pTemplate $tpl Template instance engine
  44. * @param int $domainId Domain unique identifier
  45. * @return void
  46. */
  47. function admin_generatePage($tpl, $domainId)
  48. {
  49. $domainId = (int)$domainId;
  50. $query = "SELECT `domain_admin_id` FROM `domain` WHERE `domain_id` = ?";
  51. $stmt = exec_query($query, $domainId);
  52. if (!$stmt->rowCount()) {
  53. set_page_message(tr('Domain not found.'));
  54. redirectTo('manage_users.php');
  55. }
  56. $domainProperties = get_domain_default_props($stmt->fields['domain_admin_id']);
  57. /** @var $cfg iMSCP_Config_Handler_File */
  58. $cfg = iMSCP_Registry::get('config');
  59. // Domain IP address info
  60. $stmt = exec_query(
  61. "SELECT `ip_number`, `ip_domain` FROM `server_ips` WHERE `ip_id` = ?", $domainProperties['domain_ip_id']
  62. );
  63. if (!$stmt->rowCount()) {
  64. $domainIpAddr = tr('No found.');
  65. } else {
  66. $domainIpAddr = "{$stmt->fields['ip_number']} " . (($stmt->fields['ip_domain']) ? "({$stmt->fields['ip_domain']})" : '');
  67. }
  68. $domainStatus = $domainProperties['domain_status'];
  69. // Domain status
  70. if (
  71. $domainStatus == $cfg->ITEM_OK_STATUS || $domainStatus == $cfg->ITEM_DISABLED_STATUS ||
  72. $domainStatus == $cfg->ITEM_DELETE_STATUS || $domainStatus == $cfg->ITEM_ADD_STATUS ||
  73. $domainStatus == $cfg->ITEM_RESTORE_STATUS || $domainStatus == $cfg->ITEM_CHANGE_STATUS ||
  74. $domainStatus == $cfg->ITEM_TOENABLE_STATUS || $domainStatus == $cfg->ITEM_TODISABLED_STATUS ||
  75. $domainStatus == $cfg->ITEM_DNSCHANGE_STATUS
  76. ) {
  77. $domainStatus = '<span style="color:green">' . tohtml(translate_dmn_status($domainStatus)) . '</span>';
  78. } else {
  79. $domainStatus = '<b><font size="3" color="red">' . $domainStatus . "</font></b>";
  80. }
  81. // Get total domain traffic usage in bytes
  82. $query = "
  83. SELECT
  84. IFNULL(SUM(`dtraff_web`), 0) `dtraff_web`, IFNULL(SUM(`dtraff_ftp`), 0) `dtraff_ftp`,
  85. IFNULL(SUM(`dtraff_mail`), 0) `dtraff_mail`, IFNULL(SUM(`dtraff_pop`), 0) `dtraff_pop`
  86. FROM
  87. `domain_traffic`
  88. WHERE
  89. `domain_id` = ?
  90. AND
  91. `dtraff_time` > ?
  92. AND
  93. `dtraff_time` < ?
  94. ";
  95. $stmt = exec_query($query, array($domainProperties['domain_id'], getFirstDayOfMonth(), getLastDayOfMonth()));
  96. if($stmt->rowCount()) {
  97. $trafficUsageBytes = $stmt->fields['dtraff_web'] + $stmt->fields['dtraff_ftp'] + $stmt->fields['dtraff_mail'] +
  98. $stmt->fields['dtraff_pop'];
  99. } else {
  100. $trafficUsageBytes = 0;
  101. }
  102. // Get limits in bytes
  103. $trafficLimitBytes = $domainProperties['domain_traffic_limit'] * 1048576;
  104. $diskspaceLimitBytes = $domainProperties['domain_disk_limit'] * 1048576;
  105. // Get usages in percent
  106. $trafficUsagePercent = make_usage_vals($trafficUsageBytes, $trafficLimitBytes);
  107. $diskspaceUsagePercent = make_usage_vals($domainProperties['domain_disk_usage'], $diskspaceLimitBytes);
  108. # Features
  109. $trEnabled = '<span style="color:green">' . tr('Enabled') . '</span>';
  110. $trDisabled = '<span style="color:red">' . tr('Disabled') . '</span>';
  111. $tpl->assign(
  112. array(
  113. 'DOMAIN_ID' => $domainId,
  114. 'VL_DOMAIN_NAME' => tohtml(decode_idna($domainProperties['domain_name'])),
  115. 'VL_DOMAIN_IP' => tohtml($domainIpAddr),
  116. 'VL_STATUS' => $domainStatus,
  117. 'VL_PHP_SUPP' => ($domainProperties['domain_php'] == 'yes') ? $trEnabled : $trDisabled,
  118. 'VL_CGI_SUPP' => ($domainProperties['domain_cgi'] == 'yes') ? $trEnabled : $trDisabled,
  119. 'VL_DNS_SUPP' => ($domainProperties['domain_dns'] == 'yes') ? $trEnabled : $trDisabled,
  120. 'VL_MYSQL_SUPP' => ($domainProperties['domain_sqld_limit'] >= 0) ? $trEnabled : $trDisabled,
  121. 'VL_SOFTWARE_SUPP' => ($domainProperties['domain_software_allowed'] == 'yes') ? $trEnabled : $trDisabled,
  122. 'VL_TRAFFIC_PERCENT' => $trafficUsagePercent,
  123. 'VL_TRAFFIC_USED' => bytesHuman($trafficUsageBytes),
  124. 'VL_TRAFFIC_LIMIT' => bytesHuman($trafficLimitBytes),
  125. 'VL_DISK_PERCENT' => $diskspaceUsagePercent,
  126. 'VL_DISK_USED' => bytesHuman($domainProperties['domain_disk_usage']),
  127. 'VL_DISK_LIMIT' => bytesHuman($diskspaceLimitBytes),
  128. 'VL_MAIL_ACCOUNTS_USED' => get_domain_running_mail_acc_cnt($domainId),
  129. 'VL_MAIL_ACCOUNTS_LIIT' => translate_limit_value($domainProperties['domain_mailacc_limit']),
  130. 'VL_FTP_ACCOUNTS_USED' => get_domain_running_ftp_acc_cnt($domainId),
  131. 'VL_FTP_ACCOUNTS_LIIT' => translate_limit_value($domainProperties['domain_ftpacc_limit']),
  132. 'VL_SQL_DB_ACCOUNTS_USED' => get_domain_running_sqld_acc_cnt($domainId),
  133. 'VL_SQL_DB_ACCOUNTS_LIIT' => translate_limit_value($domainProperties['domain_sqld_limit']),
  134. 'VL_SQL_USER_ACCOUNTS_USED' => get_domain_running_sqlu_acc_cnt($domainId),
  135. 'VL_SQL_USER_ACCOUNTS_LIIT' => translate_limit_value($domainProperties['domain_sqlu_limit']),
  136. 'VL_SUBDOM_ACCOUNTS_USED' => get_domain_running_sub_cnt($domainId),
  137. 'VL_SUBDOM_ACCOUNTS_LIIT' => translate_limit_value($domainProperties['domain_subd_limit']),
  138. 'VL_DOMALIAS_ACCOUNTS_USED' => get_domain_running_als_cnt($domainId),
  139. 'VL_DOMALIAS_ACCOUNTS_LIIT' => translate_limit_value($domainProperties['domain_alias_limit']),
  140. )
  141. );
  142. }
  143. /*******************************************************************************
  144. * Main script
  145. */
  146. // Include core library
  147. require 'imscp-lib.php';
  148. iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onAdminScriptStart);
  149. check_login('admin');
  150. // Get user id that comes for manage domain
  151. if (!isset($_GET['domain_id'])) {
  152. redirectTo('manage_users.php');
  153. }
  154. /** @var $cfg iMSCP_Config_Handler_File */
  155. $cfg = iMSCP_Registry::get('config');
  156. $tpl = new iMSCP_pTemplate();
  157. $tpl->define_dynamic(
  158. array(
  159. 'layout' => 'shared/layouts/ui.tpl',
  160. 'page' => 'admin/domain_details.tpl',
  161. 'page_messages' => 'layout',
  162. )
  163. );
  164. $tpl->assign(
  165. array(
  166. 'TR_PAGE_TITLE' => tr('i-MSCP - Admin / Users management / Domain Details'),
  167. 'THEME_CHARSET' => tr('encoding'),
  168. 'ISP_LOGO' => layout_getUserLogo(),
  169. 'TR_DOMAIN_DETAILS' => tr('Domain details'),
  170. 'TR_DOMAIN_NAME' => tr('Domain name'),
  171. 'TR_DOMAIN_IP' => tr('Domain IP'),
  172. 'TR_STATUS' => tr('Status'),
  173. 'TR_PHP_SUPP' => tr('PHP support'),
  174. 'TR_CGI_SUPP' => tr('CGI support'),
  175. 'TR_DNS_SUPP' => tr('Custom DNS records'),
  176. 'TR_BACKUP_SUPPORT' => tr('Backup support'),
  177. 'TR_MYSQL_SUPP' => tr('MySQL support'),
  178. 'TR_TRAFFIC' => tr('Traffic'),
  179. 'TR_DISK' => tr('Disk'),
  180. 'TR_FEATURE' => tr('Feature'),
  181. 'TR_USED' => tr('Used'),
  182. 'TR_LIMIT' => tr('Limit'),
  183. 'TR_MAIL_ACCOUNTS' => tr('Mail accounts'),
  184. 'TR_FTP_ACCOUNTS' => tr('FTP accounts'),
  185. 'TR_SQL_DB_ACCOUNTS' => tr('SQL databases'),
  186. 'TR_SQL_USER_ACCOUNTS' => tr('SQL users'),
  187. 'TR_SUBDOM_ACCOUNTS' => tr('Subdomains'),
  188. 'TR_DOMALIAS_ACCOUNTS' => tr('Domain aliases'),
  189. 'TR_UPDATE_DATA' => tr('Submit changes'),
  190. 'TR_SOFTWARE_SUPP' => tr('Software installer'),
  191. 'TR_BACK' => tr('Back')));
  192. generateNavigation($tpl);
  193. admin_generatePage($tpl, intval($_GET['domain_id']));
  194. generatePageMessage($tpl);
  195. $tpl->parse('LAYOUT_CONTENT', 'page');
  196. iMSCP_Events_Manager::getInstance()->dispatch(iMSCP_Events::onAdminScriptEnd, array('templateEngine' => $tpl));
  197. $tpl->prnt();
  198. unsetMessages();