]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - spamfilter.php
Spamfilter: re-order things a bit: filter first, then the action, reason,
[irc/unrealircd/unrealircd-webpanel.git] / spamfilter.php
1 <?php
2 require_once "common.php";
3
4 require_once "header.php";
5
6 if (!empty($_POST))
7 {
8
9 do_log($_POST);
10
11 if (($sf = (isset($_POST['sf_add'])) ? $_POST['sf_add'] : false)) // 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
114 $spamfilter = $rpc->spamfilter()->getAll();
115 ?>
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">
131
132 <form action="spamfilter.php" method="post">
133 <div class="align_label curvy">Match&nbsp;type: </div> <select name="matchtype" id="matchtype">
134 <option value="simple">Simple</option>
135 <option value="regex">Regular Expression</option>
136 </select><br>
137 <div class="align_label curvy">Entry: </div> <input class="curvy" type="text" id="sf_add" name="sf_add"><br>
138
139 <div class="align_label curvy"><label for="banlen_w">Targets: </label></div>
140
141 <input type="checkbox" class="curvy" id="target_channel" name="target_channel">Channel messages<br>
142 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_private" name="target_private">Private messages<br>
143 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_channel_notice" name="target_channel_notice">Channel notices<br>
144 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_private_notice" name="target_private_notice">Private notices<br>
145 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_part" name="target_part">Part reason<br>
146 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_dcc" name="target_dcc">DCC Filename<br>
147 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_away" name="target_away">Away messages<br>
148 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_topic" name="target_topic">Channel topic<br>
149 <div class="align_label curvy"><label></label></div><input type="checkbox" class="curvy" id="target_messagetag" name="target_messagetag">MessageTags<br>
150 <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>
151
152 <div class="align_label curvy">Action: </div> <select name="sf_bantype" id="sf_bantype">
153 <option value=""></option>
154 <optgroup label="Bans">
155 <option value="kline">Kill Line (KLine)</option>
156 <option value="gline">Global Kill Line (GLine)</option>
157 <option value="zline">Zap Line (ZLine)</option>
158 <option value="gzline">Global Zap Line (GZLine)</option>
159
160 </optgroup>
161 <optgroup label="Restrictions">
162 <option value="tempshun">Temporary Shun (Session only)</option>
163 <option value="shun">Shun</option>
164 <option value="block">Block</option>
165 <option value="dccblock">DCC Block</option>
166 <option value="viruschan">Send to "Virus Chan"</option>
167 </optgroup>
168 <optgroup label="Other">
169 <option value="warn">Warn the user</option>
170 </optgroup>
171 </select><br>
172 <div class="align_label curvy"><label for="banlen_w">Duration: </label></div>
173 <select name="banlen_w" id="banlen_w">
174 <?php
175 for ($i = 0; $i <= 56; $i++)
176 {
177 if (!$i)
178 echo "<option value=\"0w\"></option>";
179 else
180 {
181 $w = ($i == 1) ? "week" : "weeks";
182 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
183 }
184 }
185 ?>
186 </select>
187 <select name="banlen_d" id="banlen_d">
188 <?php
189 for ($i = 0; $i <= 31; $i++)
190 {
191 if (!$i)
192 echo "<option value=\"0d\"></option>";
193 else
194 {
195 $d = ($i == 1) ? "day" : "days";
196 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
197 }
198 }
199 ?>
200 </select>
201 <select name="banlen_h" id="banlen_h">
202 <?php
203 for ($i = 0; $i <= 24; $i++)
204 {
205 if (!$i)
206 echo "<option value=\"0d\"></option>";
207 else
208 {
209 $h = ($i == 1) ? "hour" : "hours";
210 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
211 }
212 }
213 ?>
214 </select><br>
215 <input class="curvy" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
216 <br><div class="align_label curvy"><label for="ban_reason">Reason: </label></div>
217 <input class="curvy" type="text" id="ban_reason" name="ban_reason"><br>
218 </div>
219
220 <div class="modal-footer">
221 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
222 <button type="submit" action="post" class="btn btn-danger">Add Spamfilter Entry</button>
223 </form>
224 </div></div></div></div>
225
226
227 <table class="table table-responsive caption-top table-striped">
228 <thead class="table-primary"><form action="spamfilter.php" method="post">
229 <th><input type="checkbox" label='selectall' onClick="toggle_sf(this)" /></th>
230 <th>Match Type</th>
231 <th>Mask</th>
232 <th>Target</th>
233 <th>Action</th>
234 <th>Action Duration</th>
235 <th>Reason</th>
236 <th>Set By</th>
237 <th>Set On</th>
238 </thead>
239
240 <?php
241 foreach($spamfilter as $sf)
242 {
243 echo "<tr>";
244 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>";
245 echo "<td>".$sf->match_type."</td>";
246 echo "<td>".$sf->name."</td>";
247 for ($i = 0, $targs = ""; $i < strlen($sf->spamfilter_targets); $i++)
248 {
249 $c = $sf->spamfilter_targets[$i];
250 if ($c == "c")
251 $targs .= "Channel, ";
252 else if ($c == "p")
253 $targs .= "Private,";
254 else if ($c == "n")
255 $targs .= "Notice, ";
256 else if ($c == "N")
257 $targs .= "Channel notice, ";
258 else if ($c == "P")
259 $targs .= "Part message, ";
260 else if ($c == "q")
261 $targs .= "Quit message, ";
262 else if ($c == "d")
263 $targs .= "DCC filename, ";
264 else if ($c == "a")
265 $targs .= "Away message, ";
266 else if ($c == "t")
267 $targs .= "Channel topic, ";
268 else if ($c == "T")
269 $targs .= "MessageTag, ";
270 else if ($c == "u")
271 $targs .= "Usermask, ";
272 }
273 $targs = rtrim($targs,", ");
274 echo "<td>".$targs."</td>";
275 echo "<td>".$sf->ban_action."</td>";
276 echo "<td>".$sf->ban_duration_string."</td>";
277 echo "<td>".$sf->reason."</td>";
278 echo "<td>".$sf->set_by."</td>";
279 echo "<td>".$sf->set_at_string."</td>";
280
281 }
282 ?></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
283 Delete selected
284 </button></p>
285 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
286 <div class="modal-dialog modal-dialog-centered" role="document">
287 <div class="modal-content">
288 <div class="modal-header">
289 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
290 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
291 <span aria-hidden="true">&times;</span>
292 </button>
293 </div>
294 <div class="modal-body">
295 Are you sure you want to do this?<br>
296 This cannot be undone.
297 </div>
298 <div class="modal-footer">
299 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
300 <button type="submit" action="post" class="btn btn-danger">Delete</button>
301
302 </div>
303 </div>
304 </div>
305 </div>
306 </form></div></div>
307
308
309 <?php require_once 'footer.php'; ?>