]> git.datanom.net - qtadmin.git/blob - quarantine.php
initial release
[qtadmin.git] / quarantine.php
1 <?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';
6
7 function error($error) {
8 $util = Utils::getInstance();
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 }
16
17 $util = Utils::getInstance();
18 $loggedIn = $util->isLoggedIn();
19 $request = isset($_GET['op']) ? $_GET['op'] : '';
20 if ($loggedIn && isset($_GET['id'])) {
21 $mail_id = urldecode($_GET['id']);
22 $mail = unserialize($_SESSION['mailInfo']["$mail_id"]);
23 $secret_id = $mail->secret_id;
24 $recipient = $mail->recipient;
25
26 $query = array();
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 }
60 $success = $DB->update($query);
61 if (! $success) {
62 error("Message not released, contact administrator [$query]");
63 exit;
64 }
65 header('Location: index.php');
66 } else if ($loggedIn && $request == 'purge') {
67 $marked = unserialize($_SESSION['marked']);
68 unset($_SESSION['marked']);
69 $query = array();
70 $error = array();
71 foreach ($marked as $mail_id) {
72 $query[] = "delete from msgs where mail_id = '$mail_id'";
73 $query[] = "delete from msgrcpt where mail_id = '$mail_id'";
74 $query[] = "delete from quarantine where mail_id = '$mail_id'";
75 $success = $DB->update($query);
76 if (! $success) {
77 $error[] = $mail_id;
78 }
79 }
80 if (count($error) > 0) {
81 $str = implode(', ', $error);
82 error("The following messages was not purged [$str], contact administrator");
83 exit;
84 }
85 header('Location: index.php');
86 } else if ($loggedIn) {
87 header('Location: index.php');
88 } else {
89 header('Location: auth.php');
90 }
91
92 ?>
93
This page took 0.077783 seconds and 6 git commands to generate.