Compare commits
6 Commits
c31642a90e
...
2e779ed606
Author | SHA1 | Date |
---|---|---|
tracer | 2e779ed606 | |
tracer | d1182c6243 | |
tracer | d8b2082778 | |
tracer | 62790a01f3 | |
tracer | 283f5328df | |
tracer | 491c26e80c |
|
@ -26,7 +26,8 @@ class ApiKeys
|
||||||
FROM " . DatabaseConnection::TABLE_USER;
|
FROM " . DatabaseConnection::TABLE_USER;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->query(statement: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $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());
|
||||||
|
|
|
@ -144,13 +144,17 @@ class BindAPI
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $domain
|
* @param String $domain
|
||||||
|
* @param $panel
|
||||||
*
|
*
|
||||||
* @return bool|void
|
* @return bool|void
|
||||||
*/
|
*/
|
||||||
function checkNS(String $domain)
|
function checkNS(String $domain, $panel)
|
||||||
{
|
{
|
||||||
$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'],
|
||||||
|
@ -166,9 +170,39 @@ class BindAPI
|
||||||
type: 'nameserver' . $domain);
|
type: 'nameserver' . $domain);
|
||||||
}
|
}
|
||||||
if ($result['header'] == 200) {
|
if ($result['header'] == 200) {
|
||||||
return true;
|
echo COLOR_GREEN . ' OK';
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
@ -208,11 +242,7 @@ 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);
|
||||||
if ($this->checkNS(domain: $domain->domain)) {
|
$this->checkNS(domain: $domain->domain, panel: $panel);
|
||||||
echo COLOR_GREEN . ' OK';
|
|
||||||
} else {
|
|
||||||
echo COLOR_RED . 'Missing';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -794,8 +824,6 @@ 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'] ?? '';
|
||||||
|
|
|
@ -19,7 +19,7 @@ class CheckController
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type): array
|
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array
|
||||||
{
|
{
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
if ($type == "panel") {
|
if ($type == "panel") {
|
||||||
|
@ -38,6 +38,10 @@ 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'];
|
||||||
|
|
||||||
|
@ -58,6 +62,7 @@ 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 {
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
// TODO create zone file and include
|
print("here");
|
||||||
$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_d', var: $panelID);
|
$statement->bindParam(param: ':panel_id', 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,6 +209,19 @@ 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
|
||||||
*
|
*
|
||||||
|
@ -216,7 +229,15 @@ class DomainController
|
||||||
*/
|
*/
|
||||||
public function delete($id): int
|
public function delete($id): int
|
||||||
{
|
{
|
||||||
// TODO delete zone file and include
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
@ -225,6 +246,8 @@ 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());
|
||||||
|
|
|
@ -23,7 +23,8 @@ 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);
|
||||||
|
|
|
@ -99,15 +99,20 @@ 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);
|
||||||
$apiResult = $apiUsers->findByPrefix(prefix: $prefix);
|
if ($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;
|
||||||
}
|
}
|
||||||
|
@ -137,18 +142,21 @@ class RequestController
|
||||||
public function handleDomainPostRequest(): void
|
public function handleDomainPostRequest(): void
|
||||||
{
|
{
|
||||||
$name = $_POST['name'] ?? '';
|
$name = $_POST['name'] ?? '';
|
||||||
$panelID = $_POST['panel_id'] ?? '';
|
$panelID = intval(value: $_POST['panel_id'] ?? 0);
|
||||||
$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)) {
|
if (empty($a) && empty($aaaa) && empty($panelID)) {
|
||||||
|
$this->header = "400 Bad Request";
|
||||||
$this->status = "400 Bad Request";
|
$this->status = "400 Bad Request";
|
||||||
$this->message = "At least one IP address is required.";
|
$this->message = "At least one IP address or panel ID 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 {
|
||||||
|
|
Loading…
Reference in New Issue