ddns service provider emulator
I have follow instruction from above post and I try to create DDNS Server for DirectAdmin and emulate to be noip.com DDNS Server.
So far I modify as followed:
- use .htaccess and .htpasswd for username : password to run the index.php file
- hostname : username mapping is hardcoded in index.php file
- domain variable has been changed to hostname to emulate noip.com DDNS Server
- index.php has been placed in /nic/update folder of public_html to follow noip.com API instruction
- directadminusername : directadminpassword has been hard coded in index.php file
noip.com api to update the record is "http://{username}:{password}@{ServiceProviderHost}/nic/update?hostname={Domain to be updated}&myip={new ip}
In Huawei Router, I select as followed:
Domain Name: my_ddns_client.mydomain.com
Service Provider: noip.com
Host of the Service Provider: ddns_server.mydomain.com
Service Port: 80
Use Name: admin
Password: password
Huawei Router should create request as followed: "http://admin
assword@ddns_server.mydomain.com/nic/update?hostname=my_ddns_client.mydomain.com&myip=newip"
If I do it from the Edge/Chrome browser, my ddns server is working normal. But if I use Huawei HG8247 router I see the request coming from Huawei router. But Huawei Router "Run State" for ddns record is said to be down and the record result in error. I would like to know if anyone can help me on how to debug of why huawei http massage reach directadmin php access log but does not update the ddns record. What is missing? And further reply to huawei router but not so neccessary.
Thanks & Best Regards,
Here is my code:
PHP:
<?php
include("httpsocket.php");
$DIRECTADMINUSER="directadminuser";
$DIRECTADMINPASSWORD="directadminpassword";
$DIRECTADMINURL="www.directadminvirutualhost.com";
$DIRECTADMINPORT="2222";
// PASSWORD ARE STORED IN .htpasswd file.
// CREATE PASSWORD FOR THE FIRST TIME, PLEASE USE 'htpasswd -c .htpasswd username'
// ANY ADDITIONAL USERNAME omit '-c'
$SUBDOMAINOWNER = array("ddnsclient1"=>"user1","ddnsclient2"=>"user2","ddnsclient3"=>"user3");
$URI= $_SERVER['REQUEST_URI'];
//echo $URI.'<br />';
$USERLOGIN= $_SERVER['PHP_AUTH_USER'];
//echo $USERLOGIN.':'.$_SERVER['PHP_AUTH_PW'].'<br />';
$SUBDOMAIN=$_GET["hostname"];
$IP=$_SERVER['REMOTE_ADDR'];
// echo 'User Input, Subdomain to be updated: '.$SUBDOMAIN.' With Login:'.$USERLOGIN.', Calling from IP: '.$IP.'<br />';
if (isset($SUBDOMAIN)) {
$HOSTNAMEARRAY = explode(".",$SUBDOMAIN);
$DOMAIN = $HOSTNAMEARRAY[1].".".$HOSTNAMEARRAY[2].".".$HOSTNAMEARRAY[3];
$HOSTNAME = $HOSTNAMEARRAY[0];
$ERROR=0;
$DATABASEOWNER=$SUBDOMAINOWNER[$HOSTNAME];
// echo 'Resolving IP '.$SUBDOMAIN.' resulting in '.gethostbyname($SUBDOMAIN).'<br />';
// echo 'USER LOGIN: '.$PASSCODE.' comparing to DATABASE PASSCODE: '.$DATABASEPASSCODE.'<br />';
if (($IP !== gethostbyname($SUBDOMAIN)) and ($USERLOGIN == $DATABASEOWNER)) {
// print_r('In the Update Loop.<br />');
$sock = new HTTPSocket;
$sock->connect($DIRECTADMINURL,$DIRECTADMINPORT);
$sock->set_login($DIRECTADMINUSER,$DIRECTADMINPASSWORD);
$sock->set_method('POST');
// Set TTL to 60 seconds
$sock->query("/CMD_API_DNS_CONTROL?domain=".$DOMAIN."&action=ttl&ttl_select=custom&ttl=60");
if (!strstr($sock->fetch_body(),"error=0")) $ERROR=1;
// Remove old A record
$sock->query("/CMD_API_DNS_CONTROL?domain=".$DOMAIN."&action=select&arecs0=name=".$HOSTNAME."&value=".gethostbyname("$HOSTNAME"));
if (!strstr($sock->fetch_body(),"error=0")) $ERROR=1;
// Create new A record
$sock->query("/CMD_API_DNS_CONTROL?domain=".$DOMAIN."&action=add&type=A&name=".$HOSTNAME."&value=".$IP);
if (!strstr($sock->fetch_body(),"error=0")) $ERROR=1;
if ($ERROR == 0) print("good ".$IP); else print ("911");
}
else print("nochg ".$IP."<br />");
}
else print("nohost<br />");
?>