From: Valerie Pond Date: Fri, 30 Dec 2022 20:58:39 +0000 (+0000) Subject: Initial commit X-Git-Tag: 0.9~612 X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/commitdiff_plain/709b97f3b90d912cb85f532180d6715f93b2ffae?hp=f334f536336dc44cf90e23ee6eee22c38ff08018 Initial commit --- diff --git a/Classes/class-rpc.php b/Classes/class-rpc.php new file mode 100644 index 0000000..76bdb65 --- /dev/null +++ b/Classes/class-rpc.php @@ -0,0 +1,218 @@ +content['sslverify'] = $sslverify; + $this->body['id'] = $this->generate_id(); + $this->body['jsonrpc'] = "2.0"; + $this->body['method'] = NULL; // MUST be set later + $this->body['params'] = []; // CAN be set later + } + function add_body(array $b) : void + { + array_merge($this->body, $b); + } + + private function generate_id() + { + $time = microtime(true); + $str = (string)$time; + $last = $str[strlen($str) - 1]; + $last = (int)$last; + $id = $time * $time * $last; + $id = md5(base64_encode($id)); + return $id; + } + + /** + * This function sets the method of the RPC call you're making. + * For a list of available methods, see: + * https://www.unrealircd.org/docs/JSON-RPC#JSON-RPC_Methods + */ + function set_method(String $method) : void + { + $this->body['method'] = $method; + } + + function set_params(array $params) : void + { + array_merge($this->body['params'], $params); + } + + function execute() + { + $this->content['body'] = json_encode($this->body); + if (!$this->content['body']) + return; + $url = "https://".UNREALIRCD_HOST.":".UNREALIRCD_PORT."/api"; + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + + $headers = array( + "Accept: application/json", + "Content-Type: application/json", + "Authorization: Basic ". base64_encode(UNREALIRCD_RPC_USER.":".UNREALIRCD_RPC_PASSWORD), + ); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + curl_setopt($curl, CURLOPT_POSTFIELDS, $this->content['body']); + + //for debug only! + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + + $apiResponse = curl_exec($curl); + curl_close($curl); + + $this->result = $apiResponse; + } + + function fetch_assoc() + { + return json_decode($this->result, true); + } + + static function die(array $err) + { + die("There was a problem processing the request: ".$err['message']." (".$err['code'].")
Please contact the plugin author.
". + "If you are a developer, see: https://www.unrealircd.org/docs/JSON-RPC#Error"); + } +} + +class RPC_List +{ + static $user = []; + static $channel = []; + static $tkl = []; + static $spamfilter = []; + + static $opercount = 0; + static $services_count = 0; + static $most_populated_channel = NULL; + static $channel_pop_count = 0; +} + +function rpc_pop_lists() +{ + $rpc = new RPC(); + + /* Get the user list */ + $rpc->set_method("user.list"); + $rpc->execute(); + + foreach($rpc->fetch_assoc() as $key => $value) + { + if ($key == "error") + { + RPC::die($value); + return; + } + if ($key == "result") + foreach($value['list'] as $r) + { + RPC_List::$user[] = $r; + if (strpos($r['user']['modes'],"o") !== false && strpos($r['user']['modes'],"S") == false) + RPC_List::$opercount++; + elseif (strpos($r['user']['modes'],"S") !== false) + RPC_List::$services_count++; + } + } + + /* Get the channels list */ + $rpc->set_method("channel.list"); + $rpc->execute(); + + foreach($rpc->fetch_assoc() as $key => $value) + { + if ($key == "error") + { + RPC::die($value); + return; + } + if ($key == "result") + foreach($value['list'] as $r) + { + RPC_List::$channel[] = $r; + if ($r['num_users'] > RPC_List::$channel_pop_count) + { + RPC_List::$channel_pop_count = $r['num_users']; + RPC_List::$most_populated_channel = $r['name']; + } + } + } + + /* Get the tkl list */ + $rpc->set_method("server_ban.list"); + $rpc->execute(); + + foreach($rpc->fetch_assoc() as $key => $value) + { + if ($key == "error") + { + RPC::die($value); + return; + } + if ($key == "result") + foreach($value['list'] as $r) + RPC_List::$tkl[] = $r; + } + + + /* Get the tkl list */ + $rpc->set_method("spamfilter.list"); + $rpc->execute(); + + foreach($rpc->fetch_assoc() as $key => $value) + { + if ($key == "error") + { + RPC::die($value); + return; + } + if ($key == "result") + foreach($value['list'] as $r) + RPC_List::$spamfilter[] = $r; + } + +} \ No newline at end of file diff --git a/Classes/index.php b/Classes/index.php new file mode 100644 index 0000000..5d01148 --- /dev/null +++ b/Classes/index.php @@ -0,0 +1,3 @@ + +
+ Overview + Users + Channels + Server Bans + Spamfilter +
+ +

UnrealIRCd

+
+
+

IRC Overview Panel

+ + + + + + + + +
Users".count(RPC_List::$user)."
Opers".RPC_List::$opercount."
Services".RPC_List::$services_count."
Most popular channel".RPC_List::$most_populated_channel." (".RPC_List::$channel_pop_count." users)
Channels".count(RPC_List::$channel)."
Server bans".count(RPC_List::$tkl)."
Spamfilter entries".count(RPC_List::$spamfilter)."
"; +?> diff --git a/js/index.php b/js/index.php new file mode 100644 index 0000000..5d01148 --- /dev/null +++ b/js/index.php @@ -0,0 +1,3 @@ + { + tab.addEventListener('click', () => { + const target = document.querySelector(tab.dataset.tabTarget) + tabContents.forEach(tabContent => { + tabContent.classList.remove('active') + }) + tabs.forEach(tab => { + tab.classList.remove('active') + }) + tab.classList.add('active'); + target.classList.add('active'); + }) +}) \ No newline at end of file