Compare commits

..

No commits in common. "2e779ed6067cfd44cfd216190d4026173e346665" and "c31642a90e5089b46de10659cb0035d57f205654" have entirely different histories.

6 changed files with 26 additions and 92 deletions

View File

@ -26,8 +26,7 @@ class ApiKeys
FROM " . DatabaseConnection::TABLE_USER; FROM " . DatabaseConnection::TABLE_USER;
try { try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement = $this->databaseConnection->getConnection()->query(statement: $sql);
$statement->execute();
return $statement->fetchAll(mode: PDO::FETCH_ASSOC); return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
exit($e->getMessage()); exit($e->getMessage());

View File

@ -144,17 +144,13 @@ class BindAPI
/** /**
* @param String $domain * @param String $domain
* @param $panel
* *
* @return bool|void * @return bool|void
*/ */
function checkNS(String $domain, $panel) function checkNS(String $domain)
{ {
$nameServers = $this->nameserverController->findAll(); $nameServers = $this->nameserverController->findAll();
foreach($nameServers as $nameServer) { foreach($nameServers as $nameServer) {
if ($nameServer['name'] == 'ns1.24unix.net') {
continue;
}
echo COLOR_DEFAULT . ' ' . $nameServer['name']; echo COLOR_DEFAULT . ' ' . $nameServer['name'];
if (!empty($nameServer['aaaa'])) { if (!empty($nameServer['aaaa'])) {
$result = $this->checkController->sendCommand(serverName: $nameServer['name'], $result = $this->checkController->sendCommand(serverName: $nameServer['name'],
@ -170,39 +166,9 @@ class BindAPI
type: 'nameserver' . $domain); type: 'nameserver' . $domain);
} }
if ($result['header'] == 200) { if ($result['header'] == 200) {
echo COLOR_GREEN . ' OK'; return true;
} else { } else {
echo COLOR_RED . ' missing' . COLOR_DEFAULT; return false;
$arguments = $this->parseArguments();
if (!empty($arguments['fix']) && $arguments['fix'] == 'yes') {
echo 'trying to fix …';
$body = [
'name' => $domain,
'panel_id' => $panel['id']
];
if (!empty($nameServer['aaaa'])) {
$result = $this->checkController->sendCommand(
serverName: $nameServer['name'],
versionIP: 6,
apiKey: $nameServer['apikey'],
command: 'domains',
type: 'nameserver',
post: true,
body: $body);
} else {
$result =$this->checkController->sendCommand(
serverName: $nameServer['name'],
versionIP: 4,
apiKey: $nameServer['apikey'],
command: 'domains',
type: 'nameserver',
post: true,
body: $body);
}
die();
} else {
echo 'error';
}
} }
} }
echo PHP_EOL; echo PHP_EOL;
@ -242,7 +208,11 @@ class BindAPI
foreach ($domains as $domain) { foreach ($domains as $domain) {
if ($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) { if ($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) {
echo PHP_EOL . COLOR_DEFAULT . "check: " . COLOR_YELLOW . str_pad(string: $domain->domain, length: $maxDomainName); echo PHP_EOL . COLOR_DEFAULT . "check: " . COLOR_YELLOW . str_pad(string: $domain->domain, length: $maxDomainName);
$this->checkNS(domain: $domain->domain, panel: $panel); if ($this->checkNS(domain: $domain->domain)) {
echo COLOR_GREEN . ' OK';
} else {
echo COLOR_RED . 'Missing';
}
} }
} }
} else { } else {
@ -824,6 +794,8 @@ class BindAPI
$id = intval(value: $this->arguments[1] ?? 0); $id = intval(value: $this->arguments[1] ?? 0);
$name = $arguments['name'] ?? ''; $name = $arguments['name'] ?? '';
print_r(value: $arguments); //findme
print("$id: id" . PHP_EOL);
$panelID = intval(value: $arguments['panel_id'] ?? 0); $panelID = intval(value: $arguments['panel_id'] ?? 0);
$a = $arguments['a'] ?? ''; $a = $arguments['a'] ?? '';
$aaaa = $arguments['aaaa'] ?? ''; $aaaa = $arguments['aaaa'] ?? '';

View File

@ -19,7 +19,7 @@ class CheckController
* *
* @return array * @return array
*/ */
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type): array
{ {
$curl = curl_init(); $curl = curl_init();
if ($type == "panel") { if ($type == "panel") {
@ -38,10 +38,6 @@ class CheckController
curl_setopt(handle: $curl, option: CURLOPT_HTTPHEADER, value: ["X-API-Key:$apiKey"]); curl_setopt(handle: $curl, option: CURLOPT_HTTPHEADER, value: ["X-API-Key:$apiKey"]);
if ($post) {
curl_setopt($curl, option: CURLOPT_POST, value: true);
curl_setopt($curl, option: CURLOPT_POSTFIELDS, value: $body);
}
if ($resultJSON = curl_exec(handle: $curl)) { if ($resultJSON = curl_exec(handle: $curl)) {
$httpResponse = curl_getinfo(handle: $curl)['http_code']; $httpResponse = curl_getinfo(handle: $curl)['http_code'];
@ -62,7 +58,6 @@ class CheckController
$result = 'Missing or wrong API Key'; $result = 'Missing or wrong API Key';
break; break;
default: default:
echo __FILE__, __LINE__, $resultJSON;
$result = 'Unhandled error: ' . $httpResponse; $result = 'Unhandled error: ' . $httpResponse;
} }
} else { } else {

View File

@ -102,7 +102,7 @@ class DomainController
*/ */
public function insert(String $name, int $panelID, String $a, String $aaaa): bool|string public function insert(String $name, int $panelID, String $a, String $aaaa): bool|string
{ {
print("here"); // TODO create zone file and include
$sql = " $sql = "
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, panel_id, a, aaaa) INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, panel_id, a, aaaa)
VALUES (:name, :panel_id, :a, :aaaa)"; VALUES (:name, :panel_id, :a, :aaaa)";
@ -110,13 +110,13 @@ class DomainController
try { try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name); $statement->bindParam(param: ':name', var: $name);
$statement->bindParam(param: ':panel_id', var: $panelID); $statement->bindParam(param: ':panel_d', var: $panelID);
$statement->bindParam(param: ':a', var: $a); $statement->bindParam(param: ':a', var: $a);
$statement->bindParam(param: ':aaaa', var: $aaaa); $statement->bindParam(param: ':aaaa', var: $aaaa);
$statement->execute(); $statement->execute();
print(PHP_EOL . "there");
if ($panel = $this->panelController->findByID(id: intval(value: $panelID))) {
if ($panel = $this->panelController->findByID(id: $panelID)) {
$a = $panel['a']; $a = $panel['a'];
$aaaa = $panel['aaaa']; $aaaa = $panel['aaaa'];
} }
@ -209,19 +209,6 @@ class DomainController
} }
function createIncludeFile()
{
$domains = $this->findAll();
print("$this->localZoneFile");
$oFile = fopen(filename: $this->localZoneFile, mode: 'w');
foreach ($domains as $domain) {
fputs(stream: $oFile, data: 'include "' . $this->localZonesDir . $domain['name'] . '";' . PHP_EOL);
}
fclose(stream: $oFile);
}
/** /**
* @param $id * @param $id
* *
@ -229,15 +216,7 @@ class DomainController
*/ */
public function delete($id): int public function delete($id): int
{ {
if ($domain = $this->findByID(id: $id)) { // TODO delete zone file and include
$zoneFile = $this->localZonesDir . $domain['name'];
print($zoneFile . PHP_EOL);
if (file_exists(filename: $this->localZonesDir . $domain['name'])) {
print("file exists");
unlink(filename: $zoneFile);
}
}
$sql = " $sql = "
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . " DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
WHERE id = :id"; WHERE id = :id";
@ -246,8 +225,6 @@ class DomainController
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: 'id', var: $id); $statement->bindParam(param: 'id', var: $id);
$statement->execute(); $statement->execute();
$this->createIncludeFile();
return $statement->rowCount(); return $statement->rowCount();
} catch (PDOException $e) { } catch (PDOException $e) {
exit($e->getMessage()); exit($e->getMessage());

View File

@ -23,8 +23,7 @@ class NameserverController
{ {
$sql = " $sql = "
SELECT id, name, a, aaaa, apikey SELECT id, name, a, aaaa, apikey
FROM " . DatabaseConnection::TABLE_NAMESERVERS . " FROM " . DatabaseConnection::TABLE_NAMESERVERS;
ORDER BY name";
try { try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);

View File

@ -99,20 +99,15 @@ class RequestController
} else { } else {
[$prefix,] = explode(separator: '.', string: $apiKey); [$prefix,] = explode(separator: '.', string: $apiKey);
$apiUsers = new ApiKeys(databaseConnection: $this->databaseConnection); $apiUsers = new ApiKeys(databaseConnection: $this->databaseConnection);
if ($apiResult = $apiUsers->findByPrefix(prefix: $prefix)) { $apiResult = $apiUsers->findByPrefix(prefix: $prefix);
$storedHash = $apiResult['api_token']; $storedHash = $apiResult['api_token'];
if (!password_verify(password: $apiKey, hash: $storedHash)) { if (!password_verify(password: $apiKey, hash: $storedHash)) {
$this->header = "401 Unauthorized"; $this->header = "401 Unauthorized";
$this->status = "401 Unauthorized"; $this->status = "401 Unauthorized";
$this->message = "API key mismatch."; $this->message = "API key mismatch.";
return false; return false;
} }
} else {
$this->header = "401 Unauthorized";
$this->status = "401 Unauthorized";
$this->message = "API key not found.";
return false;
}
} }
return true; return true;
} }
@ -142,21 +137,18 @@ class RequestController
public function handleDomainPostRequest(): void public function handleDomainPostRequest(): void
{ {
$name = $_POST['name'] ?? ''; $name = $_POST['name'] ?? '';
$panelID = intval(value: $_POST['panel_id'] ?? 0); $panelID = $_POST['panel_id'] ?? '';
$a = $_POST['a'] ?? ''; $a = $_POST['a'] ?? '';
$aaaa = $_POST['aaaa'] ?? ''; $aaaa = $_POST['aaaa'] ?? '';
if (empty($name)) { if (empty($name)) {
$this->header = "400 Bad Request";
$this->status = "400 Bad Request"; $this->status = "400 Bad Request";
$this->message = "A name is required"; $this->message = "A name is required";
} else { } else {
if (empty($a) && empty($aaaa) && empty($panelID)) { if (empty($a) && empty($aaaa)) {
$this->header = "400 Bad Request";
$this->status = "400 Bad Request"; $this->status = "400 Bad Request";
$this->message = "At least one IP address or panel ID is required."; $this->message = "At least one IP address is required.";
} else { } else {
if ($this->domainController->findByName(name: $name)) { if ($this->domainController->findByName(name: $name)) {
$this->header = "400 Bad request";
$this->status = "400 Bad request"; $this->status = "400 Bad request";
$this->message = "Domain: $name already exists."; $this->message = "Domain: $name already exists.";
} else { } else {