]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - api/users.php
Fix setting zlines on idents, reported by Jellis
[irc/unrealircd/unrealircd-webpanel.git] / api / users.php
index c0a30098fe4ada4997d301a4b7a6d7af17220294..c2e623411d9f75ef5408d05d0490ecd9c5691685 100644 (file)
@@ -1,56 +1,57 @@
 <?php
 
-require_once "../common.php";
-require_once "../connection.php";
+define('NO_EVENT_STREAM_HEADER',1);
+require_once('common_api.php');
+header("Content-type: application/json; charset=utf-8");
 
-header('Content-Type: application/json');
+if (!$rpc)
+       die(json_encode([]));
 
-if (!isset($_SESSION['id']))
-    die("Access denied");
+/* Get the user list */
+$users = $rpc->user()->getAll();
 
-if (!isset($_GET) || empty($_GET))
+$out = [];
+foreach($users as $user)
 {
-    if ($list = $rpc->user()->getAll())
-        echo json_encode($list);
-    else
-        echo json_encode(["error" => "No users found"]);
-    die();
+       $isBot = (strpos($user->user->modes, "B") !== false) ? ' <span class="badge rounded-pill badge-dark">Bot</span>' : "";
+       $nick = htmlspecialchars($user->name).$isBot;
+
+       $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) : "";
+
+       if ($user->hostname == $user->ip)
+                       $hostip = $user->ip;
+       else if ($user->ip == null)
+                       $hostip = $user->hostname;
+       else
+                       $hostip = $user->hostname . " (".$user->ip.")";
+       $hostip = htmlspecialchars($hostip);
+       
+       $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>';
+       $oper = (isset($user->user->operlogin)) ? $user->user->operlogin." <span class=\"badge rounded-pill badge-secondary\">".$user->user->operclass."</span>" : "";
+       if (!strlen($oper))
+                       $oper = (strpos($user->user->modes, "S") !== false) ? '<span class="badge rounded-pill badge-warning">Services Bot</span>' : "";
+       $servername = $user->user->servername;
+       $reputation = $user->user->reputation;
+
+       $nick = "<a href=\"details.php?nick=".$user->id."\">$nick</a>";
+
+       $out[] = [
+               "Select" => "<input type=\"checkbox\" value='" . base64_encode($user->id)."' name=\"userch[]\">", /* yeah ridiculous to have here in this file and the feed ;) */
+               "Nick" => $nick,
+               "Country" => $country,
+               "Host/IP" => $hostip,
+               "Account" => $account,
+               "Oper" => $oper,
+               "Connected to" => $servername,
+               "Reputation" => $reputation,
+       ];
 }
-elseif (isset($_GET['lookup']))
+
+function custom_sort($a,$b)
 {
-    if ($user = $rpc->user()->get($_GET['lookup']))
-        echo json_encode($user);
-    else
-        echo json_encode(["error" => "User not found"]);
-    die();
+       return strcmp(strtoupper($a["Nick"]), strtoupper($b["Nick"]));
 }
 
-else // we're filtering
-{
-    if (!($list = $rpc->user()->getAll()))
-    {
-        echo json_encode(["error" => "No users found"]);
-        die();
-    }
-
-    $return_list = [];
-    
-    if (isset($_GET['nick']) && !empty($_GET['nick']) && $nick = strtolower($_GET['nick']))
-    {
-        foreach ($list as $user)
-        {
-            if (strstr(strtolower($user->name), $nick))
-                $return_list[] = $user;
-        }
-    }
-    if (isset($_GET['hostname']) && !empty($_GET['hostname']) && $nick = strtolower($_GET['hostname']))
-    {
-        foreach ($list as $user)
-        {
-            if (strstr(strtolower($user->name), $nick))
-                $return_list[] = $user;
-        }
-    }
-    echo json_encode($return_list);
-    
-}
\ No newline at end of file
+usort($out, "custom_sort");
+
+echo json_encode($out);