]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - spamfilter.php
Spamfilter list: shorten target a bit more and add a legend.
[irc/unrealircd/unrealircd-webpanel.git] / spamfilter.php
CommitLineData
0f627622
VP
1<?php
2require_once "common.php";
0f627622
VP
3require_once "header.php";
4
6bc0b9a0
BM
5$spamfilter_target_info = Array(
6 "c"=>Array("short_text" => "chanmsg", "long_text" => "Channel message"),
7 "p"=>Array("short_text" => "usermsg", "long_text" => "User message"),
8 "n"=>Array("short_text" => "usernotice", "long_text" => "User notice"),
9 "N"=>Array("short_text" => "channotice", "long_text" => "Channel notice"),
10 "P"=>Array("short_text" => "part", "long_text" => "Part message"),
11 "q"=>Array("short_text" => "quit", "long_text" => "Quit message"),
12 "d"=>Array("short_text" => "dcc", "long_text" => "DCC Filename"),
13 "a"=>Array("short_text" => "away", "long_text" => "Away message"),
14 "t"=>Array("short_text" => "topic", "long_text" => "Channel topic"),
15 "T"=>Array("short_text" => "message-tag", "long_text" => "Message tag"),
16 "u"=>Array("short_text" => "usermask", "long_text" => "User mask"),
17);
18
19function spamfilter_targets_to_string($targets)
20{
21 GLOBAL $spamfilter_target_info;
22
23 $ret = '';
24 for ($i = 0, $targs = ""; $i < strlen($targets); $i++)
25 {
26 $c = $targets[$i];
27 if (isset($spamfilter_target_info[$c]))
28 $ret .= $spamfilter_target_info[$c]["short_text"].", ";
29 else
30 $ret .= "??, ";
31 }
32 $ret = rtrim($ret,", ");
33 return $ret;
34}
35
36function spamfilter_targets_to_string_with_info($targets)
37{
38 GLOBAL $spamfilter_target_info;
39
40 $ret = '';
41 for ($i = 0, $targs = ""; $i < strlen($targets); $i++)
42 {
43 $c = $targets[$i];
44 if (isset($spamfilter_target_info[$c]))
45 $ret .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"".$spamfilter_target_info[$c]["long_text"]."\" style=\"border-bottom: 1px dotted #000000\">".$spamfilter_target_info[$c]["short_text"]."</span>, ";
46 else
47 $ret .= "??, ";
48 }
49 $ret = rtrim($ret,", ");
50 return $ret;
51}
52
53
0f627622
VP
54if (!empty($_POST))
55{
56
57 do_log($_POST);
58
c9bbb0e6 59 if (($sf = (isset($_POST['sf_add'])) ? $_POST['sf_add'] : false)) // if it was a spamfilter entry
0f627622
VP
60 {
61 /* get targets */
62 $targets = []; // empty arrae
63 foreach($_POST as $key => $value)
64 {
65 if (substr($key, 0, 7) == "target_")
66 $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
67 }
68 if (empty($targets))
69 Message::Fail("No target was specified");
70
71 if (!isset($_POST['sf_bantype']))
72 Message::Fail("No action was chosen");
73
74 else
75 {
76
77 $bantype = $_POST['sf_bantype'];
78 $targ_chars = "";
79 foreach($targets as $targ)
80 {
81 switch ($targ) {
82 case "channel":
83 $targ_chars .= "c";
84 break;
85 case "private":
86 $targ_chars .= "p";
87 break;
88 case "channel-notice":
89 $targ_chars .= "N";
90 break;
91 case "private-notice":
92 $targ_chars .= "n";
93 break;
94 case "part":
95 $targ_chars .= "P";
96 break;
97 case "quit":
98 $targ_chars .= "q";
99 break;
100 case "dcc":
101 $targ_chars .= "d";
102 break;
103 case "away":
104 $targ_chars .= "a";
105 break;
106 case "topic":
107 $targ_chars .= "t";
108 break;
109 case "messagetag":
110 $targ_chars .= "T";
111 break;
112 case "user":
113 $targ_chars .= "u";
114 break;
115 }
116 }
117 /* duplicate code for now [= */
118 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
119 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
120 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
121 $duration = "";
122 if (!$banlen_d && !$banlen_h && !$banlen_w)
123 $duration .= "0";
124
125 else
126 {
127 if ($banlen_w)
128 $duration .= $banlen_w;
129 if ($banlen_d)
130 $duration .= $banlen_d;
131 if ($banlen_h)
132 $duration .= $banlen_h;
133 }
134 $match_type = $_POST['matchtype']; // should default to 'simple'
135 $reason = isset($_POST['ban_reason']) ? $_POST['ban_reason'] : "No reason";
136 $soft = (isset($_POST['soft'])) ? true : false;
137 if ($soft)
138 $targ_chars = "%" . $targ_chars;
139 if ($rpc->spamfilter()->add($sf, $match_type, $targ_chars, $bantype, $duration, $reason))
140 Message::Success("Added spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]");
141 else
142 Message::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error");
143 }
144 }
145 else if (!empty($_POST['sf']))
146 foreach ($_POST as $key => $value)
147 foreach ($value as $tok)
148 {
149 $tok = explode(",", $tok);
150 $name = base64_decode($tok[0]);
151 $match_type = base64_decode($tok[1]);
152 $spamfilter_targets = base64_decode($tok[2]);
153 $ban_action = base64_decode($tok[3]);
154 if ($rpc->spamfilter()->delete($name, $match_type, $spamfilter_targets, $ban_action))
155 Message::Success("Spamfilter on $name has been removed");
156 else
157 Message::Fail("Unable to remove spamfilter on $name: $rpc->error");
158 }
159
160}
161
d3697d8f 162$spamfilter = $rpc->spamfilter()->getAll();
0f627622 163?>
c88945a1
VP
164
165<h4>Spamfilter Overview</h4><br>
166<p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
167 Add entry
168 </button></p>
169 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
170 <div class="modal-dialog modal-dialog-centered" role="document">
171 <div class="modal-content">
172 <div class="modal-header">
173 <h5 class="modal-title" id="myModalLabel">Add new Spamfilter Entry</h5>
174 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
175 <span aria-hidden="true">&times;</span>
176 </button>
177 </div>
178 <div class="modal-body">
0f627622
VP
179
180 <form action="spamfilter.php" method="post">
a741bd50 181 <div class="align_label curvy">Match&nbsp;type: </div> <select name="matchtype" id="matchtype">
0f627622
VP
182 <option value="simple">Simple</option>
183 <option value="regex">Regular Expression</option>
184 </select><br>
a741bd50
BM
185 <div class="align_label curvy">Entry: </div> <input class="curvy" type="text" id="sf_add" name="sf_add"><br>
186
187 <div class="align_label curvy"><label for="banlen_w">Targets: </label></div>
188
189 <input type="checkbox" class="curvy" id="target_channel" name="target_channel">Channel messages<br>
190 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_private" name="target_private">Private messages<br>
191 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_channel_notice" name="target_channel_notice">Channel notices<br>
192 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_private_notice" name="target_private_notice">Private notices<br>
193 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_part" name="target_part">Part reason<br>
194 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_dcc" name="target_dcc">DCC Filename<br>
195 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_away" name="target_away">Away messages<br>
196 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_topic" name="target_topic">Channel topic<br>
197 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_messagetag" name="target_messagetag">MessageTags<br>
198 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_user" name="target_user">Userhost (nick!user@host:realname)<br>
199
c88945a1 200 <div class="align_label curvy">Action: </div> <select name="sf_bantype" id="sf_bantype">
0f627622
VP
201 <option value=""></option>
202 <optgroup label="Bans">
203 <option value="kline">Kill Line (KLine)</option>
204 <option value="gline">Global Kill Line (GLine)</option>
205 <option value="zline">Zap Line (ZLine)</option>
206 <option value="gzline">Global Zap Line (GZLine)</option>
207
208 </optgroup>
209 <optgroup label="Restrictions">
210 <option value="tempshun">Temporary Shun (Session only)</option>
211 <option value="shun">Shun</option>
212 <option value="block">Block</option>
213 <option value="dccblock">DCC Block</option>
214 <option value="viruschan">Send to "Virus Chan"</option>
215 </optgroup>
216 <optgroup label="Other">
217 <option value="warn">Warn the user</option>
218 </optgroup>
219 </select><br>
c88945a1 220 <div class="align_label curvy"><label for="banlen_w">Duration: </label></div>
0f627622
VP
221 <select name="banlen_w" id="banlen_w">
222 <?php
223 for ($i = 0; $i <= 56; $i++)
224 {
225 if (!$i)
226 echo "<option value=\"0w\"></option>";
227 else
228 {
229 $w = ($i == 1) ? "week" : "weeks";
230 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
231 }
232 }
233 ?>
234 </select>
235 <select name="banlen_d" id="banlen_d">
236 <?php
237 for ($i = 0; $i <= 31; $i++)
238 {
239 if (!$i)
240 echo "<option value=\"0d\"></option>";
241 else
242 {
243 $d = ($i == 1) ? "day" : "days";
244 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
245 }
246 }
247 ?>
248 </select>
249 <select name="banlen_h" id="banlen_h">
250 <?php
251 for ($i = 0; $i <= 24; $i++)
252 {
253 if (!$i)
254 echo "<option value=\"0d\"></option>";
255 else
256 {
257 $h = ($i == 1) ? "hour" : "hours";
258 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
259 }
260 }
261 ?>
a741bd50
BM
262 </select><br>
263 <input class="curvy" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
c88945a1
VP
264 <br><div class="align_label curvy"><label for="ban_reason">Reason: </label></div>
265 <input class="curvy" type="text" id="ban_reason" name="ban_reason"><br>
c88945a1
VP
266 </div>
267
268 <div class="modal-footer">
269 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
270 <button type="submit" action="post" class="btn btn-danger">Add Spamfilter Entry</button>
271 </form>
272 </div></div></div></div>
273
274
d1d9caa9 275 <table class="table table-responsive caption-top table-striped">
c88945a1 276 <thead class="table-primary"><form action="spamfilter.php" method="post">
44e93f67 277 <th><input type="checkbox" label='selectall' onClick="toggle_sf(this)" /></th>
0f627622 278 <th>Match Type</th>
a448002a
BM
279 <th>Mask</th>
280 <th>Target</th>
0f627622
VP
281 <th>Action</th>
282 <th>Action Duration</th>
0f627622 283 <th>Reason</th>
a448002a
BM
284 <th>Set By</th>
285 <th>Set On</th>
d1d9caa9 286 </thead>
0f627622
VP
287
288 <?php
d3697d8f 289 foreach($spamfilter as $sf)
0f627622
VP
290 {
291 echo "<tr>";
292 echo "<td><input type=\"checkbox\" value='" . base64_encode($sf->name).",".base64_encode($sf->match_type).",".base64_encode($sf->spamfilter_targets).",".base64_encode($sf->ban_action) . "' name=\"sf[]\"></td>";
0f627622 293 echo "<td>".$sf->match_type."</td>";
a448002a 294 echo "<td>".$sf->name."</td>";
6bc0b9a0 295 echo "<td>".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)."</td>";
a448002a
BM
296 echo "<td>".$sf->ban_action."</td>";
297 echo "<td>".$sf->ban_duration_string."</td>";
0f627622 298 echo "<td>".$sf->reason."</td>";
a448002a
BM
299 echo "<td>".$sf->set_by."</td>";
300 echo "<td>".$sf->set_at_string."</td>";
0f627622
VP
301
302 }
c88945a1
VP
303 ?></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
304 Delete selected
305 </button></p>
306 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
307 <div class="modal-dialog modal-dialog-centered" role="document">
308 <div class="modal-content">
309 <div class="modal-header">
e3f034ee 310 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
c88945a1
VP
311 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
312 <span aria-hidden="true">&times;</span>
313 </button>
314 </div>
315 <div class="modal-body">
316 Are you sure you want to do this?<br>
317 This cannot be undone.
318 </div>
319 <div class="modal-footer">
320 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
321 <button type="submit" action="post" class="btn btn-danger">Delete</button>
322
323 </div>
324 </div>
325 </div>
326 </div>
327</form></div></div>
0f627622
VP
328
329
330<?php require_once 'footer.php'; ?>