Parcourir la source

Set dns in resolv.dnsmasq.conf if available and restore the original file when the service is stopped

Julien Vaubourg il y a 7 ans
Parent
commit
33aafd1196
1 fichiers modifiés avec 12 ajouts et 3 suppressions
  1. 12 3
      conf/ynh-vpnclient

+ 12 - 3
conf/ynh-vpnclient

@@ -61,7 +61,7 @@ is_serverip6route_set() {
 
 is_dns_set() {
   [ -e /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient ]\
-  && grep -q ${ynh_dns0} /etc/resolv.conf
+  && ( grep -q ${ynh_dns0} /etc/resolv.conf || grep -q ${ynh_dns0} /etc/resolv.dnsmasq.conf )
 }
 
 is_openvpn_running() {
@@ -104,9 +104,14 @@ set_serverip6route() {
 }
 
 set_dns() {
+  resolvconf=/etc/resolv.conf
+  [ -e /etc/resolv.dnsmasq.conf ] && resolvconf=/etc/resolv.dnsmasq.conf
+
+  cp -fa "${resolvconf}" "${resolvconf}.ynh"
+
   cat << EOF > /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
-echo nameserver ${ynh_dns0} > /etc/resolv.conf
-echo nameserver ${ynh_dns1} >> /etc/resolv.conf
+echo nameserver ${ynh_dns0} > ${resolvconf}
+echo nameserver ${ynh_dns1} >> ${resolvconf}
 EOF
 
   bash /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
@@ -177,7 +182,11 @@ unset_serverip6route() {
 }
 
 unset_dns() {
+  resolvconf=/etc/resolv.conf
+  [ -e /etc/resolv.dnsmasq.conf ] && resolvconf=/etc/resolv.dnsmasq.conf
+
   rm -f /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
+  mv "${resolvconf}.ynh" "${resolvconf}"
 }
 
 stop_openvpn() {