<?
class DirectAdmin
{
var $s;
function DirectAdmin($host,$auser,$apass)
{
$this->s = new HTTPSocket;
$this->s->connect($host,2222);
$this->s->set_login($auser,$apass);
return $this->check_auth($auser,$apass);
}
function check_auth($user,$pass)
{
$this->s->query('/CMD_API_VERIFY_PASSWORD',
array(
'user' => $user,
'pass' => $pass,
));
$ret=$this->s->fetch_parsed_body();
if(! isset($ret['error']))
return 0;
else
return $ret['details'];
}
function add_user($name,$email,$passwd,$domain,$package,$ip)
{
$this->s->query('/CMD_API_ACCOUNT_USER', array(
'action' => 'create',
'username' => $name,
'email' => $email,
'passwd' => $passwd,
'passwd2' => $passwd,
'domain' => $domain,
'package' => $package,
'ip' => $ip,
'notify' => 'yes'
));
$ret=$this->s->fetch_parsed_body();
if(!isset($ret['error']))
return 0;
else
return $ret['error'].' '.$ret['details'];
}
function get_user_info($name)
{
$this->s->query('/CMD_API_SHOW_USER_CONFIG',
array(
'user' => $name,
));
$ret=$this->s->fetch_parsed_body();
if(!isset($ret['error']))
return $ret;
else
return false;
}
function is_suspended_user($name)
{
$info=$this->get_user_info($name);
return ($info['suspended']=='no')?0:1;
}
function is_active_user($name)
{
return !$this->is_suspended_user($name);
}
function suspend_user($name)
{
if($this->is_suspended_user($name)) return 0;
$this->s->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'suspend' => 'Suspend',
'select0' => $name
));
return $this->s->fetch_body();
}
function activate_user($name)
{
if($this->is_active_user($name)) return 0;
$this->s->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'suspend' => 'Unsuspend',
'select0' => $name
));
return $this->s->fetch_body();
}
function set_package_user($name,$package)
{
$this->s->query('/CMD_API_MODIFY_USER',
array(
'action' => 'package',
'user' => $name,
'package' => $package
));
$ret=$this->s->fetch_parsed_body();
if(!$ret['error'])
return 0;
else
return $ret['error'].' '.$ret['details'];
}
function get_users()
{
$this->s->query('/CMD_API_SHOW_USERS');
$ret=$this->s->fetch_parsed_body();
return $ret['list'];
}
function get_packages()
{
$this->s->query('/CMD_API_PACKAGES_USER');
$r=$this->s->fetch_parsed_body();
return $r['list'];
}
function delete_user($name)
{
$this->s->set_method('post');
$this->s->query('/CMD_SELECT_USERS',
array(
'location' => 'CMD_SELECT_USERS',
'confirmed' => 'Confirm',
'delete' => 'yes',
'select0' => $name
));
return $this->s->fetch_body();
}
}
?>