Skip to content

Instantly share code, notes, and snippets.

@thejh
Created September 1, 2013 13:29
Show Gist options
  • Save thejh/6404481 to your computer and use it in GitHub Desktop.
Save thejh/6404481 to your computer and use it in GitHub Desktop.
dyndns
#!/bin/sh
# headers first
echo 'Content-Type: text/plain'
echo ''
host="$(echo "$QUERY_STRING" | tr '&' '\n' | grep '^host=[a-zA-Z_-]\+$' | head -n1 | cut -d'=' -f2)"
pass="$(echo "$QUERY_STRING" | tr '&' '\n' | grep '^pass=[a-zA-Z0-9_-]\+$' | head -n1 | cut -d'=' -f2)"
ip="$(echo "$QUERY_STRING" | tr '&' '\n' | grep '^ip=[0-9][0-9.:]\+$' | head -n1 | cut -d'=' -f2)"
#echo "request echo"
#echo "qs: $QUERY_STRING"
#echo "host=$host, pass=$pass, ip=$ip"
hostdir="/var/lib/dyndns/host/$host"
realpass="$(cat "$hostdir/password")"
if [ "$pass" != "$realpass" ]; then
echo "bad password invalid"
exit 0
fi
echo "$ip" > "$hostdir/ip"
echo "good $ip"
#!/bin/sh
# headers first
urldecode(){
echo "$(sed 's/+/ /g; s/%/\\x/g')"
}
host="$(echo "$QUERY_STRING" | tr '&' '\n' | grep '^host=[a-zA-Z_-]\+$' | head -n1 | cut -d'=' -f2)"
pass="$(echo "$QUERY_STRING" | tr '&' '\n' | grep '^pass=[a-zA-Z0-9_-]\+$' | head -n1 | cut -d'=' -f2)"
url="$(echo "$QUERY_STRING" | tr '&' '\n' | grep '^url=http' | head -n1 | cut -d'=' -f2 | urldecode)"
url="$(echo "$url" | tr -d '\r\n')"
hostdir="/var/lib/dyndns/host/$host"
realpass="$(cat "$hostdir/rpassword")"
if [ "$pass" != "$realpass" ]; then
echo "Content-Type: text/plain"
echo ""
echo "bad password invalid"
exit 0
fi
ip="$(cat "$hostdir/ip")"
url="$(echo "$url" | sed "s|0\.0\.0\.0|$ip|")"
echo "Content-Type: text/plain" # for the status message and to decrease possible damage from Location
echo "Location: $url"
echo ""
echo "see $url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment