Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * DirectAdmin API Class
- *
- * With this class you can communicate with the DirectAdmin API
- *
- * @author Rick Doorakkers
- * @version 0.1
- */
- class DirectAdmin
- {
- private $_method,
- $_host,
- $_port,
- $_username,
- $_password,
- $_bindHost,
- $_socket,
- $_error,
- $_result;
- /**
- * DirectAdmin Constructor
- *
- * This constructor will save the settings and try to connect to the DirectAdmin API.
- *
- * @param String $host
- * @param Int $port
- * @param String $username
- * @param String $password
- * @param String $method
- */
- function __construct( $host, $port, $username, $password, $method = "GET" )
- {
- $this->_host = $host;
- $this->_port = $port;
- $this->_username = $username;
- $this->_password = $password;
- $this->_method = $method;
- $this->_bindHost = '****';
- }
- /**
- * This function will return a array with all the users
- *
- * @param String $resellerName
- */
- public function getResellerUserList( $resellerName )
- {
- $this->query( '/CMD_API_SHOW_USERS', array( 'reseller' => $resellerName ));
- }
- /**
- * This function will return a array with all the users
- *
- * @param String $resellerName
- */
- public function getResellerList()
- {
- $this->query( '/CMD_API_SHOW_RESELLERS', array());
- }
- private function query( $request, $content = array() )
- {
- $this->_error = array();
- $headers = array(
- 'User-Agent' => 'HTTPSocket/2.6',
- 'Host' => $this->_host . ':' . $this->_port,
- 'Accept' => '*/*',
- 'Connection' => 'Close'
- );
- $this->_socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
- socket_bind( $this->_socket, $this->_bindHost );
- if( !@socket_connect( $this->_socket, $this->_host, $this->_port ) )
- {
- $this->_error[] = 'Er kon geen verbinding worden gemaakt met de server.';
- return false;
- }
- $headers['Authorization'] = 'Basic ' . base64_encode($this->_username . ':' . $this->_password);
- if( count( $content ) > 0 )
- {
- $pairs = array();
- foreach( $content as $key => $value )
- {
- $pairs[] = $key . '=' . urlencode($value);
- }
- $request .= '?' . implode('&', $pairs);
- }
- echo $request;
- /*
- $query = $this->_method . ' ' . $request . " HTTP/1.0\n";
- foreach( $headers as $key => $value )
- {
- $query .= $key . ':' . $value . "\n";
- } */
- echo '<pre>' , $query , '</pre>';
- socket_write( $this->_socket, $query );
- while ( $out = socket_read( $this->_socket, 2048 ) )
- {
- $this->_result .= $out;
- }
- echo '<pre>' , $this->_result , '</pre>';
- socket_close( $this->_socket );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement