]> git.datanom.net - qtadmin.git/blame - quarantine.php
fix bug
[qtadmin.git] / quarantine.php
CommitLineData
6df4b805
MR
1<?php
2/* vim: set ts=4 tw=0 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
MR
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 }
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
MR
26 //echo "$mail_id $secret_id $recipient";
27
acaa44d2
MR
28 if ($request == 'release') {
29 $amavisserver = $CFG->amavisd_db_host;
30 $policy_port = $CFG->amavis_policy_port;
31
32 $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30);
33 if (!$fp) {
34 error("$errstr ($errno)");
35 exit;
36 }
37 $out = "request=" . $request . "\r\n";
38 $out .= "mail_id=" . $mail_id . "\r\n";
39 $out .= "recipient=" . $recipient . "\r\n";
40 $out .= "secret_id=" . $secret_id . "\r\n\r\n";
41 fwrite($fp, $out);
42 $response = fread($fp, 8192);
43 fclose($fp);
44 $response = urldecode($response);
45 if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) {
46 error("Request to release failed [$out][$response]");
47 exit;
48 }
49 if ($matches[1] != '2.0.0') {
50 error($matches[2]);
51 exit;
52 }
53
54 $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'";
55 } else if ($request == 'delete') {
56 $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'";
57 } else {
58 error("Unknown operation [$request]");
59 exit;
60 }
acaa44d2 61 }
ebed9332
MR
62
63 return $query;
acaa44d2
MR
64 }
65
b95d1cdb
MR
66 $util = Utils::getInstance();
67 $loggedIn = $util->isLoggedIn();
68 $request = isset($_GET['op']) ? $_GET['op'] : '';
69 if ($loggedIn && isset($_GET['id'])) {
acaa44d2
MR
70 $ids = explode(',', $_GET['id']);
71 $query = handleRequest($request, $ids);
ebed9332
MR
72/* exit;
73 $mail_id = urldecode($_GET['id']);
b95d1cdb
MR
74 $mail = unserialize($_SESSION['mailInfo']["$mail_id"]);
75 $secret_id = $mail->secret_id;
76 $recipient = $mail->recipient;
6df4b805 77
b95d1cdb
MR
78 $query = array();
79 if ($request == 'release') {
80 $amavisserver = $CFG->amavisd_db_host;
81 $policy_port = $CFG->amavis_policy_port;
6df4b805 82
b95d1cdb
MR
83 $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30);
84 if (!$fp) {
85 error("$errstr ($errno)");
86 exit;
87 }
88 $out = "request=" . $request . "\r\n";
89 $out .= "mail_id=" . $mail_id . "\r\n";
90 $out .= "recipient=" . $recipient . "\r\n";
91 $out .= "secret_id=" . $secret_id . "\r\n\r\n";
92 fwrite($fp, $out);
93 $response = fread($fp, 8192);
94 fclose($fp);
95 $response = urldecode($response);
96 if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) {
97 error("Request to release failed [$out][$response]");
98 exit;
99 }
100 if ($matches[1] != '2.0.0') {
101 error($matches[2]);
102 exit;
103 }
6df4b805 104
b95d1cdb
MR
105 $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'";
106 } else if ($request == 'delete') {
107 $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'";
108 } else {
109 error("Unknown operation [$request]");
110 exit;
8f1d196f 111 }
ebed9332 112 print_r($query);
8f1d196f 113 exit;*/
b95d1cdb
MR
114 $success = $DB->update($query);
115 if (! $success) {
116 error("Message not released, contact administrator [$query]");
117 exit;
118 }
119 header('Location: index.php');
6df4b805 120 } else if ($loggedIn && $request == 'purge') {
b95d1cdb
MR
121 $marked = unserialize($_SESSION['marked']);
122 unset($_SESSION['marked']);
123 $query = array();
124 $error = array();
125 foreach ($marked as $mail_id) {
126 $query[] = "delete from msgs where mail_id = '$mail_id'";
127 $query[] = "delete from msgrcpt where mail_id = '$mail_id'";
128 $query[] = "delete from quarantine where mail_id = '$mail_id'";
129 $success = $DB->update($query);
130 if (! $success) {
131 $error[] = $mail_id;
132 }
133 }
134 if (count($error) > 0) {
135 $str = implode(', ', $error);
136 error("The following messages was not purged [$str], contact administrator");
137 exit;
138 }
139 header('Location: index.php');
140 } else if ($loggedIn) {
141 header('Location: index.php');
6df4b805
MR
142 } else {
143 header('Location: auth.php');
144 }
145
146?>
147
This page took 0.093132 seconds and 5 git commands to generate.