Browse Source

add hidden mode (using '?all' in url)

Signed-off-by: r4sas <r4sas@i2pmail.org>
master
R4SAS 3 years ago
parent
commit
3c0385afad
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 8
      README.md
  2. 12
      public/index.php
  3. 19
      templates/_page.twig
  4. 3
      templates/add.twig
  5. 2
      templates/all.twig
  6. 48
      templates/hidden.twig
  7. 2
      templates/home.twig
  8. 3
      templates/jump.twig
  9. 3
      templates/search.twig
  10. 1
      views/404.php
  11. 6
      views/add.php
  12. 7
      views/alive.php
  13. 11
      views/all.php
  14. 42
      views/hidden.php
  15. 14
      views/home.php
  16. 6
      views/jump.php
  17. 2
      views/latest.php
  18. 8
      views/search.php

8
README.md

@ -8,7 +8,7 @@ Requirements
--- ---
* i2pd with enabled BOB protocol * i2pd with enabled BOB protocol
* `verifyhost` binary built inside i2pd-tools project folder * `verifyhost` binary built inside i2pd-tools project folder. It must be placed in `bin` directory
* PHP and php-fpm 7.2+ * PHP and php-fpm 7.2+
* php-intl package on PHP 7.4+ (php7.4-intl as example on Debian with PHP 7.4) * php-intl package on PHP 7.4+ (php7.4-intl as example on Debian with PHP 7.4)
* Composer * Composer
@ -20,9 +20,11 @@ Installation
1. Clone repository in your webserver working directory. Note: that must not be `/var/www/html` or something like this, your webserver must point to `public` directory of forked project. 1. Clone repository in your webserver working directory. Note: that must not be `/var/www/html` or something like this, your webserver must point to `public` directory of forked project.
2. Fetch requirements by runnning `composer update`. 2. Fetch requirements by runnning `composer update`.
3. Point your webserver to serving webpages from `public` directory. 3. Copy `config.php.dist` to `config.php` and conigure project for your needs
4. Create cron jobs for quering and updating hosts lists. 4. Point your webserver to serving webpages from `public` directory.
5. Create cron jobs for quering and updating hosts lists.
Configuration examples below are using /home/www/reg.i2p as website homedir. Note that files inside that directory must be owned by php user (usually it is `www-data`):
nginx configuration nginx configuration
--- ---

12
public/index.php

@ -7,11 +7,11 @@ require __DIR__ . '/../vendor/autoload.php';
/* Initialize pages rounting */ /* Initialize pages rounting */
$r = new Router(); $r = new Router();
$r->addRoute('^/$', function($url) { $r->addRoute('^/?(?:\?|$)', function($url) {
require __DIR__ . '/../views/home.php'; require __DIR__ . '/../views/home.php';
}); });
$r->addRoute('^/add/?$', function($url) { $r->addRoute('^/add/?(?:\?|$)', function($url) {
require __DIR__ . '/../views/add.php'; require __DIR__ . '/../views/add.php';
}); });
@ -23,7 +23,7 @@ $r->addRoute('^/all/?([0-9]+)?/?', function($url, $page = 1) {
require __DIR__ . '/../views/all.php'; require __DIR__ . '/../views/all.php';
}); });
$r->addRoute('^/jump/?(.*)/?', function($url, $query = "") { $r->addRoute('^/jump/?([^\?/]*)/?(?:\?|$)', function($url, $query = "") {
require __DIR__ . '/../views/jump.php'; require __DIR__ . '/../views/jump.php';
}); });
@ -35,10 +35,14 @@ $r->addRoute('^/latest/?(?:\?|$)', function($url) {
require __DIR__ . '/../views/latest.php'; require __DIR__ . '/../views/latest.php';
}); });
$r->addRoute('^/search/?(.*)/?', function($url, $query = "") { $r->addRoute('^/search/?([^\?/]*)/?(?:\?|$)', function($url, $query = "") {
require __DIR__ . '/../views/search.php'; require __DIR__ . '/../views/search.php';
}); });
$r->addRoute('^/hidden/?([0-9]+)?/?(?:\?|$)', function($url, $page = 1) {
require __DIR__ . '/../views/hidden.php';
});
$r->addErrorRoute(function() { $r->addErrorRoute(function() {
require __DIR__ . '/../views/404.php'; require __DIR__ . '/../views/404.php';
}); });

19
templates/_page.twig

@ -18,11 +18,14 @@
<header class="header"> <header class="header">
<div class="header__top"> <div class="header__top">
<div class="logo header__logo"> <div class="logo header__logo">
<a href="/" class="logo__link"> <a href="/{{ all ? "?all" }}" class="logo__link">
<img class="svg" src="/img/logo.svg" /> <img class="svg" src="/img/logo.svg" />
</a> </a>
</div> </div>
<form action="/search" method="post" class="search header__search"> <form action="/search" method="post" class="search header__search">
{% if all %}
<input type="hidden" name="all" value="true">
{% endif %}
<input type="text" name="q" class="text-input search__text-input" maxlength="67" placeholder="Search address"> <input type="text" name="q" class="text-input search__text-input" maxlength="67" placeholder="Search address">
<button type="submit" class="search__btn"> <button type="submit" class="search__btn">
<svg enable-background="new 0 0 32 32" id="search_svg" version="1.1" viewBox="0 0 32 32" width="20px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <svg enable-background="new 0 0 32 32" id="search_svg" version="1.1" viewBox="0 0 32 32" width="20px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
@ -45,39 +48,39 @@
<nav class="main-menu"> <nav class="main-menu">
<ul class="main-menu__list"> <ul class="main-menu__list">
<li class="main-menu__item"> <li class="main-menu__item">
<a href="/" class="main-menu__link"> <a href="/{{ all ? "?all" }}" class="main-menu__link">
home home
</a> </a>
</li> </li>
<li class="main-menu__item"> <li class="main-menu__item">
<a href="/add" class="main-menu__link"> <a href="/add{{ all ? "?all" }}" class="main-menu__link">
add add
</a> </a>
</li> </li>
<li class="main-menu__item"> <li class="main-menu__item">
<a href="/jump" class="main-menu__link"> <a href="/jump{{ all ? "?all" }}" class="main-menu__link">
jump jump
</a> </a>
</li> </li>
<li class="main-menu__item"> <li class="main-menu__item">
<a href="/latest" class="main-menu__link"> <a href="/latest{{ all ? "?all" }}" class="main-menu__link">
latest latest
</a> </a>
</li> </li>
<li class="main-menu__item"> <li class="main-menu__item">
<a href="/alive" class="main-menu__link"> <a href="/alive{{ all ? "?all" }}" class="main-menu__link">
alive alive
</a> </a>
</li> </li>
<li class="main-menu__item"> <li class="main-menu__item">
<a href="/all" class="main-menu__link"> <a href="/all{{ all ? "?all" }}" class="main-menu__link">
all all
</a> </a>
</li> </li>
</ul> </ul>
</nav> </nav>
<div class="logo header__mobile-logo"> <div class="logo header__mobile-logo">
<a href="/" class="logo__link"> <a href="/{{ all ? "?all" }}" class="logo__link">
<img src="/img/logo.svg" /> <img src="/img/logo.svg" />
</a> </a>
</div> </div>

3
templates/add.twig

@ -61,6 +61,9 @@
Domain adding Domain adding
</p> </p>
<form action="/add" method="post" class="adder__form"> <form action="/add" method="post" class="adder__form">
{% if all %}
<input type="hidden" name="all" value="true">
{% endif %}
<div class="form__field"> <div class="form__field">
<label for="record"> <label for="record">
<span> <span>

2
templates/all.twig

@ -23,7 +23,7 @@
{% for host in hosts %} {% for host in hosts %}
<tr class="table__row"> <tr class="table__row">
<td class="table__cell"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host }}</a></td> <td class="table__cell"><a href="http://{{ host.host }}/" rel="external nofollow noopener noreferrer" target="_blank">{{ host.host }}</a></td>
<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.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_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 }}</td> <td class="table__cell table__cell_full-b32 table__cell_long-ass">{{ host.base32 }}</td>
<td class="table__cell table__cell_date">{{ host.last_seen != '0000-00-00 00:00:00' ? host.last_seen : 'Never' }}</td> <td class="table__cell table__cell_date">{{ host.last_seen != '0000-00-00 00:00:00' ? host.last_seen : 'Never' }}</td>

48
templates/hidden.twig

@ -0,0 +1,48 @@
{% extends "_page.twig" %}
{% block title %}Alive hosts{% endblock %}
{% block content %}
<div class="container">
<div class="alive-hosts">
<p class="important title" align="center">
Hidden domains
</p>
<table class="table">
<thead class="table__head">
<tr class="table__row">
<th class="table__cell">Domain</th>
<th class="table__cell"><abbr title="Address Helper">AH</abbr></th>
<th class="table__cell"><abbr title="Base32 address">B32</abbr></th>
<th class="table__cell table__cell_full-b32">Full Base32</th>
<th class="table__cell table__cell_date">Last seen</th>
</tr>
</thead>
<tbody class="table__body">
{% for host in hosts %}
<tr class="table__row">
{% 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 }}</td>
<td class="table__cell table__cell_date">{{ host.last_seen }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if total > 1 %}
{% include "_pagination.twig" with {
total,
current,
url: "/alive/"
} only %}
{% endif %}
</div>
</div>
{% endblock %}

2
templates/home.twig

@ -73,7 +73,7 @@
<ul> <ul>
<li>Service owner is not responsible about content published on submitted domains</li> <li>Service owner is not responsible about content published on submitted domains</li>
<li>Submited domains processed automaticly. No human involved in process</li> <li>Submited domains processed automaticly. No human involved in process</li>
<li>Domains with offensive content will be hidden from the list <li>Domains with offensive content will be hidden from the list (currently hidden {% if all %}<a href="/hidden?all">{% endif %}{{ blackcnt }} domain(s){% if all %}</a>{% endif %})
<ul> <ul>
<li>they can be found using the search and jump links</li> <li>they can be found using the search and jump links</li>
<li>adding <code>?all</code> to page address (like <code>/alive?all</code>) will show them</li> <li>adding <code>?all</code> to page address (like <code>/alive?all</code>) will show them</li>

3
templates/jump.twig

@ -105,6 +105,9 @@
Query domain Query domain
</p> </p>
<form action="/jump" method="post" class="jumper__form"> <form action="/jump" method="post" class="jumper__form">
{% if all %}
<input type="hidden" name="all" value="true">
{% endif %}
<div class="form__field"> <div class="form__field">
<label for="q">Domain:</label> <label for="q">Domain:</label>
<input class="text-input jumper__text-input" type="text" id="q" name="q" maxlength="67" placeholder="domain.i2p" required> <input class="text-input jumper__text-input" type="text" id="q" name="q" maxlength="67" placeholder="domain.i2p" required>

3
templates/search.twig

@ -46,6 +46,9 @@
Search domain Search domain
</p> </p>
<form action="/search" method="post"> <form action="/search" method="post">
{% if all %}
<input type="hidden" name="all" value="true">
{% endif %}
<div class="form__field"> <div class="form__field">
<label for="q">Query:</label> <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> <input class="text-input search-page__text-input" type="text" id="q" name="q" maxlength="67" placeholder="domain.i2p" required>

1
views/404.php

@ -12,4 +12,3 @@ $twig = new \Twig\Environment($loader, [
$template = $twig->load('404.twig'); $template = $twig->load('404.twig');
echo $template->render(); echo $template->render();

6
views/add.php

@ -10,12 +10,16 @@ $twig = new \Twig\Environment($loader, [
'auto_reload' => true, 'auto_reload' => true,
]); ]);
$all = false;
$record = ""; $record = "";
$desc = ""; $desc = "";
$error = ""; $error = "";
$result = []; $result = [];
if (isset($_POST["all"]) || isset($_GET["all"]))
$all = true;
if (isset($_POST["record"]) && !empty($_POST["record"])) { if (isset($_POST["record"]) && !empty($_POST["record"])) {
$record = (string) $_POST["record"]; $record = (string) $_POST["record"];
@ -197,4 +201,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]); echo $template->render(['record' => $record, 'desc' => $desc, 'result' => $result, 'all' => $all]);

7
views/alive.php

@ -19,11 +19,10 @@ if (isset($_GET["all"]))
$all = true; $all = true;
/* Get records amount */ /* Get records amount */
$STH = $pdo->query ("SELECT COUNT(*) as `count` FROM `hosts` " . $STH = $pdo->query ("SELECT 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")); ($all ? "" : " AND `blacklisted` = 0"));
$STH->setFetchMode (PDO::FETCH_ASSOC); $records = $STH->fetchColumn();
$records = $STH->fetch()["count"];
$pages = intdiv($records, $options["tableitems"]) + 1; $pages = intdiv($records, $options["tableitems"]) + 1;
@ -36,4 +35,4 @@ $STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll(); $rows = $STH->fetchAll();
$template = $twig->load('alive.twig'); $template = $twig->load('alive.twig');
echo $template->render(['current' => $page, 'total' => $pages, 'hosts' => $rows]); echo $template->render(['current' => $page, 'total' => $pages, 'hosts' => $rows, 'all' => $all]);

11
views/all.php

@ -10,6 +10,7 @@ $twig = new \Twig\Environment($loader, [
'auto_reload' => true, 'auto_reload' => true,
]); ]);
$all = false;
$offset = $options["tableitems"] * ($page - 1); $offset = $options["tableitems"] * ($page - 1);
$newregoffs = date ("Y-m-d H:i:s", strtotime ("-7 day")); $newregoffs = date ("Y-m-d H:i:s", strtotime ("-7 day"));
$newseenlim = date ("Y-m-d H:i:s", strtotime ("-3 day")); $newseenlim = date ("Y-m-d H:i:s", strtotime ("-3 day"));
@ -17,10 +18,12 @@ $oldseenlim = date ("Y-m-d H:i:s", strtotime ("-7 day"));
$pdo = (new App\DB($options))->pdo; $pdo = (new App\DB($options))->pdo;
if (isset($_GET["all"]))
$all = true;
/* Get records amount */ /* Get records amount */
$STH = $pdo->query ("SELECT COUNT(*) as `count` FROM `hosts`"); $STH = $pdo->query ("SELECT COUNT(*) FROM `hosts`");
$STH->setFetchMode (PDO::FETCH_ASSOC); $records = $STH->fetchColumn();
$records = $STH->fetch()["count"];
$pages = intdiv($records, $options["tableitems"]) + 1; $pages = intdiv($records, $options["tableitems"]) + 1;
@ -30,4 +33,4 @@ $STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll(); $rows = $STH->fetchAll();
$template = $twig->load('all.twig'); $template = $twig->load('all.twig');
echo $template->render(['current' => $page, 'total' => $pages, 'hosts' => $rows]); echo $template->render(['current' => $page, 'total' => $pages, 'hosts' => $rows, 'all' => $all]);

42
views/hidden.php

@ -0,0 +1,42 @@
<?php
$all = false;
// Check for option before loading anything
if (isset($_GET["all"])) {
$all = true;
} else {
header("Location: /");
exit();
}
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,
]);
$offset = $options["tableitems"] * ($page - 1);
$pdo = (new App\DB($options))->pdo;
/* Get records amount */
$STH = $pdo->query ("SELECT COUNT(*) FROM `hosts` " .
"WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0 AND `blacklisted` = 1");
$records = $STH->fetchColumn();
$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 AND `blacklisted` = 1 " .
"LIMIT " . $offset . ", " . $options["tableitems"]);
$STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll();
$template = $twig->load('hidden.twig');
echo $template->render(['current' => $page, 'total' => $pages, 'hosts' => $rows, 'all' => $all]);

14
views/home.php

@ -10,16 +10,22 @@ $twig = new \Twig\Environment($loader, [
'auto_reload' => true, 'auto_reload' => true,
]); ]);
$all = false;
$pdo = (new App\DB($options))->pdo;
$subscrs = array(); $subscrs = array();
if ($options['fetcher']) { if (isset($_GET["all"]))
$pdo = (new App\DB($options))->pdo; $all = true;
if ($options['fetcher']) {
$STH = $pdo->query ("SELECT `name` FROM `subscriptions` WHERE `active` = 1"); $STH = $pdo->query ("SELECT `name` FROM `subscriptions` WHERE `active` = 1");
$STH->setFetchMode(PDO::FETCH_ASSOC); $STH->setFetchMode(PDO::FETCH_ASSOC);
$subscrs = $STH->fetchAll(); $subscrs = $STH->fetchAll();
} }
$STH = $pdo->query ("SELECT COUNT(*) FROM `hosts` WHERE `blacklisted` = 1");
$blackcnt = $STH->fetchColumn();
$vars = array( $vars = array(
'activation' => $options['approval'], 'activation' => $options['approval'],
'actdelay' => $options['approvedelay'], 'actdelay' => $options['approvedelay'],
@ -32,7 +38,9 @@ $vars = array(
'hidedays' => $options['hidedays'], 'hidedays' => $options['hidedays'],
'fullhour' => $options['fullhour'], 'fullhour' => $options['fullhour'],
'fetcher' => $options['fetcher'], 'fetcher' => $options['fetcher'],
'subscrs' => $subscrs 'subscrs' => $subscrs,
'blackcnt' => $blackcnt,
'all' => $all
); );
$template = $twig->load('home.twig'); $template = $twig->load('home.twig');

6
views/jump.php

@ -12,12 +12,16 @@ $twig = new \Twig\Environment($loader, [
$utils = new App\Utils; $utils = new App\Utils;
$all = false;
$data = ""; $data = "";
$domain = ""; $domain = "";
$uri = ""; $uri = "";
$result = []; $result = [];
$error = ""; $error = "";
if (isset($_POST["all"]) || isset($_GET["all"]))
$all = true;
// Get request data // Get request data
if (isset($query) && !empty($query)) { if (isset($query) && !empty($query)) {
$data = $query; $data = $query;
@ -61,4 +65,4 @@ else if(!empty($domain) && $utils->isValidDomain($domain, $error)) {
} }
$template = $twig->load('jump.twig'); $template = $twig->load('jump.twig');
echo $template->render(['domain' => $domain, 'result' => $result]); echo $template->render(['domain' => $domain, 'result' => $result, 'all' => $all]);

2
views/latest.php

@ -23,4 +23,4 @@ $STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll(); $rows = $STH->fetchAll();
$template = $twig->load('latest.twig'); $template = $twig->load('latest.twig');
echo $template->render(['limit' => $options["tableitems"], 'hosts' => $rows]); echo $template->render(['limit' => $options["tableitems"], 'hosts' => $rows, 'all' => $all]);

8
views/search.php

@ -15,6 +15,7 @@ $utils = new App\Utils;
$result = []; $result = [];
$q = ""; $q = "";
$a = false; $a = false;
$all = false;
if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST["q"]) > 67) { if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST["q"]) > 67) {
$result["error"] = "Request is too long, max length is 67 chars"; $result["error"] = "Request is too long, max length is 67 chars";
@ -24,10 +25,11 @@ if (isset($query) && strlen($query) > 67 || isset($_POST["q"]) && strlen($_POST[
$q = htmlspecialchars($_POST["q"]); $q = htmlspecialchars($_POST["q"]);
} }
if (isset($_POST["a"])) { if (isset($_POST["a"]))
$a = true; $a = true;
}
if (isset($_POST["all"]) || isset($_GET["all"]))
$all = true;
if(!empty($q)) { if(!empty($q)) {
$pdo = (new App\DB($options))->pdo; $pdo = (new App\DB($options))->pdo;
@ -47,4 +49,4 @@ if(!empty($q)) {
} }
$template = $twig->load('search.twig'); $template = $twig->load('search.twig');
echo $template->render(['query' => $q ?: 'removed request', 'result' => $result, 'limit' => $options["tableitems"]]); echo $template->render(['query' => $q ?: 'removed request', 'result' => $result, 'limit' => $options["tableitems"], 'all' => $all]);

Loading…
Cancel
Save