modified version update
This commit is contained in:
parent
efb069eb5a
commit
26b0b6de6b
|
@ -2,7 +2,7 @@
|
||||||
"name": "24unix/bindapi",
|
"name": "24unix/bindapi",
|
||||||
"description": "manage Bind9 DNS server via REST API",
|
"description": "manage Bind9 DNS server via REST API",
|
||||||
"version": "1.0.9",
|
"version": "1.0.9",
|
||||||
"build_number": "368",
|
"build_number": "369",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Micha Espey",
|
"name": "Micha Espey",
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
"enum": [
|
"enum": [
|
||||||
"ns1.24unix.net",
|
"ns1.24unix.net",
|
||||||
"ns2.24unix.net",
|
"ns2.24unix.net",
|
||||||
"ns3.24unix.net"
|
"ns3.24unix.net",
|
||||||
|
"ns4.24unix.net"
|
||||||
],
|
],
|
||||||
"default": "ns2.24unix.net"
|
"default": "ns2.24unix.net"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
const DEFAULT_NS = 'ns2.24unix.net';
|
const DEFAULT_NS = 'ns2.24unix.net';
|
||||||
const NAMESERVERS = ['ns1.24unix.net', 'ns2.24unix.net', 'ns3.24unix.net'];
|
const NAMESERVERS = ['ns1.24unix.net', 'ns2.24unix.net', 'ns3.24unix.net', 'ns4.24unix.net'];
|
||||||
const VERSION = '1.0.9';
|
const VERSION = '1.0.9';
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class CLIController
|
||||||
$this->apikeysDelete();
|
$this->apikeysDelete();
|
||||||
},
|
},
|
||||||
mandatoryParameters: ['ID'])))
|
mandatoryParameters: ['ID'])))
|
||||||
->addCommandGroup(commandGroup: (new CommandGroup(name: 'cron', description: 'Run zone fle maintenance'))
|
->addCommandGroup(commandGroup: (new CommandGroup(name: 'cron', description: 'Run zone file maintenance'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name: 'run',
|
name: 'run',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
|
@ -129,6 +129,12 @@ class CLIController
|
||||||
$this->checkNameserver();
|
$this->checkNameserver();
|
||||||
},
|
},
|
||||||
description: 'Validate setting for this panel'))
|
description: 'Validate setting for this panel'))
|
||||||
|
->addCommand(command: new Command(
|
||||||
|
name: 'nameservers',
|
||||||
|
callback: function () {
|
||||||
|
$this->checkNameservers();
|
||||||
|
},
|
||||||
|
description: 'Check version on nameservers'))
|
||||||
->addCommand(command: new Command(
|
->addCommand(command: new Command(
|
||||||
name: 'domains',
|
name: 'domains',
|
||||||
callback: function () {
|
callback: function () {
|
||||||
|
@ -1164,6 +1170,88 @@ class CLIController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function checkNameserverVersion(Nameserver $server): bool
|
||||||
|
{
|
||||||
|
$this->logger->debug(message: "checkNameServerVersion() - server: " . $server->getName());
|
||||||
|
$error = false;
|
||||||
|
$skipAAAA = false;
|
||||||
|
|
||||||
|
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||||
|
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $server->getApikey(), key: $encryptionKey);
|
||||||
|
|
||||||
|
$a = $server->getA() ?? '';
|
||||||
|
if (!empty($a)) {
|
||||||
|
$this->logger->debug("check a version");
|
||||||
|
if ($result = $this->apiClient->sendCommand(
|
||||||
|
requestType: 'GET',
|
||||||
|
serverName: $server->getName(),
|
||||||
|
versionIP: 4,
|
||||||
|
apiKey: $decryptedKey,
|
||||||
|
command: 'version',
|
||||||
|
serverType: 'nameserver')) {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
if ($result['error'] === false) {
|
||||||
|
$data = $result['data'];
|
||||||
|
$decodedData = json_decode(json: $data);
|
||||||
|
echo COLOR_DEFAULT . ' Version: ' . COLOR_YELLOW . $decodedData->version;
|
||||||
|
echo COLOR_DEFAULT . ' (Build: ' . COLOR_YELLOW . $decodedData->buildnumber . COLOR_DEFAULT . ')' . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo COLOR_RED . ' Error: ' . COLOR_YELLOW . $result['data'] . COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
|
// var_dump($result);
|
||||||
|
$skipAAAA = true;
|
||||||
|
// if ($result['data'] == 'pong') {
|
||||||
|
// echo ' ' . COLOR_GREEN . $result['data'];
|
||||||
|
// } else {
|
||||||
|
// echo COLOR_BLUE . ' skip' . COLOR_DEFAULT;
|
||||||
|
// if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||||
|
// echo ' ' . $result['data'];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aaaa = $server->getAaaa() ?? '';
|
||||||
|
if (!empty($aaaa) && !$skipAAAA) {
|
||||||
|
$this->logger->debug("check aaaa version");
|
||||||
|
if ($result = $this->apiClient->sendCommand(
|
||||||
|
requestType: 'GET',
|
||||||
|
serverName: $server->getName(),
|
||||||
|
versionIP: 6,
|
||||||
|
apiKey: $decryptedKey,
|
||||||
|
command: 'version',
|
||||||
|
serverType: 'nameserver')) {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo $result;
|
||||||
|
// if ($result['data'] == 'pong') {
|
||||||
|
// echo ' ' . COLOR_GREEN . $result['data'];
|
||||||
|
// } else {
|
||||||
|
// echo COLOR_BLUE . ' xxskip' . COLOR_DEFAULT;
|
||||||
|
// if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||||
|
// echo ' ' . $result['data'];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sodium_memzero(string: $decryptedKey);
|
||||||
|
} catch (SodiumException $e) {
|
||||||
|
exit($e->getMessage() . PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->configController->getConfig(configKey: 'quiet')) {
|
||||||
|
echo COLOR_DEFAULT . PHP_EOL;
|
||||||
|
}
|
||||||
|
return !$error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -1572,7 +1660,7 @@ class CLIController
|
||||||
|
|
||||||
// FIXME add method create bootstrap php, add it to create, delete and update nameservers
|
// FIXME add method create bootstrap php, add it to create, delete and update nameservers
|
||||||
|
|
||||||
public function createOpenAPIBootstrap()
|
public function createOpenAPIBootstrap(): void
|
||||||
{
|
{
|
||||||
$basePath = $this->baseDir . '/public/openapi/';
|
$basePath = $this->baseDir . '/public/openapi/';
|
||||||
|
|
||||||
|
@ -2295,4 +2383,19 @@ const VERSION = '{$versionSting}';
|
||||||
$this->logger->info(message: 'cronRun()');
|
$this->logger->info(message: 'cronRun()');
|
||||||
$this->domainsUpdate();
|
$this->domainsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkNameservers()
|
||||||
|
{
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo 'Check nameserver versions:' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nameservers = $this->nameserverRepository->findAll();
|
||||||
|
foreach ($nameservers as $nameserver) {
|
||||||
|
if (!$this->quiet) {
|
||||||
|
echo COLOR_YELLOW . $nameserver->getName();
|
||||||
|
$this->checkNameserverVersion(server: $nameserver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,11 @@ class NameserverRepository
|
||||||
$apikey = $nameserver->getApikey();
|
$apikey = $nameserver->getApikey();
|
||||||
$apikeyPrefix = $nameserver->getApikeyPrefix();
|
$apikeyPrefix = $nameserver->getApikeyPrefix();
|
||||||
$self = $nameserver->getSelf();
|
$self = $nameserver->getSelf();
|
||||||
|
if ($self === '') {
|
||||||
|
$selfValue = 'no';
|
||||||
|
} else {
|
||||||
|
$selfValue = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
|
@ -145,7 +150,7 @@ class NameserverRepository
|
||||||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||||
$statement->bindParam(param: ':apikey', var: $apikey);
|
$statement->bindParam(param: ':apikey', var: $apikey);
|
||||||
$statement->bindParam(param: ':apikey_prefix', var: $apikeyPrefix);
|
$statement->bindParam(param: ':apikey_prefix', var: $apikeyPrefix);
|
||||||
$statement->bindParam(param: ':self', var: $self);
|
$statement->bindParam(param: ':self', var: $selfValue);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
return intval(value: $this->databaseConnection->getConnection()->lastInsertId());
|
return intval(value: $this->databaseConnection->getConnection()->lastInsertId());
|
||||||
|
|
|
@ -63,6 +63,7 @@ class ApiClient
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
$result = $resultJSON;
|
$result = $resultJSON;
|
||||||
|
$error = true;
|
||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
$result = 'Missing or wrong API Key';
|
$result = 'Missing or wrong API Key';
|
||||||
|
@ -70,11 +71,14 @@ class ApiClient
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
$result = '404 Not Found';
|
$result = '404 Not Found';
|
||||||
|
$error = true;
|
||||||
break;
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
$result = 'server error';
|
$result = 'server error';
|
||||||
|
$error = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
$error = true;
|
||||||
$result = 'Unhandled error: ' . $httpResponse;
|
$result = 'Unhandled error: ' . $httpResponse;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue