Browse Source

add description processing

master
R4SAS 9 months ago
parent
commit
cfe7864a0c
  1. 2
      README.md
  2. 12
      composer.lock
  3. 1
      config.dist.php
  4. 14
      templates/add.twig
  5. 11
      templates/home.twig
  6. 42
      views/add.php
  7. 1
      views/home.php

2
README.md

@ -64,7 +64,7 @@ server {
php-fpm configuration php-fpm configuration
--- ---
```conf ```ini
[reg.i2p] [reg.i2p]
prefix = /home/www/$pool prefix = /home/www/$pool

12
composer.lock generated

@ -722,16 +722,16 @@
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.6.0", "version": "v3.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "106c170d08e8415d78be2d16c3d057d0d108262b" "reference": "5cf942bbab3df42afa918caeba947f1b690af64b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", "url": "https://api.github.com/repos/twigphp/Twig/zipball/5cf942bbab3df42afa918caeba947f1b690af64b",
"reference": "106c170d08e8415d78be2d16c3d057d0d108262b", "reference": "5cf942bbab3df42afa918caeba947f1b690af64b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -777,7 +777,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "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": [ "funding": [
{ {
@ -789,7 +789,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-05-03T19:06:57+00:00" "time": "2023-07-26T07:16:09+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

1
config.php.dist → config.dist.php

@ -24,6 +24,7 @@ $options = [
'approval' => true, // require approval (check host for availability before publishing) 'approval' => true, // require approval (check host for availability before publishing)
'fetcher' => true, // enable external subscriptions fetcher 'fetcher' => true, // enable external subscriptions fetcher
'tableitems' => 30, // records limit on alive, all, search pages 'tableitems' => 30, // records limit on alive, all, search pages
'desclength' => 120, // description length limit
/* Records processing options */ /* Records processing options */
'approvedelay' => 24, // check host for availability before publishing for this time (hours) 'approvedelay' => 24, // check host for availability before publishing for this time (hours)

14
templates/add.twig

@ -24,7 +24,7 @@
{% else %} {% else %}
<h3 class="adder__title title">Domain successfuly added</h3> <h3 class="adder__title title">Domain successfuly added</h3>
{% endif %} {% endif %}
<div class="adder__line line adder__line_reshost"> <div class="adder__line line adder__line_reshost">
<span> <span>
Domain: Domain:
</span> </span>
@ -32,6 +32,16 @@
{{ result.host }} {{ result.host }}
</span> </span>
</div> </div>
{% if result.desc|length > 0 %}
<div class="adder__line line adder__line_reshost">
<span>
Description:
</span>
<span>
{{ result.desc }}
</span>
</div>
{% endif %}
<div class="adder__line line adder__line_adrhelper"> <div class="adder__line line adder__line_adrhelper">
<span> <span>
Addresshelper: Addresshelper:
@ -76,7 +86,7 @@
</div> </div>
<div class="form__field"> <div class="form__field">
<label for="desc">Description:</label> <label for="desc">Description:</label>
<input class="text-input adder__text-input" type="text" id="desc" name="desc" placeholder="A bit information about service on domain"{% if desc|length > 0 %} value="{{ desc }}"{% endif %}> <input class="text-input adder__text-input" type="text" id="desc" name="desc" maxlength="{{ desclength }}" placeholder="A bit information about service on domain"{% if desc|length > 0 %} value="{{ desc }}"{% endif %}>
</div> </div>
<input class="adder__submit adder__btn btn" type="submit" value="Submit"> <input class="adder__submit adder__btn btn" type="submit" value="Submit">
</form> </form>

11
templates/home.twig

@ -13,10 +13,10 @@
<br> <br>
Supported commands: Supported commands:
<ul> <ul>
<li>adding of hosts for 2LD domains (example.i2p)</li> <li title="example.i2p=b64dest#!sig=b64sig">adding of hosts for 2LD domains (example.i2p)</li>
<li>adding subdomains (addsubdomain)</li> <li title="subdomain.example.i2p=b64dest#!action=addsubdomain#oldname=example.i2p#olddest=oldb64dest#oldsig=b64sig#sig=b64sig">adding subdomains (addsubdomain)</li>
<li>adding/changing destination (adddest, changedest) - destination is replaced with the new one, old destination is purged</li> <li title="example.i2p=b64dest#!action=adddest#olddest=oldb64dest#oldsig=b64sig#sig=b64sig">adding/changing destination (adddest, changedest) - destination is replaced with the new one, old destination is purged. Can be used for changing description by using same dest as old one</li>
<li>adding domain alias (addname) - alias must be 2LD (example.i2p). For registering subdomains as aliases please use addsubdomain command</li> <li title="example.i2p=b64dest#!action=addname#oldname=oldhostname#sig=b64sig">adding domain alias (addname) - alias must be 2LD (example.i2p). For registering subdomains as aliases please use addsubdomain command</li>
</ul> </ul>
</p> </p>
@ -48,7 +48,8 @@
</ul> </ul>
Domains that are inaccessible before the disabling date for {% trans %}one day{% plural hidedays %}{{ count }} days{% endtrans %} Domains that are inaccessible before the disabling date for {% trans %}one day{% plural hidedays %}{{ count }} days{% endtrans %}
will be hidden from <a href="/alive">alive</a> list and removed from export lists, but will still be checked every hour.<br> will be hidden from <a href="/alive">alive</a> list and removed from export lists, but will still be checked every hour.<br>
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.<br>
Description length limit is {{ desclength }} symbols.
</p> </p>
{% if activation %} {% if activation %}

42
views/add.php

@ -16,7 +16,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
$record = (string) $_POST["record"]; $record = (string) $_POST["record"];
if (isset($_POST["desc"]) && !empty($_POST["desc"])) { if (isset($_POST["desc"]) && !empty($_POST["desc"])) {
$desc = (string) $_POST["desc"]; $desc = htmlspecialchars((string) $_POST["desc"]);
} }
$pdo = (new App\DB($options))->pdo; $pdo = (new App\DB($options))->pdo;
@ -27,15 +27,19 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
if (!isset($parsed['host'])) { if (!isset($parsed['host'])) {
$result["error"] = "Error while validating: Incorrect Auth string"; $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)) { } else if (!$util->isValidDomain($parsed['host'], $error)) {
$result["error"] = "Error while validating: " . $error; $result["error"] = "Error while validating: " . $error;
} else { } else {
if ($util->isPunycodeDomain($parsed['host'])) { $domain_low = mb_strtolower($parsed['host']);
$domain = idn_to_utf8($parsed['host'], 0, INTL_IDNA_VARIANT_UTS46); if ($util->isPunycodeDomain($domain_low)) {
$domain = idn_to_utf8($domain_low, 0, INTL_IDNA_VARIANT_UTS46);
} else { } else {
$domain = $parsed['host']; $domain = $domain_low;
} }
if (!isset($parsed["commands"]) || !isset($parsed["commands"]["sig"])) { if (!isset($parsed["commands"]) || !isset($parsed["commands"]["sig"])) {
@ -82,8 +86,8 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
} else { } else {
$base32 = $util->b32from64($parsed["b64"]); $base32 = $util->b32from64($parsed["b64"]);
$STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`) VALUES (?, ?, ?)'); $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`, `description`) VALUES (?, ?, ?, ?)');
if (!$STH->execute([$domain, $parsed["b64"], $base32])) { if (!$STH->execute([$domain, $parsed["b64"], $base32, htmlspecialchars($desc)])) {
$result["error"] = "Error happened while inserting record to database. Please try again later."; $result["error"] = "Error happened while inserting record to database. Please try again later.";
} else { } else {
@ -91,6 +95,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
$result["host"] = $domain; $result["host"] = $domain;
$result["base64"] = $parsed["b64"]; $result["base64"] = $parsed["b64"];
$result["base32"] = $base32; $result["base32"] = $base32;
$result["desc"] = $desc;
} }
} }
} }
@ -112,8 +117,14 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
} else { } else {
$base32 = $util->b32from64($parsed["b64"]); $base32 = $util->b32from64($parsed["b64"]);
$STH = $pdo->prepare('UPDATE `hosts` SET `base64` = ?, `base32` = ? WHERE `host` = ?'); if (!empty($desc)) {
if (!$STH->execute([$parsed["b64"], $base32, $domain])) { $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."; $result["error"] = "Error happened while updating record in database. Please try again later.";
} else { } else {
@ -121,6 +132,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
$result["host"] = $domain; $result["host"] = $domain;
$result["base64"] = $parsed["b64"]; $result["base64"] = $parsed["b64"];
$result["base32"] = $base32; $result["base32"] = $base32;
$result["desc"] = $desc;
} }
} }
} }
@ -152,8 +164,8 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
} else { } else {
$base32 = $util->b32from64($parsed["b64"]); $base32 = $util->b32from64($parsed["b64"]);
$STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`) VALUES (?, ?, ?)'); $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`, `description`) VALUES (?, ?, ?, ?)');
if (!$STH->execute([$domain, $parsed["b64"], $base32])) { if (!$STH->execute([$domain, $parsed["b64"], $base32, $desc])) {
$result["error"] = "Error happened while updating record in database. Please try again later."; $result["error"] = "Error happened while updating record in database. Please try again later.";
} else { } else {
@ -161,6 +173,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
$result["host"] = $domain; $result["host"] = $domain;
$result["base64"] = $parsed["b64"]; $result["base64"] = $parsed["b64"];
$result["base32"] = $base32; $result["base32"] = $base32;
$result["desc"] = $desc;
} }
} }
} }
@ -218,15 +231,16 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
$base32 = $util->b32from64($parsed["b64"]); $base32 = $util->b32from64($parsed["b64"]);
/* Adding to database 2LD domain */ /* Adding to database 2LD domain */
$STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`) VALUES (?, ?, ?)'); $STH = $pdo->prepare('INSERT INTO `hosts` (`host`, `base64`, `base32`, `description`) VALUES (?, ?, ?, ?)');
if (!$STH->execute([$domain, $parsed["b64"], $base32])) { if (!$STH->execute([$domain, $parsed["b64"], $base32, $desc])) {
$result["error"] = "Error happened while inserting record to database. Please try again later."; $result["error"] = "Error happened while inserting record to database. Please try again later.";
} else { } else {
$result["command"] = 'added'; $result["command"] = 'add';
$result["host"] = $domain; $result["host"] = $domain;
$result["base64"] = $parsed["b64"]; $result["base64"] = $parsed["b64"];
$result["base32"] = $base32; $result["base32"] = $base32;
$result["desc"] = $desc;
} }
} }
} }
@ -245,4 +259,4 @@ if (!empty($result)) {
$pdo = null; $pdo = null;
$template = $twig->load('add.twig'); $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]);

1
views/home.php

@ -30,6 +30,7 @@ $vars = array(
'fullhour' => $options['fullhour'], 'fullhour' => $options['fullhour'],
'fetcher' => $options['fetcher'], 'fetcher' => $options['fetcher'],
'exportperiod' => $options['exportperiod'], 'exportperiod' => $options['exportperiod'],
'desclength' => $options['desclength'],
'subscrs' => $subscrs, 'subscrs' => $subscrs,
'blackcnt' => $blackcnt, 'blackcnt' => $blackcnt,
'all' => $all 'all' => $all

Loading…
Cancel
Save