From 0aa4d8bf03740694b261bc7a6af981d7734c974b Mon Sep 17 00:00:00 2001 From: quietsy Date: Fri, 24 May 2024 21:03:10 +0300 Subject: [PATCH] Add homepage support --- root/dashboard/swag-proxies.py | 8 ++++-- root/dashboard/www/index.php | 51 ++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/root/dashboard/swag-proxies.py b/root/dashboard/swag-proxies.py index 0e6182d..1b2abc8 100644 --- a/root/dashboard/swag-proxies.py +++ b/root/dashboard/swag-proxies.py @@ -5,6 +5,7 @@ import json import os import re import socket +import sys import urllib3 PROXY_REGEX = r"\s+set \$upstream_app (?P\S+?);.*\n(\s+)set \$upstream_port (?P\d+);.*\n(\s+)set \$upstream_proto (?P\w+);.*" @@ -14,14 +15,14 @@ BASIC_AUTH_REGEX = r"\n\s+auth_basic.*" LDAP_REGEX = r"\n\s+include \/config\/nginx\/ldap-location\.conf;.*" -def find_apps(): +def find_apps(fast=False): apps = {} auths = collections.defaultdict(dict) file_paths = glob.glob("/config/nginx/**/**", recursive=True) auto_confs = glob.glob("/etc/nginx/http.d/*", recursive=True) file_paths.extend(auto_confs) for file_path in file_paths: - if not os.path.isfile(file_path): + if not os.path.isfile(file_path) or (fast and file_path.endswith(".sample")): continue file = open(file_path, "r") content = file.read() @@ -67,7 +68,8 @@ def is_available(url): urllib3.disable_warnings() -apps, auths = find_apps() +fast = (len(sys.argv) > 1) +apps, auths = find_apps(fast) discovered_apps = collections.defaultdict(dict) with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: futures = {executor.submit(is_available, app): app for app in apps.keys()} diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index 810f7ad..0a75049 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -310,10 +310,49 @@ HTML; } - $goaccess = GetGoaccess(); - $status = GetHeader() . GetProxies() . GetF2B() . GetTemplates() . GetAnnouncements() . GetLinks() . "
"; - $page = str_replace("
", $status, $goaccess); - $ssl = GetCertificate() . "
"; - $page = str_replace("
", $ssl, $page); - echo $page; + function GetStats() { + $output = shell_exec("if test -f /lsiopy/bin/python3; then /lsiopy/bin/python3 /dashboard/swag-f2b.py; else python3 /dashboard/swag-f2b.py; fi"); + $jails = json_decode($output, true); + $banned = 0; + foreach($jails as $jail){ + $banned = $banned + $jail["bans"]; + } + + $output = shell_exec("if test -f /lsiopy/bin/python3; then /lsiopy/bin/python3 /dashboard/swag-proxies.py fast; else python3 /dashboard/swag-proxies.py fast; fi"); + $results = json_decode($output); + $proxied = 0; + $auth = 0; + foreach($results as $result => $data){ + if (!empty($data->locations)){ + $proxied++; + if ($data->auth_status == 1) { + $auth++; + } + } + } + + $output = shell_exec("/etc/s6-overlay/s6-rc.d/init-version-checks/run"); + $outdated = 0; + foreach(explode(PHP_EOL, $output) as $line) { + if(str_contains($line, "/config/")) { + $outdated++; + } + } + + return array("proxied" => "$proxied", "auth" => "$auth", "outdated" => "$outdated", "banned" => "$banned"); + } + + $stats = $_GET['stats'] == 'true' ? true : false; + if($stats) { + $page = GetStats(); + header("Content-Type: application/json"); + echo json_encode($page); + } else { + $goaccess = GetGoaccess(); + $status = GetHeader() . GetProxies() . GetF2B() . GetTemplates() . GetAnnouncements() . GetLinks() . "
"; + $page = str_replace("
", $status, $goaccess); + $ssl = GetCertificate() . "
"; + $page = str_replace("
", $ssl, $page); + echo $page; + } ?>