ddns-scripts: add one.com provider 17646/head
authorLuca Conte <main@lugico.de>
Wed, 19 Jan 2022 14:56:47 +0000 (15:56 +0100)
committerLuca Conte <main@lugico.de>
Thu, 27 Jan 2022 12:59:42 +0000 (13:59 +0100)
Signed-off-by: Luca Conte <main@lugico.de>
net/ddns-scripts/Makefile
net/ddns-scripts/files/usr/lib/ddns/update_one_com.sh [new file with mode: 0644]
net/ddns-scripts/files/usr/share/ddns/default/one.com.json [new file with mode: 0644]

index 34a366a5666114f41c0adcaa8cfbac8902d9666c..873a33b1f1ef74e730a3cc801f28129e4d421ecf 100644 (file)
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ddns-scripts
 PKG_VERSION:=2.8.2
-PKG_RELEASE:=21
+PKG_RELEASE:=22
 
 PKG_LICENSE:=GPL-2.0
 
@@ -237,6 +237,20 @@ define Package/ddns-scripts-transip/description
   "option param_opt" to contain the TTL of the DNS record to update
 endef
 
+define Package/ddns-scripts-one
+       $(call Package/ddns-scripts/Default)
+       TITLE:=Extension for one.com Control Panel
+       DEPENDS:=ddns-scripts +curl
+endef
+
+define Package/ddns-scrtips-one/description
+       Dynamic DNS Client scripts extension for "one.com".
+       It requires:
+       "option username" to be a valid Email for one.com Control Panel
+       "option password" to be the matching one.com Control Panel password
+       "option domain" to contain the domain / subdomain
+endef
+
 
 define Build/Configure
 endef
@@ -312,6 +326,7 @@ define Package/ddns-scripts-services/install
        rm $(1)/usr/share/ddns/default/pdns.json
        rm $(1)/usr/share/ddns/default/transip.nl.json
        rm $(1)/usr/share/ddns/default/ns1.com.json
+       rm $(1)/usr/share/ddns/default/one.com.json
 endef
 
 
@@ -562,6 +577,25 @@ exit 0
 endef
 
 
+define Package/ddns-scripts-one/install
+       $(INSTALL_DIR) $(1)/usr/lib/ddns
+       $(INSTALL_BIN) ./files/usr/lib/ddns/update_one_com.sh \
+               $(1)/usr/lib/ddns
+
+       $(INSTALL_DIR) $(1)/usr/share/ddns/default
+       $(INSTALL_DATA) ./files/usr/share/ddns/default/one.com.json \
+               $(1)/usr/share/ddns/default
+endef
+
+define Package/ddns-scripts-one/prerm
+#!/bin/sh
+if [-z "${IPKG_INSTROOT}" ]; then
+       /etc/init.d/ddns stop
+fi
+exit 0
+endef
+
+
 $(eval $(call BuildPackage,ddns-scripts))
 $(eval $(call BuildPackage,ddns-scripts-services))
 $(eval $(call BuildPackage,ddns-scripts-cloudflare))
@@ -577,3 +611,4 @@ $(eval $(call BuildPackage,ddns-scripts-gandi))
 $(eval $(call BuildPackage,ddns-scripts-pdns))
 $(eval $(call BuildPackage,ddns-scripts-transip))
 $(eval $(call BuildPackage,ddns-scripts-ns1))
+$(eval $(call BuildPackage,ddns-scripts-one))
diff --git a/net/ddns-scripts/files/usr/lib/ddns/update_one_com.sh b/net/ddns-scripts/files/usr/lib/ddns/update_one_com.sh
new file mode 100644 (file)
index 0000000..94ec2ef
--- /dev/null
@@ -0,0 +1,142 @@
+#!/bin/sh
+
+# ONE.COM DDNS SCRIPT
+# REQUIRES CURL
+# $ opkg install curl
+
+# SCRIPT BY LUGICO
+# CONTACT: main@lugico.de
+
+[ -z "$CURL" ] && [ -z "$CURL_SSL" ] && write_log 14 "one.com communication require cURL with SSL support. Please install"
+[ -z "$domain" ]   && write_log 14 "Service section not configured correctly! Missing 'domain'"
+[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
+[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
+
+. /usr/share/libubox/jshn.sh
+
+write_log 0 "one.com ddns script started"
+
+local __SUBDOMAIN __MAINDOMAIN __LOGINURL __RECORDID
+local __TTL=3600
+
+COOKIEJAR=$(mktemp /tmp/one_com_cookiejar.XXXXXX) || exit 1
+
+__SUBDOMAIN=$(echo $domain | sed -e 's/[^\.]*\.[^\.]*$//' -e 's/\.$//' )
+__MAINDOMAIN=$(echo $domain | sed -e "s/${__SUBDOMAIN}\.//" )
+
+
+# LOGGING IN
+# GET LOGIN POST URL FROM FORM
+__LOGINURL=$( $CURL \
+       -RsSL \
+       --stderr $ERRFILE \
+       -c $COOKIEJAR \
+       "https://www.one.com/admin/" \
+       | grep 'Login-form login autofill' \
+       | sed -e 's/.*action="//' -e 's/".*//' -e 's/\&amp;/\&/g' \
+)
+
+# POST LOGIN DATA
+$CURL \
+       -RsSL \
+       --stderr $ERRFILE \
+       -c $COOKIEJAR \
+       -b $COOKIEJAR \
+       "${__LOGINURL}" \
+       -H "Content-Type: application/x-www-form-urlencoded" \
+       -X POST \
+       -d "username=${username}&password=${password}&credentialId=" \
+       | grep "Invalid username or password." > $DATFILE
+
+if [ "$?" == "0" ] ; then
+       write_log 14 "Invalid credentials"
+       return 1
+fi
+
+
+# SETTING DOMAIN
+$CURL -RsSL \
+       --stderr $ERRFILE \
+       -c $COOKIEJAR \
+       -b $COOKIEJAR \
+       "https://www.one.com/admin/select-admin-domain.do?domain=${__MAINDOMAIN}" \
+       | grep "<meta name=\"one.com:active-domain\" content=\"${__MAINDOMAIN}\"/>" > $DATFILE
+
+if [ "$?" != "0" ] ; then
+       write_log 14 "Failed to select domain '${__MAINDOMAIN}'"
+       return 1
+fi
+
+
+# GETTING RECORD ID
+records=$( $CURL \
+       -RsSL \
+       --stderr $ERRFILE \
+       -c $COOKIEJAR \
+       -b $COOKIEJAR \
+       "https://www.one.com/admin/api/domains/${__MAINDOMAIN}/dns/custom_records"
+)
+
+json_load "$records"
+
+if json_is_a "result" "object" && \
+       json_select "result" && \
+       json_is_a "data" "array"
+then
+       json_select "data"
+       i=1
+       while json_is_a ${i} "object" ; do
+               json_select "${i}"
+               json_select "attributes"
+               json_get_var "prefix" "prefix"
+               json_close_object
+               if [ "$prefix" == "$__SUBDOMAIN" ] ; then
+                       json_get_var "__RECORDID" "id"
+                       write_log 0 "Found record id : ${__RECORDID}"
+                       break
+               fi
+               json_close_object
+               i=$(($i + 1))
+       done
+fi
+
+
+if [ "${__RECORDID}" == "" ] ; then
+       write_log 14 "domain record not found"
+       return 1
+fi
+
+
+# CREATING PATCH DATA
+json_init
+json_add_string "type" "dns_service_records"
+json_add_string "id" "${__RECORDID}"
+json_add_object "attributes"
+json_add_string "type" "A"
+json_add_string "prefix" "${__SUBDOMAIN}"
+json_add_string "content" "${__IP}"
+json_add_int "ttl" ${__TTL}
+patchdata=$(json_dump)
+
+
+# SENDING PATCH
+$CURL \
+       -RsSL \
+       --stderr $ERRFILE \
+       -c $COOKIEJAR \
+       -b $COOKIEJAR \
+       -X PATCH \
+       -d "$patchdata" \
+       -H "Content-Type: application/json" \
+       "https://www.one.com/admin/api/domains/${__MAINDOMAIN}/dns/custom_records/${__RECORDID}" \
+       | grep "priority" > $DATFILE
+
+if [ "$?" != "0" ] ; then
+       write_log 14 "one.com gave an unexpected response"
+       return 1
+fi
+
+rm $COOKIEJAR
+write_log 0 "one.com ddns script finished without errors"
+
+return 0
diff --git a/net/ddns-scripts/files/usr/share/ddns/default/one.com.json b/net/ddns-scripts/files/usr/share/ddns/default/one.com.json
new file mode 100644 (file)
index 0000000..9245a73
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "name": "one.com",
+       "ipv4": {
+               "url": "update_one_com.sh"
+       }
+}