]>
Commit | Line | Data |
---|---|---|
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 | $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 | return $query; | |
62 | } | |
63 | ||
64 | $util = Utils::getInstance(); | |
65 | $loggedIn = $util->isLoggedIn(); | |
66 | $request = isset($_GET['op']) ? $_GET['op'] : ''; | |
67 | if ($loggedIn && isset($_GET['id'])) { | |
68 | $ids = explode(',', $_GET['id']); | |
69 | $query = handleRequest($request, $ids); | |
70 | /* exit; | |
71 | $mail_id = urldecode($_GET['id']); | |
72 | $mail = unserialize($_SESSION['mailInfo']["$mail_id"]); | |
73 | $secret_id = $mail->secret_id; | |
74 | $recipient = $mail->recipient; | |
75 | ||
76 | $query = array(); | |
77 | if ($request == 'release') { | |
78 | $amavisserver = $CFG->amavisd_db_host; | |
79 | $policy_port = $CFG->amavis_policy_port; | |
80 | ||
81 | $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30); | |
82 | if (!$fp) { | |
83 | error("$errstr ($errno)"); | |
84 | exit; | |
85 | } | |
86 | $out = "request=" . $request . "\r\n"; | |
87 | $out .= "mail_id=" . $mail_id . "\r\n"; | |
88 | $out .= "recipient=" . $recipient . "\r\n"; | |
89 | $out .= "secret_id=" . $secret_id . "\r\n\r\n"; | |
90 | fwrite($fp, $out); | |
91 | $response = fread($fp, 8192); | |
92 | fclose($fp); | |
93 | $response = urldecode($response); | |
94 | if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) { | |
95 | error("Request to release failed [$out][$response]"); | |
96 | exit; | |
97 | } | |
98 | if ($matches[1] != '2.0.0') { | |
99 | error($matches[2]); | |
100 | exit; | |
101 | } | |
102 | ||
103 | $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'"; | |
104 | } else if ($request == 'delete') { | |
105 | $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'"; | |
106 | } else { | |
107 | error("Unknown operation [$request]"); | |
108 | exit; | |
109 | } | |
110 | print_r($query); | |
111 | exit;*/ | |
112 | $success = $DB->update($query); | |
113 | if (! $success) { | |
114 | error("Message not released, contact administrator [$query]"); | |
115 | exit; | |
116 | } | |
117 | header('Location: index.php'); | |
118 | } else if ($loggedIn && $request == 'purge') { | |
119 | $marked = unserialize($_SESSION['marked']); | |
120 | unset($_SESSION['marked']); | |
121 | $query = array(); | |
122 | $error = array(); | |
123 | foreach ($marked as $mail_id) { | |
124 | $query[] = "delete from msgs where mail_id = '$mail_id'"; | |
125 | $query[] = "delete from msgrcpt where mail_id = '$mail_id'"; | |
126 | $query[] = "delete from quarantine where mail_id = '$mail_id'"; | |
127 | $success = $DB->update($query); | |
128 | if (! $success) { | |
129 | $error[] = $mail_id; | |
130 | } | |
131 | } | |
132 | if (count($error) > 0) { | |
133 | $str = implode(', ', $error); | |
134 | error("The following messages was not purged [$str], contact administrator"); | |
135 | exit; | |
136 | } | |
137 | header('Location: index.php'); | |
138 | } else if ($loggedIn) { | |
139 | header('Location: index.php'); | |
140 | } else { | |
141 | header('Location: auth.php'); | |
142 | } | |
143 | ||
144 | ?> | |
145 |