Файл: _rootinc/subreg.inc.php
Строк: 517
<?
class SUBREG
{
private $host = null;
private $login = null;
private $password = null;
private $log = null;
public $error = null;
private $ssid = null;
private $answer = null;
private $isLogged = false;
public function init($host,$login,$password,$log)
{
$this->host = $host;
$this->login = $login;
$this->password = $password;
$this->log = $log;
}
private function sendCommand($command,$params) {
$this->slog("n<<< Send Request [$command]n");
$this->slog($params, MODE_CLIENT);
$client = new SoapClient(
null,
array(
"location" => "https://".$this->host."/cmd.php",
"uri" => "http://".$this->host."/soap"
)
);
$this->answer = $client->__call($command,$params);
if ($this->answer["status"]) {
$this->slog("n>>> Got Response [$command]n");
$this->slog($this->answer, MODE_SERVER);
return true;
} else {
$this->error = "::: sendCommand: $command: can't send or retrieve information"; $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")."_subreg.log");
}
}
}
}
private function login() {
if ($this->isLogged) { return true; }
$params = array (
"data" => array (
"login" => $this->login,
"password" => $this->password,
)
);
if (!$this->sendCommand("Login",$params)) { return false; }
if ($this->answer[status] == "ok") {
$this->ssid = $this->answer[data][ssid];
$this->isLogged = true;
return true;
} else {
$this->error = "::: login: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function createContact($name, $surname, $org, $street, $city, $pc, $sp, $cc, $phone, $fax, $email) {
if (!$this->login()) { return false; }
$contact = array(
"name" => $name,
"surname" => $surname,
"org" => $org,
"street" => $street,
"city" => $city,
"pc" => $pc,
"sp" => $sp,
"cc" => $cc,
"phone" => $phone,
"fax" => $fax,
"email" => $email
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"contact" => $contact
)
);
if (!$this->sendCommand("Create_Contact",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][contactid];
} else {
$this->error = "::: createContact: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function updateContact($id, $name, $surname, $org, $street, $city, $pc, $sp, $cc, $phone, $fax, $email) {
if (!$this->login()) { return false; }
$contact = array(
"id" => $id,
"name" => $name,
"surname" => $surname,
"org" => $org,
"street" => $street,
"city" => $city,
"pc" => $pc,
"sp" => $sp,
"cc" => $cc,
"phone" => $phone,
"fax" => $fax,
"email" => $email
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"contact" => $contact
)
);
if (!$this->sendCommand("Update_Contact",$params)) { return false; }
if ($this->answer[status] == "ok") {
return true;
} else {
$this->error = "::: updateContact: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function registerDomain($domain, $period, $contactId, $ns1, $ns2, $ns3, $ns4) {
if (!$this->login()) { return false; }
if ($ns1) { $nsArray[][hostname] = $ns1;}
if ($ns2) { $nsArray[][hostname] = $ns2;}
if ($ns3) { $nsArray[][hostname] = $ns3;}
if ($ns4) { $nsArray[][hostname] = $ns4;}
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
if (preg_match("/.eu$/ui",$domain)) { $orderParams = array("lang_eu" => "en"); } else { $orderParams = array(); }
$order = array(
"domain" => $domain,
"type" => "Create_Domain",
"params" => array (
"registrant" => array("id" => $contactId),
"contacts" => array(
"admin" => array("id" => $contactId),
"tech" => array("id" => $contactId),
"billing" => array("id" => $contactId)
),
"ns" => array("hosts" => $nsArray),
"period" => $period,
"params" => $orderParams
)
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"order" => $order
)
);
if (!$this->sendCommand("Make_Order",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][orderid];
} else {
$this->error = "::: registerDomain: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function transferDomain($domain, $contactId, $ns1, $ns2, $ns3, $ns4, $auth) {
if (!$this->login()) { return false; }
if ($ns1) { $nsArray[][hostname] = $ns1;}
if ($ns2) { $nsArray[][hostname] = $ns2;}
if ($ns3) { $nsArray[][hostname] = $ns3;}
if ($ns4) { $nsArray[][hostname] = $ns4;}
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
$order = array(
"domain" => $domain,
"type" => "Transfer_Domain",
"params" => array (
"operation" => "request",
"authid" => $auth,
"new" => array(
"registrant" => array("id" => $contactId),
"contacts" => array(
"admin" => array("id" => $contactId),
"tech" => array("id" => $contactId),
"billing" => array("id" => $contactId)
),
"ns" => array("hosts" => $nsArray),
)
)
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"order" => $order
)
);
if (!$this->sendCommand("Make_Order",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][orderid];
} else {
$this->error = "::: transferDomain: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function renewDomain($domain, $period) {
if (!$this->login()) { return false; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
$order = array(
"domain" => $domain,
"type" => "Renew_Domain",
"params" => array (
"period" => $period
)
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"order" => $order
)
);
if (!$this->sendCommand("Make_Order",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][orderid];
} else {
$this->error = "::: renewDomain: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function getNS($domain) {
if (!$this->login()) { return false; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
$params = array (
"data" => array (
"ssid" => $this->ssid,
"domain" => $domain
)
);
if (!$this->sendCommand("Info_Domain",$params)) { return false; }
if ($this->answer[status] == "ok") {
if ($this->answer[data][hosts][0]) { $result[] = $this->answer[data][hosts][0]; }
if ($this->answer[data][hosts][1]) { $result[] = $this->answer[data][hosts][1]; }
if ($this->answer[data][hosts][2]) { $result[] = $this->answer[data][hosts][2]; }
if ($this->answer[data][hosts][3]) { $result[] = $this->answer[data][hosts][3]; }
return $result;
} else {
$this->error = "::: getNS: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function getExpiration($domain) {
if (!$this->login()) { return false; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
$params = array (
"data" => array (
"ssid" => $this->ssid,
"domain" => $domain
)
);
if (!$this->sendCommand("Info_Domain",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][exDate];
} else {
$this->error = "::: getExpiration: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function updateNS($domain, $ns1, $ns2, $ns3, $ns4, $ns1ip, $ns2ip, $ns3ip, $ns4ip) {
if (!$this->login()) { return false; }
if ($ns1) { $nsArray[0][hostname] = $ns1; if ($ns1ip) { $nsArray[0][ipv4] = $ns1ip; } }
if ($ns2) { $nsArray[1][hostname] = $ns2; if ($ns2ip) { $nsArray[1][ipv4] = $ns2ip; } }
if ($ns3) { $nsArray[2][hostname] = $ns3; if ($ns3ip) { $nsArray[2][ipv4] = $ns3ip; } }
if ($ns4) { $nsArray[3][hostname] = $ns4; if ($ns4ip) { $nsArray[3][ipv4] = $ns4ip; } }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
$order = array(
"domain" => $domain,
"type" => "ModifyNS_Domain",
"params" => array (
"ns" => array("hosts" => $nsArray)
)
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"order" => $order
)
);
if (!$this->sendCommand("Make_Order",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][orderid];
} else {
$this->error = "::: updateNS: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function updateDomainPrivacy($domain, $privacy) {
if (!$this->login()) { return false; }
if (preg_match("/[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ]/ui",$domain)) { $idna = new idna_convert(); $domain = $idna->encode($domain); }
$order = array(
"domain" => $domain,
"type" => "Modify_Domain",
"params" => array (
"params" => array("whoisproxy" => $privacy)
)
);
$params = array (
"data" => array (
"ssid" => $this->ssid,
"order" => $order
)
);
if (!$this->sendCommand("Make_Order",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][orderid];
} else {
$this->error = "::: updateDomainPrivacy: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function infoOrder($id) {
if (!$this->login()) { return false; }
$params = array (
"data" => array (
"ssid" => $this->ssid,
"order" => $id
)
);
if (!$this->sendCommand("Info_Order",$params)) { return false; }
if ($this->answer[status] == "ok") {
return $this->answer[data][order];
} else {
$this->error = "::: infoOrder: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function reqPoll() {
if (!$this->login()) { return false; }
$params = array (
"data" => array (
"ssid" => $this->ssid
)
);
if (!$this->sendCommand("POLL_Get",$params)) { return false; }
if ($this->answer[status] == "ok") {
$this->answer[data][msgCount] = $this->answer[data][count];
$this->answer[data][msgId] = $this->answer[data][id];
return $this->answer[data];
} else {
$this->error = "::: reqPoll: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
public function ackPoll($id) {
if (!$this->login()) { return false; }
$params = array (
"data" => array (
"ssid" => $this->ssid,
"id" => $id
)
);
if (!$this->sendCommand("POLL_Ack",$params)) { return false; }
if ($this->answer[status] == "ok") {
return true;
} else {
$this->error = "::: ackPoll: Code ".$this->answer[error][errorcode][major]."/".$this->answer[error][errorcode][minor].", ".$this->answer[error][errormsg]; $this->slog($this->error);
return false;
}
}
}
?>