]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Add the start of "Network Health" tool
authorValerie Pond <redacted>
Wed, 5 Apr 2023 04:22:31 +0000 (05:22 +0100)
committerValerie Pond <redacted>
Wed, 5 Apr 2023 04:22:31 +0000 (05:22 +0100)
This tab will let you see if there are any mode mismatches or module version mismatches, and any other stuff we can think might be useful to add in.
Since we already have a hardcoded End Of Life, it sounds reasonable to add UnrealIRCd5 being EOL as a  "problem" listed on this page after July, for example.

Classes/class-checkup.php [new file with mode: 0644]
tools/checkup.php [new file with mode: 0644]

diff --git a/Classes/class-checkup.php b/Classes/class-checkup.php
new file mode 100644 (file)
index 0000000..37905ae
--- /dev/null
@@ -0,0 +1,132 @@
+<?php
+
+
+/**
+ * Does a complete checkup of the network.
+ */
+class CheckUp
+{
+    public $num_of_problems = [
+        "chanmodes" => 0,
+        "usermodes" => 0,
+        "modules" => 0,
+        "other" => 0,
+    ];
+    public $problems = [
+        "chanmodes" => [],
+        "usermodes" => [],
+        "modules" => [],
+        "other" => [],
+    ];
+
+    public $serverlist = [];
+
+    /**
+     * Construct0r
+     */
+    function __construct()
+    {
+        global $rpc;
+
+        $this->serverlist = $rpc->server()->getAll();
+        $this->chanmode_check();
+        $this->usermode_check();
+        //$this->module_check();
+        
+    }
+
+    /**
+     * Checks channel modes of servers against other servers
+     * @return void
+     */
+    function chanmode_check() : void
+    {
+        foreach($this->serverlist as $s) // cycle through each server
+        {
+            /* make a single string from the array of groups */
+            $ourchmodes = "";
+            foreach ($s->server->features->chanmodes as $set)
+                for ($i=0; isset($set[$i]); $i++)
+                    strcat($ourchmodes,$set[$i]);
+
+            /* take a look at every other server... yep, we do this for every server */
+            foreach ($this->serverlist as $serv)
+            {
+                /* except for ourselves lol */
+                if ($serv->id == $s->id)
+                    continue;
+                
+                /* hmm if it's not unreal, skip it too */
+                if (!strstr($serv->server->features->software,"UnrealIRCd"))
+                    continue;
+                
+                /* make a single string from the array of groups but for them this time */
+                $theirchmodes = "";
+                foreach ($serv->server->features->chanmodes as $set)
+                    for ($i=0; isset($set[$i]); $i++)
+                        strcat($theirchmodes,$set[$i]);
+
+                /* check ours against theirs */
+                for ($i=0; isset($ourchmodes[$i]) && $m = $ourchmodes[$i]; $i++)
+                {
+                    /* if we have a mode that they don't have */
+                    if (!strstr($theirchmodes, $m))
+                    {
+                        ++$this->num_of_problems['chanmodes'];
+                        $this->problems['chanmodes'][] = "Channel mode $m is present on $s->name but missing on $serv->name";
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Checks user modes of servers against other servers
+     * @return void
+     */
+    function usermode_check() : void
+    {
+         /* make a single string from the array of groups */
+         $ourumodes = $s->server->features->usermodes;
+
+        /* take a look at every other server... yep, we do this for every server */
+        foreach ($this->serverlist as $serv)
+        {
+            /* except for ourselves lol */
+            if ($serv->id == $s->id)
+                continue;
+            
+            /* hmm if it's not unreal, skip it too */
+            if (!strstr($serv->server->features->software,"UnrealIRCd"))
+                continue;
+            
+            $theirumodes = $serv->server->features->usermodes;
+
+            /* check ours against theirs */
+            for ($i=0; isset($ourumodes[$i]) && $m = $ourumodes[$i]; $i++)
+            {
+                /* if we have a mode that they don't have */
+                if (!strstr($theirumodes, $m))
+                {
+                    ++$this->num_of_problems['usermodes'];
+                    $this->problems['usermodes'][] = "User mode $m is present on $s->name but missing on $serv->name";
+                }
+            }
+        }
+    }
+
+    /**
+     * Checks modules of servers against other servers
+     * @return void
+     */
+    function module_check() : void
+    {
+        global $rpc;
+        $modlist = [];
+        $modarray = [];
+        foreach ($this->serverlist as $serv)
+            $modlist[$serv->name] = json_decode(json_encode($rpc->server()->module_list($serv->id)->list), true);
+
+        echo highlight_string(var_export($modlist,true));
+    }
+}
\ No newline at end of file
diff --git a/tools/checkup.php b/tools/checkup.php
new file mode 100644 (file)
index 0000000..d841daa
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+require_once "../common.php";
+require_once "../connection.php";
+require_once "../header.php";
+require_once "../Classes/class-checkup.php";
+
+
+$checkup = new CheckUp();
+
+
+?>
+<h4>Network Health Checkup</h4>
+
+<div class="container">
+
+<div class="row mt-3">
+    <div class="col-sm mb-3">
+        <div class="card text-center">
+            <div class="card-header bg-<?php echo ($checkup->num_of_problems['chanmodes']) ? "danger" : "success"; ?> text-white">
+                <div class="row">
+                    <div class="col">
+                        <i class="fa fa-hashtag fa-3x"></i>
+                    </div>
+                    <div class="col">
+                        <h3 class="display-4"><?php echo $checkup->num_of_problems['chanmodes']; ?></h3><div class="display-5">problems</div>
+                    </div>
+                </div>
+            </div>
+            <div class="card-body">
+                <div class="row">
+                    <div class="col">
+                        <h6>Channel Modes</h6>
+                    </div>
+                    <div class="col"> <a class="btn btn-primary">View</a></div>
+                </div>
+            </div>
+        </div>
+        
+
+    </div>
+    <div class="col-sm mb-3">
+        <div class="card text-center">
+            <div class="card-header bg-<?php echo ($checkup->num_of_problems['usermodes']) ? "danger" : "success"; ?> text-white">
+                <div class="row">
+                    <div class="col">
+                        <i class="fa fa-user fa-3x"></i>
+                    </div>
+                    <div class="col">
+                        <h3 class="display-4"><?php echo $checkup->num_of_problems['usermodes']; ?></h3><div class="display-5">problems</div>
+                    </div>
+                </div>
+            </div>
+            <div class="card-body">
+                <div class="row">
+                    <div class="col">
+                        <h6>User Modes</h6>
+                    </div>
+                    <div class="col"><a class="btn btn-primary">View</a></div>
+                </div>
+            </div>
+        </div>
+    </div>
+    <div class="col-sm mb-3">
+        <div class="card text-center">
+            <div class="card-header bg-warning">
+                <div class="row">
+                    <div class="col">
+                        <i class="fa fa-plug fa-3x"></i>
+                    </div>
+                    <div class="col">
+                        <h3 class="display-4"><?php // nothing ?></h3>
+                    </div>
+                </div>
+            </div>
+            <div class="card-body">
+                <div class="row">
+                    <div class="col">
+                        <h6>Modules</h6>
+                    </div>
+                    <div class="col"><a class="btn btn-primary">View</a></div>
+                </div>
+            </div>
+        </div>
+    </div>
+
+    <div class="col-sm mb-3">
+        <div class="card text-center">
+            <div class="card-header bg-secondary text-white">
+                <div class="row">
+                    <div class="col">
+                        <i class="fa fa-network-wired fa-3x"></i>
+                    </div>
+                    <div class="col">
+                        <h3 class="display-4"><?php // nothing ?></h3>
+                    </div>
+                </div>
+            </div>
+            <div class="card-body">
+                <div class="row">
+                    <div class="col">
+                        <h6>Servers</h6>
+                    </div>
+                    <div class="col"> <a class="btn btn-primary">View</a></div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
\ No newline at end of file