<?php
/*
 * ##################################################################
 * Created on: Aug 10, 2005
 * File name:  resellerone.php
 * ##################################################################
 * This code is a sole property of netenberg.com
 * ##################################################################
 */
$resellerone_fields = array (
                    array ("login"    , "0",""),
                    array ("password" , "1",""),
                    array ("lock_domain"   , "0",array("1"=>"Yes","0"=>"No")),
                    array ("whois_privacy" , "0",array("1"=>"Yes","0"=>"No")),
                    array ("mode"     , "0",array("live"=>"LIVE MODE")),
                    array ("active"   , "0",array("no"=>"No","yes"=>"Yes"))
                  );
if(isset($process_domain) && $process_domain == true){
$_GET   = $this->REQUEST;
$_POST  = $this->REQUEST;
$name   = $this->REQUEST['name'];
$address= $this->REQUEST['address'];
$city   = $this->REQUEST['city'];
$zip    = $this->REQUEST['zip'];
$state  = $this->REQUEST['state'];
$country= $this->REQUEST['country'];
$email  = $this->REQUEST['email'];
$fax    = $this->REQUEST['telephone'];
$phone  = $this->REQUEST['telephone'];
$domain = $this->REQUEST['domain'];
$NS1    = $this->REQUEST['ns1'];
$NS2    = $this->REQUEST['ns2'];
$sub_id = $this->REQUEST['sub_id'];
$dom_user=$this->REQUEST['dom_user'];
$dom_pass=$this->REQUEST['dom_pass'];
$r_ip   = $this->REQUEST['r_ip'];
$years  = 1;
if (!empty($this->REQUEST['dom_period']))
{
    $years= $this->REQUEST['dom_period'];
}

//split data\
$name_array = explode(" ",$name,2);
$first_name = $name_array[0];
$last_name  = $name_array[1];
$telepone   = str_replace("-","",$phone);
$telepone   = str_replace("+","",$telepone);
$country_code=isset($this->props->phone_codes[$this->REQUEST['country']])?$this->props->phone_codes[$this->REQUEST['country']]:"91";
if(empty($country_code))
{
    $country_code = "91";
}
$phone      = $country_code."-".$telepone;
if(empty($r_ip))
{
    $r_ip   = $this->utils->realip();
}
//get open srs params
$username     = $this->dr_vals['resellerone']['login'];
$private_key  = $this->dr_vals['resellerone']['password'];
$f_lock_domain = isset($this->dr_vals['resellerone']['lock_domain'])?$this->dr_vals['resellerone']['lock_domain']:1;
$f_whois_privacy = isset($this->dr_vals['resellerone']['whois_privacy'])?$this->dr_vals['resellerone']['whois_privacy']:1;
//construct xml
$xml = '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'no\' ?>
<!DOCTYPE OPS_envelope SYSTEM \'ops.dtd\'>
<OPS_envelope>
<header>
<version>0.9</version>
</header>
<body>
<data_block>
<dt_assoc>
<item key=\'object\'>DOMAIN</item>
<item key=\'attributes\'>
<dt_assoc>
<item key=\'auto_renew\'></item>
<item key=\'link_domains\'>0</item>
<item key=\'reg_domain\'></item>
<item key=\'f_lock_domain\'>'.$f_lock_domain.'</item>
<item key=\'f_whois_privacy\'>'.$f_whois_privacy.'</item>
<item key=\'f_parkp\'>Y</item>
<item key=\'domain\'>'.$domain.'</item>
<item key=\'affiliate_id\'></item>
<item key=\'period\'>'.$years.'</item>
<item key=\'reg_type\'>new</item>
<item key=\'reg_username\'>'.$dom_user.'</item>
<item key=\'custom_tech_contact\'>0</item>
<item key=\'contact_set\'>
<dt_assoc>
<item key=\'admin\'>
<dt_assoc>
<item key=\'state\'>'.$state.'</item>
<item key=\'first_name\'>'.$first_name.'</item>
<item key=\'country\'>'.$country.'</item>
<item key=\'address1\'>'.$address.'</item>
<item key=\'last_name\'>'.$last_name.'</item>
<item key=\'address2\'></item>
<item key=\'address3\'></item>
<item key=\'postal_code\'>'.$zip.'</item>
<item key=\'fax\'></item>
<item key=\'city\'>'.$city.'</item>
<item key=\'phone\'>'.$phone.'</item>
<item key=\'email\'>'.$email.'</item>
<item key=\'org_name\'>'.$domain.'</item>
</dt_assoc>
</item>
<item key=\'billing\'>
<dt_assoc>
<item key=\'state\'>'.$state.'</item>
<item key=\'first_name\'>'.$first_name.'</item>
<item key=\'country\'>'.$country.'</item>
<item key=\'address1\'>'.$address.'</item>
<item key=\'last_name\'>'.$last_name.'</item>
<item key=\'address2\'></item>
<item key=\'address3\'></item>
<item key=\'postal_code\'>'.$zip.'</item>
<item key=\'fax\'></item>
<item key=\'city\'>'.$city.'</item>
<item key=\'phone\'>'.$phone.'</item>
<item key=\'email\'>'.$email.'</item>
<item key=\'org_name\'>'.$domain.'</item>
</dt_assoc>
</item>
<item key=\'owner\'>
<dt_assoc>
<item key=\'state\'>'.$state.'</item>
<item key=\'first_name\'>'.$first_name.'</item>
<item key=\'country\'>'.$country.'</item>
<item key=\'address1\'>'.$address.'</item>
<item key=\'last_name\'>'.$last_name.'</item>
<item key=\'address2\'></item>
<item key=\'address3\'></item>
<item key=\'postal_code\'>'.$zip.'</item>
<item key=\'fax\'></item>
<item key=\'city\'>'.$city.'</item>
<item key=\'phone\'>'.$phone.'</item>
<item key=\'email\'>'.$email.'</item>
<item key=\'org_name\'>'.$domain.'</item>
</dt_assoc>
</item>
</dt_assoc>
</item>
<item key=\'nameserver_list\'>
<dt_array>
<item key=\'0\'>
<dt_assoc>
<item key=\'sortorder\'>1</item>
<item key=\'name\'>'.$NS1.'</item>
</dt_assoc>
</item>
<item key=\'1\'>
<dt_assoc>
<item key=\'sortorder\'>2</item>
<item key=\'name\'>'.$NS2.'</item>
</dt_assoc>
</item>
</dt_array>
</item>
<item key=\'reg_password\'>'.$dom_pass.'</item>
<item key=\'encoding_type\'></item>
<item key=\'custom_nameservers\'>1</item>
</dt_assoc>
</item>
<item key=\'registrant_ip\'>'.$r_ip.'</item>
<item key=\'protocol\'>XCP</item>
<item key=\'action\'>SW_REGISTER</item>
</dt_assoc>
</data_block>
</body>
</OPS_envelope>';

//send xml
$signature = md5(md5($xml.$private_key).$private_key);
$host       = "resellers.resellone.net";
$port       = 52443;
$url        = "/";
$header     = "";
$header    .= "POST $url HTTP/1.0\r\n";
$header    .= "Content-Type: text/xml\r\n";
$header    .= "X-Username: " . $username . "\r\n";
$header    .= "X-Signature: " . $signature . "\r\n";
$header    .= "Content-Length: " . strlen($xml) . "\r\n\r\n";
# ssl:// requires OpenSSL to be installed
$fp         = fsockopen ("ssl://$host", $port, $errno, $errstr, 30);
if (!$fp)
{
    $response_text= $errno."=>".$errstr;
}
else
{
    # post the data to the server
    $result  = "";
    fputs ($fp, $header . $xml);
    while (!feof($fp))
        $result .= fgets ($fp, 1024);
    fclose ($fp);
}
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", $result, $out, PREG_PATTERN_ORDER);
$response_text = "";
$id            = "";
foreach ($out[0] as $k => $v)
{
    if (ereg("\"response_text\"", $v))
    {
        $v1 = str_replace("<item key=\"response_text\">", "", $v);
        $v1 = str_replace("</item>", "", $v1);
        $response_text = $v1;
    }
    if (ereg("\"id\"", $v))
    {
        $v2 = str_replace("<item key=\"id\">", "", $v);
        $v2 = str_replace("</item>", "", $v2);
        $id = $v2;
    }
}
$time   = date('Y-m-d H:i:s');
$result1= $response_text." : ".$id;
$this->dom_reg_logs->insert(array("log_time"=>$time,"sub_id"=>$sub_id,"domain"=>$domain,"log_result"=>$result1));

if (empty($id))
{
    $registration_result = $this->props->lang['dom_reg_fail']."<br />".$response_text;
}
else
{
    $this->orders->update(array("sub_id"=>$sub_id,"dom_reg_comp"=>1, "dom_reg_result"=>$id, "dom_registrar"=>"resellerone"));
    $order = $this->orders->getByKey($sub_id);
    if ($order['dom_reg_comp'] == '1')
    {
        $registration_result = $this->props->lang['dom_reg_success'].$order['dom_reg_result'];
    }
    else
    {
        $registration_result = $this->props->lang['dom_reg_fail']."<br />".$response_text."<br />".$order['dom_reg_result'];
    }
}
}
?>