Skip to content

Commit cab89dc

Browse files
committed
Add auth to the proxies table
1 parent b8b9ba6 commit cab89dc

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

root/dashboard/swag-proxies.py

Lines changed: 39 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,36 @@ 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(content, file_path, apps)
29+
match_auth(apps, auths)
30+
return apps, auths
31+
32+
def match_proxy(content, file_path, apps):
33+
results = re.finditer(PROXY_REGEX, content)
34+
for result in results:
35+
params = result.groupdict()
36+
app = f"{params['proto']}://{params['name']}:{params['port']}/"
37+
if app not in apps:
38+
apps[app] = set()
39+
if file_path.startswith("/config/nginx/site-confs/") or file_path.endswith(".conf"):
40+
file_path = "auto-proxy" if file_path.startswith("/etc/nginx/http.d/") else file_path
41+
apps[app].add(file_path)
3142

43+
def match_auth(apps, auths):
44+
for app, file_paths in apps.items():
45+
for file_path in file_paths:
46+
file = open(file_path, "r")
47+
content = file.read()
48+
if re.findall(AUTHELIA_REGEX, content):
49+
auths[app][file_path] = "Authelia"
50+
elif re.findall(AUTHENTIK_REGEX, content):
51+
auths[app][file_path] = "Authentik"
52+
elif re.findall(BASIC_AUTH_REGEX, content):
53+
auths[app][file_path] = "Basic Auth"
54+
elif re.findall(LDAP_REGEX, content):
55+
auths[app][file_path] = "LDAP"
56+
else:
57+
auths[app][file_path] = "No Auth"
3258

3359
def is_available(url):
3460
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -45,7 +71,7 @@ def is_available(url):
4571

4672

4773
urllib3.disable_warnings()
48-
apps = find_apps()
74+
apps, auths = find_apps()
4975
discovered_apps = collections.defaultdict(dict)
5076
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
5177
futures = {executor.submit(is_available, app): app for app in apps.keys()}
@@ -55,5 +81,7 @@ def is_available(url):
5581
continue
5682
discovered_apps[app]["status"] = future.result()
5783
discovered_apps[app]["locations"] = list(apps[app])
84+
discovered_apps[app]["auths"] = list(f"{path} - {auth}" for path, auth in auths[app].items())
85+
discovered_apps[app]["auth_status"] = all(auth != "No Auth" for auth in auths[app].values())
5886

5987
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)