-
-
Save superbob/c8d44537c08ba1f7f22e9ea757e31595 to your computer and use it in GitHub Desktop.
#Insert this at the end of /etc.defaults/ddns_provider.conf | |
[Namecheap] | |
modulepath=/usr/syno/bin/ddns/namecheap.php | |
queryurl=https://dynamicdns.park-your-domain.com/update |
#!/usr/bin/php -d open_basedir=/usr/syno/bin/ddns | |
<?php | |
if ($argc !== 5) { | |
echo 'badparam'; | |
exit(); | |
} | |
$account = $argv[1]; | |
$pwd = (string)$argv[2]; | |
$hostname = (string)$argv[3]; | |
$ip = (string)$argv[4]; | |
// check the hostname contains '.' | |
if (strpos($hostname, '.') === false) { | |
echo 'badparam'; | |
exit(); | |
} | |
// only for IPv4 format | |
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { | |
echo "badparam"; | |
exit(); | |
} | |
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip; | |
$req = curl_init(); | |
curl_setopt($req, CURLOPT_URL, $url); | |
curl_setopt($req, CURLOPT_RETURNTRANSFER, true); | |
$badXmlString = curl_exec($req); // XML String returned has a wrong xml utf declaration | |
curl_close($req); | |
// Heading says content is UTF-16, but it is UTF-8, so it is manually changed here | |
$fixedXmlString = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $badXmlString); | |
$xml = new SimpleXMLElement($fixedXmlString); | |
if ($xml->ErrCount > 0) { | |
$error = $xml->errors[0]->Err1; | |
if (strcmp($error, "Domain name not found") === 0) { | |
echo "nohost"; | |
} elseif (strcmp($error, "Passwords do not match") === 0) { | |
echo "badauth"; | |
} elseif (strcmp($error, "No Records updated. A record not Found;") === 0) { | |
echo "nohost"; | |
} else { | |
echo "911 [".$error."]"; | |
} | |
} else { | |
echo "good"; | |
} |
Hi Superbob, Thanks for your work on this. The methods you created were working perfectly for a few weeks up until today. I rechecked the files namecheap.php and ddns_provider.conf and both files appear to be fine, but I am now receiving 'Unable to register IP Address' from my NAS running DSM7? Interestingly I created a DuckDNS provider also and this is still working fine, just wondering if you or anyone else is receiving the same issue updating namecheap A+ Dynamic DNS records.
EDIT: Further update - despite the connection failing in the DDNS menu on the NAS and receiving error notification, the Namecheap A+ Dynamic DNS records are still being updated. I confirmed this by manually changing the IP address against one of my sub-domains on the namecheap website and then running the DDNS update on the NAS.
Interesting!
It also stopped working last night for me, like @tm1rules
I will have a look at this
I'm having the same issue now, it's failing to update. I am still on DSM 6.2.4, not DSM 7.
I tested a manual update by pasting this URL into the browser, like:
https://dynamicdns.park-your-domain.com/update?host=myhost&domain=mycustomdomain.com&password=00000000000000000000000000000000&ip=123.45.67.89
This is successful, and is basically what the php script is doing anyway. It appears Namecheap is still working. I confirmed the permission mask is still good (755) and the config file is the same. I'm not sure what's going on here. Going to look into curl. Any ideas @superbob ?
Hi Guys, I found the strange solution. Apparently namecheap changed it's respone-type-encoding.
This is my new working file. I added following code: $xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
Here's the whole file.
#!/usr/bin/php
<?php
if ($argc !== 5) {
echo 'badparam';
exit();
}
$account = $argv[1];
$pwd = (string)$argv[2];
$hostname = (string)$argv[3];
$ip = (string)$argv[4];
// check the hostname contains '.'
if (strpos($hostname, '.') === false) {
echo 'badparam';
exit();
}
// only for IPv4 format
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
echo "badparam";
exit();
}
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
$req = curl_init();
curl_setopt($req, CURLOPT_URL, $url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($req);
curl_close($req);
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
$xml = new SimpleXMLElement($xml);
if ($xml->ErrCount > 0) {
$error = $xml->errors[0]->Err1;
if (strcmp($error, "Domain name not found") === 0) {
echo "nohost";
} elseif (strcmp($error, "Passwords do not match") === 0) {
echo "badauth";
} elseif (strcmp($error, "No Records updated. A record not Found;") === 0) {
echo "nohost";
} else {
echo "911 [".$error."]";
}
} else {
echo "good";
}
Hi Guys, I found the strange solution. Apparently namecheap changed it's respone-type-encoding. This is my new working file. I added following code:
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
Here's the whole file.
Well done @bloedboemmel. Confirmed working on my system. Maybe submit this as a Pull Request to @superbob? Unless he wants to make the change directly himself.
Great work @bloedboemmel, just updated and is working perfectly on my NAS! I would add to anyone else reading this, remember to update the second line also;
$xml = new SimpleXMLElement($xml);
Thx for reporting the issues and finding the solution. I'll update the code accordingly 😊
Script updates confirmed working on DSM 7.0.1-42218
Once again, many thanks.
Hi @superbob, Im still with the Error message, I followed the @obviouscap instructions, and also Did the @bloedboemmel modifications, and still the same.
Im trying to the domain as main, not subdomains and have same settings on namecheap as you ( A+ Dynamic DNS ) and my log show this:
[2.5] 2022-01-14T12:50:43-06:00 HuleNas can_export[951]: can_export.cpp:24 MediaServer INFO can_export[951]: hyperbackup [2.5] 2022-01-14T12:50:57-06:00 HuleNas ddnsd[4310]: ddnsd.c:267 DDNS hostname update error: 2022-01-14T12:50:57-06:00 HuleNas ddnsd[4310]: ddnsd.c:1938 Fail to update [alejandrom.com] with IP [189.235.83.139] at [Namecheap2] 2022-01-14T12:50:59-06:00 HuleNas ddnsd[4310]: ddnsd.c:1933 Success to update [alejandro.media] with IP [189.235.83.139] at [Cloudflare] 2022-01-14T12:51:00-06:00 HuleNas ddnsd[4310]: ddnsd.c:1933 Success to update [hule.synology.me] with IP [189.235.83.139/2806:104e:19:40d0::4] at [Synology]
This is my ddns-provider.conf
[Namecheap2] modulepath=/usr/syno/bin/ddns/namecheap.php queryurl=https://dynamicdns.park-your-domain.com/update [Namecheap3] modulepath=/usr/syno/bin/ddns/namecheap-synology-ddns.php queryurl=https://dynamicdns.park-your-domain.com/
And namecheap.php
`#!/usr/bin/php
@aalejaandro, I'm confused about the content of your ddns_provider.conf
file, BTW, it is ddns_provider.conf, not ddns-provider.conf (underscore, not dash)
It should be only:
[Namecheap]
modulepath=/usr/syno/bin/ddns/namecheap.php
queryurl=https://dynamicdns.park-your-domain.com/update
I don't understand why there are Namecheap2 and Namecheap3 configurations.
I have changed my configuration after what @bloedboemmel found out and it works just fine (last DNS updated today).
Thank you very much for your quick response @superbob.
I have 2 NameCheap configurations because I was trying with another Script, as well I wrote wrong the name of ddns_provider.conf
when submit the post, thats why I have Namecheap2 and Namecheap3 with different queryurl and different modulepath.
Did you have any idea what Im doing wrong?
@aalejaandro Is this your whole namecheap.php?
As @tm1rules mentioned, make sure to add these 2 lines above the if-error-clauses:
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
$xml = new SimpleXMLElement($xml);
@bloedboemmel I already add these 2 lines, this is my entire namecheap.php
guess that its fine.
Do you have domain working fine, with succesufully connection?
My dns is updating fine without any errors since I added these lines.
I'm very sorry, I don't know why your getting an error.
What I did to find the error, was to run the namecheap.php with a debugger on my laptop. Maybe you could try this, too.
The script works. But because my DNS entry is with the hostname "@", it does not work in DSM. @ is not recognized as hostname. @ is not recognized as a character and the field is a required field. I have simply adjusted the URL in the script and have replaced the hostname with @, so that it does not matter in the DSM what I enter in the hostname field. Now also no error comes with me. Maybe this helps others here too.
My url:
$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Thanks!.
Now works properly, updating IP and no error message.
Hi,
@aalejaandro Is this your whole namecheap.php? As @tm1rules mentioned, make sure to add these 2 lines above the if-error-clauses:
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res); $xml = new SimpleXMLElement($xml);
Thanks you! These 2 lines help me update to my Namecheap account the Dynamic IP. The problem that Synology DSM still saying "failed to connect to the server...."
But i am surely IP already update. How to fix this?
Hi, its me again.
Everything was working good, but since the last update (DSM 7.1-42661 Update 2) Now my ddns that I added doesn't work. I thought with the new update the ddns_provider.conf was restore the default, but I saw that have no more entrys in that file.
So I would like to know if Im the only one with this issue or more people have same problem.
Hi,
It's a usual thing that some files disapear after DSM updates. I don't really know what I could do about that. You just have to copy back files when it happens. Sorry for the inconvenience.
Hi,
It's a usual thing that some files disapear after DSM updates. I don't really know what I could do about that. You just have to copy back files when it happens. Sorry for the inconvenience.
Yes, but at this time I can't make it work..
That's my entire namecheap.php guess that everything looks fine....
<?php
if ($argc !== 5) {
echo 'badparam';
exit();
}
$account = $argv[1];
$pwd = (string)$argv[2];
$hostname = (string)$argv[3];
$ip = (string)$argv[4];
// check the hostname contains '.'
if (strpos($hostname, '.') === false) {
echo 'badparam';
exit();
}
// only for IPv4 format
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
echo "badparam";
exit();
}
$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
$req = curl_init();
curl_setopt($req, CURLOPT_URL, $url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($req);
curl_close($req);
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
$xml = new SimpleXMLElement($xml);
if ($xml->ErrCount > 0) {
$error = $xml->errors[0]->Err1;
if (strcmp($error, "Domain name not found") === 0) {
echo "nohost";
} elseif (strcmp($error, "Passwords do not match") === 0) {
echo "badauth";
} elseif (strcmp($error, "No Records updated. A record not Found;") === 0) {
echo "nohost";
} else {
echo "911 [".$error."]";
}
} else {
echo "good";
}
This is at the end on my ddns_provider.conf
[Namecheap2]
modulepath=/usr/syno/bin/ddns/namecheap.php
queryurl=https://dynamicdns.park-your-domain.com/update
[Namecheap]
modulepath=/usr/syno/bin/ddns/namecheap.php
queryurl=https://dynamicdns.park-your-domain.com/update
I would be grateful if you see any error or detail that could be the reason why I cannot do it again
That should not be a blocker but, there should be only one Namecheap block in the ddns_provider.conf file, you have two of them.
I don't see anything particular in the main php file besides the $url line which is different in the example file :
Yours:
$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Mine:
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
That should not be a blocker but, there should be only one Namecheap block in the ddns_provider.conf file, you have two of them.
I don't see anything particular in the main php file besides the $url line which is different in the example file : Yours:
$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Mine:
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
I had 2 Namecheap (with different name) because I have 2 Domains, and DSM doesn't allow to use same provider with different domain, so the solution is add same prover with different name (Namecheap2).
Yes the $url is little different as suggest @bonxz, was the only way to make it work properly before.
Now, I did the same things as previous time and I can't fix the problem.
That should not be a blocker but, there should be only one Namecheap block in the ddns_provider.conf file, you have two of them.
I don't see anything particular in the main php file besides the $url line which is different in the example file : Yours:$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Mine:
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
I had 2 Namecheap (with different name) because I have 2 Domains, and DSM doesn't allow to use same provider with different domain, so the solution is add same prover with different name (Namecheap2).
Yes the $url is little different as suggest @bonxz, was the only way to make it work properly before.
Now, I did the same things as previous time and I can't fix the problem.
I don't know what's wrong with your configuration.
I use the lastest version of the files provided here (namecheap.php, ddns_provider.conf) without any modification and it works for me without error.
That should not be a blocker but, there should be only one Namecheap block in the ddns_provider.conf file, you have two of them.
I don't see anything particular in the main php file besides the $url line which is different in the example file : Yours:$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Mine:
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
I had 2 Namecheap (with different name) because I have 2 Domains, and DSM doesn't allow to use same provider with different domain, so the solution is add same prover with different name (Namecheap2).
Yes the $url is little different as suggest @bonxz, was the only way to make it work properly before.
Now, I did the same things as previous time and I can't fix the problem.
Have you tried the following steps.. I just repeated them when my configuration broke upgrading to 7.1-42661 (Update 1):
- Open port 22 (see Terminal & SNMP in DSM) and open the firewall to the encrypted terminal service (See Security\Firewall in DSM)
- ssh into your admin account (I use powershell)
- sudo -i
- cd /usr/syno/bin/ddns/
- rm namecheap.php
- wget https://gist.github.com/superbob/c8d44537c08ba1f7f22e9ea757e31595/raw/51513ad51cf05b0b2be61f248fb674fe2c212013/namecheap.php
- chmod 755 namecheap.php
- exit
- exit
- Close port 22 (see Terminal & SNMP in DSM) and close the firewall to the encrypted terminal service (See Security\Firewall in DSM)
And I would then recommend just restarting your NAS..
Thank you for your quick response.
Thanks for your Instructions/Steps.
Work this for you updating IP address with no error message on DSM?
Because I guess need to make some modifications to get it work, like add $xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
as @bloedboemmel says.
Before Update I remember to need to make this to get ir work.
Thank you for your quick response.
Thanks for your Instructions/Steps.
Work this for you updating IP address with no error message on DSM?
Because I guess need to make some modifications to get it work, like add
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
as @bloedboemmel says.Before Update I remember to need to make this to get ir work.
These are the steps I followed and my DDNS entries are being refreshed with no issues or errors. You do not need to amend the file if you follow the steps exactly.
That should not be a blocker but, there should be only one Namecheap block in the ddns_provider.conf file, you have two of them.
I don't see anything particular in the main php file besides the $url line which is different in the example file : Yours:
$url = 'https://dynamicdns.park-your-domain.com/update?host=@&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Mine:
$url = 'https://dynamicdns.park-your-domain.com/update?host='.$account.'&domain='.$hostname.'&password='.$pwd.'&ip='.$ip;
Thank you for your quick response.
Thanks for your Instructions/Steps.
Work this for you updating IP address with no error message on DSM?
Because I guess need to make some modifications to get it work, like add
$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $res);
as @bloedboemmel says.Before Update I remember to need to make this to get ir work.
@aalejaandro Have you tried to change your url back to the original, because yours seems odd to me. Have you tried to paste the original url and your modified url in the browser? Maybe it shows another error.
My fix you mentioned shouldn't affect your issue, it fixed all our errors, when namecheap changed their return format. This time it strangely affects only one person.
My Synology hasn't updated yet, but I suggest to run the php file with a debugger and your input, so you can find any error.
The script at the top of this gist (which now contains the modifications from @bloedboemmel) is working for me.
Couple of things that I found helpful:
- Reading the official Namecheap documentation about performing the HTTP GET call to the URL: https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-to-dynamically-update-the-hosts-ip-with-an-http-request/
- The detailed instructions from @Dade-R which show the crucial step of adding the executable permission to the PHP file.
Great stuff, and thanks to all involved!
This script is still not working for me. I am using latest copy of the gist and the chmod of Namecheap.php
is 755. I even added
file_put_contents('OUTPUT.txt', $fixedXmlString);
to the end of the file so I can see when the script runs and what the output is. When I go to Synology DDNS and enter:
- Hostname: DOMAIN.com
- Username/Email: @
- Password/Key: [Password_From_Namecheap]
and Test Connection, i immediately get failed message and the logs say
ddnsd.c:1741 Fail to update [DOMAIN.com] with IP [XXX.XXX.XXX.XXX] at [Namecheap]
Also, there is no OUTPUT.txt
file so the PHP script did not even run.
If I manually run the namecheap.php script and pass in the parameters, it returns good
and creates the file, so why does it not work when I run it from Synology?
Edit: I was able to get it working without having to do any sort of file editing.. I went to Synology DDNS > Customize a DDNs service provider:
- Service Provider: Namecheap2 (To distinguish from the other Namecheap script)
- Query URL:
https://dynamicdns.park-your-domain.com/update?host=__USERNAME__&domain=__HOSTNAME__&password=__PASSWORD__&ip=__MYIP__
Then enter in the following settings:
- Hostname: DOMAIN.com
- Username/Email: @
- Password/Key: [Password_From_Namecheap]
Running the connection returns Normal status and actually updates the IP
Have a look here: https://arise-dream.gitbook.io/synology-notes/connectivity/ddns
This script is still not working for me. I am using latest copy of the gist and the chmod of
Namecheap.php
is 755. I even addedfile_put_contents('OUTPUT.txt', $fixedXmlString);
to the end of the file so I can see when the script runs and what the output is. When I go to Synology DDNS and enter:
- Hostname: DOMAIN.com
- Username/Email: @
- Password/Key: [Password_From_Namecheap]
and Test Connection, i immediately get failed message and the logs say
ddnsd.c:1741 Fail to update [DOMAIN.com] with IP [XXX.XXX.XXX.XXX] at [Namecheap]
Also, there is no
OUTPUT.txt
file so the PHP script did not even run.If I manually run the namecheap.php script and pass in the parameters, it returns
good
and creates the file, so why does it not work when I run it from Synology?Edit: I was able to get it working without having to do any sort of file editing.. I went to Synology DDNS > Customize a DDNs service provider:
- Service Provider: Namecheap2 (To distinguish from the other Namecheap script)
- Query URL:
https://dynamicdns.park-your-domain.com/update?host=__USERNAME__&domain=__HOSTNAME__&password=__PASSWORD__&ip=__MYIP__
Then enter in the following settings:
- Hostname: DOMAIN.com
- Username/Email: @
- Password/Key: [Password_From_Namecheap]
Running the connection returns Normal status and actually updates the IP
Thank you superbob, Dade-R, and obviouscap. Been fighting with getting DDNS working on my synology with namecheap until I found this. Now it works perfectly, thanks again.