Compare commits

...

2 Commits

Author SHA1 Message Date
tracer 1bf327cc00 modified curl handling
Signed-off-by: tracer <tracer@24unix.net>
2022-01-29 14:56:07 +01:00
tracer 1567520a5b error check on check:panels
Signed-off-by: tracer <tracer@24unix.net>
2022-01-29 14:55:40 +01:00
2 changed files with 22 additions and 7 deletions

View File

@ -152,9 +152,6 @@ class BindAPI
{ {
$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'],
@ -199,7 +196,6 @@ class BindAPI
post: true, post: true,
body: $body); body: $body);
} }
die();
} else { } else {
echo 'error'; echo 'error';
} }
@ -211,7 +207,9 @@ class BindAPI
function handleCheckPanels() function handleCheckPanels()
{ {
$id = $this->getId(); $parsedArguments = $this->parseArguments();
print_r($this->arguments);
$id = intval(value: $this->arguments[1] ?? 0);
print("id: $id " . PHP_EOL); print("id: $id " . PHP_EOL);
if ($id != 0) { if ($id != 0) {
@ -229,10 +227,21 @@ class BindAPI
command: 'domains', command: 'domains',
type: 'panel'); type: 'panel');
} }
if ($result['error']) {
echo $result['data'] . PHP_EOL;
exit(1);
}
$domains = json_decode(json: $result['data']); $domains = json_decode(json: $result['data']);
if ($domains['error']) {
echo $domains['data'];
exit(1);
}
$maxDomainName = 0; $maxDomainName = 0;
// TODO this is ugly code // TODO this is ugly code
foreach ($domains as $domain) { foreach ($domains as $domain) {
if (($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) && (strlen(string: $domain->domain) > $maxDomainName)) { if (($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) && (strlen(string: $domain->domain) > $maxDomainName)) {
$maxDomainName = strlen(string: $domain->domain); $maxDomainName = strlen(string: $domain->domain);
@ -564,6 +573,8 @@ class BindAPI
if (str_contains(haystack: $argument, needle: '=')) { if (str_contains(haystack: $argument, needle: '=')) {
[$key, $value] = explode(separator: '=', string: $argument); [$key, $value] = explode(separator: '=', string: $argument);
$arguments[strtolower(string: $key)] = $value; $arguments[strtolower(string: $key)] = $value;
} else {
$arguments[strtolower(string: $argument)] = $argument;
} }
} }
return $arguments; return $arguments;

View File

@ -21,6 +21,7 @@ class CheckController
*/ */
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command, String $type, bool $post = false, array $body = []): array
{ {
$error = false;
$curl = curl_init(); $curl = curl_init();
if ($type == "panel") { if ($type == "panel") {
curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command); curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command);
@ -28,7 +29,8 @@ class CheckController
curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command); curl_setopt(handle: $curl, option: CURLOPT_URL, value: "https://$serverName/api/" . $command);
} }
curl_setopt(handle: $curl, option: CURLOPT_RETURNTRANSFER, value: 1); curl_setopt(handle: $curl, option: CURLOPT_RETURNTRANSFER, value: 1);
curl_setopt(handle: $curl, option: CURLOPT_TIMEOUT_MS, value: 1000); curl_setopt(handle: $curl, option: CURLOPT_TIMEOUT_MS, value: 3000);
curl_setopt(handle: $curl, option: CURLOPT_HTTP_VERSION, value: CURL_HTTP_VERSION_2TLS);
if ($versionIP == 4) { if ($versionIP == 4) {
curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4); curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4);
@ -66,10 +68,12 @@ class CheckController
$result = 'Unhandled error: ' . $httpResponse; $result = 'Unhandled error: ' . $httpResponse;
} }
} else { } else {
$error = true;
$result = curl_error(handle: $curl); $result = curl_error(handle: $curl);
} }
curl_close(handle: $curl); curl_close(handle: $curl);
return [ return [
'error' => true,
'data' => $result, 'data' => $result,
'header' => $httpResponse ?? '' 'header' => $httpResponse ?? ''
]; ];