]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - misc/channel-lookup-misc.php
Logs: show search pane (on desktop)
[irc/unrealircd/unrealircd-webpanel.git] / misc / channel-lookup-misc.php
CommitLineData
261e05e8 1<?php
261e05e8
VP
2function generate_chanbans_table($channel)
3{
0b82418b
VP
4 global $rpc;
5 $channel = $rpc->channel()->get($channel->name);
861eaec3 6 ?><p><table class="container-xxl table table-sm table-responsive caption-top table-striped">
e92763ac
VP
7 <button class="btn btn-primary mr-1 btn-sm" data-toggle="modal" data-target="#ban">Add New</button>
8 <form method="post">
0b82418b
VP
9 <button class="btn btn-info btn-sm" type="submit" name="delete_sel_ban">Delete</button>
10 </p>
e92763ac 11
0b82418b
VP
12 <thead class="table-info">
13 <th><input type="checkbox" label='selectall' onClick="toggle_chanbans(this)" /></th>
14 <th>Name</th>
15 <th>Set by</th>
16 <th>Set at</th>
17 <th></th>
18 </thead>
19 <tbody>
20 <?php
21 foreach ($channel->bans as $ban) {
22 echo "<tr>";
23 echo "<td scope=\"row\"><input type=\"checkbox\" value='$ban->name' name=\"cb_checkboxes[]\"></td>";
24 echo "<td><code>".htmlspecialchars($ban->name)."</code></td>";
25 $set_by = htmlspecialchars($ban->set_by);
26 echo "<td>$set_by</td>";
27 $set_at = $ban->set_at;
28 echo "<td>$set_at</td>";
29 echo "<td></td>";
30 echo "</tr>";
31 }
32
33 ?>
34 </tbody>
35 </table>
36 </form>
37 <?php
261e05e8
VP
38}
39function generate_chaninvites_table($channel)
40{
0b82418b
VP
41 global $rpc;
42 $channel = $rpc->channel()->get($channel->name);
861eaec3 43 ?><p><table class="table table-sm table-responsive table-hover caption-top table-striped">
e92763ac
VP
44 <button class="btn btn-primary btn-sm mr-1" data-toggle="modal" data-target="#invite">Add New</button>
45 <form method="post">
0b82418b
VP
46 <button class="btn btn-info btn-sm" type="submit" name="delete_sel_inv">Delete</button>
47 </p>
e92763ac 48
0b82418b
VP
49 <thead class="table-info">
50 <th><input type="checkbox" label='selectall' onClick="toggle_chaninvs(this)" /></th>
51 <th>Name</th>
52 <th>Set by</th>
53 <th>Set at</th>
54 <th></th>
55 </thead>
56 <tbody>
57 <?php
58 foreach ($channel->invite_exceptions as $inv) {
59 echo "<tr>";
60 echo "<td scope=\"row\"><input type=\"checkbox\" value='$inv->name' name=\"ci_checkboxes[]\"></td>";
61 echo "<td><code>".htmlspecialchars($inv->name)."</code></td>";
62 $set_by = htmlspecialchars($inv->set_by);
63 echo "<td>$set_by</td>";
64 $set_at = $inv->set_at;
65 echo "<td>$set_at</td>";
66 echo "<td></td>";
67 echo "</tr>";
68 }
69
70 ?>
71 </tbody>
72 </table>
73 </form>
74 <?php
261e05e8
VP
75}
76
77
78function generate_chanexcepts_table($channel)
79{
0b82418b 80 global $rpc;
4bc0dbc0 81
0b82418b 82 $channel = $rpc->channel()->get($channel->name);
861eaec3 83 ?><p><table class="table table-sm table-responsive table-hover caption-top table-striped">
e92763ac 84 <button class="btn btn-primary mr-1 btn-sm" data-toggle="modal" data-target="#except">Add New</button>
4bc0dbc0 85 <form method="post">
0b82418b
VP
86 <button class="btn btn-info btn-sm" type="submit" name="delete_sel_ex">Delete</button>
87 </p>
e92763ac 88
0b82418b
VP
89 <thead class="table-info">
90 <th><input type="checkbox" label='selectall' onClick="toggle_chanexs(this)" /></th>
91 <th>Name</th>
92 <th>Set by</th>
93 <th>Set at</th>
94 <th></th>
95 </thead>
96 <tbody>
97 <?php
98 foreach ($channel->ban_exemptions as $ex) {
99 echo "<tr>";
100 echo "<td scope=\"row\"><input type=\"checkbox\" value='$ex->name' name=\"ce_checkboxes[]\"></td>";
101 echo "<td><code>".htmlspecialchars($ex->name)."</code></td>";
102 $set_by = htmlspecialchars($ex->set_by);
103 echo "<td>$set_by</td>";
104 $set_at = $ex->set_at;
105 echo "<td>$set_at</td>";
106 echo "<td></td>";
107 echo "</tr>";
108 }
261e05e8 109
0b82418b
VP
110 ?>
111 </tbody>
112 </table>
113 </form>
114 <?php
115}
261e05e8 116
0b82418b
VP
117/**
118 * Generate the user list of a channel
119 *
120 * Why is it called chan occupants? o.o
121 * For the code, to avoid mixups
122 * It's called "User List" on the website
123 * @param mixed $channel
124 * @return void
125 */
261e05e8
VP
126function generate_chan_occupants_table($channel)
127{
e92763ac 128 global $rpc;
0b82418b
VP
129 ?>
130 <form method="post"><p>
131
132 </p>
e92763ac 133 <table class="container-xxl table table-sm table-responsive caption-top table-striped">
0b82418b
VP
134 <thead class="table-info">
135 <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
136 <th>Name</th>
137 <th>Status</th>
43a6787a 138 <th>Host</th>
0b82418b
VP
139 </thead>
140 <tbody>
141 <?php
e92763ac 142 $m = sort_user_list($channel->members);
43a6787a
VP
143
144 $i = 0;
e92763ac 145 foreach ($m as $member)
d2db68e3
VP
146 {
147 $lvlstring = "";
148
149 if (isset($member->level))
150 {
151 for ($i = 0; isset($member->level[$i]) && $m = $member->level[$i]; $i++)
152 {
153 switch ($m)
154 {
155 case "v":
1159c538 156 $lvlstring .= "<div class='badge rounded-pill badge-primary'>Voice</div> ";
d2db68e3
VP
157 break;
158 case "h":
1159c538 159 $lvlstring .= "<div class='badge rounded-pill badge-secondary'>Half-Op</div> ";
d2db68e3
VP
160 break;
161 case "o":
1159c538 162 $lvlstring .= "<div class='badge rounded-pill badge-warning'>Op</div> ";
d2db68e3
VP
163 break;
164 case "a":
1159c538 165 $lvlstring .= "<div class='badge rounded-pill badge-danger'>Admin</div> ";
d2db68e3
VP
166 break;
167 case "q":
1159c538 168 $lvlstring .= "<div class='badge rounded-pill badge-success'>Owner</div> ";
d2db68e3
VP
169 break;
170
171 // providing support third/ojoin
172 case "Y":
1159c538 173 $lvlstring .= "<div class='badge rounded-pill'>OJOIN</div> ";
d2db68e3
VP
174 break;
175 }
176 }
177 }
43a6787a 178
0b82418b 179 echo "<tr>";
d2db68e3
VP
180 ?><form method="post" action=""><?php
181 $disabled = (current_user_can(PERMISSION_EDIT_CHANNEL_USER)) ? "" : "disabled";
182 $disabledcolor = ($disabled) ? "btn-secondary" : "btn-primary";
0b82418b 183 echo "<td scope=\"row\"><input type=\"checkbox\" value='$member->id' name=\"checkboxes[]\"></td>";
ea90b321 184 echo "<td><a href=\"".get_config("base_url")."users/details.php?nick=$member->id\">".htmlspecialchars($member->name)."</a></td>";
e92763ac 185 echo "<td class='text-right'>$lvlstring</td>";
43a6787a 186 echo "<td><code>".((property_exists($member, 'hostname')) ? htmlspecialchars($member->hostname) : "")."</code></td>";
0b82418b
VP
187 echo "</tr>";
188 }
189
190 ?>
191 </tbody>
192 </table>
193 </form>
194
195 <?php
196}
197
d2db68e3
VP
198function generate_html_chansettings($channel)
199{
d2db68e3 200 ?>
43a6787a 201
d2db68e3
VP
202 <table class="table-sm table-responsive caption-top table-hover">
203 <tbody>
204 <?php
205 if (BadPtr($channel->modes))
206 {
207 echo "No modes set";
208 return;
209 }
210 $fmodes = $channel->modes;
211 $tok = split($fmodes);
212 $modes = $tok[0];
213 $params = rparv($fmodes);
4bc0dbc0
VP
214 $paramed_modes = sort_paramed_modes($modes, $params);
215
d2db68e3
VP
216 for ($i=0; ($mode = (isset($modes[$i])) ? $modes[$i] : NULL); $i++)
217 {
4bc0dbc0 218 $modeinfo = IRCList::lookup($mode);
43a6787a
VP
219 if (!$modeinfo)
220 continue;
d2db68e3
VP
221 ?>
222 <tr>
223 <th><?php echo $modeinfo['name']; ?></th>
e049b2a2 224 <td><code><?php echo isset($paramed_modes[$mode]) ? $paramed_modes[$mode] : ""; ?></code></td>
d2db68e3
VP
225 <td>
226 <?php echo $modeinfo['description']; ?>
227 </td>
228 </tr>
229 <?php
230 }
231
232
233 ?>
234 </tbody>
235 </table>
236
237 <?php
238}
239
7eeec1d6
BM
240/** Return user-friendly mode group names as an array like:
241 * "Join restrictions"=>"kliRzOL", ...
242 * The group "Other" has a number of preset ones PLUS
243 * will be automatically filled with any remaining modes
244 * that are detected and that we forgot to put in Other.
245 */
246function group_modes()
247{
248 $modes = '';
249 foreach(IRCList::$uplink as $mode_groups)
250 $modes .= $mode_groups;
251
252 $grouping = IRCList::$grouping;
253
254 foreach (str_split($modes) as $letter)
255 {
256 $found = false;
257 foreach($grouping as $groupname=>$value)
258 {
259 if (str_contains($value, $letter))
260 {
261 $found = true;
262 break;
263 }
264 }
265 if (!$found)
266 $grouping["Other"] .= $letter;
267
268 }
269 return $grouping;
270}
271
43a6787a
VP
272function generate_edit_chmodes($chan)
273{
274 ?>
43a6787a 275 <?php
7eeec1d6
BM
276 if (!isset($chan->modes))
277 {
278 echo "No modes set";
279 return;
280 }
281 $fmodes = $chan->modes;
282 $tok = split($fmodes);
283 $modes = $tok[0];
284 $params = rparv($fmodes);
285 $paramed_modes = sort_paramed_modes($modes, $params);
ae7257d0 286
7eeec1d6
BM
287 $all_modes = IRCList::$uplink;
288 $groups = group_modes();
289
290 foreach ($groups as $group_name=>$m)
291 {
292 echo "<fieldset class=\"border p-1 col-sm-6\">\n";
293 echo "<legend class=\"w-auto\" style=\"font-size: 16px\">$group_name</legend>\n";
294 for ($i=0; ($mode = (isset($m[$i])) ? $m[$i] : NULL); $i++)
295 {
296 $group = get_chmode_group($mode);
297 if (!$group || $group == 1)
298 continue;
299 $modeinfo = IRCList::lookup($mode);
300 $checked = (strstr($modes,$mode)) ? "checked " : " ";
301
302 $disabled = "";
303 if (isset($modeinfo) && $modeinfo['requires'] == "Server")
304 $disabled = "disabled";
305
306 ?>
307 <div class="form-group row">
308 <div class="col-sm-5">
309 <input <?php echo $checked.$disabled; ?> type="checkbox" value='<?php echo $mode; ?>' name="newmodes[]">
310 <span data-toggle="tooltip" data-placement="top" title="<?php echo htmlspecialchars($modeinfo['description']); ?>"><?php echo htmlspecialchars($modeinfo['name'])." (<code>+$mode</code>)"; ?>
311 </div>
312 <div class="col-sm-2">
43a6787a 313 <?php
7eeec1d6
BM
314
315 if ($group == 2 || $group == 3)
316 {
317 ?><input type="text" class="input-group-sm" name="paramed_modes[<?php echo $mode; ?>]"
318 id="<?php echo $mode; ?>" value="<?php echo ($checked)
319 ?
320 htmlspecialchars(
321 isset($paramed_modes[$mode])
322 ?
323 $paramed_modes[$mode]
324 :
325 ""
326 )
327 :
328 ""; ?>"><?php
329 }
330 ?>
331 </div>
332 </div>
333 <?php
334 }
335 echo "</fieldset>\n";
336 }
43a6787a 337 ?>
43a6787a
VP
338 <?php
339}
340
341function get_chmode_group(string $mode) : int
342{
343 foreach(IRCList::$uplink as $i => $grp)
344 if (strstr($grp,$mode))
345 return $i + 1;
346
347 return 0; // invalid
348}
349
785717b4
VP
350/**
351 * Force loading of a particular modal by name
352 */
0b82418b
VP
353function chlkup_autoload_modal($name)
354{
355 ?>
356 <script>
357 $(document).ready(function () {
358 $("#<?php echo $name; ?>").modal("show");
359 });
360 </script>
361 <?php
362}
363
43a6787a
VP
364/**
365 * Returns an array of parametered modes and their params
366 */
367function sort_paramed_modes($modes, $params) : array
368{
369 $m = [];
370 for ($i=0; isset($modes[$i]) && $mode = $modes[$i]; $i++)
371 {
372 $group = get_chmode_group($mode);
373 if ($group != 2 && $group != 3)
374 continue;
375 $p = split($params);
376 $m[$mode] = $p[0];
377 $p[0] = NULL;
378 $params = glue($p);
379 }
380 return $m;
381}
0b82418b
VP
382
383function _do_chan_item_delete($chan, string $type, array $list, array &$errors) : bool
384{
385 global $rpc;
386 $n = "";
387 $str = "";
388
389 if ($type == "invite")
390 $char = "I";
391 elseif ($type == "ban")
392 $char = "b";
393 elseif ($type == "except")
394 $char = "e";
395 else
396 return false;
397
398 foreach($list as $l)
399 {
400 $n .= $char;
401 $str .= " ".$l;
402 }
e92763ac 403 if ($rpc->channel()->set_mode($chan->name, htmlspecialchars("-$n"), htmlspecialchars($str)))
0b82418b
VP
404 {
405 Message::Success("Deleted successfully");
406 return true;
407 }
408 $errors[] = $rpc->error . " ($rpc->errno)";
409 Message::Fail("An error occurred: $rpc->error");
410 return false;
411}
412
413function do_delete_invite($chan, $list)
414{
415 $errs = [];
416 _do_chan_item_delete($chan, "invite", $list, $errs);
417}
418
419function do_delete_chanban($chan, $list)
420{
421 $errs = [];
422 _do_chan_item_delete($chan, "ban", $list, $errs);
423}
424
425function do_delete_chanex($chan, $list)
426{
427 $errs = [];
428 _do_chan_item_delete($chan, "except", $list, $errs);
e92763ac
VP
429}
430
431
432
433/**
434 * Sort the channels user list:
435 */
436function sort_user_list($list) : array
437{
438 if (empty($list))
439 return $list;
440
441 $new = [];
442 foreach($list as $k => $user)
443 {
444 if (!property_exists($user,"level"))
445 {
446 $new["rest"][] = $user;
447 $list[$k] = NULL;
448 }
449 else if (strstr($user->level,"Y"))
450 {
451 $new["Y"][] = $user;
452 $list[$k] = NULL;
453 }
454 else if (strstr($user->level,"q"))
455 {
456 $new["q"][] = $user;
457 $list[$k] = NULL;
458 }
459 else if (strstr($user->level,"a"))
460 {
461 $new["a"][] = $user;
462 $list[$k] = NULL;
463 }
464 else if (strstr($user->level,"o"))
465 {
466 $new["o"][] = $user;
467 $list[$k] = NULL;
468 }
469 else if (strstr($user->level,"h"))
470 {
471 $new["h"][] = $user;
472 $list[$k] = NULL;
473 }
474 else if (strstr($user->level,"v"))
475 {
476 $new["v"][] = $user;
477 $list[$k] = NULL;
478 }
479
480 }
481
482 unset($list);
483 $list = [];
484 if (isset($new["q"]))
485 foreach($new["q"] as $u)
486 $list[] = $u;
487
488 if (isset($new["a"]))
489 foreach($new["a"] as $u)
490 $list[] = $u;
491
492 if (isset($new["o"]))
493 foreach($new["o"] as $u)
494 $list[] = $u;
495
496 if (isset($new["h"]))
497 foreach($new["h"] as $u)
498 $list[] = $u;
499
500 if (isset($new["v"]))
501 foreach($new["v"] as $u)
502 $list[] = $u;
503
504 if (isset($new["rest"]))
505 foreach($new["rest"] as $u)
506 $list[] = $u;
507
508 return $list;
261e05e8 509}