]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - api/users.php
Make $pages[] not have a string value in the end but an array with ["url"=>...]
[irc/unrealircd/unrealircd-webpanel.git] / api / users.php
1 <?php
2
3 define('NO_EVENT_STREAM_HEADER',1);
4 require_once('common_api.php');
5 header("Content-type: application/json; charset=utf-8");
6
7 /* Get the user list */
8 $users = $rpc->user()->getAll();
9
10 $out = [];
11 foreach($users as $user)
12 {
13 $isBot = (strpos($user->user->modes, "B") !== false) ? ' <span class="badge rounded-pill badge-dark">Bot</span>' : "";
14 $nick = htmlspecialchars($user->name).$isBot;
15
16 $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) : "";
17
18 if ($user->hostname == $user->ip)
19 $hostip = $user->ip;
20 else if ($user->ip == null)
21 $hostip = $user->hostname;
22 else
23 $hostip = $user->hostname . " (".$user->ip.")";
24 $hostip = htmlspecialchars($hostip);
25
26 $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>';
27 $oper = (isset($user->user->operlogin)) ? $user->user->operlogin." <span class=\"badge rounded-pill badge-secondary\">".$user->user->operclass."</span>" : "";
28 if (!strlen($oper))
29 $oper = (strpos($user->user->modes, "S") !== false) ? '<span class="badge rounded-pill badge-warning">Services Bot</span>' : "";
30 $servername = $user->user->servername;
31 $reputation = $user->user->reputation;
32
33 $nick = "<a href=\"details.php?nick=".$user->id."\">$nick</a>";
34
35 $out[] = [
36 "Select" => "<input type=\"checkbox\" value='" . base64_encode($user->id)."' name=\"userch[]\">", /* yeah ridiculous to have here in this file and the feed ;) */
37 "Nick" => $nick,
38 "Country" => $country,
39 "Host/IP" => $hostip,
40 "Account" => $account,
41 "Oper" => $oper,
42 "Connected to" => $servername,
43 "Reputation" => $reputation,
44 ];
45 }
46
47 function custom_sort($a,$b)
48 {
49 return strcmp(strtoupper($a["Nick"]), strtoupper($b["Nick"]));
50 }
51
52 usort($out, "custom_sort");
53
54 echo json_encode($out);