#!/bin/sh if [ "$REQUEST_METHOD" = "POST" ]; then read QUERY_STRING fi # prepare stuff . /www/cgi-bin/dhcpsplash/clients.sh . /www/cgi-bin/dhcpsplash/clients-admin.sh . /www/cgi-bin/dhcpsplash/defaults.sh . /www/cgi-bin/dhcpsplash/ranges.sh . /www/cgi-bin/dhcpsplash/vars.sh mac=$(splash_getmac "$REMOTE_ADDR") . /etc/functions.sh get_netparam # return ip of interface for given source ip ($1) splash_ifipforip() { ip route get $1 | sed -n "s#.* src[ ]\{1,\}\([0-9\.]\{1,\}\).*#\1#p" } splash_wifimac() { ip addr | sed -n "/^[0-9: ]*$WIFIDEV/,/^[0-9]/s/ *link\/ether \([0-9a-f\:\.\/]*\) .*$/\1/p" } ## uris # url function need get_netparam! splash_agreement_url() { mode=$(splash_getvar ff_dhcpsplash_ag) if [ "$mode" = "url" ]; then url=$(splash_getvar ff_dhcpsplash_agurl) echo "$url" | sed " s//$WIFIADR/ s//$(splash_wifimac)/ s//$REMOTE_ADDR/ s//$mac/" else echo "cgi-bin-agreement.html" fi } splash_welcome_url() { mode="$(splash_getvar ff_dhcpsplash_hp)" if [ "$mode" = "url" ]; then url="$(splash_getvar ff_dhcpsplash_hpurl)" echo "$url" | sed " s//$WIFIADR/ s//$(splash_wifimac)/ s//$REMOTE_ADDR/ s//$mac/" else echo "cgi-bin-welcome.html" fi } # ARG: status message url [relative] splash_redirect() { if [ "$3" != "${3#http}" -o -n "$4" -a "$4" = "relative" ]; then url="$3" else url="http://$(splash_ifipforip "$REMOTE_ADDR")/$3" fi moreheaders='' if [ "300" -le "$1" -a "$1" -lt "400" ]; then moreheaders="Location: $url" fi cat< $1 - $2

$1 - $2

click here if you are not redirected automatically.

EOF } # redirect requests which are not in our iprange to cgi-bin-index.html if ! splash_insplashrange "$REMOTE_ADDR"; then splash_redirect "302" "Temporary Redirect" "cgi-bin-index.html" "relative" exit fi # redirect blocked macs if splash_isblockedmac "$mac"; then splash_redirect "403" "WLAN access blocked" "cgi-bin-blocked.html" exit fi # show index page for known clients if splash_isknownmac "$mac"; then splash_redirect "302" "Temporary Redirect" "cgi-bin-index.html" exit fi # display info page if dhcp is blocked by default if [ "$(splash_getvar ff_dhcpsplash_block)" = "all" ]; then splash_redirect "403" "WLAN access blocked" "cgi-bin-blocked.html" exit fi # WELCOME # insert mac into iptables and display welcome page if [ "$QUERY_STRING" != "${QUERY_STRING#*post_accept=yes}" -o "$(splash_getvar ff_dhcpsplash_ag)" = "off" ]; then splash_insertmac "$mac" splash_redirect "302" "Temporary Redirect" "$(splash_welcome_url)" exit fi # AGREEMENT # goto agreement splash_redirect "403" "WLAN login required" "$(splash_agreement_url)"