Файл: _rootinc/pskz.inc.php
Строк: 369
<?
class PSKZ
{
private $host = null;
private $user = null;
private $password = null;
private $log = null;
public $error = null;
private $answer = null;
private $answerArray = null;
private $request = null;
public function init($host,$user,$password,$log)
{
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->log = $log;
}
private function send($action, $requestData) {
$url = "https://".$this->host."/kzdomain/".$action;
$url .= '?username='.urlencode($this->user);
$url .= '&password='.urlencode($this->password);
$url .= '&input_format=http&output_format=json';
$url .= '&'.http_build_query($requestData, 'custom', '&');
$this->request = $requestData;
$this->request["username"] = $this->user;
$this->request["password"] = $this->password;
$this->request["action"] = $action;
$this->slog("n<<< Send Requestn");
$this->slog($this->request, MODE_CLIENT);
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $url);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_HEADER, 0);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
$this->answer = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp); $this->slog($this->error); return false;
}
$this->slog("n>>> Got Responsen");
$this->slog($this->answer, MODE_SERVER);
curl_close($fp);
$this->answerArray = @json_decode($this->answer, true);
if(is_array($this->answerArray)) {
return $this->answerArray;
} else {
$this->error = "send ($action): no result array"; $this->slog($this->error); return false;
}
}
private function slog($str, $mode = MODE_INFO) {
if ($this->log) {
switch($mode) {
case MODE_INFO: $mode = "I"; break;
case MODE_CLIENT: $mode = "C"; break;
case MODE_SERVER: $mode = "S"; break;
}
if (is_array($str)) {
ob_start();
var_export($str);
$str = ob_get_clean();
}
if (is_string($str)) {
$str = explode("n", $str);
}
if (is_array($str)) {
foreach($str as $tmp) {
if (function_exists("posix_getpid")) { $pid = @posix_getpid(); }
else if (function_exists("getmypid")) { $pid = @getmypid(); }
$dt = date("Y-m-d H:i:s");
$tmp = sprintf("%s [%5s] %s: %sn", $dt, $pid, $mode, $tmp);
@error_log($tmp, 3, "./_rootlogs/".date("Ymd")."_pskz.log");
}
}
}
}
public function createContact($name, $org, $cc, $sp, $pc, $city, $street, $email, $voice, $fax) {
if (!$sp) { $sp = $city; }
$action = "contact-create";
$requestData = array(
'email' => $email,
'voice' => $voice,
'fax' => $fax,
'name' => $name,
'org' => $org,
'street' => $street,
'city' => $city,
'sp' => $sp,
'pc' => $pc,
'cc' => $cc
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return $result["answer"]["handle"];
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function updateContact($handle, $name, $org, $cc, $sp, $pc, $city, $street, $email, $voice, $fax) {
if (!$sp) { $sp = $city; }
$action = "contact-update";
$requestData = array(
'handle' => $handle,
'email' => $email,
'voice' => $voice,
'fax' => $fax,
'name' => $name,
'org' => $org,
'street' => $street,
'city' => $city,
'sp' => $sp,
'pc' => $pc,
'cc' => $cc
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function registerDomain($dname, $handle, $ns1, $ns2, $ns3, $ns4, $years_num) {
if ($ns1) { $nsList["ns"][] = $ns1; }
if ($ns2) { $nsList["ns"][] = $ns2; }
if ($ns3) { $nsList["ns"][] = $ns3; }
if ($ns4) { $nsList["ns"][] = $ns4; }
$action = "domain-create";
$requestData = array(
'dname' => $dname,
'registrant_handle' => $handle,
'admin_handle' => $handle,
'nameservers' => $nsList,
'years_num' => $years_num,
'srvloc' => array(
'sp' => 'Almaty',
'city' => 'Almaty',
'street' => 'pl. Respubliki, 15'
)
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function infoDomain($dname) {
$action = "domain-whois";
$requestData = array(
'dname' => $dname
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return $result["answer"];
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function renewDomain($dname, $years_num) {
$expDate = $this->infoDomain($dname);
if (!$expDate) { return false; }
$expDate = @mb_split("T", $expDate["expire"]["utc"]);
$expDate = $expDate[0];
$action = "domain-renew";
$requestData = array(
'dname' => $dname,
'years_num' => $years_num,
'cur_expiry_date' => $expDate
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function transferDomain($dname, $handle, $eppcode) {
$action = "domain-transfer";
$requestData = array(
'dname' => $dname,
'registrant_handle' => $handle,
'admin_handle' => $handle,
'eppcode' => $eppcode
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function getNS($dname) {
$action = "nss-get";
$requestData = array(
'dname' => $dname
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return $result["answer"]["nameservers"]["ns"];
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function infoIpHost($ns) {
$action = "ns-info";
$requestData = array(
'ns' => $ns
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return $result["answer"]["ip_list"]["ip"][0];
}
else if ($result["result"] == "error" and $result["error_code"] == "NS_NOT_EXIST") {
return false;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function createIpHost($ns, $ip) {
$action = "ns-create";
$requestData = array(
'ns' => $ns,
'ip_list' => array('ip' => array($ip))
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function updateIpHost($ns, $ip) {
$action = "ns-update";
$requestData = array(
'ns' => $ns,
'ip_list' => array('ip' => array($ip))
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
public function updateNS($dname, $ns1, $ns2, $ns3, $ns4, $ns1ip, $ns2ip, $ns3ip, $ns4ip) {
if ($ns1 and $ns1ip) {
$nsIpOld = $this->infoIpHost($ns1); if ($this->error) { return false; }
if ($nsIpOld and $nsIpOld != $ns1ip) { $this->updateIpHost($ns1, $ns1ip); if ($this->error) { return false; } }
else { $this->createIpHost($ns1, $ns1ip); if ($this->error) { return false; } }
}
if ($ns2 and $ns2ip) {
$nsIpOld = $this->infoIpHost($ns2); if ($this->error) { return false; }
if ($nsIpOld and $nsIpOld != $ns2ip) { $this->updateIpHost($ns2, $ns2ip); if ($this->error) { return false; } }
else { $this->createIpHost($ns2, $ns2ip); if ($this->error) { return false; } }
}
if ($ns3 and $ns3ip) {
$nsIpOld = $this->infoIpHost($ns3); if ($this->error) { return false; }
if ($nsIpOld and $nsIpOld != $ns3ip) { $this->updateIpHost($ns3, $ns3ip); if ($this->error) { return false; } }
else { $this->createIpHost($ns3, $ns3ip); if ($this->error) { return false; } }
}
if ($ns4 and $ns4ip) {
$nsIpOld = $this->infoIpHost($ns4); if ($this->error) { return false; }
if ($nsIpOld and $nsIpOld != $ns4ip) { $this->updateIpHost($ns4, $ns4ip); if ($this->error) { return false; } }
else { $this->createIpHost($ns4, $ns4ip); if ($this->error) { return false; } }
}
if ($ns1) { $nsList["ns"][] = $ns1; }
if ($ns2) { $nsList["ns"][] = $ns2; }
if ($ns3) { $nsList["ns"][] = $ns3; }
if ($ns4) { $nsList["ns"][] = $ns4; }
$action = "nss-update";
$requestData = array(
'dname' => $dname,
'nameservers' => $nsList
);
$result = $this->send($action, $requestData);
if (!$result) { return false; }
if ($result["result"] == "success") {
return true;
}
else {
$this->error = $action.": ".$result["error_code"]." (".$result["error_text"].")"; $this->slog($this->error); return false;
}
}
}
?>