From 56fb2569075306b6b1d4c4a31afed83f1b3e650f Mon Sep 17 00:00:00 2001 From: Ross Chadwick Date: Sat, 23 Dec 2017 14:53:28 +0100 Subject: [PATCH 1/4] resolv.conf fix for Ubuntu etc that use a symlink --- nordnm/networkmanager.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/nordnm/networkmanager.py b/nordnm/networkmanager.py index 7f3244e..a4052cd 100644 --- a/nordnm/networkmanager.py +++ b/nordnm/networkmanager.py @@ -137,19 +137,26 @@ def set_dns_resolv(dns_list, active_servers): dns_script = ( '#!/bin/bash\n' 'VPN_INTERFACE="tun0"\n' + 'RESOLV_PATH="/etc/resolv.conf"\n' 'interface="$1"\n\n' 'if [[ "$CONNECTION_ID" =~ ' + active_server_list + ' ]]; then\n' ' case $2 in\n' ' vpn-up)\n' ' if [[ $interface == "$VPN_INTERFACE" ]]; then\n' - ' chattr -i /etc/resolv.conf\n' - ' echo -e "' + resolv_string + '" > /etc/resolv.conf\n' - ' chattr +i /etc/resolv.conf\n' + ' if [ -L "$RESOLV_PATH" ]; then\n' + ' mv "$RESOLV_PATH" "$RESOLV_PATH".tmp' + ' fi' + ' chattr -i "$RESOLV_PATH"\n' + ' echo -e "' + resolv_string + '" > "$RESOLV_PATH"\n' + ' chattr +i "$RESOLV_PATH"\n' ' fi\n' ' ;;\n' ' vpn-down)\n' ' if [[ $interface == "$VPN_INTERFACE" ]]; then\n' - ' chattr -i /etc/resolv.conf\n' + ' chattr -i "$RESOLV_PATH"\n' + ' if [ -L "$RESOLV_PATH" ]; then\n' + ' mv "$RESOLV_PATH".tmp "$RESOLV_PATH"' + ' fi' ' fi\n' ' ;;\n' ' esac\n' From 207a33b90a7238c5199b43fc2f4534ec9af6d20e Mon Sep 17 00:00:00 2001 From: Ross Chadwick Date: Sat, 23 Dec 2017 15:56:10 +0100 Subject: [PATCH 2/4] Small fix and some comments --- nordnm/networkmanager.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nordnm/networkmanager.py b/nordnm/networkmanager.py index a4052cd..a552673 100644 --- a/nordnm/networkmanager.py +++ b/nordnm/networkmanager.py @@ -128,9 +128,9 @@ def get_interfaces(wifi=True, ethernet=True): def set_dns_resolv(dns_list, active_servers): - resolv_string = "# nordnm enforced nameservers\n" + resolv_string = "# nordnm enforced nameservers\\n" for address in dns_list: - resolv_string += "nameserver " + address + '\n' + resolv_string += "nameserver " + address + '\\n' active_server_list = "|".join(map(lambda server: "'" + active_servers[server]['name'] + "'", active_servers)) @@ -142,21 +142,21 @@ def set_dns_resolv(dns_list, active_servers): 'if [[ "$CONNECTION_ID" =~ ' + active_server_list + ' ]]; then\n' ' case $2 in\n' ' vpn-up)\n' - ' if [[ $interface == "$VPN_INTERFACE" ]]; then\n' - ' if [ -L "$RESOLV_PATH" ]; then\n' - ' mv "$RESOLV_PATH" "$RESOLV_PATH".tmp' - ' fi' + ' if [ $interface == "$VPN_INTERFACE" ]; then\n' # Check that the interface matches tun0, which should be the first OpenVPN tunnel interface opened + ' if [ -L "$RESOLV_PATH" ]; then\n' # Check if /etc/resolv.conf is a symlink, if yes, move it to a temporary file + ' mv "$RESOLV_PATH" "$RESOLV_PATH".tmp\n' # Move the symlink to a temp file + ' fi\n' ' chattr -i "$RESOLV_PATH"\n' - ' echo -e "' + resolv_string + '" > "$RESOLV_PATH"\n' + ' printf "' + resolv_string + '" > "$RESOLV_PATH"\n' ' chattr +i "$RESOLV_PATH"\n' ' fi\n' ' ;;\n' ' vpn-down)\n' - ' if [[ $interface == "$VPN_INTERFACE" ]]; then\n' + ' if [ $interface == "$VPN_INTERFACE" ]; then\n' ' chattr -i "$RESOLV_PATH"\n' - ' if [ -L "$RESOLV_PATH" ]; then\n' - ' mv "$RESOLV_PATH".tmp "$RESOLV_PATH"' - ' fi' + ' if [ -f "$RESOLV_PATH".tmp ]; then\n' # If a tmp file exists, move it back to the original filename + ' mv "$RESOLV_PATH".tmp "$RESOLV_PATH"\n' + ' fi\n' ' fi\n' ' ;;\n' ' esac\n' From df26c5674662cdac9dedfb970fdf3aa019d706b7 Mon Sep 17 00:00:00 2001 From: Ross Chadwick Date: Sat, 23 Dec 2017 15:59:45 +0100 Subject: [PATCH 3/4] force mv commands --- nordnm/networkmanager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nordnm/networkmanager.py b/nordnm/networkmanager.py index a552673..e2d4a11 100644 --- a/nordnm/networkmanager.py +++ b/nordnm/networkmanager.py @@ -144,7 +144,7 @@ def set_dns_resolv(dns_list, active_servers): ' vpn-up)\n' ' if [ $interface == "$VPN_INTERFACE" ]; then\n' # Check that the interface matches tun0, which should be the first OpenVPN tunnel interface opened ' if [ -L "$RESOLV_PATH" ]; then\n' # Check if /etc/resolv.conf is a symlink, if yes, move it to a temporary file - ' mv "$RESOLV_PATH" "$RESOLV_PATH".tmp\n' # Move the symlink to a temp file + ' mv -f "$RESOLV_PATH" "$RESOLV_PATH".tmp\n' # Move the symlink to a temp file ' fi\n' ' chattr -i "$RESOLV_PATH"\n' ' printf "' + resolv_string + '" > "$RESOLV_PATH"\n' @@ -155,7 +155,7 @@ def set_dns_resolv(dns_list, active_servers): ' if [ $interface == "$VPN_INTERFACE" ]; then\n' ' chattr -i "$RESOLV_PATH"\n' ' if [ -f "$RESOLV_PATH".tmp ]; then\n' # If a tmp file exists, move it back to the original filename - ' mv "$RESOLV_PATH".tmp "$RESOLV_PATH"\n' + ' mv -f "$RESOLV_PATH".tmp "$RESOLV_PATH"\n' ' fi\n' ' fi\n' ' ;;\n' From 27812b5563c28b472328269e95b3da1ac2358b6e Mon Sep 17 00:00:00 2001 From: Ross Chadwick Date: Sat, 23 Dec 2017 16:03:00 +0100 Subject: [PATCH 4/4] New patch version --- nordnm/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nordnm/__init__.py b/nordnm/__init__.py index 45314bb..1239f2f 100644 --- a/nordnm/__init__.py +++ b/nordnm/__init__.py @@ -1,3 +1,3 @@ __package__ = "nordnm" -__version__ = "0.2.0" +__version__ = "0.2.1" __license__ = "GNU General Public License v3 or later (GPLv3+)"