From 024e13295f3d4446805918452f2d907dda96e5ce Mon Sep 17 00:00:00 2001 From: Marius Cramer <m.cramer@pixcept.de> Date: Wed, 15 Apr 2015 09:44:33 -0400 Subject: [PATCH] - ported some patches --- interface/web/sites/web_vhost_domain_edit.php | 2 server/lib/classes/cron.d/100-mailbox_stats.inc.php | 53 ++++++++++++++++++++++++-- interface/web/sites/web_sites_stats.php | 16 ++++---- install/tpl/server.ini.master | 1 interface/web/admin/form/server_config.tform.php | 4 +- interface/web/themes/default/templates/tabbed_form.tpl.htm | 2 interface/web/themes/default/assets/javascripts/ispconfig.js | 6 ++ interface/web/themes/default/templates/error.tpl.htm | 2 8 files changed, 67 insertions(+), 19 deletions(-) diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master index 20dca2d..4cb2222 100644 --- a/install/tpl/server.ini.master +++ b/install/tpl/server.ini.master @@ -77,6 +77,7 @@ apps_vhost_servername= php_open_basedir=[website_path]/web:[website_path]/private:[website_path]/tmp:/var/www/[website_domain]/web:/srv/www/[website_domain]/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin htaccess_allow_override=All +enable_spdy=y awstats_conf_dir=/etc/awstats awstats_data_dir=/var/lib/awstats awstats_pl=/usr/lib/cgi-bin/awstats.pl diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php index 351d4de..53c184f 100644 --- a/interface/web/admin/form/server_config.tform.php +++ b/interface/web/admin/form/server_config.tform.php @@ -321,7 +321,7 @@ 'datatype' => 'INTEGER', 'formtype' => 'SELECT', 'default' => '2048', - 'value' => array('1024' => 'week (1024)', '2048' => 'normal (2048)', '4096' => 'strong (4096)') + 'value' => array('1024' => 'weak (1024)', '2048' => 'normal (2048)', '4096' => 'strong (4096)') ), 'relayhost_password' => array( 'datatype' => 'VARCHAR', @@ -1024,7 +1024,7 @@ 'enable_spdy' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'CHECKBOX', - 'default' => 'n', + 'default' => 'y', 'value' => array ( 0 => 'n', 1 => 'y' diff --git a/interface/web/sites/web_sites_stats.php b/interface/web/sites/web_sites_stats.php index a6af3dc..16c40d4 100644 --- a/interface/web/sites/web_sites_stats.php +++ b/interface/web/sites/web_sites_stats.php @@ -42,26 +42,26 @@ $tmp_month = date('m'); $tmp_rec = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) as t FROM web_traffic WHERE hostname = ? AND YEAR(traffic_date) = ? AND MONTH(traffic_date) = ?", $rec['domain'], $tmp_year, $tmp_month); $rec['this_month'] = $app->functions->formatBytes($tmp_rec['t']); - $this->sum_this_month += $app->functions->formatBytes($tmp_rec['t']); + $this->sum_this_month += $tmp_rec['t']; //** Traffic of the current year $tmp_rec = $app->db->queryOneRecord("SELECT sum(traffic_bytes) as t FROM web_traffic WHERE hostname = ? AND YEAR(traffic_date) = ?", $rec['domain'], $tmp_year); $rec['this_year'] = $app->functions->formatBytes($tmp_rec['t']); - $this->sum_this_year += $app->functions->formatBytes($tmp_rec['t']); + $this->sum_this_year += $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 = ? AND YEAR(traffic_date) = ? AND MONTH(traffic_date) = ?", $rec['domain'], $tmp_year, $tmp_month); $rec['last_month'] = $app->functions->formatBytes($tmp_rec['t']); - $this->sum_last_month += $app->functions->formatBytes($tmp_rec['t']); + $this->sum_last_month += $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 = ? AND YEAR(traffic_date) = ?", $rec['domain'], $tmp_year); $rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']); - $this->sum_last_year += $app->functions->formatBytes($tmp_rec['t']); + $this->sum_last_year += $tmp_rec['t']; //* The variable "id" contains always the index variable $rec['id'] = $rec[$this->idx_key]; @@ -73,10 +73,10 @@ { global $app; - $app->tpl->setVar('sum_this_month', number_format($app->functions->intval($this->sum_this_month), 0, '.', ' ')); - $app->tpl->setVar('sum_this_year', number_format($app->functions->intval($this->sum_this_year), 0, '.', ' ')); - $app->tpl->setVar('sum_last_month', number_format($app->functions->intval($this->sum_last_month), 0, '.', ' ')); - $app->tpl->setVar('sum_last_year', number_format($app->functions->intval($this->sum_last_year), 0, '.', ' ')); + $app->tpl->setVar('sum_this_month', $app->functions->formatBytes($this->sum_this_month)); + $app->tpl->setVar('sum_this_year', $app->functions->formatBytes($this->sum_this_year)); + $app->tpl->setVar('sum_last_month', $app->functions->formatBytes($this->sum_last_month)); + $app->tpl->setVar('sum_last_year', $app->functions->formatBytes($this->sum_last_year)); $app->tpl->setVar('sum_txt', $app->listform->lng('sum_txt')); $app->tpl_defaults(); diff --git a/interface/web/sites/web_vhost_domain_edit.php b/interface/web/sites/web_vhost_domain_edit.php index 5508440..af96fd8 100644 --- a/interface/web/sites/web_vhost_domain_edit.php +++ b/interface/web/sites/web_vhost_domain_edit.php @@ -635,7 +635,7 @@ if(is_array($ssl_domains)) { foreach( $ssl_domains as $ssl_domain) { $selected = ($ssl_domain == $this->dataRecord['ssl_domain'])?'SELECTED':''; - $ssl_domain_select .= "<option value='$ssl_domain' $selected>$ssl_domain</option>\r\n"; + $ssl_domain_select .= "<option value='$ssl_domain' $selected>".$app->functions->idn_decode($ssl_domain)."</option>\r\n"; } } $app->tpl->setVar("ssl_domain", $ssl_domain_select); diff --git a/interface/web/themes/default/assets/javascripts/ispconfig.js b/interface/web/themes/default/assets/javascripts/ispconfig.js index bc5c988..0416e40 100644 --- a/interface/web/themes/default/assets/javascripts/ispconfig.js +++ b/interface/web/themes/default/assets/javascripts/ispconfig.js @@ -635,7 +635,11 @@ var dir = $self.attr('data-ordered'); - act = act + '?orderby=' + column; + var separator = '?'; + if(act.indexOf("?") >= 0){ + separator = '&'; + } + act = act + separator + 'orderby=' + column; ISPConfig.submitForm(form, act); $(document).ajaxComplete(function() { diff --git a/interface/web/themes/default/templates/error.tpl.htm b/interface/web/themes/default/templates/error.tpl.htm index f65df61..f0c1081 100644 --- a/interface/web/themes/default/templates/error.tpl.htm +++ b/interface/web/themes/default/templates/error.tpl.htm @@ -1,5 +1,5 @@ <div class='alert alert-danger clear'> - <div class='alert-label'><strong>ERROR</strong></div> + <div class='alert-label'><strong><tmpl_var name="error_txt"></strong></div> <div class='alert-content'> <ol> <li>###ERRORMSG###</li> diff --git a/interface/web/themes/default/templates/tabbed_form.tpl.htm b/interface/web/themes/default/templates/tabbed_form.tpl.htm index d0a2684..5560f3e 100644 --- a/interface/web/themes/default/templates/tabbed_form.tpl.htm +++ b/interface/web/themes/default/templates/tabbed_form.tpl.htm @@ -10,7 +10,7 @@ </tmpl_if> <tmpl_if name="error"> <div class='alert alert-danger clear'> - <div class='alert-label'><strong>ERROR</strong></div> + <div class='alert-label'><strong><tmpl_var name="error_txt"></strong></div> <div class='alert-content'> <ol><tmpl_var name="error"></ol> <div>TODO: IP address is empty.</div> diff --git a/server/lib/classes/cron.d/100-mailbox_stats.inc.php b/server/lib/classes/cron.d/100-mailbox_stats.inc.php index 259535f..9778b2f 100644 --- a/server/lib/classes/cron.d/100-mailbox_stats.inc.php +++ b/server/lib/classes/cron.d/100-mailbox_stats.inc.php @@ -32,6 +32,9 @@ // job schedule protected $_schedule = '0 0 * * *'; + protected $mailbox_traffic = array(); + protected $mail_boxes = array(); + protected $mail_rewrites = array(); /* this function is optional if it contains no custom code */ public function onPrepare() { @@ -164,7 +167,7 @@ $cur_line = false; if(file_exists($state_file)) { - $prev_line = parse_mail_log_line(trim(file_get_contents($state_file))); + $prev_line = $this->parse_mail_log_line(trim(file_get_contents($state_file))); //if($prev_line) echo "continuing from previous run, log position: " . $prev_line['message-id'] . " at " . strftime('%d.%m.%Y %H:%M:%S', $prev_line['timestamp']) . "\n"; } @@ -175,7 +178,8 @@ while($line = fgets($fp, 8192)) { $l++; //if($l % 1000 == 0) echo "\rline $l"; - $cur_line = parse_mail_log_line($line); + $cur_line = $this->parse_mail_log_line($line); + //print_r($cur_line); if(!$cur_line) continue; if($prev_line) { @@ -190,9 +194,13 @@ } } - add_mailbox_traffic($mailbox_traffic, $cur_line['from'], $cur_line['size']); + $this->add_mailbox_traffic($cur_line['from'], $cur_line['size']); + //echo "1\n"; + //print_r($this->mailbox_traffic); foreach($cur_line['to'] as $to) { - add_mailbox_traffic($mailbox_traffic, $to, $cur_line['size']); + $this->add_mailbox_traffic($to, $cur_line['size']); + //echo "2\n"; + //print_r($this->mailbox_traffic); } $last_line = $line; // store for the state file } @@ -207,7 +215,7 @@ while($line = fgets($fp, 8192)) { $l++; //if($l % 1000 == 0) echo "\rline $l"; - $cur_line = parse_mail_log_line($line); + $cur_line = $this->parse_mail_log_line($line); if(!$cur_line) continue; if($prev_line) { @@ -265,6 +273,41 @@ parent::onAfterRun(); } + + private function parse_mail_log_line($line) { + //Oct 31 17:35:48 mx01 amavis[32014]: (32014-05) Passed CLEAN, [IPv6:xxxxx] [IPv6:xxxxx] <xxx@yyyy> -> <aaaa@bbbb>, Message-ID: <xxxx@yyyyy>, mail_id: xxxxxx, Hits: -1.89, size: 1591, queued_as: xxxxxxx, 946 ms + + if(preg_match('/^(\w+\s+\d+\s+\d+:\d+:\d+)\s+[^ ]+\s+amavis.* <([^>]+)>\s+->\s+((<[^>]+>,)+) .*Message-ID:\s+<([^>]+)>.* size:\s+(\d+),.*$/', $line, $matches) == false) return false; + + $timestamp = strtotime($matches[1]); + if(!$timestamp) return false; + + $to = array(); + $recipients = explode(',', $matches[3]); + foreach($recipients as $recipient) { + $recipient = substr($recipient, 1, -1); + if(!$recipient || $recipient == $matches[2]) continue; + $to[] = $recipient; + } + return array('line' => $line, 'timestamp' => $timestamp, 'size' => $matches[6], 'from' => $matches[2], 'to' => $to, 'message-id' => $matches[5]); + } + + private function add_mailbox_traffic($address, $traffic) { + + $address = strtolower($address); + + if(in_array($address, $this->mail_boxes) == true) { + if(!isset($this->mailbox_traffic[$address])) $this->mailbox_traffic[$address] = 0; + $this->mailbox_traffic[$address] += $traffic; + } elseif(array_key_exists($address, $this->mail_rewrites)) { + foreach($this->mail_rewrites[$address] as $address) { + if(!isset($this->mailbox_traffic[$address])) $this->mailbox_traffic[$address] = 0; + $this->mailbox_traffic[$address] += $traffic; + } + } else { + // this is not a local address - skip it + } + } } -- Gitblit v1.9.1