Skip to content

Instantly share code, notes, and snippets.

@superbob
Last active January 27, 2024 00:57
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";
}
@aalejaandro
Copy link

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.

@superbob
Copy link
Author

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.

@tm1rules
Copy link

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

  1. Open port 22 (see Terminal & SNMP in DSM) and open the firewall to the encrypted terminal service (See Security\Firewall in DSM)
  2. ssh into your admin account (I use powershell)
  3. sudo -i
  4. cd /usr/syno/bin/ddns/
  5. rm namecheap.php
  6. wget https://gist.github.com/superbob/c8d44537c08ba1f7f22e9ea757e31595/raw/51513ad51cf05b0b2be61f248fb674fe2c212013/namecheap.php
  7. chmod 755 namecheap.php
  8. exit
  9. exit
  10. 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..

@aalejaandro
Copy link

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.

@tm1rules
Copy link

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.

@bloedboemmel
Copy link

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.

@justinmcbride
Copy link

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:

  1. 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/
  2. 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!

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