modified version update
This commit is contained in:
parent
efb069eb5a
commit
26b0b6de6b
|
@ -2,7 +2,7 @@
|
|||
"name": "24unix/bindapi",
|
||||
"description": "manage Bind9 DNS server via REST API",
|
||||
"version": "1.0.9",
|
||||
"build_number": "368",
|
||||
"build_number": "369",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Micha Espey",
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
"enum": [
|
||||
"ns1.24unix.net",
|
||||
"ns2.24unix.net",
|
||||
"ns3.24unix.net"
|
||||
"ns3.24unix.net",
|
||||
"ns4.24unix.net"
|
||||
],
|
||||
"default": "ns2.24unix.net"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
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';
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class CLIController
|
|||
$this->apikeysDelete();
|
||||
},
|
||||
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(
|
||||
name: 'run',
|
||||
callback: function () {
|
||||
|
@ -129,6 +129,12 @@ class CLIController
|
|||
$this->checkNameserver();
|
||||
},
|
||||
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(
|
||||
name: 'domains',
|
||||
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
|
||||
*/
|
||||
|
@ -1572,7 +1660,7 @@ class CLIController
|
|||
|
||||
// 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/';
|
||||
|
||||
|
@ -2295,4 +2383,19 @@ const VERSION = '{$versionSting}';
|
|||
$this->logger->info(message: 'cronRun()');
|
||||
$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();
|
||||
$apikeyPrefix = $nameserver->getApikeyPrefix();
|
||||
$self = $nameserver->getSelf();
|
||||
if ($self === '') {
|
||||
$selfValue = 'no';
|
||||
} else {
|
||||
$selfValue = $self;
|
||||
}
|
||||
|
||||
|
||||
$sql = "
|
||||
|
@ -145,7 +150,7 @@ class NameserverRepository
|
|||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||
$statement->bindParam(param: ':apikey', var: $apikey);
|
||||
$statement->bindParam(param: ':apikey_prefix', var: $apikeyPrefix);
|
||||
$statement->bindParam(param: ':self', var: $self);
|
||||
$statement->bindParam(param: ':self', var: $selfValue);
|
||||
$statement->execute();
|
||||
|
||||
return intval(value: $this->databaseConnection->getConnection()->lastInsertId());
|
||||
|
|
|
@ -63,6 +63,7 @@ class ApiClient
|
|||
break;
|
||||
case 400:
|
||||
$result = $resultJSON;
|
||||
$error = true;
|
||||
break;
|
||||
case 401:
|
||||
$result = 'Missing or wrong API Key';
|
||||
|
@ -70,11 +71,14 @@ class ApiClient
|
|||
break;
|
||||
case 404:
|
||||
$result = '404 Not Found';
|
||||
$error = true;
|
||||
break;
|
||||
case 500:
|
||||
$result = 'server error';
|
||||
$error = true;
|
||||
break;
|
||||
default:
|
||||
$error = true;
|
||||
$result = 'Unhandled error: ' . $httpResponse;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue