summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
Diffstat (limited to 'etc')
-rw-r--r--etc/anytun/server/config4
-rw-r--r--etc/init.d/anytun126
2 files changed, 105 insertions, 25 deletions
diff --git a/etc/anytun/server/config b/etc/anytun/server/config
index fe5f05b..449568f 100644
--- a/etc/anytun/server/config
+++ b/etc/anytun/server/config
@@ -10,7 +10,7 @@ port 4444
## local unicast(sync) ip address to bind to
# sync-interface <ip-address>
## local unicast(sync) port to bind to
-#sync-port <port>
+#sync-port 1234
## remote hosts to sync with
#sync-hosts <hostname|ip>:<port>[,<hostname|ip>:<port>[...]]
## Device name
@@ -30,6 +30,8 @@ auth-algo sha1
## 1st argument the local address for the tun/tap device
## 2nd argument is either the remote address(tun) or netmask(tap)
#ifconfig <local> <remote|netmask>
+## Controll Host for multi client support
+#control-host 127.0.0.1:4445
### Connection Parameters (for clients without config server)
## remote host
diff --git a/etc/init.d/anytun b/etc/init.d/anytun
index f8ac738..90d7670 100644
--- a/etc/init.d/anytun
+++ b/etc/init.d/anytun
@@ -12,11 +12,14 @@
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/anytun
+ANYTUNCONFIG=/usr/bin/anytun-config
+CONTROLDAEMON=/usr/bin/anytun-controld
CHROOTDIR='/var/run/anytun'
DAEMONOPTS="--chroot --username nobody --chroot-dir $CHROOTDIR"
NAME=anytun
DESC=anytun
CONFIG_DIR=/etc/anytun
+VARCONFIG_DIR=/var/run/anytun-controld
test -x $DAEMON || exit 0
@@ -28,19 +31,46 @@ fi
start_vpn () {
STATUS=OK
if [ -f $CONFIG_DIR/$NAME/config ] ; then
+ POSTUP=''
+ test -f $CONFIG_DIR/$NAME/post-up.sh && POSTUP="-x $CONFIG_DIR/$NAME/post-up.sh"
DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e '\w' | sed 's/^/ --/' | xargs echo`
- $DAEMON --write-pid /var/run/anytun.$NAME.pid \
- $DAEMONOPTS $DAEMONARG > /dev/null || STATUS="FAILED"
+ $DAEMON --write-pid /var/run/anytun.$NAME.pid $POSTUP \
+ $DAEMONOPTS $DAEMONARG || STATUS="FAILED"
else
STATUS="no config found"
fi
+ start_configd
echo -n "($STATUS)"
}
stop_vpn () {
kill `cat $PIDFILE` || true
rm $PIDFILE
+ stop_configd
}
+start_configd () {
+ if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
+ test -d $VARCONFIG_DIR || mkdir $VARCONFIG_DIR
+ chmod 700 $VARCONFIG_DIR
+ rm -f $VARCONFIG_DIR/$NAME 2>/dev/null
+ for CLIENTNAME in `ls $CONFIG_DIR/$NAME/conf.d`; do
+ echo -n " ($CLIENTNAME)"
+ DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/conf.d/$CLIENTNAME | grep -e '\w' | sed 's/^/ --/' | xargs echo`
+ $ANYTUNCONFIG $DAEMONARG >> $VARCONFIG_DIR/$NAME
+ done
+ CONTROLHOST=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e 'control-host' | sed 's/^/ --/'`
+ $CONTROLDAEMON -f $VARCONFIG_DIR/$NAME $CONTROLHOST \
+ --write-pid $VARCONFIG_DIR/$NAME.pid
+ rm -f $VARCONFIG_DIR/$NAME
+ fi
+}
+stop_configd () {
+ if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
+ echo -n " ($NAME)"
+ kill `cat $VARCONFIG_DIR/$NAME.pid` || true
+ rm $VARCONFIG_DIR/$NAME.pid
+ fi
+}
set -e
case "$1" in
@@ -59,8 +89,11 @@ case "$1" in
fi
else
while shift ; do
- NAME=$1
- start_vpn
+ if [ ! -z $1 ] ; then
+ NAME=$1
+ echo -n "$NAME"
+ start_vpn
+ fi
done
fi
echo "."
@@ -71,8 +104,8 @@ case "$1" in
for PIDFILE in `ls /var/run/anytun.*.pid 2> /dev/null`; do
NAME=`echo $PIDFILE | cut -c17-`
NAME=${NAME%%.pid}
- stop_vpn
echo -n " $NAME"
+ stop_vpn
done
else
while shift ; do
@@ -81,8 +114,8 @@ case "$1" in
PIDFILE=`ls /var/run/anytun.$1.pid 2> /dev/null`
NAME=`echo $PIDFILE | cut -c17-`
NAME=${NAME%%.pid}
- stop_vpn
echo -n " $NAME"
+ stop_vpn
else
echo -n " (failure: No such tunnel is running: $1)"
fi
@@ -90,19 +123,67 @@ case "$1" in
fi
echo .
;;
- #reload)
- #
- # If the daemon can reload its config files on the fly
- # for example by sending it SIGHUP, do it here.
- #
- # If the daemon responds to changes in its config file
- # directly anyway, make this a do-nothing entry.
- #
- # echo "Reloading $DESC configuration files."
- # start-stop-daemon --stop --signal 1 --quiet --pidfile \
- # /var/run/$NAME.pid --exec $DAEMON
- #;;
+ reload)
+ if test -z "$2" ; then
+ for PIDFILE in `ls /var/run/anytun.*.pid 2> /dev/null`; do
+ NAME=`echo $PIDFILE | cut -c17-`
+ NAME=${NAME%%.pid}
+ if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
+ stop_vpn
+ start_vpn
+ else
+ stop_config
+ start_config
+ fi
+ echo -n " $NAME"
+ done
+ else
+ while shift ; do
+ [ -z "$1" ] && break
+ if test -e /var/run/anytun.$1.pid ; then
+ PIDFILE=`ls /var/run/anytun.$1.pid 2> /dev/null`
+ NAME=`echo $PIDFILE | cut -c17-`
+ NAME=${NAME%%.pid}
+ echo -n " $NAME"
+ if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
+ stop_vpn
+ start_vpn
+ else
+ stop_config
+ start_config
+ fi
+ else
+ echo -n " (failure: No such tunnel is running: $1)"
+ fi
+ done
+ fi
+ ;;
force-reload)
+ echo -n "Restarting $DESC: "
+ if test -z "$2" ; then
+ for PIDFILE in `ls /var/run/anytun.*.pid 2> /dev/null`; do
+ NAME=`echo $PIDFILE | cut -c17-`
+ NAME=${NAME%%.pid}
+ echo -n " $NAME"
+ stop_vpn
+ start_vpn
+ done
+ else
+ while shift ; do
+ [ -z "$1" ] && break
+ if test -e /var/run/anytun.$1.pid ; then
+ PIDFILE=`ls /var/run/anytun.$1.pid 2> /dev/null`
+ NAME=`echo $PIDFILE | cut -c17-`
+ NAME=${NAME%%.pid}
+ echo -n " $NAME"
+ stop_vpn
+ start_vpn
+ else
+ echo -n " (failure: No such tunnel is running: $1)"
+ fi
+ done
+ fi
+ echo .
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
@@ -115,13 +196,10 @@ case "$1" in
|| exit 0
;;
restart)
- echo -n "Restarting $DESC: "
- start-stop-daemon --stop --quiet --pidfile \
- /var/run/$NAME.pid --exec $DAEMON
+ shift
+ /etc/init.d/anytun stop
sleep 1
- start-stop-daemon --start --quiet --pidfile \
- /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
- echo "$NAME."
+ /etc/init.d/anytun start
;;
*)
N=/etc/init.d/$NAME