#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib DAEMON=vpnc case "$1" in ""|start|restart) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg ;; esac start() { ( if [ -x "/tmp/flash/${DAEMON}_conf" ]; then /tmp/flash/${DAEMON}_conf else /mod/etc/default.$DAEMON/${DAEMON}_conf fi if [ -r "/tmp/flash/${DAEMON}.extra" ]; then cat /tmp/flash/${DAEMON}.extra fi ) > /mod/etc/$DAEMON.conf if [ ! -r "/mod/etc/$DAEMON.conf" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi echo -n 'Starting vpnc...' # find remote network for tunneling NETWORK="$(grep network /var/mod/etc/vpnc.conf | sed -e 's/#network //g')" MASK="$(grep mask /var/mod/etc/vpnc.conf | sed -e 's/#mask //g')" if [ $NETWORK != "0.0.0.0" ]; then sed -e 's/#set -x/INTERNAL_IP4_DNS=\nCISCO_SPLIT_INC=1\nCISCO_SPLIT_INC_0_ADDR='$NETWORK'\nCISCO_SPLIT_INC_0_MASK='$MASK'\nCISCO_SPLIT_INC_0_MASKLEN=22\nCISCO_SPLIT_INC_0_PROTOCOL=0\nCISCO_SPLIT_INC_0_SPORT=0\nCISCO_SPLIT_INC_0_DPORT=0\n\n#set -x\n/g' /etc/default.vpnc/vpnc-script > /var/tmp/vpnc-script chmod +x /var/tmp/vpnc-script $DAEMON --script /var/tmp/vpnc-script /mod/etc/$DAEMON.conf else $DAEMON --script /etc/default.vpnc/vpnc-script /mod/etc/$DAEMON.conf fi exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop () { echo -n 'Stopping vpnc...' exitval=0 rm -f /mod/etc/$DAEMON.conf if [ -n "$(pidof "$DAEMON")" ]; then #daemon is running at the moment killall -15 $DAEMON > /dev/null 2>&1 exitval=$? fi if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) modreg cgi 'vpnc' 'Vpnc' if [ "$VPNC_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi start ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ -z "$(pidof "$DAEMON")" ]; then echo 'stopped' else echo 'running' fi ;; load) ;; unload) stop modunreg cgi 'vpnc' ;; *) echo "Usage: $0 [start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0