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