#!/bin/sh #Copyright (C) The openNDS Contributors 2004-2020 #Copyright (C) BlueWave Projects and Services 2015-2020 #This software is released under the GNU GPL license. # # Warning - shebang sh is for compatibliity with busybox ash (eg on OpenWrt) # This is changed to bash automatically by Makefile for Debian # # Customise the Logfile location: # # mountpoint is the mount point for the storage the log is to be kept on # # /tmp on OpenWrt is tmpfs (ram disk) and does not survive a reboot. # # /run on Raspbian is also tmpfs and also does not survive a reboot. # # These choices for OpenWrt and Raspbian are a good default for testing purposes # as long term use on internal flash could cause memory wear # In a production system, use the mount point of a usb drive for example # # # logdir is the directory path for the log file # # # logname is the name of the log file # #For Openwrt: mountpoint="/tmp" logdir="/tmp/ndslog/" logname="ndslog.log" #For Raspbian: #mountpoint="/run" #logdir="/run/ndslog/" #logname="ndslog.log" #For logging ndspid=$(ps | grep '/usr/bin/opennds' | awk -F ' ' 'NR==2 {print $1}') # functions: validate_client() { #Add your custom client validation here #For example check all the clent entered data against a database # we have: # $username, $phone, $emailaddr, $addr, $code # # Return either 0 if validation successful or 1 if not userlist="/etc/opennds/htdocs/images/wlan1/userpass.dat" varlist="username password Firstname Lastname" while read user; do for var in $varlist; do nextvar=$(echo "$varlist" | awk '{for(i=1;i<=NF;i++) if ($i=="'$var'") printf $(i+1)}') eval $var=$(echo "$user" | awk -F "$var=" '{print $2}' | awk -F ", $nextvar=" '{print $1}') done if [ "$username" = "$1" -a "$password" = "$2" ]; then exit_code=0 break else exit_code=1 fi done < $userlist return $exit_code } htmlentityencode() { entitylist="s/\"/\"/ s/>/\>/ s/\</" local buffer="$1" for entity in $entitylist; do entityencoded=$(echo "$buffer" | sed "$entity") buffer=$entityencoded done } htmlentitydecode() { entitylist="s/\"/\"/ s/\>/>/ s/\</" local buffer="$1" for entity in $entitylist; do entitydecoded=$(echo "$buffer" | sed "$entity") buffer=$entitydecoded done } 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/opennds/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 () { if [ ! -d "$logdir" ]; then mkdir -p "$logdir" fi logfile="$logdir""$logname" awkcmd="awk ""'\$6==""\"$mountpoint\"""{print \$4}'" min_freespace_to_log_ratio=10 datetime=$(date) if [ ! -f "$logfile" ]; then echo "$datetime, New log file created" > $logfile fi filesize=$(ls -s -1 $logfile | awk -F' ' '{print $1}') available=$(df | grep "$mountpoint" | eval "$awkcmd") sizeratio=$(($available/$filesize)) if [ $sizeratio -ge $min_freespace_to_log_ratio ]; then userinfo="username=$username, password=$password" clientinfo="macaddress=$clientmac, clientzone=$client_zone, useragent=$user_agent" echo "$datetime, $userinfo, $clientinfo" >> $logfile else echo "PreAuth - log file too big, please archive contents" | logger -p "daemon.err" -s -t "opennds[$ndspid]: " fi } # Get the urlencoded querystring and user_agent query_enc=$(echo "$1" | sed "s/%3f/%20/") user_agent_enc="$2" # The query string is sent to us from NDS in a urlencoded form, # 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}") # In this example script we want to ask the client user for # their username and email address. # # We could ask for anything we like and add our own variables to the html forms # we generate. # # If we want to show a sequence of forms or information pages we can do this easily. # # To return to this script and show additional pages, the form action must be set to: #