111 lines
3.7 KiB
PHP
111 lines
3.7 KiB
PHP
<?php
|
|
ini_set('display_errors', 'on');
|
|
error_reporting(-1);
|
|
|
|
require_once __DIR__ . '/whois-php/src/Whois/WhoisException.php';
|
|
require_once __DIR__ . '/whois-php/src/Whois/Servers.php';
|
|
require_once __DIR__ . '/whois-php/src/Whois/Result.php';
|
|
require_once __DIR__ . '/whois-php/src/Whois/Client.php';
|
|
|
|
define('FMWHOIS_PREFIX', 'fm:whois:domain:');
|
|
|
|
$domain = isset($_GET['domain']) && is_string($_GET['domain'])
|
|
? idn_to_ascii(mb_strtolower($_GET['domain']), IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46)
|
|
: '';
|
|
$domainHash = hash('sha256', $domain);
|
|
|
|
if(!empty($domain)) {
|
|
$redis = new Redis;
|
|
$redis->connect('/var/run/redis/redis-server.sock');
|
|
|
|
$result = $redis->get(FMWHOIS_PREFIX . $domainHash);
|
|
|
|
if($result === false) {
|
|
$whois = new Whois\Client;
|
|
|
|
try {
|
|
$result = $whois->lookup($domain);
|
|
$redis->setEx(FMWHOIS_PREFIX . $domainHash, 1800, json_encode($result));
|
|
} catch (Whois\WhoisException $ex) {
|
|
$error = $ex->getMessage();
|
|
}
|
|
} else {
|
|
$result = json_decode($result);
|
|
}
|
|
}
|
|
|
|
if(!empty($error)) {
|
|
$responseText = $error;
|
|
} elseif(!empty($result)) {
|
|
$responseText = '';
|
|
|
|
switch($result->type) {
|
|
case 'domain':
|
|
foreach($result->responses as $server => $response) {
|
|
$responseText .= "{$result->target} domain lookup results from {$server}\r\n\r\n";
|
|
$responseText .= trim($response) . "\r\n";
|
|
}
|
|
break;
|
|
|
|
case 'ip':
|
|
$responseText .= "RESULTS FOUND: " . count($result->responses);
|
|
|
|
foreach($result->responses as $server => $response) {
|
|
$responseText .= "-------------\r\n";
|
|
$responseText .= "Lookup results for {$result->target} from {$server}:\r\n\r\n";
|
|
$responseText .= trim($response) . "\r\n";
|
|
}
|
|
break;
|
|
|
|
default:
|
|
$responseText .= 'Something happened.';
|
|
break;
|
|
}
|
|
} else {
|
|
$responseText = 'Enter a domain or IP address!';
|
|
}
|
|
|
|
if(isset($_GET['ajax'])) {
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
if(!isset($result)) {
|
|
$result = new stdClass;
|
|
}
|
|
|
|
$result->responseText = $responseText;
|
|
die(json_encode($result));
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<title>flash.moe whois</title>
|
|
<link href="style.css" rel="stylesheet" type="text/css"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<div class="title">flash.moe <span style="color: #4a3650;">whois</span></div>
|
|
<div class="nav">
|
|
<a href="/">Home</a>
|
|
<!--<a href="https://github.com/flashwave/whois-php">Library</a>-->
|
|
</div>
|
|
</div>
|
|
|
|
<form class="lookup-form" method="get" action="">
|
|
<input class="lookup-form-input" type="text" name="domain" placeholder="Enter a domain or IP address to look up!" value="<?=htmlentities($domain);?>" id="lookup-input"/>
|
|
<input class="lookup-form-submit" type="submit" value="Look up" id="lookup-submit"/>
|
|
</form>
|
|
|
|
<div class="result" id="lookup-result"><?=htmlentities($responseText);?></div>
|
|
|
|
<div class="copy">
|
|
© <a href="https://flash.moe">flashwave</a> 2013-<?=date('Y');?>
|
|
</div>
|
|
</div>
|
|
<script>var whoisUrl = '<?=$_SERVER["PHP_SELF"];?>';</script>
|
|
<script src="./script.js" type="text/javascript" charset="utf-8"></script>
|
|
</body>
|
|
</html>
|