Skip to content

Commit 0d11ae2

Browse files
author
Marius Cramer
committed
Merge branch 'master' of /home/git/repositories/florian030/ispconfig3
2 parents 6b1d788 + 91c842b commit 0d11ae2

File tree

9 files changed

+75
-40
lines changed

9 files changed

+75
-40
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,9 @@ public function intval($string, $force_numeric = false) {
309309
* @param int precicion - after-comma-numbers (default: 2)
310310
* @return string - formated bytes
311311
*/
312-
313-
314312
public function formatBytes($size, $precision = 2) {
315313
$base=log($size)/log(1024);
316-
$suffixes=array('', 'k', 'M', 'G', 'T');
314+
$suffixes=array('', ' kB', ' MB', ' GB', ' TB');
317315
return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)];
318316
}
319317

interface/web/mail/mail_user_stats.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//* Check permissions for module
1616
$app->auth->check_module_permissions('mail');
1717

18+
$app->uses('functions');
19+
1820
$app->load('listform_actions');
1921

2022
class list_action extends listform_actions {
@@ -33,22 +35,30 @@ function prepareDataRow($rec)
3335
//** Traffic of the current month
3436
$tmp_date = date('Y-m');
3537
$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'");
36-
$rec['this_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
38+
// $rec['this_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
39+
$rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']);
40+
if ($rec['this_month'] == 'NAN') $rec['this_month'] = '0 KB';
3741

3842
//** Traffic of the current year
3943
$tmp_date = date('Y');
4044
$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%'");
41-
$rec['this_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
45+
// $rec['this_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
46+
$rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']);
47+
if ($rec['this_year'] == 'NAN') $rec['this_year'] = '0 KB';
4248

4349
//** Traffic of the last month
4450
$tmp_date = date('Y-m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
4551
$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'");
46-
$rec['last_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
52+
// $rec['last_month'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
53+
$rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']);
54+
if ($rec['last_month'] == 'NAN') $rec['last_month'] = '0 KB';
4755

4856
//** Traffic of the last year
4957
$tmp_date = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
5058
$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%'");
51-
$rec['last_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
59+
// $rec['last_year'] = number_format($app->functions->intval($tmp_rec['t'])/1024/1024, 0, '.', ' ');
60+
$rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']);
61+
if ($rec['last_year'] == 'NAN') $rec['last_year'] = '0 KB';
5262

5363
//* The variable "id" contains always the index variable
5464
$rec['id'] = $rec[$this->idx_key];

interface/web/mail/templates/mail_user_stats_list.htm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ <h2><tmpl_var name="list_head_txt"></h2>
3030
<tmpl_loop name="records">
3131
<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
3232
<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>
33-
<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>
34-
<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>
35-
<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>
36-
<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>
33+
<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>
34+
<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>
35+
<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>
36+
<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>
3737
<td class="tbl_col_buttons"></td>
3838
</tr>
3939
</tmpl_loop>
@@ -53,4 +53,4 @@ <h2><tmpl_var name="list_head_txt"></h2>
5353
</fieldset>
5454
</div>
5555

56-
</div>
56+
</div>

interface/web/mail/user_quota_stats.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//* Check permissions for module
1616
$app->auth->check_module_permissions('mail');
1717

18+
$app->uses('functions');
19+
1820
$app->load('listform_actions');
1921

2022
// $tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
@@ -63,11 +65,15 @@ function prepareDataRow($rec)
6365

6466

6567
$rec['used_sort'] = $rec['used'];
68+
/*
6669
if($rec['used'] < 1544000) {
6770
$rec['used'] = round($rec['used'] / 1024, 4).' KB';
6871
} else {
6972
$rec['used'] = round($rec['used'] / 1048576, 4).' MB';
7073
}
74+
*/
75+
$rec['used']=$app->functions->formatBytes($rec['used']);
76+
if ($rec['used'] == 'NAN') $rec['used']='0 KB';
7177

7278
//* The variable "id" contains always the index variable
7379
$rec['id'] = $rec[$this->idx_key];

interface/web/sites/templates/web_sites_stats_list.htm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ <h2><tmpl_var name="list_head_txt"></h2>
3030
<tmpl_loop name="records">
3131
<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
3232
<td class="tbl_col_domain"><a target="_blank" href="http://{tmpl_var name="domain"}/stats">{tmpl_var name="domain"}</a></td>
33-
<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>
34-
<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>
35-
<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>
36-
<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>
33+
<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>
34+
<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>
35+
<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>
36+
<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>
3737
<td class="tbl_col_buttons"></td>
3838
</tr>
3939
</tmpl_loop>
@@ -60,4 +60,4 @@ <h2><tmpl_var name="list_head_txt"></h2>
6060
</fieldset>
6161
</div>
6262

63-
</div>
63+
</div>

interface/web/sites/user_quota_stats.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//* Check permissions for module
1616
$app->auth->check_module_permissions('sites');
1717

18+
$app->uses('functions');
19+
1820
$app->load('listform_actions');
1921

2022
// $tmp_rec = $app->db->queryOneRecord("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
@@ -57,7 +59,12 @@ function prepareDataRow($rec)
5759
if (!is_numeric($rec['soft'])) $rec['soft']=$rec['soft'][1];
5860
if (!is_numeric($rec['hard'])) $rec['hard']=$rec['hard'][1];
5961
if (!is_numeric($rec['files'])) $rec['files']=$rec['files'][1];
60-
62+
$rec['used']=$app->functions->formatBytes($rec['used']*1024);
63+
$rec['soft']=$app->functions->formatBytes($rec['soft']*1024);
64+
$rec['hard']=$app->functions->formatBytes($rec['hard']*1024);
65+
if($rec['soft'] == "NAN") $rec['soft'] = $app->lng('unlimited');
66+
if($rec['hard'] == "NAN") $rec['hard'] = $app->lng('unlimited');
67+
/*
6168
if($rec['used'] > 1024) {
6269
$rec['used'] = round($rec['used'] / 1024, 2).' MB';
6370
} else {
@@ -78,17 +85,17 @@ function prepareDataRow($rec)
7885
7986
if($rec['soft'] == " KB") $rec['soft'] = $app->lng('unlimited');
8087
if($rec['hard'] == " KB") $rec['hard'] = $app->lng('unlimited');
81-
88+
*/
8289

8390
/*
8491
if(!strstr($rec['used'],'M') && !strstr($rec['used'],'K')) $rec['used'].= ' B';
8592
if(!strstr($rec['soft'],'M') && !strstr($rec['soft'],'K')) $rec['soft'].= ' B';
8693
if(!strstr($rec['hard'],'M') && !strstr($rec['hard'],'K')) $rec['hard'].= ' B';
8794
*/
88-
95+
/*
8996
if($rec['soft'] == '0 B' || $rec['soft'] == '0 KB' || $rec['soft'] == '0') $rec['soft'] = $app->lng('unlimited');
9097
if($rec['hard'] == '0 B' || $rec['hard'] == '0 KB' || $rec['hard'] == '0') $rec['hard'] = $app->lng('unlimited');
91-
98+
*/
9299
//* The variable "id" contains always the index variable
93100
$rec['id'] = $rec[$this->idx_key];
94101
return $rec;

interface/web/sites/web_sites_stats.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//* Check permissions for module
1616
$app->auth->check_module_permissions('sites');
1717

18+
$app->uses('functions');
19+
1820
$app->load('listform_actions');
1921

2022
class list_action extends listform_actions {
@@ -39,26 +41,35 @@ function prepareDataRow($rec)
3941
$tmp_year = date('Y');
4042
$tmp_month = date('m');
4143
$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'");
42-
$rec['this_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
43-
$this->sum_this_month += ($tmp_rec['t']/1024/1024);
44+
// $rec['this_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
45+
// $this->sum_this_month += ($tmp_rec['t']/1024/1024);
46+
$rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']);
47+
$this->sum_this_month += $app->functions->formatBytes($tmp_rec['t']);
48+
4449

4550
//** Traffic of the current year
4651
$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'");
47-
$rec['this_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
48-
$this->sum_this_year += ($tmp_rec['t']/1024/1024);
52+
// $rec['this_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
53+
// $this->sum_this_year += ($tmp_rec['t']/1024/1024);
54+
$rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']);
55+
$this->sum_this_year += $app->functions->formatBytes($tmp_rec['t']);
4956

5057
//** Traffic of the last month
5158
$tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
5259
$tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
5360
$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'");
54-
$rec['last_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
55-
$this->sum_last_month += ($tmp_rec['t']/1024/1024);
61+
// $rec['last_month'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
62+
// $this->sum_last_month += ($tmp_rec['t']/1024/1024);
63+
$rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']);
64+
$this->sum_last_month += $app->functions->formatBytes($tmp_rec['t']);
5665

5766
//** Traffic of the last year
5867
$tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
5968
$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'");
60-
$rec['last_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
61-
$this->sum_last_year += ($tmp_rec['t']/1024/1024);
69+
// $rec['last_year'] = number_format($tmp_rec['t']/1024/1024, 0, '.', ' ');
70+
// $this->sum_last_year += ($tmp_rec['t']/1024/1024);
71+
$rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']);
72+
$this->sum_last_year += $app->functions->formatBytes($tmp_rec['t']);
6273

6374
//* The variable "id" contains always the index variable
6475
$rec['id'] = $rec[$this->idx_key];

server/lib/classes/cron.d/500-backup.inc.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ public function onBeforeRun() {
5050
public function onRunJob() {
5151
global $app, $conf;
5252

53-
//######################################################################################################
54-
// Create website backups
55-
//######################################################################################################
56-
function formatBytes($size, $precision = 2) {
57-
$base=log($size)/log(1024);
58-
$suffixes=array('', 'k', 'M', 'G', 'T');
59-
return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)];
60-
}
61-
6253
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
6354
$backup_dir = $server_config['backup_dir'];
6455
$backup_mode = $server_config['backup_mode'];
@@ -121,7 +112,7 @@ function formatBytes($size, $precision = 2) {
121112
//* Insert web backup record in database
122113
//$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)."')";
123114
//$app->dbmaster->datalogInsert('web_backup', $insert_data, 'backup_id');
124-
$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))."')";
115+
$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))."')";
125116
$app->db->query($sql);
126117
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
127118
} else {
@@ -227,7 +218,7 @@ function formatBytes($size, $precision = 2) {
227218
//* Insert web backup record in database
228219
//$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')";
229220
//$app->dbmaster->datalogInsert('web_backup', $insert_data, 'backup_id');
230-
$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))."')";
221+
$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))."')";
231222
$app->db->query($sql);
232223
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
233224

server/lib/classes/functions.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public function currency_format($number, $view = '') {
129129
return number_format((double)$number, $number_format_decimals, $number_format_dec_point, $number_format_thousands_sep);
130130
}
131131

132+
/**
133+
* Function to change bytes to kB, MB, GB or TB
134+
* @param int $size - size in bytes
135+
* @param int precicion - after-comma-numbers (default: 2)
136+
* @return string - formated bytes
137+
*/
138+
public function formatBytes($size, $precision = 2) {
139+
$base=log($size)/log(1024);
140+
$suffixes=array('', ' kB', ' MB', ' GB', ' TB');
141+
return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)];
142+
}
143+
132144
public function get_ispconfig_url() {
133145
global $app;
134146

0 commit comments

Comments
 (0)