Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # User Configuration
- __USERNAME__="MyUserName"
- __PASSWORD__="MyPassword"
- __HOSTNAME__="host.example.com"
- __DOMAIN__=$(echo ${__HOSTNAME__} | cut -d. -f2-3)
- # System Configuration
- # Set the __INTERFACE__ varible to nothing (__INTERFACE__=) to use external lookup.
- __INTERFACE__=eth1
- __IP_CACHE__=/tmp/gratisdns_ddns_ip.txt
- __LOGFILE__=/var/log/gratisdns_ddns.log
- log() {
- __LOGTIME__=$(date +"%b %e %T")
- if [ "${#}" -lt 1 ]; then
- false
- else
- __LOGMSG__="${1}"
- fi
- if [ "${#}" -lt 2 ]; then
- __LOGPRIO__=7
- else
- __LOGPRIO__=${2}
- fi
- #logger -p ${__LOGPRIO__} -t "$(basename ${0})" "${__LOGMSG__}"
- echo "${__LOGTIME__} $(basename ${0}) (${__LOGPRIO__}): ${__LOGMSG__}" >> ${__LOGFILE__}
- }
- # Get the last known DDNS IP
- if [ ! -f ${__IP_CACHE__} ]; then
- echo "127.0.0.1" > ${__IP_CACHE__}
- fi
- __OLDIP__=$(cat ${__IP_CACHE__})
- if [ -z "${__INTERFACE__}" ]; then
- # Interface not defined, so getting the public IP through external lookup.
- __MYIP__=$(curl -s "http://automation.whatismyip.com/n09230945.asp")
- else
- # Get the current IP for the specified interface.
- __MYIP__=$(ifconfig ${__INTERFACE__} | sed '/inet\ /!d;s/.*r://g;s/\ .*//g')
- fi
- if [ "${__OLDIP__}" == "${__MYIP__}" ]; then
- log "IP not changed. ${__MYIP__}. Not updating." 7
- true
- else
- log "IP changed. ${__OLDIP__} > ${__MYIP__}. Attempting to update DNS." 6
- # Update DNS record
- __URL__="https://ssl.gratisdns.dk/ddns.phtml?u=${__USERNAME__}&p=${__PASSWORD__}&d=${__DOMAIN__}&h=${__HOSTNAME__}&i=${__MYIP__}"
- __STATUS__=$(curl -s -k "${__URL__}")
- case ${__STATUS__} in
- 'OK<br>')
- echo ${__MYIP__} > ${__IP_CACHE__}
- log "IP successfully updated." 6
- true
- ;;
- 'OK<br>Opdateret i forvejen')
- echo ${__MYIP__} > ${__IP_CACHE__}
- log "IP successfully updated. However, the IP was already updated, according to the DDNS provider." 5
- true
- ;;
- 'Forkerte værdier, opdatering kan ikke laves.<br><br>A record findes ikke.')
- log "Invalid parameters, nothing was updated. The A record '${__HOSTNAME__}' doesn't exist." 3
- false
- ;;
- 'Domæne kan IKKE administreres af bruger')
- log "You do not have permission to update DDNS for the domain '${__DOMAIN__}'." 3
- false
- ;;
- 'Forkerte værdier, opdatering kan ikke laves.<br><br>A record findes ikke.Hostnavn er ulovligt.')
- log "Invalid parameters, nothing was updated. The A record for '${__HOSTNAME__}' doesn't exist. The hostname must be a FQDN." 3
- false
- ;;
- 'Bruger login: 1Fejl i kodeord, prøv igen. Husk serveren ser forskel på STORE Og små BOGstAvER.')
- log "Incorrect password for '${__USERNAME__}'. The password is CaSe SeNsItIvE." 3
- false
- ;;
- 'Bruger login: Bruger eksistere ikke, husk serveren ser forskel på STORE Og smÅ BOGstAvER.')
- log "The supplied username '${__USERNAME__}' wasn't found. The username is CaSe SeNsItIvE." 3
- false
- ;;
- esac
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement