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