Файл: _rootinc/directi.inc.php
Строк: 387
<?
class DIRECTI
{
private $test = 0;
private $url = null;
private $userid = null;
private $password = null;
private $log = null;
public $error = null;
public function init($url, $userid, $password, $log)
{
$this->url = $url;
$this->userid = $userid;
$this->password = $password;
$this->log = $log;
}
private function send($script, $params)
{
$params["auth-userid"] = $this->userid;
$params["auth-password"] = $this->password;
$this->slog("n<<< Send Request [$script]n");
$this->slog($params, MODE_CLIENT);
reset($params);
while (list($k,$v) = @each($params)) {
if (@is_array($v)) {
while (list($kk,$vv) = @each($v)) {
$getParams .= $k."=".urlencode($vv)."&";
}
} else {
$getParams .= $k."=".urlencode($v)."&";
}
}
$fp = curl_init();
if ($this->test or $script == "domains/details.json") {
curl_setopt($fp, CURLOPT_URL, $this->url.$script."?".$getParams);
} else {
curl_setopt($fp, CURLOPT_URL, $this->url.$script);
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $getParams);
}
curl_setopt($fp, CURL_HTTP_VERSION_1_1, 1);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_TIMEOUT, 30);
$result = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "$script: cURL Error ".@curl_errno($fp).": ".@curl_error($fp); $this->slog($this->error);
return false;
}
curl_close($fp);
if (preg_match("/^{.*}$/",$result)) {
$result = json_decode($result,true);
}
if (!$result) {
$this->error = "$script: No Output"; $this->slog($this->error);
return false;
}
$this->slog("n>>> Got Response [$script]n");
$this->slog($result, MODE_SERVER);
return $result;
}
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")."_directi.log");
}
}
}
}
public function signUp($username, $passwd, $name, $company, $address1, $address2, $address3, $city, $state, $country, $zipcode, $phonecc, $phone, $altphonecc, $altphone, $faxcc, $fax, $langpref, $mobilecc, $mobile)
{
$params["username"] = $username;
$params["passwd"] = $passwd;
$params["name"] = $name;
$params["company"] = $company;
$params["address-line-1"] = $address1;
if ($address2) { $params["address-line-2"] = $address2; }
if ($address3) { $params["address-line-3"] = $address3; }
$params["city"] = $city;
$params["state"] = $state;
$params["country"] = $country;
$params["zipcode"] = $zipcode;
$params["phone-cc"] = $phonecc;
$params["phone"] = $phone;
if ($altphonecc) { $params["alt-phone-cc"] = $altphonecc; }
if ($altphone) { $params["alt-phone"] = $altphone; }
$params["lang-pref"] = $langpref;
if ($faxcc) { $params["fax-cc"] = $faxcc; }
if ($fax) { $params["fax"] = $fax; }
if ($mobilecc) { $params["mobile-cc"] = $mobilecc; }
if ($mobile) { $params["mobile"] = $mobile; }
$result = $this->send("customers/signup.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) != "ERROR") {
return $result;
} else {
$this->error = "signUp Error: ".$result[message].$result[error]; $this->slog($this->error);
return false;
}
}
public function getDefaultContacts($customerId, $type)
{
$params["customer-id"] = $customerId;
$params["type"] = $type;
$result = $this->send("contacts/default.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) != "ERROR") {
if ($result[$type][registrant]) {
return $result[$type][registrant];
} else {
$this->error = "getDefaultContacts Error: No registrant contact ID for $type"; $this->slog($this->error);
return false;
}
} else {
$this->error = "getDefaultContacts Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function registerDomain($domainname, $years, $contactId, $ns1, $ns2, $ns3, $ns4, $customerId, $invoiceOption, $enablePrivacyProtection)
{
$zone = getZoneTxtByDomainTxt($domainname);
$params["domain-name"] = $domainname;
$params["years"] = $years;
if ($ns1) { $params["ns"][] = $ns1; }
if ($ns2) { $params["ns"][] = $ns2; }
if ($ns3) { $params["ns"][] = $ns3; }
if ($ns4) { $params["ns"][] = $ns4; }
$params["customer-id"] = $customerId;
$params["reg-contact-id"] = $contactId;
if ($zone == "eu" or $zone == "nz") { $params["admin-contact-id"] = -1; } else { $params["admin-contact-id"] = $contactId; }
if ($zone == "eu" or $zone == "nz") { $params["tech-contact-id"] = -1; } else { $params["tech-contact-id"] = $contactId; }
if ($zone == "eu" or $zone == "nz" or $zone == "ca") { $params["billing-contact-id"] = -1; } else { $params["billing-contact-id"] = $contactId; }
$params["invoice-option"] = $invoiceOption;
$params["protect-privacy"] = $enablePrivacyProtection;
if ($zone == "asia") { $params["attr-name1"] = "cedcontactid"; $params["attr-value1"] = $contactId; }
$result = $this->send("domains/register.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS" or mb_strtoupper($result[status]) == "INVOICEPAID") {
return $result[entityid];
} else {
$this->error = "registerDomain Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function transferDomain($domainname, $authinfo, $contactId, $ns1, $ns2, $ns3, $ns4, $customerId, $invoiceOption, $enablePrivacyProtection)
{
$zone = getZoneTxtByDomainTxt($domainname);
$params["domain-name"] = $domainname;
$params["auth-code"] = $authinfo;
$params["customer-id"] = $customerId;
$params["reg-contact-id"] = $contactId;
$params["admin-contact-id"] = $contactId;
$params["tech-contact-id"] = $contactId;
$params["billing-contact-id"] = $contactId;
$params["invoice-option"] = $invoiceOption;
$params["protect-privacy"] = $enablePrivacyProtection;
if ($ns1) { $params["ns"][] = $ns1; }
if ($ns2) { $params["ns"][] = $ns2; }
if ($ns3) { $params["ns"][] = $ns3; }
if ($ns4) { $params["ns"][] = $ns4; }
if ($zone == "asia") { $params["ced-contact-id"] = $contactId;}
$result = $this->send("domains/transfer.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS" or mb_strtoupper($result[status]) == "INVOICEPAID") {
return $result[entityid];
} else {
$this->error = "transferDomain Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function getDomainExpiration($orderId) {
$params["order-id"] = $orderId;
$params["options"] = "OrderDetails";
$result = $this->send("domains/details.json",$params);
if (!$result) { return false; }
if ($result[endtime]) {
return $result[endtime];
} else {
$this->error = "getDomainExpiration Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function renewDomain($orderId, $period, $invoiceOption)
{
$endtime = $this->getDomainExpiration($orderId);
if (!$endtime) { return false; }
$params["order-id"] = $orderId;
$params["years"] = $period;
$params["exp-date"] = $endtime;
$params["invoice-option"] = $invoiceOption;
$result = $this->send("domains/renew.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS" or mb_strtoupper($result[status]) == "INVOICEPAID") {
return true;
} else {
$this->error = "renewDomain Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function getNS($orderId)
{
$params["order-id"] = $orderId;
$params["options"] = "NsDetails";
$result = $this->send("domains/details.json",$params);
if (!$result) { return false; }
if ($result[ns1] or $result[ns2] or $result[ns3] or $result[ns4]) {
if ($result[ns1]) { $res[] = $result[ns1]; }
if ($result[ns2]) { $res[] = $result[ns2]; }
if ($result[ns3]) { $res[] = $result[ns3]; }
if ($result[ns4]) { $res[] = $result[ns4]; }
return $res;
} else {
$this->error = "getNS Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function updateNS($orderId, $ns1, $ns2, $ns3, $ns4)
{
$params["order-id"] = $orderId;
if ($ns1) { $params["ns"][] = $ns1; }
if ($ns2) { $params["ns"][] = $ns2; }
if ($ns3) { $params["ns"][] = $ns3; }
if ($ns4) { $params["ns"][] = $ns4; }
$result = $this->send("domains/modify-ns.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS") {
return true;
} else {
$this->error = "updateNS Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function changePrivacyProtectionStatus($orderId, $enablePrivacyProtection, $reason)
{
$params["order-id"] = $orderId;
$params["protect-privacy"] = $enablePrivacyProtection;
$params["reason"] = $reason;
$result = $this->send("domains/modify-privacy-protection.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS") {
return true;
} else {
$this->error = "changePrivacyProtectionStatus Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function addChildNameServer($orderId, $ns, $nsip)
{
$params["order-id"] = $orderId;
$params["cns"] = $ns;
$params["ip"] = array($nsip);
$result = $this->send("domains/add-cns.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS") {
return true;
} else {
$this->error = "addChildNameServer Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
public function deleteChildNameServerIp($orderId, $ns, $nsip)
{
$params["order-id"] = $orderId;
$params["cns"] = $ns;
$params["ip"] = array($nsip);
$result = $this->send("domains/delete-cns-ip.json",$params);
if (!$result) { return false; }
if (mb_strtoupper($result[status]) == "SUCCESS") {
return true;
} else {
$this->error = "deleteChildNameServer Error: ".$result[message]." ".$result[error]." ".$result[actionstatusdesc]; $this->slog($this->error);
return false;
}
}
}
?>