// URL Interface
// See the "EnomInterface.doc" document for more information
class CEnomInterface {
var $PostString;
var $RawData;
var $RawPasswordData;
var $Values;
var $Registration;
// this is an array of user variables (address, etc.)
var $UserVars;
// this is an array of names and registration status, to be filled in after each name reg attempt.:
// $RegisteredNames[name.tld][registered (1/0)][reasonmessage]
var $RegisteredNames;
function AddParam( $Name, $Value ) {
// URL encode the value and add to PostString
$this->PostString = $this->PostString . $Name . "=" . urlencode( $Value ) . "&";
}
function Dump() {
echo "
\n";
print_r($this);
echo "
\n";
}
function Dump_Response() {
echo "\n";
print_r($this->RawData);
echo "
\n";
}
function NewRequest() {
// Clear out all previous values
$this->PostString = "";
$this->RawData = "";
$this->Values = "";
$this->UserVars = "";
$this->TotalCharges = 0;
}
function AddError( $error ) {
// Add an error to the result list
$this->Values[ "ErrCount" ] = "1";
$this->Values[ "Err1" ] = $error;
}
function ParseResponse( $buffer ) {
// Parse the string into lines
$Lines = explode( "\r", $buffer );
// Get # of lines
$NumLines = count( $Lines );
// echo " num lines = $NumLines";
// Parse lines
$GotValues = 0;
// echo "parsing...";
for ( $i = 0; $i < $NumLines; $i++ ) {
// Is this line a comment?
if ( substr( $Lines[ $i ], 1, 1 ) != ";" ) {
// It is not, parse it
// echo $Lines[$i];
$Result = explode( "=", $Lines[ $i ] );
// Make sure we got 2 strings
if ( count( $Result ) >= 2 ) {
// Trim whitespace and add values
$name = trim( $Result[0] );
$value = trim( $Result[1] );
// echo "name = $name value=$value
\n";
$this->Values[ $name ] = $value;
// Was it an ErrCount value?
if ( $name == "ErrCount" ) {
// Remember this!
$GotValues = 1;
}
}
}
}
// Check if we got values
if ( $GotValues == 0 ) {
// We didn't, so add an error message
$this->AddError( "No values returned from server" );
}
}
function SetParam($name, $value) {
// echo "$name $value
\n";
$this->UserVars[ $name ] = $value;
}
function MakeURLString($varlist) {
$this->PostString = "";
foreach($varlist as $key => $value) {
// URL encode the value and add to PostString
$this->PostString = $this->PostString . $key . "=" . urlencode( $value ) . "&";
} // for each uservar
}
function filter_my_tld($arr, $tld) {
if ( ! is_array($arr) ) {
return array();
}
$tmparr = array();
reset($arr);
while($dom = current($arr)) {
if (ereg("\\.$tld\$", $dom))
array_push($tmparr, $dom);
next($arr);
}
return $tmparr;
}
function SetDomainPassword() {
//$PasswordString = "http://reseller.enom.com/interface.asp?command=SetPassword&Uid=nameboy&Pw=powder69&Sld=" . $this->UserVars['Sld'] . "&Tld=" . $this->UserVars['Tld'] . "&DomainPassword=" . $this->UserVars['Domainpassword'] . "&AccessLevel=1";
$PasswordString = "http://reseller.enom.com/interface.asp?command=SetPassword&Uid=nameboy&Pw=heliski123&Sld=" . $this->UserVars['Sld'] . "&Tld=" . $this->UserVars['Tld'] . "&DomainPassword=" . $this->UserVars['Domainpassword'] . "&AccessLevel=1";
$in = "http://grendel.nameboy.com/interface.php?url=" . urlencode($PasswordString);
// $fp = fopen($in, "r");
// $this->RawPasswordData = fread($fp, 4096);
// fclose($fp);
$ch = curl_init ($PasswordString);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$this->RawPasswordData = curl_exec ($ch);
curl_close ($ch);
} // setpassword
function DoTransaction() {
// Clear values
unset($this->Values);
// Create connection to server
// Test = resellertest.enom.com
// Live = reseller.enom.com
$host = 'reseller.enom.com';
$port = 80;
// Get the IP address for the target host.
// In case you want to specify an IP
$address = gethostbyname( $host );
//$address = '209.19.56.73';
$this->MakeURLString($this->UserVars);
$in1 = "https://$address/interface.asp?" . $this->PostString;
//$in = "http://grendel.nameboy.com/interface.php?url=" . urlencode($in1);
register_log("enom", $this->UserVars['Sld'] . "." . $this->UserVars['Tld'] . " : Submitting XML: " . $in1);
$ch = curl_init ($in1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$this->RawData = curl_exec ($ch);
curl_close ($ch);
// Parse the output for name=value pairs
$this->ParseResponse( $this->RawData );
if (!strstr($this->RawData, "successfully")) {
// Failure
$message = "There was a registration error from ENom.\n";
$message .= "User: " . $this->UserVars['RegistrantEmailAddress'] . " (";
$message .= $this->UserVars['RegistrantFirstName'] . " ";
$message .= $this->UserVars['RegistrantLastName'] . ")\n";
$message .= "Domain: " . $this->UserVars['Sld'] . "." . $this->UserVars['Tld'] . "\n";
$message .= "ENOM RESULTS:\n";
$message .= $this->RawData;
mail("shak380@gmail.com", "Enom Registration Error", $message);
mail("tj@nameboy.com", "Enom Registration Error", $message);
register_log("enom", $message);
$this->Registration=0;
}
else {
// Success
$this->Registration = 1;
register_log("enom", $this->UserVars['Sld'] . "." . $this->UserVars['Tld'] . " registered successfully.");
register_log("enom", $this->UserVars['Sld'] . "." . $this->UserVars['Tld'] . " XML=" . $this->RawData);
}
}
}
?>