From e8b3291ecd0c5278b9ddc274769a3809e92f5c16 Mon Sep 17 00:00:00 2001 From: Dominik Mueller <info@profi-webdesign.net> Date: Wed, 26 Feb 2014 18:05:31 -0500 Subject: [PATCH] Quota-Lib für remote-quota-angaben Erweiterungen für remote-Quota --- interface/lib/classes/remoting.inc.php | 33 +++++ interface/web/dashboard/dashlets/quota.php | 84 ------------- interface/web/client/lib/remote.conf.php | 1 interface/web/dashboard/dashlets/mailquota.php | 61 --------- interface/lib/classes/quota_lib.inc.php | 160 ++++++++++++++++++++++++++ 5 files changed, 203 insertions(+), 136 deletions(-) diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php new file mode 100644 index 0000000..a811132 --- /dev/null +++ b/interface/lib/classes/quota_lib.inc.php @@ -0,0 +1,160 @@ +<?php + +class quota_lib { + public function get_quota_data(groupid = null, $readable = true) { + global $app; + + $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); + $monitor_data = array(); + if(is_array($tmp_rec)) { + foreach ($tmp_rec as $tmp_mon) { + $monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data']))); + } + } + //print_r($monitor_data); + + if($groupid != null){ + $sql_where = " AND sys_groupid = ".$groupid); + } + + // select websites belonging to client + $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".$sql_where); + //print_r($sites); + if(is_array($sites) && !empty($sites)){ + for($i=0;$i<sizeof($sites);$i++){ + $username = $sites[$i]['system_user']; + $sites[$i]['used'] = $monitor_data['user'][$username]['used']; + $sites[$i]['soft'] = $monitor_data['user'][$username]['soft']; + $sites[$i]['hard'] = $monitor_data['user'][$username]['hard']; + $sites[$i]['files'] = $monitor_data['user'][$username]['files']; + + if (!is_numeric($sites[$i]['used'])){ + if ($sites[$i]['used'][0] > $sites[$i]['used'][1]){ + $sites[$i]['used'] = $sites[$i]['used'][0]; + } else { + $sites[$i]['used'] = $sites[$i]['used'][1]; + } + } + if (!is_numeric($sites[$i]['soft'])) $sites[$i]['soft']=$sites[$i]['soft'][1]; + if (!is_numeric($sites[$i]['hard'])) $sites[$i]['hard']=$sites[$i]['hard'][1]; + if (!is_numeric($sites[$i]['files'])) $sites[$i]['files']=$sites[$i]['files'][1]; + + if ($readable) { + // colours + $sites[$i]['display_colour'] = '#000000'; + if($sites[$i]['soft'] > 0){ + $used_ratio = $sites[$i]['used']/$sites[$i]['soft']; + } else { + $used_ratio = 0; + } + if($used_ratio >= 0.8) $sites[$i]['display_colour'] = '#fd934f'; + if($used_ratio >= 1) $sites[$i]['display_colour'] = '#cc0000'; + + if($sites[$i]['used'] > 1024) { + $sites[$i]['used'] = round($sites[$i]['used'] / 1024, 2).' MB'; + } else { + if ($sites[$i]['used'] != '') $sites[$i]['used'] .= ' KB'; + } + + if($sites[$i]['soft'] > 1024) { + $sites[$i]['soft'] = round($sites[$i]['soft'] / 1024, 2).' MB'; + } else { + $sites[$i]['soft'] .= ' KB'; + } + + if($sites[$i]['hard'] > 1024) { + $sites[$i]['hard'] = round($sites[$i]['hard'] / 1024, 2).' MB'; + } else { + $sites[$i]['hard'] .= ' KB'; + } + + if($sites[$i]['soft'] == " KB") $sites[$i]['soft'] = $app->lng('unlimited'); + if($sites[$i]['hard'] == " KB") $sites[$i]['hard'] = $app->lng('unlimited'); + + if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = $app->lng('unlimited'); + if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = $app->lng('unlimited'); + + /* + if(!strstr($sites[$i]['used'],'M') && !strstr($sites[$i]['used'],'K')) $sites[$i]['used'].= ' B'; + if(!strstr($sites[$i]['soft'],'M') && !strstr($sites[$i]['soft'],'K')) $sites[$i]['soft'].= ' B'; + if(!strstr($sites[$i]['hard'],'M') && !strstr($sites[$i]['hard'],'K')) $sites[$i]['hard'].= ' B'; + */ + } + else { + if (empty($sites[$i]['soft'])) $sites[$i]['soft'] = -1; + if (empty($sites[$i]['hard'])) $sites[$i]['hard'] = -1; + + if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = -1; + if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = -1; + } + } + } + + return $sites; + } + + public function get_mailquota_data($groupid = null, $readable = true) { + global $app; + + $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC"); + $monitor_data = array(); + if(is_array($tmp_rec)) { + foreach ($tmp_rec as $tmp_mon) { + //$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data']))); + $tmp_array = unserialize($app->db->unquote($tmp_mon['data'])); + if(is_array($tmp_array)) { + foreach($tmp_array as $username => $data) { + if(!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used']; + } + } + } + } + //print_r($monitor_data); + if($_SESSION["s"]["user"]["typ"] != 'admin'){ + $sql_where = " AND sys_groupid = ".intval($_SESSION['s']['user']['default_group']); + } + + if($groupid != null){ + $sql_where = " AND sys_groupid = ".$groupid); + } + + + // select email accounts belonging to client + $emails = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE 1".$sql_where); + //print_r($emails); + if(is_array($emails) && !empty($emails)){ + for($i=0;$i<sizeof($emails);$i++){ + $email = $emails[$i]['email']; + + $emails[$i]['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0); + + if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1]; + + // colours + $emails[$i]['display_colour'] = '#000000'; + if($emails[$i]['quota'] > 0){ + $used_ratio = $emails[$i]['used']/$emails[$i]['quota']; + } else { + $used_ratio = 0; + } + if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f'; + if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000'; + + if($emails[$i]['quota'] == 0){ + $emails[$i]['quota'] = $app->lng('unlimited'); + } else { + $emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 4).' MB'; + } + + + if($emails[$i]['used'] < 1544000) { + $emails[$i]['used'] = round($emails[$i]['used'] / 1024, 4).' KB'; + } else { + $emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 4).' MB'; + } + } + } + + return $emails; + } +} \ No newline at end of file diff --git a/interface/lib/classes/remoting.inc.php b/interface/lib/classes/remoting.inc.php index 5541fcb..7acff59 100644 --- a/interface/lib/classes/remoting.inc.php +++ b/interface/lib/classes/remoting.inc.php @@ -187,6 +187,39 @@ } } + //** quota functions ----------------------------------------------------------------------------------- + public function quota_get_by_user($session_id, $group_id) + { + global $app; + $app->uses('quota_lib'); + + if(!$this->checkPerm($session_id, 'quota_get_by_user')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $group_id = $app->functions->intval($group_id); + + $sites = $app->quota_lib->get_quota_data($group_id, false); + + return $sites; + } + + public function mailquota_get_by_user($session_id, $group_id) + { + global $app; + $app->uses('quota_lib'); + + if(!$this->checkPerm($session_id, 'mailquota_get_by_user')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $group_id = $app->functions->intval($group_id); + + $sites = $app->quota_lib->get_quota_data($group_id, false); + + return $sites; + } + //** protected functions ----------------------------------------------------------------------------------- protected function klientadd($formdef_file, $reseller_id, $params) diff --git a/interface/web/client/lib/remote.conf.php b/interface/web/client/lib/remote.conf.php index 62e4dde..56c7708 100644 --- a/interface/web/client/lib/remote.conf.php +++ b/interface/web/client/lib/remote.conf.php @@ -2,6 +2,7 @@ $function_list['client_get_all,client_get,client_add,client_update,client_delete,client_get_sites_by_user,client_get_by_username,client_change_password,client_get_id,client_delete_everything'] = 'Client functions'; $function_list['domains_domain_get,domains_domain_add,domains_domain_delete,domains_get_all_by_user'] = 'Domaintool functions'; +$function_list['quota_get_by_user,mailquota_get_by_user'] = 'Quota functions'; ?> diff --git a/interface/web/dashboard/dashlets/mailquota.php b/interface/web/dashboard/dashlets/mailquota.php index 68105a5..923784f 100644 --- a/interface/web/dashboard/dashlets/mailquota.php +++ b/interface/web/dashboard/dashlets/mailquota.php @@ -16,70 +16,17 @@ if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC"); - $monitor_data = array(); - if(is_array($tmp_rec)) { - foreach ($tmp_rec as $tmp_mon) { - //$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data']))); - $tmp_array = unserialize($app->db->unquote($tmp_mon['data'])); - if(is_array($tmp_array)) { - foreach($tmp_array as $username => $data) { - if(!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used']; - } - } - } - } - //print_r($monitor_data); - if($_SESSION["s"]["user"]["typ"] != 'admin'){ - $sql_where = " AND sys_groupid = ".intval($_SESSION['s']['user']['default_group']); - } + $emails = $app->quota_lib->get_mailquota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['default_group'] : null); + //print_r($emails); $has_mailquota = false; - // select email accounts belonging to client - $emails = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE 1".$sql_where); - //print_r($emails); if(is_array($emails) && !empty($emails)){ - for($i=0;$i<sizeof($emails);$i++){ - $email = $emails[$i]['email']; - - $emails[$i]['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0); - - if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1]; - - // colours - $emails[$i]['display_colour'] = '#000000'; - if($emails[$i]['quota'] > 0){ - $used_ratio = $emails[$i]['used']/$emails[$i]['quota']; - } else { - $used_ratio = 0; - } - if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f'; - if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000'; - - if($emails[$i]['quota'] == 0){ - $emails[$i]['quota'] = $app->lng('unlimited'); - } else { - $emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 4).' MB'; - } - - - if($emails[$i]['used'] < 1544000) { - $emails[$i]['used'] = round($emails[$i]['used'] / 1024, 4).' KB'; - } else { - $emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 4).' MB'; - } - - } - $has_mailquota = true; $tpl->setloop('mailquota', $emails); + $has_mailquota = isset($emails[0]['used']); } - //print_r($sites); - $tpl->setVar('has_mailquota', $has_mailquota); - + return $tpl->grab(); - - } } diff --git a/interface/web/dashboard/dashlets/quota.php b/interface/web/dashboard/dashlets/quota.php index d0d68fd..5675098 100644 --- a/interface/web/dashboard/dashlets/quota.php +++ b/interface/web/dashboard/dashlets/quota.php @@ -3,10 +3,10 @@ class dashlet_quota { function show() { - global $app, $conf; + global $app; //* Loading Template - $app->uses('tpl'); + $app->uses('tpl','quota_lib'); $tpl = new tpl; $tpl->newTemplate("dashlets/templates/quota.htm"); @@ -16,88 +16,14 @@ if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); - $monitor_data = array(); - if(is_array($tmp_rec)) { - foreach ($tmp_rec as $tmp_mon) { - $monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data']))); - } - } - //print_r($monitor_data); - if($_SESSION["s"]["user"]["typ"] != 'admin'){ - $sql_where = " AND sys_groupid = ".$app->functions->intval($_SESSION['s']['user']['default_group']); - } + $sites = $app->quota_lib->get_quota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['default_group'] : null); + //print_r($sites); $has_quota = false; - // select websites belonging to client - $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".$sql_where); - //print_r($sites); if(is_array($sites) && !empty($sites)){ - for($i=0;$i<sizeof($sites);$i++){ - $username = $sites[$i]['system_user']; - $sites[$i]['used'] = $monitor_data['user'][$username]['used']; - $sites[$i]['soft'] = $monitor_data['user'][$username]['soft']; - $sites[$i]['hard'] = $monitor_data['user'][$username]['hard']; - $sites[$i]['files'] = $monitor_data['user'][$username]['files']; - - if (!is_numeric($sites[$i]['used'])){ - if ($sites[$i]['used'][0] > $sites[$i]['used'][1]){ - $sites[$i]['used'] = $sites[$i]['used'][0]; - } else { - $sites[$i]['used'] = $sites[$i]['used'][1]; - } - } - if (!is_numeric($sites[$i]['soft'])) $sites[$i]['soft']=$sites[$i]['soft'][1]; - if (!is_numeric($sites[$i]['hard'])) $sites[$i]['hard']=$sites[$i]['hard'][1]; - if (!is_numeric($sites[$i]['files'])) $sites[$i]['files']=$sites[$i]['files'][1]; - - // colours - $sites[$i]['display_colour'] = '#000000'; - if($sites[$i]['soft'] > 0){ - $used_ratio = $sites[$i]['used']/$sites[$i]['soft']; - } else { - $used_ratio = 0; - } - if($used_ratio >= 0.8) $sites[$i]['display_colour'] = '#fd934f'; - if($used_ratio >= 1) $sites[$i]['display_colour'] = '#cc0000'; - - if($sites[$i]['used'] > 1024) { - $sites[$i]['used'] = round($sites[$i]['used'] / 1024, 2).' MB'; - } else { - if ($sites[$i]['used'] != '') $sites[$i]['used'] .= ' KB'; - } - - if($sites[$i]['soft'] > 1024) { - $sites[$i]['soft'] = round($sites[$i]['soft'] / 1024, 2).' MB'; - } else { - $sites[$i]['soft'] .= ' KB'; - } - - if($sites[$i]['hard'] > 1024) { - $sites[$i]['hard'] = round($sites[$i]['hard'] / 1024, 2).' MB'; - } else { - $sites[$i]['hard'] .= ' KB'; - } - - if($sites[$i]['soft'] == " KB") $sites[$i]['soft'] = $app->lng('unlimited'); - if($sites[$i]['hard'] == " KB") $sites[$i]['hard'] = $app->lng('unlimited'); - - - /* - if(!strstr($sites[$i]['used'],'M') && !strstr($sites[$i]['used'],'K')) $sites[$i]['used'].= ' B'; - if(!strstr($sites[$i]['soft'],'M') && !strstr($sites[$i]['soft'],'K')) $sites[$i]['soft'].= ' B'; - if(!strstr($sites[$i]['hard'],'M') && !strstr($sites[$i]['hard'],'K')) $sites[$i]['hard'].= ' B'; - */ - - if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = $app->lng('unlimited'); - if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = $app->lng('unlimited'); - - } - $has_quota = true; $tpl->setloop('quota', $sites); + $has_quota = isset($sites[0]['used']); } - //print_r($sites); - $tpl->setVar('has_quota', $has_quota); return $tpl->grab(); -- Gitblit v1.9.1