Files
Web-Public/WEBROOT/controller/DataController.php
T

162 lines
4.9 KiB
PHP

<?php
class getSpecificData {
public function getServerIP(): string {
return $_SERVER['SERVER_ADDR'] ?? 'Unbekannt';
}
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 getRequestTimeFloat(): string {
return $_SERVER['REQUEST_TIME_FLOAT'] ?? 'Unbekannt';
}
public function getQuery(): string {
return $_SERVER['QUERY_STRING'] ?? 'Unbekannt';
}
public function getServerName(): string {
return $_SERVER['SERVER_NAME'] ?? 'Unbekannt';
}
public function getRequestMethod(): string {
return $_SERVER['REQUEST_METHOD'] ?? 'Unbekannt';
}
public function getCurrentDir(): string {
return __DIR__ ;
}
public function getDatabase(): string {
$conn = db_connect();
return $conn->host_info;
}
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) {
$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',
];
foreach ($nodes as $node => $ip) {
if ($ServerIP == $ip) {
// $ServerIP = $node;
return $node;
break;
}
}
}
function getClientStatus($ClientIP) {
if (in_array($ClientIP, $this->getWhitelistedIPs())) {
return "Trusted";
}
return "Untrusted";
}
public function getAllData(): array {
return [
'Document-Root' => $this->getDocumentRoot(),
'CurrentDir' => $this->getCurrentDir(),
'SERVER-IP' => $this->getServerIP(),
'Node' => $this->getServerNode($this->getServerIP()),
'Server-Port' => $this->getServerPort(),
'Server-Name' => $this->getServerName(),
'Client-IP' => $this->getClientIP(),
'Client-Port' => $this->getClientPort(),
'User-Agent' => $this->getUserAgent(),
'Request URL' => $this->getRequestURL(),
'Cookie' => $this->getCookie('USER'),
'Server Cookie' => $this->getCookie('SESSSRV'),
'Session' => $this->getSessionID(),
'Query' => $this->getQuery(),
'Request-Method' => $this->getRequestMethod(),
'Request-Time' => $this->getRequestTime(),
'Unix-timestamp' => $this->getRequestTimeFloat(),
'Land' => $this->getGeoIP($this->getClientIP()),
'Database' => $this->getDatabase(),
'Whitelisted Status' => $this->getClientStatus($this->getClientIP()),
'Whitelisted IPs' => $this->getWhitelistedIPs(),
];
}
public function ShowAllData(): void {
$SpecificData = (new getSpecificData())->getAllData();
echo "<pre>";
print_r($SpecificData);
echo "</pre>";
}
}
// $ShowAllDAta = (new getSpecificData())->ShowAllData();