Web whois is done

This commit is contained in:
Pinga 2023-11-15 18:17:34 +02:00
parent 41fab9ab91
commit 1add432b9f
4 changed files with 83 additions and 116 deletions

View file

@ -1,39 +0,0 @@
<?php
require 'vendor/autoload.php';
use Gregwar\Captcha\PhraseBuilder;
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_POST['domain']) || !isset($_POST['captcha'])) {
echo json_encode(['error' => 'Invalid request.']);
exit;
}
if (PhraseBuilder::comparePhrases($_SESSION['captcha'], $_POST['captcha'])) {
echo json_encode(['error' => 'Incorrect Captcha.']);
exit;
}
$domain = $_POST['domain'];
$whoisServer = 'whois.example.com';
$output = '';
$socket = fsockopen($whoisServer, 43, $errno, $errstr, 30);
if (!$socket) {
echo json_encode(['error' => "Error connecting to the Whois server."]);
exit;
}
fwrite($socket, $domain . "\r\n");
while (!feof($socket)) {
$output .= fgets($socket);
}
fclose($socket);
echo json_encode(['result' => nl2br(htmlspecialchars($output))]);
} else {
echo json_encode(['error' => 'Invalid request method.']);
}

View file

@ -1,61 +1,65 @@
<?php
require 'vendor/autoload.php';
use Gregwar\Captcha\CaptchaBuilder;
$builder = new CaptchaBuilder();
$builder->build();
session_start();
$_SESSION['captcha'] = $builder->getPhrase();
use Gregwar\Captcha\CaptchaBuilder;
// Include this part only if the script is requested as an image (for the captcha)
if ($_SERVER['REQUEST_URI'] == '/captcha.php') {
require 'vendor/autoload.php'; // Adjust path as needed
$captcha = new CaptchaBuilder;
$captcha->build();
$_SESSION['captcha'] = $captcha->getPhrase();
header('Content-type: image/jpeg');
$captcha->output();
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Whois Check</title>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
<script src="script.js"></script>
<style>
.row {
display: flex;
align-items: center;
}
.domain-input {
width: 45%;
}
.captcha-input {
width: 35%;
margin-left:10px;
}
.captcha-container {
display: flex;
align-items: center;
}
</style>
<title>WHOIS Lookup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.min.css">
</head>
<body>
<div class="container">
<h1 class="text-center">Whois Check</h1>
<form id="whoisForm">
<div class="row">
<div class="domain-input">
<label for="domain">Domain</label>
<input type="text" id="domain" name="domain" placeholder="example.com" required>
</div>
<div class="captcha-input">
<label for="captcha">Captcha</label>
<div class="captcha-container">
<input type="text" id="captcha" name="captcha" required>
<img src="<?php echo $builder->inline(); ?>" id="captchaImage" style="margin-left:10px;">
</div>
</div>
</div>
<button type="submit" class="button-primary">Check Whois</button>
</form>
<div id="result" class="mt-4"></div>
<h1>WHOIS Lookup</h1>
<div class="row">
<input type="text" id="domainInput" placeholder="Enter Domain Name" autocapitalize="none">
<img id="captchaImg" src="captcha.php" onclick="this.src='captcha.php?'+Math.random();">
<input type="text" id="captchaInput" placeholder="Enter Captcha" autocapitalize="none">
<button id="whoisButton">WHOIS</button>
</div>
<div id="result"></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('whoisButton').addEventListener('click', function() {
var domain = document.getElementById('domainInput').value;
var captcha = document.getElementById('captchaInput').value;
fetch('whois.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'domain=' + encodeURIComponent(domain) + '&captcha=' + encodeURIComponent(captcha)
})
.then(response => response.text())
.then(data => {
document.getElementById('result').innerText = data;
// Reload captcha after a successful response
document.getElementById('captchaImg').src = 'captcha.php?' + Math.random();
})
.catch(error => console.error('Error:', error));
});
});
</script>
</body>
</html>

View file

@ -1,31 +0,0 @@
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("whoisForm").addEventListener("submit", function(e) {
e.preventDefault();
var xhr = new XMLHttpRequest();
var formData = new FormData(this);
xhr.open("POST", "checkWhois.php", true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var resultDiv = document.getElementById("result");
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (data.error) {
resultDiv.innerHTML = '<div class="alert alert-danger">' + data.error + '</div>';
} else {
resultDiv.innerHTML = '<div class="alert alert-success">' + data.result + '</div>';
}
} else {
resultDiv.innerHTML = '<div class="alert alert-danger">An error occurred. Please try again.</div>';
}
}
};
xhr.onloadstart = function() {
document.getElementById("result").innerHTML = '<div class="loading">Loading...</div>';
};
xhr.send(formData);
});
});

33
whois/web/whois.php Normal file
View file

@ -0,0 +1,33 @@
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['error' => 'Invalid request method.']);
exit;
}
if ($_POST['captcha'] !== $_SESSION['captcha']) {
die('Captcha verification failed');
}
$domain = $_POST['domain'];
$whoisServer = 'ENTER_WHOIS_IP_HERE';
$output = '';
$socket = fsockopen($whoisServer, 43, $errno, $errstr, 30);
if (!$socket) {
echo json_encode(['error' => "Error connecting to the Whois server."]);
exit;
}
fwrite($socket, $domain . "\r\n");
while (!feof($socket)) {
$output .= fgets($socket);
}
fclose($socket);
// Invalidate the current captcha
unset($_SESSION['captcha']);
echo $output;