Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
5de2af 1 <?php
M 2
3 /*
4 Copyright (c) 2013, Marius Cramer, pixcept KG
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 class cronjob_quota_notify extends cronjob {
32
b1a6a5 33     // job schedule
MC 34     protected $_schedule = '0 0 * * *';
5de2af 35
b1a6a5 36     /* this function is optional if it contains no custom code */
MC 37     public function onPrepare() {
38         global $app;
5de2af 39
b1a6a5 40         parent::onPrepare();
MC 41     }
5de2af 42
b1a6a5 43     /* this function is optional if it contains no custom code */
MC 44     public function onBeforeRun() {
45         global $app;
5de2af 46
b1a6a5 47         return parent::onBeforeRun();
MC 48     }
5de2af 49
b1a6a5 50     public function onRunJob() {
MC 51         global $app, $conf;
7ee336 52         
MC 53         /* used for all monitor cronjobs */
54         $app->load('monitor_tools');
55         $this->_tools = new monitor_tools();
56         /* end global section for monitor cronjobs */
5de2af 57
b1a6a5 58         //######################################################################################################
MC 59         // enforce traffic quota (run only on the "master-server")
60         //######################################################################################################
5de2af 61
b1a6a5 62         if ($app->dbmaster == $app->db) {
5de2af 63
b1a6a5 64             $global_config = $app->getconf->get_global_config('mail');
5de2af 65
b1a6a5 66             $current_month = date('Y-m');
5de2af 67
b1a6a5 68             //* Check website traffic quota
511ba5 69             $sql = "SELECT sys_groupid,domain_id,domain,traffic_quota,traffic_quota_lock FROM web_domain WHERE (traffic_quota > 0 or traffic_quota_lock = 'y') and (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias')";
b1a6a5 70             $records = $app->db->queryAllRecords($sql);
MC 71             if(is_array($records)) {
72                 foreach($records as $rec) {
5de2af 73
b1a6a5 74                     $web_traffic_quota = $rec['traffic_quota'];
MC 75                     $domain = $rec['domain'];
5de2af 76
b1a6a5 77                     //* get the traffic
MC 78                     $tmp = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) As total_traffic_bytes FROM web_traffic WHERE traffic_date like '$current_month%' AND hostname = '$domain'");
79                     $web_traffic = round($tmp['total_traffic_bytes']/1024/1024);
5de2af 80
b1a6a5 81                     if($web_traffic_quota > 0 && $web_traffic > $web_traffic_quota) {
3a11d2 82                         $app->dbmaster->datalogUpdate('web_domain', array("traffic_quota_lock" => 'y', "active" => 'n'), 'domain_id', $rec['domain_id']);
b1a6a5 83                         $app->log('Traffic quota for '.$rec['domain'].' exceeded. Disabling website.', LOGLEVEL_DEBUG);
5de2af 84
b1a6a5 85                         //* Send traffic notifications
MC 86                         if($rec['traffic_quota_lock'] != 'y' && ($web_config['overtraffic_notify_admin'] == 'y' || $web_config['overtraffic_notify_client'] == 'y')) {
5de2af 87
b1a6a5 88                             $placeholders = array('{domain}' => $rec['domain'],
MC 89                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'));
5de2af 90
b1a6a5 91                             $recipients = array();
MC 92                             //* send email to admin
93                             if($global_config['admin_mail'] != '' && $web_config['overtraffic_notify_admin'] == 'y') {
94                                 $recipients[] = $global_config['admin_mail'];
95                             }
5de2af 96
b1a6a5 97                             //* Send email to client
MC 98                             if($web_config['overtraffic_notify_client'] == 'y') {
99                                 $client_group_id = $rec["sys_groupid"];
cc7a82 100                                 $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);
b1a6a5 101                                 if($client['email'] != '') {
MC 102                                     $recipients[] = $client['email'];
103                                 }
104                             }
105
a20430 106                             $this->_tools->send_notification_email('web_traffic_notification', $placeholders, $recipients);
b1a6a5 107                         }
MC 108
109                     } else {
110                         //* unlock the website, if traffic is lower then quota
111                         if($rec['traffic_quota_lock'] == 'y') {
3a11d2 112                             $app->dbmaster->datalogUpdate('web_domain', array("traffic_quota_lock" => 'n', "active" => 'y'), 'domain_id', $rec['domain_id']);
b1a6a5 113                             $app->log('Traffic quota for '.$rec['domain'].' ok again. Re-enabling website.', LOGLEVEL_DEBUG);
MC 114                         }
115                     }
116                 }
117             }
5de2af 118
M 119
b1a6a5 120         }
5de2af 121
M 122
b1a6a5 123         //######################################################################################################
MC 124         // send website quota warnings by email
125         //######################################################################################################
5de2af 126
b1a6a5 127         if ($app->dbmaster == $app->db) {
5de2af 128
b1a6a5 129             $global_config = $app->getconf->get_global_config('mail');
5de2af 130
b1a6a5 131             //* Check website disk quota
511ba5 132             $sql = "SELECT domain_id,sys_groupid,domain,system_user,last_quota_notification,DATEDIFF(CURDATE(), last_quota_notification) as `notified_before` FROM web_domain WHERE (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias')";
b1a6a5 133             $records = $app->db->queryAllRecords($sql);
MC 134             if(is_array($records) && !empty($records)) {
5de2af 135
b1a6a5 136                 $tmp_rec =  $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
MC 137                 $monitor_data = array();
138                 if(is_array($tmp_rec)) {
139                     foreach ($tmp_rec as $tmp_mon) {
140                         $monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data'])));
141                     }
142                 }
5de2af 143
b1a6a5 144                 foreach($records as $rec) {
5de2af 145
b1a6a5 146                     //$web_hd_quota = $rec['hd_quota'];
MC 147                     $domain = $rec['domain'];
5de2af 148
b1a6a5 149                     $username = $rec['system_user'];
ebbe63 150                     $rec['used'] = @$monitor_data['user'][$username]['used'];
MC 151                     $rec['soft'] = @$monitor_data['user'][$username]['soft'];
152                     $rec['hard'] = @$monitor_data['user'][$username]['hard'];
153                     $rec['files'] = @$monitor_data['user'][$username]['files'];
5de2af 154
b1a6a5 155                     if (!is_numeric($rec['used'])){
MC 156                         if ($rec['used'][0] > $rec['used'][1]){
157                             $rec['used'] = $rec['used'][0];
158                         } else {
159                             $rec['used'] = $rec['used'][1];
160                         }
161                     }
162                     if (!is_numeric($rec['soft'])) $rec['soft']=$rec['soft'][1];
163                     if (!is_numeric($rec['hard'])) $rec['hard']=$rec['hard'][1];
164                     if (!is_numeric($rec['files'])) $rec['files']=$rec['files'][1];
5de2af 165
b1a6a5 166                     // used space ratio
MC 167                     if($rec['soft'] > 0){
168                         $used_ratio = $rec['used']/$rec['soft'];
169                     } else {
170                         $used_ratio = 0;
171                     }
5de2af 172
b1a6a5 173                     $rec['ratio'] = number_format($used_ratio * 100, 2, '.', '').'%';
5de2af 174
b1a6a5 175                     if($rec['used'] > 1024) {
MC 176                         $rec['used'] = round($rec['used'] / 1024, 2).' MB';
177                     } else {
178                         if ($rec['used'] != '') $rec['used'] .= ' KB';
179                     }
5de2af 180
b1a6a5 181                     if($rec['soft'] > 1024) {
MC 182                         $rec['soft'] = round($rec['soft'] / 1024, 2).' MB';
183                     } elseif($rec['soft'] == 0){
184                         $rec['soft'] = '----';
185                     } else {
186                         $rec['soft'] .= ' KB';
187                     }
5de2af 188
b1a6a5 189                     if($rec['hard'] > 1024) {
MC 190                         $rec['hard'] = round($rec['hard'] / 1024, 2).' MB';
191                     } elseif($rec['hard'] == 0){
192                         $rec['hard'] = '----';
193                     } else {
194                         $rec['hard'] .= ' KB';
195                     }
5de2af 196
b1a6a5 197                     // send notifications only if 90% or more of the quota are used
MC 198                     if($used_ratio < 0.9) {
199                         // reset notification date
3a11d2 200                         if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('web_domain', array("last_quota_notification" => null), 'domain_id', $rec['domain_id']);
5de2af 201
b1a6a5 202                         // send notification - everything ok again
MC 203                         if($rec['last_quota_notification'] && $web_config['overquota_notify_onok'] == 'y' && ($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y')) {
204                             $placeholders = array('{domain}' => $rec['domain'],
205                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
206                                 '{used}' => $rec['used'],
207                                 '{soft}' => $rec['soft'],
208                                 '{hard}' => $rec['hard'],
209                                 '{ratio}' => $rec['ratio']);
5de2af 210
b1a6a5 211                             $recipients = array();
5de2af 212
b1a6a5 213                             //* send email to admin
MC 214                             if($global_config['admin_mail'] != '' && $web_config['overquota_notify_admin'] == 'y') {
215                                 $recipients[] = $global_config['admin_mail'];
216                             }
5de2af 217
b1a6a5 218                             //* Send email to client
MC 219                             if($web_config['overquota_notify_client'] == 'y') {
220                                 $client_group_id = $rec["sys_groupid"];
cc7a82 221                                 $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);
b1a6a5 222                                 if($client['email'] != '') {
MC 223                                     $recipients[] = $client['email'];
224                                 }
225                             }
a20430 226                             $this->_tools->send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
b1a6a5 227                         }
6a0c39 228                     } else {
5de2af 229
6a0c39 230                         // could a notification be sent?
MC 231                         $send_notification = false;
232                         if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
233                         elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
5de2af 234
6a0c39 235                         //* Send quota notifications
MC 236                         if(($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y') && $send_notification == true) {
3a11d2 237                             $app->dbmaster->datalogUpdate('web_domain', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'domain_id', $rec['domain_id']);
5de2af 238
6a0c39 239                             $placeholders = array('{domain}' => $rec['domain'],
MC 240                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
241                                 '{used}' => $rec['used'],
242                                 '{soft}' => $rec['soft'],
243                                 '{hard}' => $rec['hard'],
244                                 '{ratio}' => $rec['ratio']);
5de2af 245
6a0c39 246                             $recipients = array();
5de2af 247
6a0c39 248                             //* send email to admin
MC 249                             if($global_config['admin_mail'] != '' && $web_config['overquota_notify_admin'] == 'y') {
250                                 $recipients[] = $global_config['admin_mail'];
b1a6a5 251                             }
6a0c39 252
MC 253                             //* Send email to client
254                             if($web_config['overquota_notify_client'] == 'y') {
255                                 $client_group_id = $rec["sys_groupid"];
cc7a82 256                                 $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);
6a0c39 257                                 if($client['email'] != '') {
MC 258                                     $recipients[] = $client['email'];
259                                 }
260                             }
a20430 261                             $this->_tools->send_notification_email('web_quota_notification', $placeholders, $recipients);
b1a6a5 262                         }
MC 263                     }
264                 }
265             }
266         }
5de2af 267
M 268
b1a6a5 269         //######################################################################################################
MC 270         // send mail quota warnings by email
271         //######################################################################################################
5de2af 272
b1a6a5 273         if ($app->dbmaster == $app->db) {
5de2af 274
b1a6a5 275             $global_config = $app->getconf->get_global_config('mail');
MC 276             $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
5de2af 277
b1a6a5 278             //* Check email quota
MC 279             $sql = "SELECT mailuser_id,sys_groupid,email,name,quota,last_quota_notification,DATEDIFF(CURDATE(), last_quota_notification) as `notified_before` FROM mail_user";
280             $records = $app->db->queryAllRecords($sql);
281             if(is_array($records) && !empty($records)) {
5de2af 282
b1a6a5 283                 $tmp_rec =  $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC");
MC 284                 $monitor_data = array();
285                 if(is_array($tmp_rec)) {
286                     foreach ($tmp_rec as $tmp_mon) {
287                         //$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data'])));
288                         $tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
289                         if(is_array($tmp_array)) {
290                             foreach($tmp_array as $username => $data) {
291                                 if(@!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used'];
292                             }
293                         }
294                     }
295                 }
5de2af 296
b1a6a5 297                 foreach($records as $rec) {
5de2af 298
b1a6a5 299                     $email = $rec['email'];
5de2af 300
b1a6a5 301                     $rec['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0);
5de2af 302
b1a6a5 303                     if (!is_numeric($rec['used'])) $rec['used']=$rec['used'][1];
5de2af 304
b1a6a5 305                     // used space ratio
MC 306                     if($rec['quota'] > 0){
307                         $used_ratio = $rec['used']/$rec['quota'];
308                     } else {
309                         $used_ratio = 0;
310                     }
5de2af 311
b1a6a5 312                     $rec['ratio'] = number_format($used_ratio * 100, 2, '.', '').'%';
5de2af 313
b1a6a5 314                     if($rec['quota'] > 0){
MC 315                         $rec['quota'] = round($rec['quota'] / 1048576, 4).' MB';
316                     } else {
317                         $rec['quota'] = '----';
318                     }
5de2af 319
b1a6a5 320                     if($rec['used'] < 1544000) {
MC 321                         $rec['used'] = round($rec['used'] / 1024, 4).' KB';
322                     } else {
323                         $rec['used'] = round($rec['used'] / 1048576, 4).' MB';
324                     }
5de2af 325
b1a6a5 326                     // send notifications only if 90% or more of the quota are used
MC 327                     if($used_ratio < 0.9) {
328                         // reset notification date
3a11d2 329                         if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('mail_user', array("last_quota_notification" => null), 'mailuser_id', $rec['mailuser_id']);
5de2af 330
b1a6a5 331                         // send notification - everything ok again
MC 332                         if($rec['last_quota_notification'] && $mail_config['overquota_notify_onok'] == 'y' && ($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y')) {
333                             $placeholders = array('{email}' => $rec['email'],
334                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
335                                 '{used}' => $rec['used'],
336                                 '{name}' => $rec['name'],
337                                 '{quota}' => $rec['quota'],
338                                 '{ratio}' => $rec['ratio']);
5de2af 339
b1a6a5 340                             $recipients = array();
MC 341                             //* send email to admin
342                             if($global_config['admin_mail'] != '' && $mail_config['overquota_notify_admin'] == 'y') {
343                                 $recipients[] = $global_config['admin_mail'];
344                             }
5de2af 345
b1a6a5 346                             //* Send email to client
MC 347                             if($mail_config['overquota_notify_client'] == 'y') {
348                                 $client_group_id = $rec["sys_groupid"];
cc7a82 349                                 $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);
b1a6a5 350                                 if($client['email'] != '') {
MC 351                                     $recipients[] = $client['email'];
352                                 }
353                             }
5de2af 354
a20430 355                             $this->_tools->send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
b1a6a5 356                         }
6a0c39 357                     } else {
5de2af 358
6a0c39 359                         //* Send quota notifications
MC 360                         // could a notification be sent?
361                         $send_notification = false;
362                         if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
363                         elseif($mail_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $mail_config['overquota_notify_freq']) $send_notification = true;
5de2af 364
6a0c39 365                         if(($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y') && $send_notification == true) {
3a11d2 366                             $app->dbmaster->datalogUpdate('mail_user', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'mailuser_id', $rec['mailuser_id']);
5de2af 367
6a0c39 368                             $placeholders = array('{email}' => $rec['email'],
MC 369                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
370                                 '{used}' => $rec['used'],
371                                 '{name}' => $rec['name'],
372                                 '{quota}' => $rec['quota'],
373                                 '{ratio}' => $rec['ratio']);
5de2af 374
6a0c39 375                             $recipients = array();
MC 376                             //* send email to admin
377                             if($global_config['admin_mail'] != '' && $mail_config['overquota_notify_admin'] == 'y') {
378                                 $recipients[] = $global_config['admin_mail'];
b1a6a5 379                             }
5de2af 380
6a0c39 381                             //* Send email to client
MC 382                             if($mail_config['overquota_notify_client'] == 'y') {
383                                 $client_group_id = $rec["sys_groupid"];
cc7a82 384                                 $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);
6a0c39 385                                 if($client['email'] != '') {
MC 386                                     $recipients[] = $client['email'];
387                                 }
388                             }
389
a20430 390                             $this->_tools->send_notification_email('mail_quota_notification', $placeholders, $recipients);
6a0c39 391                         }
b1a6a5 392                     }
MC 393                 }
394             }
395         }
396
0543b2 397         //######################################################################################################
F 398         // send database quota warnings by email
399         //######################################################################################################
b1a6a5 400
0543b2 401         if ($app->dbmaster == $app->db) {
F 402
403             $global_config = $app->getconf->get_global_config('mail');
404
405             //* get monitor-data
406             $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
407             if(is_array($tmp_rec)) {
408                 $monitor_data = array();
409                 foreach ($tmp_rec as $tmp_mon) {
410                     $tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
411                     if(is_array($tmp_array)) 
412                         foreach($tmp_array as $sys_groupid => $data)
413                             $monitor_data[$data['sys_groupid']][] = $data;
414                 }
415                 //* remove duplicates from monitor-data
416                 foreach($monitor_data as $_monitor_data) 
417                     $monitor_data[$_monitor_data[0]['sys_groupid']]=array_map("unserialize", array_unique(array_map("serialize", $_monitor_data)));
418             }
419
420             //* get databases
cc7a82 421             $database_records = $app->db->queryAllRecords("SELECT database_id,sys_groupid,database_name,database_quota,last_quota_notification,DATEDIFF(CURDATE(), last_quota_notification) as `notified_before` FROM web_database");
0543b2 422
F 423             if(is_array($database_records) && !empty($database_records) && is_array($monitor_data) && !empty($monitor_data)) {
424                 //* check database-quota
425                 foreach($database_records as $rec) {
426                     $database = $rec['database_name'];
427                     $quota = $rec['database_quota'] * 1024 * 1024;
428                     if (!is_numeric($quota)) break;
429
430                     foreach ($monitor_data as $cid) {
431
432                         foreach($cid_data as $monitor) {
433
434                             if ($monitor['database_name'] == $database) {
435                                 //* get the client
cc7a82 436                                 $client = $app->db->queryOneRecord("SELECT client.username, client.email FROM web_database, sys_group, client WHERE web_database.sys_groupid = sys_group.groupid AND sys_group.client_id = client.client_id AND web_database.database_name=?", $database);
0543b2 437
F 438                                 //* check quota
439                                 if ($quota > 0) $used_ratio = $monitor['size'] / $quota;
440                                 else $used_ratio = 0;
441
442                                 //* send notifications only if 90% or more of the quota are used
443                                 if($used_ratio > 0.9) {
444
445                                     //* reset notification date
3a11d2 446                                     if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => null), 'database_id', $rec['database_id']);
0543b2 447
3a11d2 448                                     $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
0543b2 449
F 450                                     // send notification - everything ok again
451                                     if($rec['last_quota_notification'] && $web_config['overquota_notify_onok'] == 'y' && ($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y')) {
452                                         $placeholders = array(
453                                             '{database_name}' => $rec['database_name'],
454                                             '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
455                                             '{used}' => $app->functions->formatBytes($monitor['size']),
456                                             '{quota}' => $quota.' MB',
457                                             '{ratio}' => number_format($used_ratio * 100, 2, '.', '').'%'
458                                         );
459
460                                         $recipients = array();
461
462                                         //* send email to admin
463                                         if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y') 
464                                             $recipients[] = $global_config['admin_mail'];
465
466                                         //* Send email to client
467                                         if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '') 
468                                             $recipients[] = $client['email'];
469
a20430 470                                         $this->_tools->send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
0543b2 471
F 472                                     }
473
474                                 }
475
476                                 //* could a notification be sent?
477                                 $send_notification = false;
478                                 if(!$rec['last_quota_notification']) $send_notification = true; //* not yet notified
479                                 elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
480
481                                 //* Send quota notifications
482                                 if(($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y') && $send_notification == true) {
3a11d2 483                                     $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
0543b2 484                                     $placeholders = array(
F 485                                         '{database_name}' => $rec['database_name'],
486                                         '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
487                                         '{used}' => $app->functions->formatBytes($monitor['size']),
488                                         '{quota}' => $quota.' MB',
489                                         '{ratio}' => number_format($used_ratio * 100, 2, '.', '').'%'
490                                     );
491
492                                     $recipients = array();
493
494                                     //* send email to admin
495                                     if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y')
496                                         $recipients[] = $global_config['admin_mail'];
497
498                                     //* Send email to client
499                                     if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
500                                         $recipients[] = $client['email'];
501
a20430 502                                     $this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients);
0543b2 503
F 504                                 }
505
506                             }
507
508                         }   
509
510                     }
511
512                 }
513
514             }
515         }
b1a6a5 516         parent::onRunJob();
MC 517     }
518
519     /* this function is optional if it contains no custom code */
520     public function onAfterRun() {
521         global $app;
522
523         parent::onAfterRun();
524     }
5de2af 525
M 526 }
527
528 ?>