#!/bin/sh scriptname=$0 CONF_ENABLED=OPENVPN_ENABLED [ -z "$OPENVPN_ENABLED" ] && OPENVPN_ENABLED=no DAEMON=${scriptname##*/rc.} daemon="$(echo $DAEMON | tr [A-Z-] [a-z_])" if [ $DAEMON == "openvpn" ]; then TITLE=OpenVPN keypath=/tmp/flash/openvpn/ else keypath=/tmp/flash/openvpn/${daemon}/ TITLE=${2-$DAEMON} fi . /etc/init.d/modlibrc mypidof() { ps -w | sed -n "/\/m[o]d\/etc\/${1}.conf/ s/^[ ]*\([0-9]*\)[ ].*/\1/ p" } if [ ! -e /var/tmp/.openvpnfirstrun ]; then touch /var/tmp/.openvpnfirstrun modlib_add_user_and_group openvpn if [ -e /tmp/flash/openvpn/configs ]; then for config in $(cat /tmp/flash/openvpn/configs); do /mod/etc/default.openvpn/generate_virtual_pkg $config done fi fi [ -x /mod/sbin/$DAEMON ] || ln -s /usr/sbin/openvpn /mod/sbin/$DAEMON config() { modlib_config } start() { modlib_startdaemon ${DAEMON} --config /mod/etc/${DAEMON}.conf --writepid /var/run/${DAEMON}.pid --daemon } stop() { echo -n "Stopping ${DAEMON} ... " PID=$(mypidof $DAEMON) if [ -z "$PID" ]; then echo "not running." return 1 fi kill $PID > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi rm -f /mod/etc/${daemon}.conf rm -f /var/run/${daemon}.pid } case $1 in ""|load) modreg cgi "${DAEMON}" "${TITLE-$DAEMON}" modreg daemon ${DAEMON} modreg file ${DAEMON} 'box_crt' 'Box Cert' 0 "box_crt" modreg file ${DAEMON} 'box_key' 'Private Key' 0 "box_key" modreg file ${DAEMON} 'ca_crt' 'CA Cert' 0 "ca_crt" modreg file ${DAEMON} 'crl_pem' 'CRL' 0 "crl_pem" modreg file ${DAEMON} 'dh_pem' 'DH Param' 0 "dh_pem" modreg file ${DAEMON} 'static_key' 'Static Key' 0 "static_key" modreg file ${DAEMON} 'script1' 'Script 1' 0 "script1" modreg file ${DAEMON} 'script2' 'Script 2' 0 "script2" modreg file ${DAEMON} 'script3' 'Script 3' 0 "script3" modlib_start "${OPENVPN_ENABLED}" ;; unload) stop modunreg file ${DAEMON} modunreg daemon ${DAEMON} modunreg cgi ${DAEMON} ;; start) modlib_start ;; stop) modlib_stop ;; restart) modlib_restart ;; reload) if [ -r "/var/run/${daemon}.pid" ]; then kill -HUP $(cat /var/run/${daemon}.pid) fi ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|reload|status] [GUI-Title]" 1>&2 exit 1 ;; esac exit 0