https://wiki.uniformserver.com/index.php?title=DtDNS:_Plugin_2&feed=atom&action=historyDtDNS: Plugin 2 - Revision history2024-03-29T14:16:37ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=DtDNS:_Plugin_2&diff=3880&oldid=prevRic: New page: {{Nav DtDNS}} '''A Twist''' While writing this tutorial it became apparent two functions were ideal candidates for adding to the core functionality. The two functions now integrated prov...2009-09-11T19:54:16Z<p>New page: {{Nav DtDNS}} '''A Twist''' While writing this tutorial it became apparent two functions were ideal candidates for adding to the core functionality. The two functions now integrated prov...</p>
<p><b>New page</b></p><div>{{Nav DtDNS}}<br />
'''A Twist'''<br />
<br />
While writing this tutorial it became apparent two functions were ideal candidates for adding to the core functionality.<br />
<br />
The two functions now integrated provide additional diagnostics. A side effect concept of a plugin faded away and no longer made sense. Hence the DtDNS automatic IP updater is included as a standard component within the plugin's folder. It requires configuring and enabling for CRON operation. <br />
<br />
This page details how to configure and enable CRON operation. <br />
<br />
== Script ==<br />
The final script shown below:<br />
<br />
UniServer\plugins\dtdns_updater\'''dtdns_updater.php'''<br />
{|<br />
|-<br />
|<br />
<pre><br />
<?php<br />
/*<br />
###############################################################################<br />
# Name: The Uniform Server DtDNS Updater v 1.0<br />
# Developed By: The Uniform Server Development Team<br />
# Modified Last By: Mike Gleaves (Ric) <br />
# Web: http://www.uniformserver.com<br />
###############################################################################<br />
*/<br />
//error_reporting(0); // Disable PHP errors and warnings<br />
// Comment to Enable for testing<br />
<br />
chdir(dirname(__FILE__)); // Change wd to this files location<br />
include_once "../../unicon/main/includes/config.inc.php";<br />
include_once "../../unicon/main/includes/functions.php";<br />
<br />
run_location_tracker(); // Have servers moved if moved update configuration<br />
print"\n";<br />
<br />
//######################## User Configuration #################################<br />
// Add as many lines as required with the following format:<br />
// $id_pw[] = "hostname,password";<br />
// For example:<br />
// $id_pw[] = "books.effers.com,fred123";<br />
// $id_pw[] = "power.dtdns.net,gun22powder";<br />
//-----------------------------------------------------------------------------<br />
<br />
$id_pw[] = "books.effers.com,fred123"; // Change<br />
$id_pw[] = "books.effers.com,fred123"; // Change or delete<br />
$id_pw[] = "books.effers.com,fred123"; // Change or delete<br />
<br />
//###################### END User Configuration ###############################<br />
<br />
$test = false; // Test true = display IP address and host names<br />
// false = no display<br />
<br />
foreach ($id_pw as $value) { // Iteratate through array<br />
$idpw_array = explode(",",$value); // Split id pw pairs<br />
<br />
if(get_ip_dns($idpw_array[0])){ // Was IP from DNS returned<br />
if(get_ip_current()){ // Yes: Current IP returned<br />
<br />
if($test){ // Test code<br />
print "DNS IP = $ip_dns CURRENT IP = $ip_current $idpw_array[0]<br/>\n";<br />
}<br />
<br />
if($ip_dns != $ip_current){ // Are IP's different<br />
dtdns_update($idpw_array[0],$idpw_array[1]);// yes: Update required<br />
}<br />
}<br />
}<br />
}// End foreach<br />
<br />
//=== Get IP from DNS server ==================================================<br />
// Input: ID = Hostname:<br />
// Output: Return value true = IP was obtained<br />
// Output: Return value false = IP not obtained or error<br />
// Output: $ip_dns either IP address or host name<br />
<br />
function get_ip_dns($hostname){<br />
global $ip_dns; // IP address saved from DNS server<br />
$ip_dns = gethostbyname($hostname); // Get IP address of hostname<br />
if($ip_dns == $hostname){ // Is hostname returned (not IP address) <br />
return false; // yes: failed to get IP address<br />
}<br />
else{ // no: IP obtained <br />
return true; // set success <br />
}<br />
}<br />
//============================================== END Get IP from DNS server ===<br />
<br />
//=== DtDNS Host Update Page ==================================================<br />
// Input: $id = Hostname:<br />
// Input: $pw = User password<br />
// Output: Return value true = sucess false = failed<br />
<br />
function dtdns_update($id,$pw){<br />
$id_val = urlencode($id); // User Host on DtDNS<br />
$pw_val = urlencode($pw); // User password<br />
$client_val = urlencode('UniServerV1'); // Optional - But added it<br />
$url = 'https://www.dtdns.com/api/autodns.cfm'; // DtDNS update page<br />
<br />
// Build complete URL<br />
$str= $url."?id=".$id_val."&pw=".$pw_val."&client=".$client_val;<br />
<br />
// Access page using Curl SSL<br />
$ch=curl_init(); // Initialize Curl get handle<br />
curl_setopt($ch,CURLOPT_URL,$str); // Set Curl URL option <br />
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // no verify<br />
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); // timeout set to 10 sceonds<br />
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // curl_exec ouputs a string <br />
$buffer = curl_exec($ch); // run above, save to buffer<br />
curl_close($ch); // Close Curl frees memory<br />
<br />
// Test returned page <br />
if(preg_match("/now\spoints\sto/",$buffer)){// Is returne value "now points to"<br />
return true; // yes: update OK<br />
}<br />
else{ // no: Failed<br />
return false;<br />
}<br />
}<br />
//============================================== END DtDNS Host Update Page ===<br />
?><br />
</pre><br />
|}<br />
<br />
== Manual Update ==<br />
You can run this batch file to manually force an update, remember to leave around ten minuets before performing another update. <br />
<br />
The final batch script shown below:<br />
<br />
UniServer\plugins\dtdns_updater\'''Run_dtdns_updater.bat'''<br />
<br />
<pre><br />
COLOR B0<br />
@echo off<br />
cls<br />
<br />
rem ### working directory current folder <br />
pushd %~dp0<br />
<br />
..\..\usr\local\php\php.exe dtdns_updater.php<br />
<br />
rem ### restore original working directory<br />
pause<br />
popd<br />
EXIT<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
== Cron ==<br />
Cron provides a periodic tick Uniform Server's default is every ten minutes.<br />
<br />
DtDNS automatic updater has been pre-configured however it is disabled by default.<br />
<br />
To enable Cron edit file UniServer\unicon\main\'''run_cron.php''' <br />
<br />
Locate these two line in section '''List of scripts to be run'''<br />
<pre><br />
// $cmd = 'start ..\..\usr\local\php\php-win.exe ..\..\plugins\dtdns_updater\dtdns_updater.php';<br />
// pclose(popen($cmd,'r')); // Start detatched process <br />
</pre><br />
and uncomment as shown below<br />
<pre><br />
$cmd = 'start ..\..\usr\local\php\php-win.exe ..\..\plugins\dtdns_updater\dtdns_updater.php';<br />
pclose(popen($cmd,'r')); // Start detatched process <br />
</pre><br />
'''''Notes'':'''<br />
* When the server is first started Cron is run and the IP addreess updated if different<br />
* Every ten minuets Cron is run and the IP address are checked if different are updated.<br />
* Cron only runs when the servers are running however you can force an update using the batch file mentioned above.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
Interesting twist to this tutorial started life as a plugin only to become an integrated component.<br />
<br />
Thought I would leave the tutorial as is it contains useful information should you want to design an IP updater for another provider.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric