Skip to content

Commit 0f48ff5

Browse files
authored
Merge pull request #902 from linuxserver/swag-homepage-support
Add homepage support
2 parents ef6b1c4 + 284c37d commit 0f48ff5

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ This mod adds a dashboard to SWAG powered by [Goaccess](https://goaccess.io/).
66

77
# Enable
88

9-
In the container's docker arguments, set an environment variable DOCKER_MODS=linuxserver/mods:swag-dashboard
9+
In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-dashboard`.
1010

11-
If adding multiple mods, enter them in an array separated by |, such as DOCKER_MODS=linuxserver/mods:swag-dashboard|linuxserver/mods:swag-mod2
11+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:swag-dashboard|linuxserver/mods:swag-mod2`.
1212

1313
## Internal access using `<server-ip>:81`
1414

15-
Add a mapping of `81:81` to swag's docker run command or compose
15+
Add a mapping of `81:81` to swag's docker run command or compose.
1616

1717
## Internal access using `dashboard.domain.com`
1818

19-
Requires an internal DNS, add a rewrite of `dashboard.domain.com` to your server's IP address
19+
Requires an internal DNS, add a rewrite of `dashboard.domain.com` to your server's IP address.
2020

2121
## External access using `dashboard.domain.com`
2222

2323
Remove the allow/deny lines in `/config/nginx/proxy-confs/dashboard.subdomain.com`, and instead secure it some other way (like Authelia for example).
2424

25-
## Notes
25+
## Usage
26+
2627
- The application discovery scans for a list of known services, as well as enabled custom proxy confs that contain the following format:
2728
```yaml
2829
set $upstream_app <container/address>;
@@ -31,9 +32,15 @@ Remove the allow/deny lines in `/config/nginx/proxy-confs/dashboard.subdomain.co
3132
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
3233
```
3334
- Either [Swag Maxmind mod](https://github.com/linuxserver/docker-mods/tree/swag-maxmind) or [Swag DBIP mod](https://github.com/linuxserver/docker-mods/tree/swag-dbip) are required to enable the geo location graph.
34-
- The host's fail2ban can be supported by mounting it to swag `- /path/to/host/fail2ban.sqlite3:/dashboard/fail2ban.sqlite3:ro`
35-
- The host's logs can be supported by mounting it to swag `- /path/to/host/logs:/dashboard/logs:ro`
3635
- To clear the dashboard stats, you must remove the logs (/config/log/nginx) and **recreate** the container.
3736

37+
## Dashboard Support
38+
39+
There's a stats endpoint for integration with dashboards under `https://dashboard.domain.com/?stats=true`.
40+
41+
## External Support
42+
- External fail2ban (not required when using swag's fail2ban) can be supported by mounting it to swag `- /path/to/host/fail2ban.sqlite3:/dashboard/fail2ban.sqlite3:ro`.
43+
- External logs (not required when using swag's logs) can be supported by mounting it to swag `- /path/to/host/logs:/dashboard/logs:ro`.
44+
3845
# Example
3946
![Example](.assets/example.png)

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)