Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.  
  3. if( file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'errorHandler.php') )
  4. {
  5.     require_once __DIR__ . DIRECTORY_SEPARATOR . 'errorHandler.php';
  6. }
  7. else
  8. {
  9.     echo "some required components are missing";
  10. }
  11.  
  12. class whmApi
  13. {
  14.  
  15.     protected $username;
  16.     protected $user;
  17.     protected $password;
  18.     protected $domain;
  19.     protected $contactemail;
  20.     protected $reason;
  21.  
  22.     public function __construct($datatable)
  23.     {
  24.         $this->setData('username', $datatable['username']);
  25.         $this->setData('user', $datatable['user']);
  26.         $this->setData('password', $datatable['password']);
  27.         $this->setData('domain', $datatable['domain']);
  28.         $this->setData('contactemail', $datatable['email']);
  29.         $this->setData('reason', $datatable['reason']);
  30.     }
  31.  
  32.     function setData($field, $value)
  33.     {
  34.         $this->$field = $value ? $value : null;
  35.     }
  36.  
  37.     public static function execute($action, $user, $serverDetails)
  38.     {
  39.  
  40.         $query = $action . "?api.version=1&" . http_build_query($user, '', '&');
  41.  
  42.         $whmusername = $serverDetails['username'];
  43.         $whmpassword = $serverDetails['password'];
  44.         $curl = curl_init();
  45.         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  46.         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  47.         curl_setopt($curl, CURLOPT_HEADER, 0);
  48.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  49.         $header[0] = "Authorization: Basic " . base64_encode($whmusername . ":" . $whmpassword) . "\n\r";
  50.         curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  51.  
  52.         $query = "https://" . $serverDetails['ip'] . ":2087/json-api/" . $query;
  53.  
  54.  
  55.         curl_setopt($curl, CURLOPT_URL, $query);
  56.         $result = curl_exec($curl);
  57.         $errorHandler = new errorHandler($curl, $result);
  58.         $result = $errorHandler->getDecodedResult();
  59.  
  60.         curl_close($curl);
  61.         return $result;
  62.     }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement