mirror of
https://github.com/linuxserver/docker-mods.git
synced 2026-02-05 04:59:42 +08:00
Add fail2ban to the dashboard
This commit is contained in:
parent
47cb2ee5eb
commit
64e4cc7aa8
10
root/dashboard/swag-f2b.py
Normal file
10
root/dashboard/swag-f2b.py
Normal file
@ -0,0 +1,10 @@
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
|
||||
con = sqlite3.connect("/config/fail2ban/fail2ban.sqlite3")
|
||||
cur = con.cursor()
|
||||
results = cur.execute("SELECT jails.name, COUNT(bans.ip) AS bans FROM jails LEFT JOIN bans ON jails.name=bans.jail GROUP BY jails.name").fetchall()
|
||||
con.close()
|
||||
output = json.dumps({k:v for (k,v) in results}, sort_keys=True)
|
||||
print(output)
|
||||
@ -19,10 +19,10 @@ def find_apps():
|
||||
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)
|
||||
for result in results:
|
||||
params = result.groupdict()
|
||||
app = f"{params['proto']}://{params['name']}:{params['port']}"
|
||||
app = f"{params['proto']}://{params['name']}:{params['port']}/"
|
||||
if app not in apps:
|
||||
apps[app] = set()
|
||||
if not file_path.endswith(".sample"):
|
||||
if file_path.startswith("/config/nginx/site-confs/") or file_path.endswith(".conf"):
|
||||
apps[app].add(file_path)
|
||||
return apps
|
||||
|
||||
@ -1,32 +1,12 @@
|
||||
<?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++;
|
||||
}
|
||||
function GetHeader() {
|
||||
return <<<HTML
|
||||
<style type="text/css">
|
||||
.status-div {
|
||||
display: inline-block;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
vertical-align: top;
|
||||
}
|
||||
.status-text {
|
||||
font-size: 15px;
|
||||
@ -55,34 +35,91 @@
|
||||
<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>
|
||||
HTML;
|
||||
}
|
||||
|
||||
function GetProxies() {
|
||||
$output = shell_exec("python3 /dashboard/swag-proxies.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
|
||||
<div class="wrap-panel status-div">
|
||||
<div>
|
||||
<h2>Proxies</h2>
|
||||
<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>
|
||||
<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}
|
||||
{$status}
|
||||
</tbody>
|
||||
</table>
|
||||
<br/>
|
||||
</div>
|
||||
<br/>
|
||||
</div>
|
||||
<div class="wrap-general">
|
||||
HTML;
|
||||
}
|
||||
|
||||
function GetF2B() {
|
||||
$output = exec("python3 /dashboard/swag-f2b.py");
|
||||
$jails = json_decode($output, true);
|
||||
$status = "";
|
||||
$index = 0;
|
||||
foreach($jails as $jail=>$bans){
|
||||
$tr_class = ($index % 2 == 0) ? 'shaded' : '';
|
||||
$status .= '<tr class="'.$tr_class.'"><td><span class="status-text">'.$jail.'</span></td><td><span class="status-text">'.$bans.'</span></td></tr>';
|
||||
$index++;
|
||||
}
|
||||
return <<<HTML
|
||||
<div class="wrap-panel status-div">
|
||||
<div>
|
||||
<h2>Fail2Ban</h2>
|
||||
<table class="table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><h3>Jail</h3></td>
|
||||
<td><h3>Bans</h3></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="tbody-data">
|
||||
{$status}
|
||||
</tbody>
|
||||
</table>
|
||||
<br/>
|
||||
</div>
|
||||
<br/>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
$geodb = file_exists('/config/geoip2db/GeoLite2-City.mmdb') ? '--geoip-database=/config/geoip2db/GeoLite2-City.mmdb' : '';
|
||||
$access = shell_exec("cat /config/log/nginx/access.log | goaccess -a -o html --html-prefs='{\"theme\":\"darkGray\"}' --log-format COMBINED ".$geodb." -");
|
||||
$status = GetStatus();
|
||||
$status = GetHeader() . GetProxies() . GetF2B() . '<div class="wrap-general">';
|
||||
echo str_replace("<div class='wrap-general'>", $status, $access);
|
||||
?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user