Skip to content

Commit

Permalink
fixed auto-connect bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vfosterm committed Feb 25, 2019
1 parent f574ca4 commit 63145b1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions nord_nm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self):
self.password = None
self.sudo_password = None
self.connection_name = None
self.connected_server = None
self.domain_list = []
self.server_info_list = []
self.login_ui()
Expand Down Expand Up @@ -534,6 +535,7 @@ def get_active_vpn(self):
if self.server_info_list: # vpn connected successfully
for server in self.server_info_list:
if server_name == server.name:
self.connected_server = server.name
return True
elif not self.server_info_list: # existing Nordvpn connection found
self.connect_btn.hide()
Expand All @@ -557,12 +559,16 @@ def get_active_vpn(self):
self.server_list.setCurrentItem(server_list_item[0])
self.server_list.setFocus()
self.connection_name = connection_name
self.connected_server = server.name
return False
else:
self.statusbar.showMessage("Warning! Unknown VPN connection found", 2000)
self.repaint()
return False

except subprocess.CalledProcessError:
self.statusbar.showMessage("ERROR: Network Manager query error", 2000)
self.repaint()

def randomize_mac(self):
try:
Expand Down Expand Up @@ -681,8 +687,8 @@ def get_interfaces(self):
self.statusbar.showMessage("ERROR Fetching interfaces")

def set_auto_connect(self):
self.config.read(self.conf_path)
interfaces = self.get_interfaces()

if interfaces:
interface_string = '|'.join(interfaces)
script =(
Expand Down Expand Up @@ -710,6 +716,8 @@ def set_auto_connect(self):
p6 = subprocess.Popen(['sudo', '-S', 'chmod', '744', self.network_manager_path + 'auto_connect'], stdin=p5.stdout, stdout=subprocess.PIPE)
p5.stdout.close()
p6.stdout.close()
self.config['SETTINGS']['auto_connect'] = 'True'
self.write_conf()
except Exception as ex:
print(ex)

Expand Down Expand Up @@ -742,7 +750,12 @@ def disable_auto_connect(self):
except Exception as ex:
print(ex)

elif self.auto_connect_box.isChecked() and self.get_active_vpn:
elif self.auto_connect_box.isChecked() and self.get_active_vpn() and self.sudo_password:
self.set_auto_connect()

elif self.auto_connect_box.isChecked() and self.get_active_vpn() and not self.sudo_password:
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.exec_()
self.set_auto_connect()

def set_kill_switch(self):
Expand Down Expand Up @@ -861,12 +874,9 @@ def connect(self):
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.exec_()
self.set_auto_connect()
self.config['SETTINGS']['auto_connect'] = 'True'
self.write_conf()

elif self.auto_connect_box.isChecked() and self.sudo_password: # sudo password exists in memory
self.set_auto_connect()
self.config['SETTINGS']['auto_connect'] = 'True'
self.write_conf()

self.check_connection_validity()
self.get_ovpn()
Expand Down

0 comments on commit 63145b1

Please sign in to comment.