mirror of https://github.com/PurpleI2P/regi2p.git
R4SAS
3 years ago
18 changed files with 212 additions and 45 deletions
@ -0,0 +1,58 @@ |
|||||||
|
<?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; |
||||||
|
|
||||||
|
$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]); |
Loading…
Reference in new issue