]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - spamfilter.php
Fix post paths for new files
[irc/unrealircd/unrealircd-webpanel.git] / spamfilter.php
1 <?php
2 require_once "common.php";
3
4 require_once "header.php";
5
6 if (!empty($_POST))
7 {
8
9 do_log($_POST);
10
11 if ($sf = $_POST['sf_add']) // if it was a spamfilter entry
12 {
13 /* get targets */
14 $targets = []; // empty arrae
15 foreach($_POST as $key => $value)
16 {
17 if (substr($key, 0, 7) == "target_")
18 $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
19 }
20 if (empty($targets))
21 Message::Fail("No target was specified");
22
23 if (!isset($_POST['sf_bantype']))
24 Message::Fail("No action was chosen");
25
26 else
27 {
28
29 $bantype = $_POST['sf_bantype'];
30 $targ_chars = "";
31 foreach($targets as $targ)
32 {
33 switch ($targ) {
34 case "channel":
35 $targ_chars .= "c";
36 break;
37 case "private":
38 $targ_chars .= "p";
39 break;
40 case "channel-notice":
41 $targ_chars .= "N";
42 break;
43 case "private-notice":
44 $targ_chars .= "n";
45 break;
46 case "part":
47 $targ_chars .= "P";
48 break;
49 case "quit":
50 $targ_chars .= "q";
51 break;
52 case "dcc":
53 $targ_chars .= "d";
54 break;
55 case "away":
56 $targ_chars .= "a";
57 break;
58 case "topic":
59 $targ_chars .= "t";
60 break;
61 case "messagetag":
62 $targ_chars .= "T";
63 break;
64 case "user":
65 $targ_chars .= "u";
66 break;
67 }
68 }
69 /* duplicate code for now [= */
70 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
71 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
72 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
73 $duration = "";
74 if (!$banlen_d && !$banlen_h && !$banlen_w)
75 $duration .= "0";
76
77 else
78 {
79 if ($banlen_w)
80 $duration .= $banlen_w;
81 if ($banlen_d)
82 $duration .= $banlen_d;
83 if ($banlen_h)
84 $duration .= $banlen_h;
85 }
86 $match_type = $_POST['matchtype']; // should default to 'simple'
87 $reason = isset($_POST['ban_reason']) ? $_POST['ban_reason'] : "No reason";
88 $soft = (isset($_POST['soft'])) ? true : false;
89 if ($soft)
90 $targ_chars = "%" . $targ_chars;
91 if ($rpc->spamfilter()->add($sf, $match_type, $targ_chars, $bantype, $duration, $reason))
92 Message::Success("Added spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]");
93 else
94 Message::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error");
95 }
96 }
97 else if (!empty($_POST['sf']))
98 foreach ($_POST as $key => $value)
99 foreach ($value as $tok)
100 {
101 $tok = explode(",", $tok);
102 $name = base64_decode($tok[0]);
103 $match_type = base64_decode($tok[1]);
104 $spamfilter_targets = base64_decode($tok[2]);
105 $ban_action = base64_decode($tok[3]);
106 if ($rpc->spamfilter()->delete($name, $match_type, $spamfilter_targets, $ban_action))
107 Message::Success("Spamfilter on $name has been removed");
108 else
109 Message::Fail("Unable to remove spamfilter on $name: $rpc->error");
110 }
111
112 }
113
114 $tkl = $rpc->serverban()->getAll();
115 ?>
116 <div class="tkl_add_boxheader">
117 Add Spamfilter Entry
118 </div>
119 <div class="tkl_add_form">
120
121 <form action="spamfilter.php" method="post">
122 <div class="align_label">Entry: </div><input class="input_text" type="text" id="sf_add" name="sf_add"><br>
123 <div class="align_label">MatchType: </div><select name="matchtype" id="matchtype">
124 <option value="simple">Simple</option>
125 <option value="regex">Regular Expression</option>
126 </select><br>
127 <div class="align_label">Action: </div><select name="sf_bantype" id="sf_bantype">
128 <option value=""></option>
129 <optgroup label="Bans">
130 <option value="kline">Kill Line (KLine)</option>
131 <option value="gline">Global Kill Line (GLine)</option>
132 <option value="zline">Zap Line (ZLine)</option>
133 <option value="gzline">Global Zap Line (GZLine)</option>
134
135 </optgroup>
136 <optgroup label="Restrictions">
137 <option value="tempshun">Temporary Shun (Session only)</option>
138 <option value="shun">Shun</option>
139 <option value="block">Block</option>
140 <option value="dccblock">DCC Block</option>
141 <option value="viruschan">Send to "Virus Chan"</option>
142 </optgroup>
143 <optgroup label="Other">
144 <option value="warn">Warn the user</option>
145 </optgroup>
146 </select><br>
147
148 <div class="align_label"><label for="banlen_w">Targets: </label></div>
149 <input type="checkbox" class="input_text" id="target_channel" name="target_channel">Channel messages<br>
150 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_private" name="target_private">Private messages<br>
151 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_channel_notice" name="target_channel_notice">Channel notices<br>
152 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_private_notice" name="target_private_notice">Private notices<br>
153 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_part" name="target_part">Part reason<br>
154 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_dcc" name="target_dcc">DCC Filename<br>
155 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_away" name="target_away">Away messages<br>
156 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_topic" name="target_topic">Channel topic<br>
157 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_messagetag" name="target_messagetag">MessageTags<br>
158 <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_user" name="target_user">Userhost (nick!user@host:realname)<br>
159 <div class="align_label"><label for="banlen_w">Duration: </label></div>
160 <select name="banlen_w" id="banlen_w">
161 <?php
162 for ($i = 0; $i <= 56; $i++)
163 {
164 if (!$i)
165 echo "<option value=\"0w\"></option>";
166 else
167 {
168 $w = ($i == 1) ? "week" : "weeks";
169 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
170 }
171 }
172 ?>
173 </select>
174 <select name="banlen_d" id="banlen_d">
175 <?php
176 for ($i = 0; $i <= 31; $i++)
177 {
178 if (!$i)
179 echo "<option value=\"0d\"></option>";
180 else
181 {
182 $d = ($i == 1) ? "day" : "days";
183 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
184 }
185 }
186 ?>
187 </select>
188 <select name="banlen_h" id="banlen_h">
189 <?php
190 for ($i = 0; $i <= 24; $i++)
191 {
192 if (!$i)
193 echo "<option value=\"0d\"></option>";
194 else
195 {
196 $h = ($i == 1) ? "hour" : "hours";
197 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
198 }
199 }
200 ?>
201 </select>
202 <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
203 <input class="input_text" type="text" id="ban_reason" name="ban_reason"><br>
204 <input class="input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
205 <div class="align_right_button_tkl_add"><input class="cute_button" type="submit" id="submit" value="Submit"></div>
206 </form>
207 </div>
208 <table class='users_overview'>
209 <form action="spamfilter.php" method="post">
210 <th><input type="checkbox" label='selectall' onClick="toggle_sf(this)" />Select all</th>
211 <th>Mask</th>
212 <th>Type</th>
213 <th>Set By</th>
214 <th>Set On</th>
215 <th>Expires</th>
216 <th>Duration</th>
217 <th>Match Type</th>
218 <th>Action</th>
219 <th>Action Duration</th>
220 <th>Target</th>
221 <th>Reason</th>
222
223 <?php
224 foreach(RPC_List::$spamfilter as $sf)
225 {
226 echo "<tr>";
227 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>";
228 echo "<td>".$sf->name."</td>";
229 echo "<td>".$sf->type_string."</td>";
230 echo "<td>".$sf->set_by."</td>";
231 echo "<td>".$sf->set_at_string."</td>";
232 echo "<td>".$sf->expire_at_string."</td>";
233 echo "<td>".$sf->duration_string."</td>";
234 echo "<td>".$sf->match_type."</td>";
235 echo "<td>".$sf->ban_action."</td>";
236 echo "<td>".$sf->ban_duration_string."</td>";
237 for ($i = 0, $targs = ""; $i < strlen($sf->spamfilter_targets); $i++)
238 {
239 $c = $sf->spamfilter_targets[$i];
240 if ($c == "c")
241 $targs .= "Channel, ";
242 else if ($c == "p")
243 $targs .= "Private,";
244 else if ($c == "n")
245 $targs .= "Notice, ";
246 else if ($c == "N")
247 $targs .= "Channel notice, ";
248 else if ($c == "P")
249 $targs .= "Part message, ";
250 else if ($c == "q")
251 $targs .= "Quit message, ";
252 else if ($c == "d")
253 $targs .= "DCC filename, ";
254 else if ($c == "a")
255 $targs .= "Away message, ";
256 else if ($c == "t")
257 $targs .= "Channel topic, ";
258 else if ($c == "T")
259 $targs .= "MessageTag, ";
260 else if ($c == "u")
261 $targs .= "Usermask, ";
262 }
263 $targs = rtrim($targs,", ");
264 echo "<td>".$targs."</td>";
265 echo "<td>".$sf->reason."</td>";
266
267 }
268 ?></table><p><input class="cute_button" type="submit" value="Delete selected"></p></form></div></div>
269
270
271 <?php require_once 'footer.php'; ?>