Browse Source

add autojump, update css, add host disabling

Signed-off-by: r4sas <r4sas@i2pmail.org>
master
R4SAS 4 years ago
parent
commit
e79d2bb28e
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 2
      checker.php
  2. 6
      config.php.dist
  3. 39
      export.php
  4. 10
      lib/utils.php
  5. 6
      public/css/style.css
  6. 4
      public/index.php
  7. 6
      templates/alive.twig
  8. 3
      templates/home.twig
  9. 51
      templates/jump.twig
  10. 6
      templates/latest.twig
  11. 5
      templates/search.twig
  12. 2
      views/add.php
  13. 4
      views/alive.php
  14. 58
      views/autojump.php
  15. 2
      views/home.php
  16. 39
      views/jump.php
  17. 2
      views/latest.php
  18. 12
      views/search.php

2
checker.php

@ -65,7 +65,7 @@ foreach ($results as $host => $result) @@ -65,7 +65,7 @@ foreach ($results as $host => $result)
{
if($result)
{
$pdo->exec("UPDATE `hosts` SET `last_seen` = current_timestamp() WHERE `host` = '" . $host . "'");
$pdo->exec("UPDATE `hosts` SET `last_seen` = current_timestamp(), `disabled` = 0, `hidden` = 0 WHERE `host` = '" . $host . "'");
$i++;
}
}

6
config.php.dist

@ -28,9 +28,11 @@ $options = [ @@ -28,9 +28,11 @@ $options = [
'approvedelay' => 24, // check host for availability before publishing for this time (hours)
'approveseen' => 3, // host must be seen lesser than this amount of hours for approving (hours)
'newdays' => 7, // assume host as new for that amout of days
'newdays' => 14, // assume host as new for that amout of days
'delnewdays' => 3, // if new host not seen more than X days, disable it and disapprove
'delolddays' => 30, // same as above, but for old hosts
'delolddays' => 45, // same as above, but for old hosts
'hidedays' => 3, // days before domain will be marked as hidden in period before disabling
'fullhour' => 8, // make hosts full-check at that hour (0-23). Usage of out-of-range value or at other hours, checker will validate only enabled domains.
];

39
export.php

@ -8,16 +8,18 @@ date_default_timezone_set ('UTC'); @@ -8,16 +8,18 @@ date_default_timezone_set ('UTC');
$pdo = (new App\DB($options))->pdo;
$util = new App\Utils;
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `approved`, `initial`, `disabled` FROM hosts");
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `approved`, `initial`, `disabled`, `hidden` FROM hosts");
$hosts = $STH->fetchAll(PDO::FETCH_ASSOC);
// for automatic approving
$approffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["approvedelay"] . " hour")); // approval offset
$apprseen = date ("Y-m-d H:i:s", strtotime ("-" . $options["approveseen"] . " hour")); // approval maxseen offset
$apprseen = date ("Y-m-d H:i:s", strtotime ("-" . $options["approveseen"] . " hour")); // approval maxseen offset
$newregoffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["newdays"] . " day")); // 7
$newseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delnewdays"] . " day")); // 3
$oldseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delolddays"] . " day")); // 30
$newregoffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["newdays"] . " day"));
$newseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delnewdays"] . " day"));
$oldseenlim = date ("Y-m-d H:i:s", strtotime ("-" . $options["delolddays"] . " day"));
$hideoffs = date ("Y-m-d H:i:s", strtotime ("-" . $options["hidedays"] . " day")); // hide offset
$export_full = $export_live = $export_init = [];
$export_addr_full = $export_addr_live = $export_addr_init = [];
@ -31,27 +33,28 @@ foreach ($hosts as $host) @@ -31,27 +33,28 @@ foreach ($hosts as $host)
array_push($export_addr_full, $domain . "," . $host["base32"]);
if (
($options["approval"] == false || $host["approved"] == 1) &&
($options["approval"] == false || $host["approved"] == 1) && $host["hidden"] == 0 &&
($host["disabled"] == 0 ||
(
($host["add_date"] > $newregoffs && $host["last_seen"] > $newseenlim) ||
($host["add_date"] < $newregoffs && $host["last_seen"] > $oldseenlim)
($host["add_date"] < $newregoffs && $host["last_seen"] > $oldseenlim) // is seen till disabling date
)
)
)
{
array_push($export_live, $domain . "=" . $host["base64"]);
array_push($export_addr_live, $domain . "," . $host["base32"]);
if ($host["initial"] == 1)
{
array_push($export_init, $domain . "=" . $host["base64"]);
array_push($export_addr_init, $domain . "," . $host["base32"]);
if ($host["last_seen"] > $hideoffs) { // if seen not earlier than hide offset
array_push($export_live, $domain . "=" . $host["base64"]);
array_push($export_addr_live, $domain . "," . $host["base32"]);
if ($host["initial"] == 1)
{
array_push($export_init, $domain . "=" . $host["base64"]);
array_push($export_addr_init, $domain . "," . $host["base32"]);
}
}
if ($host["disabled"] == 1)
else // hide because not available for "hidedays" days
{
$pdo->exec ("UPDATE `hosts` SET `disabled` = 0 WHERE `host` = '" . $host["host"] . "'");
$pdo->exec ("UPDATE `hosts` SET `hidden` = 1 WHERE `host` = '" . $host["host"] . "'");
}
}
else if (
@ -68,7 +71,7 @@ foreach ($hosts as $host) @@ -68,7 +71,7 @@ foreach ($hosts as $host)
if (
$host["disabled"] == 0 &&
($host["add_date"] > $newregoffs && $host["last_seen"] < $newseenlim) ||
($host["add_date"] < $newregoffs && $host["last_seen"] < $oldseenlim)
($host["add_date"] < $newregoffs && $host["last_seen"] < $oldseenlim) // is seen more that disabling period days
)
{
$pdo->exec ("UPDATE `hosts` SET `disabled` = 1 WHERE `host` = '" . $host["host"] . "'");

10
lib/utils.php

@ -153,9 +153,9 @@ class Utils { @@ -153,9 +153,9 @@ class Utils {
{
$len = strlen($data);
if($len < 5 || $len > 67)
if($len < 5 || $len > 255) // rfc2181, section 11
{
$result = "Domain must be longer than 5 and lesser than 67 chars.";
$result = "Domain must be longer than 5 and lesser than 255 chars.";
return false;
}
@ -172,7 +172,7 @@ class Utils { @@ -172,7 +172,7 @@ class Utils {
}
else
{
$result = "Domain is not valid or is not in Punycode format.";
$result = "Domain is not valid. Check if you domain label is lesser than 63 chars, and uses only ASCII or Punycode format.";
return false;
}
@ -188,9 +188,9 @@ class Utils { @@ -188,9 +188,9 @@ class Utils {
{
$len = strlen($data);
if($len < 5 || $len > 67)
if($len < 5 || $len > 255) // rfc2181, section 11
{
$result = "Domain must be longer than 5 and lesser than 67 chars.";
$result = "Domain must be longer than 5 and lesser than 255 chars.";
return false;
}

6
public/css/style.css

@ -368,8 +368,12 @@ abbr { @@ -368,8 +368,12 @@ abbr {
color: #ddddff;
}
.table__row td:last-of-type {
white-space: nowrap;
}
.table__cell {
padding: 10px;
padding: 8px;
}
.table__cell_center-bold {

4
public/index.php

@ -27,6 +27,10 @@ $r->addRoute('^/jump/?(.*)/?', function($url, $query = "") { @@ -27,6 +27,10 @@ $r->addRoute('^/jump/?(.*)/?', function($url, $query = "") {
require __DIR__ . '/../views/jump.php';
});
$r->addRoute('^/autojump/?(.*)/?', function($url, $query = "") {
require __DIR__ . '/../views/autojump.php';
});
$r->addRoute('^/latest/?$', function($url) {
require __DIR__ . '/../views/latest.php';
});

6
templates/alive.twig

@ -21,7 +21,11 @@ @@ -21,7 +21,11 @@
<tbody class="table__body">
{% for host in hosts %}
<tr class="table__row">
<td class="table__cell"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host }}</a></td>
{% if host.host|length > 24 %}
<td class="table__cell table__cell_long-ass"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host|slice(0, 23) }}&hellip;</a></td>
{% else %}
<td class="table__cell table__cell_long-ass"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host }}</a></td>
{% endif %}
<td class="table__cell table__cell_center-bold"><a href="http://{{ host.host }}/?i2paddresshelper={{ host.base64 }}" rel="external nofollow noopener noreferrer" target="_blank">A</a></td>
<td class="table__cell table__cell_center-bold"><a href="http://{{ host.base32 }}.b32.i2p/" rel="external nofollow noopener noreferrer" target="_blank">B</a></td>
<td class="table__cell table__cell_full-b32 table__cell_long-ass">{{ host.base32 }}.b32.i2p</td>

3
templates/home.twig

@ -42,7 +42,10 @@ @@ -42,7 +42,10 @@
<ul>
<li>{{ delnewdays }} days if registered less than {{ newdays }} days ago</li>
<li>{{ delolddays }} days if registered more than {{ newdays }} days ago</li>
<li>1 year if registered more than {{ delolddays }} days ago</li>
</ul>
Domains that are inaccessible before the disabling date for {{ hidedays }} days, will be hidden from <a href="/alive">alive</a> list, 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.
</p>
{% if approval %}

51
templates/jump.twig

@ -1,6 +1,22 @@ @@ -1,6 +1,22 @@
{% extends "_page.twig" %}
{% block title %}Jump to site{% endblock %}
{% block head %}
{{ parent() }}
{% if autojump %}
{% if not result %}
<meta http-equiv="refresh" content="2; URL=/jump/" />
{% elseif result.error|length > 0 %}
{# Skipping redirect #}
{% elseif result.uri|length > 0 %}
<meta http-equiv="refresh" content="4; URL=http://{{ result.host }}/{{ result.uri }}{% if '?' in result.uri %}&{% else %}?{% endif %}i2paddresshelper={{ result.base64 }}" />
{% else %}
<meta http-equiv="refresh" content="4; URL=http://{{ result.host }}/?i2paddresshelper={{ result.base64 }}" />
{% endif %}
{% endif %}
{% endblock %}
{% block content %}
<div class="container">
<div class="jumper">
@ -13,11 +29,21 @@ @@ -13,11 +29,21 @@
{% else %}
<div class="jumper__succ">
<h3 class="jumper__title title">Query result for "{{ result.host }}"</h3>
{% if autojump %}
<div class="jumper__line line">
Site is found. You will be redirected soon...
</div>
<br>
{% endif %}
<div class="jumper__line line">
<span>
Addresshelper:
</span>
<a href="http://{{ result.host }}/?i2paddresshelper={{ result.base64 }}" rel="external nofollow noopener noreferrer" target="_blank">Go to site</a>
{% if result.uri|length > 0 %}
<a href="http://{{ result.host }}/{{ result.uri }}{% if '?' in result.uri %}&{% else %}?{% endif %}i2paddresshelper={{ result.base64 }}" rel="external nofollow noopener noreferrer" target="_blank">Go to site</a>
{% else %}
<a href="http://{{ result.host }}/?i2paddresshelper={{ result.base64 }}" rel="external nofollow noopener noreferrer" target="_blank">Go to site</a>
{% endif %}
</div>
<div class="jumper__line line">
@ -36,9 +62,31 @@ @@ -36,9 +62,31 @@
{{ result.base64 }}
</span>
</div>
<div class="jumper__line line">
<span>
Added at:
</span>
<span class="crazy-base64-span">
{{ result.add_date }}
</span>
</div>
<div class="jumper__line line">
<span>
Last seen:
</span>
<span class="crazy-base64-span">
{{ result.last_seen != '0000-00-00 00:00:00' ? result.last_seen : 'Never' }}
</span>
</div>
</div>
{% endif %}
{% elseif (autojump and not result) %}
<div class="jumper__err">
<h3 class="jumper__title title">Error</h3>
<b style="color: red;">Empty request, redirecting to jump page</b>
</div>
{% endif %}
{% if not autojump %}
<div class="jumper__itself">
<p class="important jumper__title title">
Query domain
@ -51,6 +99,7 @@ @@ -51,6 +99,7 @@
<input type="submit" value="Submit" class="btn jumper__btn">
</form>
</div>
{% endif %}
</div>
</div>
{% endblock %}

6
templates/latest.twig

@ -22,7 +22,11 @@ @@ -22,7 +22,11 @@
<tbody class="table__body">
{% for host in hosts %}
<tr class="table__row">
<td class="table__cell"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host }}</a></td>
{% if host.host|length > 24 %}
<td class="table__cell table__cell_long-ass"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host|slice(0, 23) }}&hellip;</a></td>
{% else %}
<td class="table__cell table__cell_long-ass"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host }}</a></td>
{% endif %}
<td class="table__cell table__cell_center-bold"><a href="http://{{ host.host }}/?i2paddresshelper={{ host.base64 }}" rel="external nofollow noopener noreferrer" target="_blank">A</a></td>
<td class="table__cell table__cell_center-bold"><a href="http://{{ host.base32 }}.b32.i2p/" rel="external nofollow noopener noreferrer" target="_blank">B</a></td>
<td class="table__cell table__cell_full-b32 table__cell_long-ass">{{ host.base32 }}.b32.i2p</td>

5
templates/search.twig

@ -50,8 +50,11 @@ @@ -50,8 +50,11 @@
<label for="q">Query:</label>
<input class="text-input search-page__text-input" type="text" id="q" name="q" maxlength="67" placeholder="domain.i2p" required>
</div>
<div class="form__field">
<label for="q">Alive only:</label>
<input type="checkbox" id="a" name="a" value="1">
</div>
<input type="submit" value="Submit" class="btn search-page__btn">
</form>
</div>
{% endblock %}

2
views/add.php

@ -32,7 +32,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) { @@ -32,7 +32,7 @@ if (isset($_POST["record"]) && !empty($_POST["record"])) {
$result["error"] = "Error while validating: " . $error;
} else {
if ($util->isPunycodeDomain($parsed['host'])) {
$domain = idn_to_utf8($parsed['host']);
$domain = idn_to_utf8($parsed['host'], 0, INTL_IDNA_VARIANT_UTS46);
} else {
$domain = $parsed['host'];
}

4
views/alive.php

@ -19,7 +19,7 @@ $pdo = (new App\DB($options))->pdo; @@ -19,7 +19,7 @@ $pdo = (new App\DB($options))->pdo;
/* Get records amount */
$STH = $pdo->query ("SELECT COUNT(*) as `count` FROM `hosts` " .
"WHERE `approved` = 1 AND (" .
"WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0 AND (" .
" (`add_date` < '" . $newregoffs . "' AND `last_seen` > '" . $oldseenlim . "') OR" .
" (`add_date` > '" . $newregoffs . "' AND `last_seen` > '" . $newseenlim . "')" .
")");
@ -30,7 +30,7 @@ $pages = intdiv($records, $options["tableitems"]) + 1; @@ -30,7 +30,7 @@ $pages = intdiv($records, $options["tableitems"]) + 1;
/* Get records with limit */
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` " .
"WHERE `approved` = 1 AND (" .
"WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0 AND (" .
" (`add_date` < '" . $newregoffs . "' AND `last_seen` > '" . $oldseenlim . "') OR" .
" (`add_date` > '" . $newregoffs . "' AND `last_seen` > '" . $newseenlim . "')" .
") LIMIT " . $offset . ", " . $options["tableitems"]);

58
views/autojump.php

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
/* Initialize Twig engine */
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates');
$twig = new \Twig\Environment($loader, [
'cache' => __DIR__ . '/../cache',
'auto_reload' => true,
]);
$utils = new App\Utils;
$domain = "";
$uri = "";
$result = [];
$error = "";
// Get request data and check if request contain uri path
if (isset($query) && !empty($query)) {
if (strpos($query, "/")) {
$a = explode ("/", $query, 2);
$domain = htmlspecialchars($a[0]);
$uri = $a[1];
} else {
$domain = htmlspecialchars($query);
}
}
// Check domain name
if(!empty($domain) && !$utils->isValidDomain($domain, $error)) {
$domain = "";
$result["error"] = 'Not valid query: ' . $error;
}
else if(!empty($domain) && $utils->isValidDomain($domain, $error)) {
if ((new App\Utils)->isPunycodeDomain($domain)) {
$domain = idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46);
}
$pdo = (new App\DB($options))->pdo;
$STH = $pdo->query("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1");
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetchAll();
if (empty($row)) {
$result["error"] = "No such host is found";
} else {
$result = array_merge($result, $row[0]);
if (!empty($uri)) {
$result['uri'] = $uri;
}
}
}
$template = $twig->load('jump.twig');
echo $template->render(['autojump' => true, 'domain' => $domain, 'result' => $result]);

2
views/home.php

@ -27,6 +27,8 @@ $vars = array( @@ -27,6 +27,8 @@ $vars = array(
'newdays' => $options['newdays'],
'delnewdays' => $options['delnewdays'],
'delolddays' => $options['delolddays'],
'hidedays' => $options['hidedays'],
'fullhour' => $options['fullhour'],
'fetcher' => $options['fetcher'],
'subscrs' => $subscrs
);

39
views/jump.php

@ -12,31 +12,52 @@ $twig = new \Twig\Environment($loader, [ @@ -12,31 +12,52 @@ $twig = new \Twig\Environment($loader, [
$utils = new App\Utils;
$data = "";
$domain = "";
$uri = "";
$result = [];
$error = "";
if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST["q"]) > 67)
$result["error"] = "Request is too long, max length is 67 chars";
else if (isset($query) && !empty($query))
$domain = htmlspecialchars($query);
else if (isset($_POST["q"]))
$domain = htmlspecialchars($_POST["q"]);
// Get request data
if (isset($query) && !empty($query)) {
$data = $query;
} else if (isset($_POST["q"])) {
$data = $_POST["q"];
}
// Check if request contain uri path
if (strpos($data, "/")) {
$a = explode ("/", $data, 2);
$domain = htmlspecialchars($a[0]);
$uri = $a[1];
} else {
$domain = htmlspecialchars($data);
}
// Check domain name
if(!empty($domain) && !$utils->isValidDomain($domain, $error)) {
$domain = "";
$result["error"] = 'Not valid query: ' . $error;
}
else if(!empty($domain) && $utils->isValidDomain($domain, $error)) {
if ((new App\Utils)->isPunycodeDomain($domain)) {
$domain = idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46);
}
$pdo = (new App\DB($options))->pdo;
$STH = $pdo->query("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1");
$STH = $pdo->query("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen` FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1");
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetchAll();
if (empty($row))
if (empty($row)) {
$result["error"] = "No such host is found";
else
} else {
$result = array_merge($result, $row[0]);
if (!empty($uri)) {
$result['uri'] = $uri;
}
}
}
$template = $twig->load('jump.twig');

2
views/latest.php

@ -13,7 +13,7 @@ $twig = new \Twig\Environment($loader, [ @@ -13,7 +13,7 @@ $twig = new \Twig\Environment($loader, [
$pdo = (new App\DB($options))->pdo;
/* Get records with limit */
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date` FROM `hosts` ORDER BY `add_date` DESC LIMIT " . $options["tableitems"]);
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date` FROM `hosts` WHERE `disabled` = 0 ORDER BY `add_date` DESC LIMIT " . $options["tableitems"]);
$STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll();

12
views/search.php

@ -14,6 +14,7 @@ $utils = new App\Utils; @@ -14,6 +14,7 @@ $utils = new App\Utils;
$result = [];
$q = "";
$a = false;
if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST["q"]) > 67) {
$result["error"] = "Request is too long, max length is 67 chars";
@ -23,10 +24,19 @@ if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST[ @@ -23,10 +24,19 @@ if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST[
$q = htmlspecialchars($_POST["q"]);
}
if (isset($_POST["a"])) {
$a = true;
}
if(!empty($q)) {
$pdo = (new App\DB($options))->pdo;
$STH = $pdo->query("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE `host` LIKE '%" . $q . "%' OR `base32` LIKE '%" . $q . "%' LIMIT " . $options["tableitems"]);
if ($a)
$STH = $pdo->query("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE (`host` LIKE '%" . $q . "%' OR `base32` LIKE '%" . $q . "%') AND `disabled` = 0 LIMIT " . $options["tableitems"]);
else
$STH = $pdo->query("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE `host` LIKE '%" . $q . "%' OR `base32` LIKE '%" . $q . "%' LIMIT " . $options["tableitems"]);
$STH->setFetchMode(PDO::FETCH_ASSOC);
$row = $STH->fetchAll();

Loading…
Cancel
Save