Marius Cramer
2014-01-02 0d11ae2055fe36d390e55065fa846c848a04ad07
Merge branch 'master' of /home/git/repositories/florian030/ispconfig3
9 files modified
115 ■■■■■ changed files
interface/lib/classes/functions.inc.php 4 ●●● patch | view | raw | blame | history
interface/web/mail/mail_user_stats.php 18 ●●●● patch | view | raw | blame | history
interface/web/mail/templates/mail_user_stats_list.htm 10 ●●●● patch | view | raw | blame | history
interface/web/mail/user_quota_stats.php 6 ●●●●● patch | view | raw | blame | history
interface/web/sites/templates/web_sites_stats_list.htm 10 ●●●● patch | view | raw | blame | history
interface/web/sites/user_quota_stats.php 15 ●●●● patch | view | raw | blame | history
interface/web/sites/web_sites_stats.php 27 ●●●● patch | view | raw | blame | history
server/lib/classes/cron.d/500-backup.inc.php 13 ●●●● patch | view | raw | blame | history
server/lib/classes/functions.inc.php 12 ●●●●● patch | view | raw | blame | history
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)];
    }
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];
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>
</div>
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];
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>
</div>
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;
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];
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);
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;