summaryrefslogtreecommitdiff
path: root/files/common/www/service/cgi-bin/splash_click
blob: 1eb4e85a97b93634c2346162be246d73bc49a1a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh -e
. $IPKG_INSTROOT/etc/functions.sh
. /etc/splash.sh

echo -en "Status: 200 OK\r\n"
echo -en "Content-Type: text/html\r\n"
echo -en "\r\n"

# decode request params
URL="http://$(sed 's/target_url=//g' | urldecode)"
USER_MAC=$(grep ^$REMOTE_HOST </proc/net/arp \
	 | awk 'BEGIN { FS = " " } ; { print $4 }')

# check if user is already splashed; splash otherwise
lockSplash
ISSPLASHED=0
config_load splash_users
is_mac() {
   config_get mac "$1" mac
   if [ "$mac" == "$USER_MAC" ]; then
   	ISSPLASHED=1
   fi
}
config_foreach is_mac user
if [ $ISSPLASHED -eq 0 ]; then
    # user is now free to go
    chain=$chain_prefix$chain_id
    iptables -t nat -I $chain 1 -m mac --mac-source $USER_MAC -j ACCEPT

    uci -q add splash_users user >/dev/null
    uci -q set splash_users.@user[-1].mac=$USER_MAC
    uci -q set splash_users.@user[-1].time=`date +%s`
fi
unlockSplash

# send response (encode / to not confuse sed)
sed "s/targeturl/$(echo "$URL" | sed 's#/#\\/#g')/g" iframe.html
contact: Jan Huwald // Impressum