2 require_once "common.php";
3 require_once "header.php";
5 $spamfilter_target_info = Array(
6 "p"=>Array("short_text" => "usermsg", "long_text" => "User message"),
7 "n"=>Array("short_text" => "usernotice", "long_text" => "User notice"),
8 "c"=>Array("short_text" => "chanmsg", "long_text" => "Channel message"),
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"),
16 "u"=>Array("short_text" => "usermask", "long_text" => "User mask (nick!user@host:realname)"),
19 function spamfilter_targets_to_string($targets)
21 global $spamfilter_target_info;
24 for ($i = 0, $targs = ""; $i < strlen($targets); $i++
)
27 if (isset($spamfilter_target_info[$c]))
28 $ret .= $spamfilter_target_info[$c]["short_text"].", ";
32 $ret = rtrim($ret,", ");
36 function spamfilter_targets_to_string_with_info($targets)
38 global $spamfilter_target_info;
41 for ($i = 0, $targs = ""; $i < strlen($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>, ";
49 $ret = rtrim($ret,", ");
53 function spamfilter_target_name_to_char($name)
55 global $spamfilter_target_info;
57 foreach ($spamfilter_target_info as $char=>$e)
59 if ($e["short_text"] == $name)
65 function spamfilter_targets_from_array_to_chars($ar)
68 foreach ($ar as $name)
70 $c = spamfilter_target_name_to_char($name);
82 if (($sf = (isset($_POST['sf_add'])) ? $_POST['sf_add'] : false)) // if it was a spamfilter entry
84 if (!current_user_can(PERMISSION_SPAMFILTER_ADD
))
85 Message
::Fail("Could not add Spamfilter entry: Permission denied");
90 $targets = []; // empty arrae
91 foreach($_POST as $key => $value)
93 if (substr($key, 0, 7) == "target_")
94 $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
97 Message
::Fail("No target was specified");
99 if (!isset($_POST['sf_bantype']))
100 Message
::Fail("No action was chosen");
105 $bantype = $_POST['sf_bantype'];
106 $targ_chars = spamfilter_targets_from_array_to_chars($targets);
107 /* duplicate code for now [= */
108 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
109 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
110 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
112 if (!$banlen_d && !$banlen_h && !$banlen_w)
118 $duration .= $banlen_w;
120 $duration .= $banlen_d;
122 $duration .= $banlen_h;
124 $match_type = $_POST['matchtype']; // should default to 'simple'
125 $reason = isset($_POST['ban_reason']) ? $_POST['ban_reason'] : "No reason";
126 $soft = (isset($_POST['soft'])) ? true : false;
128 $bantype = "soft-$bantype";
129 if ($rpc->spamfilter()->add($sf, $match_type, $targ_chars, $bantype, $duration, $reason))
130 Message::Success("Added spamfilter entry \"
$sf\" [match type
: $match_type] [targets
: $targ_chars] [reason
: $reason]");
132 Message::Fail("Could not add spamfilter entry \"
$sf\" [match type
: $match_type] [targets
: $targ_chars] [reason
: $reason]: $rpc->error
");
136 else if (!empty($_POST['sf']))
138 if (!current_user_can(PERMISSION_SPAMFILTER_DEL))
139 Message::Fail("Could not delete Spamfilter entry
or entries
: Permission denied
");
141 foreach ($_POST['sf'] as $key => $value)
143 $tok = explode(",", $value);
144 $name = base64_decode($tok[0]);
145 $match_type = base64_decode($tok[1]);
146 $spamfilter_targets = base64_decode($tok[2]);
147 $ban_action = base64_decode($tok[3]);
148 if ($rpc->spamfilter()->delete($name, $match_type, $spamfilter_targets, $ban_action))
149 Message::Success("Spamfilter on
$name has been removed
");
151 Message::Fail("Unable to remove spamfilter on
$name: $rpc->error
");
157 $spamfilter = $rpc->spamfilter()->getAll();
160 <h4>Spamfilter Overview</h4><br>
161 <p><button type="button
" class="btn btn
-primary
" data-toggle="modal
" data-target="#myModal" <?php echo (current_user_can(PERMISSION_SPAMFILTER_ADD)) ? "" : "disabled"; ?>>
164 <div
class="modal fade" id
="myModal" tabindex
="-1" role
="dialog" aria
-labelledby
="confirmModalCenterTitle" aria
-hidden
="true">
165 <div
class="modal-dialog modal-dialog-centered" role
="document">
166 <div
class="modal-content">
167 <div
class="modal-header">
168 <h5
class="modal-title" id
="myModalLabel">Add
new Spamfilter Entry
</h5
>
169 <button type
="button" class="close" data
-dismiss
="modal" aria
-label
="Close">
170 <span aria
-hidden
="true">×
;</span
>
173 <div
class="modal-body">
175 <form action
="spamfilter.php" method
="post">
176 <div
class="align_label curvy">Match
 
;type
: </div
> <select name
="matchtype" id
="matchtype">
177 <option value
="simple">Simple
</option
>
178 <option value
="regex">Regular Expression
</option
>
180 <div
class="align_label curvy">Entry
: </div
> <input
class="curvy" type
="text" id
="sf_add" name
="sf_add"><br
>
182 <div
class="align_label curvy"><label
for="banlen_w">Targets
: </label
></div
>
185 foreach ($spamfilter_target_info as $letter=>$e)
187 $shortname = $e['short_text'];
188 $longname = $e['long_text'];
190 echo "<div class=\"align_label curvy\"><label></label></div>";
192 echo "<input type=\"checkbox\" class=\"curvy\" id=\"target_$shortname\" name=\"target_$shortname\">$longname<br>\n";
195 <div
class="align_label curvy">Action
: </div
> <select name
="sf_bantype" id
="sf_bantype">
196 <option value
=""></option
>
197 <optgroup label
="Bans">
198 <option value
="kline">Kill
Line (KLine
)</option
>
199 <option value
="gline">Global Kill
Line (GLine
)</option
>
200 <option value
="zline">Zap
Line (ZLine
)</option
>
201 <option value
="gzline">Global Zap
Line (GZLine
)</option
>
204 <optgroup label
="Restrictions">
205 <option value
="tempshun">Temporary
Shun (Session only
)</option
>
206 <option value
="shun">Shun
</option
>
207 <option value
="block">Block
</option
>
208 <option value
="dccblock">DCC Block
</option
>
209 <option value
="viruschan">Send to
"Virus Chan"</option
>
211 <optgroup label
="Other">
212 <option value
="warn">Warn the user
</option
>
215 <div
class="align_label curvy"><label
for="banlen_w">Duration
: </label
></div
>
216 <select name
="banlen_w" id
="banlen_w">
218 for ($i = 0; $i <= 56; $i++
)
221 echo "<option value=\"0w\"></option>";
224 $w = ($i == 1) ? "week" : "weeks";
225 echo "<option value=\"$i" . "w\"
>$i $w" . "</option>";
230 <select name
="banlen_d" id
="banlen_d">
232 for ($i = 0; $i <= 31; $i++
)
235 echo "<option value=\"0d\"></option>";
238 $d = ($i == 1) ? "day" : "days";
239 echo "<option value=\"$i" . "d\"
>$i $d" . "</option>";
244 <select name
="banlen_h" id
="banlen_h">
246 for ($i = 0; $i <= 24; $i++
)
249 echo "<option value=\"0d\"></option>";
252 $h = ($i == 1) ? "hour" : "hours";
253 echo "<option value=\"$i" . "h\"
>$i $h" . "</option>";
258 <input
class="curvy" type
="checkbox" id
="soft" name
="soft">Don
't affect logged-in users (soft)
259 <br><div class="align_label curvy"><label for="ban_reason">Reason: </label></div>
260 <input class="curvy" type="text" id="ban_reason" name="ban_reason"><br>
263 <div class="modal-footer">
264 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
265 <button type="submit" action="post" class="btn btn-danger">Add Spamfilter Entry</button>
267 </div></div></div></div>
270 <table class="container-xxl table-sm table-responsive caption-top table-striped">
271 <thead class="table-primary"><form action="spamfilter.php" method="post">
272 <th><input type="checkbox" label='selectall
' onClick="toggle_sf(this)" /></th>
277 <th>Action Duration</th>
284 foreach($spamfilter as $sf)
287 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>";
288 echo "<td>".$sf->match_type."</td>";
289 echo "<td>".$sf->name."</td>";
290 echo "<td>".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)."</td>";
291 echo "<td><span class=\"badge rounded-pill badge-info\">".$sf->ban_action."</span></td>";
292 echo "<td>".$sf->ban_duration_string."</td>";
293 echo "<td>".$sf->reason."</td>";
294 echo "<td>".show_nick_only($sf->set_by)."</td>";
295 echo "<td>".$sf->set_at_string."</td>";
298 ?></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2" <?php echo (current_user_can(PERMISSION_SPAMFILTER_DEL)) ? "" : "disabled"; ?>>
301 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
302 <div class="modal-dialog modal-dialog-centered" role="document">
303 <div class="modal-content">
304 <div class="modal-header">
305 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
306 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
307 <span aria-hidden="true">×</span>
310 <div class="modal-body">
311 Are you sure you want to do this?<br>
312 This cannot be undone.
314 <div class="modal-footer">
315 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
316 <button type="submit" action="post" class="btn btn-danger">Delete</button>
325 <?php require_once 'footer
.php
'; ?>