Add "Notification mail for customers when 90% percent of disk space is exhausted", fixes #466
This commit is contained in:
@@ -1560,4 +1560,5 @@ $lng['admin']['templates']['DISKAVAILABLE'] = 'Replaced with the diskusage in MB
|
|||||||
$lng['admin']['templates']['DISKUSED'] = 'Replaced with the diskusage in MB, which was exhausted by the customer.';
|
$lng['admin']['templates']['DISKUSED'] = 'Replaced with the diskusage in MB, which was exhausted by the customer.';
|
||||||
$lng['serversettings']['dropdown'] = 'Dropdown';
|
$lng['serversettings']['dropdown'] = 'Dropdown';
|
||||||
$lng['serversettings']['manual'] = 'Manual';
|
$lng['serversettings']['manual'] = 'Manual';
|
||||||
|
$lng['mails']['webmaxpercent']['mailbody'] = 'Dear {NAME},\n\nyou used {DISKUSED} MB of your available {DISKAVAILABLE} MB of diskspace.\nThis is more than {MAX_PERCENT}%.\n\nYours sincerely, the Froxlor-Team';
|
||||||
|
$lng['mails']['webmaxpercent']['subject'] = 'Reaching your diskspace limit';
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* @copyright (c) the authors
|
* @copyright (c) the authors
|
||||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||||
* @package Configfiles
|
* @package Cron
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
182
scripts/jobs/cron_usage.inc.diskspace.php
Normal file
182
scripts/jobs/cron_usage.inc.diskspace.php
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Froxlor project.
|
||||||
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the COPYING
|
||||||
|
* file that was distributed with this source code. You can also view the
|
||||||
|
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||||
|
*
|
||||||
|
* @copyright (c) the authors
|
||||||
|
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||||
|
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||||
|
* @package Cron
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* report about diskusage for customers
|
||||||
|
*/
|
||||||
|
$result = $db->query("SELECT
|
||||||
|
`c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, `c`.`diskspace`,
|
||||||
|
`c`.`diskspace_used`, `c`.`email`, `c`.`def_language`,
|
||||||
|
`a`.`name` AS `adminname`, `a`.`email` AS `adminmail`,
|
||||||
|
FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c`
|
||||||
|
LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a`
|
||||||
|
ON `a`.`adminid` = `c`.`adminid`
|
||||||
|
WHERE `c`.`diskspace` > '0' AND `c`.`reportsent` <> '2'");
|
||||||
|
|
||||||
|
while($row = $db->fetch_array($result))
|
||||||
|
{
|
||||||
|
if(isset($row['diskspace'])
|
||||||
|
&& $row['diskspace_used'] != NULL
|
||||||
|
&& $row['diskspace_used'] > 0
|
||||||
|
&& (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax']
|
||||||
|
) {
|
||||||
|
|
||||||
|
$replace_arr = array(
|
||||||
|
'NAME' => $row['name'],
|
||||||
|
'DISKAVAILABLE' => ($row['diskspace'] / 1024), /* traffic is stored in KB, template uses MB */
|
||||||
|
'DISKUSED' => ($row['diskspace_used'] / 1024), /* traffic is stored in KB, template uses MB */
|
||||||
|
'USAGE_PERCENT' => ($row['diskspace_used'] * 100) / $row['diskspace'],
|
||||||
|
'MAX_PERCENT' => $settings['system']['report_webmax']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`
|
||||||
|
WHERE `language` ='" . $row['def_language'] . "'");
|
||||||
|
|
||||||
|
if($lngfile !== NULL)
|
||||||
|
{
|
||||||
|
$langfile = $lngfile['file'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`
|
||||||
|
WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'");
|
||||||
|
$langfile = $lngfile['file'];
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once makeCorrectFile($pathtophpfiles . '/' . $langfile);
|
||||||
|
|
||||||
|
// Get mail templates from database; the ones from 'admin' are fetched for fallback
|
||||||
|
$result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
||||||
|
WHERE `adminid`='" . (int)$row['adminid'] . "'
|
||||||
|
AND `language`='" . $db->escape($row['def_language']) . "'
|
||||||
|
AND `templategroup`='mails'
|
||||||
|
AND `varname`='webmaxpercent_subject'");
|
||||||
|
$mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['subject']), $replace_arr));
|
||||||
|
|
||||||
|
$result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
||||||
|
WHERE `adminid`='" . (int)$row['adminid'] . "'
|
||||||
|
AND `language`='" . $db->escape($row['def_language']) . "'
|
||||||
|
AND `templategroup`='mails'
|
||||||
|
AND `varname`='webmaxpercent_mailbody'");
|
||||||
|
$mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['mailbody']), $replace_arr));
|
||||||
|
|
||||||
|
$_mailerror = false;
|
||||||
|
try {
|
||||||
|
$mail->SetFrom($row['email'], $row['firstname'] . " " . $row['name']);
|
||||||
|
$mail->Subject = $mail_subject;
|
||||||
|
$mail->AltBody = $mail_body;
|
||||||
|
$mail->MsgHTML($mail_body);
|
||||||
|
$mail->AddAddress($row['email'], $row['name']);
|
||||||
|
$mail->Send();
|
||||||
|
} catch(phpmailerException $e) {
|
||||||
|
$mailerr_msg = $e->errorMessage();
|
||||||
|
$_mailerror = true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$mailerr_msg = $e->getMessage();
|
||||||
|
$_mailerror = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_mailerror) {
|
||||||
|
$cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mailerr_msg);
|
||||||
|
standard_error('errorsendingmail', $row["email"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail->ClearAddresses();
|
||||||
|
$db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `reportsent`='2'
|
||||||
|
WHERE `customerid`='" . (int)$row['customerid'] . "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* report about diskusage for admins/reseller
|
||||||
|
*/
|
||||||
|
$result = $db->query("SELECT `a`.* FROM `" . TABLE_PANEL_ADMINS . "` `a`
|
||||||
|
WHERE `a`.`reportsent` <> '2'");
|
||||||
|
|
||||||
|
while($row = $db->fetch_array($result))
|
||||||
|
{
|
||||||
|
if(isset($row['diskspace'])
|
||||||
|
&& $row['diskspace_used'] != NULL
|
||||||
|
&& $row['diskspace_used'] > 0
|
||||||
|
&& (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax']
|
||||||
|
) {
|
||||||
|
|
||||||
|
$replace_arr = array(
|
||||||
|
'NAME' => $row['name'],
|
||||||
|
'DISKAVAILABLE' => ($row['diskspace'] / 1024), /* traffic is stored in KB, template uses MB */
|
||||||
|
'DISKUSED' => ($row['diskspace_used'] / 1024), /* traffic is stored in KB, template uses MB */
|
||||||
|
'USAGE_PERCENT' => ($row['diskspace_used'] * 100) / $row['diskspace'],
|
||||||
|
'MAX_PERCENT' => $settings['system']['report_webmax']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`
|
||||||
|
WHERE `language` ='" . $row['def_language'] . "'");
|
||||||
|
|
||||||
|
if($lngfile !== NULL)
|
||||||
|
{
|
||||||
|
$langfile = $lngfile['file'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`
|
||||||
|
WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'");
|
||||||
|
$langfile = $lngfile['file'];
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once makeCorrectFile($pathtophpfiles . '/' . $langfile);
|
||||||
|
|
||||||
|
// Get mail templates from database; the ones from 'admin' are fetched for fallback
|
||||||
|
$result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
||||||
|
WHERE `adminid`='" . (int)$row['adminid'] . "'
|
||||||
|
AND `language`='" . $db->escape($row['def_language']) . "'
|
||||||
|
AND `templategroup`='mails'
|
||||||
|
AND `varname`='webmaxpercent_subject'");
|
||||||
|
$mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['subject']), $replace_arr));
|
||||||
|
|
||||||
|
$result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
||||||
|
WHERE `adminid`='" . (int)$row['adminid'] . "'
|
||||||
|
AND `language`='" . $db->escape($row['def_language']) . "'
|
||||||
|
AND `templategroup`='mails'
|
||||||
|
AND `varname`='webmaxpercent_mailbody'");
|
||||||
|
$mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['mailbody']), $replace_arr));
|
||||||
|
|
||||||
|
$_mailerror = false;
|
||||||
|
try {
|
||||||
|
$mail->SetFrom($row['email'], $row['name']);
|
||||||
|
$mail->Subject = $mail_subject;
|
||||||
|
$mail->AltBody = $mail_body;
|
||||||
|
$mail->MsgHTML($mail_body);
|
||||||
|
$mail->AddAddress($row['email'], $row['name']);
|
||||||
|
$mail->Send();
|
||||||
|
} catch(phpmailerException $e) {
|
||||||
|
$mailerr_msg = $e->errorMessage();
|
||||||
|
$_mailerror = true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$mailerr_msg = $e->getMessage();
|
||||||
|
$_mailerror = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_mailerror) {
|
||||||
|
$cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mailerr_msg);
|
||||||
|
standard_error('errorsendingmail', $row["email"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail->ClearAddresses();
|
||||||
|
$db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='2'
|
||||||
|
WHERE `adminid`='" . (int)$row['adminid'] . "'");
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ $result = $db->query("SELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`f
|
|||||||
AND `t`.`month` = '" . date("m", $yesterday) . "') as `traffic_used`
|
AND `t`.`month` = '" . date("m", $yesterday) . "') as `traffic_used`
|
||||||
FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c`
|
FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c`
|
||||||
LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` ON `a`.`adminid` = `c`.`adminid`
|
LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` ON `a`.`adminid` = `c`.`adminid`
|
||||||
WHERE `c`.`reportsent` = '0'");
|
WHERE `c`.`reportsent` <> '1'");
|
||||||
|
|
||||||
while($row = $db->fetch_array($result))
|
while($row = $db->fetch_array($result))
|
||||||
{
|
{
|
||||||
@@ -166,7 +166,7 @@ while($row = $db->fetch_array($result))
|
|||||||
|
|
||||||
$_mailerror = false;
|
$_mailerror = false;
|
||||||
try {
|
try {
|
||||||
$mail->SetFrom($row['email'], $row['firstname'] . " " . $row['name']);
|
$mail->SetFrom($row['email'], $row['name']);
|
||||||
$mail->Subject = $mail_subject;
|
$mail->Subject = $mail_subject;
|
||||||
$mail->AltBody = $mail_body;
|
$mail->AltBody = $mail_body;
|
||||||
$mail->MsgHTML($mail_body);
|
$mail->MsgHTML($mail_body);
|
||||||
@@ -187,7 +187,7 @@ while($row = $db->fetch_array($result))
|
|||||||
|
|
||||||
$mail->ClearAddresses();
|
$mail->ClearAddresses();
|
||||||
$db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='1'
|
$db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='1'
|
||||||
WHERE `customerid`='" . (int)$row['adminid'] . "'");
|
WHERE `adminid`='" . (int)$row['adminid'] . "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another month, let's build our report
|
// Another month, let's build our report
|
||||||
@@ -238,6 +238,9 @@ while($row = $db->fetch_array($result))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// include diskspace-usage report, #466
|
||||||
|
include dirname(__FILE__).'/cron_usage.inc.diskspace.php';
|
||||||
|
|
||||||
// Another month, reset the reportstatus
|
// Another month, reset the reportstatus
|
||||||
|
|
||||||
if(date('d') == '01')
|
if(date('d') == '01')
|
||||||
|
|||||||
Reference in New Issue
Block a user