Skip to content

Commit

Permalink
Merge pull request #487 from nodogsplash/4.3.4beta
Browse files Browse the repository at this point in the history
Preauth: update login and demo-preauth scripts to display client zone
  • Loading branch information
bluewavenet committed Jan 2, 2020
2 parents b7216b3 + 15d5510 commit 2c6648a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 50 deletions.
102 changes: 59 additions & 43 deletions forward_authentication_service/PreAuth/demo-preauth-remote-image.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#Copyright © The Nodogsplash Contributors 2004-2019
#Copyright © Blue Wave Projects and Services 2015-2019
#Copyright (C) The Nodogsplash Contributors 2004-2020
#Copyright (C) Blue Wave Projects and Services 2015-2020
#This software is released under the GNU GPL license.

#############################################################################################
Expand All @@ -21,9 +21,43 @@
#
#############################################################################################

# functions:

### functions
get_image_file() {
imagepath="/etc/nodogsplash/htdocs/images/remote"
mkdir "/tmp/remote"

if [ ! -f "$imagepath" ]; then
ln -s /tmp/remote /etc/nodogsplash/htdocs/images/remote
fi

md5=$(echo -e $imageurl | md5sum);
filename=$(echo -e $md5 | awk -F" -" {'print($1)'});
filename="$filename.$imagetype"

if [ ! -f "$imagepath/$filename" ]; then
wget -q -P $imagepath -O $filename $imageurl
fi
}

get_client_zone () {
# Gets the client zone, ie the connction the client is using, such as:
# local interface (br-lan, wlan0, wlan0-1 etc.,
# or remote mesh node mac address
# This zone name is only displayed here but could be used to customise the login form for each zone

client_mac=$(ip -4 neigh |grep "$clientip" | awk '{print $5}')
client_if_string=$(/usr/lib/nodogsplash/get_client_interface.sh $client_mac)
client_if=$(echo $client_if_string | awk '{printf $1}')
client_meshnode=$(echo $client_if_string | awk '{printf $2}' | awk -F ':' '{print $1$2$3$4$5$6}')
local_mesh_if=$(echo $client_if_string | awk '{printf $3}')

if [ ! -z "$client_meshnode" ]; then
client_zone="MeshZone:$client_meshnode"
else
client_zone="LocalZone:$client_if"
fi
}

write_log () {
logfile="/tmp/ndslog.log"
Expand All @@ -40,38 +74,20 @@ write_log () {
sizeratio=$(($available/$filesize))

if [ $sizeratio -ge $min_freespace_to_log_ratio ]; then
echo "PreAuth - writing log to $logfile" | logger -p "daemon.notice" -s -t "nodogsplash[$ndspid]: "
echo "$datetime, Username=$username, Email Address=$emailaddr, mac address=$clientmac, user_agent=$user_agent" \
>> $logfile
else
echo "PreAuth - log file too big, please archive contents" | logger -p "daemon.err" -s -t "nodogsplash[$ndspid]: "
fi
}

get_image_file() {
imagepath="/etc/nodogsplash/htdocs/images/remote"
mkdir "/tmp/remote"

if [ ! -f "$imagepath" ]; then
ln -s /tmp/remote /etc/nodogsplash/htdocs/images/remote
fi

md5=$(echo -e $imageurl | md5sum);
filename=$(echo -e $md5 | awk -F" -" {'print($1)'});
filename="$filename.$imagetype"

if [ ! -f "$imagepath/$filename" ]; then
wget -q -P $imagepath -O $filename $imageurl
fi
}

# Get the urlencoded querystring and user_agent
query_enc="$1"
user_agent_enc="$2"

# The query string is sent to us from NDS in a urlencoded form,
# so we must decode it here so we can parse it:
query=$(printf "${query_enc//%/\\x}")
# we can decode it or parts of it using something like the following:
# query=$(printf "${query_enc//%/\\x}")

# The User Agent string is sent urlencoded also:
user_agent=$(printf "${user_agent_enc//%/\\x}")
Expand Down Expand Up @@ -125,20 +141,24 @@ user_agent=$(printf "${user_agent_enc//%/\\x}")
# The query string will be truncated if it does exceed this length.


# Parse for the system variables always sent by NDS:
clientip="$(echo $query | awk -F ', ' '{print $1;}' | awk -F 'clientip=' '{print $2;}')"
gatewayname="$(echo $query | awk -F ', ' '{print $2;}' | awk -F 'gatewayname=' '{print $2;}')"
# Parse for the variables returned by NDS:
queryvarlist="clientip gatewayname hid redir status username emailaddr"

# The third system variable is either the originally requested url:
requested="$(echo $query | awk -F ', ' '{print $3;}' | awk -F 'redir=' '{print $2;}')"
for var in $queryvarlist; do
nextvar=$(echo $queryvarlist | awk '{for(i=1;i<=NF;i++) if ($i=="'$var'") printf $(i+1)}')
eval $var=$(echo "$query_enc" | awk -F "$var%3d" '{print $2}' | awk -F "%2c%20$nextvar%3d" '{print $1}')
done

# or it is a status message:
status="$(echo $query | awk -F ', ' '{print $3;}' | awk -F 'status=' '{print $2;}')"
# URL decode vars that need it:
gatewayname=$(printf "${gatewayname//%/\\x}")
username=$(printf "${username//%/\\x}")
emailaddr=$(printf "${emailaddr//%/\\x}")

# Parse for additional variables we define in this script, in this case username and emailaddr
username="$(echo $query | awk -F ', ' '{print $4;}' | awk -F 'username=' '{print $2;}')"
emailaddr="$(echo $query | awk -F ', ' '{print $5;}' | awk -F 'emailaddr=' '{print $2;}')"
#requested might have trailing comma space separated, user defined parameters - so remove them as well as decoding
requested=$(printf "${redir//%/\\x}" | awk -F ', ' '{print $1}')

#Get the client zone, local wired, local wireless or remote mesh node
get_client_zone

# Define some common html as the first part of the page to be served by NDS
#
Expand Down Expand Up @@ -170,19 +190,15 @@ header="
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<link rel=\"shortcut icon\" href=\"/images/splash.jpg\" type=\"image/x-icon\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"/splash.css\">
<title>$gatewayname Captive Portal.</title>
<title>$gatewayname.</title>
</head>
<body>
<div class=\"offset\">
<med-blue>$gatewayname Captive Portal.</med-blue>
<med-blue>$gatewayname.</med-blue>
<div class=\"insert\" style=\"max-width:100%;\">
<hr>
"

# Define a common footer for every page served
version="$(ndsctl status | grep Version)"
year="$(date | awk -F ' ' '{print $(6)}')"

# We want to display an image from a remote server
# Remote server can be https if required
# All we need is the image url and image type (jpg, png etc.)
Expand Down Expand Up @@ -212,6 +228,7 @@ login_form="
<form action=\"/nodogsplash_preauth/\" method=\"get\">
<input type=\"hidden\" name=\"clientip\" value=\"$clientip\">
<input type=\"hidden\" name=\"gatewayname\" value=\"$gatewayname\">
<input type=\"hidden\" name=\"hid\" value=\"$hid\">
<input type=\"hidden\" name=\"redir\" value=\"$requested\">
<input type=\"text\" name=\"username\" value=\"$username\" autocomplete=\"on\" ><br>Name<br><br>
<input type=\"email\" name=\"emailaddr\" value=\"$emailaddr\" autocomplete=\"on\" ><br>Email<br><br>
Expand Down Expand Up @@ -242,7 +259,9 @@ fi
# Note also $clientip, $gatewayname and $requested (redir) must always be preserved
#
if [ -z $username ] || [ -z $emailaddr ]; then
echo "<big-red>Welcome!</big-red><italic-black> To access the Internet you must enter your Name and Email Address</italic-black><hr>"
echo "<big-red>Welcome!</big-red><br>
<med-blue>You are connected to $client_zone</med-blue><br>
<italic-black>To access the Internet you must enter your Name and Email Address</italic-black><hr>"
echo -e $login_form
else
# If we got here, we have both the username and emailaddr fields as completed on the login page on the client,
Expand Down Expand Up @@ -303,6 +322,3 @@ echo -e $footer
# could easily be used to conduct a dialogue with the client user.
#




30 changes: 28 additions & 2 deletions forward_authentication_service/PreAuth/demo-preauth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@

# functions:

get_client_zone () {
# Gets the client zone, ie the connction the client is using, such as:
# local interface (br-lan, wlan0, wlan0-1 etc.,
# or remote mesh node mac address
# This zone name is only displayed here but could be used to customise the login form for each zone

client_mac=$(ip -4 neigh |grep "$clientip" | awk '{print $5}')
client_if_string=$(/usr/lib/nodogsplash/get_client_interface.sh $client_mac)
client_if=$(echo $client_if_string | awk '{printf $1}')
client_meshnode=$(echo $client_if_string | awk '{printf $2}' | awk -F ':' '{print $1$2$3$4$5$6}')
local_mesh_if=$(echo $client_if_string | awk '{printf $3}')

if [ ! -z "$client_meshnode" ]; then
client_zone="MeshZone:$client_meshnode"
else
client_zone="LocalZone:$client_if"
fi
}

write_log () {
logfile="/tmp/ndslog.log"
min_freespace_to_log_ratio=10
Expand Down Expand Up @@ -96,11 +115,16 @@ for var in $queryvarlist; do
done

# URL decode vars that need it:
requested=$(printf "${redir//%/\\x}")
gatewayname=$(printf "${gatewayname//%/\\x}")
username=$(printf "${username//%/\\x}")
emailaddr=$(printf "${emailaddr//%/\\x}")

#requested might have trailing comma space separated, user defined parameters - so remove them as well as decoding
requested=$(printf "${redir//%/\\x}" | awk -F ', ' '{print $1}')

#Get the client zone, local wired, local wireless or remote mesh node
get_client_zone

# Define some common html as the first part of the page to be served by NDS
#
# Note this example uses the default splash.css provided by NDS and uses splash.jpg
Expand Down Expand Up @@ -192,7 +216,9 @@ fi
# Note also $clientip, $gatewayname and $requested (redir) must always be preserved
#
if [ -z $username ] || [ -z $emailaddr ]; then
echo "<big-red>Welcome!</big-red><italic-black> To access the Internet you must enter your Name and Email Address</italic-black><hr>"
echo "<big-red>Welcome!</big-red><br>
<med-blue>You are connected to $client_zone</med-blue><br>
<italic-black>To access the Internet you must enter your Name and Email Address</italic-black><hr>"
echo -e $login_form
else
# If we got here, we have both the username and emailaddr fields as completed on the login page on the client,
Expand Down
17 changes: 12 additions & 5 deletions forward_authentication_service/libs/get_client_interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ fi

# Get default interface
# This will be the interface NDS is bound to eg. br-lan
#clientlocalip=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' ")>0 {printf $1}')
#ping=$(ping -W 1 -c 1 $clientlocalip)
#clientlocalif=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' REACHABLE")>0 {printf $3}')
clientlocalif=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' ")>0 {printf $3}')

if [ -z $clientlocalif ]; then
Expand All @@ -58,14 +61,18 @@ interface_list=$(iw dev | awk -F 'Interface ' 'NF>1{printf $2" "}')
# Scan the wireless interfaces on this device for the client mac
for interface in $interface_list; do
macscan=$(iw dev $interface station dump | awk -F " " 'match($s, "'"$mac"'")>0{printf $2}')
meshmac=$(iw dev $interface mpp dump | awk -F "$mac " 'NF>1{printf $2}')

if [ ! -z "$macscan" ]; then
clientmeshif=""
clientlocalif=$interface
fi

if [ ! -z "$meshmac" ]; then
clientmeshif=$meshmac
break
else
clientlocalip=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' ")>0 {printf $1}')
ping=$(ping -W 1 -c 1 $clientlocalip)
meshmac=$(iw dev $interface mpp dump | awk -F "$mac " 'NF>1{printf $2}')
if [ ! -z "$meshmac" ]; then
clientmeshif=$meshmac
fi
fi
done

Expand Down
7 changes: 7 additions & 0 deletions resources/splash.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@
}

input[type=text], input[type=email], input[type=password] {
font-size: 1em;
line-height: 2.0em;
height: 2.0em;
color: black;
background: lightgrey;
}

input[type=submit], input[type=button] {
font-size: 1em;
line-height: 2.0em;
height: 2.0em;
color: black;
font-weight: bold;
background: lightblue;
}

Expand Down

0 comments on commit 2c6648a

Please sign in to comment.