Skip to content

Commit 09d40ea

Browse files
author
quietsy
authored
Merge pull request #351 from quietsy/swag-dashboard
Added support for more configurations
2 parents 0d6152c + b6cbd9f commit 09d40ea

4 files changed

Lines changed: 87 additions & 25 deletions

File tree

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ In the container's docker arguments, set an environment variable DOCKER_MODS=lin
1010

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

13-
# Usage
13+
## Internal access using `<server-ip>:81`
1414

15-
Navigate to `dashboard.domain.com` from your LAN to view the dashboard.
15+
Add a mapping of `81:81` to swag's docker run command or compose
1616

17-
You can remove the allow/deny in `/config/nginx/proxy-confs/dashboard.subdomain.com` to expose it (on a VPS for example), and instead protect it some other way (like Authelia for example).
17+
## Internal access using `dashboard.domain.com`
18+
19+
Requires an internal DNS, add a rewrite of `dashboard.domain.com` to your server's IP address
20+
21+
## External access using `dashboard.domain.com`
22+
23+
Remove the allow/deny lines in `/config/nginx/proxy-confs/dashboard.subdomain.com`, and instead secure it some other way (like Authelia for example).
1824

1925
## Notes
2026
- The application discovery scans the proxy configs and looks for the following structure in accordance with the samples:
@@ -25,6 +31,8 @@ You can remove the allow/deny in `/config/nginx/proxy-confs/dashboard.subdomain.
2531
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
2632
```
2733
- 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`
2836

2937
# Example
3038
![Example](.assets/example.png)

root/dashboard/dashboard.subdomain.conf.sample

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
1-
## Version 2022/01/14
1+
## Version 2022/03/19
22
# Make sure that your dns has a cname set for dashboard
33

4+
server {
5+
listen 81;
6+
7+
server_name _;
8+
9+
root /dashboard/www;
10+
index index.php;
11+
12+
client_max_body_size 0;
13+
14+
# enable for ldap auth, fill in ldap details in ldap.conf
15+
#include /config/nginx/ldap.conf;
16+
17+
# enable for Authelia
18+
#include /config/nginx/authelia-server.conf;
19+
20+
location / {
21+
# enable the next two lines for http auth
22+
#auth_basic "Restricted";
23+
#auth_basic_user_file /config/nginx/.htpasswd;
24+
25+
# enable the next two lines for ldap auth
26+
#auth_request /auth;
27+
#error_page 401 =200 /ldaplogin;
28+
29+
# enable for Authelia
30+
#include /config/nginx/authelia-location.conf;
31+
32+
allow 10.0.0.0/8;
33+
allow 172.16.0.0/12;
34+
allow 192.168.0.0/16;
35+
deny all;
36+
37+
try_files $uri $uri/ /index.php?$args =404;
38+
}
39+
location ~ \.php$ {
40+
allow 10.0.0.0/8;
41+
allow 172.16.0.0/12;
42+
allow 192.168.0.0/16;
43+
deny all;
44+
45+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
46+
fastcgi_pass 127.0.0.1:9000;
47+
fastcgi_index index.php;
48+
include /etc/nginx/fastcgi_params;
49+
}
50+
}
51+
452
server {
553
listen 443 ssl;
654
listen [::]:443 ssl;

root/dashboard/swag-f2b.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
import json
2+
import os
23
import sqlite3
34

5+
def _get_f2b_data(db_path):
6+
if not os.path.isfile(db_path):
7+
return []
8+
9+
con = sqlite3.connect(db_path)
10+
cur = con.cursor()
11+
results = cur.execute("""
12+
SELECT jails.name,
13+
COUNT(bans.ip) AS bans,
14+
(SELECT DISTINCT bans.ip from bans where jails.name = bans.jail ORDER BY timeofban DESC) as last_ban,
15+
(SELECT DISTINCT bans.data from bans where jails.name = bans.jail ORDER BY timeofban DESC) as data
16+
FROM jails
17+
LEFT JOIN bans ON jails.name=bans.jail
18+
GROUP BY jails.name
19+
""").fetchall()
20+
con.close()
21+
return [{
22+
"name": name,
23+
"bans": bans,
24+
"last_ban": last_ban,
25+
"data": json.dumps(json.loads(data), indent=4, sort_keys=True) if data else None
26+
} for (name, bans, last_ban, data) in results]
427

5-
con = sqlite3.connect("/config/fail2ban/fail2ban.sqlite3")
6-
cur = con.cursor()
7-
results = cur.execute("""
8-
SELECT jails.name,
9-
COUNT(bans.ip) AS bans,
10-
(SELECT DISTINCT bans.ip from bans where jails.name = bans.jail ORDER BY timeofban DESC) as last_ban,
11-
(SELECT DISTINCT bans.data from bans where jails.name = bans.jail ORDER BY timeofban DESC) as data
12-
FROM jails
13-
LEFT JOIN bans ON jails.name=bans.jail
14-
GROUP BY jails.name
15-
""").fetchall()
16-
con.close()
17-
formatted_results = [{
18-
"name": name,
19-
"bans": bans,
20-
"last_ban": last_ban,
21-
"data": json.dumps(json.loads(data), indent=4, sort_keys=True) if data else None
22-
} for (name, bans, last_ban, data) in results]
28+
swag_f2b = _get_f2b_data("/config/fail2ban/fail2ban.sqlite3")
29+
host_f2b = _get_f2b_data("/dashboard/fail2ban/fail2ban.sqlite3")
2330

24-
output = json.dumps(formatted_results, sort_keys=True)
31+
output = json.dumps(swag_f2b + host_f2b, sort_keys=True)
2532
print(output)

root/dashboard/swag-proxies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import collections
2-
import contextlib
32
import concurrent.futures
43
import glob
54
import json
@@ -11,7 +10,7 @@
1110

1211
def find_apps():
1312
apps = {}
14-
file_paths = glob.glob("/config/nginx/**/*", recursive=True)
13+
file_paths = glob.glob("/config/nginx/**/**", recursive=True)
1514
auto_confs = glob.glob("/etc/nginx/http.d/*", recursive=True)
1615
file_paths.extend(auto_confs)
1716
for file_path in file_paths:

0 commit comments

Comments
 (0)