]>
git.datanom.net - qtadmin.git/blob - quarantine.php
2 /* vim: set ts=4 tw=0 sw=4 noet: */
3 require_once 'config.php';
4 require_once $CFG->root
. 'lib/db_factory.php';
5 require_once $CFG->root
. 'lib/utils.inc.php';
7 function error($error) {
9 $util->setHeading("Error");
10 echo $util->getHeader();
11 echo $util->getHeading();
12 echo "<p style=\"color: red;\">$error</p>";
13 echo '<a href="index.php">Return</a>';
14 echo $util->getFooter();
17 function handleRequest($util, $request, $ids) {
21 foreach ($ids as $id) {
22 $mail_id = urldecode($id);
23 $mail = unserialize($_SESSION['mailInfo']["$mail_id"]);
25 if (is_object($mail) && true == $util->authorized($mail->recipient
)) {
26 $secret_id = $mail->secret_id
;
27 $recipient = $mail->recipient
;
28 $sender = $mail->sender
;
30 if ($request == 'release') {
31 $amavisserver = $CFG->amavisd_db_host
;
32 $policy_port = $CFG->amavis_policy_port
;
34 $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30);
36 error("$errstr ($errno)");
39 $out = "request=" . $request . "\r\n";
40 $out .= "mail_id=" . $mail_id . "\r\n";
41 $out .= "recipient=" . $recipient . "\r\n";
42 $out .= "secret_id=" . $secret_id . "\r\n\r\n";
44 $response = fread($fp, 8192);
46 $response = urldecode($response);
47 if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) {
48 error("Request to release failed [$out][$response]");
51 if ($matches[1] != '2.0.0') {
56 $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'";
57 } else if ($request == 'delete') {
58 $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'";
59 } else if ($request == 'block') {
62 error("Unknown operation [$request]");
72 $loggedIn = $util->isLoggedIn();
73 $request = isset($_GET['op']) ?
$_GET['op'] : '';
74 if ($loggedIn && isset($_GET['id'])) {
75 $ids = explode(',', $_GET['id']);
76 if ($request == 'block') {
77 // /add/(whitelist|blacklist)/(.+)
78 $query = handleRequest($util, $request, $ids);
79 $data = json_encode($query);
80 if ($util->isAdmin()) {
81 $method = '/add/blacklist';
83 $method = '/add/blacklist/' . $util->getUser();
85 $success = $util->makeRestCall($method, $data);
87 $query = handleRequest($util, $request, $ids);
88 $success = $DB->update($query);
91 if ($request == 'block') {
92 error("Could not blacklist sender");
94 error("Message not released, contact administrator [$query]");
98 header('Location: qtadmin.php');
99 } else if ($loggedIn && $request == 'purge') {
100 $marked = unserialize($_SESSION['marked']);
101 unset($_SESSION['marked']);
104 foreach ($marked as $mail_id) {
105 $recipient = $DB->getRecipient($mail_id);
106 if ($recipient && true == $util->authorized($recipient)) {
107 $query[] = "delete from msgs where mail_id = '$mail_id'";
108 $query[] = "delete from msgrcpt where mail_id = '$mail_id'";
109 $query[] = "delete from quarantine where mail_id = '$mail_id'";
110 $success = $DB->update($query);
116 if (count($error) > 0) {
117 $str = implode(', ', $error);
118 error("The following messages was not purged [$str], contact administrator");
121 header('Location: qtadmin.php');
122 } else if ($loggedIn) {
123 header('Location: qtadmin.php');
125 header('Location: auth.php');
This page took 0.097909 seconds and 6 git commands to generate.