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