Merge branch 'Toastman-RT' into Toastman-RT-N
[tomato.git] / release / src / router / rc / openvpn-updown.sh
blob5822e9ab3f697cb24cead87b4385b75b66487720
1 #!/bin/sh
2 filedir=/etc/openvpn/dns
3 filebase=`echo $filedir/$dev | sed 's/\(tun\|tap\)1/client/;s/\(tun\|tap\)2/server/'`
4 conffile=$filebase\.conf
5 resolvfile=$filebase\.resolv
6 fileexists=
7 if [ ! -d $filedir ]; then mkdir $filedir; fi
8 if [ -f $conffile ]; then rm $conffile; fileexists=1; fi
9 if [ -f $resolvfile ]; then rm $resolvfile; fileexists=1; fi
11 if [ $script_type == 'up' ]
12 then
13 for optionname in `set | grep "^foreign_option_" | sed "s/^\(.*\)=.*$/\1/g"`
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
22 if [ -f $conffile -o -f $resolvfile -o -n "$fileexists" ]; then service dnsmasq restart; fi
23 rmdir $filedir
24 rmdir /etc/openvpn
26 exit 0