]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - channels/details.php
8cf6543914963545af6222f5a96ac72ce82f86ac
[irc/unrealircd/unrealircd-webpanel.git] / channels / details.php
1 <?php
2 require_once "../inc/common.php";
3 require_once "../inc/connection.php";
4 require_once "../inc/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
212
213 <form method="get" action="details.php">
214 <div class="text-left input-group" style="width: 35%;">
215 <input class="form-control" id="chan" name="chan" type="text" value="<?php echo $channame; ?>">
216 <div class="input-group-append">
217 <button type="submit" class="btn btn-primary">Go</button>
218 </div>
219 </div>
220 </form>
221 <?php if (!$channelObj)
222 return; ?>
223
224 <!-- Modal for Add Ban -->
225 <div class="modal fade" id="ban" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
226 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
227 <div class="modal-content">
228 <div class="modal-header">
229 <h5 class="modal-title" id="myModalLabel">Add New Channel Ban</h5>
230 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
231 <span aria-hidden="true">&times;</span>
232 </div>
233 </div>
234 <div class="modal-body">
235 <form method="post">
236 <div class="input-group mb-3">
237 <label for="ban_nick">Mask
238 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
239 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"
240 ></i></a>
241 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
242 placeholder="nick!user@host or something else"
243 ></label>
244
245 </div>
246 <div class="input-group mb-3">
247 <label for="bantype_action">Ban Action
248 <select class="form-control" name="bantype_sel_action" id="bantype_sel">
249 <option></option>
250 <option>Quiet (Mute)</option>
251 <option>Nick-change</option>
252 <option>Join</option>
253 </select>
254 </label>
255 </div>
256 <div class="input-group mb-3">
257 <label for="bantype_sel_type">Ban Type <small>Leave this blank for a "normal" ban</small>
258 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
259 <option></option>
260 <option>Match Account</option>
261 <option>Match Channel</option>
262 <option>Match Country</option>
263 <option>Match OperClass</option>
264 <option>Match RealName / GECOS</option>
265 <option>Match Security Group</option>
266 <option>Match Certificate Fingerprint</option>
267 </select>
268 </label>
269 </div>
270 <div class="input-group mb-3">
271 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
272 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
273 </label>
274 </div>
275 </div>
276 <div class="modal-footer">
277 <input type="hidden" id="server" name="add_chban" value="b"></input>
278 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
279 <button type="submit" action="post" class="btn btn-danger">Add Channel Ban</button>
280 </form>
281 </div>
282 </div>
283 </div>
284 </div>
285
286
287 <!-- Modal for Add Invite -->
288 <div class="modal fade" id="invite" tabindex="-1" role="dialog" aria-labelledby="add_invite_modal" aria-hidden="true">
289 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
290 <div class="modal-content">
291 <div class="modal-header">
292 <h5 class="modal-title" id="add_invite_modal">Add New Channel Invite</h5>
293 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
294 <span aria-hidden="true">&times;</span>
295 </div>
296 </div>
297 <div class="modal-body">
298 <form method="post">
299 <div class="input-group mb-3">
300 <label for="ban_nick">Mask
301 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
302 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"
303 ></i></a>
304 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
305 placeholder="nick!user@host or something else"
306 ></label>
307
308 </div>
309 <div class="input-group mb-3">
310 <label for="bantype_sel_type">Invite Type
311 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
312 <option></option>
313 <option>Match Account</option>
314 <option>Match Channel</option>
315 <option>Match Country</option>
316 <option>Match OperClass</option>
317 <option>Match RealName / GECOS</option>
318 <option>Match Security Group</option>
319 <option>Match Certificate Fingerprint</option>
320 </select>
321 </label>
322 </div>
323 <div class="input-group mb-3">
324 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
325 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
326 </label>
327 </div>
328 </div>
329 <div class="modal-footer">
330 <input type="hidden" name="add_chinv" value="I"></input>
331 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
332 <button type="submit" action="post" class="btn btn-danger">Add Invite</button>
333 </form>
334 </div>
335 </div>
336 </div>
337 </div>
338
339 <!-- Modal for Add Ban Exceptions -->
340 <div class="modal fade" id="except" tabindex="-1" role="dialog" aria-labelledby="except" aria-hidden="true">
341 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
342 <div class="modal-content">
343 <div class="modal-header">
344 <h5 class="modal-title" >Add New Channel Ban Exception</h5>
345 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
346 <span aria-hidden="true">&times;</span>
347 </div>
348 </div>
349 <div class="modal-body">
350 <form method="post">
351 <div class="input-group mb-3">
352 <label for="ban_nick">Mask
353 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
354 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"
355 ></i></a>
356 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
357 placeholder="nick!user@host or something else"
358 ></label>
359
360 </div>
361 <div class="input-group mb-3">
362 <label for="bantype_sel_type">Ban Type
363 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
364 <option></option>
365 <option>Match Account</option>
366 <option>Match Channel</option>
367 <option>Match Country</option>
368 <option>Match OperClass</option>
369 <option>Match RealName / GECOS</option>
370 <option>Match Security Group</option>
371 <option>Match Certificate Fingerprint</option>
372 </select>
373 </label>
374 </div>
375 <div class="input-group mb-3">
376 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
377 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
378 </label>
379 </div>
380 </div>
381 <div class="modal-footer">
382 <input type="hidden" id="server" name="add_chex" value="e"></input>
383 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
384 <button type="submit" action="post" class="btn btn-danger">Add Exception</button>
385 </form>
386 </div>
387 </div>
388 </div>
389 </div>
390
391 <!-- Modal for Edit Channel Modes -->
392 <div class="modal fade" id="editchmodes" tabindex="-1" role="dialog" aria-labelledby="editchmodes" aria-hidden="true">
393 <div class="modal-dialog modal-dialog-centered" role="document">
394 <div class="modal-content">
395 <div class="modal-header">
396 <h5 class="modal-title" id="editchmodes">Edit Channel Modes</h5>
397 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
398 <span aria-hidden="true">&times;</span>
399 </div>
400 </div>
401 <div class="modal-body">
402 <form method="post">
403 <?php generate_edit_chmodes($channelObj); ?>
404 <input type="hidden" id="server" name="add_chex" value="e"></input>
405 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
406 <button type="submit" action="post" class="btn btn-danger">Update</button>
407 </form>
408 </div>
409 </div>
410 </div>
411 </div>
412
413 <br>
414 <h6>
415 Topic:<br></h6>
416 <form method="post" action="details.php?chan=<?php echo urlencode($channelObj->name); ?>">
417 <div class="input-group">
418 <input maxlength="360" type="text" class="input-group form-control" name="set_topic" value="<?php echo (isset($channelObj->topic)) ? htmlspecialchars($channelObj->topic) : ""; ?>">
419 <div class="input-group-append"><button type="submit" name="update_topic" value="true" class="btn btn-info">Update Topic</button></div></div>
420 </form>
421 <?php
422 if ($topicset)
423 Message::Success("The topic for $channelObj->name has been updated to be: \"".htmlspecialchars($channelObj->topic)."\"");
424 ?>
425 <br>
426
427 <!-- Modal for User Action -->
428 <div class="modal fade" id="useraction" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
429 <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
430 <div class="modal-content">
431 <div class="modal-header">
432 <h5 class="modal-title" id="myModalLabel">Add New Channel Ban</h5>
433 <div type="button" class="close" data-dismiss="modal" aria-label="Close">
434 <span aria-hidden="true">&times;</span>
435 </div>
436 </div>
437 <div class="modal-body">
438 <form method="post">
439 <div class="input-group mb-3">
440 <label for="ban_nick">Mask
441 <a href="https://www.unrealircd.org/docs/Extended_bans" target="__blank"><i class="fa fa-info-circle" aria-hidden="true"
442 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"
443 ></i></a>
444 <input style="width: 170%;" name="ban_nick" id="ban_nick" class="form-control curvy" type="text"
445 placeholder="nick!user@host or something else"
446 ></label>
447
448 </div>
449 <div class="input-group mb-3">
450 <label for="bantype_action">Ban Action
451 <select class="form-control" name="bantype_sel_action" id="bantype_sel">
452 <option></option>
453 <option>Quiet (Mute)</option>
454 <option>Nick-change</option>
455 <option>Join</option>
456 </select>
457 </label>
458 </div>
459 <div class="input-group mb-3">
460 <label for="bantype_sel_type">Ban Type
461 <select class="form-control" name="bantype_sel_type" id="bantype_sel_type">
462 <option></option>
463 <option>Match Account</option>
464 <option>Match Channel</option>
465 <option>Match Country</option>
466 <option>Match OperClass</option>
467 <option>Match RealName / GECOS</option>
468 <option>Match Security Group</option>
469 <option>Match Certificate Fingerprint</option>
470 </select>
471 </label>
472 </div>
473 <div class="input-group mb-3">
474 <label for="bantype_sel_ex">Expiry Date-Time <br><small>Leave blank to mean "Permanent"</small>
475 <input type="datetime-local" name="bantype_sel_ex" id="bantype_sel_ex" class="form-control">
476 </label>
477 </div>
478 </div>
479 <div class="modal-footer">
480 <input type="hidden" id="server" name="add_chban" value="b"></input>
481 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
482 <button type="submit" action="post" class="btn btn-danger">Add Channel Ban</button>
483 </form>
484 </div>
485 </div>
486 </div>
487 </div>
488
489 <div class="container-xxl">
490 <div class="row">
491 <div class="col-sm-4">
492 <div class="card">
493 <div class="card-body">
494 <h6 class="card-title">User List</h6>
495 <p class="card-text"><?php generate_chan_occupants_table($channelObj); ?></p>
496 </div>
497 </div>
498 </div>
499 <div class="col-sm-8">
500 <div class="card">
501 <div class="card-body">
502 <h6 class="card-title">Channel Settings</h6>
503 <ul class="nav nav-tabs" role="tablist">
504 <li class="nav-item" role="presentation"><a class="nav-link" href="#chanmodes" aria-controls="chanmodes" role="tab" data-toggle="tab">Settings / Modes</a></li>
505 <li class="nav-item" role="presentation"><a class="nav-link" href="#chanbans" aria-controls="chanbans" role="tab" data-toggle="tab">Bans</a></li>
506 <li class="nav-item" role="presentation"><a class="nav-link" href="#chaninv" aria-controls="chaninv" role="tab" data-toggle="tab">Invites</a></li>
507 <li class="nav-item" role="presentation"><a class="nav-link" href="#chanex" aria-controls="chanex" role="tab" data-toggle="tab">Excepts</a></li>
508 </ul>
509
510 <div class="tab-content">
511 <br>
512 <div class="tab-pane fade in" id="chanmodes">
513 <button id="editlol" class="btn btn-sm btn-primary" <?php echo ($can_edit) ? "" : "disabled"; ?>>Change Settings</button>
514 <p class="card-text"><?php generate_html_chansettings($channelObj); ?></p>
515 </div><form id="editchanmodes" method="post" name="editchanmodes">
516 <div class="tab-pane" style="display: none" id="chanmodes_edit">
517
518 <div class="btn btn-sm btn-secondary" id="editchmodesbk">Go back</div>
519 <button type="submit" class="btn btn-sm btn-primary">Save Changes</button>
520 <p class="card-text"><?php generate_edit_chmodes($channelObj); ?></p>
521 </form>
522 </div>
523
524 <div class="tab-pane fade in" id="chanbans">
525 <p class="card-text"><?php generate_chanbans_table($channelObj); ?></p>
526 </div>
527 <div class="tab-pane fade in" id="chaninv">
528 <p class="card-text"><?php generate_chaninvites_table($channelObj); ?></p>
529 </div>
530 <div class="tab-pane fade in" id="chanex">
531 <p class="card-text"><?php generate_chanexcepts_table($channelObj); ?></p>
532 </div>
533 <div class="tab-pane fade in" id="chanmodes_edit">
534 <p class="card-text"><?php /* insert hacks here */ ?></p>
535 </div>
536
537 </div>
538 </div>
539 </div>
540 </div>
541 </div>
542 <script>
543 const toggleBtn = document.getElementById('editlol');
544 const staticInfo = document.getElementById('chanmodes');
545 const options = document.getElementById('chanmodes_edit');
546 const backBtn = document.getElementById('editchmodesbk');
547
548 backBtn.addEventListener('click', function() {
549 staticInfo.style.display = '';
550 options.style.display = 'none';
551 });
552 toggleBtn.addEventListener('click', function() {
553 staticInfo.style.display = 'none';
554 options.style.display = '';
555 });
556
557 // show dat first tab
558 $('.nav-tabs a[href="#chanmodes"]').tab('show')
559 </script>
560 <?php
561 require_once("../inc/footer.php");
562