summaryrefslogtreecommitdiff
path: root/openwrt/kamikaze/uanytun/files
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-05 19:45:19 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-05 19:45:19 +0000
commit839dd9bb09d93e2f46b9fd51a7f0cd251cf32bd5 (patch)
treeb56b5b1b5ff1619b7a9efe90c846aa82a4eec0bc /openwrt/kamikaze/uanytun/files
parentmoved uanytun-sslcrypt kamikaze package to default (uanytun) (diff)
finished kamikaze initscript
updated kamikaze package
Diffstat (limited to 'openwrt/kamikaze/uanytun/files')
-rw-r--r--openwrt/kamikaze/uanytun/files/uanytun.config1
-rwxr-xr-xopenwrt/kamikaze/uanytun/files/uanytun.init66
2 files changed, 49 insertions, 18 deletions
diff --git a/openwrt/kamikaze/uanytun/files/uanytun.config b/openwrt/kamikaze/uanytun/files/uanytun.config
index e71bb9d..9cfe579 100644
--- a/openwrt/kamikaze/uanytun/files/uanytun.config
+++ b/openwrt/kamikaze/uanytun/files/uanytun.config
@@ -19,6 +19,7 @@ config "client1"
# option dev 'anytun0'
option type 'tun'
option ifconfig '192.168.123.1/24'
+# option post-up-script '/etc/uanytun/client1-post-up.sh'
option remote_host 'example.com'
option remote_port '4444'
diff --git a/openwrt/kamikaze/uanytun/files/uanytun.init b/openwrt/kamikaze/uanytun/files/uanytun.init
index 27296ca..9c1a928 100755
--- a/openwrt/kamikaze/uanytun/files/uanytun.init
+++ b/openwrt/kamikaze/uanytun/files/uanytun.init
@@ -2,15 +2,10 @@
START=50
BIN=uanytun
+DAEMON=/usr/sbin/$BIN
DESC=uanytun
RUN_D=/var/run
-uanytun() {
- local name
- name=${2%%.pid}
- name=${name##/var/run/uanytun.}
- echo "$name" > $2
-}
option_cb() {
local varname="$1"
@@ -21,19 +16,28 @@ option_cb() {
fi
}
+foreach_config_forced() {
+ foreach_config $1 "forced"
+}
+
foreach_config() {
local cfg="$1"
local name
local option
local value
- local DAEMONARGS=""
+ local args=""
+ local forced=0
+
+ if [ -n "$2" ] && [ "x$2" == "xforced" ]; then
+ forced=1
+ fi
config_get name "$cfg" TYPE
for option in $CONFIG_OPTIONS
do
config_get value "$cfg" "$option"
if [ "x$option" == "xdisabled" ]; then
- if [ $value -eq 1 ]; then
+ if [ $forced -eq 0 ] && [ $value -eq 1 ]; then
echo -n " $name(disabled)"
return
fi
@@ -42,19 +46,40 @@ foreach_config() {
option=`echo $option | tr '_' '-'`
if [ -n "$value" ]; then
- DAEMONARGS="$DAEMONARGS --$option $value"
+ args="$args --$option $value"
fi
done
echo -n " $name"
local status="OK"
- $BIN --write-pid "$RUN_D/$BIN.$name.pid" $DAEMONARGS || status="failed"
+ $DAEMON --write-pid "$RUN_D/$BIN.$name.pid" $args || status="failed"
+ echo -n "($status)"
+}
+
+stop_vpn() {
+ local name=$1
+ local pidfile=$RUN_D/$BIN.$name.pid
+ echo -n " $name"
+ local status="OK"
+ if [ ! -f "$pidfile" ]; then
+ status="tunnel not active"
+ else
+ kill `cat $pidfile` > /dev/null 2>&1 || status="failed"
+ rm -f $pidfile
+ fi
echo -n "($status)"
}
start() {
echo -n "Starting $DESC:"
config_load uanytun
- config_foreach foreach_config ""
+ if [ $# -gt 0 ]; then
+ while [ $# -gt 0 ]; do
+ config_foreach foreach_config_forced "$1"
+ shift
+ done
+ else
+ config_foreach foreach_config ""
+ fi
echo "."
}
@@ -63,12 +88,17 @@ stop() {
local name
local pidfile
- for pidfile in `ls $RUN_D/$BIN.*.pid 2> /dev/null`; do
- name=${pidfile%%.pid}
- name=${name##$RUN_D/$BIN.}
- echo -n " $name"
- kill `cat $pidfile` || true
- rm -f $pidfile
- done
+ if [ $# -gt 0 ]; then
+ while [ $# -gt 0 ]; do
+ stop_vpn $1
+ shift
+ done
+ else
+ for pidfile in `ls $RUN_D/$BIN.*.pid 2> /dev/null`; do
+ name=${pidfile%%.pid}
+ name=${name##$RUN_D/$BIN.}
+ stop_vpn $name
+ done
+ fi
echo "."
}