Skip to content

Instantly share code, notes, and snippets.

@Lenart12
Last active December 21, 2023 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lenart12/4fb72b4d072fab873922c4c3f3545b42 to your computer and use it in GitHub Desktop.
Save Lenart12/4fb72b4d072fab873922c4c3f3545b42 to your computer and use it in GitHub Desktop.
OpenWRT DDNS client (ddns-scripts) update script for neoserv.si
#!/bin/sh
# /storitve/domena/uredizapis/[record_id]/[cart_id]
local __RECORD_ID=""
local __CART_ID=""
local __HOST=""
local __TTL=60
local __RRTYPE
local __ENDPOINT="https://moj.neoserv.si"
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing email as 'username'"
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing password as 'password'"
[ -z "$__RECORD_ID" ] && write_log 14 "Update script not configured correctly! Missing record id as '__RECORD_ID'"
[ -z "$__CART_ID" ] && write_log 14 "Update script not configured correctly! Missing cart id as '__CART_ID'"
[ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
local __COOKIEJAR="/tmp/ddns-cookies-$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32).txt"
write_log 7 "Using cookie jar $__COOKIEJAR"
local __RESPONSE __STATUS
# Login to web interface
curl -s -X POST "$__ENDPOINT/prijava/preveri" \
-F "email=$username" \
-F "password=$password" \
-c "$__COOKIEJAR" > /dev/null
# Check status
__RESPONSE=$(curl -s -X GET "$__ENDPOINT/prijava/preveri" \
-w "%{http_code}" \
-b "$__COOKIEJAR")
if [ $__RESPONSE -ne "302" ]; then
rm -f "$__COOKIEJAR"
write_log 14 "Failed to login to web interface as $username"
fi
write_log 7 "Logged in to web interface as $username"
__RESPONSE=$(curl -s -X POST "$__ENDPOINT/storitve/domena/popravizapis" \
-F "record[type]=$__RRTYPE" \
-F "record[id]=$__RECORD_ID" \
-F "record[host]=$__HOST" \
-F "record[cart_id]=$__CART_ID" \
-F "record[ttl]=$__TTL" \
-F "record[record]=$__IP" \
-b "$__COOKIEJAR" )
__STATUS="$?"
if [ "$__STATUS" -ne 0 ]; then
rm -f "$__COOKIEJAR"
write_log 14 "Failed to change record with status [$__STATUS]: '$__RESPONSE'"
fi
if ! echo "$__RESPONSE" | grep -q '"status":"1"'; then
rm -f "$__COOKIEJAR"
write_log 14 "Failed to change record: '$__RESPONSE'"
fi
rm -f "$__COOKIEJAR"
write_log 7 "Updated $domain to $__IP "
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment