]>
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 | } | |
62 | ||
63 | $util = Utils::getInstance(); | |
64 | $loggedIn = $util->isLoggedIn(); | |
65 | $request = isset($_GET['op']) ? $_GET['op'] : ''; | |
66 | if ($loggedIn && isset($_GET['id'])) { | |
67 | $ids = explode(',', $_GET['id']); | |
68 | $query = handleRequest($request, $ids); | |
69 | exit; | |
70 | /* $mail_id = urldecode($_GET['id']); | |
71 | $mail = unserialize($_SESSION['mailInfo']["$mail_id"]); | |
72 | $secret_id = $mail->secret_id; | |
73 | $recipient = $mail->recipient; | |
74 | ||
75 | $query = array(); | |
76 | if ($request == 'release') { | |
77 | $amavisserver = $CFG->amavisd_db_host; | |
78 | $policy_port = $CFG->amavis_policy_port; | |
79 | ||
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 | } | |
101 | ||
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; | |
108 | }*/ | |
109 | $success = $DB->update($query); | |
110 | if (! $success) { | |
111 | error("Message not released, contact administrator [$query]"); | |
112 | exit; | |
113 | } | |
114 | header('Location: index.php'); | |
115 | } else if ($loggedIn && $request == 'purge') { | |
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'); | |
137 | } else { | |
138 | header('Location: auth.php'); | |
139 | } | |
140 | ||
141 | ?> | |
142 |