|
|
@ -12,7 +12,6 @@ define(constant_name: 'COLOR_WHITE', value: "\033[37m");
|
|
|
|
define(constant_name: 'COLOR_DEFAULT', value: "\033[39m");
|
|
|
|
define(constant_name: 'COLOR_DEFAULT', value: "\033[39m");
|
|
|
|
|
|
|
|
|
|
|
|
use App\Entity\Domain;
|
|
|
|
use App\Entity\Domain;
|
|
|
|
use App\Entity\DynDNS;
|
|
|
|
|
|
|
|
use App\Entity\Nameserver;
|
|
|
|
use App\Entity\Nameserver;
|
|
|
|
use App\Entity\Panel;
|
|
|
|
use App\Entity\Panel;
|
|
|
|
use App\Repository\ApikeyRepository;
|
|
|
|
use App\Repository\ApikeyRepository;
|
|
|
@ -21,7 +20,6 @@ use App\Repository\DynDNSRepository;
|
|
|
|
use App\Repository\NameserverRepository;
|
|
|
|
use App\Repository\NameserverRepository;
|
|
|
|
use App\Repository\PanelRepository;
|
|
|
|
use App\Repository\PanelRepository;
|
|
|
|
use Arubacao\TldChecker\Validator;
|
|
|
|
use Arubacao\TldChecker\Validator;
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
use LucidFrame\Console\ConsoleTable;
|
|
|
|
use LucidFrame\Console\ConsoleTable;
|
|
|
|
|
|
|
|
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
|
|
@ -34,10 +32,11 @@ if (php_sapi_name() !== 'cli') {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class CLIController
|
|
|
|
class CLIController
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private array $arguments;
|
|
|
|
private int $argumentsCount;
|
|
|
|
|
|
|
|
private array $arguments;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
public function __construct(
|
|
|
|
private readonly ApiController $apiController,
|
|
|
|
private readonly ApiController $apiController,
|
|
|
@ -55,7 +54,7 @@ class CLIController
|
|
|
|
|
|
|
|
|
|
|
|
function checkSetup(): void
|
|
|
|
function checkSetup(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!$this->domainController->checkPermissions(disableVerbose: true)) {
|
|
|
|
if (!$this->domainController->checkPermissions()) {
|
|
|
|
echo 'You need to setup the bindAPI first.' . PHP_EOL;
|
|
|
|
echo 'You need to setup the bindAPI first.' . PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -78,24 +77,23 @@ class CLIController
|
|
|
|
|
|
|
|
|
|
|
|
// TODO encrypt the password in the config file, key in config
|
|
|
|
// TODO encrypt the password in the config file, key in config
|
|
|
|
|
|
|
|
|
|
|
|
function runCommand(array $arguments): void
|
|
|
|
function runCommand(int $argumentsCount, array $arguments): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (count($arguments) < 1) {
|
|
|
|
$this->argumentsCount = $argumentsCount;
|
|
|
|
$this->showUsage();
|
|
|
|
$this->arguments = $arguments;
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->logger->debug(message: "runCommand()");
|
|
|
|
$this->logger->debug(message: "runCommand()");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->argumentsCount < 1) {
|
|
|
|
if (str_contains(haystack: $arguments[0], needle: ':')) {
|
|
|
|
$this->showUsage();
|
|
|
|
[$command, $subcommand] = explode(separator: ':', string: $arguments[0]);
|
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$command = $arguments[0];
|
|
|
|
|
|
|
|
$subcommand = '';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->arguments = $this->parseArguments(arguments: $arguments);
|
|
|
|
if (str_contains(haystack: $this->arguments[0], needle: ':')) {
|
|
|
|
|
|
|
|
[$command, $subcommand] = explode(separator: ':', string: $this->arguments[0]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$command = $this->arguments[0];
|
|
|
|
|
|
|
|
$subcommand = '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
match ($command) {
|
|
|
|
match ($command) {
|
|
|
|
'check' => $this->handleChecks(subcommand: $subcommand),
|
|
|
|
'check' => $this->handleChecks(subcommand: $subcommand),
|
|
|
@ -104,7 +102,7 @@ class CLIController
|
|
|
|
'domains' => $this->handleDomains(subcommand: $subcommand),
|
|
|
|
'domains' => $this->handleDomains(subcommand: $subcommand),
|
|
|
|
'dyndns' => $this->handleDynDns(subcommand: $subcommand),
|
|
|
|
'dyndns' => $this->handleDynDns(subcommand: $subcommand),
|
|
|
|
'nameservers' => $this->handleNameservers(subcommand: $subcommand),
|
|
|
|
'nameservers' => $this->handleNameservers(subcommand: $subcommand),
|
|
|
|
default => $this->unknownCommand(command: $command)
|
|
|
|
default => $this->unknownSubcommand(subcommand: $subcommand)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -182,12 +180,6 @@ class CLIController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function unknownCommand(string $command): void
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
echo COLOR_DEFAULT . 'Unknown command: ' . COLOR_YELLOW . $command . COLOR_DEFAULT . PHP_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function unknownSubcommand(string $subcommand): void
|
|
|
|
function unknownSubcommand(string $subcommand): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ($subcommand) {
|
|
|
|
if ($subcommand) {
|
|
|
@ -217,7 +209,7 @@ class CLIController
|
|
|
|
|
|
|
|
|
|
|
|
function handleCheckSetup(): void
|
|
|
|
function handleCheckSetup(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (count($this->arguments) < 2) {
|
|
|
|
if ($this->argumentsCount < 2) {
|
|
|
|
echo 'You need to supply a username.' . PHP_EOL;
|
|
|
|
echo 'You need to supply a username.' . PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -484,7 +476,8 @@ class CLIController
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
case 404:
|
|
|
|
echo COLOR_RED . ' ' . $result['header'] . COLOR_DEFAULT;
|
|
|
|
echo COLOR_RED . ' ' . $result['header'] . COLOR_DEFAULT;
|
|
|
|
if (!empty($this->arguments['fix']) && $this->arguments['fix'] == 'yes') {
|
|
|
|
$arguments = $this->parseArguments();
|
|
|
|
|
|
|
|
if (!empty($arguments['fix']) && $arguments['fix'] == 'yes') {
|
|
|
|
echo ' trying to fix …';
|
|
|
|
echo ' trying to fix …';
|
|
|
|
$body = [
|
|
|
|
$body = [
|
|
|
|
'name' => $domainName,
|
|
|
|
'name' => $domainName,
|
|
|
@ -525,27 +518,23 @@ class CLIController
|
|
|
|
echo PHP_EOL;
|
|
|
|
echo PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param array $arguments
|
|
|
|
* @return array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function parseArguments(): array
|
|
|
|
public function parseArguments(array $arguments): array
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->logger->debug(message: "parseArguments()");
|
|
|
|
$this->logger->debug(message: "parseArguments()");
|
|
|
|
|
|
|
|
|
|
|
|
$parsedArguments = [];
|
|
|
|
$arguments = [];
|
|
|
|
$parseCount = 0;
|
|
|
|
foreach ($this->arguments as $argument) {
|
|
|
|
foreach ($arguments as $argument) {
|
|
|
|
|
|
|
|
if (str_contains(haystack: $argument, needle: '=')) {
|
|
|
|
if (str_contains(haystack: $argument, needle: '=')) {
|
|
|
|
[$key, $value] = explode(separator: '=', string: $argument);
|
|
|
|
[$key, $value] = explode(separator: '=', string: $argument);
|
|
|
|
$parsedArguments[strtolower(string: $key)] = $value;
|
|
|
|
$arguments[strtolower(string: $key)] = $value;
|
|
|
|
$parsedArguments[$parseCount++] = $value;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$parsedArguments[strtolower(string: $argument)] = $argument;
|
|
|
|
$arguments[strtolower(string: $argument)] = $argument;
|
|
|
|
$parsedArguments[$parseCount++] = $argument;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $parsedArguments;
|
|
|
|
return $arguments;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -588,14 +577,16 @@ class CLIController
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$a = $this->arguments['a'] ?? '';
|
|
|
|
$arguments = $this->parseArguments();
|
|
|
|
$aaaa = $this->arguments['aaaa'] ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
$a = $arguments['a'] ?? '';
|
|
|
|
|
|
|
|
$aaaa = $arguments['aaaa'] ?? '';
|
|
|
|
if (empty($a) && empty($aaaa)) {
|
|
|
|
if (empty($a) && empty($aaaa)) {
|
|
|
|
echo 'At least one IP address is required.' . PHP_EOL;
|
|
|
|
echo 'At least one IP address is required.' . PHP_EOL;
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$apikey = $this->arguments['apikey'] ?? '';
|
|
|
|
$apikey = $arguments['apikey'] ?? '';
|
|
|
|
$self = intval(value: $this->arguments['self'] ?? 0);
|
|
|
|
$self = intval(value: $arguments['self'] ?? 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->panelRepository->findByName(name: $name)) {
|
|
|
|
if ($this->panelRepository->findByName(name: $name)) {
|
|
|
@ -652,14 +643,15 @@ class CLIController
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->logger->debug(message: "handlePanelsUpdate()");
|
|
|
|
$this->logger->debug(message: "handlePanelsUpdate()");
|
|
|
|
|
|
|
|
|
|
|
|
$id = intval(value: $this->arguments[1] ?? 0);
|
|
|
|
$arguments = $this->parseArguments();
|
|
|
|
$name = $this->arguments['name'] ?? '';
|
|
|
|
|
|
|
|
$a = $this->arguments['a'] ?? '';
|
|
|
|
$id = intval(value: $this->arguments[1] ?? 0);
|
|
|
|
$aaaa = $this->arguments['aaaa'] ?? '';
|
|
|
|
$name = $arguments['name'] ?? '';
|
|
|
|
$apikey = $this->arguments['apikey'] ?? '';
|
|
|
|
$a = $arguments['a'] ?? '';
|
|
|
|
$self = intval(value: $this->arguments['self'] ?? 0);
|
|
|
|
$aaaa = $arguments['aaaa'] ?? '';
|
|
|
|
|
|
|
|
$apikey = $arguments['apikey'] ?? '';
|
|
|
|
|
|
|
|
$self = intval(value: $arguments['self'] ?? 0);
|
|
|
|
|
|
|
|
|
|
|
|
// a workaround for 0 being equal to false …
|
|
|
|
|
|
|
|
if ($self == 0) {
|
|
|
|
if ($self == 0) {
|
|
|
|
$self = -1;
|
|
|
|
$self = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -867,7 +859,8 @@ class CLIController
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function handleApikeysCreate(): void
|
|
|
|
function handleApikeysCreate(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$name = $this->arguments['name'] ?? '';
|
|
|
|
$arguments = $this->parseArguments();
|
|
|
|
|
|
|
|
$name = $arguments['name'] ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->apikeyRepository->create(name: $name);
|
|
|
|
$result = $this->apikeyRepository->create(name: $name);
|
|
|
|
echo 'API key ' . COLOR_YELLOW . $result['row'] . COLOR_DEFAULT . ' has been generated. Store it in a save place, it cannot be recovered.' . PHP_EOL;
|
|
|
|
echo 'API key ' . COLOR_YELLOW . $result['row'] . COLOR_DEFAULT . ' has been generated. Store it in a save place, it cannot be recovered.' . PHP_EOL;
|
|
|
@ -905,10 +898,10 @@ class CLIController
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function handleApikeysUpdate(): void
|
|
|
|
function handleApikeysUpdate(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
$arguments = $this->parseArguments();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO check for use of id instead of number, mind for all occurences
|
|
|
|
|
|
|
|
$id = $this->arguments[1] ?? 0;
|
|
|
|
$id = $this->arguments[1] ?? 0;
|
|
|
|
$name = $this->arguments['name'] ?? '';
|
|
|
|
$name = $arguments['name'] ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
if ($id == 0) {
|
|
|
|
if ($id == 0) {
|
|
|
|
echo 'An ID is required' . PHP_EOL;
|
|
|
|
echo 'An ID is required' . PHP_EOL;
|
|
|
@ -1022,7 +1015,7 @@ class CLIController
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function handleDynDnsCreate(): void
|
|
|
|
function handleDynDnsCreate(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$name = $this->arguments[1] ?? '';
|
|
|
|
$name = $this->arguments[1] ?? "";
|
|
|
|
if (empty($name)) {
|
|
|
|
if (empty($name)) {
|
|
|
|
echo 'You need to supply the FQDN (hostname).' . PHP_EOL;
|
|
|
|
echo 'You need to supply the FQDN (hostname).' . PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
@ -1036,11 +1029,8 @@ class CLIController
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$password = $this->arguments[2] ?? '';
|
|
|
|
echo 'fqdn: ' . $name;
|
|
|
|
|
|
|
|
|
|
|
|
var_dump($this->arguments);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
die();
|
|
|
|
|
|
|
|
$domainParts = explode(separator: '.', string: $name);
|
|
|
|
$domainParts = explode(separator: '.', string: $name);
|
|
|
|
$reversedParts = array_reverse(array: $domainParts);
|
|
|
|
$reversedParts = array_reverse(array: $domainParts);
|
|
|
|
$testDomain = '';
|
|
|
|
$testDomain = '';
|
|
|
@ -1062,26 +1052,11 @@ class CLIController
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->configController->getConfig(configKey: 'verbose')) {
|
|
|
|
echo "found domian" . $foundDomain . PHP_EOL;
|
|
|
|
echo "Found domain: " . COLOR_YELLOW . $foundDomain . COLOR_DEFAULT . PHP_EOL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get host
|
|
|
|
// get host
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->dynDNSRepository->findByName(name: $name)) {
|
|
|
|
// inset in db
|
|
|
|
if ($this->configController->getConfig(configKey: 'verbose')) {
|
|
|
|
|
|
|
|
echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "already exists.". PHP_EOL;
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ($this->configController->getConfig(configKey: 'verbose')) {
|
|
|
|
|
|
|
|
echo "DynDNS host " . COLOR_YELLOW . $name . COLOR_DEFAULT . "will be created.". PHP_EOL;
|
|
|
|
|
|
|
|
// insert in db
|
|
|
|
|
|
|
|
$dyndnsHost = new DynDNS();
|
|
|
|
|
|
|
|
$dyndnsHost->setName($name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check on NS
|
|
|
|
// check on NS
|
|
|
|
// => add if missing
|
|
|
|
// => add if missing
|
|
|
|