X-Git-Url: http://git.datanom.net/qtadmin.git/blobdiff_plain/3056d1173b4c0225eea764cd1bdfae965b198c14..70c7fd5765720621553b3ddaff1009c795f49a76:/quarantine.php diff --git a/quarantine.php b/quarantine.php index 031a416..b6703d8 100644 --- a/quarantine.php +++ b/quarantine.php @@ -14,48 +14,54 @@ echo $util->getFooter(); } - function handleRequest($request, $ids) { + function handleRequest($util, $request, $ids) { global $CFG; $query = array(); foreach ($ids as $id) { $mail_id = urldecode($id); $mail = unserialize($_SESSION['mailInfo']["$mail_id"]); - $secret_id = $mail->secret_id; - $recipient = $mail->recipient; - if ($request == 'release') { - $amavisserver = $CFG->amavisd_db_host; - $policy_port = $CFG->amavis_policy_port; + if (is_object($mail) && true == $util->authorized($mail->recipient)) { + $secret_id = $mail->secret_id; + $recipient = $mail->recipient; + $sender = $mail->sender; - $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30); - if (!$fp) { - error("$errstr ($errno)"); - exit; - } - $out = "request=" . $request . "\r\n"; - $out .= "mail_id=" . $mail_id . "\r\n"; - $out .= "recipient=" . $recipient . "\r\n"; - $out .= "secret_id=" . $secret_id . "\r\n\r\n"; - fwrite($fp, $out); - $response = fread($fp, 8192); - fclose($fp); - $response = urldecode($response); - if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) { - error("Request to release failed [$out][$response]"); - exit; - } - if ($matches[1] != '2.0.0') { - error($matches[2]); + if ($request == 'release') { + $amavisserver = $CFG->amavisd_db_host; + $policy_port = $CFG->amavis_policy_port; + + $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30); + if (!$fp) { + error("$errstr ($errno)"); + exit; + } + $out = "request=" . $request . "\r\n"; + $out .= "mail_id=" . $mail_id . "\r\n"; + $out .= "recipient=" . $recipient . "\r\n"; + $out .= "secret_id=" . $secret_id . "\r\n\r\n"; + fwrite($fp, $out); + $response = fread($fp, 8192); + fclose($fp); + $response = urldecode($response); + if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) { + error("Request to release failed [$out][$response]"); + exit; + } + if ($matches[1] != '2.0.0') { + error($matches[2]); + exit; + } + + $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'"; + } else if ($request == 'delete') { + $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'"; + } else if ($request == 'block') { + $query[] = $sender; + } else { + error("Unknown operation [$request]"); exit; } - - $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'"; - } else if ($request == 'delete') { - $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'"; - } else { - error("Unknown operation [$request]"); - exit; } } @@ -67,25 +73,44 @@ $request = isset($_GET['op']) ? $_GET['op'] : ''; if ($loggedIn && isset($_GET['id'])) { $ids = explode(',', $_GET['id']); - $query = handleRequest($request, $ids); - $success = $DB->update($query); + if ($request == 'block') { + // /add/(whitelist|blacklist)/(.+) + $query = handleRequest($util, $request, $ids); + $data = json_encode($query); + if ($util->isAdmin()) { + $method = '/add/blacklist'; + } else { + $method = '/add/blacklist/' . $util->getUser(); + } + $success = $util->makeRestCall($method, $data); + } else { + $query = handleRequest($util, $request, $ids); + $success = $DB->update($query); + } if (! $success) { - error("Message not released, contact administrator [$query]"); + if ($request == 'block') { + error("Could not blacklist sender"); + } else { + error("Message not released, contact administrator [$query]"); + } exit; } - header('Location: index.php'); + header('Location: qtadmin.php'); } else if ($loggedIn && $request == 'purge') { $marked = unserialize($_SESSION['marked']); unset($_SESSION['marked']); $query = array(); $error = array(); foreach ($marked as $mail_id) { - $query[] = "delete from msgs where mail_id = '$mail_id'"; - $query[] = "delete from msgrcpt where mail_id = '$mail_id'"; - $query[] = "delete from quarantine where mail_id = '$mail_id'"; - $success = $DB->update($query); - if (! $success) { - $error[] = $mail_id; + $recipient = $DB->getRecipient($mail_id); + if ($recipient && true == $util->authorized($recipient)) { + $query[] = "delete from msgs where mail_id = '$mail_id'"; + $query[] = "delete from msgrcpt where mail_id = '$mail_id'"; + $query[] = "delete from quarantine where mail_id = '$mail_id'"; + $success = $DB->update($query); + if (! $success) { + $error[] = $mail_id; + } } } if (count($error) > 0) { @@ -93,9 +118,9 @@ error("The following messages was not purged [$str], contact administrator"); exit; } - header('Location: index.php'); + header('Location: qtadmin.php'); } else if ($loggedIn) { - header('Location: index.php'); + header('Location: qtadmin.php'); } else { header('Location: auth.php'); }