migrated autoresponder-cron to new PDO database class, beautify sql-query in paging-class, fix typos in traffic-cron (thx to Dessa), refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-20 08:15:30 +01:00
parent 55185aab5c
commit 345ba3a202
3 changed files with 56 additions and 64 deletions

View File

@@ -316,7 +316,12 @@ class paging {
|| ($natSorting === null && $this->natSorting == true)
) {
// Acts similar to php's natsort(), found in one comment at http://my.opera.com/cpr/blog/show.dml/160556
$sortcode = 'ORDER BY CONCAT( IF( ASCII( LEFT( ' . $sortfield . ', 5 ) ) > 57, LEFT( ' . $sortfield . ', 1 ), \'0\' ), IF( ASCII( RIGHT( ' . $sortfield . ', 1 ) ) > 57, LPAD( ' . $sortfield . ', 255, \'0\' ), LPAD( CONCAT( ' . $sortfield . ', \'-\' ), 255, \'0\' ) ) ) ' . $sortorder;
$sortcode = "ORDER BY CONCAT( IF( ASCII( LEFT( " . $sortfield . ", 5 ) ) > 57,
LEFT( " . $sortfield . ", 1 ), 0 ),
IF( ASCII( RIGHT( " . $sortfield . ", 1 ) ) > 57,
LPAD( " . $sortfield . ", 255, '0' ),
LPAD( CONCAT( " . $sortfield . ", '-' ), 255, '0' )
)) " . $sortorder;
} else {
$sortcode = 'ORDER BY ' . $sortfield . ' ' . $sortorder;
}

View File

@@ -24,39 +24,39 @@
$mail = new PHPMailer(true);
//dont do anything when module is disabled
if((int)$settings['autoresponder']['autoresponder_active'] == 0)
{
if ((int)$settings['autoresponder']['autoresponder_active'] == 0) {
return;
}
//only send autoresponder to mails which were delivered since last run
if((int)$settings['autoresponder']['last_autoresponder_run'] == 0)
{
if ((int)$settings['autoresponder']['last_autoresponder_run'] == 0) {
//mails from last 5 minutes, otherwise all mails will be parsed -> mailbomb prevention
$cycle = 300;
}
else
{
} else {
// calculate seconds since last check
$cycle = time() - (int)$settings['autoresponder']['last_autoresponder_run'];
//prevent mailbombs when cycle is bigger than two days
if($cycle > (2 * 60 * 60 * 24))$cycle = (60 * 60 * 24);
}
// set last_autoresponder_run
$db->query("UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = '" . (int)time() . "' WHERE `settinggroup` = 'autoresponder' AND `varname` = 'last_autoresponder_run'");
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = :timeval
WHERE `settinggroup` = 'autoresponder' AND `varname` = 'last_autoresponder_run'
");
Database::pexecute($upd_stmt, array('timeval' => time()));
// get all customer set ip autoresponders
$result = $db->query("SELECT * FROM `" . TABLE_MAIL_AUTORESPONDER . "` INNER JOIN `" . TABLE_MAIL_USERS . "` ON `" . TABLE_MAIL_AUTORESPONDER . "`.`email` = `" . TABLE_MAIL_USERS . "`.`email` WHERE `enabled` = 1");
$result_stmt = Database::query("
SELECT * FROM `" . TABLE_MAIL_AUTORESPONDER . "` INNER JOIN `" . TABLE_MAIL_USERS . "`
ON `" . TABLE_MAIL_AUTORESPONDER . "`.`email` = `" . TABLE_MAIL_USERS . "`.`email`
WHERE `enabled` = 1
");
if($db->num_rows($result) > 0)
{
while($row = $db->fetch_array($result))
{
/*
* check if specific autoresponder should be used
*/
if (Database::num_rows() > 0) {
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
//check if specific autoresponder should be used
$ts_now = time();
$ts_start = (int)$row['date_from'];
$ts_end = (int)$row['date_until'];
@@ -69,11 +69,10 @@ if($db->num_rows($result) > 0)
if($ts_end != -1 && $ts_end < $ts_now) continue;
// setup mail-path (e.g. /var/customers/mail/[loginname]/[user@domain.tld]/new
$path = $row['homedir'] . $row['maildir'] . "new/";
$path = makeCorrectDir($row['homedir'] . $row['maildir'] . "new/");
// if the directory does not exist, inform syslog
if(!is_dir($path))
{
if (!is_dir($path)) {
$cronlog->logAction(CRON_ACTION, LOG_WARNING, "Error accessing maildir: " . $path);
continue;
}
@@ -84,10 +83,8 @@ if($db->num_rows($result) > 0)
);
$responded_counter = 0;
foreach ($its as $fullFilename => $it )
{
if($it->getFilename() == '.' || $it->getFilename() == '..')
{
foreach ($its as $fullFilename => $it ) {
if ($it->getFilename() == '.' || $it->getFilename() == '..') {
continue;
}
@@ -97,8 +94,7 @@ if($db->num_rows($result) > 0)
* than our cycle-seconds?
*/
$filemtime = $it->getMTime();
if(time() - $filemtime <= $cycle)
{
if (time() - $filemtime <= $cycle) {
// why not read up to k lines?
// I've been patching this forever, to avoid FATAL ERROR / memory exhausted
// (fgets() is now binary safe, too)
@@ -113,8 +109,7 @@ if($db->num_rows($result) > 0)
}
// error reading mail contents or just empty
if(count($content) == 0)
{
if (count($content) == 0) {
$cronlog->logAction(CRON_ACTION, LOG_WARNING, "Unable to read mail from maildir: " . dirname($fullFilename));
continue;
}
@@ -124,11 +119,9 @@ if($db->num_rows($result) > 0)
$to = '';
$sender = '';
$spam = false;
foreach($content as $line)
{
foreach ($content as $line) {
// header ends on first empty line, skip rest of mail
if(strlen(rtrim($line)) == 0)
{
if (strlen(rtrim($line)) == 0) {
break;
}
@@ -185,15 +178,14 @@ if($db->num_rows($result) > 0)
}
//check for amavis/spamassassin spam headers
if(preg_match("/^X-Spam-Status: (Yes|No)(.*)$/", $line, $match))
{
if($match[1] == 'Yes')
if (preg_match("/^X-Spam-Status: (Yes|No)(.*)$/", $line, $match)) {
if(strtolower($match[1]) == 'yes') {
$spam = true;
}
}
//check for precedence header
if(preg_match("/^Precedence: (bulk|list|junk)(.*)$/", $line, $match))
{
if (preg_match("/^Precedence: (bulk|list|junk)(.*)$/", $line, $match)) {
// use the spam flag to skip reply
$spam = true;
}
@@ -201,20 +193,17 @@ if($db->num_rows($result) > 0)
// check if the receiver is really the one
// with the autoresponder
if(!strlen($to) || $to != $row['email'])
{
if (!strlen($to) || $to != $row['email']) {
$to = '';
}
//skip mail when marked as spam
if($spam == true)
{
if ($spam == true) {
continue;
}
//error while parsing mail
if($to == '' || $from == '')
{
if ($to == '' || $from == '') {
$cronlog->logAction(CRON_ACTION, LOG_WARNING, "No valid headers found in mail to parse");
continue;
}
@@ -222,8 +211,7 @@ if($db->num_rows($result) > 0)
//important! prevent mailbombs when mail comes from a maildaemon/mailrobot
//robot/daemon mails must go to Sender: field in envelope header
//refers to "Das Postfix-Buch" / RFC 2822
if($sender != '')
{
if ($sender != '') {
$from = $sender;
}
@@ -233,8 +221,7 @@ if($db->num_rows($result) > 0)
//check if mail is already an answer
$fullcontent = implode("", $content);
if(strstr($fullcontent, $message) || $from == $to)
{
if (strstr($fullcontent, $message) || $from == $to) {
continue;
}

View File

@@ -378,7 +378,7 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
'mail' => $current_diskspace['mail'],
'mysql' => $current_diskspace['mysql']
);
$ins_stmt = Database::preapre("
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_DISKSPACE . "` SET
`customerid` = :customerid,
`year` = :year,
@@ -535,7 +535,7 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
'mail' => $admin_diskspace[$row['adminid']]['mail'],
'mysql' => $admin_diskspace[$row['adminid']]['mysql']
);
$ins_stmt = Database::preapre("
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_DISKSPACE_ADMINS . "` SET
`adminid` = :adminid,
`year` = :year,