appfilter.init revision 2489a517
1#!/bin/sh /etc/rc.common
2. /usr/share/libubox/jshn.sh
3. /lib/functions.sh
4
5START=96
6USE_PROCD=1
7OAFD_BIN="/usr/bin/oafd"
8
9config_apply()
10{
11    test -z "$1" && return 1
12    
13	if [ -e "/dev/appfilter" ];then
14    	echo "config json str=$1"
15    	echo "$1" >/dev/appfilter
16	fi
17}
18
19clean_rule()
20{
21    json_init
22    echo "clean appfilter rule..."
23
24    json_add_int "op" 3
25    json_add_object "data"
26    json_str=`json_dump`
27
28    config_apply "$json_str"
29
30    json_cleanup
31}
32
33load_rule()
34{
35    json_init
36    json_add_int "op" 1
37    json_add_object "data"
38    json_add_array "apps"
39
40    for file in `ls /tmp/appfilter/*.class`
41    do
42	class_name=`echo "$file" | awk -F/ '{print $4}'| awk -F. '{print $1}'`
43	config_get appid_list "appfilter" "${class_name}apps"
44	echo "appid_list=$appid_list"
45
46	if ! test -z "$appid_list";then
47	    for appid in $appid_list:
48	    do
49	        json_add_int "" $appid
50	    done
51	fi
52    done
53
54    json_str=`json_dump`
55    config_apply "$json_str"
56    json_cleanup
57}
58
59load_mac_list()
60{
61    json_init
62    config_load appfilter
63    json_add_int "op" 4
64    json_add_object "data"
65    json_add_array "mac_list"
66	config_get appid_list "user" "users"
67	echo "appid list=$appid_list"
68	for appid in $appid_list:
69	do
70		echo "appid=$appid"
71		json_add_string "" $appid
72	done
73    json_str=`json_dump`
74    config_apply "$json_str"
75	echo "json str=$json_str"
76    json_cleanup
77}
78
79
80service_triggers()
81{
82	procd_add_reload_trigger "appfilter"
83}
84
85stop_service(){
86	clean_rule
87}
88
89start_service(){
90	gen_class.sh /etc/appfilter/feature.cfg
91
92	config_load appfilter
93    config_get enable "global" enable
94    echo "enable = $enable"	
95	
96    if [ x"$enable" != x"1" ];then
97		echo "appfilter is disabled"
98		echo 0 >/proc/sys/oaf/enable>/dev/null
99		return 0
100    else
101		insmod oaf >/dev/null
102		echo 1 >/proc/sys/oaf/enable
103	fi
104
105	load_rule
106	load_mac_list
107	procd_open_instance
108	procd_set_param respawn 60 5 5
109	procd_set_param stderr 1
110	procd_set_param command "$OAFD_BIN"
111	procd_close_instance
112}
113