mirror of
https://github.com/YGGverse/web-api.git
synced 2025-08-28 14:52:09 +00:00
implement node settings
This commit is contained in:
parent
6bc9b53d24
commit
7e3f7c6df0
@ -10,6 +10,12 @@ cd web-api
|
|||||||
composer install
|
composer install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
```
|
||||||
|
nano config.json
|
||||||
|
```
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"yggverse/net": "^1.0"
|
"yggverse/net": "^1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
composer.lock
generated
14
composer.lock
generated
@ -4,20 +4,20 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "0bf82e6e2a05c49f8a6c7e89da62a373",
|
"content-hash": "c062f15666280a924bcafbc19443d914",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "yggverse/net",
|
"name": "yggverse/net",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/YGGverse/net-php.git",
|
"url": "https://github.com/YGGverse/net-php.git",
|
||||||
"reference": "3a89da61d56fba97e5f48c2d840dd9f70b4fd295"
|
"reference": "60114e9d1e19731b79b7a0de7824164d7a288d7e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/YGGverse/net-php/zipball/3a89da61d56fba97e5f48c2d840dd9f70b4fd295",
|
"url": "https://api.github.com/repos/YGGverse/net-php/zipball/60114e9d1e19731b79b7a0de7824164d7a288d7e",
|
||||||
"reference": "3a89da61d56fba97e5f48c2d840dd9f70b4fd295",
|
"reference": "60114e9d1e19731b79b7a0de7824164d7a288d7e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
@ -32,9 +32,9 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/YGGverse/net-php/issues",
|
"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": [],
|
"packages-dev": [],
|
||||||
|
86
config.json
Normal file
86
config.json
Normal file
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,42 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Init config
|
||||||
|
$config = json_decode(
|
||||||
|
file_get_contents(
|
||||||
|
__DIR__ . '/../../../config.json'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init helpers
|
||||||
|
function isRegex(array $regex, string $value): bool
|
||||||
|
{
|
||||||
|
foreach ($regex as $regex)
|
||||||
|
{
|
||||||
|
if (preg_match($regex, $value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set headers
|
// Set headers
|
||||||
header('Access-Control-Allow-Origin: *');
|
foreach ($config->net->dig->response->headers as $key => $value)
|
||||||
|
{
|
||||||
|
header(
|
||||||
|
sprintf(
|
||||||
|
'%s: %s',
|
||||||
|
$key,
|
||||||
|
$value
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
// Load dependencies
|
// Load dependencies
|
||||||
require_once(__DIR__ . '/../../vendor/autoload.php');
|
require_once(__DIR__ . '/../../../vendor/autoload.php');
|
||||||
|
|
||||||
// Valid name required to continue
|
// Valid name required to continue
|
||||||
if (empty($_GET['name']) || !is_string($_GET['name']) || !\Yggverse\Net\Dig::isHostName($_GET['name']))
|
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
|
// Valid records required to continue
|
||||||
$records = [];
|
$records = [];
|
||||||
|
|
||||||
if (isset($_GET['record']) && is_string($_GET['record']) && \Yggverse\Net\Dig::isRecord($_GET['record']))
|
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'];
|
$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 (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;
|
$records[] = $record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,42 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Init config
|
||||||
|
$config = json_decode(
|
||||||
|
file_get_contents(
|
||||||
|
__DIR__ . '/../../../config.json'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init helpers
|
||||||
|
function isRegex(array $regex, string $value): bool
|
||||||
|
{
|
||||||
|
foreach ($regex as $regex)
|
||||||
|
{
|
||||||
|
if (preg_match($regex, $value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set headers
|
// Set headers
|
||||||
header('Access-Control-Allow-Origin: *');
|
foreach ($config->net->socket->response->headers as $key => $value)
|
||||||
|
{
|
||||||
|
header(
|
||||||
|
sprintf(
|
||||||
|
'%s: %s',
|
||||||
|
$key,
|
||||||
|
$value
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
// Load dependencies
|
// Load dependencies
|
||||||
require_once(__DIR__ . '/../../vendor/autoload.php');
|
require_once(__DIR__ . '/../../../vendor/autoload.php');
|
||||||
|
|
||||||
// Valid port required to continue
|
// Valid port required to continue
|
||||||
if (empty($_GET['port']) || !\Yggverse\Net\Socket::isPort($_GET['port']))
|
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
|
// Set client address if optional host not provided
|
||||||
if (empty($_GET['host']))
|
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
|
// Connection test
|
||||||
exit(
|
exit(
|
||||||
json_encode(
|
json_encode(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user