From cfe7864a0c4d021f2404618928997b7e12f8b710 Mon Sep 17 00:00:00 2001 From: r4sas Date: Wed, 9 Aug 2023 23:21:53 +0000 Subject: [PATCH] add description processing --- README.md | 2 +- composer.lock | 12 ++++----- config.php.dist => config.dist.php | 1 + templates/add.twig | 14 ++++++++-- templates/home.twig | 11 ++++---- views/add.php | 42 ++++++++++++++++++++---------- views/home.php | 1 + 7 files changed, 55 insertions(+), 28 deletions(-) rename config.php.dist => config.dist.php (97%) diff --git a/README.md b/README.md index 79efe33..16db777 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ server { php-fpm configuration --- -```conf +```ini [reg.i2p] prefix = /home/www/$pool diff --git a/composer.lock b/composer.lock index 6c16168..f851947 100644 --- a/composer.lock +++ b/composer.lock @@ -722,16 +722,16 @@ }, { "name": "twig/twig", - "version": "v3.6.0", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" + "reference": "5cf942bbab3df42afa918caeba947f1b690af64b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/5cf942bbab3df42afa918caeba947f1b690af64b", + "reference": "5cf942bbab3df42afa918caeba947f1b690af64b", "shasum": "" }, "require": { @@ -777,7 +777,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.6.0" + "source": "https://github.com/twigphp/Twig/tree/v3.7.0" }, "funding": [ { @@ -789,7 +789,7 @@ "type": "tidelift" } ], - "time": "2023-05-03T19:06:57+00:00" + "time": "2023-07-26T07:16:09+00:00" } ], "packages-dev": [], diff --git a/config.php.dist b/config.dist.php similarity index 97% rename from config.php.dist rename to config.dist.php index fbc126b..fbd3715 100644 --- a/config.php.dist +++ b/config.dist.php @@ -24,6 +24,7 @@ $options = [ 'approval' => true, // require approval (check host for availability before publishing) 'fetcher' => true, // enable external subscriptions fetcher 'tableitems' => 30, // records limit on alive, all, search pages + 'desclength' => 120, // description length limit /* Records processing options */ 'approvedelay' => 24, // check host for availability before publishing for this time (hours) diff --git a/templates/add.twig b/templates/add.twig index 8d73326..7c98c4f 100644 --- a/templates/add.twig +++ b/templates/add.twig @@ -24,7 +24,7 @@ {% else %}

Domain successfuly added

{% endif %} -
+
Domain: @@ -32,6 +32,16 @@ {{ result.host }}
+ {% if result.desc|length > 0 %} +
+ + Description: + + + {{ result.desc }} + +
+ {% endif %}
Addresshelper: @@ -76,7 +86,7 @@
- 0 %} value="{{ desc }}"{% endif %}> + 0 %} value="{{ desc }}"{% endif %}>
diff --git a/templates/home.twig b/templates/home.twig index 681c110..dc1f337 100644 --- a/templates/home.twig +++ b/templates/home.twig @@ -13,10 +13,10 @@
Supported commands:

@@ -48,7 +48,8 @@ Domains that are inaccessible before the disabling date for {% trans %}one day{% plural hidedays %}{{ count }} days{% endtrans %} will be hidden from alive list and removed from export lists, but will still be checked every hour.
- When domain dead for amount days stated above, it will be marked as disabled, opened for registration and will be checked once a day for availability at {{ fullhour }} o'clock UTC. + When domain dead for amount days stated above, it will be marked as disabled, opened for registration and will be checked once a day for availability at {{ fullhour }} o'clock UTC.
+ Description length limit is {{ desclength }} symbols.

{% if activation %} diff --git a/views/add.php b/views/add.php index 879b7ad..a10dfb7 100644 --- a/views/add.php +++ b/views/add.php @@ -16,7 +16,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { $record = (string) $_POST["record"]; if (isset($_POST["desc"]) && !empty($_POST["desc"])) { - $desc = (string) $_POST["desc"]; + $desc = htmlspecialchars((string) $_POST["desc"]); } $pdo = (new App\DB($options))->pdo; @@ -27,15 +27,19 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { if (!isset($parsed['host'])) { $result["error"] = "Error while validating: Incorrect Auth string"; + } else if (strlen($desc) > $options['desclength']) { + $result["error"] = "Error while validating: Too long description"; + } else if (!$util->isValidDomain($parsed['host'], $error)) { $result["error"] = "Error while validating: " . $error; } else { - if ($util->isPunycodeDomain($parsed['host'])) { - $domain = idn_to_utf8($parsed['host'], 0, INTL_IDNA_VARIANT_UTS46); + $domain_low = mb_strtolower($parsed['host']); + if ($util->isPunycodeDomain($domain_low)) { + $domain = idn_to_utf8($domain_low, 0, INTL_IDNA_VARIANT_UTS46); } else { - $domain = $parsed['host']; + $domain = $domain_low; } if (!isset($parsed["commands"]) || !isset($parsed["commands"]["sig"])) { @@ -82,8 +86,8 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { } else { $base32 = $util->b32from64($parsed["b64"]); - $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`) VALUES (?, ?, ?)'); - if (!$STH->execute([$domain, $parsed["b64"], $base32])) { + $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`, `description`) VALUES (?, ?, ?, ?)'); + if (!$STH->execute([$domain, $parsed["b64"], $base32, htmlspecialchars($desc)])) { $result["error"] = "Error happened while inserting record to database. Please try again later."; } else { @@ -91,6 +95,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { $result["host"] = $domain; $result["base64"] = $parsed["b64"]; $result["base32"] = $base32; + $result["desc"] = $desc; } } } @@ -112,8 +117,14 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { } else { $base32 = $util->b32from64($parsed["b64"]); - $STH = $pdo->prepare('UPDATE `hosts` SET `base64` = ?, `base32` = ? WHERE `host` = ?'); - if (!$STH->execute([$parsed["b64"], $base32, $domain])) { + if (!empty($desc)) { + $STH = $pdo->prepare('UPDATE `hosts` SET `base64` = ?, `base32` = ?, `description` = ? WHERE `host` = ?'); + $args = [$parsed["b64"], $base32, $domain, $desc]; + } else { + $STH = $pdo->prepare('UPDATE `hosts` SET `base64` = ?, `base32` = ? WHERE `host` = ?'); + $args = [$parsed["b64"], $base32, $domain]; + } + if (!$STH->execute($args)) { $result["error"] = "Error happened while updating record in database. Please try again later."; } else { @@ -121,6 +132,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { $result["host"] = $domain; $result["base64"] = $parsed["b64"]; $result["base32"] = $base32; + $result["desc"] = $desc; } } } @@ -152,8 +164,8 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { } else { $base32 = $util->b32from64($parsed["b64"]); - $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`) VALUES (?, ?, ?)'); - if (!$STH->execute([$domain, $parsed["b64"], $base32])) { + $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`, `description`) VALUES (?, ?, ?, ?)'); + if (!$STH->execute([$domain, $parsed["b64"], $base32, $desc])) { $result["error"] = "Error happened while updating record in database. Please try again later."; } else { @@ -161,6 +173,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { $result["host"] = $domain; $result["base64"] = $parsed["b64"]; $result["base32"] = $base32; + $result["desc"] = $desc; } } } @@ -218,15 +231,16 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { $base32 = $util->b32from64($parsed["b64"]); /* Adding to database 2LD domain */ - $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`) VALUES (?, ?, ?)'); - if (!$STH->execute([$domain, $parsed["b64"], $base32])) { + $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`, `description`) VALUES (?, ?, ?, ?)'); + if (!$STH->execute([$domain, $parsed["b64"], $base32, $desc])) { $result["error"] = "Error happened while inserting record to database. Please try again later."; } else { - $result["command"] = 'added'; + $result["command"] = 'add'; $result["host"] = $domain; $result["base64"] = $parsed["b64"]; $result["base32"] = $base32; + $result["desc"] = $desc; } } } @@ -245,4 +259,4 @@ if (!empty($result)) { $pdo = null; $template = $twig->load('add.twig'); -echo $template->render(['record' => $record, 'desc' => $desc, 'result' => $result, 'all' => $all]); +echo $template->render(['record' => $record, 'desc' => $desc, 'desclength' => $options['desclength'], 'result' => $result, 'all' => $all]); diff --git a/views/home.php b/views/home.php index 78667df..ce74f44 100644 --- a/views/home.php +++ b/views/home.php @@ -30,6 +30,7 @@ $vars = array( 'fullhour' => $options['fullhour'], 'fetcher' => $options['fetcher'], 'exportperiod' => $options['exportperiod'], + 'desclength' => $options['desclength'], 'subscrs' => $subscrs, 'blackcnt' => $blackcnt, 'all' => $all