-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4d215e
Showing
33 changed files
with
3,573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## [Unreleased] | ||
## Changed | ||
- Switch to PHP-CS-Fixer 2 | ||
- Switch to new Coveralls packages | ||
|
||
## [0.1.4] - 2016-12-09 | ||
### Added | ||
- Creating domain pointers and aliases | ||
- Suspending/unsuspending resellers and users (#19) | ||
|
||
## [0.1.3] - 2016-10-18 | ||
### Added | ||
- Add access hosts to database management (#13) | ||
- Enabled SSL verification (#14) | ||
|
||
## [0.1.2] - 2016-01-31 | ||
### Added | ||
- Catch-all email management | ||
- Database management | ||
|
||
## [0.1.1] - 2015-11-10 | ||
### Added | ||
- Domain management | ||
- Subdomain management | ||
- User config modification | ||
|
||
## 0.1.0 - 2015-11-06 | ||
### Added | ||
- Admin/reseller/user contexts and logins | ||
- Impersonation of other users ("log in as") | ||
- Creating and deleting all account types | ||
- Fetching admin, reseller and user lists | ||
- Fetching user info | ||
- Fetching domain lists | ||
- Retrieving domain stats and configuration | ||
- Retrieving, creating and deleting email forwarders | ||
- Retrieving, creating and deleting mailboxes | ||
- Resetting mailbox passwords | ||
|
||
[Unreleased]: https://github.com/omines/directadmin/compare/v0.1.4...master | ||
[0.1.4]: https://github.com/omines/directadmin/compare/v0.1.3...v0.1.4 | ||
[0.1.3]: https://github.com/omines/directadmin/compare/v0.1.2...v0.1.3 | ||
[0.1.2]: https://github.com/omines/directadmin/compare/v0.1.1...v0.1.2 | ||
[0.1.1]: https://github.com/omines/directadmin/compare/v0.1.0...v0.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Omines Internetbureau B.V. | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# DirectAdmin API client | ||
|
||
[![Build Status](https://travis-ci.org/omines/directadmin.svg?branch=master)](https://travis-ci.org/omines/directadmin) | ||
[![Coverage Status](https://coveralls.io/repos/omines/directadmin/badge.svg?branch=master&service=github)](https://coveralls.io/github/omines/directadmin?branch=master) | ||
[![Scrutinizer](https://img.shields.io/scrutinizer/g/omines/directadmin.svg)](https://scrutinizer-ci.com/g/omines/directadmin/?branch=master) | ||
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/47a71204-f274-4416-9db1-9773d65845ca.svg)](https://insight.sensiolabs.com/projects/47a71204-f274-4416-9db1-9773d65845ca) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/omines/directadmin/master/LICENSE) | ||
|
||
This is a PHP client library to manage DirectAdmin control panel servers. We simply decided to develop this as we needed | ||
automation of our own DirectAdmin servers, and the existing implementations were unsupported and incomplete. | ||
|
||
[API documentation for this project is automatically generated on each push](https://hieupt7.github.io/directadmin/api/). | ||
|
||
## Installation | ||
|
||
[![Packagist](https://img.shields.io/packagist/v/omines/directadmin.svg)](https://packagist.org/packages/hieupt7/directadmin) | ||
[![Packagist](https://img.shields.io/packagist/vpre/omines/directadmin.svg)](https://packagist.org/packages/omines/directadmin#dev-master) | ||
|
||
The recommended way to install this library is through [Composer](http://getcomposer.org): | ||
```bash | ||
composer require hieupt7/directadmin | ||
``` | ||
|
||
If you're not familiar with `composer` follow the installation instructions for | ||
[Linux/Unix/Mac](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx) or | ||
[Windows](https://getcomposer.org/doc/00-intro.md#installation-windows), and then read the | ||
[basic usage introduction](https://getcomposer.org/doc/01-basic-usage.md). | ||
|
||
## Dependencies | ||
|
||
The library uses [Guzzle 6](https://github.com/guzzle/guzzle) as its HTTP communication layer. PHP versions supported | ||
are 5.6, 7.0, 7.1 and hhvm. | ||
|
||
## Basic usage | ||
|
||
To set up the connection use one of the base functions: | ||
|
||
```php | ||
use Omines\DirectAdmin\DirectAdmin; | ||
|
||
$adminContext = DirectAdmin::connectAdmin('http://hostname:2222', 'admin', 'pass'); | ||
$resellerContext = DirectAdmin::connectReseller('http://hostname:2222', 'reseller', 'pass'); | ||
$userContext = DirectAdmin::connectUser('http://hostname:2222', 'user', 'pass'); | ||
``` | ||
|
||
These functions return an | ||
[`AdminContext`](https://hieupt7.github.io/directadmin/api/class-Omines.DirectAdmin.Context.AdminContext.html), | ||
[`ResellerContext`](https://hieupt7.github.io/directadmin/api/class-Omines.DirectAdmin.Context.ResellerContext.html), and | ||
[`UserContext`](https://hieupt7.github.io/directadmin/api/class-Omines.DirectAdmin.Context.UserContext.html) | ||
respectively exposing the functionality available at the given level. All three extend eachother as DirectAdmin uses a | ||
strict is-a model. To act on behalf of a user you can use impersonation calls: | ||
|
||
```php | ||
$resellerContext = $adminContext->impersonateReseller($resellerName); | ||
$userContext = $resellerContext->impersonateUser($userName); | ||
``` | ||
Both are essentially the same but mapped to the correct return type. Impersonation is also done implicitly | ||
when managing a user's domains: | ||
|
||
```php | ||
$domain = $adminContext->getUser('user')->getDomain('example.tld'); | ||
``` | ||
This returns, if the domain exists, a [`Domain`](https://hieupt7.github.io/directadmin/api/class-Omines.DirectAdmin.Objects.Domain.html) | ||
instance in the context of its owning user, allowing you to manage its email accounts et al transparently. | ||
|
||
## Contributions | ||
|
||
As the DirectAdmin API keeps expanding pull requests are welcomed, as are requests for specific functionality. | ||
Pull requests should in general include proper unit tests for the implemented or corrected functions. | ||
|
||
For more information about unit testing see the `README.md` in the tests folder. | ||
|
||
## Legal | ||
|
||
This software was developed for internal use at [Omines Full Service Internetbureau](https://www.omines.nl/) | ||
in Eindhoven, the Netherlands. It is shared with the general public under the permissive MIT license, without | ||
any guarantee of fitness for any particular purpose. Refer to the included `LICENSE` file for more details. | ||
|
||
The project is not in any way affiliated with JBMC Software or its employees. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
set -e | ||
cd $(dirname $0)/.. | ||
|
||
# Create required folders | ||
mkdir -p _docs | ||
cd _docs | ||
git clone https://${GH_TOKEN}@github.com/omines/directadmin.git . > /dev/null | ||
git checkout gh-pages | ||
rm -rf api | ||
|
||
# Generate Api | ||
wget http://www.apigen.org/apigen.phar | ||
php apigen.phar generate -s ../src -d api --template-theme "bootstrap" | ||
rm apigen.phar | ||
|
||
# Set identity | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Travis" | ||
git config --global push.default "simple" | ||
|
||
# Push generated files | ||
git add --all . | ||
git commit -m "API documentation auto-updated" | ||
git push origin -fq > /dev/null | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "hieupt7/directadmin", | ||
"type": "library", | ||
"description": "PHP client library to manage DirectAdmin control panel servers.", | ||
"license": "MIT", | ||
"keywords": [ | ||
"library", "php", "directadmin", "control panel", "api", "direct admin" | ||
], | ||
"homepage": "https://github.com/hieupt7/directadmin", | ||
"authors": [ | ||
{ | ||
"name": "Niels Keurentjes", | ||
"email": "[email protected]", | ||
"homepage": "https://www.omines.nl/" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/hieupt7/directadmin/issues" | ||
}, | ||
"require": { | ||
"php": ">=5.6.0", | ||
"guzzlehttp/guzzle": "^6.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7 || ^7.3", | ||
"friendsofphp/php-cs-fixer": "^2.0", | ||
"php-coveralls/php-coveralls": "^2.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Omines\\DirectAdmin\\": "src/DirectAdmin/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.1.x-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="tests/phpunit-bootstrap.php"> | ||
|
||
<php> | ||
<ini name="date.timezone" value="UTC" /> | ||
<ini name="error_reporting" value="-1" /> | ||
<ini name="intl.default_locale" value="en" /> | ||
<ini name="intl.error_level" value="0" /> | ||
<ini name="memory_limit" value="-1" /> | ||
|
||
<!-- Override the following variables by environment or edit here --> | ||
<env name="DIRECTADMIN_URL" value="https://www.directadmin.com:2222" /> | ||
<env name="MASTER_ADMIN_USERNAME" value="admin" /> | ||
<env name="MASTER_ADMIN_PASSWORD" value="demo" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="DirectAdmin"> | ||
<directory>./tests/DirectAdmin/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
/* | ||
* DirectAdmin API Client | ||
* (c) Omines Internetbureau B.V. - https://omines.nl/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Omines\DirectAdmin\Context; | ||
|
||
use Omines\DirectAdmin\Objects\BaseObject; | ||
use Omines\DirectAdmin\Objects\Users\Admin; | ||
use Omines\DirectAdmin\Objects\Users\Reseller; | ||
use Omines\DirectAdmin\Objects\Users\User; | ||
|
||
/** | ||
* Context for administrator functions. | ||
* | ||
* @author Niels Keurentjes <[email protected]> | ||
*/ | ||
class AdminContext extends ResellerContext | ||
{ | ||
/** | ||
* Creates a new Admin level account. | ||
* | ||
* @param string $username | ||
* @param string $password | ||
* @param string $email | ||
* @return Admin The newly created Admin | ||
*/ | ||
public function createAdmin($username, $password, $email) | ||
{ | ||
return $this->createAccount($username, $password, $email, [], 'ACCOUNT_ADMIN', Admin::class); | ||
} | ||
|
||
/** | ||
* Creates a new Reseller level account. | ||
* | ||
* @param string $username | ||
* @param string $password | ||
* @param string $email | ||
* @param string $domain | ||
* @param string|array $package Either a package name or an array of options for custom | ||
* @param string $ip shared, sharedreseller or assign. Defaults to 'shared' | ||
* @return Reseller | ||
* @url http://www.directadmin.com/api.html#create for options to use. | ||
*/ | ||
public function createReseller($username, $password, $email, $domain, $package = [], $ip = 'shared') | ||
{ | ||
$options = array_merge( | ||
['ip' => $ip, 'domain' => $domain, 'serverip' => 'ON', 'dns' => 'OFF'], | ||
is_array($package) ? $package : ['package' => $package] | ||
); | ||
return $this->createAccount($username, $password, $email, $options, 'ACCOUNT_RESELLER', Reseller::class); | ||
} | ||
|
||
/** | ||
* Returns a list of known admins on the server. | ||
* | ||
* @return Admin[] | ||
*/ | ||
public function getAdmins() | ||
{ | ||
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_ADMINS'), Admin::class, $this); | ||
} | ||
|
||
/** | ||
* Returns a full list of all accounts of any type on the server. | ||
* | ||
* @return User[] | ||
*/ | ||
public function getAllAccounts() | ||
{ | ||
$accounts = array_merge($this->getAllUsers(), $this->getResellers(), $this->getAdmins()); | ||
ksort($accounts); | ||
return $accounts; | ||
} | ||
|
||
/** | ||
* Returns a full list of all users on the server, so no resellers or admins. | ||
* | ||
* @return User[] | ||
*/ | ||
public function getAllUsers() | ||
{ | ||
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_ALL_USERS'), User::class, $this); | ||
} | ||
|
||
/** | ||
* Returns a specific reseller by name, or NULL if there is no reseller by this name. | ||
* | ||
* @param string $username | ||
* @return null|Reseller | ||
*/ | ||
public function getReseller($username) | ||
{ | ||
$resellers = $this->getResellers(); | ||
return isset($resellers[$username]) ? $resellers[$username] : null; | ||
} | ||
|
||
/** | ||
* Returns the list of known resellers. | ||
* | ||
* @return Reseller[] | ||
*/ | ||
public function getResellers() | ||
{ | ||
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_RESELLERS'), Reseller::class, $this); | ||
} | ||
|
||
/** | ||
* Returns a new AdminContext acting as the specified admin. | ||
* | ||
* @param string $username | ||
* @param bool $validate Whether to check the admin exists and is an admin | ||
* @return AdminContext | ||
*/ | ||
public function impersonateAdmin($username, $validate = false) | ||
{ | ||
return new self($this->getConnection()->loginAs($username), $validate); | ||
} | ||
|
||
/** | ||
* Returns a new ResellerContext acting as the specified reseller. | ||
* | ||
* @param string $username | ||
* @param bool $validate Whether to check the reseller exists and is a reseller | ||
* @return ResellerContext | ||
*/ | ||
public function impersonateReseller($username, $validate = false) | ||
{ | ||
return new ResellerContext($this->getConnection()->loginAs($username), $validate); | ||
} | ||
} |
Oops, something went wrong.