added curl timing
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
ff5160d9bd
commit
b3ce1d9dbf
|
@ -145,6 +145,8 @@ class BindAPI
|
||||||
echo COLOR_GREEN . "\t check:permissions" . PHP_EOL;
|
echo COLOR_GREEN . "\t check:permissions" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t check:panels {ID} {fix=yes}" . PHP_EOL;
|
echo COLOR_GREEN . "\t check:panels {ID} {fix=yes}" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t check:domains {ID} {fix=yes}" . PHP_EOL;
|
echo COLOR_GREEN . "\t check:domains {ID} {fix=yes}" . PHP_EOL;
|
||||||
|
echo COLOR_GREEN . "\t check:showinclude" . COLOR_DEFAULT . " Temporary needed until KeyHelp 22.1" . PHP_EOL;
|
||||||
|
|
||||||
|
|
||||||
echo COLOR_YELLOW . "panels" . COLOR_DEFAULT . "\t all Keyhelp systems configured" . PHP_EOL;
|
echo COLOR_YELLOW . "panels" . COLOR_DEFAULT . "\t all Keyhelp systems configured" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t panels:list" . PHP_EOL;
|
echo COLOR_GREEN . "\t panels:list" . PHP_EOL;
|
||||||
|
@ -185,6 +187,7 @@ class BindAPI
|
||||||
match ($subcommand) {
|
match ($subcommand) {
|
||||||
'permissions' => $this->handleCheckPermissions(),
|
'permissions' => $this->handleCheckPermissions(),
|
||||||
'panels' => $this->handleCheckPanels(),
|
'panels' => $this->handleCheckPanels(),
|
||||||
|
'showincludes' => $this->showIncludes(),
|
||||||
};
|
};
|
||||||
} catch (UnhandledMatchError) {
|
} catch (UnhandledMatchError) {
|
||||||
echo 'Unknown action: ' . $subcommand . PHP_EOL;
|
echo 'Unknown action: ' . $subcommand . PHP_EOL;
|
||||||
|
@ -245,16 +248,59 @@ class BindAPI
|
||||||
$this->log->debug(message: "checkSinglePanel()");
|
$this->log->debug(message: "checkSinglePanel()");
|
||||||
}
|
}
|
||||||
|
|
||||||
echo COLOR_DEFAULT . 'Keyhelp-Panel: ' . COLOR_YELLOW . $panel->getName() . PHP_EOL;
|
echo COLOR_DEFAULT . 'Keyhelp-Panel: ' . COLOR_YELLOW . $panel->getName();
|
||||||
if (!empty($panel->getAaaa())) {
|
|
||||||
|
if ($this->config['verbose']) {
|
||||||
|
if (empty($panel->getA())) {
|
||||||
|
try {
|
||||||
|
$panelRequest = $this->apiController->sendCommand(
|
||||||
|
requestType: 'GET',
|
||||||
|
serverName : $panel->getName(),
|
||||||
|
versionIP : 6,
|
||||||
|
apiKey : $panel->getApikey(),
|
||||||
|
command : '/server',
|
||||||
|
serverType : 'panel');
|
||||||
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
|
echo $e->getMessage();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$panelRequest = $this->apiController->sendCommand(
|
||||||
|
requestType: 'GET',
|
||||||
|
serverName : $panel->getName(),
|
||||||
|
versionIP : 4,
|
||||||
|
apiKey : $panel->getApikey(),
|
||||||
|
command : '/server',
|
||||||
|
serverType : 'panel');
|
||||||
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
|
echo $e->getMessage();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$panelData = json_decode(json: $panelRequest['data']);
|
||||||
|
if (!empty($panelData)) {
|
||||||
|
$panelVersion = $panelData->meta->panel_version;
|
||||||
|
$responseTime = sprintf("%0.3f", $panelRequest['responseTime']);
|
||||||
|
} else {
|
||||||
|
$panelVersion = 'n/a';
|
||||||
|
$responseTime = 'n/a';
|
||||||
|
}
|
||||||
|
echo COLOR_DEFAULT . ' KeyHelp version: ' . $panelVersion . " ($responseTime seconds)" . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($panel->getA())) {
|
||||||
try {
|
try {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName: $panel->getName(),
|
serverName : $panel->getName(),
|
||||||
versionIP: 6,
|
versionIP : 6,
|
||||||
apiKey: $panel->getApikey(),
|
apiKey : $panel->getApikey(),
|
||||||
command: 'domains',
|
command : 'domains',
|
||||||
serverType: 'panel'
|
serverType : 'panel'
|
||||||
);
|
);
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
|
@ -263,16 +309,17 @@ class BindAPI
|
||||||
try {
|
try {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName: $panel->getName(),
|
serverName : $panel->getName(),
|
||||||
versionIP: 4,
|
versionIP : 4,
|
||||||
apiKey: $panel->getApikey(),
|
apiKey : $panel->getApikey(),
|
||||||
command: 'domains',
|
command : 'domains',
|
||||||
serverType: 'panel');
|
serverType : 'panel');
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!empty($result['error'])) {
|
if (!empty($result['error'])) {
|
||||||
echo $result['data'] . PHP_EOL;
|
echo $result['data'] . PHP_EOL;
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -295,7 +342,7 @@ class BindAPI
|
||||||
$domainCount = 0;
|
$domainCount = 0;
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
if ($this->isValidSecondLevelDomain(domainName: $domain->domain, panel: $panel->getName(), parent: $domain->id_parent_domain)) {
|
if ($this->isValidSecondLevelDomain(domainName: $domain->domain, panel: $panel->getName(), parent: $domain->id_parent_domain)) {
|
||||||
echo COLOR_DEFAULT . "Domain: " . COLOR_YELLOW . str_pad(string: $domain->domain, length: $maxDomainName);
|
echo COLOR_DEFAULT . " Domain: " . COLOR_YELLOW . str_pad(string: $domain->domain, length: $maxDomainName);
|
||||||
try {
|
try {
|
||||||
$this->checkNS(domainName: $domain->domain, panel: $panel);
|
$this->checkNS(domainName: $domain->domain, panel: $panel);
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
|
@ -306,9 +353,9 @@ class BindAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($domainCount == 0) {
|
if ($domainCount == 0) {
|
||||||
echo 'No second level domains found.' . PHP_EOL;
|
echo 'No second level domains found.' . COLOR_DEFAULT . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
echo PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidSecondLevelDomain(string $domainName, string $panel, int $parent): bool
|
function isValidSecondLevelDomain(string $domainName, string $panel, int $parent): bool
|
||||||
|
@ -371,19 +418,19 @@ class BindAPI
|
||||||
if (!empty($nameServer->getName())) {
|
if (!empty($nameServer->getName())) {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName: $nameServer->getName(),
|
serverName : $nameServer->getName(),
|
||||||
versionIP: 6,
|
versionIP : 6,
|
||||||
apiKey: $nameServer->getApikey(),
|
apiKey : $nameServer->getApikey(),
|
||||||
command: 'domains/name/' . $domainName,
|
command : 'domains/name/' . $domainName,
|
||||||
serverType: 'nameserver');
|
serverType : 'nameserver');
|
||||||
} else {
|
} else {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName: $nameServer->getName(),
|
serverName : $nameServer->getName(),
|
||||||
versionIP: 4,
|
versionIP : 4,
|
||||||
apiKey: $nameServer->getApikey(),
|
apiKey : $nameServer->getApikey(),
|
||||||
command: 'domains/name/',
|
command : 'domains/name/',
|
||||||
serverType: 'nameserver' . $domainName);
|
serverType : 'nameserver' . $domainName);
|
||||||
}
|
}
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
|
@ -408,21 +455,21 @@ class BindAPI
|
||||||
if (!empty($nameServer->getAaaa())) {
|
if (!empty($nameServer->getAaaa())) {
|
||||||
$create = $this->apiController->sendCommand(
|
$create = $this->apiController->sendCommand(
|
||||||
requestType: 'POST',
|
requestType: 'POST',
|
||||||
serverName: $nameServer->getName(),
|
serverName : $nameServer->getName(),
|
||||||
versionIP: 6,
|
versionIP : 6,
|
||||||
apiKey: $nameServer->getApikey(),
|
apiKey : $nameServer->getApikey(),
|
||||||
command: 'domains',
|
command : 'domains',
|
||||||
serverType: 'nameserver',
|
serverType : 'nameserver',
|
||||||
body: $body);
|
body : $body);
|
||||||
} else {
|
} else {
|
||||||
$create = $this->apiController->sendCommand(
|
$create = $this->apiController->sendCommand(
|
||||||
requestType: 'POST',
|
requestType: 'POST',
|
||||||
serverName: $nameServer->getName(),
|
serverName : $nameServer->getName(),
|
||||||
versionIP: 4,
|
versionIP : 4,
|
||||||
apiKey: $nameServer->getAPikey(),
|
apiKey : $nameServer->getAPikey(),
|
||||||
command: 'domains',
|
command : 'domains',
|
||||||
serverType: 'nameserver',
|
serverType : 'nameserver',
|
||||||
body: $body);
|
body : $body);
|
||||||
}
|
}
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
|
@ -748,11 +795,11 @@ class BindAPI
|
||||||
try {
|
try {
|
||||||
if ($result = $this->apiController->sendCommand(
|
if ($result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName: $server->getName(),
|
serverName : $server->getName(),
|
||||||
versionIP: 4,
|
versionIP : 4,
|
||||||
apiKey: $server->getApikey(),
|
apiKey : $server->getApikey(),
|
||||||
command: 'ping',
|
command : 'ping',
|
||||||
serverType: $type)) {
|
serverType : $type)) {
|
||||||
if ($this->config['verbose']) {
|
if ($this->config['verbose']) {
|
||||||
if ($result['data'] == 'pong') {
|
if ($result['data'] == 'pong') {
|
||||||
echo COLOR_GREEN . $result['data'];
|
echo COLOR_GREEN . $result['data'];
|
||||||
|
@ -775,11 +822,11 @@ class BindAPI
|
||||||
try {
|
try {
|
||||||
if ($result = $this->apiController->sendCommand(
|
if ($result = $this->apiController->sendCommand(
|
||||||
requestType: 'GET',
|
requestType: 'GET',
|
||||||
serverName: $server->getName(),
|
serverName : $server->getName(),
|
||||||
versionIP: 6,
|
versionIP : 6,
|
||||||
apiKey: $server->getApikey(),
|
apiKey : $server->getApikey(),
|
||||||
command: 'ping',
|
command : 'ping',
|
||||||
serverType: $type)) {
|
serverType : $type)) {
|
||||||
if ($this->config['verbose']) {
|
if ($this->config['verbose']) {
|
||||||
if ($result['data'] == 'pong') {
|
if ($result['data'] == 'pong') {
|
||||||
echo COLOR_GREEN . $result['data'];
|
echo COLOR_GREEN . $result['data'];
|
||||||
|
@ -969,28 +1016,14 @@ class BindAPI
|
||||||
}
|
}
|
||||||
if (!empty($domains)) {
|
if (!empty($domains)) {
|
||||||
$table = new ConsoleTable();
|
$table = new ConsoleTable();
|
||||||
$table->setHeaders(content: ['ID', 'Name', 'Content']);
|
$table->setHeaders(content: ['ID', 'Name', 'Panel']);
|
||||||
/** @var Domain $domain */
|
/** @var Domain $domain */
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$row = [];
|
$row = [];
|
||||||
try {
|
try {
|
||||||
$row[] = $domain->getId();
|
$row[] = $domain->getId();
|
||||||
$row[] = $domain->getName();
|
$row[] = $domain->getName();
|
||||||
$content = json_decode(json: $domain->getContent());
|
$row[] = $domain->getPanel();
|
||||||
$column = '';
|
|
||||||
if (!empty($content->panel)) {
|
|
||||||
$column = 'Panel: ' . $content->panel;
|
|
||||||
}
|
|
||||||
if (!empty($content->custom)) {
|
|
||||||
$column .= 'Custom: ';
|
|
||||||
if (!empty($content->custom->a)) {
|
|
||||||
$column .= 'A: ' . $content->custom->a;
|
|
||||||
}
|
|
||||||
if (!empty($content->custom->aaaa)) {
|
|
||||||
$column .= ' AAAA: ' . $content->custom->a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$row[] = $column;
|
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
}
|
}
|
||||||
|
@ -1023,16 +1056,11 @@ class BindAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = $this->parseArguments();
|
$arguments = $this->parseArguments();
|
||||||
|
|
||||||
|
|
||||||
$a = $arguments['a'] ?? '';
|
|
||||||
$aaaa = $arguments['aaaa'] ?? '';
|
|
||||||
$panel = $arguments['panel'] ?? '';
|
$panel = $arguments['panel'] ?? '';
|
||||||
|
|
||||||
print("panel: $panel");
|
if (empty($panel)) {
|
||||||
if (empty($a) && empty($aaaa) && empty($panel)) {
|
echo 'You need to supply the panel name.' . PHP_EOL;
|
||||||
echo 'At least one IP address or panel is required.' . PHP_EOL;
|
exit(1);
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1040,24 +1068,13 @@ class BindAPI
|
||||||
echo "Domain: $name already exists." . PHP_EOL;
|
echo "Domain: $name already exists." . PHP_EOL;
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
if (!empty($panel)) {
|
|
||||||
if ($this->panelRepository->findByName(name: $panel)) {
|
if ($this->panelRepository->findByName(name: $panel)) {
|
||||||
$content = $this->domainController->createPanelContent(panel: $panel);
|
$content = $this->domainController->createPanelContent(panel: $panel);
|
||||||
} else {
|
} else {
|
||||||
echo 'Unknown panel: ' . $panel;
|
echo 'Unknown panel: ' . $panel;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
$domain = new Domain(name: $name, panel: $panel);
|
||||||
$content = [];
|
|
||||||
if (!empty($a)) {
|
|
||||||
$content['a'] = $a;
|
|
||||||
}
|
|
||||||
if (!empty($aaaa)) {
|
|
||||||
$content['aaaa'] = $aaaa;
|
|
||||||
}
|
|
||||||
$content = $this->domainController->createIPContent(ip: $content);
|
|
||||||
}
|
|
||||||
$domain = new Domain(name: $name, content: $content);
|
|
||||||
$result = $this->domainRepository->insert(domain: $domain);
|
$result = $this->domainRepository->insert(domain: $domain);
|
||||||
echo "Domain $name has been created with id $result" . PHP_EOL;
|
echo "Domain $name has been created with id $result" . PHP_EOL;
|
||||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||||
|
@ -1078,9 +1095,7 @@ class BindAPI
|
||||||
|
|
||||||
$id = intval(value: $this->arguments[1] ?? 0);
|
$id = intval(value: $this->arguments[1] ?? 0);
|
||||||
$name = $arguments['name'] ?? '';
|
$name = $arguments['name'] ?? '';
|
||||||
$panel = $arguments['panel'] ?? '';
|
$panelName = $arguments['panel'] ?? '';
|
||||||
$a = $arguments['a'] ?? '';
|
|
||||||
$aaaa = $arguments['aaaa'] ?? '';
|
|
||||||
|
|
||||||
if ($id == 0) {
|
if ($id == 0) {
|
||||||
echo 'An ID is required' . PHP_EOL;
|
echo 'An ID is required' . PHP_EOL;
|
||||||
|
@ -1093,35 +1108,17 @@ class BindAPI
|
||||||
|
|
||||||
|
|
||||||
$content = [];
|
$content = [];
|
||||||
if (!empty($panel)) {
|
if (!empty($panelName)) {
|
||||||
$panel = $this->panelRepository->findByName(name: $panel);
|
$panel = $this->panelRepository->findByName(name: $panelName);
|
||||||
$content = $this->domainController->createPanelContent(panel: $panel->getName());
|
|
||||||
} else {
|
|
||||||
$addresses = [];
|
|
||||||
if (!empty($a)) {
|
|
||||||
$addresses[] = [
|
|
||||||
'a' => $a
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
if (!empty($aaaa)) {
|
|
||||||
$addresses[] = [
|
if (empty($name) && empty($panel)) {
|
||||||
'aaaa' => $aaaa
|
|
||||||
];
|
|
||||||
}
|
|
||||||
if (!empty($addresses)) {
|
|
||||||
$content = $this->domainController->createIPContent(ip: $content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($name) && empty($content)) {
|
|
||||||
echo 'No name or panel given, just recreate the config file' . PHP_EOL;
|
echo 'No name or panel given, just recreate the config file' . PHP_EOL;
|
||||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (empty($content)) {
|
$newDomain = new Domain(name: $name, panel: $panelName, id: $domain->getId());
|
||||||
$newDomain = new Domain(name: $name, id: $domain->getId(), content: '');
|
|
||||||
} else {
|
|
||||||
$newDomain = new Domain(name: $name, id: $domain->getId(), content: $content);
|
|
||||||
}
|
|
||||||
if ($this->domainRepository->update(domain: $newDomain) !== false) {
|
if ($this->domainRepository->update(domain: $newDomain) !== false) {
|
||||||
echo 'Domain server has been updated' . PHP_EOL;
|
echo 'Domain server has been updated' . PHP_EOL;
|
||||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||||
|
@ -1319,4 +1316,36 @@ class BindAPI
|
||||||
$this->nameserverRepository->delete(id: $id);
|
$this->nameserverRepository->delete(id: $id);
|
||||||
echo "The nameserver with ID $id has been deleted." . PHP_EOL;
|
echo "The nameserver with ID $id has been deleted." . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \DI\DependencyException
|
||||||
|
* @throws \DI\NotFoundException
|
||||||
|
*/
|
||||||
|
private function showIncludes()
|
||||||
|
{
|
||||||
|
$nameservers = $this->nameserverRepository->findAll();
|
||||||
|
|
||||||
|
echo COLOR_DEFAULT . 'You need to add these lines to ' . COLOR_YELLOW . '/etc/bind/local.bindapi.options' . COLOR_DEFAULT . ' and make sure' . PHP_EOL;
|
||||||
|
echo 'that ' . COLOR_YELLOW . 'include "/etc/bind/local.bindapi.options";' . COLOR_DEFAULT . ' exists in ' . COLOR_YELLOW . '/etc/bind/named.conf.options' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||||
|
$ip = [];
|
||||||
|
foreach ($nameservers as $nameserver) {
|
||||||
|
if (!empty($nameserver->getA())) {
|
||||||
|
$ip[] = $nameserver->getA();
|
||||||
|
}
|
||||||
|
if (!empty($nameserver->getAaaa())) {
|
||||||
|
$ip[] = $nameserver->getAaaa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo PHP_EOL . 'allow-transfer {' . PHP_EOL;
|
||||||
|
foreach ($ip as $currentIp)
|
||||||
|
echo "\t$currentIp;" . PHP_EOL;
|
||||||
|
echo '};';
|
||||||
|
echo PHP_EOL . 'also-notify {' . PHP_EOL;
|
||||||
|
foreach ($ip as $currentIp)
|
||||||
|
echo "\t$currentIp;" . PHP_EOL;
|
||||||
|
echo '};' . PHP_EOL;
|
||||||
|
echo PHP_EOL . 'After the modification feel free to run ' . COLOR_YELLOW . 'named-checkconf' . COLOR_DEFAULT . ' to ensure there were no errors.' . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue