Skip to content

Commit df76de9

Browse files
committed
- Added overtraffic notifications to traffic quota system (part of FS#2059 - Extend Traffic quota system)
1 parent e9ff785 commit df76de9

File tree

7 files changed

+87
-3
lines changed

7 files changed

+87
-3
lines changed

install/tpl/server.ini.master

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ php_ini_path_cgi=/etc/php5/cgi/php.ini
6666
check_apache_config=y
6767
enable_sni=y
6868
enable_ip_wildcard=y
69+
overtraffic_notify_admin=y
70+
overtraffic_notify_client=y
6971
nginx_cgi_socket=/var/run/fcgiwrap.socket
7072
php_fpm_init_script=php5-fpm
7173
php_fpm_ini_path=/etc/php5/fpm/php.ini

interface/web/admin/form/server_config.tform.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,18 @@
500500
'default' => 'y',
501501
'value' => array(0 => 'n', 1 => 'y')
502502
),
503+
'overtraffic_notify_admin' => array(
504+
'datatype' => 'VARCHAR',
505+
'formtype' => 'CHECKBOX',
506+
'default' => 'y',
507+
'value' => array(0 => 'n', 1 => 'y')
508+
),
509+
'overtraffic_notify_client' => array(
510+
'datatype' => 'VARCHAR',
511+
'formtype' => 'CHECKBOX',
512+
'default' => 'y',
513+
'value' => array(0 => 'n', 1 => 'y')
514+
),
503515
'user' => array(
504516
'datatype' => 'VARCHAR',
505517
'formtype' => 'TEXT',

interface/web/admin/lib/lang/en_server_config.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,6 @@ $wb["firewall_txt"] = 'Firewall';
168168
$wb["mailbox_quota_stats_txt"] = 'Mailbox quota statistics';
169169
$wb["enable_ip_wildcard_txt"] = 'Enable IP wildcard (*)';
170170
$wb["web_folder_protection_txt"] = 'Web folder protection';
171+
$wb["overtraffic_notify_admin_txt"] = 'Send overtraffic notification to admin';
172+
$wb["overtraffic_notify_client_txt"] = 'Send overtraffic notification to client';
171173
?>

interface/web/admin/templates/server_config_web_edit.htm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ <h2><tmpl_var name="list_head_txt"></h2>
9494
<div class="multiField">
9595
{tmpl_var name='enable_ip_wildcard'}
9696
</div>
97+
</div>
98+
<div class="ctrlHolder">
99+
<p class="label">{tmpl_var name='overtraffic_notify_admin_txt'}</p>
100+
<div class="multiField">
101+
{tmpl_var name='overtraffic_notify_admin'}
102+
</div>
103+
</div>
104+
<div class="ctrlHolder">
105+
<p class="label">{tmpl_var name='overtraffic_notify_client_txt'}</p>
106+
<div class="multiField">
107+
{tmpl_var name='overtraffic_notify_client'}
108+
</div>
97109
</div>
98110
<div class="subsectiontoggle"><span></span>{tmpl_var name='ssl_settings_txt'}<em></em></div>
99111
<div style="display:none;">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Subject:Website traffic notification
2+
3+
The website {domain} is over traffic and has been disabled.

server/cron_daily.php

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ function setConfigVar( $filename, $varName, $varValue ) {
447447

448448
if ($app->dbmaster == $app->db) {
449449

450+
$global_config = $app->getconf->get_global_config('mail');
451+
450452
$current_month = date('Y-m');
451453

452454
//* Check website traffic quota
@@ -478,12 +480,63 @@ function setConfigVar( $filename, $varName, $varValue ) {
478480
($reseller_traffic_quota > 0 && $web_traffic > $reseller_traffic_quota)) {*/
479481
if($web_traffic_quota > 0 && $web_traffic > $web_traffic_quota) {
480482
$app->dbmaster->datalogUpdate('web_domain', "traffic_quota_lock = 'y',active = 'n'", 'domain_id', $rec['domain_id']);
481-
$app->log('Traffic quota for '.$rec['domain_id'].' exceeded. Disabling website.',LOGLEVEL_DEBUG);
483+
$app->log('Traffic quota for '.$rec['domain'].' exceeded. Disabling website.',LOGLEVEL_DEBUG);
484+
485+
//* Send traffic notifications
486+
if($web_config['overtraffic_notify_admin'] == 'y' || $web_config['overtraffic_notify_client'] == 'y') {
487+
488+
if(file_exists($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_'.$conf['language'].'.txt')) {
489+
$lines = file($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_'.$conf['language'].'.txt');
490+
} elseif(file_exists($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_en.txt')) {
491+
$lines = file($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_en.txt');
492+
} elseif(file_exists($conf['rootpath'].'/conf/mail/web_traffic_notification_'.$conf['language'].'.txt')) {
493+
$lines = file($conf['rootpath'].'/conf/mail/web_traffic_notification_'.$conf['language'].'.txt');
494+
} else {
495+
$lines = file($conf['rootpath'].'/conf/mail/web_traffic_notification_en.txt');
496+
}
497+
498+
//* Get subject
499+
$parts = explode(':',trim($lines[0]));
500+
unset($parts[0]);
501+
$traffic_mail_subject = implode(':',$parts);
502+
unset($lines[0]);
503+
504+
//* Get message
505+
$traffic_mail_message = trim(implode($lines));
506+
unset($tmp);
507+
508+
//* Replace placeholders
509+
$traffic_mail_message = str_replace('{domain}',$rec['domain'],$traffic_mail_message);
510+
511+
$mailHeaders = "MIME-Version: 1.0" . "\n";
512+
$mailHeaders .= "Content-type: text/plain; charset=utf-8" . "\n";
513+
$mailHeaders .= "Content-Transfer-Encoding: 8bit" . "\n";
514+
$mailHeaders .= "From: ". $global_config['admin_mail'] . "\n";
515+
$mailHeaders .= "Reply-To: ". $global_config['admin_mail'] . "\n";
516+
$mailSubject = "=?utf-8?B?".base64_encode($traffic_mail_subject)."?=";
517+
518+
//* send email to admin
519+
if($global_config['admin_mail'] != '' && $web_config['overtraffic_notify_admin'] == 'y') {
520+
mail($global_config['admin_mail'], $mailSubject, $traffic_mail_message, $mailHeaders);
521+
}
522+
523+
//* Send email to client
524+
if($web_config['overtraffic_notify_admin'] == 'y') {
525+
$client_group_id = $rec["sys_groupid"];
526+
$client = $app->db->queryOneRecord("SELECT client.email FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
527+
if($client['email'] != '') {
528+
mail($client['email'], $mailSubject, $traffic_mail_message, $mailHeaders);
529+
}
530+
}
531+
532+
}
533+
534+
482535
} else {
483536
//* unlock the website, if traffic is lower then quota
484537
if($rec['traffic_quota_lock'] == 'y') {
485538
$app->dbmaster->datalogUpdate('web_domain', "traffic_quota_lock = 'n',active = 'y'", 'domain_id', $rec['domain_id']);
486-
$app->log('Traffic quota for '.$rec['domain_id'].' ok again. Re-enabling website.',LOGLEVEL_DEBUG);
539+
$app->log('Traffic quota for '.$rec['domain'].' ok again. Re-enabling website.',LOGLEVEL_DEBUG);
487540
}
488541
}
489542
}

server/lib/classes/getconf.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function get_server_config($server_id, $section = '') {
5252
public function get_global_config($section = '') {
5353
global $app;
5454

55-
if(!is_array($this->config['global'])) {
55+
if(!@is_array($this->config['global'])) {
5656
$app->uses('ini_parser');
5757
$tmp = $app->db->queryOneRecord('SELECT config FROM sys_ini WHERE sysini_id = 1');
5858
$this->config['global'] = $app->ini_parser->parse_ini_string(stripslashes($tmp['config']));

0 commit comments

Comments
 (0)