summaryrefslogtreecommitdiff
path: root/pkg/linux/update-resolv-conf
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-05-16 15:50:41 -0300
committerTomás Touceda <chiiph@leap.se>2014-05-16 15:50:41 -0300
commit2bb3e9200adf7fcc1781ba7ff119f6dd6d09f7dc (patch)
tree400ac91ea22e121344b123ea6a0ac1ba6769120d /pkg/linux/update-resolv-conf
parentf995ff502089bcb7ef6a0fe71c692ee7274d45cb (diff)
parentdfbe8c4f0158366e91ea5118e5aa68c07d28ddbf (diff)
Merge remote-tracking branch 'kali/linux-firewall-root-py-2' into develop
Diffstat (limited to 'pkg/linux/update-resolv-conf')
-rwxr-xr-xpkg/linux/update-resolv-conf58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkg/linux/update-resolv-conf b/pkg/linux/update-resolv-conf
new file mode 100755
index 00000000..76c69413
--- /dev/null
+++ b/pkg/linux/update-resolv-conf
@@ -0,0 +1,58 @@
+#!/bin/bash
+#
+# Parses DHCP options from openvpn to update resolv.conf
+# To use set as 'up' and 'down' script in your openvpn *.conf:
+# up /etc/leap/update-resolv-conf
+# down /etc/leap/update-resolv-conf
+#
+# Used snippets of resolvconf script by Thomas Hood and Chris Hanson.
+# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
+#
+# Example envs set from openvpn:
+#
+# foreign_option_1='dhcp-option DNS 193.43.27.132'
+# foreign_option_2='dhcp-option DNS 193.43.27.133'
+# foreign_option_3='dhcp-option DOMAIN be.bnc.ch'
+#
+
+[ -x /sbin/resolvconf ] || exit 0
+[ "$script_type" ] || exit 0
+[ "$dev" ] || exit 0
+
+split_into_parts()
+{
+ part1="$1"
+ part2="$2"
+ part3="$3"
+}
+
+case "$script_type" in
+ up)
+ NMSRVRS=""
+ SRCHS=""
+ for optionvarname in ${!foreign_option_*} ; do
+ option="${!optionvarname}"
+ echo "$option"
+ split_into_parts $option
+ if [ "$part1" = "dhcp-option" ] ; then
+ if [ "$part2" = "DNS" ] ; then
+ NMSRVRS="${NMSRVRS:+$NMSRVRS }$part3"
+ elif [ "$part2" = "DOMAIN" ] ; then
+ SRCHS="${SRCHS:+$SRCHS }$part3"
+ fi
+ fi
+ done
+ R=""
+ [ "$SRCHS" ] && R="search $SRCHS
+"
+ for NS in $NMSRVRS ; do
+ R="${R}nameserver $NS
+"
+ done
+ echo -n "$R" | /sbin/resolvconf -a "${dev}.openvpn"
+ ;;
+ down)
+ /sbin/resolvconf -d "${dev}.openvpn"
+ ;;
+esac
+