aboutsummaryrefslogtreecommitdiff
path: root/net/apfree-wifidog/files/wifidogx.init
blob: 8b9bbb86984bc6d0b6bceacf2f7b91ccdb53e352 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh /etc/rc.common
# Copyright (C) 2018 Dengfeng Liu

START=99

USE_PROCD=1
NAME=wifidogx
PROG=/usr/bin/${NAME}
CONFIGFILE=/tmp/wifidogx.conf

prepare_wifidog_conf() {

	[ -f ${CONFIGFILE} ] && rm -f ${CONFIGFILE}

	uci_validate_section ${NAME} ${NAME} common \
		'enabled:bool:0' \
		'gateway_id:string' \
		'gateway_interface:string:br-lan' \
		'auth_server_hostname:string' \
		'auth_server_port:port:443' \
		'auth_server_path:string:/wifidog/' \
		'check_interval:integer:60' \
		'client_timeout:integer:5' \
		'wired_passed:bool:1' \
		'apple_cna:bool:0' \
		'channel_path:string' \
		'trusted_domains:string' \
		'trusted_macs:string' \
		'js_filter:bool:1' 

	# if gateway_id is not set, get it from br-lan
	if [ -z "$gateway_id" ]; then
		gateway_id=$(sed -e 's/://g' /sys/class/net/${gateway_interface}/address)
		# convert to upper case
		gateway_id=$(echo $gateway_id | tr '[a-z]' '[A-Z]')
		# uci add gateway_id to config file
		uci set ${NAME}.common.gateway_id=$gateway_id
		uci commit ${NAME}
	fi
	
	# if channel_path is not set, set it to apfree
	if [ -z "$channel_path" ]; then
		channel_path=apfree
		uci set ${NAME}.common.channel_path=$channel_path
		uci commit ${NAME}
	fi

	# set above variables to config file
	echo "GatewayID $gateway_id" > ${CONFIGFILE}
	echo "GatewayInterface $gateway_interface" >> ${CONFIGFILE}
	echo "AuthServer {
	Hostname $auth_server_hostname
	HTTPPort $auth_server_port
	Path $auth_server_path
}" >> ${CONFIGFILE}
	echo "CheckInterval $check_interval" >> ${CONFIGFILE}
	echo "ClientTimeout $client_timeout" >> ${CONFIGFILE}
	echo "JsFilter $js_filter" >> ${CONFIGFILE}
	echo "WiredPassed $wired_passed" >> ${CONFIGFILE}
	echo "BypassAppleCNA $apple_cna" >> ${CONFIGFILE}
	# if has trusted_domains, add it to config file
	if [ ! -z "$trusted_domains" ]; then
		echo "TrustedDomains $trusted_domains" >> ${CONFIGFILE}
	fi
	# if has trusted_macs, add it to config file
	if [ ! -z "$trusted_macs" ]; then
		echo "TrustedMACList $trusted_macs" >> ${CONFIGFILE}
	fi
}

start_service() {
	config_load $NAME

	prepare_wifidog_conf

	[ "$enabled" -eq 0 ] && {
		echo "wifidogx is disabled, exit..." >&2
		return
	}

	procd_open_instance
	# -f: run in foreground
	procd_set_param command $PROG -c $CONFIGFILE -f -d 0
	procd_set_param respawn # respawn automatically if something died
	procd_set_param file /etc/config/wifidogx
	procd_close_instance
}

status_service() {
	/usr/bin/wdctlx status
}

reload_service() {
	stop 
	start
}

service_triggers() {
	procd_add_reload_trigger "${NAME}"
}