Skip to content

Commit

Permalink
if vpn config not found suggest to 'openpyn --update' #57
Browse files Browse the repository at this point in the history
  • Loading branch information
jotyGill committed Sep 25, 2017
1 parent 3dfbdc4 commit c260ac3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 41 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ sudo apt install openvpn python-gobject unzip wget
1. For Ubuntu / Kali / Debian / based OS's with Python=>3.4
```bash
sudo apt install python3-colorama python3-requests python3-setuptools #dependencies
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.3/python3-openpyn_1.7.3-1_all.deb
sudo dpkg -i python3-openpyn_1.7.3-1_all.deb
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.4/python3-openpyn_1.7.4-1_all.deb
sudo dpkg -i python3-openpyn_1.7.4-1_all.deb
```
2. For Fedora 26, all dependencies should be auto installed.
```bash
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.3/openpyn-1.7.3-1.noarch.rpm
sudo dnf install ./openpyn-1.7.3-1.noarch.rpm
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.4/openpyn-1.7.4-1.noarch.rpm
sudo dnf install ./openpyn-1.7.4-1.noarch.rpm
```
3. Install openpyn with pip3. (Python=>3.4, Don't use on Debian, causes issues):
``` bash
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ sudo apt install openvpn python-gobject unzip wget
1. For Ubuntu / Kali / Debian / based OS's with Python=>3.4
```bash
sudo apt install python3-colorama python3-requests python3-setuptools #dependencies
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.3/python3-openpyn_1.7.3-1_all.deb
sudo dpkg -i python3-openpyn_1.7.3-1_all.deb
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.4/python3-openpyn_1.7.4-1_all.deb
sudo dpkg -i python3-openpyn_1.7.4-1_all.deb
```
2. For Fedora 26, all dependencies should be auto installed.
```bash
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.3/openpyn-1.7.3-1.noarch.rpm
sudo dnf install ./openpyn-1.7.3-1.noarch.rpm
wget https://github.com/jotyGill/openpyn-nordvpn/releases/download/1.7.4/openpyn-1.7.4-1.noarch.rpm
sudo dnf install ./openpyn-1.7.4-1.noarch.rpm
```
3. Install openpyn with pip3. (Python=>3.4, Don't use on Debian, causes issues):
``` bash
Expand Down
2 changes: 1 addition & 1 deletion openpyn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.7.3"
__version__ = "1.7.4"
__license__ = "GNU General Public License v3 or later (GPLv3+)"
77 changes: 45 additions & 32 deletions openpyn/openpyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def run(
firewall.internally_allow_ports(network_interfaces, internally_allowed)
connection = connect(chosen_servers[0], port, daemon, test, skip_dns_patch)
else:
while True: # keep trying to connect
for tries in range(5): # keep trying to connect
# connect to chosen_servers, if one fails go to next
for aserver in chosen_servers:
# if "-f" used appy Firewall rules
Expand Down Expand Up @@ -588,33 +588,41 @@ def connect(server, port, daemon, test, skip_dns_patch, server_provider="nordvpn
if resolvconf_exists is True and skip_dns_patch is False: # Debian Based OS + do DNS patching
# tunnel dns throught vpn by changing /etc/resolv.conf using
# "update-resolv-conf.sh" to change the dns servers to NordVPN's.
if daemon:
subprocess.Popen(
["sudo", "openvpn", "--redirect-gateway", "--auth-retry",
"nointeract", "--config", vpn_config_file, "--auth-user-pass",
"/usr/share/openpyn/credentials", "--script-security", "2",
"--up", "/usr/share/openpyn/update-resolv-conf.sh",
"--down", "/usr/share/openpyn/update-resolv-conf.sh", "--daemon",
"--management", "127.0.0.1", "7015", "--management-up-down"])
print("Started 'openvpn' in" + Fore.GREEN + "--daemon" + Fore.BLUE + "mode")
else:
try:
try:
if daemon:
subprocess.Popen(
["sudo", "openvpn", "--redirect-gateway", "--auth-retry",
"nointeract", "--config", vpn_config_file, "--auth-user-pass",
"/usr/share/openpyn/credentials", "--script-security", "2",
"--up", "/usr/share/openpyn/update-resolv-conf.sh",
"--down", "/usr/share/openpyn/update-resolv-conf.sh", "--daemon",
"--management", "127.0.0.1", "7015", "--management-up-down"])
print("Started 'openvpn' in" + Fore.GREEN + "--daemon" + Fore.BLUE + "mode")
print(Style.RESET_ALL)
else:
print("Your OS'" + Fore.GREEN + detected_os + Fore.BLUE +
"' Does have '/sbin/resolvconf'",
"using it to update DNS Resolver Entries")
print(Style.RESET_ALL)
subprocess.call(
subprocess.check_output(
"sudo openvpn --redirect-gateway --auth-retry nointeract" +
" --config " + vpn_config_file + " --auth-user-pass \
/usr/share/openpyn/credentials --script-security 2 --up \
/usr/share/openpyn/update-resolv-conf.sh --down \
/usr/share/openpyn/update-resolv-conf.sh \
--management 127.0.0.1 7015 --management-up-down", shell=True)
except (KeyboardInterrupt) as err:
print('\nShutting down safely, please wait until process exits\n')
sys.exit()
except PermissionError: # needed cause complains when killing sudo process

except subprocess.CalledProcessError as openvpn_err:
# print(openvpn_err.output)
if 'Error opening configuration file' in str(openvpn_err.output):
print("Error opening configuration file", vpn_config_file,
"Make Sure it exists, run 'openpyn --update'")
sys.exit()
except (KeyboardInterrupt) as err:
print('\nShutting down safely, please wait until process exits\n')
sys.exit()
except PermissionError: # needed cause complains when killing sudo process
sys.exit()

else: # If not Debian Based or skip_dns_patch
# if skip_dns_patch, do not touch etc/resolv.conf
Expand All @@ -630,26 +638,31 @@ def connect(server, port, daemon, test, skip_dns_patch, server_provider="nordvpn
print(Fore.RED + "Not Modifying /etc/resolv.conf, DNS traffic",
"likely won't go through the encrypted tunnel")
print(Style.RESET_ALL)

if daemon:
subprocess.Popen(
["sudo", "openvpn", "--redirect-gateway", "--auth-retry",
"nointeract", "--config", vpn_config_file,
"--auth-user-pass", "/usr/share/openpyn/credentials", "--daemon",
"--management", "127.0.0.1", "7015", "--management-up-down"])
print("Started 'openvpn' in --daemon mode")
else:
try:
subprocess.call((
try:
if daemon:
subprocess.Popen(
["sudo", "openvpn", "--redirect-gateway", "--auth-retry",
"nointeract", "--config", vpn_config_file,
"--auth-user-pass", "/usr/share/openpyn/credentials", "--daemon",
"--management", "127.0.0.1", "7015", "--management-up-down"])
print("Started 'openvpn' in --daemon mode")
else:
subprocess.check_output((
"sudo openvpn --redirect-gateway --auth-retry nointeract " +
"--config " + vpn_config_file + " --auth-user-pass " +
"/usr/share/openpyn/credentials --management 127.0.0.1 7015 " +
"--management-up-down").split())
except (KeyboardInterrupt) as err:
print('\nShutting down safely, please wait until process exits\n')
sys.exit()
except PermissionError: # needed cause complains when killing sudo process
except subprocess.CalledProcessError as openvpn_err:
# print(openvpn_err.output)
if 'Error opening configuration file' in str(openvpn_err.output):
print("Error opening configuration file", vpn_config_file,
"Make Sure it exists, run 'openpyn --update'")
sys.exit()
except (KeyboardInterrupt) as err:
print('\nShutting down safely, please wait until process exits\n')
sys.exit()
except PermissionError: # needed cause complains when killing sudo process
sys.exit()


if __name__ == '__main__':
Expand Down

0 comments on commit c260ac3

Please sign in to comment.