2 require_once "../inc/common.php";
3 require_once "../inc/header.php";
4 require_once "../inc/connection.php";
6 $spamfilter_target_info = Array(
7 "p"=>Array("short_text" => "usermsg", "long_text" => "User message"),
8 "n"=>Array("short_text" => "usernotice", "long_text" => "User notice"),
9 "c"=>Array("short_text" => "chanmsg", "long_text" => "Channel message"),
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"),
17 "u"=>Array("short_text" => "usermask", "long_text" => "User mask (nick!user@host:realname)"),
20 function spamfilter_targets_to_string($targets)
22 global $spamfilter_target_info;
25 for ($i = 0, $targs = ""; $i < strlen($targets); $i++
)
28 if (isset($spamfilter_target_info[$c]))
29 $ret .= $spamfilter_target_info[$c]["short_text"].", ";
33 $ret = rtrim($ret,", ");
37 function spamfilter_targets_to_string_with_info($targets)
39 global $spamfilter_target_info;
42 for ($i = 0, $targs = ""; $i < strlen($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>, ";
50 $ret = rtrim($ret,", ");
54 function spamfilter_target_name_to_char($name)
56 global $spamfilter_target_info;
58 foreach ($spamfilter_target_info as $char=>$e)
60 if ($e["short_text"] == $name)
66 function spamfilter_targets_from_array_to_chars($ar)
69 foreach ($ar as $name)
71 $c = spamfilter_target_name_to_char($name);
83 if (($sf = (isset($_POST['sf_add'])) ? $_POST['sf_add'] : false)) // if it was a spamfilter entry
85 if (!current_user_can(PERMISSION_SPAMFILTER_ADD
))
86 Message
::Fail("Could not add Spamfilter entry: Permission denied");
91 $targets = []; // empty arrae
92 foreach($_POST as $key => $value)
94 if (substr($key, 0, 7) == "target_")
95 $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
98 Message
::Fail("No target was specified");
100 if (!isset($_POST['sf_bantype']))
101 Message
::Fail("No action was chosen");
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;
113 if (!$banlen_d && !$banlen_h && !$banlen_w)
119 $duration .= $banlen_w;
121 $duration .= $banlen_d;
123 $duration .= $banlen_h;
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;
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]");
133 Message::Fail("Could not add spamfilter entry \"
$sf\" [match type
: $match_type] [targets
: $targ_chars] [reason
: $reason]: $rpc->error
");
137 else if (!empty($_POST['sf']))
139 if (!current_user_can(PERMISSION_SPAMFILTER_DEL))
140 Message::Fail("Could not delete Spamfilter entry
or entries
: Permission denied
");
142 foreach ($_POST['sf'] as $key => $value)
144 $tok = explode(",", $value);
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
");
152 Message::Fail("Unable to remove spamfilter on
$name: $rpc->error
");
158 $spamfilter = $rpc->spamfilter()->getAll();
161 <h4>Spamfilter Overview</h4><br>
162 <p><button type="button
" class="btn btn
-primary
" data-toggle="modal
" data-target="#myModal" <?php echo (current_user_can(PERMISSION_SPAMFILTER_ADD)) ? "" : "disabled"; ?>>
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
>
174 <div
class="modal-body">
176 <form action
="spamfilter.php" method
="post">
177 <div
class="align_label curvy">Match
 
;type
: </div
> <select name
="matchtype" id
="matchtype">
178 <option value
="simple">Simple
</option
>
179 <option value
="regex">Regular Expression
</option
>
181 <div
class="align_label curvy">Entry
: </div
> <input
class="curvy" type
="text" id
="sf_add" name
="sf_add"><br
>
183 <div
class="align_label curvy"><label
for="banlen_w">Targets
: </label
></div
>
186 foreach ($spamfilter_target_info as $letter=>$e)
188 $shortname = $e['short_text'];
189 $longname = $e['long_text'];
191 echo "<div class=\"align_label curvy\"><label></label></div>";
193 echo "<input type=\"checkbox\" class=\"curvy\" id=\"target_$shortname\" name=\"target_$shortname\">$longname<br>\n";
196 <div
class="align_label curvy">Action
: </div
> <select name
="sf_bantype" id
="sf_bantype">
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
>
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
>
212 <optgroup label
="Other">
213 <option value
="warn">Warn the user
</option
>
216 <div
class="align_label curvy"><label
for="banlen_w">Duration
: </label
></div
>
217 <select name
="banlen_w" id
="banlen_w">
219 for ($i = 0; $i <= 56; $i++
)
222 echo "<option value=\"0w\"></option>";
225 $w = ($i == 1) ? "week" : "weeks";
226 echo "<option value=\"$i" . "w\"
>$i $w" . "</option>";
231 <select name
="banlen_d" id
="banlen_d">
233 for ($i = 0; $i <= 31; $i++
)
236 echo "<option value=\"0d\"></option>";
239 $d = ($i == 1) ? "day" : "days";
240 echo "<option value=\"$i" . "d\"
>$i $d" . "</option>";
245 <select name
="banlen_h" id
="banlen_h">
247 for ($i = 0; $i <= 24; $i++
)
250 echo "<option value=\"0d\"></option>";
253 $h = ($i == 1) ? "hour" : "hours";
254 echo "<option value=\"$i" . "h\"
>$i $h" . "</option>";
259 <input
class="curvy" type
="checkbox" id
="soft" name
="soft">Don
't affect logged-in users (soft)
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>
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>
268 </div></div></div></div>
271 <table class="container-xxl table-sm table-responsive caption-top table-striped">
272 <thead class="table-primary"><form action="spamfilter.php" method="post">
273 <th><input type="checkbox" label='selectall
' onClick="toggle_sf(this)" /></th>
278 <th>Action Duration</th>
285 foreach($spamfilter as $sf)
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>";
289 echo "<td>".$sf->match_type."</td>";
290 echo "<td data-toggle='tooltip
' data-placement='bottom
' title='$sf->name
'>".(strlen($sf->name) > 50 ? substr($sf->name, 0, 50)."..." : $sf->name)."</td>";
291 echo "<td>".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)."</td>";
292 echo "<td><span class=\"badge rounded-pill badge-info\">".$sf->ban_action."</span></td>";
293 echo "<td>".$sf->ban_duration_string."</td>";
294 echo "<td>".$sf->reason."</td>";
295 echo "<td>".show_nick_only($sf->set_by)."</td>";
296 echo "<td>".$sf->set_at_string."</td>";
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"; ?>>
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">
306 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
307 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
308 <span aria-hidden="true">×</span>
311 <div class="modal-body">
312 Are you sure you want to do this?<br>
313 This cannot be undone.
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>
326 <?php require_once '../inc
/footer
.php
'; ?>