Skip to content

Commit 6bd7e3b

Browse files
authored
Merge pull request #767 from linuxserver/swag-dashboard-auth
Add auth to the proxies table
2 parents b8b9ba6 + b5fb66d commit 6bd7e3b

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

root/dashboard/swag-proxies.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
import socket
88
import urllib3
99

10+
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+);.*"
11+
AUTHELIA_REGEX = r"\n\s+include \/config\/nginx\/authelia-location\.conf;.*"
12+
AUTHENTIK_REGEX = r"\n\s+include \/config\/nginx\/authentik-location\.conf;.*"
13+
BASIC_AUTH_REGEX = r"\n\s+auth_basic.*"
14+
LDAP_REGEX = r"\n\s+include \/config\/nginx\/ldap-location\.conf;.*"
15+
1016

1117
def find_apps():
1218
apps = {}
19+
auths = collections.defaultdict(dict)
1320
file_paths = glob.glob("/config/nginx/**/**", recursive=True)
1421
auto_confs = glob.glob("/etc/nginx/http.d/*", recursive=True)
1522
file_paths.extend(auto_confs)
@@ -18,17 +25,32 @@ def find_apps():
1825
continue
1926
file = open(file_path, "r")
2027
content = file.read()
21-
results = re.finditer(r"(\s+)set \$upstream_app (?P<name>\S+?);.*\n(\s+)set \$upstream_port (?P<port>\d+);.*\n(\s+)set \$upstream_proto (?P<proto>\w+);.*", content)
22-
for result in results:
23-
params = result.groupdict()
24-
app = f"{params['proto']}://{params['name']}:{params['port']}/"
25-
if app not in apps:
26-
apps[app] = set()
27-
if file_path.startswith("/config/nginx/site-confs/") or file_path.endswith(".conf"):
28-
file_path = "auto-proxy" if file_path.startswith("/etc/nginx/http.d/") else file_path
29-
apps[app].add(file_path)
30-
return apps
28+
match_proxy(apps, auths, content, file_path)
29+
return apps, auths
30+
31+
def match_proxy(apps, auths, content, file_path):
32+
results = re.finditer(PROXY_REGEX, content)
33+
for result in results:
34+
params = result.groupdict()
35+
app = f"{params['proto']}://{params['name']}:{params['port']}/"
36+
if app not in apps:
37+
apps[app] = set()
38+
if file_path.startswith("/config/nginx/site-confs/") or file_path.endswith(".conf"):
39+
file_path = "auto-proxy" if file_path.startswith("/etc/nginx/http.d/") else file_path
40+
apps[app].add(file_path)
41+
match_auth(auths, app, file_path, content)
3142

43+
def match_auth(auths, app, file_path, content):
44+
if re.findall(AUTHELIA_REGEX, content):
45+
auths[app][file_path] = "Authelia"
46+
elif re.findall(AUTHENTIK_REGEX, content):
47+
auths[app][file_path] = "Authentik"
48+
elif re.findall(BASIC_AUTH_REGEX, content):
49+
auths[app][file_path] = "Basic Auth"
50+
elif re.findall(LDAP_REGEX, content):
51+
auths[app][file_path] = "LDAP"
52+
else:
53+
auths[app][file_path] = "No Auth"
3254

3355
def is_available(url):
3456
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -45,7 +67,7 @@ def is_available(url):
4567

4668

4769
urllib3.disable_warnings()
48-
apps = find_apps()
70+
apps, auths = find_apps()
4971
discovered_apps = collections.defaultdict(dict)
5072
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
5173
futures = {executor.submit(is_available, app): app for app in apps.keys()}
@@ -55,5 +77,7 @@ def is_available(url):
5577
continue
5678
discovered_apps[app]["status"] = future.result()
5779
discovered_apps[app]["locations"] = list(apps[app])
80+
discovered_apps[app]["auths"] = list(f"{path} - {auth}" for path, auth in auths[app].items())
81+
discovered_apps[app]["auth_status"] = all(auth != "No Auth" for auth in auths[app].values())
5882

5983
print(json.dumps(discovered_apps, sort_keys=True))

root/dashboard/www/index.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ function GetProxies() {
6363
if (!empty($data->locations)) {
6464
$locations = $data->locations;
6565
$location = implode(",", $locations);
66-
$status .= '<i class="fas fa-check-circle"></i></td><td class="left-text"><span class="status-text">'.$location.'</span></td>';
66+
$status .= '<i class="fas fa-check-circle"></i></td><td class="align-td">';
67+
$auths = implode(PHP_EOL, $data->auths);
68+
if ($data->auth_status == 1) {
69+
$status .= '<i class="fas fa-check-circle" title="'.$auths.'"></i>';
70+
} else {
71+
$status .= '<i class="fas fa-exclamation-circle" title="'.$auths.'"></i>';
72+
}
73+
$status .= '</td><td class="left-text"><span class="status-text">'.$location.'</span></td>';
6774
} else {
6875
$error = 'Unable to locate the proxy config for '.$result.', it must use the following structure:'.PHP_EOL;
6976
$error .= '&#09;set $upstream_app <container/address>;'.PHP_EOL;
7077
$error .= '&#09;set $upstream_port <port>;'.PHP_EOL;
7178
$error .= '&#09;set $upstream_proto <protocol>;'.PHP_EOL;
7279
$error .= '&#09;proxy_pass $upstream_proto://$upstream_app:$upstream_port;'.PHP_EOL;
73-
$status .= '<i class="fas fa-exclamation-circle" title="'.$error.'"></i></td><td></td>';
80+
$status .= '<i class="fas fa-exclamation-circle" title="'.$error.'"></i></td><td></td><td></td>';
7481
}
7582
$status .= '</tr>';
7683
$index++;
@@ -85,6 +92,7 @@ function GetProxies() {
8592
<td><h3>Application</h3></td>
8693
<td><h3>Available</h3></td>
8794
<td><h3>Proxied</h3></td>
95+
<td><h3>Auth</h3></td>
8896
<td><h3>Location</h3></td>
8997
</tr>
9098
</thead>

0 commit comments

Comments
 (0)