Changes

Jump to navigation Jump to search

PHP cURL: CLI DtDNS Updater 1

806 bytes removed, 07:54, 24 November 2010
m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
=[http://ovarynetyv.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
{{Nav PHP cURL}}
'''cURL CLI DtDNS Updater - Part 1'''
This template is accessed using one of two URLs
* &lt;<nowiki&gt;>http://&lt;</nowiki&gt;>www.dtdns.com/api/autodns.cfm?'''id'''=hostname&amp;'''pw'''=password&amp;'''ip'''=address&amp;'''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
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.
'''''[[#top | Top]]'''''
=== name-value pairs ===
{|cellspacing=&quot;"6&quot;"|-valign=&quot;"top&quot;"
|
1)
* 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;"
|
2)
|
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;"
|
3)
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.|-valign=&quot;"top&quot;"
|
4)
=== returned messages ===
{|
|-valign=&quot;"top&quot;"|&amp;nbsp;||'''''Messages'''''||'''''Description'''''|-valign=&quot;"top&quot;"
|
1)
|
This message is returned when no ID is specified.
|-valign=&quot;"top&quot;"
|
2)
|
Returned when no PW is given.
|-valign=&quot;"top&quot;"
|
3)
|
Returned when ID is not a valid hostname or domain on the system.
|-valign=&quot;"top&quot;"
|
4)
|
Returned when the value of PW does not match the password defined for the value in the ID tag.
|-valign=&quot;"top&quot;"
|
5)
|
Returned when the account has not been activated for usage.
|-valign=&quot;"top&quot;"
|
6)
Administration has disabled this account.
|
Returned when the disabled bit is active for the specified ID, meaning that the hostname&lt;<br /&gt;>
or domain name has been disabled for some reason.
|-valign=&quot;"top&quot;"
|
7)
Illegal character in IP.
|
Returned when a non-numeric or period character is detected in the IP field when the user&lt;<br /&gt;>has their account setup for A name resolution. Having a non-standard IP when set to A&lt;<br /&gt;>resolution causes the service to not update the IP database. Also returned when a number&lt;<br /&gt;>
in the IP address is higher than 255.
|-valign=&quot;"top&quot;"
|
8)
|-
|
&lt;<pre&gt;>
A to Z ; upper case characters
a to z ; lower case characters
0 to 9 ; numeric characters 0 to 9
- ; dash
&lt;</pre&gt;>
|
* A label can start or end with a letter or a number
|-
|
&lt;<pre&gt;>&lt;<?php
$host = &quot;"uniserver-test.dtdns.net&quot;"; // Change this for testing
// === Check for vailid host =================================================
$failed=false;
if(preg_match(&quot;"/^[A-Za-z0-9\-.]+$/&quot;",$host)){ // Allowed characters
// Invalid period either end not allowed set flag
if(preg_match(&quot;"/^[.]/&quot;",$host)|preg_match(&quot;"/[.]$/&quot;",$host)){
$failed=true;
}
// Looks ok now split at periods to give array each element contains a Label
else{
$host_array = explode(&quot;".&quot;",$host); // into an array
// Scan each element for &quot;"-&quot; " either end of element not allowed set flag
foreach($host_array as $el){
if(preg_match(&quot;"/^-/&quot;",$host)|preg_match(&quot;"/-$/&quot;",$el)){
$failed=true; // not allowed set flag
}
// Last element is tld allowed characters lower cae alpha
if(!preg_match(&quot;"/^[a-z]+$/&quot;",end($host_array))){
$failed=true;
}
if($failed){
print &quot;&lt;"<br /&gt;>==== Errors In Host =======&lt;<br /&gt;&quot;>";
exit;
}
// === END Check for vailid host =============================================
print &quot;&lt;"<br /&gt;>=== Host OK =====&lt;<br /&gt;&quot;>";?&gt;>&lt;</pre&gt;>
|}
'''''[[#top | Top]]'''''
|-
|
&lt;<pre&gt;>&lt;<?php$hostname = &quot;"uni.dtdns.net&quot;"; // Host name you created at DtDNS$password = &quot;"me123&quot;"; // Account password you set
$information = true; // true = display information false = for real tests set to false
if($information){
print &quot;&lt;"<p&gt;&lt;><b&gt;>Information&lt;</b&gt;&lt;></p&gt;&quot;>";
$id=$pw=$ip=$client=NULL;
if(isset($_GET['id'])) $id = $_GET['id'];
}
else{
$client = &quot;"Unknown&quot;";
}
print "&quot;&amp;lt;pre&amp;gt;Host (id) = $id&lt;<br /&gt;&quot;>"; print &quot;"Password (pw) = $pw&lt;<br /&gt;&quot;>"; print &quot;"Ip (ip) = $ip&lt;<br /&gt;&quot;>"; print &quot;"Client (client)= $client &amp;lt;/pre&amp;gt;&quot;";
}//End Information
}
else{
print &quot;"No hostname to update was supplied.&quot;";
exit;
}
}
else{
print &quot;"No password was supplied.&quot;";
exit;
}
// === Check id (hostname) matches
if($id!=$hostname){
print &quot;"The hostname you supplied is not valid.&quot;";
exit;
}
// === Check pwd matches
if($pw!=$password){
print &quot;"The password you supplied is not valid.&quot;";
exit;
}
// === Check if account activated
if(!$activated){
print &quot;"This account has not yet been activated.&quot;";
exit;
}
// === Check if Admin disabled account
if($account_disabled){
print &quot;"Administration has disabled this account.&quot;";
exit;
}
// === 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)){ print &quot;"Illegal character in IP&quot;";
exit;
}
else{
//Gets the IP address
$ip = getenv(&quot;"REMOTE_ADDR&quot;") ;
}
print &quot;"Host $id now points to $ip.&quot;";?&gt;>&lt;</pre&gt;>
|}
=== Test ===
Start server '''curl_2''' copy and paste the following into your browser address bar:
&lt;<pre&gt;>http://localhost:82/autodns.php?id=uni.dtdns.net&amp;pw=me123&amp;ip=11.22.33.44&amp;client=UniServerV1&lt;</pre&gt;>
Browser displays:
&lt;<pre&gt;>
Information
Host uni.dtdns.net now points to 11.22.33.44.
&lt;</pre&gt;>
Change the variables and generally check whats displayed.
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* '''$password''' = &quot;"me123&quot;"; // Account password you set
'''''[[#top | Top]]'''''

Navigation menu