From 073df620ae2f12b7b8b444e3710266fce4735c6d Mon Sep 17 00:00:00 2001 From: Thom Pol Date: Thu, 26 May 2022 13:29:25 +0200 Subject: [PATCH 1/3] Fix reseller notifications (#6347) --- .../classes/cron.d/300-quota_notify.inc.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/server/lib/classes/cron.d/300-quota_notify.inc.php b/server/lib/classes/cron.d/300-quota_notify.inc.php index e7c13ce09a..89d16ffb3c 100644 --- a/server/lib/classes/cron.d/300-quota_notify.inc.php +++ b/server/lib/classes/cron.d/300-quota_notify.inc.php @@ -108,7 +108,7 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overtraffic_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -246,7 +246,7 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -293,7 +293,7 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -398,7 +398,7 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -445,7 +445,7 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -544,7 +544,7 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_db_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -578,13 +578,14 @@ class cronjob_quota_notify extends cronjob { $recipients = array(); //* send email to admin - if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y') + if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y') { $recipients[] = $global_config['admin_mail']; + } //* Send email to reseller if($web_config['overquota_db_notify_reseller'] == 'y') { $client_group_id = $rec["sys_groupid"]; - $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); if($client['parent_client_id'] > 0) { $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); } @@ -594,8 +595,14 @@ class cronjob_quota_notify extends cronjob { } //* Send email to client - if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '') - $recipients[] = $client['email']; + if($mail_config['overquota_notify_client'] == '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'] != '') { + $recipients[] = $client['email']; + } + } + $this->_tools->send_notification_email('db_quota_ok_notification', $placeholders, $recipients); -- GitLab From 44d21b5c71049e164fe31fdaa0c0e20ce398984c Mon Sep 17 00:00:00 2001 From: Thom Pol Date: Thu, 26 May 2022 13:55:16 +0200 Subject: [PATCH 2/3] Clean up code --- .../classes/cron.d/300-quota_notify.inc.php | 64 ++++--------------- 1 file changed, 12 insertions(+), 52 deletions(-) diff --git a/server/lib/classes/cron.d/300-quota_notify.inc.php b/server/lib/classes/cron.d/300-quota_notify.inc.php index 89d16ffb3c..2fbbd5ad20 100644 --- a/server/lib/classes/cron.d/300-quota_notify.inc.php +++ b/server/lib/classes/cron.d/300-quota_notify.inc.php @@ -57,6 +57,13 @@ class cronjob_quota_notify extends cronjob { $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); + // Get client email and eventual reseller email + $client_group_id = $rec["sys_groupid"]; + $client = $app->db->queryOneRecord("SELECT client.email, client.parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); + if($client['parent_client_id'] > 0) { + $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); + } + //###################################################################################################### // enforce traffic quota (run only on the "master-server") //###################################################################################################### @@ -107,11 +114,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overtraffic_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } @@ -119,8 +121,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to client if($web_config['overtraffic_notify_client'] == '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'] != '') { $recipients[] = $client['email']; } @@ -245,11 +245,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } @@ -257,8 +252,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to client if($web_config['overquota_notify_client'] == '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'] != '') { $recipients[] = $client['email']; } @@ -292,11 +285,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } @@ -304,8 +292,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to client if($web_config['overquota_notify_client'] == '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'] != '') { $recipients[] = $client['email']; } @@ -397,11 +383,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } @@ -409,8 +390,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to client if($mail_config['overquota_notify_client'] == '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'] != '') { $recipients[] = $client['email']; } @@ -444,11 +423,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } @@ -456,8 +430,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to client if($mail_config['overquota_notify_client'] == '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'] != '') { $recipients[] = $client['email']; } @@ -508,9 +480,6 @@ class cronjob_quota_notify extends cronjob { foreach($cid as $monitor) { if ($monitor['database_name'] == $database) { - //* get the client - $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); - //* check quota if ($quota > 0) $used_ratio = $monitor['size'] / $quota; else $used_ratio = 0; @@ -543,19 +512,17 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_db_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } } //* Send email to client - if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '') - $recipients[] = $client['email']; + if($web_config['overquota_db_notify_client'] == 'y') { + if($client['email'] != '') { + $recipients[] = $client['email']; + } + $this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients); @@ -584,11 +551,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to reseller if($web_config['overquota_db_notify_reseller'] == 'y') { - $client_group_id = $rec["sys_groupid"]; - $client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - if($client['parent_client_id'] > 0) { - $reseller = $app->db->queryOneRecord("SELECT email FROM client WHERE client_id = ?", $client['parent_client_id']); - } if($reseller['email'] != '') { $recipients[] = $reseller['email']; } @@ -596,8 +558,6 @@ class cronjob_quota_notify extends cronjob { //* Send email to client if($mail_config['overquota_notify_client'] == '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'] != '') { $recipients[] = $client['email']; } -- GitLab From 48edbdf0eaf9bf01f746bd823dc96e3d2843e164 Mon Sep 17 00:00:00 2001 From: Thom Pol Date: Thu, 26 May 2022 14:04:39 +0200 Subject: [PATCH 3/3] Fix typo --- server/lib/classes/cron.d/300-quota_notify.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/lib/classes/cron.d/300-quota_notify.inc.php b/server/lib/classes/cron.d/300-quota_notify.inc.php index 2fbbd5ad20..08cd283ef7 100644 --- a/server/lib/classes/cron.d/300-quota_notify.inc.php +++ b/server/lib/classes/cron.d/300-quota_notify.inc.php @@ -522,8 +522,7 @@ class cronjob_quota_notify extends cronjob { if($client['email'] != '') { $recipients[] = $client['email']; } - - + } $this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients); } -- GitLab