Add the swag dashboard mod

This commit is contained in:
quietsy
2022-01-12 20:32:39 +02:00
parent d1dc6e5858
commit f6db7a5673
11 changed files with 200 additions and 70 deletions
@@ -0,0 +1,45 @@
## Version 2022/01/12
# Make sure that your dns has a cname set for dashboard
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name dashboard.*;
root /dashboard/www;
index index.php;
include /config/nginx/ssl.conf;
client_max_body_size 0;
# enable for ldap auth, fill in ldap details in ldap.conf
#include /config/nginx/ldap.conf;
# enable for Authelia
#include /config/nginx/authelia-server.conf;
location / {
# enable the next two lines for http auth
#auth_basic "Restricted";
#auth_basic_user_file /config/nginx/.htpasswd;
# enable the next two lines for ldap auth
#auth_request /auth;
#error_page 401 =200 /ldaplogin;
# enable for Authelia
#include /config/nginx/authelia-location.conf;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
+49
View File
@@ -0,0 +1,49 @@
import collections
import concurrent.futures
import glob
import json
import os
import re
import requests
import urllib3
def find_apps():
apps = {}
file_paths = glob.glob("/config/nginx/**/*", recursive=True)
for file_path in file_paths:
if not os.path.isfile(file_path):
continue
file = open(file_path, "r")
content = file.read()
results = re.finditer(r"(\s+)set \$upstream_app (?P<name>\S+?);(\s+)set \$upstream_port (?P<port>\d+);\n(\s+)set \$upstream_proto (?P<proto>\w+);", content)
for result in results:
params = result.groupdict()
app = f"{params['proto']}://{params['name']}:{params['port']}"
if app not in apps:
apps[app] = set()
if not file_path.endswith(".sample"):
apps[app].add(file_path)
return apps
def is_available(url):
try:
ans = requests.head(url, timeout=5, verify=False)
return ans.status_code < 404
except:
return False
urllib3.disable_warnings()
apps = find_apps()
discovered_apps = collections.defaultdict(dict)
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
futures = {executor.submit(is_available, app): app for app in apps.keys()}
for future in concurrent.futures.as_completed(futures):
app = futures[future]
if not future.result() and not apps[app]:
continue
discovered_apps[app]["status"] = future.result()
discovered_apps[app]["locations"] = list(apps[app])
print(json.dumps(discovered_apps, sort_keys=True))
+87
View File
@@ -0,0 +1,87 @@
<?php
function GetStatus() {
$output = shell_exec("python3 /dashboard/swag-status.py");
$results = json_decode($output);
$status = "";
$index = 0;
foreach($results as $result => $data){
$tr_class = ($index % 2 == 0) ? 'shaded' : '';
$status .= '<tr class="'.$tr_class.'"><td><span class="status-text">'.$result.'</span></td><td class="align-td">';
if ($data->status == 1) {
$status .= '<span class="green-circle circle-empty"></span>';
} else {
$status .= '<span class="red-circle"></span>';
}
$status .= '</td><td class="align-td">';
if (!empty($data->locations)) {
$locations = $data->locations;
$location = implode(",", $locations);
$status .= '<span class="green-circle circle-empty"></span></td><td><span class="status-text">'.$location.'</span></td>';
} else {
$status .= '<span class="red-circle"></span></td><td></td>';
}
$status .= '</tr>';
$index++;
}
return <<<HTML
<style type="text/css">
.status-div {
display: inline-block;
}
.status-text {
font-size: 15px;
}
td {
padding: 6px;
text-align: center;
}
.align-td {
text-align: center;
}
.green-circle {
padding: 2px 10px;
border-radius: 100%;
background-color: green;
border: 1px solid black;
}
.red-circle {
padding: 2px 10px;
border-radius: 50%;
background-color: red;
border: 1px solid black;
}
</style>
<h1>Welcome to your <a target="_blank" href="https://github.com/linuxserver/docker-swag">SWAG</a> instance</h1>
<h4>A webserver and reverse proxy solution brought to you by <a target="_blank" href="https://www.linuxserver.io/">linuxserver.io</a> with php support and a built-in Certbot client.</h4>
<h4>We have an article on how to use swag here: <a target="_blank" href="https://docs.linuxserver.io/general/swag">docs.linuxserver.io</a></h4>
<h4>For help and support, please visit: <a target="_blank" href="https://www.linuxserver.io/support">linuxserver.io/support</a></h4>
<div class="wrap-panel status-div">
<div>
<table class="table-hover">
<col>
<col>
<col>
<col>
<thead>
<tr>
<td><h3>Application</h3></td>
<td><h3>Available</h3></td>
<td><h3>Proxied</h3></td>
<td><h3>Location</h3></td>
</tr>
</thead>
<tbody class="tbody-data">
{$status}
</tbody>
</table>
<br/>
</div>
<br/>
</div>
<div class="wrap-general">
HTML;
}
$access = shell_exec("cat /config/log/nginx/access.log | goaccess -a -o html --html-prefs='{\"theme\":\"darkGray\"}' --log-format COMBINED --geoip-database=/config/geoip2db/GeoLite2-City.mmdb -");
$status = GetStatus();
echo str_replace("<div class='wrap-general'>", $status, $access);
?>
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv bash
echo "Applying the SWAG dashboard mod..."
apk add --no-cache --upgrade goaccess
cp -f /dashboard/dashboard.subdomain.conf.sample /config/nginx/proxy-confs/
echo "Applied the SWAG dashboard mod"
-27
View File
@@ -1,27 +0,0 @@
#!/usr/bin/with-contenv bash
# Determine if setup is needed
if [ ! -f /usr/local/lib/python***/dist-packages/sshuttle ] && \
[ -f /usr/bin/apt ]; then
## Ubuntu
apt-get update
apt-get install --no-install-recommends -y \
iptables \
openssh-client \
python3 \
python3-pip
pip3 install sshuttle
fi
if [ ! -f /usr/lib/python***/site-packages/sshuttle ] && \
[ -f /sbin/apk ]; then
# Alpine
apk add --no-cache \
iptables \
openssh \
py3-pip \
python3
pip3 install sshuttle
fi
chown -R root:root /root
chmod -R 600 /root/.ssh
-3
View File
@@ -1,3 +0,0 @@
#!/usr/bin/with-contenv bash
sshuttle --dns --remote root@${HOST}:${PORT} 0/0 -x 172.17.0.0/16