]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - index.php
Merge branch 'main' of https://github.com/unrealircd/unrealircd-webpanel
[irc/unrealircd/unrealircd-webpanel.git] / index.php
index 044775f4de88e67cc5fd9407b4aeedd828c36eba..dc7f37d3e20ddd63bf605591f583bf9c1a79c93f 100644 (file)
--- a/index.php
+++ b/index.php
-<!DOCTYPE html>
-<link href="css/unrealircd-admin.css" rel="stylesheet">
-<body>
-<div id="headerContainer">
-<h2>UnrealIRCd <small>Administration Panel</small></h2><br>
+<?php
+require_once "inc/common.php";
+if (!isset($config['unrealircd']))
+{
+       $redirect = get_config("base_url")."settings/rpc-servers.php";
+       header('Location: ' . $redirect);
+       die;
+}
+
+require_once "inc/header.php";
+
+?>
+<div class="row ml-0">
+       <h2>Network Overview</h2>
+       <div id="live_stats" data-toggle="tooltip" data-placement="top" title="The stats on this page are updated in real-time"
+            class="card text-center row font-weight-bold"
+            style="margin-left:5%;height:26px;width:60px;background-color:red;color:white;visibility:hidden">
+            <small style="margin-left:-40px;padding-top:3px;margin-right:-45px">⚪</small>LIVE
+       </div>
 </div>
-<script src="js/unrealircd-admin.js" defer></script>
-<div class="topnav">
-  <a data-tab-target="#overview" class="active" href="#overview">Overview</a>
-  <a data-tab-target="#Users" href="#Users">Users</a>
-  <a data-tab-target="#Channels" href="#Channels">Channels</a>
-  <a data-tab-target="#TKL" href="#TKL">Server Bans</a>
-  <a data-tab-target="#Spamfilter" href="#Spamfilter">Spamfilter</a>
-</div> 
 <?php
-/**
- * Provide a admin area view for the plugin
- *
- * This file is used to markup the admin-facing aspects of the plugin.
- *
- * @link          https://https://github.com/ValwareIRC
- * @since        1.0.0
- *
- * @package    Unrealircd
- * @subpackage Unrealircd/admin/partials
- */
-
-define('UPATH', true);
-include "Classes/class-rpc.php";
-
-if (!empty($_POST['tklch']))
-       foreach ($_POST as $key => $value)
+$array_of_stats = [];
+
+/* What if someone wants to add their own stats... */
+Hook::run(HOOKTYPE_PRE_OVERVIEW_CARD, $array_of_stats);
+
+/* This makes sure that a plugin which called the parameter
+ * by reference can add/update the stats for display here.
+*/
+$stats = (object) $array_of_stats;
+$userlist = [];
+Hook::run(HOOKTYPE_GET_USER_LIST, $userlist);
+$num_of_panel_admins = count($userlist);
+
+?>
+<style>
+       .card {
+               min-height: 80%;
+               border-radius: 16px;
+       }
+       .card-body i {
+               position: fixed;
+               top: 10px;
+               right: 10px;
+       }
+       .card:hover {
+               text-decoration: none;
+       }
+
+
+       .frosted-glass-success {
+               /* From https://css.glass */
+               background: rgba(63, 162, 36, 0.73);
+               box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
+               backdrop-filter: blur(9.8px);
+               -webkit-backdrop-filter: blur(9.8px);
+       }
+       .frosted-glass-info {
+               /* From https://css.glass */
+               background: rgba(57, 127, 207, 0.73);
+               box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
+               backdrop-filter: blur(9.8px);
+               -webkit-backdrop-filter: blur(9.8px);
+       }
+       .frosted-glass-danger {
+               /* From https://css.glass */
+               background: rgba(207, 57, 57, 0.73);
+               box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
+               backdrop-filter: blur(9.8px);
+               -webkit-backdrop-filter: blur(9.8px);
+       }
+       .frosted-glass-warning {
+               /* From https://css.glass */
+               background: rgba(207, 194, 57, 0.73);
+               box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
+               backdrop-filter: blur(9.8px);
+               -webkit-backdrop-filter: blur(9.8px);
+       }
+       .frosted-glass-secondary {
+               /* From https://css.glass */
+               background: rgba(75, 75, 75, 0.73);
+               box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
+               backdrop-filter: blur(9.8px);
+               -webkit-backdrop-filter: blur(9.8px);
+       }
+
+       </style>
+<div class="container card-container ml-1">
+
+<div class="row mt-3">
+       <div class="col-sm mb-3">
+                       <a class="card frosted-glass-success text-center" href="<?php echo get_config("base_url"); ?>users/">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <span id="userRecord" class="position-absolute badge rounded-pill badge-warning" hidden>
+                                                       <?php echo "Record: "; ?>
+                                               </span>
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-users fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="stats_user_total" class="display-4"></h5>
+                                                               <h5 class="display-5">Users Online</h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-info text-center" href="<?php echo get_config("base_url"); ?>channels/">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-hashtag fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="stats_channel_total" class="display-4"></h5>
+                                                               <h5 class="display-5">Channels</h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-warning text-center" href="<?php echo get_config("base_url"); ?>users/">
+                               <div class="card-body text-dark">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-shield-halved fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="stats_oper_total" class="display-4"></h5>
+                                                               <h5 class="display-5" style="margin-top: -3px">Operators</h5>
+                                                               <h5 style="font-size: 10px; margin-top:-12px">View in Users ></h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-secondary text-center" href="<?php echo get_config("base_url"); ?>servers/">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-network-wired fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="stats_server_total" class="display-4"></h5>
+                                                               <h5 class="display-5">Servers</h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+       </div>
+</div>
+<div class="container card-container ml-1">
+
+       <div class="row">
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-danger text-center" href="<?php echo get_config("base_url"); ?>server-bans/">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-ban fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="num_server_bans" class="display-4"></h5>
+                                                               <h5 class="display-5">Server Bans</h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-secondary text-center" href="<?php echo get_config("base_url"); ?>spamfilter.php/">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-filter fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="num_spamfilter_entries" class="display-4"></h5>
+                                                               <h5 class="display-5">Spamfilter</h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-info text-center" href="<?php echo get_config("base_url"); ?>server-bans/ban-exceptions.php">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-door-open fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="num_ban_exceptions" class="display-4"></h5>
+                                                               <h5 class="display-5">Server Ban Exceptions</h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+               <div class="col-sm mb-3">
+                       <a class="card frosted-glass-success text-center" href="<?php echo get_config("base_url"); ?>servers">
+                               <div class="card-body text-white">
+                                       <div class="row text-center">
+                                               <div class="col">
+                                                       <div class="col">
+                                                               <i aria-hidden="true" class="fa fa-database fa-2x"></i>
+                                                       </div>
+                                                       <div class="col">
+                                                               <h5 id="stats_uline_total" class="display-4"></h5>
+                                                               <h5 class="display-5" style="margin-top: -3px">Services Online</h5>
+                                                               <h5 style="font-size: 10px; margin-top:-12px">View in Servers ></h5>
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </a>
+               </div>
+       </div>
+</div>
+
+
+<script>
+       /* Last time stats were updated */
+       let stats_tick = 0;
+
+       function updateStats(e)
        {
-               foreach ($value as $tok)
-               {
-                       $tok = explode(",",$tok);
-                       rpc_tkl_del(base64_decode($tok[0]), base64_decode($tok[1]));
+               var data;
+               try {
+                       data = JSON.parse(e.data);
+               } catch(e) {
+                       return;
                }
+               stats_tick = Date.now()
+               console.log(data);
+               document.getElementById("userRecord").innerHTML = "Record: "+data.user.record;
+               document.getElementById("live_stats").style.visibility = '';
+               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;
        }
+       function checkStatsOutdated()
+       {
+               setTimeout(checkStatsOutdated, 2000);
+               if (Date.now() - stats_tick > 10000)
+                       document.getElementById("live_stats").style.visibility = 'hidden';
+       }
+       setTimeout(checkStatsOutdated, 2000);
 
-rpc_pop_lists(); // populate our static lists (users, channels, tkl, spamfilter)
-?>
+       function initStats()
+       {
+               if (!!window.EventSource) {
+                       var source = new EventSource('api/overview.php');
+                       source.addEventListener('message', updateStats, false);
+               }
+       }
+       initStats();
+       //setInterval(updateStats, 1000); // Update stats every second
+       // ^ commented out but may want to restart initStats() when connection is lost.
 
-<div class="tab-content\">
-<div id="overview" data-tab-content class="active">
-       <table class='unrealircd_overview'>
-       <th>Chat Overview</th><th></th>
-               <tr><td><b>Users</b></td><td><?php echo count(RPC_List::$user); ?></td></tr>
-               <tr><td><b>Opers</b></td><td><?php echo RPC_List::$opercount; ?></td></tr>
-               <tr><td><b>Services</b></td><td><?php echo RPC_List::$services_count; ?></td></tr>
-               <tr><td><b>Most popular channel</b></td><td><?php echo RPC_List::$most_populated_channel; ?> (<?php echo RPC_List::$channel_pop_count; ?> users)</td></tr>
-               <tr><td><b>Channels</b></td><td><?php echo count(RPC_List::$channel); ?></td></tr>
-               <tr><td><b>Server bans</b></td><td><?php echo count(RPC_List::$tkl); ?></td></tr>
-               <tr><td><b>Spamfilter entries</b></td><td><?php echo count(RPC_List::$spamfilter); ?></td></tr></th>
-       </table></div></div>
-
-       <div class="tab-content\">
-       <div id="Users" data-tab-content>
-       <p></p>
-       <table class='users_overview'>
-       <th>Nick</th>
-       <th>UID</th>
-       <th>Host / IP</th>
-       <th>Account</th>
-       <th>Usermodes</th>
-       <th>Oper</th>
-       <th>Secure</th>
-       <th>Connected to</th>
-       <th>Reputation <a href="https://www.unrealircd.org/docs/Reputation_score"></a>ℹ️</th>
        
-       <?php
-               foreach(RPC_List::$user as $user)
+       window.addEventListener('resize', function() {
+               var containers = document.querySelectorAll('.card-container');
+               var width = window.innerWidth;
+               if (width < 768)
                {
-                       echo "<tr>";
-                       echo "<td>".$user['name']."</td>";
-                       echo "<td>".$user['id']."</td>";
-                       echo "<td>".$user['hostname']." (".$user['ip'].")</td>";
-                       $account = (isset($user['user']['account'])) ? $user['user']['account'] : "";
-                       echo "<td>".$account."</td>";
-                       $modes = (isset($user['user']['modes'])) ? "+" . $user['user']['modes'] : "<none>";
-                       echo "<td>".$modes."</td>";
-                       $oper = (isset($user['user']['operlogin'])) ? $user['user']['operlogin']." (".$user['user']['operclass'].")" : "";
-                       echo "<td>".$oper."</td>";
-                       $secure = (isset($user['tls'])) ? "✅" : "❌";
-                       echo "<td>".$secure."</td>";
-                       echo "<td>".$user['user']['servername']."</td>";
-                       echo "<td>".$user['user']['reputation']."</td>";
-               }
-       ?></table></div></div>
-
-       <div class="tab-content\">
-       <div id="Channels" data-tab-content>
-       <p></p>
-       <table class='users_overview'>
-       <th>Name</th>
-       <th>Created</th>
-       <th>User count</th>
-       <th>Topic</th>
-       <th>Topic Set</th>
-       <th>Modes</th>
-       
-       <?php
-               foreach(RPC_List::$channel as $channel)
+                       containers.forEach((container) => {
+                               container.removeAttribute('style');
+
+                       });
+               } else 
                {
-                       echo "<tr>";
-                       echo "<td>".$channel['name']."</td>";
-                       echo "<td>".$channel['creation_time']."</td>";
-                       echo "<td>".$channel['num_users']."</td>";
-                       $topic = (isset($channel['topic'])) ? $channel['topic'] : "";
-                       echo "<td>".$topic."</td>";
-                       $setby = (isset($channel['topic'])) ? "By ".$channel['topic_set_by'] .", at ".$channel['topic_set_at'] : "";
-                       echo "<td>".$setby."</td>";
-                       $modes = (isset($channel['modes'])) ? "+" . $channel['modes'] : "<none>";
-                       echo "<td>".$modes."</td>";
+                       containers.forEach((container) => {
+                               container.style.marginLeft = "40px";
+                               container.style.marginTop = "30px";
+
+                       });
                }
-       ?></table></div></div>
+       });
+</script>
 
+<div class="container card-container card-container ml-1">
 
-       <div class="tab-content\">
-       <div id="TKL" data-tab-content>
-       
-       <table class='users_overview'>
-       <form action="" method="post">
-       <th><input type="checkbox" label='selectall' onClick="toggle(this)" />Select all</th>
-       <th>Mask</th>
-       <th>Type</th>
-       <th>Set By</th>
-       <th>Set On</th>
-       <th>Expires</th>
-       <th>Duration</th>
-       <th>Reason</th>
-       
-       <?php
-               foreach(RPC_List::$tkl as $tkl)
-               {
-                       echo "<tr>";
-                       echo "<td><input type=\"checkbox\" value='" . base64_encode($tkl['name']).",".base64_encode($tkl['type']) . "' name=\"tklch[]\"></td>";
-                       echo "<td>".$tkl['name']."</td>";
-                       echo "<td>".$tkl['type_string']."</td>";
-                       echo "<td>".$tkl['set_by']."</td>";
-                       echo "<td>".$tkl['set_at_string']."</td>";
-                       echo "<td>".$tkl['expire_at_string']."</td>";
-                       echo "<td>".$tkl['duration_string']."</td>";
-                       echo "<td>".$tkl['reason']."</td>";
-               }
-       ?></table><p><input class="cute_button" type="submit" value="Delete selected"></p></form></div></div>
-       
+                       <div class="row">
+                               <div class="col-sm mb-3">
+                                       <a class="card frosted-glass-success text-center" href="<?php echo get_config("base_url"); ?>settings">
+                                               <div class="card-body text-white">
+                                                       <div class="row text-center">
+                                                               <div class="col">
+                                                                       <div class="col">
+                                                                               <i aria-hidden="true" class="fa fa-lock-open fa-2x"></i>
+                                                                       </div>
+                                                                       <div class="col">
+                                                                               <h5 class="display-4"><?php echo $num_of_panel_admins; ?></h5>
+                                                                               <h5 class="display-5">Panel Accounts</h5>
+                                                                       </div>
+                                                               </div>
+                                                       </div>
+                                               </div>
+                                       </a>
+                               </div>
+                               <div class="col-sm mb-3">
+                                       <a class="card frosted-glass-info text-center" href="<?php echo get_config("base_url"); ?>settings/plugins.php">
+                                               <div class="card-body text-light">
+                                                       <div class="row text-center">
+                                                               <div class="col">
+                                                                       <div class="col">
+                                                                               <i aria-hidden="true" class="fa fa-plug fa-2x"></i>
+                                                                       </div>
+                                                                       <div class="col">
+                                                                               <h5 class="display-4"><?php echo count(Plugins::$list); ?></h5>
+                                                                               <h5 class="display-5">Plugins</h5>
+                                                                       </div>
+                                                               </div>
+                                                       </div>
+                                               </div>
+                                       </a>
+                               </div>
+                       </div>
+               </div>  
+<?php
 
-       <div class="tab-content\">
-       <div id="Spamfilter" data-tab-content>
-       <p></p>
-       <table class='users_overview'>
-       <th>Mask</th>
-       <th>Type</th>
-       <th>Set By</th>
-       <th>Set On</th>
-       <th>Expires</th>
-       <th>Duration</th>
-       <th>Match Type</th>
-       <th>Action</th>
-       <th>Action Duration</th>
-       <th>Target</th>
-       <th>Reason</th>
-       
-       <?php
-               foreach(RPC_List::$spamfilter as $sf)
-               {
-                       echo "<tr>";
-                       echo "<td>".$sf['name']."</td>";
-                       echo "<td>".$sf['type_string']."</td>";
-                       echo "<td>".$sf['set_by']."</td>";
-                       echo "<td>".$sf['set_at_string']."</td>";
-                       echo "<td>".$sf['expire_at_string']."</td>";
-                       echo "<td>".$sf['duration_string']."</td>";
-                       echo "<td>".$sf['match_type']."</td>";
-                       echo "<td>".$sf['ban_action']."</td>";
-                       echo "<td>".$sf['ban_duration_string']."</td>";
-                       for ($i = 0, $targs = ""; ($c = $sf['spamfilter_targets'][$i]); $i++)
-                       {
-                               if ($c == "c")
-                                       $targs .= "Channel, ";
-                               else if ($c == "p")
-                                       $targs .= "Private,";
-                               else if ($c == "n")
-                                       $targs .= "Notice, ";
-                               else if ($c == "N")
-                                       $targs .= "Channel notice, ";
-                               else if ($c == "P")
-                                       $targs .= "Part message, ";
-                               else if ($c == "q")
-                                       $targs .= "Quit message, ";
-                               else if ($c == "d")
-                                       $targs .= "DCC filename, ";
-                               else if ($c == "a")
-                                       $targs .= "Away message, ";
-                               else if ($c == "t")
-                                       $targs .= "Channel topic, ";
-                               else if ($c == "T")
-                                       $targs .= "MessageTag, ";
-                               else if ($c == "u")
-                                       $targs .= "Usermask, ";
-
-                               $targs = rtrim($targs,", ");
-                       }
-                       echo "<td>".$targs."</td>";
-                       echo "<td>".$sf['reason']."</td>";
-                       
-               }
-       ?></table></div></div>
-       
-</body>
+Hook::run(HOOKTYPE_OVERVIEW_CARD, $stats);
 
-<div class="footer"><p>Copyright 2022-2023 © <a href="https://unrealircd.org/">UnrealIRCd</a></p></div>
\ No newline at end of file
+require_once "inc/footer.php";