update: new services and LogController

This commit is contained in:
Bruno Eckhardt committed 2026-02-16 11:04:23 +01:00
1 parent 466af07095
commit b004fcaf40
6 files changed
+314 -18

No files matched your search

+28 -7
View File
@@ -26,8 +26,11 @@ $serviceGroups = array (
'defaultOpen' => true,
'services' =>
array (
0 => 'request_logs',
1 => 'request_chart',
0 => 'public_request_logs',
1 => 'public_request_chart',
2 => 'backend_request_logs',
3 => 'backend_request_chart',
4 => 'personal_request_logs',
),
),
'System' =>
@@ -55,15 +58,33 @@ $services = array (
'active' => true,
'adminOnly' => false,
),
'request_logs' =>
'public_request_logs' =>
array (
'name' => 'Logs',
'name' => 'Public Logs',
'active' => true,
'adminOnly' => false,
),
'request_chart' =>
'public_request_chart' =>
array (
'name' => 'Statistik',
'name' => 'Public Statistik',
'active' => true,
'adminOnly' => false,
),
'backend_request_logs' =>
array (
'name' => 'Backend Logs',
'active' => true,
'adminOnly' => false,
),
'backend_request_chart' =>
array (
'name' => 'Backend Statistik',
'active' => true,
'adminOnly' => false,
),
'personal_request_logs' =>
array (
'name' => 'Persönliche Logs',
'active' => true,
'adminOnly' => false,
),
@@ -155,4 +176,4 @@ $linkButtons = array (
'adminOnly' => false,
'group' => 'devices',
),
);
);
+6 -2
View File
@@ -4,6 +4,7 @@
function logging() {
include_once 'DatabaseConnect.php';
include_once 'DatabaseController.php';
include_once '../modules/ConsoleLog.php';
include_once 'DataController.php';
$ClientIP = (new getSpecificData())->getClientIP();
@@ -16,6 +17,7 @@ function logging() {
$LAND = (new getSpecificData())->getGeoIP($ClientIP);
$Whitelisted = (new getSpecificData())->getWhitelistedIPs();
$node = (new getSpecificData())->getServerNode((new getSpecificData())->getServerIP());
$username = $_SESSION['username'] ?? 'Unbekannt';
$website = (new getSpecificData())->getWebsite();
// if (in_array($ClientIP, $Whitelisted)) {
@@ -65,7 +67,7 @@ function logging() {
} else {
DatabaseInsert(
"logs",
"CLIENT_IP, LAND, SERVER_IP, USER_AGENT, REQUEST_URL, USER_COOKIE_VALUE, USER_SESSION_VALUE, FIRST_REQUEST, QUERY, WEBSITE",
"CLIENT_IP, LAND, SERVER_IP, USER_AGENT, REQUEST_URL, USER_COOKIE_VALUE, USER_SESSION_VALUE, FIRST_REQUEST, QUERY, WEBSITE, USER",
$ClientIP,
$LAND,
$node,
@@ -75,8 +77,10 @@ function logging() {
$SessionID,
$REQUESTTIME,
$QUERY,
$website
$website,
$username
);
}
// ConsoleLog("Client IP: $ClientIP | User Agent: $UserAgent | Request URL: $RequestURL | User Cookie: $USERCOOKIE | Session ID: $SessionID | Request Time: $REQUESTTIME | GeoIP: $LAND | Server Node: $node | Website: $website");
}
}
@@ -1,7 +1,7 @@
<?php
$conn = db_connect();
$sql = "SELECT DATE(FIRST_REQUEST) as tag, COUNT(*) as anzahl FROM logs GROUP BY DATE(FIRST_REQUEST) ORDER BY DATE(FIRST_REQUEST)";
$sql = "SELECT DATE(FIRST_REQUEST) as tag, COUNT(*) as anzahl FROM logs WHERE WEBSITE = 'backend.blackpi.ipv64.net' GROUP BY DATE(FIRST_REQUEST) ORDER BY DATE(FIRST_REQUEST)";
$result = $conn->query($sql);
$labels = [];
@@ -39,8 +39,7 @@ if (!$useCustom) {
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE CLIENT_IP NOT IN ($devips_sql)
AND DATE(FIRST_REQUEST) = CURDATE()
WHERE DATE(FIRST_REQUEST) = CURDATE() AND WEBSITE = 'backend.blackpi.ipv64.net'
ORDER BY FIRST_REQUEST DESC
";
break;
@@ -49,7 +48,7 @@ if (!$useCustom) {
$sql = "
SELECT CLIENT_IP, LAND, USER_AGENT, SUM(counter) AS gesamt_counter
FROM logs
WHERE CLIENT_IP NOT IN ($devips_sql)
WHERE WEBSITE = 'backend.blackpi.ipv64.net'
GROUP BY CLIENT_IP
ORDER BY gesamt_counter DESC
";
@@ -59,7 +58,7 @@ if (!$useCustom) {
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node1'
WHERE `SERVER_IP` = 'node1' AND WEBSITE = 'backend.blackpi.ipv64.net'
ORDER BY `FIRST_REQUEST` DESC;
";
break;
@@ -68,7 +67,7 @@ if (!$useCustom) {
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node2'
WHERE `SERVER_IP` = 'node2' AND WEBSITE = 'backend.blackpi.ipv64.net'
ORDER BY `FIRST_REQUEST` DESC;
";
break;
@@ -77,7 +76,7 @@ if (!$useCustom) {
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node3'
WHERE `SERVER_IP` = 'node3' AND WEBSITE = 'backend.blackpi.ipv64.net'
ORDER BY `FIRST_REQUEST` DESC;
";
break;
@@ -86,7 +85,7 @@ if (!$useCustom) {
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node4'
WHERE `SERVER_IP` = 'node4' AND WEBSITE = 'backend.blackpi.ipv64.net'
ORDER BY `FIRST_REQUEST` DESC;
";
break;
@@ -95,7 +94,7 @@ if (!$useCustom) {
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE CLIENT_IP NOT IN ($devips_sql)
WHERE WEBSITE = 'backend.blackpi.ipv64.net'
ORDER BY FIRST_REQUEST DESC
";
}
+105
View File
@@ -0,0 +1,105 @@
<?php
$conn = db_connect();
$sql = "SELECT DATE(FIRST_REQUEST) as tag, COUNT(*) as anzahl FROM logs WHERE WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL GROUP BY DATE(FIRST_REQUEST) ORDER BY DATE(FIRST_REQUEST)";
$result = $conn->query($sql);
$labels = [];
$data = [];
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$labels[] = $row['tag'];
$data[] = (int)$row['anzahl'];
}
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Logs Chart</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom"></script>
</head>
<body>
<canvas id="logChart" width="600" height="400"></canvas>
<script>
const ctx = document.getElementById('logChart').getContext('2d');
const logChart = new Chart(ctx, {
type: 'line',
data: {
labels: <?php echo json_encode($labels); ?>,
datasets: [{
label: 'Logs pro Tag',
data: <?php echo json_encode($data); ?>,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
fill: true,
tension: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'Logs pro Tag'
},
legend: {
display: true,
position: 'top'
},
zoom: {
pan: {
enabled: true,
mode: 'x',
},
zoom: {
wheel: {
enabled: true,
},
mode: 'x',
}
}
},
interaction: {
mode: 'index',
intersect: false
},
scales: {
x: {
title: {
display: true,
text: 'Datum'
}
},
y: {
min: 0,
max: 300,
title: {
display: true,
text: 'Anzahl Logs'
},
ticks: {
stepSize: 20
},
beginAtZero: true
}
}
}
});
</script>
</body>
</html>
+167
View File
@@ -0,0 +1,167 @@
<?php
$conn = db_connect();
// Dev-IPs
$devips = (new getSpecificData())->getWhitelistedIPs();
$devips_sql = "'" . implode("','", $devips) . "'";
// Filter
$filter = $_GET['filter'] ?? 'today';
$customQuery = $_POST['custom_query'] ?? '';
$useCustom = false;
// Custom Query Schutz
if ($customQuery) {
$forbidden = ['DELETE', 'UPDATE', 'INSERT', 'DROP', 'ALTER', 'TRUNCATE'];
$upper = strtoupper($customQuery);
foreach ($forbidden as $bad) {
if (strpos($upper, $bad) !== false) {
echo "<b style='color:red'>Gefährliche Query blockiert ($bad)</b>";
return;
}
}
if (stripos(trim($customQuery), "SELECT") !== 0) {
echo "<b style='color:red'>Nur SELECT erlaubt</b>";
return;
}
$sql = $customQuery;
$useCustom = true;
}
// Standard Queries
if (!$useCustom) {
switch ($filter) {
case 'today':
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE CLIENT_IP NOT IN ($devips_sql) AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
AND DATE(FIRST_REQUEST) = CURDATE()
ORDER BY FIRST_REQUEST DESC
";
break;
case 'counterperip':
$sql = "
SELECT CLIENT_IP, LAND, USER_AGENT, SUM(counter) AS gesamt_counter
FROM logs
WHERE CLIENT_IP NOT IN ($devips_sql) AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
GROUP BY CLIENT_IP
ORDER BY gesamt_counter DESC
";
break;
case 'node1':
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node1' AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
ORDER BY `FIRST_REQUEST` DESC;
";
break;
case 'node2':
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node2' AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
ORDER BY `FIRST_REQUEST` DESC;
";
break;
case 'node3':
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node3' AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
ORDER BY `FIRST_REQUEST` DESC;
";
break;
case 'node4':
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE `SERVER_IP` = 'node4' AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
ORDER BY `FIRST_REQUEST` DESC;
";
break;
default:
$sql = "
SELECT `CLIENT_IP`, `LAND`, `REQUEST_URL`, `COUNTER`
FROM logs
WHERE CLIENT_IP NOT IN ($devips_sql) AND WEBSITE = 'blackpi.ipv64.net' OR WEBSITE IS NULL
ORDER BY FIRST_REQUEST DESC
";
}
}
?>
<h1>📊 Logs</h1>
<form method="GET" action="index.php">
<input type="hidden" name="service" value="<?= htmlspecialchars($_GET['service'] ?? 'logs') ?>">
<select name="filter" onchange="this.form.submit()">
<?php
$options = ['alle','today','node1','node2','node3','node4','counterperip'];
foreach ($options as $opt) {
$sel = ($filter === $opt) ? 'selected' : '';
echo "<option value='$opt' $sel>$opt</option>";
}
?>
</select>
</form>
<!-- <br>
<form method="POST">
<textarea name="custom_query" style="width:100%;height:60px;"><?= htmlspecialchars($customQuery) ?></textarea>
<br>
<button type="submit">Query ausführen</button>
</form>
<hr> -->
<br>
<?php
$daten = [];
if ($erg = $conn->query($sql)) {
// echo "<pre style='background:var(--bg-soft,#f4f4f4);padding:10px;'>$sql</pre>";
while ($row = $erg->fetch_object()) {
$daten[] = $row;
}
}
?>
<?php if (!$daten): ?>
<b>Keine Daten gefunden</b>
<?php else: ?>
<div style="overflow-x:auto;">
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse;width:100%;">
<tr>
<?php foreach ($daten[0] as $key => $_): ?>
<th><?= htmlspecialchars($key) ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($daten as $row): ?>
<tr>
<?php foreach ($row as $val): ?>
<td><?= htmlspecialchars($val ?? '') ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif; ?>