diff --git a/root/dashboard/swag-f2b.py b/root/dashboard/swag-f2b.py index 92b6349..d59074e 100644 --- a/root/dashboard/swag-f2b.py +++ b/root/dashboard/swag-f2b.py @@ -4,7 +4,22 @@ import sqlite3 con = sqlite3.connect("/config/fail2ban/fail2ban.sqlite3") cur = con.cursor() -results = cur.execute("SELECT jails.name, COUNT(bans.ip) AS bans FROM jails LEFT JOIN bans ON jails.name=bans.jail GROUP BY jails.name").fetchall() +results = cur.execute(""" + SELECT jails.name, + COUNT(bans.ip) AS bans, + (SELECT DISTINCT bans.ip from bans where jails.name = bans.jail ORDER BY timeofban DESC) as last_ban, + (SELECT DISTINCT bans.data from bans where jails.name = bans.jail ORDER BY timeofban DESC) as data + FROM jails + LEFT JOIN bans ON jails.name=bans.jail + GROUP BY jails.name + """).fetchall() con.close() -output = json.dumps({k:v for (k,v) in results}, sort_keys=True) +formatted_results = [{ + "name": name, + "bans": bans, + "last_ban": last_ban, + "data": json.dumps(json.loads(data), indent=4, sort_keys=True) if data else None +} for (name, bans, last_ban, data) in results] + +output = json.dumps(formatted_results, sort_keys=True) print(output) diff --git a/root/dashboard/www/icon.svg b/root/dashboard/www/icon.svg new file mode 100644 index 0000000..1d60dcc --- /dev/null +++ b/root/dashboard/www/icon.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Asset 1 + + + + + + + + + + + + + + + + + diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index f9cdea7..19d2cb1 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -4,7 +4,7 @@ -

Welcome to your SWAG instance

-

A webserver and reverse proxy solution brought to you by linuxserver.io with php support and a built-in Certbot client.

-

We have an article on how to use swag here: docs.linuxserver.io

-

For help and support, please visit: linuxserver.io/support

HTML; } @@ -93,9 +89,11 @@ $jails = json_decode($output, true); $status = ""; $index = 0; - foreach($jails as $jail=>$bans){ + foreach($jails as $jail){ $tr_class = ($index % 2 == 0) ? 'shaded' : ''; - $status .= ''.$jail.''.$bans.''; + $status .= ''.$jail["name"].''; + $status .= ''.$jail["bans"].''; + $status .= ''.$jail["last_ban"].''; $index++; } return <<

Jail

Bans

+

Last

@@ -153,8 +152,34 @@ HTML; } + function GetLinks() { + return << +
+

Useful Links

+ + + + + + + + +
+
+
+
+ + HTML; + } + $geodb = file_exists('/config/geoip2db/GeoLite2-City.mmdb') ? '--geoip-database=/config/geoip2db/GeoLite2-City.mmdb' : ''; - $access = shell_exec("goaccess -a -o html --config-file=/dashboard/goaccess.conf ".$geodb); - $status = GetHeader() . GetProxies() . GetF2B() . GetAnnouncements() . '
'; - echo str_replace("
", $status, $access); + $goaccess = shell_exec("goaccess -a -o html --config-file=/dashboard/goaccess.conf ".$geodb); + $status = GetHeader() . GetProxies() . GetF2B() . GetAnnouncements() . GetLinks() . '
'; + $page = str_replace("
", $status, $goaccess); + $page = str_replace("Server Statistics", "<title>SWAG Dashboard", $page); + $page = str_replace("<h1 class='h-dashboard'>", "<h1>", $page); + $page = str_replace("<i class='fa fa-tachometer'></i>", "<img src='/icon.svg' width='32' height='32'> SWAG ", $page); + $page = preg_replace("/(<link rel='icon' )(.*?)(>)/", "<link rel='icon' type='image/svg+xml' href='/icon.svg'>", $page); + echo $page; ?>