From b906febeeb7d67971aab1feeaeaf79432cf78d9d Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:48:39 +0200 Subject: [PATCH] Fixed issue in DAS too --- das/start_das.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/das/start_das.php b/das/start_das.php index 669b1bd..a7380f1 100644 --- a/das/start_das.php +++ b/das/start_das.php @@ -25,23 +25,24 @@ $server->set([ 'package_eof' => "\r\n" ]); +// Connect to the database +try { + $c = require_once 'config.php'; + $pdo = new PDO("{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}", $c['db_username'], $c['db_password']); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + $server->send($fd, "Error connecting to database"); + $server->close($fd); +} + // Register a callback to handle incoming connections $server->on('connect', function ($server, $fd) { echo "Client connected: {$fd}\r\n"; }); // Register a callback to handle incoming requests -$server->on('receive', function ($server, $fd, $reactorId, $data) { - // Connect to the database - try { - $c = require_once 'config.php'; - $pdo = new PDO("{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']}", $c['db_username'], $c['db_password']); - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } catch (PDOException $e) { - $server->send($fd, "Error connecting to database"); - $server->close($fd); - } - +$server->on('receive', function ($server, $fd, $reactorId, $data) use ($c, $pdo) { + // Validate and sanitize the domain name $domain = trim($data); if (!$domain) {