]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - index.php
Make the Services overview card live too
[irc/unrealircd/unrealircd-webpanel.git] / index.php
index 1e966ecc94e095cac8b5a36147042fd984cd0a28..6384929e931f85540ae84a0dab19ce7e686bc9b3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,5 +1,6 @@
 <?php
 require_once "common.php";
+require_once "connection.php";
 require_once "header.php";
 
 $stats = $rpc->query("stats.get", []);
@@ -18,6 +19,9 @@ Hook::run(HOOKTYPE_PRE_OVERVIEW_CARD, $array_of_stats);
 */
 $stats = (object) $array_of_stats;
 
+$userlist = [];
+Hook::run(HOOKTYPE_GET_USER_LIST, $userlist);
+$num_of_panel_admins = count($userlist);
 
 ?>
 <div class="container">
@@ -33,7 +37,7 @@ $stats = (object) $array_of_stats;
                                                </span>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->user->total; ?></h3>
+                                                       <h3 id="stats_user_total" class="display-4"><?php echo $stats->user->total; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -57,7 +61,7 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-hashtag fa-3x"></i>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->channel->total; ?></h3>
+                                                       <h3 id="stats_channel_total" class="display-4"><?php echo $stats->channel->total; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -79,7 +83,7 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-shield-halved fa-3x"></i>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->user->oper; ?></h3>
+                                                       <h3 id="stats_oper_total" class="display-4"><?php echo $stats->user->oper; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -102,7 +106,7 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-network-wired fa-3x"></i>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->server->total; ?></h3>
+                                                       <h3 id="stats_server_total" class="display-4"><?php echo $stats->server->total; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -129,7 +133,7 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-ban fa-3x"></i>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->server_ban->server_ban; ?></h3>
+                                                       <h3 id="num_server_bans" class="display-4"><?php echo $stats->server_ban->server_ban; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -151,7 +155,7 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-filter fa-3x"></i>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->server_ban->spamfilter; ?></h3>
+                                                       <h3 id="num_spamfilter_entries" class="display-4"><?php echo $stats->server_ban->spamfilter; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -173,7 +177,7 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-door-open fa-3x"></i>
                                                </div>
                                                <div class="col">
-                                                       <h3 class="display-4"><?php echo $stats->server_ban->server_ban_exception; ?></h3>
+                                                       <h3 id="num_ban_exceptions" class="display-4"><?php echo $stats->server_ban->server_ban_exception; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -191,12 +195,7 @@ $stats = (object) $array_of_stats;
                <?php
                if ($stats->server->ulined) {
                        $bg = "bg-success";
-
-                       /* honestly can't think of a case where there would actually be only one uline... but... well here we are, worrying over the small stuff =] */
-                       $user_noun = ($stats->user->ulined == 1) ? "user" : "users"; // use "users" even if 0, sounds better.
-                       $is_are = ($stats->user->ulined == 1) ? "is" : "are";
-                       $server_noun = ($stats->server->ulined == 1) ? "server" : "servers";
-                       $tooltip = "There $is_are " . $stats->user->ulined . " U-Lined $user_noun over " . $stats->server->ulined . " U-Lined $server_noun";
+                       $tooltip = "Users / Servers";
                }
                else
                        $bg = "bg-warning";
@@ -209,7 +208,8 @@ $stats = (object) $array_of_stats;
                                                        <i class="fa fa-database fa-3x"> </i>
                                                </div>
                                                <div class="col">
-                                               <span data-toggle="tooltip" title="<?php echo $tooltip; ?>" style="border-bottom: 1px dotted #000000"><h3 class="display-4"><?php echo $stats->user->ulined; ?>/<?php echo $stats->server->ulined; ?></h3>
+                                               <span data-toggle="tooltip" title="<?php echo $tooltip; ?>" style="border-bottom: 1px dotted #000000">
+                                               <h3 id="stats_uline_total" class="display-4"><?php echo $stats->user->ulined; ?>/<?php echo $stats->server->ulined; ?></h3>
                                                </div>
                                        </div>
                                </div>
@@ -226,13 +226,32 @@ $stats = (object) $array_of_stats;
                </div>
        </div>
 </div>
-<?php
-$userlist = [];
-Hook::run(HOOKTYPE_GET_USER_LIST, $userlist);
-$num_of_panel_admins = count($userlist);
-?>
 
-<div class="container mt-5">
+
+<script>
+    function updateStats() {
+        var xhttp = new XMLHttpRequest();
+        xhttp.onreadystatechange = function() {
+            if (this.readyState == 4 && this.status == 200) {
+                var data = JSON.parse(this.responseText);
+                document.getElementById("stats_user_total").innerHTML = data.user.total;
+                document.getElementById("stats_channel_total").innerHTML = data.channel.total;
+                               document.getElementById("stats_oper_total").innerHTML = data.user.oper;
+                               document.getElementById("stats_server_total").innerHTML = data.server.total;
+                               document.getElementById("num_server_bans").innerHTML = data.server_ban.server_ban;
+                               document.getElementById("num_spamfilter_entries").innerHTML = data.server_ban.spamfilter;
+                               document.getElementById("num_ban_exceptions").innerHTML = data.server_ban.server_ban_exception;
+                               document.getElementById("stats_uline_total").innerHTML = data.user.ulined + "/" + data.server.ulined;
+            }
+        };
+        xhttp.open("GET", "api/overview.php", true);
+        xhttp.send();
+    }
+    updateStats();
+    setInterval(updateStats, 1000); // Update stats every second
+</script>
+
+<div class="container mt-3">
 
                        <div class="row">
                                <div class="col-sm-3">
@@ -250,7 +269,7 @@ $num_of_panel_admins = count($userlist);
                                                <div class="card-body">
                                                        <div class="row">
                                                                <div class="col">
-                                                                       <h6>Panel Users</h6>
+                                                                       <h6>Panel Access</h6>
                                                                </div>
                                                                <div class="col"> <a class="btn btn-primary" href="<?php echo BASE_URL; ?>settings">View</a></div>
                                                        </div>