mirror of
https://github.com/PurpleI2P/regi2p.git
synced 2025-02-05 14:04:20 +00:00
add API status command, add information
Signed-off-by: r4sas <r4sas@i2pmail.org>
This commit is contained in:
parent
67655b7501
commit
0b161dd417
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Info:</b><br>
|
<b>Info:</b><br>
|
||||||
Service is Up. Hosts check is done every hour.<br>
|
Hosts check is done every hour.<br>
|
||||||
Supported commands:
|
Supported commands:
|
||||||
<ul>
|
<ul>
|
||||||
<li>adding of hosts for 2LD domains (example.i2p)</li>
|
<li>adding of hosts for 2LD domains (example.i2p)</li>
|
||||||
@ -68,6 +68,21 @@
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>API:</b><br>
|
||||||
|
Service providing minimal JSON API for requesting information about domains in our base.<br>
|
||||||
|
<pre><i>/api/<command>/[query]</i><br></pre>
|
||||||
|
<ul>
|
||||||
|
<li><i>command</i> - required field, possible values:
|
||||||
|
<ul>
|
||||||
|
<li><i>all</i> returns all alive domains b32 and last seen timestamp</li>
|
||||||
|
<li><i>status</i> returns base64, base32 and last seen timestamp for requested domain</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><i>query</i> - domain for <i>status</i> query
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Terms of use:</b>
|
<b>Terms of use:</b>
|
||||||
<ul>
|
<ul>
|
||||||
@ -76,7 +91,7 @@
|
|||||||
<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 %})
|
<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 <i>?all</i> to page address (like <i>/alive?all</i>) will show them</li>
|
||||||
<li>such domains won't be exported to subscriptions</li>
|
<li>such domains won't be exported to subscriptions</li>
|
||||||
<li>if you disagree with some eepsite's content - we won't do anything, only specific categories might be hidden</li>
|
<li>if you disagree with some eepsite's content - we won't do anything, only specific categories might be hidden</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
require_once __DIR__ . '/../config.php';
|
require_once __DIR__ . '/../config.php';
|
||||||
|
|
||||||
$all = false;
|
$all = false;
|
||||||
|
$data = [];
|
||||||
|
|
||||||
$pdo = (new App\DB($options))->pdo;
|
$pdo = (new App\DB($options))->pdo;
|
||||||
|
|
||||||
@ -11,20 +12,39 @@ header('Content-Type: application/json');
|
|||||||
if (isset($_GET["all"]))
|
if (isset($_GET["all"]))
|
||||||
$all = true;
|
$all = true;
|
||||||
|
|
||||||
if(!$command || !in_array($command, ['all', 'status']))
|
switch ($command) {
|
||||||
exit(json_encode(["status" => "error", "message" => "Incorrect request"]));
|
case "all":
|
||||||
|
$STH = $pdo->query ("SELECT `base32`, UNIX_TIMESTAMP(`last_seen`) as `last_seen` FROM `hosts` " .
|
||||||
|
"WHERE `approved` = 1 AND `disabled` = 0" .
|
||||||
|
($all ? " " : " AND `blacklisted` = 0 "));
|
||||||
|
$STH->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
|
$rows = $STH->fetchAll();
|
||||||
|
|
||||||
if($command == "all") {
|
foreach($rows as $row) {
|
||||||
$STH = $pdo->query ("SELECT `base32`, UNIX_TIMESTAMP(`last_seen`) as `last_seen` FROM `hosts` " .
|
$data[$row["base32"] . ".b32.i2p"] = $row["last_seen"];
|
||||||
"WHERE `approved` = 1 AND `disabled` = 0" .
|
}
|
||||||
($all ? " " : " AND `blacklisted` = 0 "));
|
break;
|
||||||
$STH->setFetchMode(PDO::FETCH_ASSOC);
|
case "status":
|
||||||
$rows = $STH->fetchAll();
|
if (!$query || empty($query)) {
|
||||||
|
$data = array_merge($data, ["status" => "error", "message" => "Empty query"]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$q = htmlspecialchars($query);
|
||||||
|
|
||||||
$data = [];
|
$STH = $pdo->query("SELECT `host` AS `hostname`, `base64`, `base32`, UNIX_TIMESTAMP(`last_seen`) as `last_seen` FROM `hosts` WHERE `host` = '" . $q . "' LIMIT 1");
|
||||||
foreach($rows as $row) {
|
$row = $STH->fetch(PDO::FETCH_ASSOC);
|
||||||
$data[$row["base32"] . ".b32.i2p"] = $row["last_seen"];
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(json_encode($data, JSON_PRETTY_PRINT));
|
if (empty($row)) {
|
||||||
|
$data = array_merge($data, ["status" => "error", "message" => "Not found"]);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if ($row["last_seen"] == "0000-00-00 00:00:00") $row["last_seen"] = "Never";
|
||||||
|
$row["base32"] .= ".b32.i2p";
|
||||||
|
$data = array_merge($data, $row);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$data = array_merge($data, ["status" => "error", "message" => "Incorrect request"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit(json_encode($data, JSON_PRETTY_PRINT));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user