Browse Source

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

Julien Vaubourg 7 years ago
parent
commit
33aafd1196
1 changed files with 12 additions and 3 deletions
  1. 12 3
      conf/ynh-vpnclient

+ 12 - 3
conf/ynh-vpnclient

@@ -61,7 +61,7 @@ is_serverip6route_set() {
 
 
 is_dns_set() {
 is_dns_set() {
   [ -e /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient ]\
   [ -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() {
 is_openvpn_running() {
@@ -104,9 +104,14 @@ set_serverip6route() {
 }
 }
 
 
 set_dns() {
 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
   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
 EOF
 
 
   bash /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
   bash /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
@@ -177,7 +182,11 @@ unset_serverip6route() {
 }
 }
 
 
 unset_dns() {
 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
   rm -f /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
+  mv "${resolvconf}.ynh" "${resolvconf}"
 }
 }
 
 
 stop_openvpn() {
 stop_openvpn() {