Fwknop: add flexibility to uci support
[feed/packages.git] / net / fwknop / files / fwknopd.init
1 #!/bin/sh /etc/rc.common
2 #
3 # Fwknop is developed primarily by the people listed in the file 'AUTHORS'.
4 # Copyright (C) 2009-2014 fwknop developers and contributors. For a full
5 # list of contributors, see the file 'CREDITS'.
6 #
7 . /lib/functions.sh
8 UCI_ENABLED=0
9 START=60
10
11 FWKNOPD_BIN=/usr/sbin/fwknopd
12
13 start()
14 {
15 gen_confs
16 $FWKNOPD_BIN
17 }
18
19 stop()
20 {
21 $FWKNOPD_BIN -K
22 }
23
24 restart()
25 {
26 stop;
27 sleep 1;
28 start;
29 }
30
31 reload()
32 {
33 gen_confs
34 $FWKNOPD_BIN -R
35 }
36
37 gen_confs()
38 {
39 [ -f /tmp/access.conf.tmp ] && rm /tmp/access.conf.tmp
40 config_cb() {
41 local type="$1"
42 local name="$2"
43 if [ "$type" = "global" ]; then
44 option_cb() {
45 local option="$1"
46 local value="$2"
47 if [ "$option" = "uci_enabled" ] && [ "$value" -eq 1 ] ; then
48 > /etc/fwknop/fwknopd.conf
49 > /etc/fwknop/access.conf
50 UCI_ENABLED=1
51 fi
52 }
53 elif [ "$type" = "config" ]; then
54 option_cb() {
55 local option="$1"
56 local value="$2"
57 if [ $UCI_ENABLED ]; then
58 echo "$option $value" >> /etc/fwknop/fwknopd.conf #writing each option to fwknopd.conf
59 fi
60 }
61 elif [ "$type" = "access" ]
62 then
63 if [ -f /tmp/access.conf.tmp ] ; then
64 cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
65 rm /tmp/access.conf.tmp
66 fi
67 option_cb() {
68 local option="$1"
69 local value="$2"
70 if [ $UCI_ENABLED ] && [ $option = "SOURCE" ]; then
71 echo "$option $value" >> /etc/fwknop/access.conf #writing each option to access.conf
72 fi
73 if [ $UCI_ENABLED ] && [ $option != "SOURCE" ]; then
74 echo "$option $value" >> /tmp/access.conf.tmp #writing each option to access.conf
75 fi
76 }
77 fi
78 }
79
80 if [ -f /etc/config/fwknopd ]; then
81 config_load fwknopd
82 if [ -f /tmp/access.conf.tmp ] ; then
83 cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
84 rm /tmp/access.conf.tmp
85 fi
86 fi
87
88 }