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:panels {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_GREEN . "\t panels:list" . PHP_EOL;
|
||||
@ -185,6 +187,7 @@ class BindAPI
|
||||
match ($subcommand) {
|
||||
'permissions' => $this->handleCheckPermissions(),
|
||||
'panels' => $this->handleCheckPanels(),
|
||||
'showincludes' => $this->showIncludes(),
|
||||
};
|
||||
} catch (UnhandledMatchError) {
|
||||
echo 'Unknown action: ' . $subcommand . PHP_EOL;
|
||||
@ -245,16 +248,59 @@ class BindAPI
|
||||
$this->log->debug(message: "checkSinglePanel()");
|
||||
}
|
||||
|
||||
echo COLOR_DEFAULT . 'Keyhelp-Panel: ' . COLOR_YELLOW . $panel->getName() . PHP_EOL;
|
||||
if (!empty($panel->getAaaa())) {
|
||||
echo COLOR_DEFAULT . 'Keyhelp-Panel: ' . COLOR_YELLOW . $panel->getName();
|
||||
|
||||
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 {
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'domains',
|
||||
serverType: 'panel'
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'domains',
|
||||
serverType : 'panel'
|
||||
);
|
||||
} catch (DependencyException|NotFoundException $e) {
|
||||
echo $e->getMessage();
|
||||
@ -263,16 +309,17 @@ class BindAPI
|
||||
try {
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'domains',
|
||||
serverType: 'panel');
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'domains',
|
||||
serverType : 'panel');
|
||||
} catch (DependencyException|NotFoundException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($result['error'])) {
|
||||
echo $result['data'] . PHP_EOL;
|
||||
exit(1);
|
||||
@ -295,7 +342,7 @@ class BindAPI
|
||||
$domainCount = 0;
|
||||
foreach ($domains as $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 {
|
||||
$this->checkNS(domainName: $domain->domain, panel: $panel);
|
||||
} catch (DependencyException|NotFoundException $e) {
|
||||
@ -306,9 +353,9 @@ class BindAPI
|
||||
}
|
||||
}
|
||||
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
|
||||
@ -371,19 +418,19 @@ class BindAPI
|
||||
if (!empty($nameServer->getName())) {
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $nameServer->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $nameServer->getApikey(),
|
||||
command: 'domains/name/' . $domainName,
|
||||
serverType: 'nameserver');
|
||||
serverName : $nameServer->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $nameServer->getApikey(),
|
||||
command : 'domains/name/' . $domainName,
|
||||
serverType : 'nameserver');
|
||||
} else {
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $nameServer->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $nameServer->getApikey(),
|
||||
command: 'domains/name/',
|
||||
serverType: 'nameserver' . $domainName);
|
||||
serverName : $nameServer->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $nameServer->getApikey(),
|
||||
command : 'domains/name/',
|
||||
serverType : 'nameserver' . $domainName);
|
||||
}
|
||||
} catch (DependencyException|NotFoundException $e) {
|
||||
echo $e->getMessage();
|
||||
@ -403,26 +450,26 @@ class BindAPI
|
||||
'name' => $domainName,
|
||||
'panel' => $panel->getName(),
|
||||
'content' => $this->domainController->createPanelContent(panel: $panel->getName())
|
||||
];
|
||||
];
|
||||
try {
|
||||
if (!empty($nameServer->getAaaa())) {
|
||||
$create = $this->apiController->sendCommand(
|
||||
requestType: 'POST',
|
||||
serverName: $nameServer->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $nameServer->getApikey(),
|
||||
command: 'domains',
|
||||
serverType: 'nameserver',
|
||||
body: $body);
|
||||
serverName : $nameServer->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $nameServer->getApikey(),
|
||||
command : 'domains',
|
||||
serverType : 'nameserver',
|
||||
body : $body);
|
||||
} else {
|
||||
$create = $this->apiController->sendCommand(
|
||||
requestType: 'POST',
|
||||
serverName: $nameServer->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $nameServer->getAPikey(),
|
||||
command: 'domains',
|
||||
serverType: 'nameserver',
|
||||
body: $body);
|
||||
serverName : $nameServer->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $nameServer->getAPikey(),
|
||||
command : 'domains',
|
||||
serverType : 'nameserver',
|
||||
body : $body);
|
||||
}
|
||||
} catch (DependencyException|NotFoundException $e) {
|
||||
echo $e->getMessage();
|
||||
@ -748,11 +795,11 @@ class BindAPI
|
||||
try {
|
||||
if ($result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $server->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $server->getApikey(),
|
||||
command: 'ping',
|
||||
serverType: $type)) {
|
||||
serverName : $server->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $server->getApikey(),
|
||||
command : 'ping',
|
||||
serverType : $type)) {
|
||||
if ($this->config['verbose']) {
|
||||
if ($result['data'] == 'pong') {
|
||||
echo COLOR_GREEN . $result['data'];
|
||||
@ -775,11 +822,11 @@ class BindAPI
|
||||
try {
|
||||
if ($result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $server->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $server->getApikey(),
|
||||
command: 'ping',
|
||||
serverType: $type)) {
|
||||
serverName : $server->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $server->getApikey(),
|
||||
command : 'ping',
|
||||
serverType : $type)) {
|
||||
if ($this->config['verbose']) {
|
||||
if ($result['data'] == 'pong') {
|
||||
echo COLOR_GREEN . $result['data'];
|
||||
@ -969,28 +1016,14 @@ class BindAPI
|
||||
}
|
||||
if (!empty($domains)) {
|
||||
$table = new ConsoleTable();
|
||||
$table->setHeaders(content: ['ID', 'Name', 'Content']);
|
||||
$table->setHeaders(content: ['ID', 'Name', 'Panel']);
|
||||
/** @var Domain $domain */
|
||||
foreach ($domains as $domain) {
|
||||
$row = [];
|
||||
try {
|
||||
$row[] = $domain->getId();
|
||||
$row[] = $domain->getName();
|
||||
$content = json_decode(json: $domain->getContent());
|
||||
$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;
|
||||
$row[] = $domain->getPanel();
|
||||
} catch (DependencyException|NotFoundException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
@ -1023,16 +1056,11 @@ class BindAPI
|
||||
}
|
||||
|
||||
$arguments = $this->parseArguments();
|
||||
|
||||
|
||||
$a = $arguments['a'] ?? '';
|
||||
$aaaa = $arguments['aaaa'] ?? '';
|
||||
$panel = $arguments['panel'] ?? '';
|
||||
|
||||
print("panel: $panel");
|
||||
if (empty($a) && empty($aaaa) && empty($panel)) {
|
||||
echo 'At least one IP address or panel is required.' . PHP_EOL;
|
||||
exit(0);
|
||||
if (empty($panel)) {
|
||||
echo 'You need to supply the panel name.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -1040,24 +1068,13 @@ class BindAPI
|
||||
echo "Domain: $name already exists." . PHP_EOL;
|
||||
exit(1);
|
||||
} else {
|
||||
if (!empty($panel)) {
|
||||
if ($this->panelRepository->findByName(name: $panel)) {
|
||||
$content = $this->domainController->createPanelContent(panel: $panel);
|
||||
} else {
|
||||
echo 'Unknown panel: ' . $panel;
|
||||
exit(1);
|
||||
}
|
||||
if ($this->panelRepository->findByName(name: $panel)) {
|
||||
$content = $this->domainController->createPanelContent(panel: $panel);
|
||||
} else {
|
||||
$content = [];
|
||||
if (!empty($a)) {
|
||||
$content['a'] = $a;
|
||||
}
|
||||
if (!empty($aaaa)) {
|
||||
$content['aaaa'] = $aaaa;
|
||||
}
|
||||
$content = $this->domainController->createIPContent(ip: $content);
|
||||
echo 'Unknown panel: ' . $panel;
|
||||
exit(1);
|
||||
}
|
||||
$domain = new Domain(name: $name, content: $content);
|
||||
$domain = new Domain(name: $name, panel: $panel);
|
||||
$result = $this->domainRepository->insert(domain: $domain);
|
||||
echo "Domain $name has been created with id $result" . PHP_EOL;
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
@ -1078,9 +1095,7 @@ class BindAPI
|
||||
|
||||
$id = intval(value: $this->arguments[1] ?? 0);
|
||||
$name = $arguments['name'] ?? '';
|
||||
$panel = $arguments['panel'] ?? '';
|
||||
$a = $arguments['a'] ?? '';
|
||||
$aaaa = $arguments['aaaa'] ?? '';
|
||||
$panelName = $arguments['panel'] ?? '';
|
||||
|
||||
if ($id == 0) {
|
||||
echo 'An ID is required' . PHP_EOL;
|
||||
@ -1093,35 +1108,17 @@ class BindAPI
|
||||
|
||||
|
||||
$content = [];
|
||||
if (!empty($panel)) {
|
||||
$panel = $this->panelRepository->findByName(name: $panel);
|
||||
$content = $this->domainController->createPanelContent(panel: $panel->getName());
|
||||
} else {
|
||||
$addresses = [];
|
||||
if (!empty($a)) {
|
||||
$addresses[] = [
|
||||
'a' => $a
|
||||
];
|
||||
}
|
||||
if (!empty($aaaa)) {
|
||||
$addresses[] = [
|
||||
'aaaa' => $aaaa
|
||||
];
|
||||
}
|
||||
if (!empty($addresses)) {
|
||||
$content = $this->domainController->createIPContent(ip: $content);
|
||||
}
|
||||
if (!empty($panelName)) {
|
||||
$panel = $this->panelRepository->findByName(name: $panelName);
|
||||
}
|
||||
if (empty($name) && empty($content)) {
|
||||
|
||||
if (empty($name) && empty($panel)) {
|
||||
echo 'No name or panel given, just recreate the config file' . PHP_EOL;
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
exit(1);
|
||||
}
|
||||
if (empty($content)) {
|
||||
$newDomain = new Domain(name: $name, id: $domain->getId(), content: '');
|
||||
} else {
|
||||
$newDomain = new Domain(name: $name, id: $domain->getId(), content: $content);
|
||||
}
|
||||
$newDomain = new Domain(name: $name, panel: $panelName, id: $domain->getId());
|
||||
|
||||
if ($this->domainRepository->update(domain: $newDomain) !== false) {
|
||||
echo 'Domain server has been updated' . PHP_EOL;
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
@ -1319,4 +1316,36 @@ class BindAPI
|
||||
$this->nameserverRepository->delete(id: $id);
|
||||
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
Block a user