1. /usr/share/libubox/jshn.sh
2. /lib/functions.sh
3
4
5config_apply()
6{
7    test -z "$1" && return 1
8	if [ -e "/dev/appfilter" ];then
9    	echo "$1" >/dev/appfilter
10	fi
11}
12
13clean_rule()
14{
15    json_init
16    json_add_int "op" 3
17    json_add_object "data"
18    json_str=`json_dump`
19    config_apply "$json_str"
20    json_cleanup
21}
22
23load_rule()
24{
25    json_init
26    json_add_int "op" 1
27    json_add_object "data"
28    json_add_array "apps"
29    for file in `ls /tmp/appfilter/*.class`
30    do
31        class_name=`echo "$file" | awk -F/ '{print $4}'| awk -F. '{print $1}'`
32        config_get appid_list "appfilter" "${class_name}apps"
33
34        if ! test -z "$appid_list";then
35            for appid in $appid_list:
36            do
37                json_add_int "" $appid
38            done
39        fi
40    done
41
42    json_str=`json_dump`
43    config_apply "$json_str"
44    json_cleanup
45}
46
47load_mac_list()
48{
49    json_init
50    config_load appfilter
51    json_add_int "op" 4
52    json_add_object "data"
53    json_add_array "mac_list"
54    config_get mac_list "user" "users"
55    if [ x"$mac_list" != x"" ];then    
56        for mac in $mac_list:          
57        do                             
58            json_add_string "" $mac
59        done                           
60    fi  
61    json_str=`json_dump`
62    config_apply "$json_str"
63    json_cleanup
64}
65
66reload_rule(){
67    config_load appfilter
68    clean_rule
69    load_rule
70    load_mac_list
71}
72
73reload_base_config(){       
74    config_load appfilter              
75    config_get work_mode "global" "work_mode"
76    echo "$work_mode" >/proc/sys/oaf/work_mode
77}
78
79case $1 in
80"reload")
81    reload_base_config
82	reload_rule
83;;
84esac
85