forked from nicolasb827/sgwi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.php
231 lines (207 loc) · 7.65 KB
/
connect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/***********************************************
SQLgrey Web Interface
Filename: connect.php
Purpose: Renders the email/domains pages
Version: 1.1.8
************************************************/
require "includes/functions.inc.php";
require "includes/connect.inc.php";
isset($_GET["action"]) ? $action = $_GET["action"] : $action = "";
// For sort order.
isset($_GET["csort"]) ? $csort = $_GET["csort"] : $csort = "";
isset($_GET["sort"]) ? $sort = $_GET["sort"] : $sort = "";
if ($sort==null || $sort=="") {
$sort = "sender_name";
}
$dir = "asc";
$ndir = "desc";
if ($sort == $csort && $_GET["order"] == "desc") {
$dir = "desc";
$ndir = "asc";
}
// Perform demanded action.
$clearit = '<br /><br /><a class="navlike" href="connect.php">Clear this report</a>';
$report2 = "";
switch ($action) {
case "act":
isset($_POST["acttype"]) ? $acttype = $_POST["acttype"] : $acttype = "";
isset($_POST["chk"]) ? $chk = $_POST["chk"] : $chk = "";
switch ($acttype) {
case "dodelete":
// For batch deleting.
if ($chk == '') {
$report = '<br />Nothing was selected - nothing has been deleted.'.$clearit;
} else {
foreach ($chk as $args) {
$parts = explode("@@", $args);
forget_entry($parts[0], $parts[1], $parts[2], $parts[3]);
}
$report = $deleted.$clearit;
}
break;
case "domove":
// For batch moving to whitelist.
if ($chk == '') {
$report = '<br />Nothing was selected - nothing has been moved.'.$clearit;
} else {
foreach ($chk as $args) {
$parts = explode("@@", $args);
move_entry($parts[0], $parts[1], $parts[2], $parts[3]);
}
$report = $moved.$clearit;
}
break;
case "":
$report = '<br />Please select Forget... or Move...';
break;
}
break;
case "del_old":
$year = $_POST["year"];
$month = $_POST["month"];
$day = $_POST["day"];
$hour = $_POST["hour"];
$minute = $_POST["minute"];
$seconds = $_POST["seconds"];
$err = 0;
if ($year < 2000 || $year > 9999) $err = 1;
else if ($month < 1 || $month > 12) $err = 1;
else if ($day < 1 || $day > 31) $err = 1;
else if ($hour < 0 || $hour > 23) $err = 1;
else if ($minute < 0 || $minute > 59) $err = 1;
else if ($seconds < 0 || $seconds > 60) $err = 1; # 60 indeed...
del_older_than($year, $month, $day, $hour, $minute, $seconds, $err);
$report2 = $message.$warning;
$report = "";
break;
case "":
$report = "";
break;
}
// For the header.
$query = "SELECT COUNT(*) AS count FROM connect";
$result = do_query($query);
$n = fetch_row($result);
/* mysql> describe connect;
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| sender_name | varchar(64) | | | | |
| sender_domain | varchar(255) | | | | |
| src | varchar(39) | | MUL | | |
| rcpt | varchar(255) | | | | |
| first_seen | timestamp(14) | YES | MUL | NULL | |
+---------------+---------------+------+-----+---------+-------+
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Greylisted hosts/domains</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
</head>
<body>
<div id="page">
<div class="navcontainer">
<?php shownav('grey','','con','con'); ?>
</div>
<table width="100%" border="0" summary="header">
<tr>
<td>
<h1>Greylisted hosts/domains (<?php echo $n["count"] . ")" ?></h1>
</td>
<td align="right">
<a class="navlike" href="#end" title="End of List">EoL</a>
</td>
</tr>
</table>
<table border="0" summary="sortbar"><?php echo ('
<tr>
<td width="20"> </td>
<td width="210"><b><a href="connect.php?sort=sender_name&csort='.$sort.'&order='.$ndir.'">Sender name</a></b></td>
<td width="190"><b><a href="connect.php?sort=sender_domain&csort='.$sort.'&order='.$ndir.'">Sender domain</a></b></td>
<td width="100"><b><a href="connect.php?sort=src&csort='.$sort.'&order='.$ndir.'">IP address</a></b></td>
<td width="260"><b><a href="connect.php?sort=rcpt&csort='.$sort.'&order='.$ndir.'">Recipient</a></b></td>
<td width="120"><b><a href="connect.php?sort=first_seen&csort='.$sort.'&order='.$ndir.'">Seen at</a></b></td>
</tr>
')?></table>
<form method="post" action="connect.php?action=act">
<div id="table_con">
<table border="0" summary="data">
<tr><td><a name="top"></a></td></tr>
<?php
if ($sort == "sender_name")
$order = "sender_name ".$dir.", sender_domain ".$dir;
else if ($sort == "sender_domain")
$order = "sender_domain ".$dir.", sender_name ".$dir;
else
$order = $sort." ".$dir;
$query = "SELECT sender_name, sender_domain, src, rcpt, first_seen FROM connect ORDER BY ".$order;
$result = do_query($query);
while($line = fetch_row($result)) {
$sn = $line["sender_name"];
$sd = $line["sender_domain"];
$src = $line["src"];
$sr = $line["rcpt"];
$fs = $line["first_seen"];
echo ('
<tr>
<td width="20"><input type="checkbox" name="chk[]" value="'.$sn.'@@'.$sd.'@@'.$src.'@@'.$sr.'" /></td>
<td width="210"><span title="'.$sn.'">'.shorten_it($sn, 30).'</span></td>
<td width="190"><span title="'.$sd.'">'.shorten_it($sd, 30).'</span></td>
<td width="100"><span title="'.$src.'">'.shorten_it($src, 15).'</span> </td>
<td width="260"><span title="'.$sr.'">'.shorten_it($sr, 40).'</span></td>
<td width="120">'.strip_millisecs($fs).'</td>
</tr>
');
}
?>
<tr><td><a name="end"></a></td></tr>
</table>
</div>
<br />
<table width="100%" summary="options">
<tr>
<td>
<input type="radio" name="acttype" value="dodelete" /> Forget (delete) selected entries<br />
<input type="radio" name="acttype" value="domove" /> Move selected entries to whitelist
</td>
<td align="right">
<a class="navlike" href="#top" title="Top of List">ToL</a>
</td>
</tr>
<tr>
<td colspan="2"><input class="btn" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php if (! $report == '' ) echo '<span class="alert">'.$report.'</span>'; ?>
<div id="form">
<h2>Delete older than...</h2>
<form method="post" action="connect.php?action=del_old&sort=first_seen&csort=first_seen&order=asc">
<table summary="date">
<tr>
<td>y</td><td>m</td><td>d</td><td>h</td><td>m</td><td>s</td>
</tr>
<tr class="datefld">
<td><input type="text" value="0" name="year" />-</td>
<td><input type="text" value="0" name="month" />-</td>
<td><input type="text" value="0" name="day" /> </td>
<td><input type="text" value="0" name="hour" />:</td>
<td><input type="text" value="0" name="minute" />:</td>
<td><input type="text" value="0" name="seconds" /></td>
<td><input class="btn" type="submit" value="Delete" /></td>
</tr>
</table>
</form>
</div>
<?php if (! $report2 == '' ) echo '<span class="alert">'.$report2.'</span>'; ?>
<div id="footer">
<?php include "includes/copyright.inc.php" ?>
</div>
</div>
</body>
</html>