1<?php # $Id$
2
3/* Show the list of people caught up in the CR system
4 * for the current user. */
5
6require_once 'login.inc';
7require_once 'functions.inc';
8require_once 'email-validation.inc';
9
10head("challenge response anti-spam thingamy");
11
12db_connect();
13
14if (isset($_POST['confirm_them']) && isset($_POST['confirm']) && is_array($_POST['confirm'])) {
15	foreach ($_POST['confirm'] as $address) {
16		db_query_safe("insert into accounts.confirmed (email, ts) values (?, NOW())", [$address]);
17	}
18}
19
20// TODO: Where does $user come from here?
21$res = db_query_safe(
22  "select distinct sender from phpmasterdb.users left join accounts.quarantine on users.email = rcpt " .
23  "where username=? and not isnull(id)", [$user]);
24
25$inmates = [];
26while ($row = mysql_fetch_row($res)) {
27	$inmates[] = $row[0];
28}
29
30function sort_by_domain($a, $b)
31{
32	list($al, $ad) = explode('@', $a, 2);
33	list($bl, $bd) = explode('@', $b, 2);
34
35	$x = strcmp($ad, $bd);
36	if ($x)
37		return $x;
38
39	return strcmp($al, $bl);
40}
41
42usort($inmates, 'sort_by_domain');
43
44?>
45
46<h1>Addresses in quarantine for <?php echo hsc($user); ?>@php.net</h1>
47
48<form method="post" action="<?php echo hsc($_SERVER['PHP_SELF']); ?>">
49
50<table>
51	<tr>
52		<td>&nbsp;</td>
53		<td>Sender</td>
54		<td>Domain</td>
55	</tr>
56
57<?php
58$i = 0;
59foreach ($inmates as $prisoner) {
60	list($localpart, $domain) = explode('@', $prisoner, 2);
61	$bgcolor = ($i & 1) ? '#eeeeee' : '#ffffff';
62?>
63<tr bgcolor="<?php echo $bgcolor; ?>">
64	<td><input type="checkbox" name="confirm[]" value="<?php echo hsc($prisoner) ?>"/></td>
65	<td align="right"><?php echo hsc($localpart) ?></td>
66	<td align="left">@ <?php echo hsc($domain) ?></td>
67</tr>
68<?php
69}
70?>
71</table>
72
73<p>
74If you see an address listed here that you are 100% sure is a legitimate
75sender, you may tick the appropriate box and confirm them.  Quarantine is
76processed every 15 minutes; once you have confirmed an address, be prepared to
77wait that long before the mail is delivered.
78</p>
79
80<input type="submit" name="confirm_them" value="Confirm Ticked Senders"/>
81
82</form>
83
84<?php
85$res = db_query_safe(
86  "select count(id) from phpmasterdb.users left join accounts.quarantine on users.email = rcpt " .
87  " where username=?", [$user]);
88
89$n = 0;
90if (mysql_num_rows($res) > 0) {
91	$n = mysql_result($res, 0);
92}
93
94echo "You have <b>$n</b> messages in quarantine<br>";
95
96foot();
97?>
98