From 82191c2fbdeb0c69ae2a8179441056d680cfaaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Chachu=C5=82a?= Date: Sun, 4 Feb 2024 15:38:47 +0100 Subject: [PATCH] Use some of the passed variables CURL, CURL_SSL, DATFILE, ERRFILE, USE_CURL, use_https --- update_hexonet.sh | 50 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/update_hexonet.sh b/update_hexonet.sh index d98b044..e977518 100644 --- a/update_hexonet.sh +++ b/update_hexonet.sh @@ -2,29 +2,50 @@ # # script for sending updates to hexonet.net #.2024 Krystian ChachuĊ‚a +# +# TODO: make use of vars: +# CURL_PROXY, LOGFILE, PID_SLEEP, RETRY_COUNT, RETRY_SECONDS, VERBOSE, +# force_ipversion, use_ipv6, URL_PENC + call() { command="$1" - curl -s \ + + write_log 7 "Calling HEXONET with command:" $command + + $CURL -s \ -X POST \ -H 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 's_entity=54cd' \ --data-urlencode "s_command=$command" \ --data "s_login=$URL_USER&s_pw=$URL_PASS" \ + --output $DATFILE --stderr $ERRFILE \ https://api.ispapi.net/api/call.cgi + + if [ "$?" -ne 0 ]; then + write_log 14 "cURL error (exit code $?): " $(cat "$ERRFILE") + fi + + write_log 7 "HEXONET responded:" $(cat "$DATFILE") } +[ -z "$CURL" ] && [ -z "$CURL_SSL" ] && write_log 14 "HEXONET 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'" +[ -z "$URL_USER" ] && write_log 14 "Service section not configured correctly! Missing 'username'" +[ -z "$URL_PASS" ] && write_log 14 "Service section not configured correctly! Missing 'password'" +[ "$USE_CURL" -ne 1 ] && write_log 5 "The 'use_curl' setting is being forced to 1 as HEXONET communication require it." +[ "$use_https" -ne 1 ] && write_log 5 "The 'use_https' setting is being forced to 1 as HEXONET communication require it." domain="${domain%.}". zone="${domain#*.}" name="${domain%%.*}" +write_log 7 "Parsed domain='$domain' zone='$zone' name='$name'" + record="$name 3600 IN A $__IP" +write_log 6 "Desired record is '$record'" update_cmd="COMMAND = UPDATEDNSZONE -ADDRR0 = $name 3600 IN A $__IP +ADDRR0 = $record DNSZONE = $zone EXTENDED = 1 INCSERIAL = 1 @@ -32,31 +53,30 @@ RESOLVETTLCONFLICTS = 1" query_cmd="COMMAND = QueryDNSZoneRRList DNSZONE = $zone" -existing=$(call "$query_cmd" \ +call "$query_cmd" +existing=$(cat "$DATFILE" \ | awk "/PROPERTY\[RR\]\[[0-9]+\]=${domain}/ {print \$2,\$3,\$4,\$5}") if [ -n "$existing" ] && [ "$name $existing" != "$record" ]; then - write_log 7 "Record exists but IP is wrong, will be replaced" + write_log 6 "Found existing record '$name $existing'. It will be removed" update_cmd="$update_cmd DELRR0 = $name $existing" elif [ -z "$existing" ]; then - write_log 7 "Record does not exist" + write_log 6 "Desired record does not exist. It will be added" else - write_log 7 "Record exists" + write_log 6 "Desired record exists. Nothing to do" return 0 fi -write_log 7 "$update_cmd" - -res=$(call "$update_cmd") -code=$(echo "$res" \ +call "$update_cmd" +code=$(cat "$DATFILE" \ | awk -F= '/CODE=[0-9]+/ { print $2 }') if [ -z "$code" ]; then - write_log 7 "Unexpected response: $res" + write_log 4 "Error parsing response" return 1 elif [ "$code" != 200 ]; then - write_log 7 "Error response: $res" + write_log 4 "Error response code: $code" return 1 fi -write_log 7 "Success" +write_log 6 "Update successful" return 0 -- 2.45.2