first commit

This commit is contained in:
2026-07-30 16:26:21 +02:00
commit 9e32a4d786
33 changed files with 3475 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace SyslogDash;
use PDO;
use PDOException;
class Database
{
private static ?PDO $instance = null;
public static function getInstance(): PDO
{
if (self::$instance === null) {
$config = self::getConfig();
try {
self::$instance = new PDO(
$config['dsn'],
$config['username'],
$config['password'],
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
);
} catch (PDOException $e) {
throw new \RuntimeException('Database verbinding mislukt: ' . $e->getMessage());
}
}
return self::$instance;
}
private static function getConfig(): array
{
$cfg = require __DIR__ . '/../config.php';
return $cfg['db'];
}
public static function table(): string
{
$cfg = require __DIR__ . '/../config.php';
return $cfg['syslog']['table'] ?? 'SystemEvents';
}
public static function getHostToIp(): array
{
$cfg = require __DIR__ . '/../config.php';
return $cfg['syslog']['host_to_ip'] ?? [];
}
public static function resolveHostnames(): bool
{
$cfg = require __DIR__ . '/../config.php';
return $cfg['syslog']['resolve_hostnames'] ?? true;
}
}