SHARE
TWEET

Namesilo WHMCS Module with ID protection - Pegaz Hosting

a guest Feb 2nd, 2014 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*****************************************/
  4. /* Set WHMCS Configuration Variables     */
  5. /*****************************************/
  6. function namesilo_getConfigArray() {
  7.         $configarray = array(
  8.          "Live_API_Key" => array( "Type" => "text", "Size" => "30", "Description" => "Enter your Live API Key", ),
  9.          "Sandbox_API_Key" => array( "Type" => "text", "Size" => "30", "Description" => "Enter your Sandbox API Key (Optional)", ),
  10.          "Payment_ID" => array( "Type" => "text", "Size" => "20", "Description" => "Enter your Payment ID (Optional)", ),
  11.          "Coupon" => array( "Type" => "text", "Size" => "20", "Description" => "Enter your Reseller Discount Coupon (Optional)", ),
  12.          "Test_Mode" => array("Type" => "yesno",'Description'=>"Enable this option ONLY if you have a Sandbox account (Optional)" ),
  13.      "Auto_Renew" => array("Type" => "yesno",'Description'=>"Do you want new domain registrations to automatically renew at NameSilo?" ),
  14.          "Sync_Next_Due_Date" => array("Type" => "yesno",'Description'=>"Tick this box if you want the expiry date sync script to update both expiry and next due dates. If left unchecked it will only update the domain expiration date. (cron must be configured)"),
  15.          "Debug_Recipient" => array( "Type" => "text", "Size" => "30", "Description" => "Enter the email address where debug emails should be sent", ),
  16.          "Debug_ON" => array("Type" => "yesno",'Description'=>"Enable this option ONLY if you want debug emails" ),
  17.         );
  18.         return $configarray;
  19. }
  20.  
  21. /*****************************************/
  22. /* Define Debug Information                              */
  23. /*****************************************/
  24. define ('DEBUG_ON', $params['Debug_ON']);
  25. define ('DEBUG_RECIPIENT', $params['Debug_Recipient']);
  26.  
  27. /*****************************************/
  28. /* Define Test Mode                                              */
  29. /*****************************************/
  30. define ('TEST_MODE', $params["Test_Mode"]);
  31. //var_dump($params); exit;
  32.  
  33. /*****************************************/
  34. /* Define API Servers                                    */
  35. /*****************************************/
  36. define ('LIVE_API_SERVER', 'https://www.namesilo.com');
  37. define ('TEST_API_SERVER', 'http://sandbox.namesilo.com');
  38.  
  39. /*****************************************/
  40. /* Define API Keys                                               */
  41. /*****************************************/
  42. define ('TEST_API_KEY', $params['Sandbox_API_Key']);
  43. define ('LIVE_API_KEY', $params['Live_API_Key']);
  44.  
  45. /*****************************************/
  46. /* Define Auto-Renew                                     */
  47. /*****************************************/
  48. define ('AUTO_RENEW', $params['Auto_Renew']);
  49.  
  50. /*****************************************/
  51. /* Define Domain                                                 */
  52. /*****************************************/
  53. define ('SLD', $params['sld']);
  54. define ('TLD', $params['tld']);
  55.  
  56. /*****************************************/
  57. /* Transaction Processor                                 */
  58. /*****************************************/
  59. function namesilo_transactionCall($callType, $call, $params)
  60. {
  61.     $action = explode("?",str_replace(array(LIVE_API_SERVER,TEST_API_SERVER),"",$call));
  62.     $callvars = explode("&",$action[1]);
  63.         # Set CURL Options
  64.     $options = array(
  65.         CURLOPT_RETURNTRANSFER => true,     // return web page
  66.         CURLOPT_HEADER         => false,    // don't return headers
  67.         CURLOPT_USERAGENT      => "Namesilo WHMCS Module V3.7", // who am i
  68.         CURLOPT_SSL_VERIFYPEER => true //if your curl does not have access to the CA certs, you can set this to false to avoid ssl errors
  69.     );
  70.        
  71.         # Process Request
  72.     $ch      = curl_init($call);
  73.     curl_setopt_array($ch, $options);
  74.     $content = curl_exec( $ch );
  75.     $err     = curl_errno( $ch );
  76.     $errmsg  = curl_error( $ch );
  77.     $header  = curl_getinfo( $ch );
  78.     curl_close( $ch );
  79.  
  80.         # Process Result
  81.         if(!$err){
  82.         $xml = new SimpleXMLElement($content);
  83.         switch ($callType) {
  84.         case "Standard":
  85.             $code = (int)$xml->reply->code;
  86.                 $detail = (string)$xml->reply->detail;
  87.                 $message = (string)$xml->reply->message;
  88.                 if ($code == '300' || $code == '301' || $code == '302'){ $response = array(); }
  89.                 else { $response['error'] = $detail;}
  90.             //var_dump($response); exit;
  91.             break;
  92.         case "getRegistrarLock":
  93.             $code = (int)$xml->reply->code;
  94.             $detail = (string)$xml->reply->detail;
  95.             $status = (string)$xml->reply->locked;
  96.                 if ($status == 'Yes') { $response = 'locked'; }
  97.                 elseif ($status == 'No') { $response = 'unlocked'; }
  98.                 else {
  99.                 $response['error'] = 'There was a problem';            
  100.             }
  101.             break;
  102.         case "getNameServers":
  103.             $code = (int)$xml->reply->code;
  104.                 $detail = (string)$xml->reply->detail;
  105.                 if ($code == '300'){
  106.                         $response['ns1'] = $xml->reply->nameservers->nameserver[0];
  107.                         $response['ns2'] = $xml->reply->nameservers->nameserver[1];
  108.                         $response['ns3'] = $xml->reply->nameservers->nameserver[2];
  109.                         $response['ns4'] = $xml->reply->nameservers->nameserver[3];
  110.                 $response['ns5'] = $xml->reply->nameservers->nameserver[4];
  111.                 }
  112.                 else {
  113.                         $response['error'] = $detail;
  114.                 }
  115.             break;
  116.         case "getContactID":
  117.             $code = (int)$xml->reply->code;
  118.                 $detail = (string)$xml->reply->detail;
  119.                 if ($code == '300'){
  120.                         $response['registrant'] = $xml->reply->contact_ids->registrant;
  121.                 $response['admin'] = $xml->reply->contact_ids->administrative;
  122.                 $response['tech'] = $xml->reply->contact_ids->technical;
  123.                 }
  124.                 else {
  125.                         $response['error'] = $detail;
  126.                 }
  127.             break;
  128.         case "contactAdd":
  129.             $code = (int)$xml->reply->code;
  130.                 $detail = (string)$xml->reply->detail;
  131.                 if ($code == '300'){
  132.                         $response['new_contact_id'] = $xml->reply->contact_id;
  133.                 }
  134.                 else {
  135.                         $response['error'] = $detail;
  136.                 }
  137.             break;
  138.         case "getContactDetails":
  139.             $code = (int)$xml->reply->code;
  140.                 $detail = (string)$xml->reply->detail;
  141.                 if ($code == '300'){
  142.                         $response['firstname'] = $xml->reply->contact->first_name;
  143.                         $response['lastname'] = $xml->reply->contact->last_name;
  144.                         $response['company'] = $xml->reply->contact->company;
  145.                         $response['address'] = $xml->reply->contact->address;
  146.                         $response['address2'] = $xml->reply->contact->address2;
  147.                         $response['city'] = $xml->reply->contact->city;
  148.                         $response['state'] = $xml->reply->contact->state;
  149.                         $response['postalcode'] = $xml->reply->contact->zip;
  150.                         $response['country'] = $xml->reply->contact->country;
  151.                         $response['email'] = $xml->reply->contact->email;
  152.                         $response['phone'] = $xml->reply->contact->phone;
  153.                         $response['fax'] = $xml->reply->contact->fax;
  154.                 }
  155.                 else {
  156.                         $response['error'] = $detail;
  157.                 }
  158.             break;
  159.                 case "listDNS":
  160.             $code = (int)$xml->reply->code;
  161.                 $detail = (string)$xml->reply->detail;
  162.                 if ($code == '300'){
  163.                         foreach($xml->reply->resource_record as $record)
  164.                         {
  165.                                 $hostname = $record->host;
  166.                                 if ($hostname == SLD . "." . TLD){
  167.                                         $hostname = '';
  168.                                 }
  169.                                 $hostname = explode(".", $hostname);
  170.                                 $hostname = (string) $hostname[0];
  171.                                 $response[] = array( "hostname" => $hostname, "type" => $record->type, "address" => $record->value, "record_id" => $record->record_id, "priority" => $record->distance );
  172.                         }
  173.                 }
  174.                 else {
  175.                         $response['error'] = $detail;
  176.                 }
  177.             break;
  178.         }
  179.     }else{
  180.         $response["error"] = "$err - $errmsg";
  181.     }
  182.        
  183.         # Send Debug Email if Debug is Enabled
  184.         if(DEBUG_ON == 'on') {
  185.                 # Prepare Headers
  186.                 $to      = DEBUG_RECIPIENT;
  187.                 $subject = 'Namesilo Registrar Module Debug Notification';
  188.                 $headers = "From: NameSilo Registrar Module<no-reply@" . $_SERVER['SERVER_NAME'] . ">\r\n" .
  189.                 'X-Mailer: PHP/' . phpversion();
  190.                 # Prepare Message
  191.                 $message = "Transaction Call: " . $call ."\n\n";
  192.                 $message .= "XML Response: " . $content . "\n\n";
  193.                 $message .= "Error Message: " . $response['error'] . "\n\n";
  194.                 $message .= "Response Code: " . $code . "\n\n";
  195.                 $message .= "Response Detail: " . $detail . "\n\n";
  196.                 $message .= $params["sld"] . "." . $params["tld"];
  197.                 # Send Email   
  198.                 mail($to, $subject, $message, $headers);
  199.         }
  200.        
  201.         $apikey = "";
  202.         foreach($callvars as $callv){
  203.             $namevalue = explode("=",$callv);
  204.             if($namevalue[0] == "key") $apikey = $namevalue[1];
  205.         if($apikey) break;
  206.         }
  207.         logModuleCall("Namesilo",$action[0],$call,$content,$response,array($apikey));
  208.  
  209.         # Return Result
  210.     return $response;
  211. }
  212.  
  213. /*****************************************/
  214. /* Retrieve Domain's Name Servers                */
  215. /*****************************************/
  216. function namesilo_GetNameservers($params) {
  217.         # Set Appropriate API Server
  218.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  219.     # Set Appropriate API Key
  220.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  221.         # Register Variables
  222.         $tld = urlencode($params["tld"]);
  223.         $sld = urlencode($params["sld"]);
  224.         # Transaction Call
  225.         $nameservers = namesilo_transactionCall("getNameServers", $apiServerUrl . "/api/getDomainInfo?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  226.         # Register Results
  227.         $values["ns1"] = $nameservers["ns1"];
  228.         $values["ns2"] = $nameservers["ns2"];
  229.     $values["ns3"] = $nameservers["ns3"];
  230.     $values["ns4"] = $nameservers["ns4"];
  231.     $values["ns5"] = $nameservers["ns5"];
  232.     $values["error"] = $nameservers["error"];
  233.         # Return Results
  234.         return $values;
  235. }
  236.  
  237. /*****************************************/
  238. /* Update Domain's Name Servers                  */
  239. /*****************************************/
  240. function namesilo_SaveNameservers($params) {
  241.         # Set Appropriate API Server
  242.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  243.     # Set Appropriate API Key
  244.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  245.         # Register Variables
  246.         $tld = urlencode($params["tld"]);
  247.         $sld = urlencode($params["sld"]);
  248.         # Prepare Name Server Information to Send
  249.     $nameserver1 = urlencode($params["ns1"]);
  250.         $nameserver2 = urlencode($params["ns2"]);
  251.     $nameserver3 = urlencode($params["ns3"]);
  252.         $nameserver4 = urlencode($params["ns4"]);
  253.     $nameserver5 = urlencode($params["ns5"]);
  254.         # Transaction Call
  255.         $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/changeNameServers?version=1&type=xml&key=$apiKey&domain=$sld.$tld&ns1=$nameserver1&ns2=$nameserver2&ns3=$nameserver3&ns4=$nameserver4&ns5=$nameserver5");
  256.         # Return Results
  257.         return $values;
  258. }
  259.  
  260. /*****************************************/
  261. /* Retrieve Registrar Lock Status                */
  262. /*****************************************/
  263. function namesilo_GetRegistrarLock($params) {
  264.         # Set Appropriate API Server
  265.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  266.     # Set Appropriate API Key
  267.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  268.         # Register Variables
  269.         $tld = urlencode($params["tld"]);
  270.         $sld = urlencode($params["sld"]);
  271.         # Transaction Call
  272.         $lockstatus = namesilo_transactionCall("getRegistrarLock", $apiServerUrl . "/api/getDomainInfo?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  273.         # Return Results
  274.         return $lockstatus;
  275. }
  276.  
  277. /*****************************************/
  278. /* Update Registrar Lock Status                  */
  279. /*****************************************/
  280. function namesilo_SaveRegistrarLock($params) {
  281.     # Set Appropriate API Server
  282.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  283.     # Set Appropriate API Key
  284.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  285.         # Register Variables
  286.         $tld = urlencode($params["tld"]);
  287.         $sld = urlencode($params["sld"]);
  288.         # Determine Lock Status and Run Appropriate Call
  289.         if ($params["lockenabled"] == "unlocked") {
  290.                 # Transaction Call
  291.                 $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/domainUnlock?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  292.         }
  293.         else {
  294.                 # Transaction Call
  295.                 $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/domainLock?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  296.         }
  297.         # Return Results
  298.         return $values;
  299. }
  300.  
  301. /*
  302. /*****************************************/
  303. /* Retrieve DNS Records for a Domain     */
  304. /*****************************************/
  305. function namesilo_GetDNS($params) {
  306.         # Set Appropriate API Server
  307.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  308.     # Set Appropriate API Key
  309.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  310.         # Register Variables
  311.         $tld = urlencode($params["tld"]);
  312.         $sld = urlencode($params["sld"]);
  313.     # Transaction Call
  314.         $hostrecords = namesilo_transactionCall("listDNS", $apiServerUrl . "/api/dnsListRecords?version=1&type=xml&key=$apiKey&domain=$sld.$tld");    
  315.         # Return Results
  316.         return $hostrecords;
  317.  
  318. }
  319.  
  320. /*****************************************/
  321. /* Update DNS Records for a Domain               */
  322. /*****************************************/
  323. function namesilo_SaveDNS($params) {
  324.         # Set Appropriate API Server
  325.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  326.     # Set Appropriate API Key
  327.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  328.         # Register Variables
  329.         $tld = urlencode($params["tld"]);
  330.         $sld = urlencode($params["sld"]);
  331.     # Retrieve Record IDs for existing records
  332.         $hostrecords = namesilo_transactionCall("listDNS", $apiServerUrl . "/api/dnsListRecords?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  333.         foreach ($hostrecords as $host) {
  334.                 $record_id = $host["record_id"];
  335.                 # Remove existing records (except base domain)
  336.                 namesilo_transactionCall("Standard", $apiServerUrl . "/api/dnsDeleteRecord?version=1&type=xml&key=$apiKey&domain=$sld.$tld&rrid=$record_id");
  337.         }
  338.         # Add each record
  339.         foreach ($params["dnsrecords"] AS $key=>$values) {
  340.                 $hostname = $values["hostname"];
  341.                 $type = $values["type"];
  342.                 $address = $values["address"];
  343.                 $priority = $values["priority"];
  344.                 # Check to make sure there is something to add
  345.                 //if (empty($hostname) || empty($address)) { continue; }
  346.         if (empty($address)) { continue; }
  347.                 if ($type == 'MX' && empty($priority)) { continue; }
  348.                 # Build API Call
  349.                 $apicall = "/api/dnsAddRecord?version=1&type=xml&key=$apiKey&domain=$sld.$tld&rrtype=$type&rrhost=$hostname&rrvalue=$address&rrttl=7200";
  350.                 if ($type == 'MX' && !empty($priority)) {
  351.                         $apicall .= "&rrdistance=$priority";
  352.                 }
  353.                 # API call to add rescord
  354.                 $values = namesilo_transactionCall("Standard", $apiServerUrl . $apicall);
  355.         }
  356.         # Return Results
  357.         return $values;
  358. }
  359.  
  360. /*****************************************/
  361. /* Register New Domain                                   */
  362. /*****************************************/
  363. function namesilo_RegisterDomain($params) {
  364.         # Set Appropriate API Server
  365.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  366.     # Set Appropriate API Key
  367.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  368.         # Set Appropriate Private Trigger
  369.         $private = $params["idprotection"];
  370.     # Set Appropriate Auto-Renew Trigger
  371.         $auto_renew = (AUTO_RENEW == "on") ? '1' : '0';
  372.         # Register Variables;
  373.         $paymentid = $params["Payment_ID"];
  374.         $coupon = urlencode($params["Coupon"]);
  375.         $tld = urlencode($params["tld"]);
  376.         $sld = urlencode($params["sld"]);
  377.         $regperiod = $params["regperiod"];
  378.         $nameserver1 = $params["ns1"];
  379.         $nameserver2 = $params["ns2"];
  380.     $nameserver3 = $params["ns3"];
  381.     $nameserver4 = $params["ns4"];
  382.     $nameserver5 = $params["ns5"];
  383.         # Registrant Details
  384.         $RegistrantFirstName = urlencode($params["firstname"]);
  385.         $RegistrantLastName = urlencode($params["lastname"]);
  386.         $RegistrantAddress1 = urlencode($params["address1"]);
  387.         $RegistrantAddress2 = urlencode($params["address2"]);
  388.         $RegistrantCity = urlencode($params["city"]);
  389.         $RegistrantStateProvince = urlencode($params["state"]);
  390.         $RegistrantPostalCode = urlencode($params["postcode"]);
  391.         $RegistrantCountry = urlencode($params["country"]);
  392.         $RegistrantEmailAddress = urlencode($params["email"]);
  393.         $RegistrantPhone = urlencode($params["phonenumber"]);
  394.         # Transaction Call
  395.         $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/registerDomain?version=1&type=xml&key=$apiKey&domain=$sld.$tld&years=$regperiod&payment_id=$paymentid&coupon=$coupon&private=$private&ns1=$nameserver1&ns2=$nameserver2&ns3=$nameserver3&ns4=$nameserver4&ns5=$nameserver5&fn=$RegistrantFirstName&ln=$RegistrantLastName&ad=$RegistrantAddress1&ad2=$RegistrantAddress2&cy=$RegistrantCity&st=$RegistrantStateProvince&zp=$RegistrantPostalCode&ct=$RegistrantCountry&em=$RegistrantEmailAddress&ph=$RegistrantPhone&auto_renew=$auto_renew");
  396.         # Return Results
  397.         return $values;
  398. }
  399.  
  400. /*****************************************/
  401. /* Initiate Domain Transfer                              */
  402. /*****************************************/
  403. function namesilo_TransferDomain($params) {
  404.         # Set Appropriate API Server
  405.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  406.     # Set Appropriate API Key
  407.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  408.         # Set Appropriate Private Trigger    
  409.         $private = $params["idprotection"];
  410.     # Set Appropriate Auto-Renew Trigger
  411.         $auto_renew = (AUTO_RENEW == "on") ? '1' : '0';
  412.         # Register Variables
  413.         $paymentid = $params["Payment_ID"];
  414.         $coupon = urlencode($params["Coupon"]);
  415.         $tld = urlencode($params["tld"]);
  416.         $sld = urlencode($params["sld"]);
  417.         $transfersecret = urlencode($params["transfersecret"]);
  418.         # Registrant Details
  419.         $RegistrantFirstName = urlencode($params["firstname"]);
  420.         $RegistrantLastName = urlencode($params["lastname"]);
  421.         $RegistrantAddress1 = urlencode($params["address1"]);
  422.         $RegistrantAddress2 = urlencode($params["address2"]);
  423.         $RegistrantCity = urlencode($params["city"]);
  424.         $RegistrantStateProvince = urlencode($params["state"]);
  425.         $RegistrantPostalCode = urlencode($params["postcode"]);
  426.         $RegistrantCountry = urlencode($params["country"]);
  427.         $RegistrantEmailAddress = urlencode($params["email"]);
  428.         $RegistrantPhone = urlencode($params["phonenumber"]);
  429.         # Transaction Call
  430.         $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/transferDomain?version=1&type=xml&key=$apiKey&domain=$sld.$tld&auth=$transfersecret&payment_id=$paymentid&coupon=$coupon&private=$private&fn=$RegistrantFirstName&ln=$RegistrantLastName&ad=$RegistrantAddress1&ad2=$RegistrantAddress2&cy=$RegistrantCity&st=$RegistrantStateProvince&zp=$RegistrantPostalCode&ct=$RegistrantCountry&em=$RegistrantEmailAddress&ph=$RegistrantPhone&auto_renew=$auto_renew");
  431.         # Return Results
  432.         return $values;
  433. }
  434.  
  435. /*****************************************/
  436. /* Renew Domain                                                  */
  437. /*****************************************/
  438. function namesilo_RenewDomain($params) {
  439.         # Set Appropriate API Server
  440.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  441.     # Set Appropriate API Key
  442.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  443.         # Register Variables
  444.         $paymentid = $params["Payment_ID"];
  445.         $coupon = urlencode($params["Coupon"]);
  446.         $tld = urlencode($params["tld"]);
  447.         $sld = urlencode($params["sld"]);
  448.         $regperiod = $params["regperiod"];
  449.         # Transaction Call
  450.         $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/renewDomain?version=1&type=xml&key=$apiKey&domain=$sld.$tld&years=$regperiod&payment_id=$paymentid&coupon=$coupon");
  451.         # Return Results
  452.         return $values;
  453. }
  454.  
  455. /*****************************************/
  456. /* Retrieve Domain Contact Details               */
  457. /*****************************************/
  458. function namesilo_GetContactDetails($params) {
  459.         # Set Appropriate API Server
  460.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  461.     # Set Appropriate API Key
  462.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  463.         # Register Variables
  464.         $tld = urlencode($params["tld"]);
  465.         $sld = urlencode($params["sld"]);
  466.         # Transaction Call
  467.         $contactid = namesilo_transactionCall("getContactID", $apiServerUrl . "/api/getDomainInfo?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  468.         $details_registrant = namesilo_transactionCall("getContactDetails", $apiServerUrl . "/api/contactList?version=1&type=xml&key=$apiKey&contact_id={$contactid['registrant']}");
  469.     $details_admin = namesilo_transactionCall("getContactDetails", $apiServerUrl . "/api/contactList?version=1&type=xml&key=$apiKey&contact_id={$contactid['admin']}");
  470.     $details_tech = namesilo_transactionCall("getContactDetails", $apiServerUrl . "/api/contactList?version=1&type=xml&key=$apiKey&contact_id={$contactid['tech']}");
  471.         # Data should be returned in an array as follows
  472.         $values["Registrant"]["First Name"] = $details_registrant['firstname'];
  473.         $values["Registrant"]["Last Name"] = $details_registrant['lastname'];
  474.         $values["Registrant"]["Company"] = $details_registrant['company'];
  475.         $values["Registrant"]["Address"] = $details_registrant['address'];
  476.         $values["Registrant"]["Address 2"] = $details_registrant['address2'];
  477.         $values["Registrant"]["City"] = $details_registrant['city'];
  478.         $values["Registrant"]["State"] = $details_registrant['state'];
  479.         $values["Registrant"]["Postal Code"] = $details_registrant['postalcode'];
  480.         $values["Registrant"]["Country"] = $details_registrant['country'];
  481.         $values["Registrant"]["Email"] = $details_registrant['email'];
  482.         $values["Registrant"]["Phone"] = $details_registrant['phone'];
  483.         $values["Registrant"]["Fax"] = $details_registrant['fax'];
  484.  
  485.     $values["Admin"]["First Name"] = $details_admin['firstname'];
  486.         $values["Admin"]["Last Name"] = $details_admin['lastname'];
  487.     $values["Admin"]["Company"] = $details_admin['company'];
  488.         $values["Admin"]["Address"] = $details_admin['address'];
  489.         $values["Admin"]["Address 2"] = $details_admin['address2'];
  490.         $values["Admin"]["City"] = $details_admin['city'];
  491.         $values["Admin"]["State"] = $details_admin['state'];
  492.         $values["Admin"]["Postal Code"] = $details_admin['postalcode'];
  493.         $values["Admin"]["Country"] = $details_admin['country'];
  494.         $values["Admin"]["Email"] = $details_admin['email'];
  495.         $values["Admin"]["Phone"] = $details_admin['phone'];
  496.         $values["Admin"]["Fax"] = $details_admin['fax'];
  497.  
  498.     $values["Tech"]["First Name"] = $details_tech['firstname'];
  499.         $values["Tech"]["Last Name"] = $details_tech['lastname'];
  500.     $values["Tech"]["Company"] = $details_tech['company'];
  501.         $values["Tech"]["Address"] = $details_tech['address'];
  502.         $values["Tech"]["Address 2"] = $details_tech['address2'];
  503.         $values["Tech"]["City"] = $details_tech['city'];
  504.         $values["Tech"]["State"] = $details_tech['state'];
  505.         $values["Tech"]["Postal Code"] = $details_tech['postalcode'];
  506.         $values["Tech"]["Country"] = $details_tech['country'];
  507.         $values["Tech"]["Email"] = $details_tech['email'];
  508.         $values["Tech"]["Phone"] = $details_tech['phone'];
  509.         $values["Tech"]["Fax"] = $details_tech['fax'];
  510.         # Return Results
  511.         return $values;
  512. }
  513.  
  514. /*****************************************/
  515. /* Update Domain Contact Details                 */
  516. /*****************************************/
  517. function namesilo_SaveContactDetails($params) {
  518.     //var_dump($params); exit;
  519.         # Set Appropriate API Server
  520.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  521.     # Set Appropriate API Key
  522.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  523.         # Register Variables
  524.         $tld = urlencode($params["tld"]);
  525.         $sld = urlencode($params["sld"]);
  526.         # Data is returned as specified in the GetContactDetails() function
  527.  
  528.     # Get the contact IDs that are currently associated with the domain
  529.     $contactid = namesilo_transactionCall("getContactID", $apiServerUrl . "/api/getDomainInfo?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  530.  
  531.     # Default IDs to associate with their current values (only change if needed based on code below)
  532.     $update_reg_id = $contactid['registrant'];
  533.     $update_admin_id = $contactid['admin'];
  534.     $update_tech_id = $contactid['tech'];
  535.  
  536.     //Regsitrant
  537.  
  538.         //Get Current Registrant Info
  539.         $current_registrant = namesilo_transactionCall("getContactDetails", $apiServerUrl . "/api/contactList?version=1&type=xml&key=$apiKey&contact_id={$contactid['registrant']}");
  540.  
  541.         $c_reg_firstname = trim(urlencode($current_registrant['firstname']));
  542.         $c_reg_lastname = trim(urlencode($current_registrant['lastname']));
  543.         $c_reg_company = trim(urlencode($current_registrant['company']));
  544.         $c_reg_address = trim(urlencode($current_registrant['address']));
  545.         $c_reg_address2 = trim(urlencode($current_registrant['address2']));
  546.         $c_reg_city = trim(urlencode($current_registrant['city']));
  547.         $c_reg_state = trim(urlencode($current_registrant['state']));        
  548.         $c_reg_zip = trim(urlencode($current_registrant['postalcode']));
  549.         $c_reg_country = trim(urlencode($current_registrant['country']));
  550.         $c_reg_email = trim(urlencode($current_registrant['email']));
  551.         $c_reg_phone = trim(urlencode($current_registrant['phone']));
  552.         $c_reg_fax = trim(urlencode($current_registrant['fax']));
  553.  
  554.         $md5_c_reg = md5($c_reg_firstname.$c_reg_lastname.$c_reg_company.$c_reg_address.$c_reg_address2.$c_reg_city.$c_reg_state.$c_reg_zip.$c_reg_country.$c_reg_email.$c_reg_phone.$c_reg_fax);
  555.        
  556.         //Get Entered Registrant Info
  557.         $e_reg_firstname = trim(urlencode($params["contactdetails"]["Registrant"]["First Name"]));
  558.         $e_reg_lastname = trim(urlencode($params["contactdetails"]["Registrant"]["Last Name"]));
  559.         $e_reg_company = trim(urlencode($params["contactdetails"]["Registrant"]["Company"]));
  560.         $e_reg_address = trim(urlencode($params["contactdetails"]["Registrant"]["Address"]));
  561.         $e_reg_address2 = trim(urlencode($params["contactdetails"]["Registrant"]["Address 2"]));
  562.         $e_reg_city = trim(urlencode($params["contactdetails"]["Registrant"]["City"]));
  563.         $e_reg_state = trim(urlencode($params["contactdetails"]["Registrant"]["State"]));
  564.         $e_reg_zip = trim(urlencode(@$params["contactdetails"]["Registrant"]["Postcode"] ? $params["contactdetails"]["Registrant"]["Postcode"] : $params["contactdetails"]["Registrant"]["Postal Code"]));
  565.         $e_reg_country = trim(urlencode($params["contactdetails"]["Registrant"]["Country"]));
  566.         $e_reg_email = trim(urlencode($params["contactdetails"]["Registrant"]["Email"]));
  567.         $e_reg_phone = trim(urlencode($params["contactdetails"]["Registrant"]["Phone"]));
  568.         $e_reg_fax = trim(urlencode($params["contactdetails"]["Registrant"]["Fax"]));
  569.  
  570.         $md5_e_reg = md5($e_reg_firstname.$e_reg_lastname.$e_reg_company.$e_reg_address.$e_reg_address2.$e_reg_city.$e_reg_state.$e_reg_zip.$e_reg_country.$e_reg_email.$e_reg_phone.$e_reg_fax);
  571.  
  572.         //Create new contact profile and associate it if necessary
  573.         if($md5_c_reg != $md5_e_reg) {
  574.  
  575.             $new_reg_id = namesilo_transactionCall("contactAdd", $apiServerUrl . "/api/contactAdd?version=1&type=xml&key=$apiKey&fn=$e_reg_firstname&ln=$e_reg_lastname&cp=$e_reg_company&ad=$e_reg_address&ad2=$e_reg_address2&cy=$e_reg_city&st=$e_reg_state&zp=$e_reg_zip&ct=$e_reg_country&em=$e_reg_email&ph=$e_reg_phone&fx=$e_reg_fax");
  576.  
  577.             if(@$new_reg_id['error']) {
  578.                 return $new_reg_id;
  579.             }
  580.  
  581.             $update_reg_id = $new_reg_id['new_contact_id'];
  582.  
  583.         }
  584.  
  585.     //Admin
  586.  
  587.         //Get Current Admin Info
  588.         $current_admin = namesilo_transactionCall("getContactDetails", $apiServerUrl . "/api/contactList?version=1&type=xml&key=$apiKey&contact_id={$contactid['admin']}");
  589.  
  590.         $c_admin_firstname = trim(urlencode($current_admin['firstname']));
  591.         $c_admin_lastname = trim(urlencode($current_admin['lastname']));
  592.         $c_admin_company = trim(urlencode($current_admin['company']));
  593.         $c_admin_address = trim(urlencode($current_admin['address']));
  594.         $c_admin_address2 = trim(urlencode($current_admin['address2']));
  595.         $c_admin_city = trim(urlencode($current_admin['city']));
  596.         $c_admin_state = trim(urlencode($current_admin['state']));        
  597.         $c_admin_zip = trim(urlencode($current_admin['postalcode']));
  598.         $c_admin_country = trim(urlencode($current_admin['country']));
  599.         $c_admin_email = trim(urlencode($current_admin['email']));
  600.         $c_admin_phone = trim(urlencode($current_admin['phone']));
  601.         $c_admin_fax = trim(urlencode($current_admin['fax']));
  602.  
  603.         $md5_c_admin = $c_admin_firstname.$c_admin_lastname.$c_admin_company.$c_admin_address.$c_admin_address2.$c_admin_city.$c_admin_state.$c_admin_zip.$c_admin_country.$c_admin_email.$c_admin_phone.$c_admin_fax;
  604.  
  605.         //Get Entered Admin Info
  606.         $e_admin_firstname = trim(urlencode($params["contactdetails"]["Admin"]["First Name"]));
  607.         $e_admin_lastname = trim(urlencode($params["contactdetails"]["Admin"]["Last Name"]));
  608.         $e_admin_company = trim(urlencode($params["contactdetails"]["Admin"]["Company"]));
  609.         $e_admin_address = trim(urlencode($params["contactdetails"]["Admin"]["Address"]));
  610.         $e_admin_address2 = trim(urlencode($params["contactdetails"]["Admin"]["Address 2"]));
  611.         $e_admin_city = trim(urlencode($params["contactdetails"]["Admin"]["City"]));
  612.         $e_admin_state = trim(urlencode($params["contactdetails"]["Admin"]["State"]));
  613.         $e_admin_zip = trim(urlencode(@$params["contactdetails"]["Admin"]["Postcode"] ? $params["contactdetails"]["Admin"]["Postcode"] : $params["contactdetails"]["Admin"]["Postal Code"]));
  614.         $e_admin_country = trim(urlencode($params["contactdetails"]["Admin"]["Country"]));
  615.         $e_admin_email = trim(urlencode($params["contactdetails"]["Admin"]["Email"]));
  616.         $e_admin_phone = trim(urlencode($params["contactdetails"]["Admin"]["Phone"]));
  617.         $e_admin_fax = trim(urlencode($params["contactdetails"]["Admin"]["Fax"]));
  618.  
  619.         $md5_e_admin = $e_admin_firstname.$e_admin_lastname.$e_admin_company.$e_admin_address.$e_admin_address2.$e_admin_city.$e_admin_state.$e_admin_zip.$e_admin_country.$e_admin_email.$e_admin_phone.$e_admin_fax;
  620.         //echo $md5_c_admin. '<br>'. $md5_e_admin; exit;
  621.  
  622.         //Create new contact profile and associate it if necessary
  623.         if($md5_c_admin != $md5_e_admin) {
  624.  
  625.             $new_admin_id = namesilo_transactionCall("contactAdd", $apiServerUrl . "/api/contactAdd?version=1&type=xml&key=$apiKey&fn=$e_admin_firstname&ln=$e_admin_lastname&cp=$e_admin_company&ad=$e_admin_address&ad2=$e_admin_address2&cy=$e_admin_city&st=$e_admin_state&zp=$e_admin_zip&ct=$e_admin_country&em=$e_admin_email&ph=$e_admin_phone&fx=$e_admin_fax");
  626.  
  627.             if(@$new_admin_id['error']) {
  628.                 return $new_admin_id;
  629.             }
  630.  
  631.             $update_admin_id = $new_admin_id['new_contact_id'];
  632.  
  633.         }
  634.  
  635.     //Tech
  636.  
  637.         //Get Current Tech Info
  638.         $current_tech = namesilo_transactionCall("getContactDetails", $apiServerUrl . "/api/contactList?version=1&type=xml&key=$apiKey&contact_id={$contactid['tech']}");
  639.  
  640.         $c_tech_firstname = trim(urlencode($current_tech['firstname']));
  641.         $c_tech_lastname = trim(urlencode($current_tech['lastname']));
  642.         $c_tech_company = trim(urlencode($current_tech['company']));
  643.         $c_tech_address = trim(urlencode($current_tech['address']));
  644.         $c_tech_address2 = trim(urlencode($current_tech['address2']));
  645.         $c_tech_city = trim(urlencode($current_tech['city']));
  646.         $c_tech_state = trim(urlencode($current_tech['state']));        
  647.         $c_tech_zip = trim(urlencode($current_tech['postalcode']));
  648.         $c_tech_country = trim(urlencode($current_tech['country']));
  649.         $c_tech_email = trim(urlencode($current_tech['email']));
  650.         $c_tech_phone = trim(urlencode($current_tech['phone']));
  651.         $c_tech_fax = trim(urlencode($current_tech['fax']));
  652.  
  653.         $md5_c_tech = md5($c_tech_firstname.$c_tech_lastname.$c_tech_company.$c_tech_address.$c_tech_address2.$c_tech_city.$c_tech_state.$c_tech_zip.$c_tech_country.$c_tech_email.$c_tech_phone.$c_tech_fax);
  654.  
  655.         //Get Entered Admin Info
  656.         $e_tech_firstname = trim(urlencode($params["contactdetails"]["Tech"]["First Name"]));
  657.         $e_tech_lastname = trim(urlencode($params["contactdetails"]["Tech"]["Last Name"]));
  658.         $e_tech_company = trim(urlencode($params["contactdetails"]["Tech"]["Company"]));
  659.         $e_tech_address = trim(urlencode($params["contactdetails"]["Tech"]["Address"]));
  660.         $e_tech_address2 = trim(urlencode($params["contactdetails"]["Tech"]["Address 2"]));
  661.         $e_tech_city = trim(urlencode($params["contactdetails"]["Tech"]["City"]));
  662.         $e_tech_state = trim(urlencode($params["contactdetails"]["Tech"]["State"]));
  663.         $e_tech_zip = trim(urlencode(@$params["contactdetails"]["Tech"]["Postcode"] ? $params["contactdetails"]["Tech"]["Postcode"] : $params["contactdetails"]["Tech"]["Postal Code"]));
  664.         $e_tech_country = trim(urlencode($params["contactdetails"]["Tech"]["Country"]));
  665.         $e_tech_email = trim(urlencode($params["contactdetails"]["Tech"]["Email"]));
  666.         $e_tech_phone = trim(urlencode($params["contactdetails"]["Tech"]["Phone"]));
  667.         $e_tech_fax = trim(urlencode($params["contactdetails"]["Tech"]["Fax"]));
  668.  
  669.         $md5_e_tech = md5($e_tech_firstname.$e_tech_lastname.$e_tech_company.$e_tech_address.$e_tech_address2.$e_tech_city.$e_tech_state.$e_tech_zip.$e_tech_country.$e_tech_email.$e_tech_phone.$e_tech_fax);
  670.  
  671.         //Create new contact profile and associate it if necessary
  672.         if($md5_c_tech != $md5_e_tech) {
  673.  
  674.             $new_tech_id = namesilo_transactionCall("contactAdd", $apiServerUrl . "/api/contactAdd?version=1&type=xml&key=$apiKey&fn=$e_tech_firstname&ln=$e_tech_lastname&cp=$e_tech_company&ad=$e_tech_address&ad2=$e_tech_address2&cy=$e_tech_city&st=$e_tech_state&zp=$e_tech_zip&ct=$e_tech_country&em=$e_tech_email&ph=$e_tech_phone&fx=$e_tech_fax");
  675.  
  676.             if(@$new_tech_id['error']) {
  677.                 return $new_tech_id;
  678.             }
  679.  
  680.             $update_tech_id = $new_tech_id['new_contact_id'];
  681.  
  682.         }
  683.  
  684.         //echo "Registrant: $update_reg_id <br> Admin: $update_admin_id <br> Tech: $update_tech_id"; exit;
  685.  
  686.         # Now, update the domain to use the IDs
  687.     $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/contactDomainAssociate?version=1&type=xml&key=$apiKey&domain=$sld.$tld&registrant=$update_reg_id&administrative=$update_admin_id&technical=$update_tech_id");
  688.  
  689.         # Return Results
  690.         return $values;
  691. }
  692.  
  693. /*****************************************/
  694. /* Send EPP Code to Domain Admin Contact */
  695. /*****************************************/
  696. function namesilo_GetEPPCode($params) {
  697.         # Set Appropriate API Server
  698.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  699.     # Set Appropriate API Key
  700.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  701.         # Register Variables
  702.         $tld = urlencode($params["tld"]);
  703.         $sld = urlencode($params["sld"]);
  704.     # Transaction Call
  705.     $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/retrieveAuthCode?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  706.         # Return Results    
  707.     return $values;
  708. }
  709.  
  710. /*****************************************/
  711. /* Register a new name server */
  712. /*****************************************/
  713. function namesilo_RegisterNameserver($params) {
  714.     # Set Appropriate API Server
  715.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  716.     # Set Appropriate API Key
  717.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  718.         # Register Variables
  719.         $tld = urlencode($params["tld"]);
  720.         $sld = urlencode($params["sld"]);
  721.     $nameserver = trim(urlencode(str_replace(".$sld.$tld", '', $params["nameserver"])));
  722.     $ipaddress = trim(urlencode($params["ipaddress"]));
  723.     # Transaction Call
  724.     $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/addRegisteredNameServer?version=1&type=xml&key=$apiKey&domain=$sld.$tld&new_host=$nameserver&ip1=$ipaddress");
  725.     # Return Results
  726.     return $values;
  727. }
  728.  
  729. /*****************************************/
  730. /* Modify a name server */
  731. /*****************************************/
  732. function namesilo_ModifyNameserver($params) {
  733.     # Set Appropriate API Server
  734.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  735.     # Set Appropriate API Key
  736.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  737.         # Register Variables
  738.         $tld = urlencode($params["tld"]);
  739.         $sld = urlencode($params["sld"]);
  740.     $nameserver = trim(urlencode(str_replace(".$sld.$tld", '', $params["nameserver"])));
  741.     $currentipaddress = trim(urlencode($params["currentipaddress"]));
  742.     $newipaddress = trim(urlencode($params["newipaddress"]));
  743.     # Transaction Call
  744.     $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/modifyRegisteredNameServer?version=1&type=xml&key=$apiKey&domain=$sld.$tld&current_host=$nameserver&new_host=$nameserver&ip1=$newipaddress");
  745.     # Return Results
  746.     return $values;
  747. }
  748.  
  749. /*****************************************/
  750. /* Delete a name server */
  751. /*****************************************/
  752. function namesilo_DeleteNameserver($params) {
  753.     # Set Appropriate API Server
  754.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  755.     # Set Appropriate API Key
  756.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  757.         # Register Variables
  758.         $tld = urlencode($params["tld"]);
  759.         $sld = urlencode($params["sld"]);
  760.     $nameserver = trim(urlencode(str_replace(".$sld.$tld", '', $params["nameserver"])));
  761.     # Transaction Call
  762.     $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/deleteRegisteredNameServer?version=1&type=xml&key=$apiKey&domain=$sld.$tld&current_host=$nameserver");
  763.     # Return Results
  764.     return $values;
  765. }
  766. /*****************************************/
  767. /* ID Protection */
  768. /*****************************************/
  769. function namesilo_IDProtectToggle($params) {
  770.     # Set Appropriate API Server
  771.     $apiServerUrl = ($params['Test_Mode'] == 'on') ? TEST_API_SERVER : LIVE_API_SERVER;
  772.     # Set Appropriate API Key
  773.     $apiKey = ($params['Test_Mode'] == 'on') ? $params['Sandbox_API_Key'] : $params['Live_API_Key'];
  774.         # Register Variables
  775.         $tld = urlencode($params["tld"]);
  776.         $sld = urlencode($params["sld"]);
  777.         # Determine ID Protection Status and Run Appropriate Call
  778.                 if($params["protectenable"]){
  779. $postfields["protect-privacy"] = "true";
  780. $idprotect = "on";
  781.                 # Transaction Call
  782.                 $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/addPrivacy?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  783.         }
  784.         else {
  785. $postfields["protect-privacy"] = "false";
  786. $idprotect = "";
  787.                 # Transaction Call
  788.                 $values = namesilo_transactionCall("Standard", $apiServerUrl . "/api/removePrivacy?version=1&type=xml&key=$apiKey&domain=$sld.$tld");
  789.         }
  790.     # Return Results
  791.     return $values;
  792. }
  793. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top