This commit is contained in:
deepend 2024-01-11 01:48:17 -07:00
parent cf586bee39
commit a70d65a560
1 changed files with 142 additions and 130 deletions

View File

@ -1,131 +1,143 @@
<?php <?php
require_once 'initdb.php'; require_once 'initdb.php';
session_start(); session_start();
// Logout handling // Logout handling
if (isset($_GET['action']) && $_GET['action'] == 'logout') { if (isset($_GET['action']) && $_GET['action'] == 'logout') {
session_destroy(); session_destroy();
header('Location: /'); header('Location: /');
exit; exit;
} }
// Function to get DNS server information from BIND files // Function to get DNS server information from BIND files
function getDnsServersInfo() { function getDnsServersInfo() {
$masterFile = '../dottilde/db.master.tilde'; $masterFile = '../dottilde/db.master.tilde';
$servers = []; $servers = [];
$nsFilter = ['ns1', 'ns2', 'ns3']; // Add more nameserver identifiers as needed $nsFilter = ['ns1', 'ns2', 'ns3']; // Add more nameserver identifiers as needed
// Manually assigned geographical areas for each nameserver // Manually assigned geographical areas for each nameserver
$nsGeographicalAreas = [ $nsGeographicalAreas = [
'ns1' => 'Quebec, Canada', // Replace with actual locations 'ns1' => 'Quebec, Canada', // Replace with actual locations
'ns2' => 'Frankfurt, Germany', 'ns2' => 'Frankfurt, Germany',
'ns3' => 'Sydney, Australia', 'ns3' => 'Sydney, Australia',
// Add more as needed // Add more as needed
]; ];
if (file_exists($masterFile)) { if (file_exists($masterFile)) {
$content = file_get_contents($masterFile); $content = file_get_contents($masterFile);
// Regex to match A records (IPv4) // Regex to match A records (IPv4)
preg_match_all('/(\S+)\s+IN\s+A\s+(\S+)/', $content, $aMatches); preg_match_all('/(\S+)\s+IN\s+A\s+(\S+)/', $content, $aMatches);
// Regex to match AAAA records (IPv6) // Regex to match AAAA records (IPv6)
preg_match_all('/(\S+)\s+IN\s+AAAA\s+(\S+)/', $content, $aaaaMatches); preg_match_all('/(\S+)\s+IN\s+AAAA\s+(\S+)/', $content, $aaaaMatches);
$ipv4Records = array_combine($aMatches[1], $aMatches[2]); $ipv4Records = array_combine($aMatches[1], $aMatches[2]);
$ipv6Records = array_combine($aaaaMatches[1], $aaaaMatches[2]); $ipv6Records = array_combine($aaaaMatches[1], $aaaaMatches[2]);
foreach ($nsFilter as $nsName) { foreach ($nsFilter as $nsName) {
$ipv4 = isset($ipv4Records[$nsName]) ? $ipv4Records[$nsName] : 'IPv4 not found'; $ipv4 = isset($ipv4Records[$nsName]) ? $ipv4Records[$nsName] : 'IPv4 not found';
$ipv6 = isset($ipv6Records[$nsName]) ? $ipv6Records[$nsName] : 'IPv6 not found'; $ipv6 = isset($ipv6Records[$nsName]) ? $ipv6Records[$nsName] : 'IPv6 not found';
$geographicalArea = isset($nsGeographicalAreas[$nsName]) ? $nsGeographicalAreas[$nsName] : 'Unknown Location'; $geographicalArea = isset($nsGeographicalAreas[$nsName]) ? $nsGeographicalAreas[$nsName] : 'Unknown Location';
$servers[] = [ $servers[] = [
'hostname' => $nsName, 'hostname' => $nsName,
'ipv4' => $ipv4, 'ipv4' => $ipv4,
'ipv6' => $ipv6, 'ipv6' => $ipv6,
'location' => $geographicalArea 'location' => $geographicalArea
]; ];
} }
} }
return $servers; return $servers;
} }
$dnsServers = getDnsServersInfo(); $dnsServers = getDnsServersInfo();
// Function to check server status // Function to check server status
function checkServerStatus($server) { //function checkServerStatus($server) {
// Ping command varies depending on the operating system // Ping command varies depending on the operating system
// This is an example for a Unix-like system // This is an example for a Unix-like system
$output = []; // $output = [];
$status = null; // $status = null;
exec("ping -c 1 " . escapeshellarg($server), $output, $status); // exec("ping -c 1 -W 5000 " . escapeshellarg($server), $output, $status);
//
return $status === 0 ? "Online" : "Offline"; // return $status === 0 ? "Online" : "Offline";
} //}
function checkServerStatus($server) {
?> $port = 53; // DNS port, change if necessary
$timeout = 5; // Timeout in seconds
<!DOCTYPE html>
<html lang="en"> $fp = @fsockopen($server, $port, $errno, $errstr, $timeout);
<head>
<meta charset="UTF-8"> if ($fp) {
<title>|--===TildeNIC ===--| Bringing .tilde to the Tildeverse!</title> fclose($fp);
<link rel="stylesheet" href="css/styles.css"> return "Online";
</head> } else {
<body> return "Offline";
<header> }
<nav> }
<?php if (!isset($_SESSION['username'])): ?> ?>
<a href="/?page=login">Login</a> |
<a href="/?page=register">Register</a> <!DOCTYPE html>
<?php else: ?> <html lang="en">
<a href="/?page=main">Home</a> | <head>
<a href="/?page=user_domains">My Account</a> | <meta charset="UTF-8">
<a href="/?page=domain_register">Register Domain</a> | <title>|--===TildeNIC ===--| Bringing .tilde to the Tildeverse!</title>
<a href="/?page=main&action=logout">Logout</a><br><br> <link rel="stylesheet" href="css/styles.css">
<span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span> </head>
<?php endif; ?> <body>
</nav> <header>
</header> <nav>
<?php if (!isset($_SESSION['username'])): ?>
<div class="content"> <a href="/?page=login">Login</a> |
<h1>Welcome to TildeNIC</h1> <a href="/?page=register">Register</a>
<div class="info-section"> <?php else: ?>
<p>TildeNIC is where you can request your .tilde top level domain. To do so, you need to first change your DNS over to one of the resolvers we offer, or you can self-host one.</p> <a href="/?page=main">Home</a> |
<ul> <a href="/?page=user_domains">My Account</a> |
<li><a href="https://tildegit.org/tildenic/.tilde/wiki/Setting-up-a-.tilde-DNS-server" target="_blank">Self-host information</a></li> <a href="/?page=domain_register">Register Domain</a> |
</ul> <a href="/?page=main&action=logout">Logout</a><br><br>
<p><strong>NOTE!</strong> None of the servers currently listed are functional. They are old IP addresses. New servers will be online very soon!</p> <span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span>
<h3> <?php endif; ?>
<a href="https://opennic.org/" target="_blank">OpenNIC Information</a> </nav>
</h3> </header>
<p>
Domains offered by OpenNIC are also able to be resolved using our servers, Such as: <div class="content">
<ul> <h1>Welcome to TildeNIC</h1>
<li>.geek</li> <div class="info-section">
<li>.bbs</li> <p>TildeNIC is where you can request your .tilde top level domain. To do so, you need to first change your DNS over to one of the resolvers we offer, or you can self-host one.</p>
<li>.gopher and more.</li> <ul>
</ul> <li><a href="https://tildegit.org/tildenic/.tilde/wiki/Setting-up-a-.tilde-DNS-server" target="_blank">Self-host information</a></li>
Will all resolve using our dns servers. For more information about OpenNIC you can visit <a href="https://opennic.org/" target="_blank">http://opennic.org</a> </ul>
</p> <p><strong>NOTE!</strong> None of the servers currently listed are functional. They are old IP addresses. New servers will be online very soon!</p>
</div> <h3>
<a href="https://opennic.org/" target="_blank">OpenNIC Information</a>
<div class="server-list"> </h3>
<h2>TildeNIC Available DNS Servers</h2> <p>
<ul> Domains offered by OpenNIC are also able to be resolved using our servers, Such as:
<?php foreach ($dnsServers as $server): ?> <ul>
<li> <li>.geek</li>
<?php echo htmlspecialchars($server['hostname']); ?> - <li>.bbs</li>
IPv4: <?php echo htmlspecialchars($server['ipv4']); ?>, <li>.gopher and more.</li>
IPv6: <?php echo htmlspecialchars($server['ipv6']); ?>, </ul>
Location: <?php echo htmlspecialchars($server['location']); ?> - Will all resolve using our dns servers. For more information about OpenNIC you can visit <a href="https://opennic.org/" target="_blank">http://opennic.org</a>
<span class="status <?php echo checkServerStatus($server['hostname']) === 'Online' ? 'online' : 'offline'; ?>"> </p>
<?php echo checkServerStatus($server['hostname']); ?> </div>
</span>
</li> <div class="server-list">
<?php endforeach; ?> <h2>TildeNIC Available DNS Servers</h2>
</ul> <ul>
</div> <?php foreach ($dnsServers as $server): ?>
</div> <li>
</body> <?php echo htmlspecialchars($server['hostname']); ?> -
IPv4: <?php echo htmlspecialchars($server['ipv4']); ?>,
IPv6: <?php echo htmlspecialchars($server['ipv6']); ?>,
Location: <?php echo htmlspecialchars($server['location']); ?> -
<span class="status <?php echo checkServerStatus($server['hostname']) === 'Online' ? 'online' : 'offline'; ?>">
<?php echo checkServerStatus($server['hostname']); ?>
</span>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
</body>
</html> </html>