Skip to content

Commit 0aa4d8b

Browse files
committed
Add homepage support
1 parent ef6b1c4 commit 0aa4d8b

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

root/dashboard/swag-proxies.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import re
77
import socket
8+
import sys
89
import urllib3
910

1011
PROXY_REGEX = r"\s+set \$upstream_app (?P<name>\S+?);.*\n(\s+)set \$upstream_port (?P<port>\d+);.*\n(\s+)set \$upstream_proto (?P<proto>\w+);.*"
@@ -14,14 +15,14 @@
1415
LDAP_REGEX = r"\n\s+include \/config\/nginx\/ldap-location\.conf;.*"
1516

1617

17-
def find_apps():
18+
def find_apps(fast=False):
1819
apps = {}
1920
auths = collections.defaultdict(dict)
2021
file_paths = glob.glob("/config/nginx/**/**", recursive=True)
2122
auto_confs = glob.glob("/etc/nginx/http.d/*", recursive=True)
2223
file_paths.extend(auto_confs)
2324
for file_path in file_paths:
24-
if not os.path.isfile(file_path):
25+
if not os.path.isfile(file_path) or (fast and file_path.endswith(".sample")):
2526
continue
2627
file = open(file_path, "r")
2728
content = file.read()
@@ -67,7 +68,8 @@ def is_available(url):
6768

6869

6970
urllib3.disable_warnings()
70-
apps, auths = find_apps()
71+
fast = (len(sys.argv) > 1)
72+
apps, auths = find_apps(fast)
7173
discovered_apps = collections.defaultdict(dict)
7274
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
7375
futures = {executor.submit(is_available, app): app for app in apps.keys()}

root/dashboard/www/index.php

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,49 @@ function GetCertificate() {
310310
HTML;
311311
}
312312

313-
$goaccess = GetGoaccess();
314-
$status = GetHeader() . GetProxies() . GetF2B() . GetTemplates() . GetAnnouncements() . GetLinks() . "<div class='wrap-general'>";
315-
$page = str_replace("<div class='wrap-general'>", $status, $goaccess);
316-
$ssl = GetCertificate() . "<div class='pull-right hide'>";
317-
$page = str_replace("<div class='pull-right'>", $ssl, $page);
318-
echo $page;
313+
function GetStats() {
314+
$output = shell_exec("if test -f /lsiopy/bin/python3; then /lsiopy/bin/python3 /dashboard/swag-f2b.py; else python3 /dashboard/swag-f2b.py; fi");
315+
$jails = json_decode($output, true);
316+
$banned = 0;
317+
foreach($jails as $jail){
318+
$banned = $banned + $jail["bans"];
319+
}
320+
321+
$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");
322+
$results = json_decode($output);
323+
$proxied = 0;
324+
$auth = 0;
325+
foreach($results as $result => $data){
326+
if (!empty($data->locations)){
327+
$proxied++;
328+
if ($data->auth_status == 1) {
329+
$auth++;
330+
}
331+
}
332+
}
333+
334+
$output = shell_exec("/etc/s6-overlay/s6-rc.d/init-version-checks/run");
335+
$outdated = 0;
336+
foreach(explode(PHP_EOL, $output) as $line) {
337+
if(str_contains($line, "/config/")) {
338+
$outdated++;
339+
}
340+
}
341+
342+
return array("proxied" => "$proxied", "auth" => "$auth", "outdated" => "$outdated", "banned" => "$banned");
343+
}
344+
345+
$stats = $_GET['stats'] == 'true' ? true : false;
346+
if($stats) {
347+
$page = GetStats();
348+
header("Content-Type: application/json");
349+
echo json_encode($page);
350+
} else {
351+
$goaccess = GetGoaccess();
352+
$status = GetHeader() . GetProxies() . GetF2B() . GetTemplates() . GetAnnouncements() . GetLinks() . "<div class='wrap-general'>";
353+
$page = str_replace("<div class='wrap-general'>", $status, $goaccess);
354+
$ssl = GetCertificate() . "<div class='pull-right hide'>";
355+
$page = str_replace("<div class='pull-right'>", $ssl, $page);
356+
echo $page;
357+
}
319358
?>

0 commit comments

Comments
 (0)