tbrehm
2012-08-22 df76de91840361f83644cecc07c3752bdc1c1810
- Added overtraffic notifications to traffic quota system (part of FS#2059 - Extend Traffic quota system)
1 files added
6 files modified
90 ■■■■■ changed files
install/tpl/server.ini.master 2 ●●●●● patch | view | raw | blame | history
interface/web/admin/form/server_config.tform.php 12 ●●●●● patch | view | raw | blame | history
interface/web/admin/lib/lang/en_server_config.lng 2 ●●●●● patch | view | raw | blame | history
interface/web/admin/templates/server_config_web_edit.htm 12 ●●●●● patch | view | raw | blame | history
server/conf/mail/web_traffic_notification_en.txt 3 ●●●●● patch | view | raw | blame | history
server/cron_daily.php 57 ●●●●● patch | view | raw | blame | history
server/lib/classes/getconf.inc.php 2 ●●● patch | view | raw | blame | history
install/tpl/server.ini.master
@@ -66,6 +66,8 @@
check_apache_config=y
enable_sni=y
enable_ip_wildcard=y
overtraffic_notify_admin=y
overtraffic_notify_client=y
nginx_cgi_socket=/var/run/fcgiwrap.socket
php_fpm_init_script=php5-fpm
php_fpm_ini_path=/etc/php5/fpm/php.ini
interface/web/admin/form/server_config.tform.php
@@ -500,6 +500,18 @@
            'default' => 'y',
            'value' => array(0 => 'n', 1 => 'y')
        ),
        'overtraffic_notify_admin' => array(
            'datatype' => 'VARCHAR',
            'formtype' => 'CHECKBOX',
            'default' => 'y',
            'value' => array(0 => 'n', 1 => 'y')
        ),
        'overtraffic_notify_client' => array(
            'datatype' => 'VARCHAR',
            'formtype' => 'CHECKBOX',
            'default' => 'y',
            'value' => array(0 => 'n', 1 => 'y')
        ),
        'user' => array(
            'datatype' => 'VARCHAR',
            'formtype' => 'TEXT',
interface/web/admin/lib/lang/en_server_config.lng
@@ -168,4 +168,6 @@
$wb["mailbox_quota_stats_txt"] = 'Mailbox quota statistics';
$wb["enable_ip_wildcard_txt"] = 'Enable IP wildcard (*)';
$wb["web_folder_protection_txt"] = 'Web folder protection';
$wb["overtraffic_notify_admin_txt"] = 'Send overtraffic notification to admin';
$wb["overtraffic_notify_client_txt"] = 'Send overtraffic notification to client';
?>
interface/web/admin/templates/server_config_web_edit.htm
@@ -95,6 +95,18 @@
                    {tmpl_var name='enable_ip_wildcard'}
                </div>
            </div>
            <div class="ctrlHolder">
                <p class="label">{tmpl_var name='overtraffic_notify_admin_txt'}</p>
                <div class="multiField">
                    {tmpl_var name='overtraffic_notify_admin'}
                </div>
            </div>
            <div class="ctrlHolder">
                <p class="label">{tmpl_var name='overtraffic_notify_client_txt'}</p>
                <div class="multiField">
                    {tmpl_var name='overtraffic_notify_client'}
                </div>
            </div>
            <div class="subsectiontoggle"><span></span>{tmpl_var name='ssl_settings_txt'}<em></em></div>
            <div style="display:none;">
                <div class="ctrlHolder">
server/conf/mail/web_traffic_notification_en.txt
New file
@@ -0,0 +1,3 @@
Subject:Website traffic notification
The website {domain} is over traffic and has been disabled.
server/cron_daily.php
@@ -447,6 +447,8 @@
if ($app->dbmaster == $app->db) {
    $global_config = $app->getconf->get_global_config('mail');
    $current_month = date('Y-m');
    //* Check website traffic quota
@@ -478,12 +480,63 @@
                ($reseller_traffic_quota > 0 && $web_traffic > $reseller_traffic_quota)) {*/
            if($web_traffic_quota > 0 && $web_traffic > $web_traffic_quota) {
                $app->dbmaster->datalogUpdate('web_domain', "traffic_quota_lock = 'y',active = 'n'", 'domain_id', $rec['domain_id']);
                $app->log('Traffic quota for '.$rec['domain_id'].' exceeded. Disabling website.',LOGLEVEL_DEBUG);
                $app->log('Traffic quota for '.$rec['domain'].' exceeded. Disabling website.',LOGLEVEL_DEBUG);
                //* Send traffic notifications
                if($web_config['overtraffic_notify_admin'] == 'y' || $web_config['overtraffic_notify_client'] == 'y') {
                    if(file_exists($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_'.$conf['language'].'.txt')) {
                        $lines = file($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_'.$conf['language'].'.txt');
                    } elseif(file_exists($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_en.txt')) {
                        $lines = file($conf['rootpath'].'/conf-custom/mail/web_traffic_notification_en.txt');
                    } elseif(file_exists($conf['rootpath'].'/conf/mail/web_traffic_notification_'.$conf['language'].'.txt')) {
                        $lines = file($conf['rootpath'].'/conf/mail/web_traffic_notification_'.$conf['language'].'.txt');
                    } else {
                        $lines = file($conf['rootpath'].'/conf/mail/web_traffic_notification_en.txt');
                    }
                    //* Get subject
                    $parts = explode(':',trim($lines[0]));
                    unset($parts[0]);
                    $traffic_mail_subject  = implode(':',$parts);
                    unset($lines[0]);
                    //* Get message
                    $traffic_mail_message = trim(implode($lines));
                    unset($tmp);
                    //* Replace placeholders
                    $traffic_mail_message = str_replace('{domain}',$rec['domain'],$traffic_mail_message);
                    $mailHeaders      = "MIME-Version: 1.0" . "\n";
                    $mailHeaders     .= "Content-type: text/plain; charset=utf-8" . "\n";
                    $mailHeaders     .= "Content-Transfer-Encoding: 8bit" . "\n";
                    $mailHeaders     .= "From: ". $global_config['admin_mail'] . "\n";
                    $mailHeaders     .= "Reply-To: ". $global_config['admin_mail'] . "\n";
                    $mailSubject      = "=?utf-8?B?".base64_encode($traffic_mail_subject)."?=";
                    //* send email to admin
                    if($global_config['admin_mail'] != '' && $web_config['overtraffic_notify_admin'] == 'y') {
                        mail($global_config['admin_mail'], $mailSubject, $traffic_mail_message, $mailHeaders);
                    }
                    //* Send email to client
                    if($web_config['overtraffic_notify_admin'] == 'y') {
                        $client_group_id = $rec["sys_groupid"];
                        $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");
                        if($client['email'] != '') {
                            mail($client['email'], $mailSubject, $traffic_mail_message, $mailHeaders);
                        }
                    }
                }
            } else {
                //* unlock the website, if traffic is lower then quota
                if($rec['traffic_quota_lock'] == 'y') {
                    $app->dbmaster->datalogUpdate('web_domain', "traffic_quota_lock = 'n',active = 'y'", 'domain_id', $rec['domain_id']);
                    $app->log('Traffic quota for '.$rec['domain_id'].' ok again. Re-enabling website.',LOGLEVEL_DEBUG);
                    $app->log('Traffic quota for '.$rec['domain'].' ok again. Re-enabling website.',LOGLEVEL_DEBUG);
                }
            }
        }
server/lib/classes/getconf.inc.php
@@ -52,7 +52,7 @@
    public function get_global_config($section = '') {
        global $app;
        
        if(!is_array($this->config['global'])) {
        if(!@is_array($this->config['global'])) {
            $app->uses('ini_parser');
            $tmp = $app->db->queryOneRecord('SELECT config FROM sys_ini WHERE sysini_id = 1');
            $this->config['global'] = $app->ini_parser->parse_ini_string(stripslashes($tmp['config']));