Moved classic code to classic branch

This commit is contained in:
Finn
2025-12-11 11:09:04 +01:00
parent fd0c062aed
commit 7c02af118a
30 changed files with 1604 additions and 305 deletions

11
frontend/auth/index.php Normal file
View File

@@ -0,0 +1,11 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
header('Location: index.php');
?>

69
frontend/auth/login.php Normal file
View File

@@ -0,0 +1,69 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
session_start();
include(__DIR__ . "/../utils/connection.php");
include(__DIR__ . "/../utils/functions.php");
global $con;
$user_data = check_login($con);
if ($user_data != null) {
header('Location: dashboard.php');
die();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = $_POST["username"];
$pass = $_POST["password"];
if (!empty($user) && !empty($pass)) {
if (!username_exists($con, $user)) echo "Username not exists.";
else {
if (login($con, $user, $pass)) {
$_SESSION['user'] = $user;
$pw = hash('sha512', $pass);
$_SESSION['pass'] = $pw;
header('Location: ../dashboard.php');
die();
} else echo "Failed to login. Wrong credentials?";
}
} else echo "Please enter username and password";
}
?>
<html>
<head>
<title>Open Autonomous Connection - Management/Login</title>
<meta name="charset" content="UTF-8" />
<meta name="author" content="Open Autonomous Connection" />
<meta name="description" content="Register here your API Key or (Top level) Domain" />
</head>
<body>
<div id="box">
<h4>Login</h4>
<form method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Login" />
</form>
<a href="auth/register.php">Register</a>
</div>
</body>
</html>
<?php
?>

View File

@@ -0,0 +1,67 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
session_start();
include(__DIR__ . "/../utils/connection.php");
include(__DIR__ . "/../utils/functions.php");
global $con;
$user_data = check_login($con);
if ($user_data != null) {
header('Location: dashboard.php');
die();
}
if (!accountRegisteringAllowed($con)) {
echo "No account registering allowed!";
die();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = $_POST["username"];
$pass = $_POST["password"];
if (!empty($user) && !empty($pass)) {
if (username_exists($con, $user)) echo "Username already exists.";
else {
if (create_account($con, $user, $pass)) {
header('Location: auth/login.php');
die();
} else echo "Failed to register.";
}
} else echo "Please enter username and password";
}
?>
<html>
<head>
<title>Open Autonomous Connection - Management/Register</title>
<meta name="charset" content="UTF-8" />
<meta name="author" content="Open Autonomous Connection" />
<meta name="description" content="Register here your API Key or (Top level) Domain" />
</head>
<body>
<div id="box">
<h4>Register</h4>
<form method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Register" />
</form>
<a href="auth/login.php">Login</a>
</div>
</body>
</html>

17
frontend/config.php Normal file
View File

@@ -0,0 +1,17 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
$DATABASE_HOST = "127.0.0.1";
$DATABASE_PORT = 3306;
$DATABASE_USER = "my_user";
$DATABASE_PASSWORD = "my_pass";
$DATABASE_NAME = "my_db";
?>

197
frontend/dashboard.php Normal file
View File

@@ -0,0 +1,197 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include(__DIR__ . "/utils/connection.php");
include(__DIR__ . "/utils/functions.php");
global $con;
$username = $_SESSION['user'];
$user_data = check_login($con);
if ($user_data == null) {
header('Location: index.php');
die();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['delete_domain'])) {
$name = $_POST['domain_name'];
$tld = $_POST['tld'];
$accessKey = $_POST['accessKey'];
delete_domain($con, $name, $tld, $accessKey);
} elseif (isset($_POST['delete_tld'])) {
$name = $_POST['tld_name'];
$accessKey = $_POST['accessKey'];
delete_top_level_domain($con, $name, $accessKey);
} elseif (isset($_POST['delete_apikey'])) {
$application = $_POST['application'];
$apiKey = $_POST['apiKey'];
delete_api_key($con, $username, $application, $apiKey);
} elseif (isset($_POST['delete_account'])) {
delete_account($con, $username);
logout($con);
header('Location: index.php');
die();
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['create_domain'])) {
if (!domainRegisteringAllowed($con)) {
echo "No domain registering allowed!";
die();
}
$name = $_POST['domain_name'];
$tld = $_POST['tld'];
$destination = $_POST['destination'];
create_domain($con, $name, $tld, $destination, $username);
} elseif (isset($_POST['create_tld'])) {
if (!topLevelDomainRegisteringAllowed($con)) {
echo "No top level domain registering allowed!";
die();
}
$name = $_POST['tld_name'];
$infoSite = $_POST['info_site'];
create_top_level_domain($con, $name, $infoSite, $username);
} elseif (isset($_POST['create_apikey'])) {
$application = $_POST['application'];
create_api_key($con, $username, $application);
}
}
$domains = list_domains($con, $username);
$tlds = list_topleveldomains($con, $username);
$apikeys = list_apikeys($con, $username);
?>
<head>
<title>Open Autonomous Connection - Management/Dashboard</title>
<meta name="charset" content="UTF-8" />
<meta name="author" content="Open Autonomous Connection" />
<meta name="description" content="Register here your API Key or (Top level) Domain" />
</head>
<body>
<h1>Welcome, <?php echo $username; ?></h1>
<h2>Your Domains</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Top Level Domain</th>
<th>Destination</th>
<th>Access Key</th>
<th>Action</th>
</tr>
<?php foreach ($domains as $domain): ?>
<tr>
<td><?php echo $domain['name']; ?></td>
<td><?php echo $domain['topleveldomain']; ?></td>
<td><?php echo $domain['destination']; ?></td>
<td><?php echo $domain['accesskey']; ?></td>
<td>
<form method="post">
<input type="hidden" name="domain_name" value="<?php echo $domain['name']; ?>">
<input type="hidden" name="tld" value="<?php echo $domain['topleveldomain']; ?>">
<input type="hidden" name="accessKey" value="<?php echo $domain['accesskey']; ?>">
<input type="submit" name="delete_domain" value="Delete">
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<h2>Your Top Level Domains</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Info Site</th>
<th>Access Key</th>
<th>Action</th>
</tr>
<?php foreach ($tlds as $tld): ?>
<tr>
<td><?php echo $tld['name']; ?></td>
<td><?php echo $tld['info']; ?></td>
<td><?php echo $tld['accesskey']; ?></td>
<td>
<form method="post">
<input type="hidden" name="tld_name" value="<?php echo $tld['name']; ?>">
<input type="hidden" name="accessKey" value="<?php echo $tld['accesskey']; ?>">
<input type="submit" name="delete_tld" value="Delete">
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<h2>Your API Keys</h2>
<table border="1">
<tr>
<th>Application</th>
<th>API Key</th>
<th>Action</th>
</tr>
<?php foreach ($apikeys as $apikey): ?>
<tr>
<td><?php echo $apikey['application']; ?></td>
<td><?php echo $apikey['keyapi']; ?></td>
<td>
<form method="post">
<input type="hidden" name="application" value="<?php echo $apikey['application']; ?>">
<input type="hidden" name="apiKey" value="<?php echo $apikey['keyapi']; ?>">
<input type="submit" name="delete_apikey" value="Delete">
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<h2>Create Domain</h2>
<form method="post">
<label for="domain_name">Domain Name:</label>
<input type="text" id="domain_name" name="domain_name" required>
<label for="tld">Top Level Domain:</label>
<input type="text" id="tld" name="tld" required>
<label for="destination">Destination:</label>
<input type="text" id="destination" name="destination" required>
<input type="submit" name="create_domain" value="Create Domain">
</form>
<h2>Create Top Level Domain</h2>
<form method="post">
<label for="tld_name">TLD Name:</label>
<input type="text" id="tld_name" name="tld_name" required>
<label for="info_site">Info Site:</label>
<input type="text" id="info_site" name="info_site" required>
<input type="submit" name="create_tld" value="Create TLD">
</form>
<h2>Create API Key</h2>
<form method="post">
<label for="application">Application:</label>
<input type="text" id="application" name="application" required>
<input type="submit" name="create_apikey" value="Create API Key">
</form>
<h2>Delete Account</h2>
<form method="post">
<input type="submit" name="delete_account" value="Delete Account">
</form>
</body>
</html>

40
frontend/index.php Normal file
View File

@@ -0,0 +1,40 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include(__DIR__ . "/utils/connection.php");
include(__DIR__ . "/utils/functions.php");
global $con;
$user_data = check_login($con);
if ($user_data != null) {
header('Location: dashboard.php');
die();
}
?>
<html>
<head>
<title>Open Autonomous Connection - Management</title>
<meta name="charset" content="UTF-8" />
<meta name="author" content="Open Autonomous Connection" />
<meta name="description" content="Register here your API Key or (Top level) Domain" />
<meta name="keywords" content="domain,api,oac,registration,key,host,manager,management" />
</head>
<body>
<a href="auth/register.php">Register</a>
<a href="auth/login.php">Login</a>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
include(__DIR__ . "/../config.php");
global $DATABASE_HOST, $DATABASE_USER, $DATABASE_PASSWORD, $DATABASE_NAME;
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASSWORD, $DATABASE_NAME);
if (!$con) echo "Failed to connect";
?>

View File

@@ -0,0 +1,449 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
$DOMAIN_PATTERN = '/^(?!-)[A-Za-z0-9-]{1,63}(?<!-)$/';
$TOP_LEVEL_DOMAIN_PATTERN = '/^[A-Za-z]{2,6}$/';
function check_login($con) {
if (isset($_SESSION["user"]) && isset($_SESSION["pass"])) {
$user = $_SESSION["user"];
$pass = $_SESSION["pass"];
if (!username_exists($con, $user)) {
logout();
return null;
}
$query = "SELECT * FROM accounts WHERE username = '$user' AND password = '$pass'";
$result = mysqli_query($con, $query);
if ($result && mysqli_num_rows($result) > 0) {
if (!login($con, $user, $pass, true)) {
logout();
return null;
}
$user_data = mysqli_fetch_assoc($result);
return $user_data && login($con, $user, $pass, true);
}
}
return null;
}
function logout() {
unset($_SESSION["user"]);
unset($_SESSION["pass"]);
}
function list_domains($con, $username) {
$domains = [];
// Get the infokeys for the domains associated with the user
$query = "SELECT infokey FROM accountinfos WHERE username = ? AND type = 'domain'";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$infokeys = [];
while ($row = mysqli_fetch_assoc($result)) {
$infokeys[] = $row['infokey'];
}
// Fetch the domains based on the infokeys
if (!empty($infokeys)) {
$placeholders = implode(',', array_fill(0, count($infokeys), '?'));
$types = str_repeat('s', count($infokeys));
$query = "SELECT * FROM domains WHERE accesskey IN ($placeholders)";
$stmt = mysqli_prepare($con, $query);
// Dynamically bind the parameters
mysqli_stmt_bind_param($stmt, $types, ...$infokeys);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$domains = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
return $domains;
}
function list_topleveldomains($con, $username) {
$query = "SELECT infokey FROM accountinfos WHERE username = ? AND type = 'tld'";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$tlds = [];
while ($row = mysqli_fetch_assoc($result)) {
$infokey = $row['infokey'];
$query = "SELECT * FROM topleveldomains WHERE accesskey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $infokey);
mysqli_stmt_execute($stmt);
$result_tld = mysqli_stmt_get_result($stmt);
$tlds = array_merge($tlds, mysqli_fetch_all($result_tld, MYSQLI_ASSOC));
}
return $tlds;
}
function list_apikeys($con, $username) {
$query = "SELECT infokey FROM accountinfos WHERE username = ? AND type = 'api'";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$apikeys = [];
while ($row = mysqli_fetch_assoc($result)) {
$infokey = $row['infokey'];
$query = "SELECT * FROM apikeys WHERE keyapi = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $infokey);
mysqli_stmt_execute($stmt);
$result_apikey = mysqli_stmt_get_result($stmt);
$apikeys = array_merge($apikeys, mysqli_fetch_all($result_apikey, MYSQLI_ASSOC));
}
return $apikeys;
}
function create_domain($con, $name, $topLevelDomain, $destination, $username) {
if (!domainRegisteringAllowed($con)) return false;
if (domain_exists($con, $name, $topLevelDomain)) return false;
if (strlen($name) < 3 || strlen($name) > 20) return false;
if (!top_level_domain_exists($con, $topLevelDomain)) return false;
if (!is_valid_domain($name)) return false;
if (!is_valid_top_level_domain($topLevelDomain)) return false;
if (!username_exists($con, $username)) return false;
$access_key = generate_key($name . "." . $topLevelDomain . "=" . $username);
$query = "INSERT INTO domains (name, topleveldomain, destination, accesskey) VALUES (?, ?, ?, ?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ssss', $name, $topLevelDomain, $destination, $access_key);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$query = "INSERT INTO accountinfos (username, infokey, type) VALUES (?, ?, 'domain')";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ss', $username, $access_key);
$result = mysqli_stmt_execute($stmt);
return $result;
}
return false;
}
function create_top_level_domain($con, $name, $infoSite, $username) {
if (!topLevelDomainRegisteringAllowed($con)) return false;
if (strlen($name) < 3 || strlen($name) > 10) return false;
if (top_level_domain_exists($con, $name)) return false;
if (!is_valid_top_level_domain($name)) return false;
if (!username_exists($con, $username)) return false;
$access_key = generate_key($infoSite . "." . $name . "=" . $username);
$query = "INSERT INTO topleveldomains (name, accesskey, info) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'sss', $name, $access_key, $infoSite);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$query = "INSERT INTO accountinfos (username, infokey, type) VALUES (?, ?, 'tld')";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ss', $username, $access_key);
$result = mysqli_stmt_execute($stmt);
return $result;
}
return false;
}
function create_api_key($con, $username, $application) {
if (!username_exists($con, $username)) return false;
if (has_api_key($con, $username, $application)) return false;
$currentApiKeyCount = getCurrentApiKeyCount($con, $username);
$maxApiKeyCount = maxApiKeys($con);
if ($maxApiKeyCount != -1 && $currentApiKeyCount >= $maxApiKeyCount) return false;
$apikey = generate_key($username . "=" . $application);
$query = "INSERT INTO apikeys (username, application, keyapi) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'sss', $username, $application, $apikey);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$query = "INSERT INTO accountinfos (username, infokey, type) VALUES (?, ?, 'api')";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ss', $username, $apikey);
$result = mysqli_stmt_execute($stmt);
return $result;
}
return false;
}
function getCurrentApiKeyCount($con, $username) {
$query = "SELECT COUNT(*) as count FROM apikeys WHERE username = '$username'";
$result = mysqli_query($con, $query);
if ($result && $row = mysqli_fetch_assoc($result)) {
return intval($row['count']);
}
return 0;
}
function is_valid_domain(string $name) {
global $DOMAIN_PATTERN;
return preg_match($DOMAIN_PATTERN, $name);
}
function is_valid_top_level_domain(string $topLevelDomain) {
global $TOP_LEVEL_DOMAIN_PATTERN;
return preg_match($TOP_LEVEL_DOMAIN_PATTERN, $topLevelDomain);
}
function validate_domain_access_key($con, $name, $topLevelDomain, $accessKey) {
$query = "SELECT * FROM domains WHERE name = '$name' AND topleveldomain = '$topLevelDomain' AND accesskey = '$accessKey'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function validate_top_level_domain_access_key($con, $topLevelDomain, $accessKey) {
$query = "SELECT * FROM topleveldomains WHERE name = '$topLevelDomain' AND accesskey = '$accessKey'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function domain_exists($con, $name, $topLevelDomain) {
if (strcasecmp($name, "info") == 0) return true;
$query = "SELECT * FROM domains WHERE name = '$name' AND topleveldomain = '$topLevelDomain'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function top_level_domain_exists($con, $topLevelDomain) {
if (strcasecmp($topLevelDomain, "oac") == 0) return true;
$query = "SELECT * FROM topleveldomains WHERE name = '$topLevelDomain'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function validate_api_key($con, $username, $application, $apikey) {
if (!username_exists($con, $username)) return false;
if (!has_api_key($con, $username, $application)) return false;
$query = "SELECT * FROM apikeys WHERE application = '$application' AND keyapi = '$apikey' AND username = '$username'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function has_api_key($con, $username, $application) {
if (!username_exists($con, $username)) return false;
$query = "SELECT * FROM apikeys WHERE application = '$application' AND username = '$username'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function username_exists($con, $username) {
$query = "SELECT * FROM accounts WHERE username = '$username'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function create_account($con, $username, $password) {
if (!accountRegisteringAllowed($con)) return false;
if (username_exists($con, $username)) return false;
$pw = hash('sha512', $password);
$query = "INSERT INTO accounts (username, password) VALUES (?, ?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ss', $username, $pw);
$result = mysqli_stmt_execute($stmt);
return $result;
}
function login($con, $username, $password, $sha = false) {
if (!username_exists($con, $username)) return false;
$pw = $password;
if (!$sha) $pw = hash('sha512', $password);
$query = "SELECT * FROM accounts WHERE username = '$username' AND password = '$pw'";
$result = mysqli_query($con, $query);
return $result && mysqli_num_rows($result) > 0;
}
function generate_key($based) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 20; $i++) $randomString .= $characters[random_int(0, $charactersLength - 1)];
return hash("sha512", $based . $randomString);
}
function delete_api_key($con, $username, $application, $apiKey) {
if (!username_exists($con, $username)) return false;
if (!has_api_key($con, $username, $application)) return false;
if (!validate_api_key($con, $username, $application, $apiKey)) return false;
$query = "DELETE FROM apikeys WHERE application = ? AND keyapi = ? AND username = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'sss', $application, $apiKey, $username);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$query = "DELETE FROM accountinfos WHERE username = ? AND infokey = ? AND type = 'api'";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ss', $username, $apiKey);
$result = mysqli_stmt_execute($stmt);
}
return $result;
}
function delete_domain($con, $name, $topLevelDomain, $accessKey) {
if (!validate_domain_access_key($con, $name, $topLevelDomain, $accessKey)) return false;
$query = "DELETE FROM domains WHERE name = ? AND topleveldomain = ? AND accesskey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'sss', $name, $topLevelDomain, $accessKey);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$query = "DELETE FROM accountinfos WHERE infokey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $accessKey);
mysqli_stmt_execute($stmt);
}
return $result;
}
function delete_top_level_domain($con, $topLevelDomain, $accessKey) {
if (!validate_top_level_domain_access_key($con, $topLevelDomain, $accessKey)) return false;
$query = "DELETE FROM topleveldomains WHERE name = ? AND accesskey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 'ss', $topLevelDomain, $accessKey);
$result = mysqli_stmt_execute($stmt);
if ($result) {
$query = "DELETE FROM accountinfos WHERE infokey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $accessKey);
mysqli_stmt_execute($stmt);
}
return $result;
}
function delete_account($con, $username) {
if (!username_exists($con, $username)) return false;
$query = "SELECT infokey FROM accountinfos WHERE username = ? AND type = 'domain'";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
$infokey = $row['infokey'];
$query = "DELETE FROM domains WHERE accesskey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $infokey);
mysqli_stmt_execute($stmt);
}
$query = "SELECT infokey FROM accountinfos WHERE username = ? AND type = 'tld'";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
$infokey = $row['infokey'];
$query = "DELETE FROM topleveldomains WHERE accesskey = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $infokey);
mysqli_stmt_execute($stmt);
}
$query = "DELETE FROM apikeys WHERE username = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$query = "DELETE FROM accountinfos WHERE username = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$query = "DELETE FROM accounts WHERE username = ?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, 's', $username);
$result = mysqli_stmt_execute($stmt);
return $result;
}
function getConfigValue($con, $name) {
$query = "SELECT value FROM config WHERE name = '$name'";
$result = mysqli_query($con, $query);
if ($result && $row = mysqli_fetch_assoc($result)) {
return $row['value'];
}
return null;
}
function parseBoolean($value) {
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
function topLevelDomainRegisteringAllowed($con) {
$value = getConfigValue($con, 'allow_register_tld');
return $value !== null && parseBoolean(intval($value));
}
function domainRegisteringAllowed($con) {
$value = getConfigValue($con, 'allow_register_domain');
return $value !== null && parseBoolean(intval($value));
}
function accountRegisteringAllowed($con) {
$value = getConfigValue($con, 'allow_register_account');
return $value !== null && parseBoolean(intval($value));
}
function maxApiKeys($con) {
$value = getConfigValue($con, 'max_apikeys');
return $value !== null ? intval($value) : 0;
}
?>

11
frontend/utils/index.php Normal file
View File

@@ -0,0 +1,11 @@
<!--
Copyright (C) 2024 Open Autonomous Connection - All Rights Reserved
You are unauthorized to remove this copyright.
You have to give Credits to the Author in your project and link this GitHub site: https://github.com/Open-Autonomous-Connection
See LICENSE-File if exists
-->
<?php
header('Location: index.php');
?>