]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - index.php
Allow soft-bans (doesn't affect logged-in users)
[irc/unrealircd/unrealircd-webpanel.git] / index.php
1 <!DOCTYPE html>
2 <title>UnrealIRCd Panel</title>
3 <link rel="icon" type="image/x-icon" href="/img/favicon.ico">
4 <link href="css/unrealircd-admin.css" rel="stylesheet">
5 <body class="body-for-sticky">
6 <div id="headerContainer">
7 <h2><a href="">UnrealIRCd <small>Administration Panel</small></a></h2></div>
8 <script src="js/unrealircd-admin.js" defer></script>
9 <div class="topnav">
10 <a data-tab-target="#overview" class="active" href="#overview">Overview</a>
11 <a data-tab-target="#Users" href="#Users">Users</a>
12 <a data-tab-target="#Channels" href="#Channels">Channels</a>
13 <a data-tab-target="#TKL" href="#TKL">Server Bans</a>
14 <a data-tab-target="#Spamfilter" href="#Spamfilter">Spamfilter</a>
15 <a data-tab-target="#News" href="#News">News</a>
16 </div>
17 <?php
18 define('UPATH', dirname(__FILE__));
19 require_once "config.php";
20 require_once UPATH . '/vendor/autoload.php';
21 require_once "connection.php";
22 require_once "Classes/class-log.php";
23 require_once "Classes/class-message.php";
24 require_once "Classes/class-rpc.php";
25
26 do_log($_POST);
27
28 if (!empty($_POST)) {
29 if (!($bantype = $_POST['bantype']))
30 {
31 }
32 else if (!($users = $_POST["userch"]))
33 {
34 /* check if this came from our Server Bans tab. */
35 if (!($iphost = $_POST['tkl_add']))
36 Message::Fail("No user was specified");
37
38 else /* It did */
39 {
40 if ((
41 $bantype == "gline" ||
42 $bantype == "gzline" ||
43 $bantype == "shun" ||
44 $bantype == "eline"
45 ) && strpos($iphost, "@") == false) // doesn't have full mask
46 $iphost = "*@" . $iphost;
47
48 $soft = ($_POST['soft']) ? true : false;
49
50 if ($soft)
51 $iphost = "%" . $iphost;
52 /* duplicate code for now [= */
53 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
54 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
55 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
56 $duration = "";
57 if (!$banlen_d && !$banlen_h && !$banlen_w)
58 $duration .= "0";
59
60 else
61 {
62 if ($banlen_w)
63 $duration .= $banlen_w;
64 if ($banlen_d)
65 $duration .= $banlen_d;
66 if ($banlen_h)
67 $duration .= $banlen_h;
68 }
69 $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for ".rpc_convert_duration_string($duration);
70 $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
71 if ($rpc->serverban()->add($iphost, $bantype, $duration, $reason))
72 {
73 Message::Success("Host / IP: $iphost has been $bantype" . "d $msg_msg: $reason");
74 }
75 else
76 Message::Fail("The $bantype against \"$iphost\" could not be added: $rpc->error");
77 }
78 }
79 else /* It came from the Users tab */
80 {
81 foreach ($_POST["userch"] as $user)
82 {
83 $user = base64_decode($user);
84 $bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : NULL;
85 if (!$bantype) /* shouldn't happen? */
86 {
87 Message::Fail("An error occured");
88 return;
89 }
90 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
91 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
92 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
93
94 $duration = "";
95 if (!$banlen_d && !$banlen_h && !$banlen_w)
96 $duration .= "0";
97
98 else
99 {
100 if ($banlen_w)
101 $duration .= $banlen_w;
102 if ($banlen_d)
103 $duration .= $banlen_d;
104 if ($banlen_h)
105 $duration .= $banlen_h;
106 }
107
108 $nick = $rpc->user()->get($user);
109 if (!$nick)
110 {
111 Message::Fail("Could not find that user. Maybe they disconnected after you clicked this?");
112 return;
113 }
114
115 $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for ".rpc_convert_duration_string($duration);
116 $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
117 if ($rpc->serverban()->add($user, $bantype, $duration, $reason))
118 {
119 $c = $nick->client;
120 Message::Success($c->name . " (*@".$c->hostname.") has been $bantype" . "d $msg_msg: $reason");
121 }
122 }
123 }
124
125 if (!empty($_POST['tklch']))
126 foreach ($_POST as $key => $value) {
127 foreach ($value as $tok) {
128 $tok = explode(",", $tok);
129 $ban = base64_decode($tok[0]);
130 $type = base64_decode($tok[1]);
131 if ($rpc->serverban()->delete($ban, $type))
132 Message::Success("$type has been removed for $ban");
133 else
134 Message::Fail("Unable to remove $type on $ban: $rpc->error");
135 }
136 }
137
138 if (!empty($_POST['sf']))
139 foreach ($_POST as $key => $value) {
140 foreach ($value as $tok) {
141 $tok = explode(",", $tok);
142 $name = base64_decode($tok[0]);
143 $match_type = base64_decode($tok[1]);
144 $spamfilter_targets = base64_decode($tok[2]);
145 $ban_action = base64_decode($tok[3]);
146 if ($rpc->spamfilter()->delete($name, $match_type, $spamfilter_targets, $ban_action))
147 Message::Success("Spamfilter on $name has been removed");
148 else
149 Message::Fail("Unable to remove spamfilter on $name: $rpc->error");
150 }
151 }
152 }
153
154 rpc_pop_lists();
155 ?>
156
157 <div class="tab-content\">
158 <div id="overview" data-tab-content class="active">
159 <table class='unrealircd_overview'>
160 <th>Chat Overview</th><th></th>
161 <tr><td><b>Users</b></td><td><?php echo count(RPC_List::$user); ?></td></tr>
162 <tr><td><b>Opers</b></td><td><?php echo RPC_List::$opercount; ?></td></tr>
163 <tr><td><b>Services</b></td><td><?php echo RPC_List::$services_count; ?></td></tr>
164 <tr><td><b>Most popular channel</b></td><td><?php echo RPC_List::$most_populated_channel; ?> (<?php echo RPC_List::$channel_pop_count; ?> users)</td></tr>
165 <tr><td><b>Channels</b></td><td><?php echo count(RPC_List::$channel); ?></td></tr>
166 <tr><td><b>Server bans</b></td><td><?php echo count(RPC_List::$tkl); ?></td></tr>
167 <tr><td><b>Spamfilter entries</b></td><td><?php echo count(RPC_List::$spamfilter); ?></td></tr></th>
168 </table></div></div>
169
170 <div class="tab-content\">
171 <div id="Users" data-tab-content>
172 <table class='users_filter'>
173 <th class="thuf">Filter by: </th>
174 <th>
175 <form action="" method="post">
176 Nick: <input name="uf_nick" id="uf_nick" type="text">
177 <input class="cute_button2" type="submit" value="Search">
178 </form>
179 </th>
180 <th>
181 <form action="" method="post">
182 Hostname: <input name="uf_host" id="uf_host" type="text">
183 <input class="cute_button2" type="submit" value="Search">
184 </form>
185 </th>
186 <th>
187 <form action="" method="post">
188 IP: <input name="uf_ip" id="uf_ip" type="text">
189 <input class="cute_button2" type="submit" value="Search">
190 </form>
191 </th>
192 <th class="thuffer">
193 <form action="" method="post">
194 Account: <input name="uf_account" id="uf_account" type="text">
195 <input class="cute_button2" type="submit" value="Search">
196 </form>
197 </th>
198 </form>
199 </table>
200 <?php
201 if (isset($_POST['uf_nick']) && strlen($_POST['uf_nick']))
202 Message::Info("Listing users which match nick: \"" . $_POST['uf_nick'] . "\"");
203
204 if (isset($_POST['uf_ip']) && strlen($_POST['uf_ip']))
205 Message::Info("Listing users which match IP: \"" . $_POST['uf_ip'] . "\"");
206
207 if (isset($_POST['uf_host']) && strlen($_POST['uf_host']))
208 Message::Info("Listing users which match hostmask: \"" . $_POST['uf_host'] . "\"");
209
210 if (isset($_POST['uf_account']) && strlen($_POST['uf_account']))
211 Message::Info("Listing users which match account: \"" . $_POST['uf_account'] . "\"");
212
213 ?>
214 <table class='users_overview'>
215 <th><input type="checkbox" label='selectall' onClick="toggle_user(this)" />Select all</th>
216 <th>Nick</th>
217 <th>UID</th>
218 <th>Host / IP</th>
219 <th>Account</th>
220 <th>Usermodes<a href="https://www.unrealircd.org/docs/User_modes" target="_blank">ℹ️</a></th>
221 <th>Oper</th>
222 <th>Secure</th>
223 <th>Connected to</th>
224 <th>Reputation <a href="https://www.unrealircd.org/docs/Reputation_score" target="_blank">ℹ️</a></th>
225
226 <form action="" method="post">
227 <?php
228 foreach(RPC_List::$user as $user)
229 {
230
231 /* Some basic filtering for NICK */
232 if (isset($_POST['uf_nick']) && strlen($_POST['uf_nick']) &&
233 strpos(strtolower($user->name), strtolower($_POST['uf_nick'])) !== 0 &&
234 strpos(strtolower($user->name), strtolower($_POST['uf_nick'])) == false)
235 continue;
236
237 /* Some basic filtering for HOST */
238 if (isset($_POST['uf_host']) && strlen($_POST['uf_host']) &&
239 strpos(strtolower($user->hostname), strtolower($_POST['uf_host'])) !== 0 &&
240 strpos(strtolower($user->hostname), strtolower($_POST['uf_host'])) == false)
241 continue;
242
243 /* Some basic filtering for IP */
244 if (isset($_POST['uf_ip']) && strlen($_POST['uf_ip']) &&
245 strpos(strtolower($user->ip), strtolower($_POST['uf_ip'])) !== 0 &&
246 strpos(strtolower($user->ip), strtolower($_POST['uf_ip'])) == false)
247 continue;
248
249 /* Some basic filtering for ACCOUNT */
250 if (isset($_POST['uf_account']) && strlen($_POST['uf_account']) &&
251 strpos(strtolower($user->user->account), strtolower($_POST['uf_account'])) !== 0 &&
252 strpos(strtolower($user->user->account), strtolower($_POST['uf_account'])) == false)
253 continue;
254
255 echo "<tr>";
256 echo "<td><input type=\"checkbox\" value='" . base64_encode($user->id)."' name=\"userch[]\"></td>";
257 $isBot = (strpos($user->user->modes, "B") !== false) ? ' <span class="label">Bot</span>' : "";
258 echo "<td>".$user->name.$isBot.'</td>';
259 echo "<td>".$user->id."</td>";
260 echo "<td>".$user->hostname." (".$user->ip.")</td>";
261 $account = (isset($user->user->account)) ? $user->user->account : '<span class="label noaccount">None</span>';
262 echo "<td>".$account."</td>";
263 $modes = (isset($user->user->modes)) ? "+" . $user->user->modes : "<none>";
264 echo "<td>".$modes."</td>";
265 $oper = (isset($user->user->operlogin)) ? $user->user->operlogin." <span class=\"label operclass-label\">".$user->user->operclass."</span>" : "";
266 if (!strlen($oper))
267 $oper = (strpos($user->user->modes, "S") !== false) ? '<span class="label secure-connection">Service</span>' : "";
268 echo "<td>".$oper."</td>";
269 $secure = (isset($user->tls)) ? "<span class=\"label secure-connection\">Secure</span>" : "<span class=\"label noaccount\">Insecure</span>";
270 echo "<td>".$secure."</td>";
271 echo "<td>".$user->user->servername."</td>";
272 echo "<td>".$user->user->reputation."</td>";
273 }
274 ?></table>
275 <label for="bantype">Apply action: </label><br>
276 <select name="bantype" id="bantype">
277 <option value=""></option>
278 <optgroup label="Bans">
279 <option value="gline">GLine</option>
280 <option value="gzline">GZLine</option>
281 </optgroup>
282 </select>
283 <br>
284 <label for="banlen_w">Duration: </label><br>
285 <select name="banlen_w" id="banlen_w">
286 <?php
287 for ($i = 0; $i <= 56; $i++)
288 {
289 if (!$i)
290 echo "<option value=\"0w\"></option>";
291 else
292 {
293 $w = ($i == 1) ? "week" : "weeks";
294 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
295 }
296 }
297 ?>
298 </select>
299 <select name="banlen_d" id="banlen_d">
300 <?php
301 for ($i = 0; $i <= 31; $i++)
302 {
303 if (!$i)
304 echo "<option value=\"0d\"></option>";
305 else
306 {
307 $d = ($i == 1) ? "day" : "days";
308 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
309 }
310 }
311 ?>
312 </select>
313 <select name="banlen_h" id="banlen_h">
314 <?php
315 for ($i = 0; $i <= 24; $i++)
316 {
317 if (!$i)
318 echo "<option value=\"0d\"></option>";
319 else
320 {
321 $h = ($i == 1) ? "hour" : "hours";
322 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
323 }
324 }
325 ?>
326 </select>
327 <br><label for="ban_reason">Reason:<br></label>
328 <textarea name="ban_reason" id="ban_reason">No reason</textarea><br>
329 <input class="cute_button" type="submit" value="Apply">
330 </form>
331
332 </div></div>
333
334 <div class="tab-content\">
335 <div id="Channels" data-tab-content>
336 <p></p>
337 <table class='users_overview'>
338 <th>Name</th>
339 <th>Created</th>
340 <th>User count</th>
341 <th>Topic</th>
342 <th>Topic Set</th>
343 <th>Modes</th>
344
345 <?php
346 foreach(RPC_List::$channel as $channel)
347 {
348 echo "<tr>";
349 echo "<td>".$channel->name."</td>";
350 echo "<td>".$channel->creation_time."</td>";
351 echo "<td>".$channel->num_users."</td>";
352 $topic = (isset($channel->topic)) ? $channel->topic : "";
353 echo "<td>".$topic."</td>";
354 $setby = (isset($channel->topic)) ? "By ".$channel->topic_set_by .", at ".$channel->topic_set_at : "";
355 echo "<td>".$setby."</td>";
356 $modes = (isset($channel->modes)) ? "+" . $channel->modes : "<none>";
357 echo "<td>".$modes."</td>";
358 }
359 ?></table></div></div>
360
361
362 <div class="tab-content\">
363 <div id="TKL" data-tab-content>
364 <div class="tkl_add_boxheader">
365 Add Server Ban
366 </div>
367 <div class="tkl_add_form">
368
369 <form action="" method="post">
370 <div class="align_label">IP / Host:</div><input class="input_text" type="text" id="tkl_add" name="tkl_add"><br>
371 <div class="align_label">Ban Type:</div><select name="bantype" id="bantype">
372 <option value=""></option>
373 <optgroup label="Bans">
374 <option value="kline">Kill Line (KLine)</option>
375 <option value="gline">Global Kill Line (GLine)</option>
376 <option value="zline">Zap Line (ZLine)</option>
377 <option value="gzline">Global Zap Line (GZLine)</option>
378
379 </optgroup>
380 <optgroup label="Restrictions">
381 <option value="local-qline">Reserve Nick Locally(QLine)</option>
382 <option value="qline">Reserve Nick Globally (QLine)</option>
383 <option value="shun">Shun</option>
384
385 </optgroup>
386 <optgroup label="Settings">
387 <option value="except">Global Exception (ELine)</option>
388 <option value="local-exception">Local Exception (ELine)</option>
389 </optgroup>
390 </select><br>
391 <div class="align_label"><label for="banlen_w">Duration: </label></div>
392 <select name="banlen_w" id="banlen_w">
393 <?php
394 for ($i = 0; $i <= 56; $i++)
395 {
396 if (!$i)
397 echo "<option value=\"0w\"></option>";
398 else
399 {
400 $w = ($i == 1) ? "week" : "weeks";
401 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
402 }
403 }
404 ?>
405 </select>
406 <select name="banlen_d" id="banlen_d">
407 <?php
408 for ($i = 0; $i <= 31; $i++)
409 {
410 if (!$i)
411 echo "<option value=\"0d\"></option>";
412 else
413 {
414 $d = ($i == 1) ? "day" : "days";
415 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
416 }
417 }
418 ?>
419 </select>
420 <select name="banlen_h" id="banlen_h">
421 <?php
422 for ($i = 0; $i <= 24; $i++)
423 {
424 if (!$i)
425 echo "<option value=\"0d\"></option>";
426 else
427 {
428 $h = ($i == 1) ? "hour" : "hours";
429 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
430 }
431 }
432 ?>
433 </select>
434 <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
435 <input class="input_text" type="text" id="ban_reason" name="ban_reason"><br>
436 <input class="input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
437 <div class="align_right_button_tkl_add"><input class="cute_button" type="submit" id="submit" value="Submit"></div>
438 </form>
439 </div>
440 <table class='users_overview'>
441 <form action="" method="post">
442 <th><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" />Select all</th>
443 <th>Mask</th>
444 <th>Type</th>
445 <th>Set By</th>
446 <th>Set On</th>
447 <th>Expires</th>
448 <th>Duration</th>
449 <th>Reason</th>
450
451 <?php
452 foreach(RPC_List::$tkl as $tkl)
453 {
454 echo "<tr>";
455 echo "<td><input type=\"checkbox\" value='" . base64_encode($tkl->name).",".base64_encode($tkl->type) . "' name=\"tklch[]\"></td>";
456 echo "<td>".$tkl->name."</td>";
457 echo "<td>".$tkl->type_string."</td>";
458 echo "<td>".$tkl->set_by."</td>";
459 echo "<td>".$tkl->set_at_string."</td>";
460 echo "<td>".$tkl->expire_at_string."</td>";
461 echo "<td>".$tkl->duration_string."</td>";
462 echo "<td>".$tkl->reason."</td>";
463 }
464 ?></table><p><input class="cute_button" type="submit" value="Delete selected"></p></form></div></div>
465
466
467 <div class="tab-content\">
468 <div id="Spamfilter" data-tab-content>
469 <p></p>
470 <table class='users_overview'>
471 <form action="" method="post">
472 <th><input type="checkbox" label='selectall' onClick="toggle_sf(this)" />Select all</th>
473 <th>Mask</th>
474 <th>Type</th>
475 <th>Set By</th>
476 <th>Set On</th>
477 <th>Expires</th>
478 <th>Duration</th>
479 <th>Match Type</th>
480 <th>Action</th>
481 <th>Action Duration</th>
482 <th>Target</th>
483 <th>Reason</th>
484
485 <?php
486 foreach(RPC_List::$spamfilter as $sf)
487 {
488 echo "<tr>";
489 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>";
490 echo "<td>".$sf->name."</td>";
491 echo "<td>".$sf->type_string."</td>";
492 echo "<td>".$sf->set_by."</td>";
493 echo "<td>".$sf->set_at_string."</td>";
494 echo "<td>".$sf->expire_at_string."</td>";
495 echo "<td>".$sf->duration_string."</td>";
496 echo "<td>".$sf->match_type."</td>";
497 echo "<td>".$sf->ban_action."</td>";
498 echo "<td>".$sf->ban_duration_string."</td>";
499 for ($i = 0, $targs = ""; $i < strlen($sf->spamfilter_targets); $i++)
500 {
501 $c = $sf->spamfilter_targets[$i];
502 if ($c == "c")
503 $targs .= "Channel, ";
504 else if ($c == "p")
505 $targs .= "Private,";
506 else if ($c == "n")
507 $targs .= "Notice, ";
508 else if ($c == "N")
509 $targs .= "Channel notice, ";
510 else if ($c == "P")
511 $targs .= "Part message, ";
512 else if ($c == "q")
513 $targs .= "Quit message, ";
514 else if ($c == "d")
515 $targs .= "DCC filename, ";
516 else if ($c == "a")
517 $targs .= "Away message, ";
518 else if ($c == "t")
519 $targs .= "Channel topic, ";
520 else if ($c == "T")
521 $targs .= "MessageTag, ";
522 else if ($c == "u")
523 $targs .= "Usermask, ";
524 }
525 $targs = rtrim($targs,", ");
526 echo "<td>".$targs."</td>";
527 echo "<td>".$sf->reason."</td>";
528
529 }
530 ?></table><p><input class="cute_button" type="submit" value="Delete selected"></p></form></div></div>
531
532
533
534 <div class="tab-content\">
535 <div id="News" data-tab-content>
536 <iframe style="border:none;" height="1000" width="600" data-tweet-url="https://twitter.com/Unreal_IRCd" src="data:text/html;charset=utf-8,%3Ca%20class%3D%22twitter-timeline%22%20href%3D%22https%3A//twitter.com/Unreal_IRCd%3Fref_src%3Dtwsrc%255Etfw%22%3ETweets%20by%20Unreal_IRCd%3C/a%3E%0A%3Cscript%20async%20src%3D%22https%3A//platform.twitter.com/widgets.js%22%20charset%3D%22utf-8%22%3E%3C/script%3E%0A%3Cstyle%3Ehtml%7Boverflow%3Ahidden%20%21important%3B%7D%3C/style%3E"></iframe>
537 <iframe style="border:none;" height="1000" width="600" data-tweet-url="https://twitter.com/irc_stats" src="data:text/html;charset=utf-8,%3Ca%20class%3D%22twitter-timeline%22%20href%3D%22https%3A//twitter.com/irc_stats%3Fref_src%3Dtwsrc%255Etfw%22%3ETweets%20by%20IRC%20Stats%3C/a%3E%0A%3Cscript%20async%20src%3D%22https%3A//platform.twitter.com/widgets.js%22%20charset%3D%22utf-8%22%3E%3C/script%3E%0A%3Cstyle%3Ehtml%7Boverflow%3Ahidden%20%21important%3B%7D%3C/style%3E"></iframe>
538 </div></div>
539
540 </body>