sendCommand('domain_check', $params); //echo $apiClient->command ; //******************************************************************* // RECUPERATION ET TRAITEMENT DU RESULTAT //******************************************************************* $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "contents"); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE); if ( xml_parse($xml_parser, $apiResponse) ) { // } xml_parser_free($xml_parser); if ( $nodes["code"] == "200" ) { echo "Command OK
"; } else { echo "Command KO
"; } foreach ($nodes as $key => $value) { echo "\r\n$key : $value
"; } //******************************************************************* // FUNCTIONS ET CLASSE //******************************************************************* $current_tag=""; $nodes = array(); function contents($parser, $name){ global $current_tag, $nodes; $cur_name = ltrim(str_replace("\n", "", $name)); if ( $cur_name != '') { if ( !isset($nodes[$current_tag]) ) { $nodes[$current_tag] = $cur_name; } else { $nodes[$current_tag] .= ";" . $cur_name; } } } function startTag($parser, $name, $attrs){ global $current_tag, $nodes; $current_tag = $name; while (list($k, $v) = each($attrs)) { $nodes[$k] = $v; } } function endTag($parser, $name){ // } class APIClient { var $command; var $apiLogin; var $apiPassWord; function apiClient($login, $password) { $this->apiLogin = $login; $this->apiPassWord = $password; } function StartCommand() { $str = "\r\n"; $str .= " \r\n"; $str .= " " . API_LOGIN . "\r\n"; $str .= " " . API_PASSWORD . "\r\n"; $str .= " PHP client V.0.1\r\n"; $str .= " \r\n"; $str .= " \r\n"; return $str; } function EndCommand() { $str = " \r\n"; $str .= ""; return $str; } function sendCommand($command, $params) { $this->command = $this->StartCommand(); switch ( $command ) { //DOMAIN case "domain_check": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " \r\n"; break; case "domain_info": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " \r\n"; break; case "domain_whois": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " \r\n"; break; case "domain_renew": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " " . $params['period'] . "\r\n"; $this->command .= " " . $params['curExpDate'] . "\r\n"; $this->command .= " \r\n"; break; case "domain_update": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; if ( isset($params['admin']) ) $this->command .= " " . $params['admin'] . "\r\n"; if ( isset($params['tech']) ) $this->command .= " " . $params['tech'] . "\r\n"; if ( isset($params['billing']) ) $this->command .= " " . $params['billing'] . "\r\n"; if ( isset($params['ns']) ) { $ns = explode(";", $params['ns']); for ( $i = 0; $i < count($ns); $i++ ) { if ( strlen(trim($ns[$i])) > 0 ) $this->command .= " " . trim($ns[$i]) . "\r\n"; } } $this->command .= " \r\n"; break; case "domain_create": $this->command .= " \r\n"; $this->command .= " " . $params['registrant'] . "\r\n"; $this->command .= " " . $params['admin'] . "\r\n"; $this->command .= " " . $params['tech'] . "\r\n"; $this->command .= " " . $params['billing'] . "\r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " " . $params['period'] . "\r\n"; $ns = explode(";", $params['ns']); for ( $i = 0; $i < count($ns); $i++ ) { $this->command .= " " . trim($ns[$i]) . "\r\n"; } if ( isset($params['number']) && isset($params['number_type']) ) $this->command .= " " . $params['number'] . "\r\n"; $this->command .= " \r\n"; break; //CONTACT case "contact_info": $this->command .= " \r\n"; $this->command .= " " . $params['contact_id'] . "\r\n"; $this->command .= " \r\n"; break; case "contact_update": $this->command .= " \r\n"; $this->command .= " " . $params['contact_id'] . "\r\n"; if ( isset($params['street']) ) $this->command .= " " . $params['street'] . "\r\n"; if ( isset($params['street2']) ) $this->command .= " " . $params['street2'] . "\r\n"; if ( isset($params['city']) ) $this->command .= " " . $params['city'] . "\r\n"; if ( isset($params['pc']) ) $this->command .= " " . $params['pc'] . "\r\n"; if ( isset($params['sp']) ) $this->command .= " " . $params['sp'] . "\r\n"; if ( isset($params['voice']) ) $this->command .= " " . str_replace("+", "%2B", $params['voice']) . "\r\n"; if ( isset($params['fax']) ) $this->command .= " " . str_replace("+", "%2B", $params['fax']) . "\r\n"; if ( isset($params['email']) ) $this->command .= " " . $params['email'] . "\r\n"; if ( isset($params['password']) ) $this->command .= " " . $params['password'] . "\r\n"; $this->command .= " \r\n"; break; case "contact_create": $this->command .= " \r\n"; $this->command .= " " . $params['is_individual'] . "\r\n"; $this->command .= " " . $params['firstname'] . "\r\n"; $this->command .= " " . $params['lastname'] . "\r\n"; if ( isset($params['orgname']) && strlen($params['orgname']) > 0) $this->command .= " " . $params['orgname'] . "\r\n"; $this->command .= " " . $params['street'] . "\r\n"; if ( isset($params['street2']) && strlen($params['street2']) > 0 ) $this->command .= " " . $params['street2'] . "\r\n"; $this->command .= " " . $params['city'] . "\r\n"; $this->command .= " " . $params['pc'] . "\r\n"; if ( isset($params['sp']) && strlen($params['sp']) > 0 ) $this->command .= " " . $params['sp'] . "\r\n"; $this->command .= " " . $params['cc'] . "\r\n"; $this->command .= " " . str_replace("+", "%2B", $params['voice']) . "\r\n"; if ( isset($params['fax']) && strlen($params['fax']) > 0 ) $this->command .= " " . str_replace("+", "%2B", $params['fax']) . "\r\n"; $this->command .= " " . $params['email'] . "\r\n"; $this->command .= " " . $params['password'] . "\r\n"; $this->command .= " \r\n"; break; //NS case "ns_check": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " " . $params['registry_id'] . "\r\n"; $this->command .= " \r\n"; break; case "ns_info": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " \r\n"; break; case "ns_update": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " " . $params['addr_ip1'] . "\r\n"; if ( isset($params['addr_ip2']) && strlen($params['addr_ip2']) > 0 ) $this->command .= " " . $params['addr_ip2'] . "\r\n"; $this->command .= " \r\n"; break; case "ns_create": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " " . $params['registry_id'] . "\r\n"; $this->command .= " " . $params['addr_ip1'] . "\r\n"; if ( isset($params['addr_ip2']) && strlen($params['addr_ip2']) > 0 ) $this->command .= " " . $params['addr_ip2'] . "\r\n"; $this->command .= " \r\n"; break; case "ns_delete": $this->command .= " \r\n"; $this->command .= " " . $params['name'] . "\r\n"; $this->command .= " " . $params['registry_id'] . "\r\n"; $this->command .= " \r\n"; break; } $this->command .= $this->EndCommand(); return $this->submit(); } function submit() { $xml_response = ''; $http_response = ''; $mycommand = "request=$this->command"; $fp = fsockopen("api.namebay.com", 80, $errno, $errstr, 20); if ( $fp ) { fputs($fp, "POST /" . API_PATH . " HTTP/1.1\r\n"); fputs($fp, "Host: " . API_SERVER . "\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($mycommand) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $mycommand); while(!feof($fp)) { $http_response .= fgets($fp, 128); } fclose($fp); list($header, $xml_response) = explode("\r\n\r\n", $http_response, 2); } else { echo "$errstr ($errno)
\n"; } return $xml_response; } } ?>