194 lines
6.0 KiB
PHP
194 lines
6.0 KiB
PHP
<?php
|
|
|
|
class getSpecificData {
|
|
|
|
public function getUserAgent(): string {
|
|
return $_SERVER['HTTP_USER_AGENT'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getRequestURL(): string {
|
|
return $_SERVER['REQUEST_URI'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getCookie(string $name): ?string {
|
|
return $_COOKIE[$name] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getServerCookie(string $name): ?string {
|
|
return $_COOKIE[$name] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getSessionID(): string {
|
|
return $session_id ?? 'Unbekannt ';
|
|
}
|
|
|
|
public function getServerPort(): string {
|
|
return $_SERVER['SERVER_PORT'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getClientPort(): string {
|
|
return $_SERVER['REMOTE_PORT'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getDocumentRoot(): string {
|
|
return $_SERVER['DOCUMENT_ROOT'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getQuery(): string {
|
|
return $_SERVER['QUERY_STRING'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getRequestMethod(): string {
|
|
return $_SERVER['REQUEST_METHOD'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getCurrentDir(): string {
|
|
return __DIR__ ;
|
|
}
|
|
|
|
public function getReferer(): string {
|
|
return $_SERVER['HTTP_REFERER'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getWebsite(): string {
|
|
return $_SERVER['HTTP_HOST'] ?? 'Unbekannt';
|
|
}
|
|
|
|
public function getDatabase(): string {
|
|
$conn = db_connect();
|
|
return $conn->host_info;
|
|
}
|
|
|
|
public function getServerName(): string {
|
|
$Servername = $_SERVER['SERVER_NAME'] ?? 'Unbekannt';
|
|
|
|
if (in_array($Servername, ['Unbekannt', '0.0.0.0', '127.0.0.1'])) {
|
|
return "Lokal";
|
|
} else {
|
|
return $Servername;
|
|
}
|
|
}
|
|
|
|
public function getServerIP(): string {
|
|
$ServerIP = $_SERVER['SERVER_ADDR'] ?? 'Unbekannt';
|
|
|
|
if (in_array($ServerIP, ['Unbekannt', '0.0.0.0', '127.0.0.1'])) {
|
|
return "Lokal";
|
|
} else {
|
|
return $ServerIP;
|
|
}
|
|
}
|
|
|
|
public function getClientIP(): string {
|
|
$xff = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? null;
|
|
|
|
if ($xff) {
|
|
$ips = array_map('trim', explode(',', $xff));
|
|
$clientIp = $ips[0];
|
|
return $clientIp;
|
|
} else {
|
|
return $_SERVER['REMOTE_ADDR'];
|
|
}
|
|
}
|
|
|
|
public function getRequestTime(): string {
|
|
date_default_timezone_set('Europe/Berlin');
|
|
$timestamp = $_SERVER['REQUEST_TIME'] ?? time();
|
|
return date('Y-m-d H:i:s', $timestamp);
|
|
}
|
|
|
|
function getGeoIP($ClientIP) {
|
|
$whitelist = (new getSpecificData())->getWhitelistedIPs();
|
|
|
|
if (in_array($ClientIP, ['0.0.0.0', '127.0.0.1'])) {
|
|
return "Lokal";
|
|
} elseif (in_array($ClientIP, ['Unbekannt', '0.0.0.0', '127.0.0.1'])) {
|
|
return "Lokal";
|
|
} else {
|
|
$response = file_get_contents("http://ip-api.com/json/{$ClientIP}?fields=country,countryCode");
|
|
$data = json_decode($response);
|
|
return $data->country;
|
|
}
|
|
}
|
|
|
|
function getWhitelistedIPs() {
|
|
include_once 'DatabaseController.php';
|
|
$data = DatabaseShow(
|
|
"Whitelisted",
|
|
"`IP-ADDRESSE`"
|
|
);
|
|
|
|
$results = [];
|
|
foreach ($data as $row) {
|
|
$results[] =$row['IP-ADDRESSE'];
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
function getServerNode($ServerIP) {
|
|
$nodes = [
|
|
'node1' => '172.30.0.11',
|
|
'node2' => '172.30.0.12',
|
|
'node3' => '172.30.0.13',
|
|
'node4' => '172.30.0.14',
|
|
'Lokal' => 'Lokal',
|
|
];
|
|
|
|
foreach ($nodes as $node => $ip) {
|
|
if ($ServerIP == $ip) {
|
|
return $node;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
function getClientStatus($ClientIP) {
|
|
if (in_array($ClientIP, $this->getWhitelistedIPs())) {
|
|
return "Trusted";
|
|
}
|
|
return "Untrusted";
|
|
}
|
|
|
|
function test() {
|
|
return "TEST";
|
|
}
|
|
|
|
public function getAllData(): array {
|
|
return [
|
|
'Document-Root' => $this->getDocumentRoot(),
|
|
'CurrentDir' => $this->getCurrentDir(),
|
|
'Referer' => $this->getReferer(),
|
|
'Request URL' => $this->getRequestURL(),
|
|
'Server-Port' => $this->getServerPort(),
|
|
'Server-IP' => $this->getServerIP(),
|
|
'Server-Name' => $this->getServerName(),
|
|
'Server-Node' => $this->getServerNode($this->getServerIP()),
|
|
'Client-IP' => $this->getClientIP(),
|
|
'Client-Port' => $this->getClientPort(),
|
|
'Client-Land' => $this->getGeoIP($this->getClientIP()),
|
|
'Client-User-Agent' => $this->getUserAgent(),
|
|
'Client-Cookie' => $this->getCookie('USER'),
|
|
'Client-Server-Cookie' => $this->getCookie('SESSSRV'),
|
|
'Client-Session-ID' => $this->getSessionID(),
|
|
'Query' => $this->getQuery(),
|
|
'Request-Method' => $this->getRequestMethod(),
|
|
'Request-Time' => $this->getRequestTime(),
|
|
'Database' => $this->getDatabase(),
|
|
'Whitelisted Status' => $this->getClientStatus($this->getClientIP()),
|
|
'Whitelisted IPs' => $this->getWhitelistedIPs(),
|
|
];
|
|
}
|
|
|
|
public function ShowAllData(): void {
|
|
$SpecificData = (new getSpecificData())->getAllData();
|
|
|
|
echo "<pre>";
|
|
foreach ($SpecificData as $key => $value) {
|
|
if (is_array($value)) {
|
|
$value = implode(', ', $value);
|
|
}
|
|
printf("%-22s : %s\n", $key, $value);
|
|
}
|
|
echo "</pre>";
|
|
}
|
|
} |