Файл: billing/_rootinc/da.class.inc.php
Строк: 199
<?
class DirectAdmin
{
public $controller = true;
public $protocol = null;
public $host = null;
public $user=null;
public $password = null;
public $error = null;
public $cookie = null;
public $fp=null;
public function startup(&$controller) {
$this->controller =& $controller;
}
public function DirectAdmin($protocol,$host,$user,$password) {
$this->protocol=$protocol;
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->cookie="_da_".str_replace(" ","",microtime()).".cookie";
$this->logIn();
}
public function send($api,$query,$post) {
global $full_home_path;
if ($post == "get") { $getAddon = "?".$query; }
$this->fp = curl_init();
curl_setopt($this->fp, CURLOPT_URL, $this->protocol."://".$this->host.":2222/".$api.$getAddon);
curl_setopt($this->fp, CURL_HTTP_VERSION_1_1, 1);
if ($post == "post") {
curl_setopt($this->fp, CURLOPT_POST, 1);
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $query);
}
curl_setopt($this->fp, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->fp, CURLOPT_FAILONERROR, 0);
curl_setopt($this->fp, CURLOPT_COOKIEJAR, $full_home_path."/_roottemp/".$this->cookie);
curl_setopt($this->fp, CURLOPT_COOKIEFILE, $full_home_path."/_roottemp/".$this->cookie);
curl_setopt($this->fp, CURLOPT_TIMEOUT, 120);
$result = curl_exec($this->fp);
curl_close($this->fp);
return $result;
}
public function logIn() {
$result = $this->send("CMD_LOGIN","referer=/&username=$this->user&password=$this->password","post");
if ($this->checkLogin()) {
return true;
} else {
return false;
}
}
public function checkLogin() {
$result = $this->send("CMD_API_LOGIN_TEST","","post");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "logIn: Authentication error";
return false;
}
}
public function logOut() {
global $full_home_path;
$result = $this->send("CMD_LOGOUT","","get");
@unlink($full_home_path."/_roottemp/".$this->cookie);
}
public function createAccount($login, $email, $pwd, $domain, $tarif, $userip) {
$result = $this->send("CMD_API_ACCOUNT_USER","action=create&add=Submit&username=$login&email=$email&passwd=$pwd&passwd2=$pwd&domain=$domain&package=$tarif&ip=$userip¬ify=no","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "createAccount: ".$result[error]." ".$result[details];
return false;
}
}
public function createResellerAccount($login, $email, $pwd, $domain, $tarif) {
$result = $this->send("CMD_API_ACCOUNT_USER","action=create&add=Submit&username=$login&email=$email&passwd=$pwd&passwd2=$pwd&domain=$domain&package=$tarif&ip=shared¬ify=no","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "createAccount: ".$result[error]." ".$result[details];
return false;
}
}
public function get_user_info($name) {
$result = $this->send("CMD_API_SHOW_USER_CONFIG","user=$name","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return $result;
} else {
$this->error = "get_user_info: ".$result[error]." ".$result[details];
return false;
}
}
public function is_suspended_user($name) {
$info=$this->get_user_info($name);
return ($info['suspended']=='no')?false:true;
}
public function is_active_user($name) {
return !$this->is_suspended_user($name);
}
public function suspend_user($name) {
# if($this->is_suspended_user($name)) return false;
$result = $this->send("CMD_API_SELECT_USERS","select0=$name&dosuspend=1","post");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "suspend_user: ".$result[error]." ".$result[details];
return false;
}
}
public function activate_user($name) {
# if($this->is_active_user($name)) return false;
$result = $this->send("CMD_API_SELECT_USERS","select0=$name&dounsuspend=1","post");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "activate_user: ".$result[error]." ".$result[details];
return false;
}
}
public function set_language($name,$lng) {
$result = $this->send("CMD_API_MODIFY_USER","action=single&user=$name&lvalue=$lng&language=1","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "set_language: ".$result[error]." ".$result[details];
return false;
}
}
public function set_package_user($name,$package) {
$result = $this->send("CMD_API_MODIFY_USER","action=package&user=$name&package=$package","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "set_package_user: ".$result[error]." ".$result[details];
return false;
}
}
public function add_domain_pointer($mainDomain,$domain) {
$result = $this->send("CMD_API_DOMAIN_POINTER","domain=$mainDomain&action=add&from=$domain&alias=yes","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "add_domain_pointer: ".$result[error]." ".$result[details];
return false;
}
}
public function set_password($name,$pwd) {
$result = $this->send("CMD_API_USER_PASSWD","username=$name&passwd=$pwd&passwd2=$pwd","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "set_password: ".$result[error]." ".$result[details];
return false;
}
}
public function get_users() {
$result = $this->send("CMD_API_SHOW_USERS","","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return $result['list'];
} else {
$this->error = "get_users: ".$result[error]." ".$result[details];
return false;
}
}
public function get_packages() {
$result = $this->send("CMD_API_PACKAGES_USER","","get");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return $result['list'];
} else {
$this->error = "get_packages: ".$result[error]." ".$result[details];
return false;
}
}
public function delete_user($name) {
$result = $this->send("CMD_API_SELECT_USERS","select0=$name&delete=yes&confirmed=Confirm","post");
$result = $this->parseAPIresult($result);
if (!$result[error]) {
return true;
} else {
$this->error = "delete_user: ".$result[error]." ".$result[details];
return false;
}
}
public function parseAPIresult($results) {
if (!preg_match("/<html>/iu",$results)) {
$results = mb_split("&",$results);
$result_array = array();
while (list($i,$result) = @each($results)) {
$result = mb_split("=",$result);
$param = $result[0];
$value = $result[1];
if (preg_match("/[]$/u",$param)) {
$param = preg_replace("/[]$/u","",$param);
$result_array[$param][] = $value;
} else {
$result_array[$param] = $value;
}
}
return $result_array;
}
}
}
?>