lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

fwknopd.init (2240B)


      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=95
      9 
     10 FWKNOPD_BIN=/usr/sbin/fwknopd
     11 
     12 start()
     13 {
     14 	gen_confs
     15 	if [ $UCI_ENABLED ]; then
     16         	$FWKNOPD_BIN -c /var/etc/fwknopd.conf -a /var/etc/access.conf 
     17 	else
     18         	$FWKNOPD_BIN 
     19 	fi
     20 
     21 }
     22 
     23 stop()
     24 {
     25         $FWKNOPD_BIN -K
     26 }
     27 
     28 restart()
     29 {
     30     stop;
     31     sleep 1;
     32     start;
     33 }
     34 
     35 reload()
     36 {
     37 	gen_confs
     38         $FWKNOPD_BIN -R
     39 }
     40 
     41 gen_confs()
     42 {
     43 	[ -f /tmp/access.conf.tmp ] && rm /tmp/access.conf.tmp
     44 	if [ -z "$( uci get fwknopd.@config[0].PCAP_INTF )" ]
     45 	then
     46 		. /lib/functions/network.sh
     47 		network_get_physdev device wan
     48 		uci set fwknopd.@config[0].PCAP_INTF="$device"
     49 		uci commit
     50 	fi
     51 	config_cb() {
     52 		local type="$1"
     53 		local name="$2"
     54 		if [ "$type" = "global" ]; then
     55 			option_cb() {
     56 				local option="$1"
     57 				local value="$2"
     58 				if [ "$option" = "uci_enabled" ] && [ "$value" -eq 1 ] ; then
     59 					> /var/etc/fwknopd.conf
     60 					> /var/etc/access.conf
     61                                         chmod 600 /var/etc/fwknopd.conf
     62                                         chmod 600 /var/etc/access.conf
     63 					UCI_ENABLED=1
     64 				fi
     65 			}
     66 		elif [ "$type" = "config" ]; then
     67 			option_cb() {
     68 				local option="$1"
     69 				local value="$2"
     70 				if [ $UCI_ENABLED ]; then
     71 					echo "$option $value" >> /var/etc/fwknopd.conf  #writing each option to fwknopd.conf
     72 				fi
     73 			}
     74 		elif [ "$type" = "access" ]
     75 		then
     76 			if [ -f /tmp/access.conf.tmp ] ; then
     77 				cat /tmp/access.conf.tmp >> /var/etc/access.conf
     78 				rm /tmp/access.conf.tmp
     79 			fi
     80 			option_cb() {
     81 				local option="$1"
     82 				local value="$2"
     83 				if [ $UCI_ENABLED ] && [ $option = "SOURCE" ]; then
     84 					echo "$option $value" >> /var/etc/access.conf  #writing each option to access.conf
     85 				fi
     86 				if [ $UCI_ENABLED ] && [ $option != "SOURCE" ]; then
     87 					echo "$option $value" >> /tmp/access.conf.tmp  #writing each option to access.conf
     88 				fi
     89 			}
     90 		fi
     91 	}
     92 
     93 	if [ -f /etc/config/fwknopd ]; then
     94 		config_load fwknopd
     95 		if [ -f /tmp/access.conf.tmp ] ; then
     96 			cat /tmp/access.conf.tmp >> /var/etc/access.conf
     97 			rm /tmp/access.conf.tmp
     98 		fi
     99 	fi
    100 
    101 }