90 lines
3.8 KiB
PHP
90 lines
3.8 KiB
PHP
<?php
|
|
|
|
|
|
function logging() {
|
|
include_once 'DataController.php';
|
|
if ((new getSpecificData())->getLoggingStatus("GENERAL_BACKEND_LOGGING")[0]['WERT'] == 'ON') {
|
|
include_once 'DatabaseConnect.php';
|
|
include_once 'DatabaseController.php';
|
|
include_once 'DataController.php';
|
|
|
|
$ClientIP = (new getSpecificData())->getClientIP();
|
|
$UserAgent = (new getSpecificData())->getUserAgent();
|
|
$RequestURL = (new getSpecificData())->getRequestURL();
|
|
$USERCOOKIE = (new getSpecificData())->getCookie("USER");
|
|
$SessionID = (new getSpecificData())->getSessionID();
|
|
$REQUESTTIME = (new getSpecificData())->getRequestTime();
|
|
$QUERY = (new getSpecificData())->getQuery();
|
|
$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 ((new getSpecificData())->getLoggingStatus("DEV_BACKEND_LOGGING")[0]['WERT'] == 'OFF') {
|
|
if (in_array($ClientIP, $Whitelisted)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
$db_conn = db_connect();
|
|
|
|
$stmt = $db_conn->prepare("SELECT * FROM logs WHERE
|
|
`CLIENT_IP` LIKE ? and
|
|
`REQUEST_URL` = ? and
|
|
`REQUEST_URL` <> '/favicon.ico'
|
|
");
|
|
|
|
$stmt->bind_param("ss", $ClientIP, $RequestURL);
|
|
$stmt->execute();
|
|
$stmt->store_result();
|
|
|
|
if ($RequestURL !== '/favicon.ico') {
|
|
if ($stmt->num_rows > 0) { //wenn mindestens eine zeile vorhanden ist für die client ip dann führe updates durch, wenn nicht mache neue zeile
|
|
$updateCounter = $db_conn->prepare("
|
|
UPDATE logs
|
|
SET COUNTER = COUNTER + 1
|
|
WHERE `CLIENT_IP` = ?
|
|
AND `REQUEST_URL` = ?
|
|
");
|
|
$updateCounter->bind_param("ss", $ClientIP, $RequestURL);
|
|
$updateCounter->execute();
|
|
|
|
$updateLastRequest = $db_conn->prepare("
|
|
UPDATE logs
|
|
SET `LAST_REQUEST` = ?
|
|
WHERE `CLIENT_IP` = ?
|
|
AND `REQUEST_URL` = ?
|
|
");
|
|
$updateLastRequest->bind_param("sss", $REQUESTTIME, $ClientIP, $RequestURL);
|
|
$updateLastRequest->execute();
|
|
|
|
$updateCookieValue = $db_conn->prepare("
|
|
UPDATE logs
|
|
SET `USER_COOKIE_VALUE` = ?
|
|
WHERE `CLIENT_IP` = ?
|
|
AND `REQUEST_URL` = ?
|
|
");
|
|
$updateCookieValue->bind_param("sss", $USERCOOKIE, $ClientIP, $RequestURL);
|
|
$updateCookieValue->execute();
|
|
} else {
|
|
DatabaseInsert(
|
|
"logs",
|
|
"CLIENT_IP, LAND, SERVER_IP, USER_AGENT, REQUEST_URL, USER_COOKIE_VALUE, USER_SESSION_VALUE, FIRST_REQUEST, QUERY, WEBSITE, USER",
|
|
$ClientIP,
|
|
$LAND,
|
|
$node,
|
|
$UserAgent,
|
|
$RequestURL,
|
|
$USERCOOKIE,
|
|
$SessionID,
|
|
$REQUESTTIME,
|
|
$QUERY,
|
|
$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");
|
|
}
|
|
}
|
|
} |