]> git.datanom.net - qtadmin.git/blob - quarantine.php
fix bug
[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 function handleRequest($request, $ids) {
18 global $CFG;
19
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;
26 //echo "$mail_id $secret_id $recipient";
27
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 }
61 }
62
63 return $query;
64 }
65
66 $util = Utils::getInstance();
67 $loggedIn = $util->isLoggedIn();
68 $request = isset($_GET['op']) ? $_GET['op'] : '';
69 if ($loggedIn && isset($_GET['id'])) {
70 $ids = explode(',', $_GET['id']);
71 $query = handleRequest($request, $ids);
72 /* exit;
73 $mail_id = urldecode($_GET['id']);
74 $mail = unserialize($_SESSION['mailInfo']["$mail_id"]);
75 $secret_id = $mail->secret_id;
76 $recipient = $mail->recipient;
77
78 $query = array();
79 if ($request == 'release') {
80 $amavisserver = $CFG->amavisd_db_host;
81 $policy_port = $CFG->amavis_policy_port;
82
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 }
104
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;
111 }
112 print_r($query);
113 exit;*/
114 $success = $DB->update($query);
115 if (! $success) {
116 error("Message not released, contact administrator [$query]");
117 exit;
118 }
119 header('Location: index.php');
120 } else if ($loggedIn && $request == 'purge') {
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');
142 } else {
143 header('Location: auth.php');
144 }
145
146 ?>
147
This page took 0.164805 seconds and 6 git commands to generate.