first commit
This commit is contained in:
commit
52dff05673
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
includes/initdb.php
|
130
css/styles.css
Normal file
130
css/styles.css
Normal file
@ -0,0 +1,130 @@
|
||||
body {
|
||||
font-family: 'Courier New', monospace;
|
||||
background-color: #000;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
color: #0f0; /* Green text, typical of classic terminals */
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
color: #0f0;
|
||||
border-bottom: 1px solid #0f0;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.content {
|
||||
background-color: #222; /* Darker background for content */
|
||||
padding: 20px;
|
||||
margin-top: 20px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.info-section, .server-list {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
form {
|
||||
background: #000; /* Black background */
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid #0f0; /* Green border */
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
background: #222; /* Dark gray background */
|
||||
border: 1px solid #0f0; /* Green border */
|
||||
color: #0f0; /* Green text */
|
||||
border-radius: 0; /* Square corners */
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
input[type="submit"],
|
||||
input[type="button"] {
|
||||
padding: 10px 20px;
|
||||
margin: 10px 0;
|
||||
background-color: #222; /* Dark gray background */
|
||||
color: #0f0; /* Green text */
|
||||
border: 1px solid #0f0; /* Green border */
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
border-radius: 0; /* Square corners */
|
||||
}
|
||||
|
||||
input[type="submit"]:hover,
|
||||
input[type="button"]:hover {
|
||||
background-color: #333; /* Slightly lighter gray */
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
li {
|
||||
background: #000; /* Black background */
|
||||
margin-bottom: 10px;
|
||||
padding: 20px;
|
||||
border: 1px solid #0f0; /* Green border */
|
||||
box-shadow: none;
|
||||
border-radius: 0; /* Square corners */
|
||||
}
|
||||
|
||||
a {
|
||||
color: #4af;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
color: #7cf;
|
||||
}
|
||||
|
||||
.status {
|
||||
font-weight: bold;
|
||||
}
|
||||
.online {
|
||||
color: green;
|
||||
}
|
||||
.offline {
|
||||
color: red;
|
||||
}
|
||||
|
||||
/* Centering form buttons */
|
||||
form {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Aligning form inputs to the left */
|
||||
form input[type="text"],
|
||||
form input[type="password"] {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
display: block;
|
||||
}
|
||||
.domain-input-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.tilde-extension {
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 0 4px 4px 0; /* Rounded right corners */
|
||||
}
|
||||
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.register-link {
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
123
dns_cron.php
Normal file
123
dns_cron.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
require_once 'includes/initdb.php';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Open a log file for writing
|
||||
$logFile = fopen("webchangelog.log", "a") or die("Unable to open file!");
|
||||
|
||||
// Function to write to log
|
||||
function writeToLog($message, $logFile) {
|
||||
fwrite($logFile, date('Y-m-d H:i:s') . " - " . $message . "\n");
|
||||
}
|
||||
|
||||
// Function to fetch all domain names
|
||||
function getAllDomainNames($pdo) {
|
||||
$stmt = $pdo->query("SELECT domain_name FROM domains");
|
||||
return $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
}
|
||||
|
||||
// Function to fetch all domains
|
||||
function getAllDomains($pdo) {
|
||||
$stmt = $pdo->query("SELECT domain_name, ip_address FROM domains");
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Function to generate BIND DNS file content
|
||||
function generateDnsFileContent($domain, $ipAddress) {
|
||||
$content = "; BIND data file for $domain\n";
|
||||
$content .= "\$TTL 604800\n";
|
||||
$content .= "@ IN SOA ns1.master.tilde. root.$domain. (\n";
|
||||
$content .= " " . date('Ymd') . "01 ; Serial\n"; // Date-based serial
|
||||
$content .= " 604800 ; Refresh\n";
|
||||
$content .= " 86400 ; Retry\n";
|
||||
$content .= " 2419200 ; Expire\n";
|
||||
$content .= " 604800 ) ; Negative Cache TTL\n";
|
||||
$content .= ";\n";
|
||||
$content .= "@ IN NS ns1.master.tilde.\n";
|
||||
$content .= "@ IN NS ns2.master.tilde.\n";
|
||||
$content .= "www IN CNAME $domain\n";
|
||||
$content .= "@ IN A $ipAddress\n";
|
||||
$content .= "* IN A $ipAddress\n"; // Wildcard A record
|
||||
// Add more DNS records as needed
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Change to the Git repository directory
|
||||
chdir('/home/retrodig/dottilde');
|
||||
|
||||
// Perform a git pull to ensure the repository is up to date
|
||||
exec('git pull');
|
||||
|
||||
// Fetch domain names from the database
|
||||
$databaseDomains = getAllDomainNames($pdo);
|
||||
|
||||
// Fetch domains and generate/update DNS files
|
||||
$domains = getAllDomains($pdo);
|
||||
$currentFiles = glob('db.*'); // Get all current db files
|
||||
$changes = false;
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
$filename = "db." . $domain['domain_name'];
|
||||
$content = generateDnsFileContent($domain['domain_name'], $domain['ip_address']);
|
||||
|
||||
if (!file_exists($filename) || $content !== file_get_contents($filename)) {
|
||||
file_put_contents($filename, $content);
|
||||
$changes = true;
|
||||
writeToLog("Updated or created DNS file: $filename", $logFile);
|
||||
}
|
||||
|
||||
// Remove filename from the list of current files if it's in the database
|
||||
if (($key = array_search($filename, $currentFiles)) !== false) {
|
||||
unset($currentFiles[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function to update named.conf.local file
|
||||
function updateNamedConfLocal($domains, $namedConfPath, $logFile) {
|
||||
$confContent = "// Dynamic BIND configuration\n\n";
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
$zoneEntry = "zone \"" . $domain['domain_name'] . "\" {\n";
|
||||
$zoneEntry .= "\ttype master;\n";
|
||||
$zoneEntry .= "\tfile \"/etc/bind/db." . $domain['domain_name'] . "\";\n";
|
||||
$zoneEntry .= "};\n\n";
|
||||
$confContent .= $zoneEntry;
|
||||
}
|
||||
|
||||
// Write the new configuration to the file
|
||||
file_put_contents($namedConfPath, $confContent);
|
||||
writeToLog("Updated named.conf.local", $logFile);
|
||||
}
|
||||
|
||||
// Define the path to named.conf.local
|
||||
$namedConfPath = '/home/retrodig/dottilde/named.conf.local';
|
||||
|
||||
// Update named.conf.local with current domains
|
||||
updateNamedConfLocal($domains, $namedConfPath, $logFile);
|
||||
|
||||
// List of DNS files that should never be deleted
|
||||
$protectedFiles = ['db.master.tilde', 'db.tilde.tilde', 'db.nic.tilde']; // Add your protected filenames here
|
||||
|
||||
// Delete any remaining files that are no longer in the database
|
||||
foreach ($currentFiles as $file) {
|
||||
$domainName = substr($file, 3); // Extract domain name from filename
|
||||
if (!in_array($domainName, $databaseDomains) && !in_array($file, $protectedFiles)) {
|
||||
unlink($file);
|
||||
$changes = true;
|
||||
writeToLog("Deleted orphaned DNS file: $file", $logFile);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the log file
|
||||
fclose($logFile);
|
||||
|
||||
// Git commit and push if there are changes
|
||||
if ($changes) {
|
||||
exec('git add .');
|
||||
exec('git commit -m "Updated DNS files"');
|
||||
exec('git push origin master');
|
||||
}
|
||||
|
87
includes/dns_cron.php
Normal file
87
includes/dns_cron.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
require_once 'initdb.php';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Open a log file for writing
|
||||
$logFile = fopen("wtf.log", "a") or die("Unable to open file!");
|
||||
|
||||
// Function to write to log
|
||||
function writeToLog($message, $logFile) {
|
||||
fwrite($logFile, date('Y-m-d H:i:s') . " - " . $message . "\n");
|
||||
}
|
||||
|
||||
// Function to fetch all domains
|
||||
function getAllDomains($pdo) {
|
||||
$stmt = $pdo->query("SELECT domain_name, ip_address FROM domains");
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Function to generate BIND DNS file content
|
||||
function generateDnsFileContent($domain, $ipAddress) {
|
||||
$content = "; BIND data file for $domain\n";
|
||||
$content .= "\$TTL 604800\n";
|
||||
$content .= "@ IN SOA ns1.master.tilde. root.$domain. (\n";
|
||||
$content .= " " . date('Ymd') . "01 ; Serial\n"; // Date-based serial
|
||||
$content .= " 604800 ; Refresh\n";
|
||||
$content .= " 86400 ; Retry\n";
|
||||
$content .= " 2419200 ; Expire\n";
|
||||
$content .= " 604800 ) ; Negative Cache TTL\n";
|
||||
$content .= ";\n";
|
||||
$content .= "@ IN NS ns1.master.tilde.\n";
|
||||
$content .= "@ IN NS ns2.master.tilde.\n";
|
||||
$content .= "www IN CNAME $domain\n";
|
||||
$content .= "@ IN A $ipAddress\n";
|
||||
$content .= "* IN A $ipAddress\n"; // Wildcard A record
|
||||
// Add more DNS records as needed
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Change to the Git repository directory
|
||||
chdir('../dottilde');
|
||||
|
||||
// Perform a git pull to ensure the repository is up to date
|
||||
exec('git pull');
|
||||
|
||||
// Fetch domains and generate DNS files
|
||||
$domains = getAllDomains($pdo);
|
||||
$changes = false;
|
||||
$currentFiles = glob('db.*'); // Get all current db files
|
||||
|
||||
writeToLog("Current files before processing: " . implode(', ', $currentFiles), $logFile);
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
$filename = "db." . $domain['domain_name'];
|
||||
$content = generateDnsFileContent($domain['domain_name'], $domain['ip_address']);
|
||||
|
||||
// Check if file content is different from existing file
|
||||
if (!file_exists($filename) || $content !== file_get_contents($filename)) {
|
||||
file_put_contents($filename, $content);
|
||||
$changes = true;
|
||||
}
|
||||
|
||||
// Remove filename from the list of current files
|
||||
if (($key = array_search($filename, $currentFiles)) !== false) {
|
||||
unset($currentFiles[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
writeToLog("Files to be deleted: " . implode(', ', $currentFiles), $logFile);
|
||||
|
||||
// Delete any remaining files that are no longer in the database
|
||||
foreach ($currentFiles as $file) {
|
||||
writeToLog("Deleting file: $file", $logFile);
|
||||
unlink($file);
|
||||
$changes = true;
|
||||
}
|
||||
|
||||
// Close the log file
|
||||
fclose($logFile);
|
||||
|
||||
// Git commit and push if there are changes
|
||||
if ($changes) {
|
||||
// exec('git add .');
|
||||
// exec('git commit -m "Updated DNS files"');
|
||||
// exec('git push origin master');
|
||||
}
|
94
includes/domain_register.php
Normal file
94
includes/domain_register.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
require_once 'initdb.php';
|
||||
|
||||
session_start();
|
||||
|
||||
// Redirect to login if not logged in
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header("Location: https://tildenic.org/?page=login");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Restricted domains that cannot be registered
|
||||
$restrictedDomains = ['master.tilde', 'nic.tilde', 'tilde.tilde']; // Add more as needed
|
||||
|
||||
// Function to register domain
|
||||
function registerDomain($domain, $userId, $pdo, $restrictedDomains) {
|
||||
if (in_array($domain, $restrictedDomains)) {
|
||||
return "Error: The domain '$domain' cannot be registered.";
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO domains (user_id, domain_name) VALUES (?, ?)");
|
||||
$stmt->execute([$userId, $domain]);
|
||||
return "Domain registered successfully: " . htmlspecialchars($domain);
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getCode() == 23000) {
|
||||
return "Error: The domain '$domain' is already registered.";
|
||||
} else {
|
||||
return "Error: An error occurred while registering the domain.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to get user ID
|
||||
function getUserId($username, $pdo) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
// Handle domain registration
|
||||
$message = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['registerdomain'])) {
|
||||
$domain = $_POST['registerdomain'] . '.tilde';
|
||||
$userId = getUserId($_SESSION['username'], $pdo);
|
||||
|
||||
$message = registerDomain($domain, $userId, $pdo, $restrictedDomains);
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Register Domain</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
<script>
|
||||
function submitForm() {
|
||||
var form = document.getElementById("domainForm");
|
||||
var domain = document.getElementById("domain").value;
|
||||
form.action = "https://tildenic.org/?page=domain_register®isterdomain=" + encodeURIComponent(domain);
|
||||
form.submit();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav>
|
||||
<?php if (!isset($_SESSION['username'])): ?>
|
||||
<a href="https://tildenic.org/?page=login">Login</a> |
|
||||
<a href="https://tildenic.org/?page=register">Register</a>
|
||||
<?php else: ?>
|
||||
<a href="https://tildenic.org/?page=main">Home</a> |
|
||||
<a href="https://tildenic.org/?page=user_domains">My Account</a> |
|
||||
<a href="https://tildenic.org/?page=domain_register">Register Domain</a> |
|
||||
<a href="https://tildenic.org/?page=main&action=logout">Logout</a><br><br>
|
||||
<span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
</header>
|
||||
<h1>Register Domain</h1>
|
||||
<form id="domainForm" method="post" onsubmit="submitForm(); return false;">
|
||||
<div class="domain-input-container">
|
||||
<label for="domain">Domain Name:</label>
|
||||
<input type="text" id="domain" name="registerdomain" required>
|
||||
<span class="tilde-extension">.tilde</span>
|
||||
</div>
|
||||
<input type="submit" value="Register Domain">
|
||||
</form>
|
||||
<?php if (!empty($message)): ?>
|
||||
<p><?php echo $message; ?></p>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
47
includes/initdb-template.php
Normal file
47
includes/initdb-template.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// Use the latest PHP version and enable error reporting
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Database credentials
|
||||
$host = 'hostname';
|
||||
$db = 'db_name';
|
||||
$user = 'db_username';
|
||||
$pass = 'db_password';
|
||||
$charset = 'utf8mb4';
|
||||
|
||||
// DSN (Data Source Name)
|
||||
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
// Create a PDO instance (connect to the database)
|
||||
$pdo = new PDO($dsn, $user, $pass, $options);
|
||||
|
||||
// SQL for creating tables
|
||||
// Users table
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;");
|
||||
|
||||
// Domains table with added ip_address column
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS domains (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
domain_name VARCHAR(255) NOT NULL UNIQUE,
|
||||
dns_records TEXT,
|
||||
ip_address VARCHAR(15), -- Added column for IP address
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
) ENGINE=InnoDB;");
|
||||
|
||||
} catch (\PDOException $e) {
|
||||
throw new \PDOException($e->getMessage(), (int)$e->getCode());
|
||||
}
|
53
includes/login.php
Normal file
53
includes/login.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
require_once 'initdb.php';
|
||||
|
||||
session_start();
|
||||
|
||||
// Function to check user credentials
|
||||
function checkCredentials($username, $password, $pdo) {
|
||||
$stmt = $pdo->prepare("SELECT password FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
$user = $stmt->fetch();
|
||||
return $user && password_verify($password, $user['password']);
|
||||
}
|
||||
|
||||
// Handle login
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (checkCredentials($username, $password, $pdo)) {
|
||||
$_SESSION['username'] = $username;
|
||||
header("Location: /?page=user_domains");
|
||||
exit;
|
||||
} else {
|
||||
$error = "Invalid username or password.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Login</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Login</h1>
|
||||
<form method="post">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
<br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<br>
|
||||
<input type="submit" name="login" value="Login">
|
||||
<!-- Registration Button -->
|
||||
<input type="button" onclick="location.href='/?page=register';" value="Register">
|
||||
</form>
|
||||
<?php if (!empty($error)): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
126
includes/main.php
Normal file
126
includes/main.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
require_once 'initdb.php';
|
||||
session_start();
|
||||
|
||||
// Logout handling
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'logout') {
|
||||
session_destroy();
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Function to get DNS server information from BIND files
|
||||
function getDnsServersInfo() {
|
||||
$masterFile = '../dottilde/db.master.tilde';
|
||||
$servers = [];
|
||||
$nsFilter = ['ns1', 'ns2']; // Add more nameserver identifiers as needed
|
||||
|
||||
if (file_exists($masterFile)) {
|
||||
$content = file_get_contents($masterFile);
|
||||
// Regex to match A records (IPv4)
|
||||
preg_match_all('/(\S+)\s+IN\s+A\s+(\S+)/', $content, $aMatches);
|
||||
// Regex to match AAAA records (IPv6)
|
||||
preg_match_all('/(\S+)\s+IN\s+AAAA\s+(\S+)/', $content, $aaaaMatches);
|
||||
|
||||
$ipv4Records = array_combine($aMatches[1], $aMatches[2]);
|
||||
$ipv6Records = array_combine($aaaaMatches[1], $aaaaMatches[2]);
|
||||
|
||||
foreach ($nsFilter as $nsName) {
|
||||
if (isset($ipv4Records[$nsName])) {
|
||||
$ipv4 = $ipv4Records[$nsName];
|
||||
} else {
|
||||
$ipv4 = 'IPv4 not found';
|
||||
}
|
||||
|
||||
if (isset($ipv6Records[$nsName])) {
|
||||
$ipv6 = $ipv6Records[$nsName];
|
||||
} else {
|
||||
$ipv6 = 'IPv6 not found';
|
||||
}
|
||||
|
||||
$servers[] = ['hostname' => $nsName, 'ipv4' => $ipv4, 'ipv6' => $ipv6];
|
||||
}
|
||||
}
|
||||
|
||||
return $servers;
|
||||
}
|
||||
|
||||
$dnsServers = getDnsServersInfo();
|
||||
|
||||
// Function to check server status
|
||||
function checkServerStatus($server) {
|
||||
// Ping command varies depending on the operating system
|
||||
// This is an example for a Unix-like system
|
||||
$output = [];
|
||||
$status = null;
|
||||
exec("ping -c 1 " . escapeshellarg($server), $output, $status);
|
||||
|
||||
return $status === 0 ? "Online" : "Offline";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>|--===TildeNIC ===--| Bringing .tilde to the Tildeverse!</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav>
|
||||
<?php if (!isset($_SESSION['username'])): ?>
|
||||
<a href="/?page=login">Login</a> |
|
||||
<a href="/?page=register">Register</a>
|
||||
<?php else: ?>
|
||||
<a href="/?page=main">Home</a> |
|
||||
<a href="/?page=user_domains">My Account</a> |
|
||||
<a href="/?page=domain_register">Register Domain</a> |
|
||||
<a href="/?page=main&action=logout">Logout</a><br><br>
|
||||
<span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
<h1>Welcome to TildeNIC</h1>
|
||||
<div class="info-section">
|
||||
<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>
|
||||
<ul>
|
||||
<li><a href="https://tildegit.org/.tilde/.tilde/wiki/Setting-up-a-.tilde-DNS-server" target="_blank">Self-host information</a></li>
|
||||
</ul>
|
||||
<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>
|
||||
<h3>
|
||||
<a href="https://opennic.org/" target="_blank">OpenNIC Information</a>
|
||||
</h3>
|
||||
<p>
|
||||
Domains offered by OpenNIC are also able to be resolved using our servers, Such as:
|
||||
<ul>
|
||||
<li>.geek</li>
|
||||
<li>.bbs</li>
|
||||
<li>.gopher and more.</li>
|
||||
</ul>
|
||||
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>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="server-list">
|
||||
<h2>TildeNIC Available DNS Servers</h2>
|
||||
<ul>
|
||||
|
||||
<?php foreach ($dnsServers as $server): ?>
|
||||
<li>
|
||||
<?php echo htmlspecialchars($server['hostname']); ?> -
|
||||
IPv4: <?php echo htmlspecialchars($server['ipv4']); ?>,
|
||||
IPv6: <?php echo htmlspecialchars($server['ipv6']); ?> -
|
||||
<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>
|
58
includes/register.php
Normal file
58
includes/register.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
require_once 'initdb.php';
|
||||
|
||||
session_start();
|
||||
|
||||
// Function to register user
|
||||
function registerUser($username, $password, $pdo) {
|
||||
$hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
|
||||
$stmt->execute([$username, $hash]);
|
||||
}
|
||||
|
||||
// Function to check if username exists
|
||||
function doesUserExist($username, $pdo) {
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
return $stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
// Handle registration
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['register'])) {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (!doesUserExist($username, $pdo)) {
|
||||
registerUser($username, $password, $pdo);
|
||||
$_SESSION['username'] = $username;
|
||||
header("Location: https://tildenic.org/?page=domain_register");
|
||||
exit;
|
||||
} else {
|
||||
$error = "Username already exists.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Register</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Register</h1>
|
||||
<form method="post">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
<br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<br>
|
||||
<input type="submit" name="register" value="Register">
|
||||
</form>
|
||||
<?php if (!empty($error)): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
118
includes/user_domains.php
Normal file
118
includes/user_domains.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
require_once 'initdb.php';
|
||||
|
||||
session_start();
|
||||
|
||||
// Redirect to login if not logged in
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header("Location: https://tildenic.org/?page=login");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Function to get user ID
|
||||
function getUserId($username, $pdo) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
// Function to get user's domains
|
||||
function getUserDomains($userId, $pdo) {
|
||||
$stmt = $pdo->prepare("SELECT id, domain_name, ip_address FROM domains WHERE user_id = ?"); // Fetching ip_address
|
||||
$stmt->execute([$userId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
// Function to remove a domain
|
||||
function removeDomain($domainId, $pdo) {
|
||||
$stmt = $pdo->prepare("DELETE FROM domains WHERE id = ?");
|
||||
$stmt->execute([$domainId]);
|
||||
}
|
||||
|
||||
// Function to update domain's IP address
|
||||
function updateDomainIP($domainId, $ipAddress, $pdo) {
|
||||
$stmt = $pdo->prepare("UPDATE domains SET ip_address = ? WHERE id = ?"); // Updating ip_address
|
||||
$stmt->execute([$ipAddress, $domainId]);
|
||||
}
|
||||
|
||||
// Handle domain removal
|
||||
if (isset($_GET['remove'])) {
|
||||
removeDomain($_GET['remove'], $pdo);
|
||||
header("Location: https://tildenic.org/?page=user_domains");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle IP address update
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['update_ip'])) {
|
||||
$domainId = $_POST['domain_id'];
|
||||
$ipAddress = $_POST['ip_address'];
|
||||
updateDomainIP($domainId, $ipAddress, $pdo);
|
||||
header("Location: https://tildenic.org/?page=user_domains");
|
||||
exit;
|
||||
}
|
||||
// Handle logout
|
||||
if (isset($_POST['logout'])) {
|
||||
session_destroy();
|
||||
header("Location: https://tildenic.org/?page=login");
|
||||
exit;
|
||||
}
|
||||
// Handle form submission
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$domainId = $_POST['domain_id'];
|
||||
|
||||
if (isset($_POST['update_ip'])) {
|
||||
// Update IP address
|
||||
$ipAddress = $_POST['ip_address'];
|
||||
updateDomainIP($domainId, $ipAddress, $pdo);
|
||||
} elseif (isset($_POST['remove_domain'])) {
|
||||
// Remove domain
|
||||
removeDomain($domainId, $pdo);
|
||||
}
|
||||
|
||||
header("Location: https://tildenic.org/?page=user_domains");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userId = getUserId($_SESSION['username'], $pdo);
|
||||
$domains = getUserDomains($userId, $pdo);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>My Account</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav>
|
||||
<?php if (!isset($_SESSION['username'])): ?>
|
||||
<a href="https://tildenic.org/?page=login">Login</a> |
|
||||
<a href="https://tildenic.org/?page=register">Register</a>
|
||||
<?php else: ?>
|
||||
<a href="https://tildenic.org/?page=main">Home</a> |
|
||||
<a href="https://tildenic.org/?page=user_domains" active>My Account</a> |
|
||||
<a href="https://tildenic.org/?page=domain_register">Register Domain</a> |
|
||||
<a href="https://tildenic.org/?page=main&action=logout">Logout</a><br><br>
|
||||
<span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
</header>
|
||||
<h2>Your Domains</h2>
|
||||
<ul>
|
||||
<?php foreach ($domains as $domain): ?>
|
||||
<li>
|
||||
<?php echo htmlspecialchars($domain['domain_name']); ?>
|
||||
<form method="post" class="domain-form">
|
||||
<input type="hidden" name="domain_id" value="<?php echo $domain['id']; ?>">
|
||||
<input type="text" name="ip_address" placeholder="Default IP Address" value="<?php echo htmlspecialchars($domain['ip_address'] ?? ''); ?>">
|
||||
<input type="submit" name="update_ip" value="Update IP">
|
||||
<!-- Remove button -->
|
||||
<input type="submit" name="remove_domain" value="Remove" class="remove-button">
|
||||
</form>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
22
index.php
Normal file
22
index.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// Define the default page
|
||||
$defaultPage = 'domain_search';
|
||||
|
||||
// Get the requested page from the query parameter
|
||||
$page = isset($_GET['page']) ? $_GET['page'] : $defaultPage;
|
||||
|
||||
// Sanitize the page parameter to prevent directory traversal
|
||||
$page = preg_replace('/[^-a-zA-Z0-9_]/', '', $page);
|
||||
|
||||
// Path to the includes directory
|
||||
$includesPath = './includes/';
|
||||
|
||||
// Check if the file exists
|
||||
if (file_exists($includesPath . $page . '.php')) {
|
||||
require_once $includesPath . $page . '.php';
|
||||
} else {
|
||||
// If the file doesn't exist, you can include a default page or show an error
|
||||
echo "Page not found.";
|
||||
// Or include a 404 page
|
||||
// require_once $includesPath . '404.php';
|
||||
}
|
Loading…
Reference in New Issue
Block a user