-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpaths.php
More file actions
66 lines (56 loc) · 1.87 KB
/
paths.php
File metadata and controls
66 lines (56 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Use existing Session or start a new one
if (session_status() === PHP_SESSION_NONE) {
require_once __DIR__ . '/auth.php';
}
// Config Pfad
$CONFIG_ROOT = "/opt/Fail2Ban-Report/Settings/";
// Basispfad
$ARCHIVE_ROOT = dirname(__DIR__) . "/archive/";
// Serverliste automatisch aus archive/ generieren
$SERVERS = [];
if (is_dir($ARCHIVE_ROOT)) {
foreach (scandir($ARCHIVE_ROOT) as $entry) {
if ($entry === '.' || $entry === '..') {
continue;
}
if (is_dir($ARCHIVE_ROOT . $entry)) {
// z. B. Key = Ordnername, Value = "Schönschreibweise"
$SERVERS[$entry] = ucfirst($entry);
}
}
}
// Config einlesen
$configFile = $CONFIG_ROOT . 'fail2ban-report.config';
$config = parse_ini_file($configFile, true);
// Standardserver aus Config lesen
$configDefault = $config['Default Server']['defaultserver'] ?? null;
// Validierung Default: aus Config, sonst erster gefundener Server
if ($configDefault && array_key_exists($configDefault, $SERVERS)) {
$DEFAULT_SERVER = $configDefault;
} else {
$DEFAULT_SERVER = array_key_first($SERVERS);
}
// If choosen item -> dont forget
if (isset($_POST['server']) && array_key_exists($_POST['server'], $SERVERS)) {
$_SESSION['active_server'] = $_POST['server'];
}
// active server (Session → Default)
$activeServer = (isset($_SESSION['active_server']) && array_key_exists($_SESSION['active_server'], $SERVERS))
? $_SESSION['active_server']
: $DEFAULT_SERVER;
/**
* Pfade für den aktuell aktiven Server zurückgeben
*/
function getPaths($server) {
global $ARCHIVE_ROOT;
$base = $ARCHIVE_ROOT . $server . "/";
return [
"fail2ban" => $base . "fail2ban/",
"blocklists" => $base . "blocklists/",
"ufw" => $base . "ufw/",
];
}
// Globale PATHS-Variable setzen
$PATHS = getPaths($activeServer);
$PATHS['config'] = $CONFIG_ROOT;