#!/bin/sh . /etc/init.d/globals ip_forwarding() { v=${1:-0} echo ${v} > /proc/sys/net/ipv4/ip_forward } sbin_base=/sbin if [ -x /var/sbin/openvpn ]; then sbin_base=/var/sbin fi case "$1" in start) if [ -e /var/etc/.openvpn ]; then read mode < /var/etc/.openvpn mode=${mode:-client} if [ ! -e /var/etc/openvpn/${mode}.conf ]; then SHOWINFO "/var/etc/openvpn/${mode}.conf not found." exit 1 fi ip_forwarding 1 ${sbin_base}/openvpn \ --config /var/etc/openvpn/${mode}.conf \ --log /tmp/openvpn_${mode}.log \ --daemon \ --script-security 2 \ --up /var/etc/openvpn/up.sh fi ;; stop) killall -TERM openvpn sleep 3 ip_forwarding 0 ;; restart) $0 stop $0 start ;; *) echo "[${BASENAME}] Usage: $0 {start|restart|stop}" ;; esac