<?php
// Database connection
$dsn = "mysql:host=localhost;dbname=your_database";
$username = "your_username";
$password = "your_password";
try {
$conn = new PDO($dsn, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
// Function to get domain details from local WHOIS command
function getDomainDetails($domain) {
$whoisOutput = shell_exec("whois " . $domain);
return $whoisOutput;
}
// Function to parse WHOIS output
function parseWhois($whoisOutput) {
$domainDetails = array(
'status' => parseStatus($whoisOutput),
'registrar' => parseRegistrar($whoisOutput),
'expiration_date' => parseExpirationDate($whoisOutput),
'registration_date' => parseRegistrationDate($whoisOutput),
'transfer_lock_status' => parseTransferLockStatus($whoisOutput),
'dnssec_status' => parseDnssecStatus($whoisOutput),
'name_servers' => parseNameServers($whoisOutput),
);
return $domainDetails;
}
// Helper functions for parsing specific details using regular expressions
function parseStatus($whoisOutput) {
// Implement your status parsing logic using regular expressions
preg_match("/Status:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
function parseRegistrar($whoisOutput) {
// Implement your registrar parsing logic using regular expressions
preg_match("/Registrar:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
function parseExpirationDate($whoisOutput) {
// Implement your expiration date parsing logic using regular expressions
preg_match("/Expiration Date:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
function parseRegistrationDate($whoisOutput) {
// Implement your registration date parsing logic using regular expressions
preg_match("/Creation Date:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
function parseTransferLockStatus($whoisOutput) {
// Implement your transfer lock status parsing logic using regular expressions
preg_match("/TransferLock:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
function parseDnssecStatus($whoisOutput) {
// Implement your DNSSEC status parsing logic using regular expressions
preg_match("/DNSSEC:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
function parseNameServers($whoisOutput) {
// Implement your name servers parsing logic using regular expressions
preg_match("/Name Server:(.\*)\\n/i", $whoisOutput, $matches);
return isset($matches[1]) ? trim($matches[1]) : null;
}
// Function to insert domain details into the database
function insertDomainDetails($conn, $client_id, $domain, $domainDetails) {
$query = "INSERT INTO domain_details (client_id, domain, status, registrar, expiration_date, registration_date, transfer_lock_status, dnssec_status, name_servers)
VALUES (:client_id, :domain, :status, :registrar, :expiration_date, :registration_date, :transfer_lock_status, :dnssec_status, :name_servers)";
$stmt = $conn->prepare($query);
$stmt->bindParam(':client_id', $client_id);
$stmt->bindParam(':domain', $domain);
$stmt->bindParam(':status', $domainDetails['status']);
$stmt->bindParam(':registrar', $domainDetails['registrar']);
$stmt->bindParam(':expiration_date', $domainDetails['expiration_date']);
$stmt->bindParam(':registration_date', $domainDetails['registration_date']);
$stmt->bindParam(':transfer_lock_status', $domainDetails['transfer_lock_status']);
$stmt->bindParam(':dnssec_status', $domainDetails['dnssec_status']);
$stmt->bindParam(':name_servers', $domainDetails['name_servers']);
$stmt->execute();
}
// Example usage
$client_id = 1;
$domain = "example.com";
// Get domain details
$whoisOutput = getDomainDetails($domain);
// Parse domain details
$domainDetails = parseWhois($whoisOutput);
// Insert domain details into the database
insertDomainDetails($conn, $client_id, $domain, $domainDetails);
// Close database connection
$conn = null;
?>