diff --git a/checker.php b/checker.php index 2714d46..64cf572 100644 --- a/checker.php +++ b/checker.php @@ -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++; } } diff --git a/config.php.dist b/config.php.dist index 1220567..2963b9c 100644 --- a/config.php.dist +++ b/config.php.dist @@ -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. ]; diff --git a/export.php b/export.php index 7cea76a..a5bffdc 100644 --- a/export.php +++ b/export.php @@ -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) 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) 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"] . "'"); diff --git a/lib/utils.php b/lib/utils.php index bc4cd71..248efa4 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -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 { } 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 { { $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; } diff --git a/public/css/style.css b/public/css/style.css index 1678348..952d5a1 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -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 { diff --git a/public/index.php b/public/index.php index a36398b..503cf55 100644 --- a/public/index.php +++ b/public/index.php @@ -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'; }); diff --git a/templates/alive.twig b/templates/alive.twig index 393a327..8f10e42 100644 --- a/templates/alive.twig +++ b/templates/alive.twig @@ -21,7 +21,11 @@ {% for host in hosts %} - {{ host.host }} + {% if host.host|length > 24 %} + {{ host.host|slice(0, 23) }}… + {% else %} + {{ host.host }} + {% endif %} A B {{ host.base32 }}.b32.i2p diff --git a/templates/home.twig b/templates/home.twig index 21e0b83..a46fa68 100644 --- a/templates/home.twig +++ b/templates/home.twig @@ -42,7 +42,10 @@ + Domains that are inaccessible before the disabling date for {{ hidedays }} days, will be hidden from alive list, 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.

{% if approval %} diff --git a/templates/jump.twig b/templates/jump.twig index c724ee2..b86ccd7 100644 --- a/templates/jump.twig +++ b/templates/jump.twig @@ -1,6 +1,22 @@ {% extends "_page.twig" %} {% block title %}Jump to site{% endblock %} + +{% block head %} + {{ parent() }} + {% if autojump %} + {% if not result %} + + {% elseif result.error|length > 0 %} + {# Skipping redirect #} + {% elseif result.uri|length > 0 %} + + {% else %} + + {% endif %} + {% endif %} +{% endblock %} + {% block content %}
@@ -13,11 +29,21 @@ {% else %}

Query result for "{{ result.host }}"

+ {% if autojump %} +
+ Site is found. You will be redirected soon... +
+
+ {% endif %}
Addresshelper: - Go to site + {% if result.uri|length > 0 %} + Go to site + {% else %} + Go to site + {% endif %}
@@ -36,9 +62,31 @@ {{ result.base64 }}
+
+ + Added at: + + + {{ result.add_date }} + +
+
+ + Last seen: + + + {{ result.last_seen != '0000-00-00 00:00:00' ? result.last_seen : 'Never' }} + +
{% endif %} + {% elseif (autojump and not result) %} +
+

Error

+ Empty request, redirecting to jump page +
{% endif %} + {% if not autojump %}

Query domain @@ -51,6 +99,7 @@

+ {% endif %}
{% endblock %} diff --git a/templates/latest.twig b/templates/latest.twig index 3519335..84d0453 100644 --- a/templates/latest.twig +++ b/templates/latest.twig @@ -22,7 +22,11 @@ {% for host in hosts %} - {{ host.host }} + {% if host.host|length > 24 %} + {{ host.host|slice(0, 23) }}… + {% else %} + {{ host.host }} + {% endif %} A B {{ host.base32 }}.b32.i2p diff --git a/templates/search.twig b/templates/search.twig index 2aef5d9..4619cab 100644 --- a/templates/search.twig +++ b/templates/search.twig @@ -50,8 +50,11 @@ +
+ + +
{% endblock %} - diff --git a/views/add.php b/views/add.php index e884255..c5329e2 100644 --- a/views/add.php +++ b/views/add.php @@ -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']; } diff --git a/views/alive.php b/views/alive.php index 503ec34..89b5221 100644 --- a/views/alive.php +++ b/views/alive.php @@ -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; /* 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"]); diff --git a/views/autojump.php b/views/autojump.php new file mode 100644 index 0000000..6ba88fe --- /dev/null +++ b/views/autojump.php @@ -0,0 +1,58 @@ + __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]); diff --git a/views/home.php b/views/home.php index 026faae..bdc97bd 100644 --- a/views/home.php +++ b/views/home.php @@ -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 ); diff --git a/views/jump.php b/views/jump.php index a065335..a4c84de 100644 --- a/views/jump.php +++ b/views/jump.php @@ -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'); diff --git a/views/latest.php b/views/latest.php index be44544..f682ed7 100644 --- a/views/latest.php +++ b/views/latest.php @@ -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(); diff --git a/views/search.php b/views/search.php index 90e4c47..411a20b 100644 --- a/views/search.php +++ b/views/search.php @@ -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[ $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();