From 0d11ae2055fe36d390e55065fa846c848a04ad07 Mon Sep 17 00:00:00 2001 From: Marius Cramer <m.cramer@pixcept.de> Date: Thu, 02 Jan 2014 08:47:04 -0500 Subject: [PATCH] Merge branch 'master' of /home/git/repositories/florian030/ispconfig3 --- interface/web/sites/templates/web_sites_stats_list.htm | 10 ++-- server/lib/classes/functions.inc.php | 12 ++++++ interface/web/mail/user_quota_stats.php | 6 +++ interface/web/sites/web_sites_stats.php | 27 +++++++++---- interface/web/mail/templates/mail_user_stats_list.htm | 10 ++-- interface/web/sites/user_quota_stats.php | 15 +++++-- interface/lib/classes/functions.inc.php | 4 - server/lib/classes/cron.d/500-backup.inc.php | 13 +----- interface/web/mail/mail_user_stats.php | 18 +++++++-- 9 files changed, 75 insertions(+), 40 deletions(-) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index 48aa361..a964634 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -309,11 +309,9 @@ * @param int precicion - after-comma-numbers (default: 2) * @return string - formated bytes */ - - public function formatBytes($size, $precision = 2) { $base=log($size)/log(1024); - $suffixes=array('', 'k', 'M', 'G', 'T'); + $suffixes=array('', ' kB', ' MB', ' GB', ' TB'); return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)]; } diff --git a/interface/web/mail/mail_user_stats.php b/interface/web/mail/mail_user_stats.php index e922e3d..6fd72e2 100644 --- a/interface/web/mail/mail_user_stats.php +++ b/interface/web/mail/mail_user_stats.php @@ -15,6 +15,8 @@ //* Check permissions for module $app->auth->check_module_permissions('mail'); +$app->uses('functions'); + $app->load('listform_actions'); class list_action extends listform_actions { @@ -33,22 +35,30 @@ //** Traffic of the current month $tmp_date = date('Y-m'); $tmp_rec = $app->db->queryOneRecord("SELECT traffic as t FROM mail_traffic WHERE mailuser_id = ".$app->functions->intval($rec['mailuser_id'])." AND month = '$tmp_date'"); - $rec['this_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); +// $rec['this_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); + $rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']); + if ($rec['this_month'] == 'NAN') $rec['this_month'] = '0 KB'; //** Traffic of the current year $tmp_date = date('Y'); $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic) as t FROM mail_traffic WHERE mailuser_id = ".$app->functions->intval($rec['mailuser_id'])." AND month like '$tmp_date%'"); - $rec['this_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); +// $rec['this_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); + $rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']); + if ($rec['this_year'] == 'NAN') $rec['this_year'] = '0 KB'; //** Traffic of the last month $tmp_date = date('Y-m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); $tmp_rec = $app->db->queryOneRecord("SELECT traffic as t FROM mail_traffic WHERE mailuser_id = ".$app->functions->intval($rec['mailuser_id'])." AND month = '$tmp_date'"); - $rec['last_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); +// $rec['last_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); + $rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']); + if ($rec['last_month'] == 'NAN') $rec['last_month'] = '0 KB'; //** Traffic of the last year $tmp_date = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1)); $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic) as t FROM mail_traffic WHERE mailuser_id = ".$app->functions->intval($rec['mailuser_id'])." AND month like '$tmp_date%'"); - $rec['last_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); +// $rec['last_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' '); + $rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']); + if ($rec['last_year'] == 'NAN') $rec['last_year'] = '0 KB'; //* The variable "id" contains always the index variable $rec['id'] = $rec[$this->idx_key]; diff --git a/interface/web/mail/templates/mail_user_stats_list.htm b/interface/web/mail/templates/mail_user_stats_list.htm index 5bd773c..35e2235 100644 --- a/interface/web/mail/templates/mail_user_stats_list.htm +++ b/interface/web/mail/templates/mail_user_stats_list.htm @@ -30,10 +30,10 @@ <tmpl_loop name="records"> <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>"> <td class="tbl_col_email"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="email"}</a></td> - <td class="tbl_col_this_month"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_month"} MB</a></td> - <td class="tbl_col_last_month"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_month"} MB</a></td> - <td class="tbl_col_this_year"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_year"} MB</a></td> - <td class="tbl_col_last_year"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_year"} MB</a></td> + <td class="tbl_col_this_month"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_month"}</a></td> + <td class="tbl_col_last_month"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_month"}</a></td> + <td class="tbl_col_this_year"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_year"}</a></td> + <td class="tbl_col_last_year"><a href="#" onclick="loadContent('mail/mail_user_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_year"}</a></td> <td class="tbl_col_buttons"></td> </tr> </tmpl_loop> @@ -53,4 +53,4 @@ </fieldset> </div> -</div> \ No newline at end of file +</div> diff --git a/interface/web/mail/user_quota_stats.php b/interface/web/mail/user_quota_stats.php index d491071..88ab8f4 100644 --- a/interface/web/mail/user_quota_stats.php +++ b/interface/web/mail/user_quota_stats.php @@ -15,6 +15,8 @@ //* Check permissions for module $app->auth->check_module_permissions('mail'); +$app->uses('functions'); + $app->load('listform_actions'); // $tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); @@ -63,11 +65,15 @@ $rec['used_sort'] = $rec['used']; +/* if($rec['used'] < 1544000) { $rec['used'] = round($rec['used'] / 1024, 4).' KB'; } else { $rec['used'] = round($rec['used'] / 1048576, 4).' MB'; } +*/ + $rec['used']=$app->functions->formatBytes($rec['used']); + if ($rec['used'] == 'NAN') $rec['used']='0 KB'; //* The variable "id" contains always the index variable $rec['id'] = $rec[$this->idx_key]; diff --git a/interface/web/sites/templates/web_sites_stats_list.htm b/interface/web/sites/templates/web_sites_stats_list.htm index 2fbf872..f721dfb 100644 --- a/interface/web/sites/templates/web_sites_stats_list.htm +++ b/interface/web/sites/templates/web_sites_stats_list.htm @@ -30,10 +30,10 @@ <tmpl_loop name="records"> <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>"> <td class="tbl_col_domain"><a target="_blank" href="http://{tmpl_var name="domain"}/stats">{tmpl_var name="domain"}</a></td> - <td class="tbl_col_this_month"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_month"} MB</a></td> - <td class="tbl_col_last_month"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_month"} MB</a></td> - <td class="tbl_col_this_year"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_year"} MB</a></td> - <td class="tbl_col_last_year"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_year"} MB</a></td> + <td class="tbl_col_this_month"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_month"}</a></td> + <td class="tbl_col_last_month"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_month"}</a></td> + <td class="tbl_col_this_year"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="this_year"}</a></td> + <td class="tbl_col_last_year"><a href="#" onclick="loadContent('sites/web_<tmpl_if name='type' op='==' value='vhostsubdomain'>vhost_sub</tmpl_if>domain_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="last_year"}</a></td> <td class="tbl_col_buttons"></td> </tr> </tmpl_loop> @@ -60,4 +60,4 @@ </fieldset> </div> -</div> \ No newline at end of file +</div> diff --git a/interface/web/sites/user_quota_stats.php b/interface/web/sites/user_quota_stats.php index aed8e22..76dd0df 100644 --- a/interface/web/sites/user_quota_stats.php +++ b/interface/web/sites/user_quota_stats.php @@ -15,6 +15,8 @@ //* Check permissions for module $app->auth->check_module_permissions('sites'); +$app->uses('functions'); + $app->load('listform_actions'); // $tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC"); @@ -57,7 +59,12 @@ if (!is_numeric($rec['soft'])) $rec['soft']=$rec['soft'][1]; if (!is_numeric($rec['hard'])) $rec['hard']=$rec['hard'][1]; if (!is_numeric($rec['files'])) $rec['files']=$rec['files'][1]; - + $rec['used']=$app->functions->formatBytes($rec['used']*1024); + $rec['soft']=$app->functions->formatBytes($rec['soft']*1024); + $rec['hard']=$app->functions->formatBytes($rec['hard']*1024); + if($rec['soft'] == "NAN") $rec['soft'] = $app->lng('unlimited'); + if($rec['hard'] == "NAN") $rec['hard'] = $app->lng('unlimited'); +/* if($rec['used'] > 1024) { $rec['used'] = round($rec['used'] / 1024, 2).' MB'; } else { @@ -78,17 +85,17 @@ if($rec['soft'] == " KB") $rec['soft'] = $app->lng('unlimited'); if($rec['hard'] == " KB") $rec['hard'] = $app->lng('unlimited'); - +*/ /* if(!strstr($rec['used'],'M') && !strstr($rec['used'],'K')) $rec['used'].= ' B'; if(!strstr($rec['soft'],'M') && !strstr($rec['soft'],'K')) $rec['soft'].= ' B'; if(!strstr($rec['hard'],'M') && !strstr($rec['hard'],'K')) $rec['hard'].= ' B'; */ - +/* if($rec['soft'] == '0 B' || $rec['soft'] == '0 KB' || $rec['soft'] == '0') $rec['soft'] = $app->lng('unlimited'); if($rec['hard'] == '0 B' || $rec['hard'] == '0 KB' || $rec['hard'] == '0') $rec['hard'] = $app->lng('unlimited'); - +*/ //* The variable "id" contains always the index variable $rec['id'] = $rec[$this->idx_key]; return $rec; diff --git a/interface/web/sites/web_sites_stats.php b/interface/web/sites/web_sites_stats.php index f5eb927..9bf96cb 100644 --- a/interface/web/sites/web_sites_stats.php +++ b/interface/web/sites/web_sites_stats.php @@ -15,6 +15,8 @@ //* Check permissions for module $app->auth->check_module_permissions('sites'); +$app->uses('functions'); + $app->load('listform_actions'); class list_action extends listform_actions { @@ -39,26 +41,35 @@ $tmp_year = date('Y'); $tmp_month = date('m'); $tmp_rec = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$app->db->quote($rec['domain'])."' AND YEAR(traffic_date) = '$tmp_year' AND MONTH(traffic_date) = '$tmp_month'"); - $rec['this_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); - $this->sum_this_month += ($tmp_rec['t']/1024/1024); +// $rec['this_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); +// $this->sum_this_month += ($tmp_rec['t']/1024/1024); + $rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']); + $this->sum_this_month += $app->functions->formatBytes($tmp_rec['t']); + //** Traffic of the current year $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$app->db->quote($rec['domain'])."' AND YEAR(traffic_date) = '$tmp_year'"); - $rec['this_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); - $this->sum_this_year += ($tmp_rec['t']/1024/1024); +// $rec['this_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); +// $this->sum_this_year += ($tmp_rec['t']/1024/1024); + $rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']); + $this->sum_this_year += $app->functions->formatBytes($tmp_rec['t']); //** Traffic of the last month $tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); $tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$app->db->quote($rec['domain'])."' AND YEAR(traffic_date) = '$tmp_year' AND MONTH(traffic_date) = '$tmp_month'"); - $rec['last_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); - $this->sum_last_month += ($tmp_rec['t']/1024/1024); +// $rec['last_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); +// $this->sum_last_month += ($tmp_rec['t']/1024/1024); + $rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']); + $this->sum_last_month += $app->functions->formatBytes($tmp_rec['t']); //** Traffic of the last year $tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1)); $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = '".$app->db->quote($rec['domain'])."' AND YEAR(traffic_date) = '$tmp_year'"); - $rec['last_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); - $this->sum_last_year += ($tmp_rec['t']/1024/1024); +// $rec['last_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' '); +// $this->sum_last_year += ($tmp_rec['t']/1024/1024); + $rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']); + $this->sum_last_year += $app->functions->formatBytes($tmp_rec['t']); //* The variable "id" contains always the index variable $rec['id'] = $rec[$this->idx_key]; diff --git a/server/lib/classes/cron.d/500-backup.inc.php b/server/lib/classes/cron.d/500-backup.inc.php index 6010c75..4b2fd10 100644 --- a/server/lib/classes/cron.d/500-backup.inc.php +++ b/server/lib/classes/cron.d/500-backup.inc.php @@ -50,15 +50,6 @@ public function onRunJob() { global $app, $conf; - //###################################################################################################### - // Create website backups - //###################################################################################################### - function formatBytes($size, $precision = 2) { - $base=log($size)/log(1024); - $suffixes=array('', 'k', 'M', 'G', 'T'); - return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)]; - } - $server_config = $app->getconf->get_server_config($conf['server_id'], 'server'); $backup_dir = $server_config['backup_dir']; $backup_mode = $server_config['backup_mode']; @@ -121,7 +112,7 @@ //* Insert web backup record in database //$insert_data = "(server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename) VALUES (".$conf['server_id'].",".$web_id.",'web','".$backup_mode."',".time().",'".$app->db->quote($web_backup_file)."')"; //$app->dbmaster->datalogInsert('web_backup', $insert_data, 'backup_id'); - $sql = "INSERT INTO web_backup (server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename,filesize) VALUES (".$conf['server_id'].",".$web_id.",'web','".$backup_mode."',".time().",'".$app->db->quote($web_backup_file)."','".formatBytes(filesize($web_backup_dir.'/'.$web_backup_file))."')"; + $sql = "INSERT INTO web_backup (server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename,filesize) VALUES (".$conf['server_id'].",".$web_id.",'web','".$backup_mode."',".time().",'".$app->db->quote($web_backup_file)."','".$app->functions->formatBytes(filesize($web_backup_dir.'/'.$web_backup_file))."')"; $app->db->query($sql); if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql); } else { @@ -227,7 +218,7 @@ //* Insert web backup record in database //$insert_data = "(server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename) VALUES (".$conf['server_id'].",$web_id,'mysql','sqlgz',".time().",'".$app->db->quote($db_backup_file).".gz')"; //$app->dbmaster->datalogInsert('web_backup', $insert_data, 'backup_id'); - $sql = "INSERT INTO web_backup (server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename,filesize) VALUES (".$conf['server_id'].",$web_id,'mysql','sqlgz',".time().",'".$app->db->quote($db_backup_file).".gz','".formatBytes(filesize($db_backup_dir.'/'.$db_backup_file))."')"; + $sql = "INSERT INTO web_backup (server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename,filesize) VALUES (".$conf['server_id'].",$web_id,'mysql','sqlgz',".time().",'".$app->db->quote($db_backup_file).".gz','".$app->functions->formatBytes(filesize($db_backup_dir.'/'.$db_backup_file))."')"; $app->db->query($sql); if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql); diff --git a/server/lib/classes/functions.inc.php b/server/lib/classes/functions.inc.php index a4b217a..be55503 100644 --- a/server/lib/classes/functions.inc.php +++ b/server/lib/classes/functions.inc.php @@ -129,6 +129,18 @@ return number_format((double)$number, $number_format_decimals, $number_format_dec_point, $number_format_thousands_sep); } + /** + * Function to change bytes to kB, MB, GB or TB + * @param int $size - size in bytes + * @param int precicion - after-comma-numbers (default: 2) + * @return string - formated bytes + */ + public function formatBytes($size, $precision = 2) { + $base=log($size)/log(1024); + $suffixes=array('', ' kB', ' MB', ' GB', ' TB'); + return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)]; + } + public function get_ispconfig_url() { global $app; -- Gitblit v1.9.1