]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Make API pages return empty data / die when server is not available.
authorBram Matthys <redacted>
Wed, 26 Apr 2023 16:27:57 +0000 (18:27 +0200)
committerBram Matthys <redacted>
Wed, 26 Apr 2023 16:27:57 +0000 (18:27 +0200)
This fixes annoying JS popup in "Users" and "Server bans" when the
IRC server is down.

api/notification.php
api/overview.php
api/server-bans.php
api/users.php
inc/connection.php

index e403b753ea9e8a4f37bf15084cbc04256d22c09f..df1b91c00197ab62d13e25f02b263daf5806485e 100644 (file)
@@ -2,4 +2,7 @@
 
 require_once('common_api.php');
 
+if (!$rpc)
+    die();
+
 api_log_loop(["!debug", "warn", "error", "link"]);
index a4bf424b798039f8ebca2eb2e74f0bf889d66b0e..c77905dbb1f75f23c3c0f25e8f4a2bd99522dd39 100644 (file)
@@ -1,4 +1,7 @@
 <?php
 require_once('common_api.php');
 
+if (!$rpc)
+    die();
+
 api_timer_loop(1000, "stats.get");
index baff47e5a110607a634d348d6df640d7f9c35cec..225511f114c7ccf60442c6465b1dc74fb0bbf534 100644 (file)
@@ -1,8 +1,12 @@
 <?php
-
 define('NO_EVENT_STREAM_HEADER',1);
 require_once('common_api.php');
 header("Content-type: application/json; charset=utf-8");
+
+if (!$rpc)
+    die(json_encode([]));
+
+
 $tkls = $rpc->serverban()->getAll();
 
 $out = [];
index f516f12a719f48b2a9166d2da3b97869a52ce39d..c2e623411d9f75ef5408d05d0490ecd9c5691685 100644 (file)
@@ -4,6 +4,9 @@ define('NO_EVENT_STREAM_HEADER',1);
 require_once('common_api.php');
 header("Content-type: application/json; charset=utf-8");
 
+if (!$rpc)
+       die(json_encode([]));
+
 /* Get the user list */
 $users = $rpc->user()->getAll();
 
index f66d7507b7d65d3bf7f1ffaefe2560d610cc73b9..0a06ab2a6d64225aecf699e9f6035db8c2197806 100644 (file)
@@ -8,9 +8,15 @@ function connect_to_ircd()
        GLOBAL $rpc;
        GLOBAL $config;
 
+       $is_api_page = str_contains($_SERVER['SCRIPT_FILENAME'], "/api/") ? true : false;
+
+       $rpc = null; /* Initialize, mostly for API page failures */
+
        $server = get_active_rpc_server();
        if (!$server)
        {
+               if ($is_api_page)
+                       return;
                Message::Fail("No RPC server configured. Go to Settings - RPC Servers.");
                die;
        }
@@ -23,10 +29,16 @@ function connect_to_ircd()
        $tls_verify = $config["unrealircd"][$server]["tls_verify_cert"];
 
        if (!$host || !$port || !$rpc_user)
+       {
+               if ($is_api_page)
+                       return;
                die("RPC Server is missing credentials");
+       }
 
        if ($rpc_password === null)
        {
+               if ($is_api_page)
+                       return;
                Message::Fail("Your RPC password in the DB was encrypted with a different key than config/config.php contains.<br>\n".
                              "Either restore your previous config/config.php or start with a fresh database.<br>\n");
                die;
@@ -43,10 +55,11 @@ function connect_to_ircd()
        }
        catch (Exception $e)
        {
+               if ($is_api_page)
+                       return;
                Message::Fail("Unable to connect to UnrealIRCd: ".$e->getMessage() . "<br>".
-                             "Verify your connection details in config.php (rpc user, rpc password, host) and ".
-                             "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ".
-                             "an rpc-user block with the correct IP allowed and the correct username and password).");
+                             "Verify that the connection details from Settings - RPC Servers match the ones in UnrealIRCd ".
+                             "and that UnrealIRCd is up and running");
                throw $e;
        }