PHP cURL: CLI DtDNS Updater 1: Difference between revisions

m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
No edit summary
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric)
 
Line 1: Line 1:
=[http://ovarynetyv.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
{{Nav PHP cURL}}
{{Nav PHP cURL}}
'''cURL CLI DtDNS Updater - Part 1'''
'''cURL CLI DtDNS Updater - Part 1'''
Line 22: Line 21:


This template is accessed using one of two URLs
This template is accessed using one of two URLs
* <nowiki>http://</nowiki>www.dtdns.com/api/autodns.cfm?'''id'''=hostname&'''pw'''=password&'''ip'''=address&'''client'''=name
* <nowiki>http://</nowiki>www.dtdns.com/api/autodns.cfm?'''id'''=hostname&'''pw'''=password&'''ip'''=address&'''client'''=name
* &lt;nowiki&gt;https://&lt;/nowiki&gt;www.dtdns.com/api/autodns.cfm?'''id'''=hostname&amp;'''pw'''=password&amp;'''ip'''=address&amp;'''client'''=name
* <nowiki>https://</nowiki>www.dtdns.com/api/autodns.cfm?'''id'''=hostname&'''pw'''=password&'''ip'''=address&'''client'''=name


Although it is possible to run files with extension cfm as PHP scripts its easier to just use a php extension. Anyway there is nothing to prevent us creating a simulation script.   
Although it is possible to run files with extension cfm as PHP scripts its easier to just use a php extension. Anyway there is nothing to prevent us creating a simulation script.   
Line 31: Line 30:
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
=== name-value pairs ===
=== name-value pairs ===
{|cellspacing=&quot;6&quot;
{|cellspacing="6"
|-valign=&quot;top&quot;
|-valign="top"
|
|
1)
1)
Line 41: Line 40:


* NOTE: Hostnames are now passed using the full hostname and the domain name it's on, not just the hostname (ex:test.dtdns.net, myhost.etowns.org, etc.). Full domain names are passed using just the domain name (ex: blah.com, mydomain.net, etc.).
* NOTE: Hostnames are now passed using the full hostname and the domain name it's on, not just the hostname (ex:test.dtdns.net, myhost.etowns.org, etc.). Full domain names are passed using just the domain name (ex: blah.com, mydomain.net, etc.).
|-valign=&quot;top&quot;
|-valign="top"
|
|
2)
2)
Line 48: Line 47:
|
|
This is a required field that will specify the member's password.  This will be compared to what is stored in the userbase for the specified hostname. If they do not match, an error (specified below) will be returned.
This is a required field that will specify the member's password.  This will be compared to what is stored in the userbase for the specified hostname. If they do not match, an error (specified below) will be returned.
|-valign=&quot;top&quot;
|-valign="top"
|
|
3)
3)
Line 60: Line 59:
We recommend giving the user the option of not sending the IP address with IP updates if they are behind a NAT router.  Hardware clients that do not act as a direct bridge should send the user's WAN address, and hardware clients that act as bridges should not send an IP address.
We recommend giving the user the option of not sending the IP address with IP updates if they are behind a NAT router.  Hardware clients that do not act as a direct bridge should send the user's WAN address, and hardware clients that act as bridges should not send an IP address.


DtDNS now provides an &quot;offline IP&quot; for our members to use. By pointing their hostname or domain to this IP address, anyone trying to visit their web site on port 80 will see a standard offline message or be redirected to a URL configured via the web site. The offline IP address is 0.0.0.0.
DtDNS now provides an "offline IP" for our members to use. By pointing their hostname or domain to this IP address, anyone trying to visit their web site on port 80 will see a standard offline message or be redirected to a URL configured via the web site. The offline IP address is 0.0.0.0.
|-valign=&quot;top&quot;
|-valign="top"
|
|
4)
4)
Line 72: Line 71:
=== returned messages ===
=== returned messages ===
{|
{|
|-valign=&quot;top&quot;
|-valign="top"
|&amp;nbsp;||'''''Messages'''''||'''''Description'''''
|&nbsp;||'''''Messages'''''||'''''Description'''''
|-valign=&quot;top&quot;
|-valign="top"
|
|
1)
1)
Line 81: Line 80:
|
|
This message is returned when no ID is specified.
This message is returned when no ID is specified.
|-valign=&quot;top&quot;
|-valign="top"
|
|
2)
2)
Line 88: Line 87:
|
|
Returned when no PW is given.
Returned when no PW is given.
|-valign=&quot;top&quot;
|-valign="top"
|
|
3)
3)
Line 95: Line 94:
|
|
Returned when ID is not a valid hostname or domain on the system.
Returned when ID is not a valid hostname or domain on the system.
|-valign=&quot;top&quot;
|-valign="top"
|
|
4)
4)
Line 102: Line 101:
|
|
Returned when the value of PW does not match the password defined for the value in the ID tag.
Returned when the value of PW does not match the password defined for the value in the ID tag.
|-valign=&quot;top&quot;
|-valign="top"
|
|
5)
5)
Line 109: Line 108:
|
|
Returned when the account has not been activated for usage.
Returned when the account has not been activated for usage.
|-valign=&quot;top&quot;
|-valign="top"
|
|
6)
6)
Line 115: Line 114:
Administration has disabled this account.
Administration has disabled this account.
|
|
Returned when the disabled bit is active for the specified ID, meaning that the hostname&lt;br /&gt;
Returned when the disabled bit is active for the specified ID, meaning that the hostname<br />
or domain name has been disabled for some reason.
or domain name has been disabled for some reason.
|-valign=&quot;top&quot;
|-valign="top"
|
|
7)
7)
Line 123: Line 122:
Illegal character in IP.
Illegal character in IP.
|
|
Returned when a non-numeric or period character is detected in the IP field when the user&lt;br /&gt;
Returned when a non-numeric or period character is detected in the IP field when the user<br />
has their account setup for A name resolution. Having a non-standard IP when set to A&lt;br /&gt;
has their account setup for A name resolution. Having a non-standard IP when set to A<br />
resolution causes the service to not update the IP database. Also returned when a number&lt;br /&gt;
resolution causes the service to not update the IP database. Also returned when a number<br />
in the IP address is higher than 255.
in the IP address is higher than 255.
|-valign=&quot;top&quot;
|-valign="top"
|
|
8)
8)
Line 148: Line 147:
|-
|-
|
|
&lt;pre&gt;
<pre>
A to Z ; upper case characters
A to Z ; upper case characters
a to z ; lower case characters
a to z ; lower case characters
0 to 9 ; numeric characters 0 to 9
0 to 9 ; numeric characters 0 to 9
-      ; dash
-      ; dash
&lt;/pre&gt;
</pre>
|
|
* A label can start or end with a letter or a number
* A label can start or end with a letter or a number
Line 170: Line 169:
|-
|-
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php


$host = &quot;uniserver-test.dtdns.net&quot;; // Change this for testing
$host = "uniserver-test.dtdns.net"; // Change this for testing


// === Check for vailid host =================================================
// === Check for vailid host =================================================
$failed=false;
$failed=false;
if(preg_match(&quot;/^[A-Za-z0-9\-.]+$/&quot;,$host)){ // Allowed characters
if(preg_match("/^[A-Za-z0-9\-.]+$/",$host)){ // Allowed characters
    
    
   // Invalid period either end not allowed set flag
   // Invalid period either end not allowed set flag
   if(preg_match(&quot;/^[.]/&quot;,$host)|preg_match(&quot;/[.]$/&quot;,$host)){
   if(preg_match("/^[.]/",$host)|preg_match("/[.]$/",$host)){
     $failed=true;                                 
     $failed=true;                                 
   }                                             
   }                                             
Line 186: Line 185:
   // Looks ok now split at periods to give array each element contains a Label   
   // Looks ok now split at periods to give array each element contains a Label   
   else{                                           
   else{                                           
     $host_array = explode(&quot;.&quot;,$host); // into an array
     $host_array = explode(".",$host); // into an array


       // Scan each element for &quot;-&quot; either end of element not allowed set flag   
       // Scan each element for "-" either end of element not allowed set flag   
       foreach($host_array as $el){  
       foreach($host_array as $el){  
       if(preg_match(&quot;/^-/&quot;,$host)|preg_match(&quot;/-$/&quot;,$el)){
       if(preg_match("/^-/",$host)|preg_match("/-$/",$el)){
         $failed=true;  // not allowed set flag     
         $failed=true;  // not allowed set flag     
       }       
       }       
Line 196: Line 195:


     // Last element is tld allowed characters lower cae alpha  
     // Last element is tld allowed characters lower cae alpha  
     if(!preg_match(&quot;/^[a-z]+$/&quot;,end($host_array))){
     if(!preg_match("/^[a-z]+$/",end($host_array))){
       $failed=true;                                             
       $failed=true;                                             
     }
     }
Line 203: Line 202:


if($failed){
if($failed){
  print &quot;&lt;br /&gt;==== Errors In Host =======&lt;br /&gt;&quot;;
  print "<br />==== Errors In Host =======<br />";
  exit;
  exit;
}
}
// === END Check for vailid host =============================================
// === END Check for vailid host =============================================
  print &quot;&lt;br /&gt;=== Host OK =====&lt;br /&gt;&quot;;
  print "<br />=== Host OK =====<br />";
?&gt;
?>
&lt;/pre&gt;
</pre>
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
Line 224: Line 223:
|-
|-
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php
$hostname        = &quot;uni.dtdns.net&quot;;  // Host name you created at DtDNS
$hostname        = "uni.dtdns.net";  // Host name you created at DtDNS
$password        = &quot;me123&quot;;          // Account password you set
$password        = "me123";          // Account password you set


$information      = true;  // true = display information false = for real tests set to false
$information      = true;  // true = display information false = for real tests set to false
Line 234: Line 233:


if($information){
if($information){
  print &quot;&lt;p&gt;&lt;b&gt;Information&lt;/b&gt;&lt;/p&gt;&quot;;
  print "<p><b>Information</b></p>";
  $id=$pw=$ip=$client=NULL;
  $id=$pw=$ip=$client=NULL;
  if(isset($_GET['id']))      $id    = $_GET['id'];
  if(isset($_GET['id']))      $id    = $_GET['id'];
Line 245: Line 244:
  }
  }
  else{
  else{
   $client = &quot;Unknown&quot;;
   $client = "Unknown";
  }
  }


  print &quot;&amp;lt;pre&amp;gt;Host    (id)    = $id&lt;br /&gt;&quot;;
  print "&lt;pre&gt;Host    (id)    = $id<br />";
  print &quot;Password (pw)    = $pw&lt;br /&gt;&quot;;
  print "Password (pw)    = $pw<br />";
  print &quot;Ip      (ip)    = $ip&lt;br /&gt;&quot;;
  print "Ip      (ip)    = $ip<br />";
  print &quot;Client  (client)= $client &amp;lt;/pre&amp;gt;&quot;;
  print "Client  (client)= $client &lt;/pre&gt;";
}//End Information
}//End Information


Line 259: Line 258:
}
}
else{
else{
  print &quot;No hostname to update was supplied.&quot;;
  print "No hostname to update was supplied.";
  exit;
  exit;
}
}
Line 268: Line 267:
}
}
else{
else{
  print &quot;No password was supplied.&quot;;
  print "No password was supplied.";
  exit;
  exit;
}
}
Line 274: Line 273:
// === Check id (hostname) matches
// === Check id (hostname) matches
if($id!=$hostname){
if($id!=$hostname){
  print &quot;The hostname you supplied is not valid.&quot;;
  print "The hostname you supplied is not valid.";
  exit;
  exit;
}
}
Line 280: Line 279:
// === Check pwd matches
// === Check pwd matches
if($pw!=$password){
if($pw!=$password){
  print &quot;The password you supplied is not valid.&quot;;
  print "The password you supplied is not valid.";
  exit;
  exit;
}
}
Line 286: Line 285:
// === Check if account activated
// === Check if account activated
if(!$activated){
if(!$activated){
  print &quot;This account has not yet been activated.&quot;;
  print "This account has not yet been activated.";
  exit;
  exit;
}
}
Line 292: Line 291:
// === Check if Admin disabled account
// === Check if Admin disabled account
if($account_disabled){
if($account_disabled){
  print &quot;Administration has disabled this account.&quot;;
  print "Administration has disabled this account.";
  exit;
  exit;
}
}
Line 301: Line 300:


  // === Validate
  // === Validate
  if(!preg_match(&quot;/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/&quot;,$ip)){
  if(!preg_match("/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/",$ip)){
   print &quot;Illegal character in IP&quot;;
   print "Illegal character in IP";
   exit;
   exit;
  }
  }
Line 308: Line 307:
else{
else{
   //Gets the IP address
   //Gets the IP address
   $ip = getenv(&quot;REMOTE_ADDR&quot;) ;
   $ip = getenv("REMOTE_ADDR") ;
}
}


  print &quot;Host $id now points to $ip.&quot;;
  print "Host $id now points to $ip.";
?&gt;
?>
&lt;/pre&gt;
</pre>
|}
|}


Line 320: Line 319:
=== Test ===
=== Test ===
Start server '''curl_2''' copy and paste the following into your browser address bar:
Start server '''curl_2''' copy and paste the following into your browser address bar:
&lt;pre&gt;
<pre>
http://localhost:82/autodns.php?id=uni.dtdns.net&amp;pw=me123&amp;ip=11.22.33.44&amp;client=UniServerV1
http://localhost:82/autodns.php?id=uni.dtdns.net&pw=me123&ip=11.22.33.44&client=UniServerV1
&lt;/pre&gt;
</pre>
Browser displays:
Browser displays:
&lt;pre&gt;
<pre>
Information
Information


Line 333: Line 332:


Host uni.dtdns.net now points to 11.22.33.44.
Host uni.dtdns.net now points to 11.22.33.44.
&lt;/pre&gt;
</pre>
Change the variables and generally check whats displayed.
Change the variables and generally check whats displayed.


Line 339: Line 338:


Note: If you are simulaing a real DtDNS account remember to change the following:
Note: If you are simulaing a real DtDNS account remember to change the following:
* '''$hostname'''        = &quot;uni.dtdns.net&quot;;  // Host name you created at DtDNS
* '''$hostname'''        = "uni.dtdns.net";  // Host name you created at DtDNS
* '''$password'''        = &quot;me123&quot;;          // Account password you set
* '''$password'''        = "me123";          // Account password you set


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''