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