Initial commit

This commit is contained in:
2022-01-18 17:14:29 +01:00
commit 320a153918
18 changed files with 622 additions and 0 deletions

93
src/Customer.php Normal file
View File

@@ -0,0 +1,93 @@
<?php
namespace Envoyr\Froxlor;
class Customer
{
public array $attributes;
public Databases $databases;
public Domains $domains;
public Ftps $ftps;
public Emails $emails;
public string $loginname;
public Server $server;
public function __construct(Server $server, string $loginname)
{
$this->server = $server;
$this->loginname = $loginname;
$this->attributes = $this->server->request('Customers.get', [
'loginname' => $this->loginname
]);
$this->databases = $this->databases();
$this->domains = $this->domains();
$this->ftps = $this->ftps();
$this->emails = $this->emails();
}
private function databases(): Databases
{
return new Databases($this);
}
private function domains(): Domains
{
return new Domains($this);
}
private function ftps(): Ftps
{
return new Ftps($this);
}
private function emails(): Emails
{
return new Emails($this);
}
public function database(string $dbname): Database
{
return new Database($this, $dbname);
}
public function domain(string $domainname): Domain
{
return new Domain($this, $domainname);
}
public function email(string $emailaddr): Email
{
return new Email($this, $emailaddr);
}
public function ftp(string $username): Ftp
{
return new Ftp($this, $username);
}
public function deactivated(bool $deactivated): array
{
return $this->server->request('Customers.update', [
'loginname' => $this->loginname,
'deactivated' => $deactivated
]);
}
public function update(array $attributes): array
{
return $this->server->request(
'Customers.update',
array_merge($attributes, [
'loginname' => $this->loginname
])
);
}
public function delete(): array
{
return $this->server->request('Customers.delete', [
'loginname' => $this->loginname
]);
}
}

18
src/Customers.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace Envoyr\Froxlor;
class Customers
{
public Server $server;
public function __construct(Server $server)
{
$this->server = $server;
}
public function create(array $attributes): array
{
return $this->server->request('Customers.add', $attributes);
}
}

38
src/Database.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
namespace Envoyr\Froxlor;
class Database
{
public array $attributes;
public string $dbname;
public Customer $customer;
public function __construct(Customer $customer, string $dbname)
{
$this->customer = $customer;
$this->dbname = $dbname;
$this->attributes = $this->customer->server->request('Mysqls.get', [
'dbname' => $this->dbname
]);
}
public function update(array $attributes): array
{
return $this->customer->server->request(
'Mysqls.update',
array_merge($attributes, [
'loginname' => $this->customer->loginname,
'dbname' => $this->dbname,
])
);
}
public function delete(): array
{
return $this->customer->server->request('Mysqls.delete', [
'loginname' => $this->customer->loginname,
'dbname' => $this->dbname
]);
}
}

35
src/Databases.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace Envoyr\Froxlor;
class Databases
{
public Customer $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function create(
string $password,
string $description = null,
bool $mail = false,
string $suffix = null
): array {
return $this->customer->server->request('Mysqls.add', [
'loginname' => $this->customer->loginname,
'mysql_password' => $password,
'description' => $description,
'sendinfomail' => $mail,
'custom_suffix' => $suffix,
]);
}
public function list(): array
{
return $this->customer->server->request('Mysqls.listing', [
'loginname' => $this->customer->loginname,
]);
}
}

36
src/Domain.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
namespace Envoyr\Froxlor;
class Domain
{
public array $attributes;
public Customer $customer;
public string $domainname;
public function __construct(Customer $customer, string $domainname)
{
$this->domainname = $domainname;
$this->customer = $customer;
$this->attributes = $this->customer->server->request('Domains.get', [
'domainname' => $this->domainname
]);
}
public function update(array $attributes): array
{
return $this->customer->server->request(
'Domains.update',
array_merge($attributes, [
'domainname' => $this->domainname,
])
);
}
public function delete(): array
{
return $this->customer->server->request('Domains.delete', [
'domainname' => $this->domainname
]);
}
}

36
src/Domains.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
namespace Envoyr\Froxlor;
class Domains
{
public Customer $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function create(string $domain, bool $letsencrypt = false): array
{
return $this->customer->server->request('Domains.add', [
'loginname' => $this->customer->loginname,
'domain' => $domain,
'letsencrypt' => $letsencrypt,
'isemaildomain' => true,
'caneditdomain' => true,
]);
}
public function list(): array
{
return $this->customer->server->request('Domains.listing', [
'sql_search' => [
'loginname' => [
'op' => '=',
'value' => $this->customer->loginname,
]
],
]);
}
}

51
src/Email.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace Envoyr\Froxlor;
class Email
{
public array $attributes;
public EmailAccounts $email_accounts;
public string $emailaddr;
public Customer $customer;
public function __construct(Customer $customer, string $emailaddr)
{
$this->customer = $customer;
$this->emailaddr = $emailaddr;
$this->attributes = $this->customer->server->request('Emails.get', [
'emailaddr' => $this->emailaddr
]);
$this->email_accounts = $this->email_accounts();
}
private function email_accounts(): EmailAccounts
{
return new EmailAccounts($this);
}
public function email_account(): EmailAccount
{
return new EmailAccount($this);
}
public function update(array $attributes): array
{
return $this->customer->server->request(
'Emails.update',
array_merge($attributes, [
'loginname' => $this->customer->loginname,
'emailaddr' => $this->emailaddr,
])
);
}
public function delete(): array
{
return $this->customer->server->request('Emails.delete', [
'loginname' => $this->customer->loginname,
'emailaddr' => $this->emailaddr
]);
}
}

34
src/EmailAccount.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace Envoyr\Froxlor;
class EmailAccount
{
public array $attributes;
public Email $email;
public function __construct(Email $email)
{
$this->email = $email;
$this->attributes = $this->email->attributes;
}
public function delete()
{
$this->email->customer->server->request('EmailAccounts.delete', [
'loginname' => $this->email->customer->loginname,
'emailaddr' => $this->email->emailaddr,
]);
}
public function update(array $attributes): array
{
return $this->email->customer->server->request(
'EmailAccounts.update',
array_merge($attributes, [
'loginname' => $this->email->customer->loginname,
'emailaddr' => $this->email->emailaddr,
])
);
}
}

23
src/EmailAccounts.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace Envoyr\Froxlor;
class EmailAccounts
{
public Email $email;
public function __construct(Email $email)
{
$this->email = $email;
}
public function create(string $email_password, bool $sendinfomail = false): array
{
return $this->email->customer->server->request('EmailAccounts.add', [
'loginname' => $this->email->customer->loginname,
'emailaddr' => $this->email->emailaddr,
'email_password' => $email_password,
'sendinfomail' => $sendinfomail,
]);
}
}

30
src/Emails.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
namespace Envoyr\Froxlor;
class Emails
{
public Customer $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function create(string $email_part, string $domain, string $description = null): array
{
return $this->customer->server->request('Emails.add', [
'loginname' => $this->customer->loginname,
'email_part' => $email_part,
'domain' => $domain,
'description' => $description,
]);
}
public function list(): array
{
return $this->customer->server->request('Emails.listing', [
'loginname' => $this->customer->loginname,
]);
}
}

39
src/Ftp.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace Envoyr\Froxlor;
class Ftp
{
public array $attributes;
public string $username;
public Customer $customer;
public function __construct(Customer $customer, string $username)
{
$this->customer = $customer;
$this->username = $username;
$this->attributes = $this->customer->server->request('Ftps.get', [
'loginname' => $this->customer->loginname,
'username' => $this->username
]);
}
public function update(array $attributes): array
{
return $this->customer->server->request(
'Ftps.update',
array_merge($attributes, [
'loginname' => $this->customer->loginname,
'username' => $this->username,
])
);
}
public function delete(): array
{
return $this->customer->server->request('Ftps.delete', [
'loginname' => $this->customer->loginname,
'username' => $this->username
]);
}
}

31
src/Ftps.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
namespace Envoyr\Froxlor;
class Ftps
{
public Customer $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function create(string $password, string $path = '/', string $description = null, bool $mail = false): array
{
return $this->customer->server->request('Ftps.add', [
'loginname' => $this->customer->loginname,
'ftp_password' => $password,
'path' => $path,
'ftp_description' => $description,
'sendinfomail' => $mail,
]);
}
public function list(): array
{
return $this->customer->server->request('Ftps.listing', [
'loginname' => $this->customer->loginname,
]);
}
}

65
src/Server.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
namespace Envoyr\Froxlor;
use GuzzleHttp\Client;
class Server
{
public Customers $customers;
protected Client $client;
protected string $apiKey;
protected string $apiSecret;
protected array $config;
public function __construct(array $config)
{
$this->config = $config;
$this->client = new Client([
'base_uri' => $config['host']
]);
$this->apiKey = $config['key'];
$this->apiSecret = $config['secret'];
$this->customers = $this->customers();
}
private function customers(): Customers
{
return new Customers($this);
}
public function request($command, array $attributes = [], bool $clear_empty_attributes = false): array
{
if ($clear_empty_attributes) {
$attributes = array_filter($attributes, fn($value) => !is_null($value) && $value !== '');
}
$payload = [
'header' => [
'apikey' => $this->apiKey,
'secret' => $this->apiSecret,
],
'body' => [
'command' => $command,
'params' => $attributes
]
];
$response = $this->client->post("api.php", [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => json_encode($payload)
]);
$payload = json_decode($response->getBody(), true);
return $payload['data'];
}
public function customer(string $loginname): Customer
{
return new Customer($this, $loginname);
}
}