1#!/bin/sh
2filedir=/etc/openvpn/dns
3filebase=`echo $filedir/$dev | sed 's/\(tun\|tap\)1/client/;s/\(tun\|tap\)2/server/'`
4conffile=$filebase\.conf
5resolvfile=$filebase\.resolv
6fileexists=
7if [ ! -d $filedir ]; then mkdir $filedir; fi
8if [ -f $conffile ]; then rm $conffile; fileexists=1; fi
9if [ -f $resolvfile ]; then rm $resolvfile; fileexists=1; fi
10
11if [ $script_type == 'up' ]
12then
13	for optionname in `set | grep "^foreign_option_" | sed "s/^\(.*\)=.*$/\1/g"`
14	do
15		option=`eval "echo \\$$optionname"`
16		if echo $option | grep "dhcp-option WINS "; then echo $option | sed "s/ WINS /=44,/" >> $conffile; fi
17		if echo $option | grep "dhcp-option DNS"; then echo $option | sed "s/dhcp-option DNS/nameserver/" >> $resolvfile; fi
18		if echo $option | grep "dhcp-option DOMAIN"; then echo $option | sed "s/dhcp-option DOMAIN/search/" >> $resolvfile; fi
19	done
20fi
21
22if [ -f $conffile -o -f $resolvfile -o -n "$fileexists" ]; then service updateresolv; fi
23rmdir $filedir
24rmdir /etc/openvpn
25
26if [ -f /jffs/scripts/openvpn-event ]
27then
28	sh /jffs/scripts/openvpn-event $*
29fi
30exit 0
31