commit 320a1539184b1b345312a9255c058dd60e4d6a27 Author: envoyr Date: Tue Jan 18 17:14:29 2022 +0100 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f31fd39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.idea +/example +/vendor +composer.lock \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5acac91 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Maurice Preuß (envoyr) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2eec6d --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# PHP Froxlor API Client + +API Wrapper for Froxlor. + +## How to use + +```` +$froxlor = new \Envoyr\Froxlor\Server([ + 'host' => 'de-nue-dev.bitinflow.space', + 'key' => '', + 'secret' => '' +]); +```` + +### Customer + +```` +$response = $froxlor + ->customers + ->create([ + 'email' => 'hello@example.com', + 'firstname' => 'Test', + 'name' => 'Testman', + 'custom_notes' => 'Created By API', + 'customernumber' => 1337, + 'new_loginname' => 'username', + 'new_customer_password' => 'someRandomString', + 'hosting_plan_id' => 1, + 'api_allowed' => false, + 'createstdsubdomain' => true, + ]); +```` + +### Email + +```` +$response = $froxlor + ->customer('example') + ->email('hello@example.com') + ->attributes; +```` + +### Info + +Domains, Ftps, Email & EmailAccounts are also available. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4e345c6 --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "envoyr/php-froxlor-client", + "type": "library", + "autoload": { + "psr-4": { + "Envoyr\\Froxlor\\": "src/" + } + }, + "authors": [ + { + "name": "envoyr", + "email": "hello@envoyr.com" + } + ], + "minimum-stability": "dev", + "require": { + "php": "^7.4|^8.0", + "guzzlehttp/guzzle": "^7.0.1", + "ext-json": "*" + } +} diff --git a/src/Customer.php b/src/Customer.php new file mode 100644 index 0000000..b8975cb --- /dev/null +++ b/src/Customer.php @@ -0,0 +1,93 @@ +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 + ]); + } +} diff --git a/src/Customers.php b/src/Customers.php new file mode 100644 index 0000000..fb8322c --- /dev/null +++ b/src/Customers.php @@ -0,0 +1,18 @@ +server = $server; + } + + public function create(array $attributes): array + { + return $this->server->request('Customers.add', $attributes); + } +} \ No newline at end of file diff --git a/src/Database.php b/src/Database.php new file mode 100644 index 0000000..c30e816 --- /dev/null +++ b/src/Database.php @@ -0,0 +1,38 @@ +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 + ]); + } +} \ No newline at end of file diff --git a/src/Databases.php b/src/Databases.php new file mode 100644 index 0000000..818ae5c --- /dev/null +++ b/src/Databases.php @@ -0,0 +1,35 @@ +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, + ]); + } +} \ No newline at end of file diff --git a/src/Domain.php b/src/Domain.php new file mode 100644 index 0000000..545edff --- /dev/null +++ b/src/Domain.php @@ -0,0 +1,36 @@ +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 + ]); + } +} \ No newline at end of file diff --git a/src/Domains.php b/src/Domains.php new file mode 100644 index 0000000..b25ddb1 --- /dev/null +++ b/src/Domains.php @@ -0,0 +1,36 @@ +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, + ] + ], + ]); + } +} \ No newline at end of file diff --git a/src/Email.php b/src/Email.php new file mode 100644 index 0000000..857629c --- /dev/null +++ b/src/Email.php @@ -0,0 +1,51 @@ +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 + ]); + } +} \ No newline at end of file diff --git a/src/EmailAccount.php b/src/EmailAccount.php new file mode 100644 index 0000000..86ed5d8 --- /dev/null +++ b/src/EmailAccount.php @@ -0,0 +1,34 @@ +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, + ]) + ); + } +} \ No newline at end of file diff --git a/src/EmailAccounts.php b/src/EmailAccounts.php new file mode 100644 index 0000000..e15652a --- /dev/null +++ b/src/EmailAccounts.php @@ -0,0 +1,23 @@ +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, + ]); + } +} \ No newline at end of file diff --git a/src/Emails.php b/src/Emails.php new file mode 100644 index 0000000..a189798 --- /dev/null +++ b/src/Emails.php @@ -0,0 +1,30 @@ +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, + ]); + } +} \ No newline at end of file diff --git a/src/Ftp.php b/src/Ftp.php new file mode 100644 index 0000000..7fc0bd7 --- /dev/null +++ b/src/Ftp.php @@ -0,0 +1,39 @@ +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 + ]); + } +} diff --git a/src/Ftps.php b/src/Ftps.php new file mode 100644 index 0000000..5aa064c --- /dev/null +++ b/src/Ftps.php @@ -0,0 +1,31 @@ +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, + ]); + } +} \ No newline at end of file diff --git a/src/Server.php b/src/Server.php new file mode 100644 index 0000000..d370800 --- /dev/null +++ b/src/Server.php @@ -0,0 +1,65 @@ +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); + } +}