arcdns: update

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-09-07 12:38:49 +02:00
parent 06b0a7c172
commit b1daab939f
3 changed files with 86 additions and 55 deletions

70
arcdns/all/usr/bin/arcdns.php Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/php -d open_basedir=/usr/syno/bin/ddns
<?php
/*
Usage Instructions ( Obviously your domain has to be hosted on ArcDNS )
1) Copy this file to /usr/syno/bin/ddns/arcdns.php
2) Add the following entry in /etc.defaults/ddns_provider.conf
[Custom - ArcDNS]
modulepath=/usr/syno/bin/ddns/arcdns.php
queryurl=dyn.arcdns.tech
3) In Synology External Access > DDNS
Hostname = subdomain.domain.com OR domain.com
Username = put-random-string-here-for-validation-purpose
Password = ArcDNS DDNS Token (Accounts > Domain List > Advanced DNS)
*/
if ($argc !== 5) {
echo 'badparam';
exit();
}
$account = (string)$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();
}
$array = explode('.', $hostname);
if (count($array) >= 3) {
$domain = implode('.', array_slice($array, 1));
$hostname = implode('.', array_slice($array, 0, 1));
} else {
$domain = implode('.', $array);
$hostname = '@';
}
$url = 'https://arcdns.tech/update/'.$hostname.'/'.$pwd.;
$req = curl_init();
curl_setopt($req, CURLOPT_URL, $url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($req);
curl_close($req);
$xml = new SimpleXMLElement($res);
if ($xml->ErrCount > 0) {
$error = $xml->errors[0]->Err1;
if (strcmp($error, "This hostname has not been registered or is expired.") === 0) {
echo "nohost";
} elseif (strcmp($error, "You have supplied the wrong token to manipulate this host") === 0) {
echo "badauth";
} else {
echo "911 [".$error."]";
}
} else {
echo "good";
}

View File

@ -1,24 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (C) 2023 AuxXxilium <https://github.com/AuxXxilium>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
ARCHOST="${1}"
if curl https://arcdns.tech/update/${ARCHOST} -o /tmp/arcdns; then
if cat /tmp/arcdns | grep -q "Successfuly updated"; then
IP=$(cat /tmp/arcdns | grep "current_ip" | sed 's/.*current_ip":"\([0-9.]*\).*/\1/')
echo "ArcDNS: IP updated to ${IP}"
rm -f /tmp/arcdns
exit 0
else
echo "ArcDNS: Failed to update IP"
rm -f /tmp/arcdns
exit 1
fi
else
echo "ArcDNS: Can't connect to the server"
exit 1
fi

View File

@ -11,39 +11,24 @@ if [ "${1}" = "late" ]; then
mkdir -p "/tmpRoot/usr/arc/addons/"
cp -vf "${0}" "/tmpRoot/usr/arc/addons/"
cp -vf /usr/bin/arcdns.sh /tmpRoot/usr/bin/arcdns.sh
cp -vf /usr/bin/arcdns.php /tmpRoot/usr/syno/bin/ddns/arcdns.php
SED_PATH='/tmpRoot/usr/bin/sed'
${SED_PATH} -i '/\/usr\/bin\/arcdns.sh/d' /tmpRoot/etc/crontab
# Add line to crontab, execute each minute
echo "*/5 * * * * root /usr/bin/arcdns.sh ${2} #arcdns addon" >>/tmpRoot/etc/crontab
# Define the entries to be added
ENTRIES=("[Custom - ArcDNS]")
for ENTRY in "${ENTRIES[@]}"
do
if [ -f "/tmpRoot/etc.defaults/ddns_provider.conf" ]; then
if grep -Fxq "${ENTRY}" /tmpRoot/etc.defaults/ddns_provider.conf; then
echo "arcdns: Entry ${ENTRY} already exists"
else
echo "arcdns: Entry ${ENTRY} does not exist, adding now"
echo "${ENTRY}" >> /tmpRoot/etc.defaults/ddns_provider.conf
echo " modulepath=/usr/syno/bin/ddns/namecheap.php" >> /tmpRoot/etc.defaults/ddns_provider.conf
echo " queryurl=https://arcdns.tech/update/__HOSTNAME__/__PASSWORD__" >> /tmpRoot/etc.defaults/ddns_provider.conf
fi
fi
done
mkdir -p "/tmpRoot/usr/lib/systemd/system"
DEST="/tmpRoot/usr/lib/systemd/system/arcdns.service"
cat << EOF > ${DEST}
[Unit]
Description=addon arcdns
DefaultDependencies=no
IgnoreOnIsolate=true
After=multi-user.target
[Service]
User=root
Type=simple
Restart=on-failure
RestartSec=10
ExecStart=/usr/bin/arcdns.sh "${2}"
[Install]
WantedBy=multi-user.target
[X-Synology]
Author=Virtualization Team
EOF
mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants
ln -vsf /usr/lib/systemd/system/arcdns.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/arcdns.service
fi
elif [ "${1}" = "uninstall" ]; then
echo "Installing addon arcdns - ${1}"
# To-Do