You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.3 KiB

  1. #!/bin/sh
  2. # ONE.COM DDNS SCRIPT
  3. # REQUIRES CURL
  4. # $ opkg install curl
  5. # SCRIPT BY LUGICO
  6. # CONTACT: main@lugico.de
  7. [ -z "$CURL" ] && [ -z "$CURL_SSL" ] && write_log 14 "one.com communication require cURL with SSL support. Please install"
  8. [ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
  9. [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
  10. [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
  11. . /usr/share/libubox/jshn.sh
  12. write_log 0 "one.com ddns script started"
  13. local __SUBDOMAIN __MAINDOMAIN __LOGINURL __RECORDID
  14. local __TTL=3600
  15. COOKIEJAR=$(mktemp /tmp/one_com_cookiejar.XXXXXX) || exit 1
  16. __SUBDOMAIN=$(echo $domain | sed -e 's/[^\.]*\.[^\.]*$//' -e 's/\.$//' )
  17. __MAINDOMAIN=$(echo $domain | sed -e "s/${__SUBDOMAIN}\.//" )
  18. # LOGGING IN
  19. # GET LOGIN POST URL FROM FORM
  20. __LOGINURL=$( $CURL \
  21. -RsSL \
  22. --stderr $ERRFILE \
  23. -c $COOKIEJAR \
  24. "https://www.one.com/admin/" \
  25. | grep 'Login-form login autofill' \
  26. | sed -e 's/.*action="//' -e 's/".*//' -e 's/\&/\&/g' \
  27. )
  28. # POST LOGIN DATA
  29. $CURL \
  30. -RsSL \
  31. --stderr $ERRFILE \
  32. -c $COOKIEJAR \
  33. -b $COOKIEJAR \
  34. "${__LOGINURL}" \
  35. -H "Content-Type: application/x-www-form-urlencoded" \
  36. -X POST \
  37. -d "username=${username}&password=${password}&credentialId=" \
  38. | grep "Invalid username or password." > $DATFILE
  39. if [ "$?" == "0" ] ; then
  40. write_log 14 "Invalid credentials"
  41. return 1
  42. fi
  43. # SETTING DOMAIN
  44. $CURL -RsSL \
  45. --stderr $ERRFILE \
  46. -c $COOKIEJAR \
  47. -b $COOKIEJAR \
  48. "https://www.one.com/admin/select-admin-domain.do?domain=${__MAINDOMAIN}" \
  49. | grep "<meta name=\"one.com:active-domain\" content=\"${__MAINDOMAIN}\"/>" > $DATFILE
  50. if [ "$?" != "0" ] ; then
  51. write_log 14 "Failed to select domain '${__MAINDOMAIN}'"
  52. return 1
  53. fi
  54. # GETTING RECORD ID
  55. records=$( $CURL \
  56. -RsSL \
  57. --stderr $ERRFILE \
  58. -c $COOKIEJAR \
  59. -b $COOKIEJAR \
  60. "https://www.one.com/admin/api/domains/${__MAINDOMAIN}/dns/custom_records"
  61. )
  62. json_load "$records"
  63. if json_is_a "result" "object" && \
  64. json_select "result" && \
  65. json_is_a "data" "array"
  66. then
  67. json_select "data"
  68. i=1
  69. while json_is_a ${i} "object" ; do
  70. json_select "${i}"
  71. json_select "attributes"
  72. json_get_var "prefix" "prefix"
  73. json_close_object
  74. if [ "$prefix" == "$__SUBDOMAIN" ] ; then
  75. json_get_var "__RECORDID" "id"
  76. write_log 0 "Found record id : ${__RECORDID}"
  77. break
  78. fi
  79. json_close_object
  80. i=$(($i + 1))
  81. done
  82. fi
  83. if [ "${__RECORDID}" == "" ] ; then
  84. write_log 14 "domain record not found"
  85. return 1
  86. fi
  87. # CREATING PATCH DATA
  88. json_init
  89. json_add_string "type" "dns_service_records"
  90. json_add_string "id" "${__RECORDID}"
  91. json_add_object "attributes"
  92. json_add_string "type" "A"
  93. json_add_string "prefix" "${__SUBDOMAIN}"
  94. json_add_string "content" "${__IP}"
  95. json_add_int "ttl" ${__TTL}
  96. patchdata=$(json_dump)
  97. # SENDING PATCH
  98. $CURL \
  99. -RsSL \
  100. --stderr $ERRFILE \
  101. -c $COOKIEJAR \
  102. -b $COOKIEJAR \
  103. -X PATCH \
  104. -d "$patchdata" \
  105. -H "Content-Type: application/json" \
  106. "https://www.one.com/admin/api/domains/${__MAINDOMAIN}/dns/custom_records/${__RECORDID}" \
  107. | grep "priority" > $DATFILE
  108. if [ "$?" != "0" ] ; then
  109. write_log 14 "one.com gave an unexpected response"
  110. return 1
  111. fi
  112. rm $COOKIEJAR
  113. write_log 0 "one.com ddns script finished without errors"
  114. return 0