diff --git a/bindAPI/src/Controller/BindAPI.php b/bindAPI/src/Controller/BindAPI.php index 93ab022..3872bed 100755 --- a/bindAPI/src/Controller/BindAPI.php +++ b/bindAPI/src/Controller/BindAPI.php @@ -2,6 +2,10 @@ namespace App\Controller; +define('COLOR_YELLOW', "\033[33m"); +define('COLOR_GREEN', "\033[32m"); +define('COLOR_DEFAULT', "\033[39m"); + // TODO add to all Controllers error_reporting(E_ALL); @@ -27,14 +31,44 @@ class BindAPI private DomainController $domainController; private PanelController $panelController; private NameserverController $nameserverController; + private CheckController $checkController; - public function __construct(private int $argc, private array $argv) + public function __construct(private array $config, private int $argc, private array $argv) { - $this->dbConnection = (new DatabaseConnection())->getConnection(); + $this->dbConnection = (new DatabaseConnection(config: $this->config))->getConnection(); $this->panelController = new PanelController($this->dbConnection); $this->apiUsers = new ApiUsers($this->dbConnection); $this->domainController = new DomainController($this->dbConnection); $this->nameserverController = new NameserverController($this->dbConnection); + $this->checkController = new CheckController(); + } + + /** + * @param bool|array $panel + * + * @return void + */ + public function checkPing(bool|array $panel): void + { + $a = $panel['a'] ?? ''; + print(COLOR_YELLOW . $panel['name']); + if (!empty($a)) { + if ($this->checkController->sendCommand(serverName: $panel['name'], versionIP: 4, apiKey: $panel['apikey'], command: 'ping')) { + // if verbose … + print(COLOR_DEFAULT . ' ' . $panel['a'] . ': ' . COLOR_GREEN . 'pong'); + } else { + $error = true; + } + } + $aaaa = $panel['aaaa'] ?? ''; + if (!empty($aaaa)) { + if ($this->checkController->sendCommand(serverName: $panel['name'], versionIP: 6, apiKey: $panel['apikey'], command: 'ping')) { + // if verbose … + print(COLOR_DEFAULT . ' ' . $panel['aaaa'] . ': ' . COLOR_GREEN . 'pong' . PHP_EOL); + } else { + $error = true; + } + } } @@ -95,6 +129,7 @@ class BindAPI echo "\033[32m\tcheck:domains {ID}" . PHP_EOL; echo "\033[33mpanels\t\033[39mall Keyhelp systems configured" . PHP_EOL; echo "\033[32m\tpanels:list" . PHP_EOL; + echo "\033[32m\tpanels:apiping {}" . PHP_EOL; echo "\033[32m\tpanels:create {A=} {AAAA=} {apikey=}" . PHP_EOL; echo "\033[32m\tpanels:update {name=} {A=} {AAAA=} {apikey=}" . PHP_EOL; echo "\033[32m\tpanels:delete" . PHP_EOL; @@ -145,6 +180,7 @@ class BindAPI { try { match ($subcommand) { + 'apiping' => $this->handlePanelsAPIPing(), 'create' => $this->handlePanelsCreate(), 'list' => $this->handlePanelsList(), 'update' => $this->handlePanelsUpdate(), @@ -155,6 +191,28 @@ class BindAPI } } + + function handlePanelsAPIPing() + { + $error = false; + $id = $this->argv[2] ?? 0; + + if ($id != 0) { + $panel = $this->panelController->findByID($id); + $this->checkPing($panel); + } else { + $panels = $this->panelController->findAll(); + foreach ($panels as $panel) { + $this->checkPing(panel: $panel); + } + } + + + + print(PHP_EOL); + } + + /** * @return void */