]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - channels/details.php
Merge pull request #17 from PeGaSuS-Coder/patch-1
[irc/unrealircd/unrealircd-webpanel.git] / channels / details.php
1 <?php
2 require_once "../common.php";
3 require_once "../connection.php";
4 require_once "../header.php";
5
6 if ($uplink = $rpc->server()->get())
7 IRCList::setmodes($uplink->server->features->chanmodes);
8 $title = "Channel Lookup";
9 $channel = "";
10 $channame = "";
11 $nick = NULL;
12 $channelObj = NULL;
13
14 $can_edit = current_user_can(PERMISSION_EDIT_CHANNEL);
15 do_log($_GET);
16 do_log($_POST);
17 if (isset($_GET['chan']))
18 {
19 $channel = $_GET['chan'];
20 $channelObj = $rpc->channel()->get($channel, 4);
21 if (!$channelObj && strlen($channel))
22 {
23 Message::Fail("Could not find channel: \"$channel\"");
24 } elseif (strlen($channel)) {
25
26 $channame = $channelObj->name;
27 $title .= " for \"" . $channame . "\"";
28 do_log($channelObj);
29 }
30 }
31 $topicset = false;
32 $del_ex = false;
33 $del_inv = false;
34 $del_ban = false;
35 $checkboxes = [];
36
37 $chanban_errors = [];
38 if (!empty($_POST))
39 {
40 if (isset($_POST['update_topic']) && isset($_POST['set_topic']))
41 {
42 if (isset($channelObj))
43 {
44 if (!isset($channelObj->topic) || strcmp($channelObj->topic,$_POST['set_topic'])) // if the set topic is different
45 {
46 $user = (function_exists('unreal_get_current_user') && $u = unreal_get_current_user()) ? $u->username : NULL;
47 $topicset = $rpc->channel()->set_topic($channelObj->name, $_POST['set_topic'], $user);
48 $channelObj->topic = $_POST['set_topic'];
49 }
50 }
51 }
52 $checkboxes = (isset($_POST['ban_checkboxes'])) ? $_POST['ban_checkboxes'] : [];
53 if (isset($_POST['delete_sel_ex']))
54 {
55 foreach($_POST['ce_checkboxes'] as $c)
56 $checkboxes[] = $c;
57 do_delete_chanex($channelObj, $checkboxes);
58 }
59 if (isset($_POST['delete_sel_inv']))
60 {
61 foreach($_POST['ci_checkboxes'] as $c)
62 $checkboxes[] = $c;
63 do_delete_invite($channelObj, $checkboxes);
64 }
65 else if (isset($_POST['delete_sel_ban']))
66 {
67 foreach($_POST['cb_checkboxes'] as $c)
68 $checkboxes[] = $c;
69 do_delete_chanban($channelObj, $checkboxes);
70 }
71 if (isset($_POST['add_chban']) || isset($_POST['add_chinv']) || isset($_POST['add_chex']))
72 {
73
74 if (isset($_POST['add_chban']))
75 $mode = $_POST['add_chban'];
76 else
77 $mode = (isset($_POST['add_chinv'])) ? $_POST['add_chinv'] : $_POST['add_chex'];
78
79 $nick = (strlen($_POST['ban_nick'])) ? $_POST['ban_nick'] : false;
80 $action_string = (isset($_POST['bantype_sel_action']) && strlen($_POST['bantype_sel_action'])) ? $_POST['bantype_sel_action'] : false;
81 $action = "";
82 $type_string = (strlen($_POST['bantype_sel_type'])) ? $_POST['bantype_sel_type'] : false;
83 $type = "";
84 $expiry = (strlen($_POST['bantype_sel_ex'])) ? $_POST['bantype_sel_ex'] : false;
85 $time = "";
86
87 if (!$nick)
88 $chanban_errors[] = "You did not specify a nick/mask";
89
90 if ($action_string)
91 {
92 if (strstr($action_string,"Quiet"))
93 $action = "~quiet:";
94 elseif (strstr($action_string,"Nick-change"))
95 $action = "~nickchange:";
96 elseif (strstr($action_string,"Join"))
97 $action = "~join:";
98 }
99 if ($type_string)
100 {
101 if (strstr($type_string,"Account"))
102 $type = "~account:";
103 elseif (strstr($type_string,"Channel"))
104 $type = "~channel:";
105 elseif (strstr($type_string,"Country"))
106 $type = "~country:";
107 elseif (strstr($type_string,"OperClass"))
108 $type = "~operclass:";
109 elseif (strstr($type_string,"GECOS"))
110 $type = "~realname:";
111 elseif (strstr($type_string,"Security"))
112 $type = "~security-group:";
113 elseif (strstr($type_string,"Certificate"))
114 $type = "~certfp:";
115 }
116 if ($expiry)
117 {
118 $future = strtotime($expiry);
119 $now = strtotime(date("Y-m-d h:i:s"));
120 $ts = ($future - $now) / 60;
121 $ts = (int)$ts;
122 $time = "~time:$ts:";
123 if ($ts > 9999 || $ts < 1)
124 $chanban_errors[] = "Cannot set expiry more than ".(9999 / 60)." hours (".(9999 / 1440)." days) in the future, or in the past";
125 }
126 if (empty($chanban_errors))
127 if ($rpc->channel()->set_mode($channel, "$mode", "$time$action$type$nick"))
128 Message::Success("The mode was set successfully: $mode $time$action$type$nick");
129
130 else
131 foreach($chanban_errors as $err)
132 Message::Fail($err);
133 }
134 if ((isset($_POST['kickban']) || isset($_POST['muteban'])) && current_user_can(PERMISSION_EDIT_CHANNEL_USER))
135 {
136 $mute = (isset($_POST['muteban'])) ? true : false;
137 $mutestr = ($mute) ? "~quiet:" : "";
138 $user = (!$mute) ? $_POST['kickban'] : $_POST['muteban'];
139
140 $kbuser = $rpc->user()->get($user);
141
142 if (!$kbuser)
143 Message::Fail("Could not kickban user: User does not exist");
144 else
145 {
146 $rpc->channel()->set_mode($channelObj->name, "+b", "~time:".DEFAULT_CHAN_DETAIL_QUICK_ACTION_TIME.":".$mutestr."*!*@".$kbuser->user->cloakedhost);
147 if (!$mute)
148 $rpc->channel()->kick($channelObj->name, $kbuser->name, DEFAULT_CHAN_DETAIL_QUICK_BAN_REASON);
149
150 $msgbox_str = ($mute)
151 ?
152 "User \"$kbuser->name\" has been muted for ".DEFAULT_CHAN_DETAIL_QUICK_ACTION_TIME." minutes."
153 :
154 "User \"$kbuser->name\" has been banned for ".DEFAULT_CHAN_DETAIL_QUICK_ACTION_TIME." minutes."
155 ;
156 Message::Success($msgbox_str);
157 }
158 }
159
160 if (isset($_POST['newmodes']) && isset($_POST['paramed_modes']) && $can_edit)
161 {
162 $m = $_POST['newmodes'];
163 $p = $_POST['paramed_modes'];
164
165 do_log($p,$m);
166 $addmodestring = "+";
167 $addparamstring = "";
168 $delmodestring = "-";
169 $delparamstring = "";
170 foreach ($m as $mode)
171 {
172 strcat($addmodestring, $mode);
173 if (isset($p[$mode]) && strlen($p[$mode]))
174 strcat($addparamstring, $p[$mode]." ");
175 }
176
177 $fmodes = $channelObj->modes;
178 $tok = split($fmodes);
179 $modes = $tok[0];
180 $params = rparv($fmodes);
181 $paramed_modes = sort_paramed_modes($modes, $params);
182 for ($i = 0; isset($modes[$i]) && $mode = $modes[$i]; $i++)
183 {
184 if (!strstr($addmodestring, $mode))
185 {
186 $req = IRCList::lookup($mode)['requires'];
187 if ($req == "Server")
188 continue;
189 strcat($delmodestring, $mode);
190 $grp = get_chmode_group($mode);
191 if ($grp == 2)
192 strcat($delparamstring, $paramed_modes[$mode]." ");
193 }
194
195 }
196
197
198 if ($rpc->channel()->set_mode($channel, $delmodestring.$addmodestring, $delparamstring." ".$addparamstring))
199 Message::Success("Channel settings have been successfully updated");
200 else
201 Message::Fail("Could not change channel settings: $rpc->error");
202 }
203
204 /* Re-grab the channel because of updates */
205 $channelObj = $rpc->channel()->get($channel, 4);
206 }
207
208 ?>
209 <title><?php echo $title; ?></title>
210 <h6><?php echo $title; ?></h6>
211 <br>
212
213
214 <form method="get" action="details.php">
215 <div class="text-left input-group" style="width: 35%;">
216 <input class="form-control" id="chan" name="chan" type="text" value="<?php echo $channame; ?>">
217 <div class="input-group-append">
218 <button type="submit" class="btn btn-primary">Go</button>
219 </div>
220 </div>
221 </form>
222 <?php if (!$channelObj)
223 return; ?>
224
225 <!-- Modal for Add Ban -->
226 <div class="modal fade" id="ban" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
227 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
228 <div class="modal-content">
229 <div class="modal-header">
230 <h5 class="modal-title" id="myModalLabel">Add New Channel Ban</h5>
231 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
232 <span aria-hidden="true">&times;</span>
233 </div>
234 </div>
235 <div class="modal-body">
236 <form method="post">
237 <div class="input-group mb-3">
238 <label for="ban_nick">Mask
239 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
240 title="The mask or other value. For example if you are matching a country in 'Ban Type' then you would put the country code as this value. Click to view more information on Extended Bans"
241 ></i></a>
242 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
243 placeholder="nick!user@host or something else"
244 ></label>
245
246 </div>
247 <div class="input-group mb-3">
248 <label for="bantype_action">Ban Action
249 <select class="form-control" name="bantype_sel_action" id="bantype_sel">
250 <option></option>
251 <option>Quiet (Mute)</option>
252 <option>Nick-change</option>
253 <option>Join</option>
254 </select>
255 </label>
256 </div>
257 <div class="input-group mb-3">
258 <label for="bantype_sel_type">Ban Type
259 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
260 <option></option>
261 <option>Match Account</option>
262 <option>Match Channel</option>
263 <option>Match Country</option>
264 <option>Match OperClass</option>
265 <option>Match RealName / GECOS</option>
266 <option>Match Security Group</option>
267 <option>Match Certificate Fingerprint</option>
268 </select>
269 </label>
270 </div>
271 <div class="input-group mb-3">
272 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
273 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
274 </label>
275 </div>
276 </div>
277 <div class="modal-footer">
278 <input type="hidden" id="server" name="add_chban" value="b"></input>
279 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
280 <button type="submit" action="post" class="btn btn-danger">Add Channel Ban</button>
281 </form>
282 </div>
283 </div>
284 </div>
285 </div>
286
287
288 <!-- Modal for Add Invite -->
289 <div class="modal fade" id="invite" tabindex="-1" role="dialog" aria-labelledby="add_invite_modal" aria-hidden="true">
290 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
291 <div class="modal-content">
292 <div class="modal-header">
293 <h5 class="modal-title" id="add_invite_modal">Add New Channel Invite</h5>
294 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
295 <span aria-hidden="true">&times;</span>
296 </div>
297 </div>
298 <div class="modal-body">
299 <form method="post">
300 <div class="input-group mb-3">
301 <label for="ban_nick">Mask
302 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
303 title="The mask or other value. For example if you are matching a country in 'Invite Type' then you would put the country code as this value. Click to view more information on Extended Bans"
304 ></i></a>
305 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
306 placeholder="nick!user@host or something else"
307 ></label>
308
309 </div>
310 <div class="input-group mb-3">
311 <label for="bantype_sel_type">Invite Type
312 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
313 <option></option>
314 <option>Match Account</option>
315 <option>Match Channel</option>
316 <option>Match Country</option>
317 <option>Match OperClass</option>
318 <option>Match RealName / GECOS</option>
319 <option>Match Security Group</option>
320 <option>Match Certificate Fingerprint</option>
321 </select>
322 </label>
323 </div>
324 <div class="input-group mb-3">
325 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
326 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
327 </label>
328 </div>
329 </div>
330 <div class="modal-footer">
331 <input type="hidden" name="add_chinv" value="I"></input>
332 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
333 <button type="submit" action="post" class="btn btn-danger">Add Invite</button>
334 </form>
335 </div>
336 </div>
337 </div>
338 </div>
339
340 <!-- Modal for Add Ban Exceptions -->
341 <div class="modal fade" id="except" tabindex="-1" role="dialog" aria-labelledby="except" aria-hidden="true">
342 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
343 <div class="modal-content">
344 <div class="modal-header">
345 <h5 class="modal-title" >Add New Channel Ban Exception</h5>
346 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
347 <span aria-hidden="true">&times;</span>
348 </div>
349 </div>
350 <div class="modal-body">
351 <form method="post">
352 <div class="input-group mb-3">
353 <label for="ban_nick">Mask
354 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
355 title="The mask or other value. For example if you are matching a country in 'Ban Type' then you would put the country code as this value. Click to view more information on Extended Bans"
356 ></i></a>
357 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
358 placeholder="nick!user@host or something else"
359 ></label>
360
361 </div>
362 <div class="input-group mb-3">
363 <label for="bantype_sel_type">Ban Type
364 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
365 <option></option>
366 <option>Match Account</option>
367 <option>Match Channel</option>
368 <option>Match Country</option>
369 <option>Match OperClass</option>
370 <option>Match RealName / GECOS</option>
371 <option>Match Security Group</option>
372 <option>Match Certificate Fingerprint</option>
373 </select>
374 </label>
375 </div>
376 <div class="input-group mb-3">
377 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
378 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
379 </label>
380 </div>
381 </div>
382 <div class="modal-footer">
383 <input type="hidden" id="server" name="add_chex" value="e"></input>
384 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
385 <button type="submit" action="post" class="btn btn-danger">Add Exception</button>
386 </form>
387 </div>
388 </div>
389 </div>
390 </div>
391
392 <!-- Modal for Edit Channel Modes -->
393 <div class="modal fade" id="editchmodes" tabindex="-1" role="dialog" aria-labelledby="editchmodes" aria-hidden="true">
394 <div class="modal-dialog modal-dialog-centered" role="document">
395 <div class="modal-content">
396 <div class="modal-header">
397 <h5 class="modal-title" id="editchmodes">Edit Channel Modes</h5>
398 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
399 <span aria-hidden="true">&times;</span>
400 </div>
401 </div>
402 <div class="modal-body">
403 <form method="post">
404
405 <?php generate_edit_chmodes($channelObj); ?>
406
407 </div>
408 <div class="modal-footer">
409 <input type="hidden" id="server" name="add_chex" value="e"></input>
410 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
411 <button type="submit" action="post" class="btn btn-danger">Update</button>
412 </form>
413 </div>
414 </div>
415 </div>
416 </div>
417
418 <br>
419 <h6>
420 Topic:<br></h6>
421 <form method="post" action="details.php?chan=<?php echo urlencode($channelObj->name); ?>">
422 <div class="input-group">
423 <input maxlength="360" type="text" class="input-group form-control" name="set_topic" value="<?php echo (isset($channelObj->topic)) ? htmlspecialchars($channelObj->topic) : ""; ?>">
424 <div class="input-group-append"><button type="submit" name="update_topic" value="true" class="btn btn-info">Update Topic</button></div></div>
425 </form>
426 <?php
427 if ($topicset)
428 Message::Success("The topic for $channelObj->name has been updated to be: \"".htmlspecialchars($channelObj->topic)."\"");
429 ?>
430 <br>
431
432 <!-- Modal for User Action -->
433 <div class="modal fade" id="useraction" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
434 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
435 <div class="modal-content">
436 <div class="modal-header">
437 <h5 class="modal-title" id="myModalLabel">Add New Channel Ban</h5>
438 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
439 <span aria-hidden="true">&times;</span>
440 </div>
441 </div>
442 <div class="modal-body">
443 <form method="post">
444 <div class="input-group mb-3">
445 <label for="ban_nick">Mask
446 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
447 title="The mask or other value. For example if you are matching a country in 'Ban Type' then you would put the country code as this value. Click to view more information on Extended Bans"
448 ></i></a>
449 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
450 placeholder="nick!user@host or something else"
451 ></label>
452
453 </div>
454 <div class="input-group mb-3">
455 <label for="bantype_action">Ban Action
456 <select class="form-control" name="bantype_sel_action" id="bantype_sel">
457 <option></option>
458 <option>Quiet (Mute)</option>
459 <option>Nick-change</option>
460 <option>Join</option>
461 </select>
462 </label>
463 </div>
464 <div class="input-group mb-3">
465 <label for="bantype_sel_type">Ban Type
466 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
467 <option></option>
468 <option>Match Account</option>
469 <option>Match Channel</option>
470 <option>Match Country</option>
471 <option>Match OperClass</option>
472 <option>Match RealName / GECOS</option>
473 <option>Match Security Group</option>
474 <option>Match Certificate Fingerprint</option>
475 </select>
476 </label>
477 </div>
478 <div class="input-group mb-3">
479 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
480 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
481 </label>
482 </div>
483 </div>
484 <div class="modal-footer">
485 <input type="hidden" id="server" name="add_chban" value="b"></input>
486 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
487 <button type="submit" action="post" class="btn btn-danger">Add Channel Ban</button>
488 </form>
489 </div>
490 </div>
491 </div>
492 </div>
493
494 <div class="container-xxl">
495 <div class="row">
496 <div class="col-sm-4">
497 <div class="card">
498 <div class="card-body">
499 <h6 class="card-title">User List</h6>
500 <p class="card-text"><?php generate_chan_occupants_table($channelObj); ?></p>
501 </div>
502 </div>
503 </div>
504 <div class="col-sm-8">
505 <div class="card">
506 <div class="card-body">
507 <h6 class="card-title">Channel Settings</h6>
508 <ul class="nav nav-tabs" role="tablist">
509 <li class="nav-item" role="presentation"><a class="nav-link" href="#chanmodes" aria-controls="chanmodes" role="tab" data-toggle="tab">Settings / Modes</a></li>
510 <li class="nav-item" role="presentation"><a class="nav-link" href="#chanbans" aria-controls="chanbans" role="tab" data-toggle="tab">Bans</a></li>
511 <li class="nav-item" role="presentation"><a class="nav-link" href="#chaninv" aria-controls="chaninv" role="tab" data-toggle="tab">Invites</a></li>
512 <li class="nav-item" role="presentation"><a class="nav-link" href="#chanex" aria-controls="chanex" role="tab" data-toggle="tab">Excepts</a></li>
513 </ul>
514
515 <div class="tab-content">
516 <br>
517 <div class="tab-pane fade in" id="chanmodes">
518 <button id="editlol" class="btn btn-sm btn-primary" <?php echo ($can_edit) ? "" : "disabled"; ?>>Change Settings</button>
519 <p class="card-text"><?php generate_html_chansettings($channelObj); ?></p>
520 </div><form id="editchanmodes" method="post" name="editchanmodes">
521 <div class="tab-pane" style="display: none" id="chanmodes_edit">
522
523 <div class="btn btn-sm btn-secondary" id="editchmodesbk">Go back</div>
524 <button type="submit" class="btn btn-sm btn-primary">Save Changes</button>
525 <p class="card-text"><?php generate_edit_chmodes($channelObj); ?></p>
526 </form>
527 </div>
528
529 <div class="tab-pane fade in" id="chanbans">
530 <p class="card-text"><?php generate_chanbans_table($channelObj); ?></p>
531 </div>
532 <div class="tab-pane fade in" id="chaninv">
533 <p class="card-text"><?php generate_chaninvites_table($channelObj); ?></p>
534 </div>
535 <div class="tab-pane fade in" id="chanex">
536 <p class="card-text"><?php generate_chanexcepts_table($channelObj); ?></p>
537 </div>
538 <div class="tab-pane fade in" id="chanmodes_edit">
539 <p class="card-text"><?php /* insert hacks here */ ?></p>
540 </div>
541
542 </div>
543 </div>
544 </div>
545 </div>
546 </div>
547 <script>
548 const toggleBtn = document.getElementById('editlol');
549 const staticInfo = document.getElementById('chanmodes');
550 const options = document.getElementById('chanmodes_edit');
551 const backBtn = document.getElementById('editchmodesbk');
552
553 backBtn.addEventListener('click', function() {
554 staticInfo.style.display = '';
555 options.style.display = 'none';
556 });
557 toggleBtn.addEventListener('click', function() {
558 staticInfo.style.display = 'none';
559 options.style.display = '';
560 });
561
562 // show dat first tab
563 $('.nav-tabs a[href="#chanmodes"]').tab('show')
564 </script>
565 <?php
566 require_once("../footer.php");
567