#!/bin/sh
# HotSpot add-on module to webif^2 v1.0
# by Liran Tal <liran@enginx.com>
#
# this module is part of the webif^2 interface for the x-wrt.
# thanks to thepeople and nbd for their help to understand the webif

. /etc/functions.sh

config_cb() {
	local cfg_type="$1"
	local cfg_name="$2"
	[ "$cfg_type" = "chilli" ] && chilli_cfg="$cfg_name" || unset chilli_cfg
}

option_cb() {
	local var_name="$1"; shift
	local var_value="$*"
	[ -n "$chilli_cfg" ] && [ -n "$var_value" ] && {
		case "$var_name" in
			debug|macauth|uamanydns|coanoipcheck|acctupdate|fg|eapolenable)
				case "$var_value" in
					1|on|enabled) chilli_options="$chilli_options${var_name}${_lf}" ;;
				esac
			;;
			*) chilli_options="$chilli_options${var_name} ${var_value}${_lf}" ;;
		esac
	}
}

_lf="
"
chilli_config="/etc/chilli.conf"
chilli_options="# this file is automatically generated${_lf}"
config_load hotspot
echo "$chilli_options" > "$chilli_config"
