Domain registry project http://reg.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 lines
1.6 KiB

<?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;
$data = "";
$domain = "";
$uri = "";
$result = [];
$error = "";
// 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`, `add_date`, `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(['domain' => $domain, 'result' => $result]);