Compare commits
No commits in common. "2e779ed6067cfd44cfd216190d4026173e346665" and "c31642a90e5089b46de10659cb0035d57f205654" have entirely different histories.
2e779ed606
...
c31642a90e
|
@ -26,8 +26,7 @@ class ApiKeys
|
|||
FROM " . DatabaseConnection::TABLE_USER;
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
$statement = $this->databaseConnection->getConnection()->query(statement: $sql);
|
||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
|
|
|
@ -144,17 +144,13 @@ class BindAPI
|
|||
|
||||
/**
|
||||
* @param String $domain
|
||||
* @param $panel
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
function checkNS(String $domain, $panel)
|
||||
function checkNS(String $domain)
|
||||
{
|
||||
$nameServers = $this->nameserverController->findAll();
|
||||
foreach($nameServers as $nameServer) {
|
||||
if ($nameServer['name'] == 'ns1.24unix.net') {
|
||||
continue;
|
||||
}
|
||||
echo COLOR_DEFAULT . ' ' . $nameServer['name'];
|
||||
if (!empty($nameServer['aaaa'])) {
|
||||
$result = $this->checkController->sendCommand(serverName: $nameServer['name'],
|
||||
|
@ -170,39 +166,9 @@ class BindAPI
|
|||
type: 'nameserver' . $domain);
|
||||
}
|
||||
if ($result['header'] == 200) {
|
||||
echo COLOR_GREEN . ' OK';
|
||||
return true;
|
||||
} else {
|
||||
echo COLOR_RED . ' missing' . COLOR_DEFAULT;
|
||||
$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';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
echo PHP_EOL;
|
||||
|
@ -242,7 +208,11 @@ class BindAPI
|
|||
foreach ($domains as $domain) {
|
||||
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);
|
||||
$this->checkNS(domain: $domain->domain, panel: $panel);
|
||||
if ($this->checkNS(domain: $domain->domain)) {
|
||||
echo COLOR_GREEN . ' OK';
|
||||
} else {
|
||||
echo COLOR_RED . 'Missing';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -824,6 +794,8 @@ class BindAPI
|
|||
|
||||
$id = intval(value: $this->arguments[1] ?? 0);
|
||||
$name = $arguments['name'] ?? '';
|
||||
print_r(value: $arguments); //findme
|
||||
print("$id: id" . PHP_EOL);
|
||||
$panelID = intval(value: $arguments['panel_id'] ?? 0);
|
||||
$a = $arguments['a'] ?? '';
|
||||
$aaaa = $arguments['aaaa'] ?? '';
|
||||
|
|
|
@ -19,7 +19,7 @@ class CheckController
|
|||
*
|
||||
* @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();
|
||||
if ($type == "panel") {
|
||||
|
@ -38,10 +38,6 @@ class CheckController
|
|||
|
||||
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)) {
|
||||
$httpResponse = curl_getinfo(handle: $curl)['http_code'];
|
||||
|
||||
|
@ -62,7 +58,6 @@ class CheckController
|
|||
$result = 'Missing or wrong API Key';
|
||||
break;
|
||||
default:
|
||||
echo __FILE__, __LINE__, $resultJSON;
|
||||
$result = 'Unhandled error: ' . $httpResponse;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -102,7 +102,7 @@ class DomainController
|
|||
*/
|
||||
public function insert(String $name, int $panelID, String $a, String $aaaa): bool|string
|
||||
{
|
||||
print("here");
|
||||
// TODO create zone file and include
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, panel_id, a, aaaa)
|
||||
VALUES (:name, :panel_id, :a, :aaaa)";
|
||||
|
@ -110,13 +110,13 @@ class DomainController
|
|||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$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: ':aaaa', var: $aaaa);
|
||||
$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'];
|
||||
$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
|
||||
*
|
||||
|
@ -229,15 +216,7 @@ class DomainController
|
|||
*/
|
||||
public function delete($id): int
|
||||
{
|
||||
if ($domain = $this->findByID(id: $id)) {
|
||||
$zoneFile = $this->localZonesDir . $domain['name'];
|
||||
print($zoneFile . PHP_EOL);
|
||||
if (file_exists(filename: $this->localZonesDir . $domain['name'])) {
|
||||
print("file exists");
|
||||
unlink(filename: $zoneFile);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO delete zone file and include
|
||||
$sql = "
|
||||
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
WHERE id = :id";
|
||||
|
@ -246,8 +225,6 @@ class DomainController
|
|||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: 'id', var: $id);
|
||||
$statement->execute();
|
||||
|
||||
$this->createIncludeFile();
|
||||
return $statement->rowCount();
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
|
|
|
@ -23,8 +23,7 @@ class NameserverController
|
|||
{
|
||||
$sql = "
|
||||
SELECT id, name, a, aaaa, apikey
|
||||
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||
ORDER BY name";
|
||||
FROM " . DatabaseConnection::TABLE_NAMESERVERS;
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
|
|
|
@ -99,20 +99,15 @@ class RequestController
|
|||
} else {
|
||||
[$prefix,] = explode(separator: '.', string: $apiKey);
|
||||
$apiUsers = new ApiKeys(databaseConnection: $this->databaseConnection);
|
||||
if ($apiResult = $apiUsers->findByPrefix(prefix: $prefix)) {
|
||||
$apiResult = $apiUsers->findByPrefix(prefix: $prefix);
|
||||
$storedHash = $apiResult['api_token'];
|
||||
|
||||
if (!password_verify(password: $apiKey, hash: $storedHash)) {
|
||||
$this->header = "401 Unauthorized";
|
||||
$this->status = "401 Unauthorized";
|
||||
$this->message = "API key mismatch.";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->header = "401 Unauthorized";
|
||||
$this->status = "401 Unauthorized";
|
||||
$this->message = "API key not found.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -142,21 +137,18 @@ class RequestController
|
|||
public function handleDomainPostRequest(): void
|
||||
{
|
||||
$name = $_POST['name'] ?? '';
|
||||
$panelID = intval(value: $_POST['panel_id'] ?? 0);
|
||||
$panelID = $_POST['panel_id'] ?? '';
|
||||
$a = $_POST['a'] ?? '';
|
||||
$aaaa = $_POST['aaaa'] ?? '';
|
||||
if (empty($name)) {
|
||||
$this->header = "400 Bad Request";
|
||||
$this->status = "400 Bad Request";
|
||||
$this->message = "A name is required";
|
||||
} else {
|
||||
if (empty($a) && empty($aaaa) && empty($panelID)) {
|
||||
$this->header = "400 Bad Request";
|
||||
if (empty($a) && empty($aaaa)) {
|
||||
$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 {
|
||||
if ($this->domainController->findByName(name: $name)) {
|
||||
$this->header = "400 Bad request";
|
||||
$this->status = "400 Bad request";
|
||||
$this->message = "Domain: $name already exists.";
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue