]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - spamfilter.php
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
85 $targets = []; // empty arrae
86 foreach($_POST as $key => $value)
88 if (substr($key, 0, 7) == "target_")
89 $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
92 Message
::Fail("No target was specified");
94 if (!isset($_POST['sf_bantype']))
95 Message
::Fail("No action was chosen");
100 $bantype = $_POST['sf_bantype'];
101 $targ_chars = spamfilter_targets_from_array_to_chars($targets);
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;
107 if (!$banlen_d && !$banlen_h && !$banlen_w)
113 $duration .= $banlen_w;
115 $duration .= $banlen_d;
117 $duration .= $banlen_h;
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;
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]");
127 Message
::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error");
130 else if (!empty($_POST['sf']))
131 foreach ($_POST as $key => $value)
132 foreach ($value as $tok)
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");
142 Message
::Fail("Unable to remove spamfilter on $name: $rpc->error");
147 $spamfilter = $rpc->spamfilter()->getAll();
150 <h4
>Spamfilter Overview
</h4
><br
>
151 <p
><button type
="button" class="btn btn-primary" data
-toggle
="modal" data
-target
="#myModal">
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
>
163 <div
class="modal-body">
165 <form action
="spamfilter.php" method
="post">
166 <div
class="align_label curvy">Match
 
;type
: </div
> <select name
="matchtype" id
="matchtype">
167 <option value
="simple">Simple
</option
>
168 <option value
="regex">Regular Expression
</option
>
170 <div
class="align_label curvy">Entry
: </div
> <input
class="curvy" type
="text" id
="sf_add" name
="sf_add"><br
>
172 <div
class="align_label curvy"><label
for="banlen_w">Targets
: </label
></div
>
175 foreach ($spamfilter_target_info as $letter=>$e)
177 $shortname = $e['short_text'];
178 $longname = $e['long_text'];
180 echo "<div class=\"align_label curvy\"><label></label></div>";
182 echo "<input type=\"checkbox\" class=\"curvy\" id=\"target_$shortname\" name=\"target_$shortname\">$longname<br>\n";
185 <div
class="align_label curvy">Action
: </div
> <select name
="sf_bantype" id
="sf_bantype">
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
>
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
>
201 <optgroup label
="Other">
202 <option value
="warn">Warn the user
</option
>
205 <div
class="align_label curvy"><label
for="banlen_w">Duration
: </label
></div
>
206 <select name
="banlen_w" id
="banlen_w">
208 for ($i = 0; $i <= 56; $i++
)
211 echo "<option value=\"0w\"></option>";
214 $w = ($i == 1) ? "week" : "weeks";
215 echo "<option value=\"$i" . "w\"
>$i $w" . "</option>";
220 <select name
="banlen_d" id
="banlen_d">
222 for ($i = 0; $i <= 31; $i++
)
225 echo "<option value=\"0d\"></option>";
228 $d = ($i == 1) ? "day" : "days";
229 echo "<option value=\"$i" . "d\"
>$i $d" . "</option>";
234 <select name
="banlen_h" id
="banlen_h">
236 for ($i = 0; $i <= 24; $i++
)
239 echo "<option value=\"0d\"></option>";
242 $h = ($i == 1) ? "hour" : "hours";
243 echo "<option value=\"$i" . "h\"
>$i $h" . "</option>";
248 <input
class="curvy" type
="checkbox" id
="soft" name
="soft">Don
't affect logged-in users (soft)
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>
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>
257 </div></div></div></div>
260 <table class="table table-responsive caption-top table-striped">
261 <thead class="table-primary"><form action="spamfilter.php" method="post">
262 <th><input type="checkbox" label='selectall
' onClick="toggle_sf(this)" /></th>
267 <th>Action Duration</th>
274 foreach($spamfilter as $sf)
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>";
278 echo "<td>".$sf->match_type."</td>";
279 echo "<td>".$sf->name."</td>";
280 echo "<td>".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)."</td>";
281 echo "<td>".$sf->ban_action."</td>";
282 echo "<td>".$sf->ban_duration_string."</td>";
283 echo "<td>".$sf->reason."</td>";
284 echo "<td>".show_nick_only($sf->set_by)."</td>";
285 echo "<td>".$sf->set_at_string."</td>";
288 ?></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
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">
295 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
296 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
297 <span aria-hidden="true">×</span>
300 <div class="modal-body">
301 Are you sure you want to do this?<br>
302 This cannot be undone.
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>
315 <?php require_once 'footer
.php
'; ?>