From 7e3f7c6df01b49e02ca0e59294880773d7225eca Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 1 Jan 2024 13:10:38 +0200 Subject: [PATCH] implement node settings --- README.md | 6 +++ composer.json | 2 +- composer.lock | 14 +++---- config.json | 86 +++++++++++++++++++++++++++++++++++++++ src/public/net/dig.php | 77 ++++++++++++++++++++++++++++++++++- src/public/net/socket.php | 59 ++++++++++++++++++++++++++- 6 files changed, 232 insertions(+), 12 deletions(-) create mode 100644 config.json diff --git a/README.md b/README.md index fb94c97..c9a25ed 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ cd web-api composer install ``` +## Config + +``` +nano config.json +``` + ## Run ``` diff --git a/composer.json b/composer.json index ef4f8e1..07679bb 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,6 @@ } }, "require": { - "yggverse/net": "^1.0" + "yggverse/net": "^1.2" } } diff --git a/composer.lock b/composer.lock index e7bb34d..b5adf47 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0bf82e6e2a05c49f8a6c7e89da62a373", + "content-hash": "c062f15666280a924bcafbc19443d914", "packages": [ { "name": "yggverse/net", - "version": "1.0.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/YGGverse/net-php.git", - "reference": "3a89da61d56fba97e5f48c2d840dd9f70b4fd295" + "reference": "60114e9d1e19731b79b7a0de7824164d7a288d7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/YGGverse/net-php/zipball/3a89da61d56fba97e5f48c2d840dd9f70b4fd295", - "reference": "3a89da61d56fba97e5f48c2d840dd9f70b4fd295", + "url": "https://api.github.com/repos/YGGverse/net-php/zipball/60114e9d1e19731b79b7a0de7824164d7a288d7e", + "reference": "60114e9d1e19731b79b7a0de7824164d7a288d7e", "shasum": "" }, "type": "library", @@ -32,9 +32,9 @@ ], "support": { "issues": "https://github.com/YGGverse/net-php/issues", - "source": "https://github.com/YGGverse/net-php/tree/1.0.0" + "source": "https://github.com/YGGverse/net-php/tree/1.2.0" }, - "time": "2023-12-16T10:55:48+00:00" + "time": "2023-12-17T05:59:26+00:00" } ], "packages-dev": [], diff --git a/config.json b/config.json new file mode 100644 index 0000000..8dfacaf --- /dev/null +++ b/config.json @@ -0,0 +1,86 @@ +{ + "net": + { + "dig": + { + "response": + { + "headers": + { + "Access-Control-Allow-Origin":"*" + } + }, + "request": + { + "name":{ + "regex": + [ + "/\\.ygg$/i", + "/\\.btn$/i", + "/\\.anon$/i", + "/\\.conf$/i", + "/\\.index$/i", + "/\\.index$/i", + "/\\.merch$/i", + "/\\.mirror$/i", + "/\\.mob$/i", + "/\\.screen$/i", + "/\\.srv$/i" + ] + }, + "record":{ + "regex": + [ + "/^A$/i", + "/^AAAA$/i", + "/^SRV$/i" + ] + }, + "records":{ + "regex": + [ + "/^A$/i", + "/^AAAA$/i", + "/^SRV$/i" + ] + } + } + }, + "socket": + { + "response": + { + "headers": + { + "Access-Control-Allow-Origin":"*" + } + }, + "request": + { + "port":{ + "regex": + [ + "/^[\\d]{2,6}$/" + ] + }, + "host":{ + "regex": + [ + "/^0{0,1}[2-3][a-f0-9]{0,2}:/", + "/\\.ygg$/i", + "/\\.btn$/i", + "/\\.anon$/i", + "/\\.conf$/i", + "/\\.index$/i", + "/\\.index$/i", + "/\\.merch$/i", + "/\\.mirror$/i", + "/\\.mob$/i", + "/\\.screen$/i", + "/\\.srv$/i" + ] + } + } + } + } +} \ No newline at end of file diff --git a/src/public/net/dig.php b/src/public/net/dig.php index 1d271d3..cbb00af 100644 --- a/src/public/net/dig.php +++ b/src/public/net/dig.php @@ -1,11 +1,42 @@ net->dig->response->headers as $key => $value) +{ + header( + sprintf( + '%s: %s', + $key, + $value + ) + ); +} + header('Content-Type: application/json; charset=utf-8'); // Load dependencies -require_once(__DIR__ . '/../../vendor/autoload.php'); +require_once(__DIR__ . '/../../../vendor/autoload.php'); // Valid name required to continue if (empty($_GET['name']) || !is_string($_GET['name']) || !\Yggverse\Net\Dig::isHostName($_GET['name'])) @@ -20,11 +51,38 @@ if (empty($_GET['name']) || !is_string($_GET['name']) || !\Yggverse\Net\Dig::isH ); } +if (!isRegex($config->net->dig->request->name->regex, $_GET['name'])) +{ + exit( + json_encode( + [ + 'success' => false, + 'message' => _('name not supported') + ] + ) + ); +} + // Valid records required to continue $records = []; if (isset($_GET['record']) && is_string($_GET['record']) && \Yggverse\Net\Dig::isRecord($_GET['record'])) { + if (!isRegex($config->net->dig->request->record->regex, $_GET['record'])) + { + exit( + json_encode( + [ + 'success' => false, + 'message' => sprintf( + _('record "%s" not supported'), + $_GET['record'] + ) + ] + ) + ); + } + $records[] = $_GET['record']; } @@ -34,6 +92,21 @@ if (isset($_GET['records']) && is_array($_GET['records'])) { if (is_string($record) && \Yggverse\Net\Dig::isRecord($record)) { + if (!isRegex($config->net->dig->request->records->regex, $record)) + { + exit( + json_encode( + [ + 'success' => false, + 'message' => sprintf( + _('record "%s" not supported'), + $record + ) + ] + ) + ); + } + $records[] = $record; } } diff --git a/src/public/net/socket.php b/src/public/net/socket.php index d7eb349..c7f3f7f 100644 --- a/src/public/net/socket.php +++ b/src/public/net/socket.php @@ -1,11 +1,42 @@ net->socket->response->headers as $key => $value) +{ + header( + sprintf( + '%s: %s', + $key, + $value + ) + ); +} + header('Content-Type: application/json; charset=utf-8'); // Load dependencies -require_once(__DIR__ . '/../../vendor/autoload.php'); +require_once(__DIR__ . '/../../../vendor/autoload.php'); // Valid port required to continue if (empty($_GET['port']) || !\Yggverse\Net\Socket::isPort($_GET['port'])) @@ -20,6 +51,18 @@ if (empty($_GET['port']) || !\Yggverse\Net\Socket::isPort($_GET['port'])) ); } +if (!isRegex($config->net->socket->request->port->regex, $_GET['port'])) +{ + exit( + json_encode( + [ + 'success' => false, + 'message' => _('port not supported') + ] + ) + ); +} + // Set client address if optional host not provided if (empty($_GET['host'])) { @@ -63,6 +106,18 @@ else } } +if (!isRegex($config->net->socket->request->host->regex, $host)) +{ + exit( + json_encode( + [ + 'success' => false, + 'message' => _('host not supported') + ] + ) + ); +} + // Connection test exit( json_encode(