#!/bin/sh /etc/rc.common

UCI_CONFIG=appuser_apply_all
TARGET_CONFIG=appuser
SEC=base

config_load $UCI_CONFIG

apply()
{
	old_nowtime=$(cat /proc/uptime | awk 'FS="[.]+" {print $1}')
	#state
	config_get mod_profile_status $SEC mod_profile_status
	config_get profile_status $SEC profile_status
	#user_mnt_status
	config_get mod_web_portal_login $SEC mod_web_portal_login
	config_get allow_web_portal_login $SEC allow_web_portal_login
	#user_enable_time_quota
	config_get mod_time_quota $SEC mod_time_quota
	config_get enable_time_quota $SEC enable_time_quota
	#user_set_time_quota
	config_get mod_time_quota_value $SEC mod_time_quota_value
	config_get set_time_quota $SEC set_time_quota
	#login_quota
	config_get mod_login_quota $SEC mod_login_quota
	config_get login_quota $SEC login_quota
	#idle timeout
	config_get mod_idle_timeout $SEC mod_idle_timeout
	config_get set_idle_timeout $SEC set_idle_timeout
	#pptp
	config_get mod_pptp $SEC mod_pptp
	config_get pptp $SEC pptp
	#l2tp
	config_get mod_l2tp $SEC mod_l2tp
	config_get l2tp $SEC l2tp
	#ssltunnel
	config_get mod_ssltunnel $SEC mod_ssltunnel
	config_get ssltunnel $SEC ssltunnel
	#mOTP
	config_get mod_usemotp $SEC mod_usemotp
	config_get usemotp $SEC usemotp
	#pppoe
	config_get mod_pppoe $SEC mod_pppoe
	config_get pppoe $SEC pppoe
	
	echo "config $TARGET_CONFIG" >/tmp/apply_all_$TARGET_CONFIG
	echo "sectype userprofile" >>/tmp/apply_all_$TARGET_CONFIG
	echo "section all" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_profile_status" = "enable" ] && echo "option state=$profile_status" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_web_portal_login" = "enable" ] && echo "option user_mnt_status=$allow_web_portal_login" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_time_quota" = "enable" ] && echo "option user_enable_time_quota=$enable_time_quota" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_time_quota_value" = "enable" ] && echo "option user_set_time_quota=$set_time_quota" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_login_quota" = "enable" ] && echo "option login_quota=$login_quota" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_idle_timeout" = "enable" ] && echo "option timeout=$set_idle_timeout" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_pptp" = "enable" ] && echo "option pptp=$pptp" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_l2tp" = "enable" ] && echo "option l2tp=$l2tp" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_ssltunnel" = "enable" ] && echo "option ssltunnel=$ssltunnel" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_usemotp" = "enable" ] && echo "option usemotp=$usemotp" >>/tmp/apply_all_$TARGET_CONFIG
	[ "$mod_pppoe" = "enable" ] && echo "option pppoe=$pppoe" >>/tmp/apply_all_$TARGET_CONFIG
	
	uci commit $TARGET_CONFIG
	/sbin/uci_apply_all "/tmp/apply_all_$TARGET_CONFIG"
	rm -f /tmp/apply_all_$TARGET_CONFIG
	
	uci revert $UCI_CONFIG
	nowtime=$(cat /proc/uptime | awk 'FS="[.]+" {print $1}')
	echo "appuser_apply_all($$): execution time=$(($nowtime - $old_nowtime))" >/dev/console
}
