public static function createDB($client_id) { $cfg = erConfigClassLhConfig::getInstance(); $sock = new HTTPSocket(); $sock->connect('ssl://' . $cfg->getSetting('site', 'direct_admin_ip'), $cfg->getSetting('site', 'direct_admin_port')); $sock->set_login($cfg->getSetting('site', 'direct_admin_user'), $cfg->getSetting('site', 'direct_admin_pass')); $sock->set_method('POST'); $sock->query('/CMD_API_DATABASES', array('action' => 'create', 'name' => "client{$client_id}", 'userlist' => $cfg->getSetting('site', 'direct_admin_dbuser'), 'passwd' => $cfg->getSetting('site', 'direct_admin_dbpass'), 'passwd2' => $cfg->getSetting('site', 'direct_admin_dbpass'))); return $sock->fetch_body(); }
/** * laravel-directadmin * * Laravel bundle to access the DirectAdmin API * * @author Chris Schalenborgh <*****@*****.**> * @version 0.1 * @package laravel-directadmin * @link http://www.directadmin.com/api.html * @license BSD License */ // configure autoloader Autoloader::map(array('HTTPSocket' => Bundle::path('directadmin') . 'lib' . DS . 'DirectAdmin.php')); // Register a mailer in the IoC container IoC::singleton('DirectAdmin', function () { // instantiate new directadmin $sock = new HTTPSocket(); // load settings $config = Config::get('directadmin::settings', array()); // set host/port if (!empty($config['host']) && !empty($config['port'])) { $sock->connect($config['host'], $config['port']); } // set login/password if (!empty($config['login']) && !empty($config['password'])) { $sock->set_login($config['login'], $config['password']); } // Return the instance. return $sock; });
<?php echo '<pre>'; include '../Source/DA/Emails.php'; // Optional, you can pass these as arguments of the class constructor too $socket = new HTTPSocket(); $socket->connect('topdomain.nl', 2222); $socket->set_login('user', 'pass'); DA_Api::$DEFAULT_SOCKET = $socket; DA_Api::$DEFAULT_DOMAIN = 'domain.nl'; // new DA_Emails instance $emails = new DA_Emails(); // displays the users print_r($emails->fetch()); // creates a new user, should return true var_dump($emails->create('testing', 'test_pass', 20)); // fetches the data, quota and usage, of one user print_r($emails->fetchUserQuota('testing')); // sets a new password and quota var_dump($emails->modify('testing', 'new_test_pass', 30)); // fetches all data, including quotas and usage print_r($emails->fetchQuotas()); // deletes the test user, should be true var_dump($emails->delete('testing'));
<?php echo '<pre>'; include_once '../Source/HTTPSocket.php'; $sock = new HTTPSocket(); $sock->connect('domain.nl', 2222); $sock->set_login('DirectAdminUsername', 'DirectAdminPassword'); include_once '../Source/DA/Emails.php'; $emails = new DA_Emails($sock, 'domain.com'); try { // Fetch a list of users (before the @ sign) or pop emails print_r($emails->fetch()); // Fetch a list of users and their usage and quota print_r($emails->fetchQuotas()); // Fetch the quota and usage for a single user print_r($emails->fetchUserQuota('username')); // Create a user email => username - password - quota (MiB) var_dump($emails->create('username', 'pass', 50)); // Modify a user email => username - password - quota (MiB) var_dump($emails->modify('username')); // Delete a user email var_dump($emails->delete('username')); } catch (DA_Exception $e) { echo $e->getMessage(); } include_once '../Source/DA/Forwarders.php'; $fwd = new DA_Forwarders($sock); $fwd->setDomain('refox.nl'); try { // Fetch a list of users and their forward emails print_r($fwd->fetch());