Skip to content

Instantly share code, notes, and snippets.

@superbob
Last active February 23, 2025 13:44
Show Gist options
  • Save superbob/c8d44537c08ba1f7f22e9ea757e31595 to your computer and use it in GitHub Desktop.
Save superbob/c8d44537c08ba1f7f22e9ea757e31595 to your computer and use it in GitHub Desktop.
Namecheap Synology DSM DDNS provider
#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";
}
@Abolfazl
Copy link

Abolfazl commented Feb 20, 2025

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

@24mu13
Copy link

24mu13 commented Feb 23, 2025

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 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment