Compare commits
No commits in common. "010914b7bdd8bea95d8ca4035015e7c941e298ff" and "19576dd6b78096c8d6319190cdf73ad5d6f8f568" have entirely different histories.
010914b7bd
...
19576dd6b7
|
@ -34,11 +34,11 @@ class CommandGroup
|
|||
echo COLOR_YELLOW . str_pad(string: $this->name, length: $longestCommandLength + 1) . COLOR_WHITE . $this->description . COLOR_DEFAULT . PHP_EOL;
|
||||
foreach ($this->commands as $command) {
|
||||
echo COLOR_GREEN . str_pad(string: ' ', length: $longestCommandLength + 1, pad_type: STR_PAD_LEFT) . $this->name . ':' . $command->getName();
|
||||
foreach ($command->getMandatoryParameters() as $optionals) {
|
||||
echo ' <' . $optionals . '>';
|
||||
foreach ($command->getMandatoryParameters() as $parameter) {
|
||||
echo ' <' . $parameter . '>';
|
||||
}
|
||||
foreach ($command->getOptionalParameters() as $mandatory) {
|
||||
echo ' {' . $mandatory . '}';
|
||||
foreach ($command->getOptionalParameters() as $parameter) {
|
||||
echo ' {' . $parameter . '}';
|
||||
}
|
||||
echo COLOR_WHITE . ' ' . $command->getDescription();
|
||||
echo COLOR_DEFAULT . PHP_EOL;
|
||||
|
|
|
@ -9,21 +9,7 @@ class ConfigController
|
|||
{
|
||||
private array $config;
|
||||
|
||||
/**
|
||||
* @param bool $verbose
|
||||
* @param bool $quiet
|
||||
* @param bool $test
|
||||
*/
|
||||
public function __construct(bool $verbose = false, bool $quiet = false, bool $test = false)
|
||||
{
|
||||
|
||||
if ($test) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.test";
|
||||
if (!file_exists(filename: $configFile)) {
|
||||
echo 'No testing (config.json.test) config has benn setup.' . PHP_EOL;
|
||||
die(1);
|
||||
}
|
||||
} else {
|
||||
public function __construct(bool $verbose = false, bool $quiet = false) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
|
||||
if (!file_exists(filename: $configFile)) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
|
||||
|
@ -40,7 +26,6 @@ class ConfigController
|
|||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
$configJSON = file_get_contents(filename: $configFile);
|
||||
|
||||
if (json_decode(json: $configJSON) === null) {
|
||||
|
@ -51,13 +36,19 @@ class ConfigController
|
|||
|
||||
$this->config = json_decode(json: $configJSON, associative: true);
|
||||
|
||||
$this->config['verbose'] = (bool)$verbose;
|
||||
$this->config['quiet'] = (bool)$quiet;
|
||||
$this->config['test'] = (bool)$test;
|
||||
if ($verbose) {
|
||||
$this->config['verbose'] = true;
|
||||
} else {
|
||||
$this->config['verbose'] = false;
|
||||
}
|
||||
if ($quiet) {
|
||||
$this->config['quiet'] = true;
|
||||
} else {
|
||||
$this->config['quiet'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfig(string $configKey): string
|
||||
{
|
||||
public function getConfig(string $configKey): string {
|
||||
return $this->config[$configKey];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@ use UnhandledMatchError;
|
|||
*/
|
||||
#[OAT\Info(version: '0.0.1', title: 'bindAPI')]
|
||||
#[OAT\Server(
|
||||
url: "{schema}://{hostname}/api",
|
||||
url : "{schema}://{hostname}/api",
|
||||
description: "The bindAPI URL.",
|
||||
variables: [
|
||||
variables : [
|
||||
new OAT\ServerVariable(
|
||||
serverVariable: "schema",
|
||||
default: "https",
|
||||
enum: ["https", "http"]
|
||||
default : "https",
|
||||
enum : ["https", "http"]
|
||||
),
|
||||
new OAT\ServerVariable(
|
||||
serverVariable: "hostname",
|
||||
default: "ns2.24unix.net",
|
||||
default : "ns2.24unix.net",
|
||||
)
|
||||
]
|
||||
)]
|
||||
|
@ -41,10 +41,10 @@ use UnhandledMatchError;
|
|||
)]
|
||||
#[OAT\SecurityScheme(
|
||||
securityScheme: "Authorization",
|
||||
type: "apiKey",
|
||||
description: "description",
|
||||
name: "X-API-Key",
|
||||
in: "header"
|
||||
type : "apiKey",
|
||||
description : "description",
|
||||
name : "X-API-Key",
|
||||
in : "header"
|
||||
)]
|
||||
class RequestController
|
||||
{
|
||||
|
@ -63,8 +63,6 @@ class RequestController
|
|||
* @param DomainRepository $domainRepository
|
||||
* @param DynDNSRepository $dynDNSRepository
|
||||
* @param PanelRepository $panelRepository
|
||||
* @param ConfigController $configController
|
||||
* @param EncryptionController $encryptionController
|
||||
* @param Logger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -74,8 +72,6 @@ class RequestController
|
|||
private readonly DomainRepository $domainRepository,
|
||||
private readonly DynDNSRepository $dynDNSRepository,
|
||||
private readonly PanelRepository $panelRepository,
|
||||
private readonly ConfigController $configController,
|
||||
private readonly EncryptionController $encryptionController,
|
||||
private readonly Logger $logger)
|
||||
{
|
||||
$this->status = '';
|
||||
|
@ -88,29 +84,29 @@ class RequestController
|
|||
* @return void
|
||||
*/
|
||||
#[OAT\Get(
|
||||
path: '/domains',
|
||||
path : '/domains',
|
||||
operationId: 'getAllDomains',
|
||||
description: 'Returns a list of all domains on this server.',
|
||||
summary: 'Listing all domains.',
|
||||
summary : 'Listing all domains.',
|
||||
// security: [
|
||||
// 'Authorization' => [
|
||||
//
|
||||
// "read:api"
|
||||
// ]
|
||||
// ],
|
||||
servers: [],
|
||||
tags: ['Domains'],
|
||||
responses: [
|
||||
servers : [],
|
||||
tags : ['Domains'],
|
||||
responses : [
|
||||
new OAT\Response(
|
||||
response: 200,
|
||||
response : 200,
|
||||
description: 'OK'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 401,
|
||||
response : 401,
|
||||
description: 'API key is missing or invalid.'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 404,
|
||||
response : 404,
|
||||
description: 'Domain not found.'
|
||||
)]
|
||||
)]
|
||||
|
@ -211,27 +207,27 @@ class RequestController
|
|||
|
||||
#[
|
||||
OAT\Get(
|
||||
path: '/domains/{name}',
|
||||
path : '/domains/{name}',
|
||||
operationId: 'getSingleDomain',
|
||||
description: 'Returns information of a single domain specified by its domain name.',
|
||||
summary: 'Returns a single domain.',
|
||||
security: [
|
||||
summary : 'Returns a single domain.',
|
||||
security : [
|
||||
],
|
||||
tags: ['Domains'],
|
||||
parameters: [
|
||||
tags : ['Domains'],
|
||||
parameters : [
|
||||
new OAT\Parameter(name: 'name', in: 'path', required: true, schema: new OAT\Schema(type: 'string')),
|
||||
],
|
||||
responses: [
|
||||
responses : [
|
||||
new OAT\Response(
|
||||
response: 200,
|
||||
response : 200,
|
||||
description: 'OK'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 401,
|
||||
response : 401,
|
||||
description: 'API key is missing or invalid.'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 404,
|
||||
response : 404,
|
||||
description: 'Domain not found.'
|
||||
)]
|
||||
|
||||
|
@ -300,11 +296,8 @@ class RequestController
|
|||
} else {
|
||||
[$prefix,] = explode(separator: '.', string: $apiKey);
|
||||
if ($apiResult = $this->apikeyRepository->findByPrefix(prefix: $prefix)) {
|
||||
$encryptedHash = $apiResult->getApikey();
|
||||
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||
$decryptedHash = $this->encryptionController->safeDecrypt(encrypted: $encryptedHash, key: $encryptionKey);
|
||||
|
||||
if (!password_verify(password: $apiKey, hash: $decryptedHash)) {
|
||||
$storedHash = $apiResult->getApiToken();
|
||||
if (!password_verify(password: $apiKey, hash: $storedHash)) {
|
||||
$this->status = "401 Unauthorized";
|
||||
$this->message = "API key mismatch.";
|
||||
return false;
|
||||
|
@ -539,19 +532,19 @@ class RequestController
|
|||
if (!empty($panel->getAaaa())) {
|
||||
$domainData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'domains/name/' . $domainName,
|
||||
serverType: 'panel');
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'domains/name/' . $domainName,
|
||||
serverType : 'panel');
|
||||
} else {
|
||||
$domainData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'domains/name/' . $domainName,
|
||||
serverType: 'panel');
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'domains/name/' . $domainName,
|
||||
serverType : 'panel');
|
||||
}
|
||||
|
||||
$domainDecodedData = json_decode(json: $domainData['data']);
|
||||
|
@ -560,19 +553,19 @@ class RequestController
|
|||
if (!empty($panel->getAaaa())) {
|
||||
$dnsData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'dns/' . $domainID,
|
||||
serverType: 'panel');
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'dns/' . $domainID,
|
||||
serverType : 'panel');
|
||||
} else {
|
||||
$dnsData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'dns/' . $domainID,
|
||||
serverType: 'panel');
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'dns/' . $domainID,
|
||||
serverType : 'panel');
|
||||
}
|
||||
|
||||
$dnsDataDecoded = json_decode(json: $dnsData['data']);
|
||||
|
@ -609,22 +602,22 @@ class RequestController
|
|||
if (!empty($panel->getAaaa())) {
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'PUT',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 6,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'dns/' . $domainID,
|
||||
serverType: 'panel',
|
||||
body: json_decode(json: $newDnsData, associative: true)
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 6,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'dns/' . $domainID,
|
||||
serverType : 'panel',
|
||||
body : json_decode(json: $newDnsData, associative: true)
|
||||
);
|
||||
} else {
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'PUT',
|
||||
serverName: $panel->getName(),
|
||||
versionIP: 4,
|
||||
apiKey: $panel->getApikey(),
|
||||
command: 'dns/' . $domainID,
|
||||
serverType: 'panel',
|
||||
body: json_decode(json: $newDnsData, associative: true)
|
||||
serverName : $panel->getName(),
|
||||
versionIP : 4,
|
||||
apiKey : $panel->getApikey(),
|
||||
command : 'dns/' . $domainID,
|
||||
serverType : 'panel',
|
||||
body : json_decode(json: $newDnsData, associative: true)
|
||||
);
|
||||
}
|
||||
if ($result['header'] == 200) {
|
||||
|
|
|
@ -16,8 +16,8 @@ class Apikey
|
|||
public function __construct(
|
||||
private int $id = 0,
|
||||
private string $name = '',
|
||||
private string $apikey = '',
|
||||
private string $apikeyPrefix = '',
|
||||
private string $apiTokenPrefix = '',
|
||||
private string $apiToken = '',
|
||||
private readonly string $passphrase = ''
|
||||
)
|
||||
{
|
||||
|
@ -27,39 +27,31 @@ class Apikey
|
|||
|
||||
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
||||
|
||||
$this->apikey = strtok(string: $this->passphrase, token: '.');
|
||||
$this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.');
|
||||
|
||||
try {
|
||||
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
||||
$this->apiToken = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
||||
} catch (Exception|SodiumException $e) {
|
||||
die($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassphrase(): string
|
||||
{
|
||||
return $this->passphrase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public function getApikey(): string
|
||||
public function getApiToken(): string
|
||||
{
|
||||
return $this->apikey;
|
||||
return $this->apiToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApikeyPrefix(): string
|
||||
public function getApiTokenPrefix(): string
|
||||
{
|
||||
return $this->apikeyPrefix;
|
||||
return $this->apiTokenPrefix;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,19 +80,19 @@ class Apikey
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $apikeyPrefix
|
||||
* @param string $apiTokenPrefix
|
||||
*/
|
||||
public function setApikeyPrefix(string $apikeyPrefix): void
|
||||
public function setApiTokenPrefix(string $apiTokenPrefix): void
|
||||
{
|
||||
$this->apikeyPrefix = $apikeyPrefix;
|
||||
$this->apiTokenPrefix = $apiTokenPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $apiToken
|
||||
*/
|
||||
public function setApikey(string $apikey): void
|
||||
public function setApiToken(string $apiToken): void
|
||||
{
|
||||
$this->apikey = $apikey;
|
||||
$this->apiToken = $apiToken;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class DynDNS
|
|||
|
||||
/**
|
||||
*/
|
||||
public function __construct(private string $name, private string $a = '', private string $aaaa = '', private $password = '', private int $id = 0)
|
||||
public function __construct(private string $name, private string $a, private string $aaaa, private $password = '', private int $id = 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue