Marius Cramer
2015-04-15 3a11d23a2f32a1b9b2ec43429917c000017c5eff
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;
5de2af 52
b1a6a5 53         //######################################################################################################
MC 54         // enforce traffic quota (run only on the "master-server")
55         //######################################################################################################
5de2af 56
b1a6a5 57         if ($app->dbmaster == $app->db) {
5de2af 58
b1a6a5 59             $global_config = $app->getconf->get_global_config('mail');
5de2af 60
b1a6a5 61             $current_month = date('Y-m');
5de2af 62
b1a6a5 63             //* Check website traffic quota
511ba5 64             $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 65             $records = $app->db->queryAllRecords($sql);
MC 66             if(is_array($records)) {
67                 foreach($records as $rec) {
5de2af 68
b1a6a5 69                     $web_traffic_quota = $rec['traffic_quota'];
MC 70                     $domain = $rec['domain'];
5de2af 71
b1a6a5 72                     //* get the traffic
MC 73                     $tmp = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) As total_traffic_bytes FROM web_traffic WHERE traffic_date like '$current_month%' AND hostname = '$domain'");
74                     $web_traffic = round($tmp['total_traffic_bytes']/1024/1024);
5de2af 75
b1a6a5 76                     if($web_traffic_quota > 0 && $web_traffic > $web_traffic_quota) {
3a11d2 77                         $app->dbmaster->datalogUpdate('web_domain', array("traffic_quota_lock" => 'y', "active" => 'n'), 'domain_id', $rec['domain_id']);
b1a6a5 78                         $app->log('Traffic quota for '.$rec['domain'].' exceeded. Disabling website.', LOGLEVEL_DEBUG);
5de2af 79
b1a6a5 80                         //* Send traffic notifications
MC 81                         if($rec['traffic_quota_lock'] != 'y' && ($web_config['overtraffic_notify_admin'] == 'y' || $web_config['overtraffic_notify_client'] == 'y')) {
5de2af 82
b1a6a5 83                             $placeholders = array('{domain}' => $rec['domain'],
MC 84                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'));
5de2af 85
b1a6a5 86                             $recipients = array();
MC 87                             //* send email to admin
88                             if($global_config['admin_mail'] != '' && $web_config['overtraffic_notify_admin'] == 'y') {
89                                 $recipients[] = $global_config['admin_mail'];
90                             }
5de2af 91
b1a6a5 92                             //* Send email to client
MC 93                             if($web_config['overtraffic_notify_client'] == 'y') {
94                                 $client_group_id = $rec["sys_groupid"];
cc7a82 95                                 $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 96                                 if($client['email'] != '') {
MC 97                                     $recipients[] = $client['email'];
98                                 }
99                             }
100
a20430 101                             $this->_tools->send_notification_email('web_traffic_notification', $placeholders, $recipients);
b1a6a5 102                         }
MC 103
104                     } else {
105                         //* unlock the website, if traffic is lower then quota
106                         if($rec['traffic_quota_lock'] == 'y') {
3a11d2 107                             $app->dbmaster->datalogUpdate('web_domain', array("traffic_quota_lock" => 'n', "active" => 'y'), 'domain_id', $rec['domain_id']);
b1a6a5 108                             $app->log('Traffic quota for '.$rec['domain'].' ok again. Re-enabling website.', LOGLEVEL_DEBUG);
MC 109                         }
110                     }
111                 }
112             }
5de2af 113
M 114
b1a6a5 115         }
5de2af 116
M 117
b1a6a5 118         //######################################################################################################
MC 119         // send website quota warnings by email
120         //######################################################################################################
5de2af 121
b1a6a5 122         if ($app->dbmaster == $app->db) {
5de2af 123
b1a6a5 124             $global_config = $app->getconf->get_global_config('mail');
5de2af 125
b1a6a5 126             //* Check website disk quota
511ba5 127             $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 128             $records = $app->db->queryAllRecords($sql);
MC 129             if(is_array($records) && !empty($records)) {
5de2af 130
b1a6a5 131                 $tmp_rec =  $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
MC 132                 $monitor_data = array();
133                 if(is_array($tmp_rec)) {
134                     foreach ($tmp_rec as $tmp_mon) {
135                         $monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data'])));
136                     }
137                 }
5de2af 138
b1a6a5 139                 foreach($records as $rec) {
5de2af 140
b1a6a5 141                     //$web_hd_quota = $rec['hd_quota'];
MC 142                     $domain = $rec['domain'];
5de2af 143
b1a6a5 144                     $username = $rec['system_user'];
ebbe63 145                     $rec['used'] = @$monitor_data['user'][$username]['used'];
MC 146                     $rec['soft'] = @$monitor_data['user'][$username]['soft'];
147                     $rec['hard'] = @$monitor_data['user'][$username]['hard'];
148                     $rec['files'] = @$monitor_data['user'][$username]['files'];
5de2af 149
b1a6a5 150                     if (!is_numeric($rec['used'])){
MC 151                         if ($rec['used'][0] > $rec['used'][1]){
152                             $rec['used'] = $rec['used'][0];
153                         } else {
154                             $rec['used'] = $rec['used'][1];
155                         }
156                     }
157                     if (!is_numeric($rec['soft'])) $rec['soft']=$rec['soft'][1];
158                     if (!is_numeric($rec['hard'])) $rec['hard']=$rec['hard'][1];
159                     if (!is_numeric($rec['files'])) $rec['files']=$rec['files'][1];
5de2af 160
b1a6a5 161                     // used space ratio
MC 162                     if($rec['soft'] > 0){
163                         $used_ratio = $rec['used']/$rec['soft'];
164                     } else {
165                         $used_ratio = 0;
166                     }
5de2af 167
b1a6a5 168                     $rec['ratio'] = number_format($used_ratio * 100, 2, '.', '').'%';
5de2af 169
b1a6a5 170                     if($rec['used'] > 1024) {
MC 171                         $rec['used'] = round($rec['used'] / 1024, 2).' MB';
172                     } else {
173                         if ($rec['used'] != '') $rec['used'] .= ' KB';
174                     }
5de2af 175
b1a6a5 176                     if($rec['soft'] > 1024) {
MC 177                         $rec['soft'] = round($rec['soft'] / 1024, 2).' MB';
178                     } elseif($rec['soft'] == 0){
179                         $rec['soft'] = '----';
180                     } else {
181                         $rec['soft'] .= ' KB';
182                     }
5de2af 183
b1a6a5 184                     if($rec['hard'] > 1024) {
MC 185                         $rec['hard'] = round($rec['hard'] / 1024, 2).' MB';
186                     } elseif($rec['hard'] == 0){
187                         $rec['hard'] = '----';
188                     } else {
189                         $rec['hard'] .= ' KB';
190                     }
5de2af 191
b1a6a5 192                     // send notifications only if 90% or more of the quota are used
MC 193                     if($used_ratio < 0.9) {
194                         // reset notification date
3a11d2 195                         if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('web_domain', array("last_quota_notification" => null), 'domain_id', $rec['domain_id']);
5de2af 196
b1a6a5 197                         // send notification - everything ok again
MC 198                         if($rec['last_quota_notification'] && $web_config['overquota_notify_onok'] == 'y' && ($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y')) {
199                             $placeholders = array('{domain}' => $rec['domain'],
200                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
201                                 '{used}' => $rec['used'],
202                                 '{soft}' => $rec['soft'],
203                                 '{hard}' => $rec['hard'],
204                                 '{ratio}' => $rec['ratio']);
5de2af 205
b1a6a5 206                             $recipients = array();
5de2af 207
b1a6a5 208                             //* send email to admin
MC 209                             if($global_config['admin_mail'] != '' && $web_config['overquota_notify_admin'] == 'y') {
210                                 $recipients[] = $global_config['admin_mail'];
211                             }
5de2af 212
b1a6a5 213                             //* Send email to client
MC 214                             if($web_config['overquota_notify_client'] == 'y') {
215                                 $client_group_id = $rec["sys_groupid"];
cc7a82 216                                 $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 217                                 if($client['email'] != '') {
MC 218                                     $recipients[] = $client['email'];
219                                 }
220                             }
a20430 221                             $this->_tools->send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
b1a6a5 222                         }
6a0c39 223                     } else {
5de2af 224
6a0c39 225                         // could a notification be sent?
MC 226                         $send_notification = false;
227                         if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
228                         elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
5de2af 229
6a0c39 230                         //* Send quota notifications
MC 231                         if(($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y') && $send_notification == true) {
3a11d2 232                             $app->dbmaster->datalogUpdate('web_domain', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'domain_id', $rec['domain_id']);
5de2af 233
6a0c39 234                             $placeholders = array('{domain}' => $rec['domain'],
MC 235                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
236                                 '{used}' => $rec['used'],
237                                 '{soft}' => $rec['soft'],
238                                 '{hard}' => $rec['hard'],
239                                 '{ratio}' => $rec['ratio']);
5de2af 240
6a0c39 241                             $recipients = array();
5de2af 242
6a0c39 243                             //* send email to admin
MC 244                             if($global_config['admin_mail'] != '' && $web_config['overquota_notify_admin'] == 'y') {
245                                 $recipients[] = $global_config['admin_mail'];
b1a6a5 246                             }
6a0c39 247
MC 248                             //* Send email to client
249                             if($web_config['overquota_notify_client'] == 'y') {
250                                 $client_group_id = $rec["sys_groupid"];
cc7a82 251                                 $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 252                                 if($client['email'] != '') {
MC 253                                     $recipients[] = $client['email'];
254                                 }
255                             }
a20430 256                             $this->_tools->send_notification_email('web_quota_notification', $placeholders, $recipients);
b1a6a5 257                         }
MC 258                     }
259                 }
260             }
261         }
5de2af 262
M 263
b1a6a5 264         //######################################################################################################
MC 265         // send mail quota warnings by email
266         //######################################################################################################
5de2af 267
b1a6a5 268         if ($app->dbmaster == $app->db) {
5de2af 269
b1a6a5 270             $global_config = $app->getconf->get_global_config('mail');
MC 271             $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
5de2af 272
b1a6a5 273             //* Check email quota
MC 274             $sql = "SELECT mailuser_id,sys_groupid,email,name,quota,last_quota_notification,DATEDIFF(CURDATE(), last_quota_notification) as `notified_before` FROM mail_user";
275             $records = $app->db->queryAllRecords($sql);
276             if(is_array($records) && !empty($records)) {
5de2af 277
b1a6a5 278                 $tmp_rec =  $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC");
MC 279                 $monitor_data = array();
280                 if(is_array($tmp_rec)) {
281                     foreach ($tmp_rec as $tmp_mon) {
282                         //$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data'])));
283                         $tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
284                         if(is_array($tmp_array)) {
285                             foreach($tmp_array as $username => $data) {
286                                 if(@!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used'];
287                             }
288                         }
289                     }
290                 }
5de2af 291
b1a6a5 292                 foreach($records as $rec) {
5de2af 293
b1a6a5 294                     $email = $rec['email'];
5de2af 295
b1a6a5 296                     $rec['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0);
5de2af 297
b1a6a5 298                     if (!is_numeric($rec['used'])) $rec['used']=$rec['used'][1];
5de2af 299
b1a6a5 300                     // used space ratio
MC 301                     if($rec['quota'] > 0){
302                         $used_ratio = $rec['used']/$rec['quota'];
303                     } else {
304                         $used_ratio = 0;
305                     }
5de2af 306
b1a6a5 307                     $rec['ratio'] = number_format($used_ratio * 100, 2, '.', '').'%';
5de2af 308
b1a6a5 309                     if($rec['quota'] > 0){
MC 310                         $rec['quota'] = round($rec['quota'] / 1048576, 4).' MB';
311                     } else {
312                         $rec['quota'] = '----';
313                     }
5de2af 314
b1a6a5 315                     if($rec['used'] < 1544000) {
MC 316                         $rec['used'] = round($rec['used'] / 1024, 4).' KB';
317                     } else {
318                         $rec['used'] = round($rec['used'] / 1048576, 4).' MB';
319                     }
5de2af 320
b1a6a5 321                     // send notifications only if 90% or more of the quota are used
MC 322                     if($used_ratio < 0.9) {
323                         // reset notification date
3a11d2 324                         if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('mail_user', array("last_quota_notification" => null), 'mailuser_id', $rec['mailuser_id']);
5de2af 325
b1a6a5 326                         // send notification - everything ok again
MC 327                         if($rec['last_quota_notification'] && $mail_config['overquota_notify_onok'] == 'y' && ($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y')) {
328                             $placeholders = array('{email}' => $rec['email'],
329                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
330                                 '{used}' => $rec['used'],
331                                 '{name}' => $rec['name'],
332                                 '{quota}' => $rec['quota'],
333                                 '{ratio}' => $rec['ratio']);
5de2af 334
b1a6a5 335                             $recipients = array();
MC 336                             //* send email to admin
337                             if($global_config['admin_mail'] != '' && $mail_config['overquota_notify_admin'] == 'y') {
338                                 $recipients[] = $global_config['admin_mail'];
339                             }
5de2af 340
b1a6a5 341                             //* Send email to client
MC 342                             if($mail_config['overquota_notify_client'] == 'y') {
343                                 $client_group_id = $rec["sys_groupid"];
cc7a82 344                                 $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 345                                 if($client['email'] != '') {
MC 346                                     $recipients[] = $client['email'];
347                                 }
348                             }
5de2af 349
a20430 350                             $this->_tools->send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
b1a6a5 351                         }
6a0c39 352                     } else {
5de2af 353
6a0c39 354                         //* Send quota notifications
MC 355                         // could a notification be sent?
356                         $send_notification = false;
357                         if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
358                         elseif($mail_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $mail_config['overquota_notify_freq']) $send_notification = true;
5de2af 359
6a0c39 360                         if(($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y') && $send_notification == true) {
3a11d2 361                             $app->dbmaster->datalogUpdate('mail_user', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'mailuser_id', $rec['mailuser_id']);
5de2af 362
6a0c39 363                             $placeholders = array('{email}' => $rec['email'],
MC 364                                 '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
365                                 '{used}' => $rec['used'],
366                                 '{name}' => $rec['name'],
367                                 '{quota}' => $rec['quota'],
368                                 '{ratio}' => $rec['ratio']);
5de2af 369
6a0c39 370                             $recipients = array();
MC 371                             //* send email to admin
372                             if($global_config['admin_mail'] != '' && $mail_config['overquota_notify_admin'] == 'y') {
373                                 $recipients[] = $global_config['admin_mail'];
b1a6a5 374                             }
5de2af 375
6a0c39 376                             //* Send email to client
MC 377                             if($mail_config['overquota_notify_client'] == 'y') {
378                                 $client_group_id = $rec["sys_groupid"];
cc7a82 379                                 $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 380                                 if($client['email'] != '') {
MC 381                                     $recipients[] = $client['email'];
382                                 }
383                             }
384
a20430 385                             $this->_tools->send_notification_email('mail_quota_notification', $placeholders, $recipients);
6a0c39 386                         }
b1a6a5 387                     }
MC 388                 }
389             }
390         }
391
0543b2 392         //######################################################################################################
F 393         // send database quota warnings by email
394         //######################################################################################################
b1a6a5 395
0543b2 396         if ($app->dbmaster == $app->db) {
F 397
398             $global_config = $app->getconf->get_global_config('mail');
399
400             //* get monitor-data
401             $tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
402             if(is_array($tmp_rec)) {
403                 $monitor_data = array();
404                 foreach ($tmp_rec as $tmp_mon) {
405                     $tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
406                     if(is_array($tmp_array)) 
407                         foreach($tmp_array as $sys_groupid => $data)
408                             $monitor_data[$data['sys_groupid']][] = $data;
409                 }
410                 //* remove duplicates from monitor-data
411                 foreach($monitor_data as $_monitor_data) 
412                     $monitor_data[$_monitor_data[0]['sys_groupid']]=array_map("unserialize", array_unique(array_map("serialize", $_monitor_data)));
413             }
414
415             //* get databases
cc7a82 416             $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 417
F 418             if(is_array($database_records) && !empty($database_records) && is_array($monitor_data) && !empty($monitor_data)) {
419                 //* check database-quota
420                 foreach($database_records as $rec) {
421                     $database = $rec['database_name'];
422                     $quota = $rec['database_quota'] * 1024 * 1024;
423                     if (!is_numeric($quota)) break;
424
425                     foreach ($monitor_data as $cid) {
426
427                         foreach($cid_data as $monitor) {
428
429                             if ($monitor['database_name'] == $database) {
430                                 //* get the client
cc7a82 431                                 $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 432
F 433                                 //* check quota
434                                 if ($quota > 0) $used_ratio = $monitor['size'] / $quota;
435                                 else $used_ratio = 0;
436
437                                 //* send notifications only if 90% or more of the quota are used
438                                 if($used_ratio > 0.9) {
439
440                                     //* reset notification date
3a11d2 441                                     if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => null), 'database_id', $rec['database_id']);
0543b2 442
3a11d2 443                                     $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
0543b2 444
F 445                                     // send notification - everything ok again
446                                     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')) {
447                                         $placeholders = array(
448                                             '{database_name}' => $rec['database_name'],
449                                             '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
450                                             '{used}' => $app->functions->formatBytes($monitor['size']),
451                                             '{quota}' => $quota.' MB',
452                                             '{ratio}' => number_format($used_ratio * 100, 2, '.', '').'%'
453                                         );
454
455                                         $recipients = array();
456
457                                         //* send email to admin
458                                         if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y') 
459                                             $recipients[] = $global_config['admin_mail'];
460
461                                         //* Send email to client
462                                         if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '') 
463                                             $recipients[] = $client['email'];
464
a20430 465                                         $this->_tools->send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
0543b2 466
F 467                                     }
468
469                                 }
470
471                                 //* could a notification be sent?
472                                 $send_notification = false;
473                                 if(!$rec['last_quota_notification']) $send_notification = true; //* not yet notified
474                                 elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
475
476                                 //* Send quota notifications
477                                 if(($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y') && $send_notification == true) {
3a11d2 478                                     $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
0543b2 479                                     $placeholders = array(
F 480                                         '{database_name}' => $rec['database_name'],
481                                         '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
482                                         '{used}' => $app->functions->formatBytes($monitor['size']),
483                                         '{quota}' => $quota.' MB',
484                                         '{ratio}' => number_format($used_ratio * 100, 2, '.', '').'%'
485                                     );
486
487                                     $recipients = array();
488
489                                     //* send email to admin
490                                     if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y')
491                                         $recipients[] = $global_config['admin_mail'];
492
493                                     //* Send email to client
494                                     if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
495                                         $recipients[] = $client['email'];
496
a20430 497                                     $this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients);
0543b2 498
F 499                                 }
500
501                             }
502
503                         }   
504
505                     }
506
507                 }
508
509             }
510         }
b1a6a5 511         parent::onRunJob();
MC 512     }
513
514     /* this function is optional if it contains no custom code */
515     public function onAfterRun() {
516         global $app;
517
518         parent::onAfterRun();
519     }
5de2af 520
M 521 }
522
523 ?>