Browse Source

add description processing

master
R4SAS 10 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 { @@ -64,7 +64,7 @@ server {
php-fpm configuration
---
```conf
```ini
[reg.i2p]
prefix = /home/www/$pool

12
composer.lock generated

@ -722,16 +722,16 @@ @@ -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 @@ @@ -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 @@ @@ -789,7 +789,7 @@
"type": "tidelift"
}
],
"time": "2023-05-03T19:06:57+00:00"
"time": "2023-07-26T07:16:09+00:00"
}
],
"packages-dev": [],

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

@ -24,6 +24,7 @@ $options = [ @@ -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)

14
templates/add.twig

@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
{% else %}
<h3 class="adder__title title">Domain successfuly added</h3>
{% endif %}
<div class="adder__line line adder__line_reshost">
<div class="adder__line line adder__line_reshost">
<span>
Domain:
</span>
@ -32,6 +32,16 @@ @@ -32,6 +32,16 @@
{{ result.host }}
</span>
</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">
<span>
Addresshelper:
@ -76,7 +86,7 @@ @@ -76,7 +86,7 @@
</div>
<div class="form__field">
<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>
<input class="adder__submit adder__btn btn" type="submit" value="Submit">
</form>

11
templates/home.twig

@ -13,10 +13,10 @@ @@ -13,10 +13,10 @@
<br>
Supported commands:
<ul>
<li>adding of hosts for 2LD domains (example.i2p)</li>
<li>adding subdomains (addsubdomain)</li>
<li>adding/changing destination (adddest, changedest) - destination is replaced with the new one, old destination is purged</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#!sig=b64sig">adding of hosts for 2LD domains (example.i2p)</li>
<li title="subdomain.example.i2p=b64dest#!action=addsubdomain#oldname=example.i2p#olddest=oldb64dest#oldsig=b64sig#sig=b64sig">adding subdomains (addsubdomain)</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 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>
</p>
@ -48,7 +48,8 @@ @@ -48,7 +48,8 @@
</ul>
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>
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>
{% if activation %}

42
views/add.php

@ -16,7 +16,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { @@ -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"])) { @@ -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"])) { @@ -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"])) { @@ -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"])) { @@ -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"])) { @@ -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"])) { @@ -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"])) { @@ -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"])) { @@ -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)) { @@ -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]);

1
views/home.php

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

Loading…
Cancel
Save