diff --git a/export.php b/export.php index bd6c0de..777dcb0 100644 --- a/export.php +++ b/export.php @@ -8,7 +8,7 @@ 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`, `hidden` FROM hosts"); +$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `approved`, `initial`, `disabled`, `hidden`, `blacklisted` FROM hosts"); $hosts = $STH->fetchAll(PDO::FETCH_ASSOC); $curr_time = time(); @@ -41,7 +41,7 @@ foreach ($hosts as $host) array_push($export_full, $domain . "=" . $host["base64"]); array_push($export_addr_full, $domain . "," . $host["base32"]); - if (($options["approval"] == false || $host["approved"] == 1) && $host["hidden"] == 0 && $host["disabled"] == 0) + if (($options["approval"] == false || $host["approved"] == 1) && $host["hidden"] == 0 && $host["disabled"] == 0 && $host["blacklisted"] == 0) { if (($last_seen + $hideoffs) > $curr_time) { array_push($export_live, $domain . "=" . $host["base64"]); diff --git a/fetch.php b/fetch.php index 3a752f1..1d856f5 100644 --- a/fetch.php +++ b/fetch.php @@ -22,7 +22,7 @@ $STH = $pdo->query ("SELECT `name`, `url`, `modified`, `etag` FROM `subscription $lists = $STH->fetchAll(PDO::FETCH_ASSOC); foreach ($lists as $list) { - echo "Processing " . $list['name'] . " subscription..."; + echo "Processing " . $list['name'] . " subscription... "; if (!empty($list['modified'])) $aContext['http']['header'] = 'If-Modified-Since: ' . $list['modified'] . '\r\n'; @@ -37,7 +37,7 @@ foreach ($lists as $list) { $f_meta = stream_get_meta_data($f); if (strpos($f_meta['wrapper_data'][0], "200") === false) { - echo " no changes." . PHP_EOL; + echo "no changes (" . $f_meta['wrapper_data'][0]. ")" . PHP_EOL; continue; } @@ -45,13 +45,16 @@ foreach ($lists as $list) { $etag = $util->getResponseHeader("Etag", $f_meta['wrapper_data']); if (!empty($lastmod) || !empty($etag)) { - $pdo->exec("UPDATE `subscriptions` SET " . (!empty($lastmod) ? ("`modified` = '" . $lastmod . "' ") : "") . (!empty($etag) ? ("`etag` = '" . $etag . "' ") : "") . "WHERE `name` = '" . $list['name'] . "'"); + $pdo->exec("UPDATE `subscriptions` SET" . (!empty($lastmod) ? (" `modified` = '" . $lastmod . "'") : "") . (!empty($etag) ? ((!empty($lastmod) ? "," : "") . " `etag` = '" . $etag . "'") : "") . " WHERE `name` = '" . $list['name'] . "'"); } // reset line - echo " fetching updated list." . PHP_EOL; + echo "fetching updated list." . PHP_EOL; while (($buffer = fgets($f, 4096)) !== false) { + if (substr($buffer, 0, 1) === "#") + continue; + $domain = ""; $record = $util->parseHostRecord($buffer); @@ -69,6 +72,7 @@ foreach ($lists as $list) { } if (!$util->isValidBase64($record['b64'])) { + echo "Error while validating " . $record['host'] . ": invalid or unsupported base64 (len: " . strlen($record['b64']) . ")" . PHP_EOL; continue; } @@ -91,7 +95,7 @@ foreach ($lists as $list) { continue; } - if(isset($record['commands']) && !$pdo->query("SELECT COUNT(*) FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1")->fetchColumn()) { + if(!$pdo->query("SELECT COUNT(*) FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1")->fetchColumn()) { $base32 = $util->b32from64($record['b64']); $pdo->exec("INSERT INTO `hosts` (`host`, `base64`, `base32`, `approved`) VALUES ('" . $domain . "', '" . $record["b64"] . "', '" . $base32 . "', 1)"); diff --git a/lib/utils.php b/lib/utils.php index 7b9d946..0d53477 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -153,15 +153,33 @@ class Utils { { $len = strlen($data); - if($len < 5 || $len > 255) // rfc2181, section 11 + if($len < 5 || $len > 255) // 255 max: rfc2181, section 11 { $result = "Domain must be longer than 5 and lesser than 255 chars."; return false; } - if(preg_match('/\.b32\.i2p$/', $data)) + if(preg_match('/(?:^b32|\.b32)\.i2p$/', $data)) { - $result = "Domain can't end with .b32.i2p."; + $result = "Domain can't be b32.i2p or end with .b32.i2p."; + return false; + } + + if(preg_match('/(?:^console|\.console)\.i2p$/', $data)) + { + $result = "Domain can't be console.i2p or end with .console.i2p."; + return false; + } + + if(preg_match('/(?:^proxy|\.proxy)\.i2p$/', $data)) + { + $result = "Domain can't be proxy.i2p or end with .proxy.i2p."; + return false; + } + + if(preg_match('/(?:^router|\.router)\.i2p$/', $data)) + { + $result = "Domain can't be router.i2p or end with .router.i2p."; return false; } diff --git a/public/css/style.css b/public/css/style.css index 952d5a1..c411114 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -35,6 +35,12 @@ main { margin-bottom: 5px; } +.container_main li ul { + padding-left: 22px; + margin-bottom: unset; + margin-top: 5px; +} + .container_main b { font-size: 18px; margin-bottom: 5px; @@ -187,6 +193,7 @@ abbr { flex-flow: row nowrap; align-items: stretch; justify-content: space-between; + background: #c1c1c1; } .main-menu__item { @@ -368,10 +375,6 @@ abbr { color: #ddddff; } -.table__row td:last-of-type { - white-space: nowrap; -} - .table__cell { padding: 8px; } @@ -381,6 +384,16 @@ abbr { font-weight: bold; } +.table__cell_date { + white-space: nowrap; + max-width: 225px; + text-align: center; +} + +.table__cell_full-b32 { + user-select: all; +} + .pagination { margin-top: 40px; display: flex; @@ -596,6 +609,7 @@ abbr { flex-flow: column nowrap; align-items: stretch; justify-content: flex-start; + background: unset; } .main-menu__item { @@ -628,10 +642,6 @@ abbr { min-width: 48px; } - .table__cell_full-b32 { - display: none; - } - .text-input { padding: 0 6px; font-size: 16px; @@ -658,4 +668,14 @@ abbr { .main-menu__item { min-width: 45vw; } + + .table__cell_date { + white-space: unset; + } +} + +@media screen and (max-width: 530px) { + .table__cell_full-b32 { + display: none; + } } diff --git a/public/index.php b/public/index.php index 503cf55..1ce51df 100644 --- a/public/index.php +++ b/public/index.php @@ -15,7 +15,7 @@ $r->addRoute('^/add/?$', function($url) { require __DIR__ . '/../views/add.php'; }); -$r->addRoute('^/alive/?([0-9]+)?/?', function($url, $page = 1) { +$r->addRoute('^/alive/?([0-9]+)?/?(?:\?|$)', function($url, $page = 1) { require __DIR__ . '/../views/alive.php'; }); @@ -31,7 +31,7 @@ $r->addRoute('^/autojump/?(.*)/?', function($url, $query = "") { require __DIR__ . '/../views/autojump.php'; }); -$r->addRoute('^/latest/?$', function($url) { +$r->addRoute('^/latest/?(?:\?|$)', function($url) { require __DIR__ . '/../views/latest.php'; }); diff --git a/templates/_page.twig b/templates/_page.twig index 6bbb57f..26bfd8f 100644 --- a/templates/_page.twig +++ b/templates/_page.twig @@ -15,7 +15,6 @@ {% endblock %} -
- {% endif %} {% endblock %} diff --git a/templates/jump.twig b/templates/jump.twig index b86ccd7..f3b4ff6 100644 --- a/templates/jump.twig +++ b/templates/jump.twig @@ -7,7 +7,7 @@ {% if autojump %} {% if not result %} - {% elseif result.error|length > 0 %} + {% elseif result.error|length > 0 or result.blacklisted == 1 %} {# Skipping redirect #} {% elseif result.uri|length > 0 %} @@ -30,10 +30,23 @@

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

{% if autojump %} + {% if result.blacklisted == 1 %} +
+ Site is found, but autoredirect is disabled because site marked as offensive. Press link below to continue anyway. +
+
+ {% else %}
Site is found. You will be redirected soon...

+ {% endif %} + {% endif %} + {% if not autojump and result.blacklisted == 1 %} +
+ Note: site marked as offensive. Press link below to continue anyway. +
+
{% endif %}
diff --git a/templates/latest.twig b/templates/latest.twig index ac0dc62..b6c07e0 100644 --- a/templates/latest.twig +++ b/templates/latest.twig @@ -16,7 +16,7 @@ AH B32 Full Base32 - Added + Added @@ -29,8 +29,8 @@ {% endif %} A B - {{ host.base32 }}.b32.i2p - {{ host.add_date }} + {{ host.base32 }} + {{ host.add_date }} {% endfor %} diff --git a/templates/search.twig b/templates/search.twig index 4619cab..3818132 100644 --- a/templates/search.twig +++ b/templates/search.twig @@ -24,7 +24,7 @@ AH B32 Full Base32 - Last seen + Last seen @@ -33,8 +33,8 @@ {{ host.host }} A B - {{ host.base32 }}.b32.i2p - {{ host.last_seen != '0000-00-00 00:00:00' ? host.last_seen : 'Never' }} + {{ host.base32 }} + {{ host.last_seen != '0000-00-00 00:00:00' ? host.last_seen : 'Never' }} {% endfor %} diff --git a/views/alive.php b/views/alive.php index c85d729..f1ed3b2 100644 --- a/views/alive.php +++ b/views/alive.php @@ -10,13 +10,18 @@ $twig = new \Twig\Environment($loader, [ 'auto_reload' => true, ]); +$all = false; $offset = $options["tableitems"] * ($page - 1); $pdo = (new App\DB($options))->pdo; +if (isset($_GET["all"])) + $all = true; + /* Get records amount */ $STH = $pdo->query ("SELECT COUNT(*) as `count` FROM `hosts` " . - "WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0"); + "WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0" . + ($all ? "" : " AND `blacklisted` = 0")); $STH->setFetchMode (PDO::FETCH_ASSOC); $records = $STH->fetch()["count"]; @@ -24,7 +29,8 @@ $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 `disabled` = 0 AND `hidden` = 0 " . + "WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0" . + ($all ? " " : " AND `blacklisted` = 0 ") . "LIMIT " . $offset . ", " . $options["tableitems"]); $STH->setFetchMode(PDO::FETCH_ASSOC); $rows = $STH->fetchAll(); diff --git a/views/autojump.php b/views/autojump.php index 6ba88fe..f75f940 100644 --- a/views/autojump.php +++ b/views/autojump.php @@ -40,7 +40,7 @@ else if(!empty($domain) && $utils->isValidDomain($domain, $error)) { $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`, `last_seen`, `blacklisted` FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1"); $STH->setFetchMode(PDO::FETCH_ASSOC); $row = $STH->fetchAll(); diff --git a/views/home.php b/views/home.php index ecb35a4..cb93919 100644 --- a/views/home.php +++ b/views/home.php @@ -21,13 +21,13 @@ if ($options['fetcher']) { } $vars = array( - 'approval' => $options['approval'], - 'apprdelay' => $options['approvedelay'], - 'apprseen' => $options['approveseen'], + 'activation' => $options['approval'], + 'actdelay' => $options['approvedelay'], + 'actseen' => $options['approveseen'], 'newdays' => $options['newdays'], 'olddays' => $options['olddays'], 'delnewdays' => $options['delnewdays'], - 'delapprdays' => $options['delapprdays'], + 'delactdays' => $options['delapprdays'], 'delstabdays' => $options['delstabdays'], 'hidedays' => $options['hidedays'], 'fullhour' => $options['fullhour'], diff --git a/views/jump.php b/views/jump.php index a4c84de..561ee22 100644 --- a/views/jump.php +++ b/views/jump.php @@ -46,7 +46,7 @@ else if(!empty($domain) && $utils->isValidDomain($domain, $error)) { $pdo = (new App\DB($options))->pdo; - $STH = $pdo->query("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen` FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1"); + $STH = $pdo->query("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen`, `blacklisted` FROM `hosts` WHERE `host` = '" . $domain . "' LIMIT 1"); $STH->setFetchMode(PDO::FETCH_ASSOC); $row = $STH->fetchAll(); diff --git a/views/latest.php b/views/latest.php index 0c1d77d..01e2cbb 100644 --- a/views/latest.php +++ b/views/latest.php @@ -10,10 +10,15 @@ $twig = new \Twig\Environment($loader, [ 'auto_reload' => true, ]); +$all = false; + $pdo = (new App\DB($options))->pdo; +if (isset($_GET["all"])) + $all = true; + /* Get records with limit */ -$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen` FROM `hosts` WHERE `disabled` = 0 ORDER BY `add_date` DESC LIMIT " . $options["tableitems"]); +$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `add_date`, `last_seen` FROM `hosts` WHERE `disabled` = 0" . ($all ? "" : " AND `blacklisted` = 0") . " ORDER BY `add_date` DESC LIMIT " . $options["tableitems"]); $STH->setFetchMode(PDO::FETCH_ASSOC); $rows = $STH->fetchAll();