Merge pull request #1247 from oneru/master
[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 START=60
9
10 FWKNOPD_BIN=/usr/sbin/fwknopd
11
12 start()
13 {
14 gen_confs
15 $FWKNOPD_BIN
16 }
17
18 stop()
19 {
20 $FWKNOPD_BIN -K
21 }
22
23 restart()
24 {
25 stop;
26 sleep 1;
27 start;
28 }
29
30 reload()
31 {
32 gen_confs
33 $FWKNOPD_BIN -R
34 }
35
36 gen_confs()
37 {
38 [ -f /tmp/access.conf.tmp ] && rm /tmp/access.conf.tmp
39 config_cb() {
40 local type="$1"
41 local name="$2"
42 if [ "$type" = "global" ]; then
43 option_cb() {
44 local option="$1"
45 local value="$2"
46 if [ "$option" = "uci_enabled" ] && [ "$value" -eq 1 ] ; then
47 > /etc/fwknop/fwknopd.conf
48 > /etc/fwknop/access.conf
49 UCI_ENABLED=1
50 fi
51 }
52 elif [ "$type" = "config" ]; then
53 option_cb() {
54 local option="$1"
55 local value="$2"
56 if [ $UCI_ENABLED ]; then
57 echo "$option $value" >> /etc/fwknop/fwknopd.conf #writing each option to fwknopd.conf
58 fi
59 }
60 elif [ "$type" = "access" ]
61 then
62 if [ -f /tmp/access.conf.tmp ] ; then
63 cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
64 rm /tmp/access.conf.tmp
65 fi
66 option_cb() {
67 local option="$1"
68 local value="$2"
69 if [ $UCI_ENABLED ] && [ $option = "SOURCE" ]; then
70 echo "$option $value" >> /etc/fwknop/access.conf #writing each option to access.conf
71 fi
72 if [ $UCI_ENABLED ] && [ $option != "SOURCE" ]; then
73 echo "$option $value" >> /tmp/access.conf.tmp #writing each option to access.conf
74 fi
75 }
76 fi
77 }
78
79 if [ -f /etc/config/fwknopd ]; then
80 config_load fwknopd
81 if [ -f /tmp/access.conf.tmp ] ; then
82 cat /tmp/access.conf.tmp >> /etc/fwknop/access.conf
83 rm /tmp/access.conf.tmp
84 fi
85 fi
86
87 }