]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - api/users.php
Add a `Plugins` overview card
[irc/unrealircd/unrealircd-webpanel.git] / api / users.php
CommitLineData
cd5d0af0
VP
1<?php
2
5485abb5
BM
3define('NO_EVENT_STREAM_HEADER',1);
4require_once('common_api.php');
5header("Content-type: application/json; charset=utf-8");
cd5d0af0 6
cefec45f
BM
7if (!$rpc)
8 die(json_encode([]));
9
5485abb5
BM
10/* Get the user list */
11$users = $rpc->user()->getAll();
cd5d0af0 12
5485abb5
BM
13$out = [];
14foreach($users as $user)
cd5d0af0 15{
5485abb5
BM
16 $isBot = (strpos($user->user->modes, "B") !== false) ? ' <span class="badge rounded-pill badge-dark">Bot</span>' : "";
17 $nick = htmlspecialchars($user->name).$isBot;
18
19 $country = isset($user->geoip->country_code) ? '<img src="https://flagcdn.com/48x36/'.htmlspecialchars(strtolower($user->geoip->country_code)).'.png" width="20" height="15"> '.htmlspecialchars($user->geoip->country_code) : "";
20
21 if ($user->hostname == $user->ip)
22 $hostip = $user->ip;
23 else if ($user->ip == null)
24 $hostip = $user->hostname;
25 else
26 $hostip = $user->hostname . " (".$user->ip.")";
27 $hostip = htmlspecialchars($hostip);
28
29 $account = (isset($user->user->account)) ? "<a href=\"".get_config("base_url")."users/?account=".$user->user->account."\">".htmlspecialchars($user->user->account)."</a>" : '<span class="badge rounded-pill badge-primary">None</span>';
5485abb5
BM
30 $oper = (isset($user->user->operlogin)) ? $user->user->operlogin." <span class=\"badge rounded-pill badge-secondary\">".$user->user->operclass."</span>" : "";
31 if (!strlen($oper))
32 $oper = (strpos($user->user->modes, "S") !== false) ? '<span class="badge rounded-pill badge-warning">Services Bot</span>' : "";
5485abb5
BM
33 $servername = $user->user->servername;
34 $reputation = $user->user->reputation;
35
36 $nick = "<a href=\"details.php?nick=".$user->id."\">$nick</a>";
37
38 $out[] = [
78142aba 39 "Select" => "<input type=\"checkbox\" value='" . base64_encode($user->id)."' name=\"userch[]\">", /* yeah ridiculous to have here in this file and the feed ;) */
5485abb5
BM
40 "Nick" => $nick,
41 "Country" => $country,
42 "Host/IP" => $hostip,
43 "Account" => $account,
5485abb5 44 "Oper" => $oper,
5485abb5
BM
45 "Connected to" => $servername,
46 "Reputation" => $reputation,
47 ];
cd5d0af0 48}
5485abb5
BM
49
50function custom_sort($a,$b)
cd5d0af0 51{
5485abb5 52 return strcmp(strtoupper($a["Nick"]), strtoupper($b["Nick"]));
cd5d0af0
VP
53}
54
5485abb5
BM
55usort($out, "custom_sort");
56
57echo json_encode($out);