]> git.datanom.net - qtadmin.git/blame - quarantine.php
Finish change row per page
[qtadmin.git] / quarantine.php
CommitLineData
6df4b805 1<?php
7ef22e21 2/* vim: set ts=4 tw=4 sw=4 noet: */
b95d1cdb
MR
3 require_once 'config.php';
4 require_once $CFG->root . 'lib/db_factory.php';
5 require_once $CFG->root . 'lib/utils.inc.php';
6df4b805 6
b95d1cdb 7 function error($error) {
3056d117 8 $util = new Utils;
b95d1cdb
MR
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();
15 }
6df4b805 16
acaa44d2 17 function handleRequest($request, $ids) {
6b8a5143
MR
18 global $CFG;
19
acaa44d2
MR
20 $query = array();
21 foreach ($ids as $id) {
22 $mail_id = urldecode($id);
23 $mail = unserialize($_SESSION['mailInfo']["$mail_id"]);
24 $secret_id = $mail->secret_id;
25 $recipient = $mail->recipient;
ebed9332 26
acaa44d2
MR
27 if ($request == 'release') {
28 $amavisserver = $CFG->amavisd_db_host;
29 $policy_port = $CFG->amavis_policy_port;
30
31 $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30);
32 if (!$fp) {
33 error("$errstr ($errno)");
34 exit;
35 }
36 $out = "request=" . $request . "\r\n";
37 $out .= "mail_id=" . $mail_id . "\r\n";
38 $out .= "recipient=" . $recipient . "\r\n";
39 $out .= "secret_id=" . $secret_id . "\r\n\r\n";
40 fwrite($fp, $out);
41 $response = fread($fp, 8192);
42 fclose($fp);
43 $response = urldecode($response);
44 if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) {
45 error("Request to release failed [$out][$response]");
46 exit;
47 }
48 if ($matches[1] != '2.0.0') {
49 error($matches[2]);
50 exit;
51 }
52
53 $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'";
54 } else if ($request == 'delete') {
55 $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'";
56 } else {
57 error("Unknown operation [$request]");
58 exit;
59 }
acaa44d2 60 }
ebed9332
MR
61
62 return $query;
acaa44d2
MR
63 }
64
3056d117 65 $util = new Utils;
b95d1cdb
MR
66 $loggedIn = $util->isLoggedIn();
67 $request = isset($_GET['op']) ? $_GET['op'] : '';
68 if ($loggedIn && isset($_GET['id'])) {
acaa44d2
MR
69 $ids = explode(',', $_GET['id']);
70 $query = handleRequest($request, $ids);
b95d1cdb
MR
71 $success = $DB->update($query);
72 if (! $success) {
73 error("Message not released, contact administrator [$query]");
74 exit;
75 }
76 header('Location: index.php');
6df4b805 77 } else if ($loggedIn && $request == 'purge') {
b95d1cdb
MR
78 $marked = unserialize($_SESSION['marked']);
79 unset($_SESSION['marked']);
80 $query = array();
81 $error = array();
82 foreach ($marked as $mail_id) {
83 $query[] = "delete from msgs where mail_id = '$mail_id'";
84 $query[] = "delete from msgrcpt where mail_id = '$mail_id'";
85 $query[] = "delete from quarantine where mail_id = '$mail_id'";
86 $success = $DB->update($query);
87 if (! $success) {
88 $error[] = $mail_id;
89 }
90 }
91 if (count($error) > 0) {
92 $str = implode(', ', $error);
93 error("The following messages was not purged [$str], contact administrator");
94 exit;
95 }
96 header('Location: index.php');
97 } else if ($loggedIn) {
98 header('Location: index.php');
6df4b805
MR
99 } else {
100 header('Location: auth.php');
101 }
102
103?>
104
This page took 0.113488 seconds and 5 git commands to generate.