Web lookup (whois and rdap) now completed

This commit is contained in:
Pinga 2023-12-28 20:20:19 +02:00
parent 8a6d8630ed
commit 69a670b4b1
6 changed files with 54 additions and 26 deletions

View file

@ -294,23 +294,18 @@ This command will install the dependencies defined in your ```composer.json``` f
5. Remove the Script: Once verified, delete the script to maintain system security.
## 8. Setup Web WHOIS:
## 8. Setup Web Lookup:
```bash
mkdir -p /var/www/whois
cd /opt/registry/whois/web
cp -r * /var/www/whois
```
Change your working directory to ```/var/www/whois/``` using a command line interface. This can be done with the command ```cd /var/www/whois/```.
Once in the correct directory, run the following command to install necessary dependencies:
```bash
cd /var/www/whois/
composer require gregwar/captcha
mv config.php.dist config.php
```
This command will install the **gregwar/captcha** package, which is required for the WHOIS web interface functionality.
- Configure all options in ```config.php```.
## 9. Setup WHOIS:

View file

@ -5,7 +5,14 @@ use Gregwar\Captcha\CaptchaBuilder;
require 'vendor/autoload.php';
$captcha = new CaptchaBuilder;
$captcha->build();
//$captcha->setBackgroundColor(255, 255, 255);
$captcha->setMaxAngle(25);
//$captcha->setMaxBehindLines(0);
//$captcha->setMaxFrontLines(0);
$captcha->setTextColor(0, 0, 0);
$captcha->setInterpolation(false);
$captcha->setDistortion(false);
$captcha->build($width = 100, $height = 40);
$_SESSION['captcha'] = $captcha->getPhrase();

View file

@ -1,5 +1,6 @@
<?php
session_start();
$c = require_once 'config.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['error' => 'Invalid request method.']);
@ -7,20 +8,31 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
}
if ($_POST['captcha'] !== $_SESSION['captcha']) {
die('Captcha verification failed');
echo json_encode(['error' => 'Captcha verification failed.']);
exit;
}
$domain = $_POST['domain'];
$type = $_POST['type'];
$whoisServer = 'whois.example.com';
$rdapServer = 'https://rdap.example.com/domain/';
$whoisServer = $c['whois_url'];
$rdapServer = 'https://' . $c['rdap_url'] . '/domain/';
$sanitized_domain = filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
if ($sanitized_domain) {
$domain = $sanitized_domain;
} else {
echo json_encode(['error' => 'Invalid domain.']);
exit;
}
$sanitized_type = filter_var($type, FILTER_SANITIZE_STRING);
if ($sanitized_type === 'whois' || $sanitized_type === 'rdap') {
$type = $sanitized_type;
} else {
$type = null; // or throw new Exception("Invalid input");
echo json_encode(['error' => 'Invalid input.']);
exit;
}
if ($type === 'whois') {
@ -28,7 +40,7 @@ if ($type === 'whois') {
$socket = fsockopen($whoisServer, 43, $errno, $errstr, 30);
if (!$socket) {
echo json_encode(['error' => "Error connecting to the Whois server."]);
echo json_encode(['error' => "Error fetching WHOIS data."]);
exit;
}
@ -43,11 +55,9 @@ if ($type === 'whois') {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Execute cURL session and close it
$output = curl_exec($ch);
curl_close($ch);
// Check for errors
if (!$output) {
echo json_encode(['error' => 'Error fetching RDAP data.']);
exit;

3
whois/web/chota.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,6 @@
<?php
return [
'whois_url' => 'whois.example.com',
'rdap_url' => 'rdap.example.com'
];

View file

@ -7,20 +7,25 @@ session_start();
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Domain Lookup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.min.css">
<link rel="stylesheet" href="chota.min.css">
<style>
#bottom {
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Domain Lookup</h1>
<div class="row">
<div class="column"><input type="text" id="domainInput" placeholder="Enter Domain Name" autocapitalize="none"></div>
<div class="column"><img id="captchaImg" src="captcha.php" onclick="this.src='captcha.php?'+Math.random();"></div>
<div class="column"><input type="text" id="captchaInput" placeholder="Enter Captcha" autocapitalize="none"></div>
<div class="column"><button class="button" id="whoisButton">WHOIS</button> <button class="button button-outline" id="rdapButton">RDAP</button></div>
<div class="col col-4-md col-8-lg"><input type="text" id="domainInput" placeholder="Enter Domain Name" autocapitalize="none"></div>
<div class="col col-2-md col-4-lg"><img id="captchaImg" src="captcha.php" onclick="this.src='captcha.php?'+Math.random();"></div>
<div class="col col-3-md col-6-lg"><input type="text" id="captchaInput" placeholder="Enter Captcha" autocapitalize="none"></div>
<div class="col col-3-md col-6-lg"><button class="button primary" id="whoisButton">WHOIS</button> <button class="button secondary" id="rdapButton">RDAP</button></div>
</div>
<div class="row">
<div class="column"><pre><code><div id="result"></div></code></pre></div>
<div class="row" id="bottom">
<div class="col col-12-lg"><pre><code><div id="result"></div></code></pre></div>
</div>
</div>
@ -41,6 +46,7 @@ session_start();
.then(response => response.text())
.then(data => {
document.getElementById('result').innerText = data;
document.getElementById('bottom').style.display = 'block';
// Reload captcha after a successful response
document.getElementById('captchaImg').src = 'captcha.php?' + Math.random();
})
@ -67,9 +73,10 @@ session_start();
// Parse and display RDAP data
let output = parseRdapResponse(data);
document.getElementById('result').innerText = output;
document.getElementById('bottom').style.display = 'block';
// Reload captcha
document.getElementById('captchaImg').src = 'captcha.php?' + Math.random();
}
// Reload captcha
document.getElementById('captchaImg').src = 'captcha.php?' + Math.random();
})
.catch(error => console.error('Error:', error));
});