Skip to content

Commit

Permalink
fixed numerous bugs relating to the sudo dialog and Network manager s…
Browse files Browse the repository at this point in the history
…cripts
  • Loading branch information
vfosterm committed Jun 9, 2019
1 parent 360d78a commit 0de190d
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions nord_nm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,7 @@ def randomize_mac(self):
try:
self.statusbar.showMessage("Randomizing MAC Address", 2000)
self.repaint()
output = subprocess.run(['nmcli', '--mode', 'tabular', '--terse', '--fields', 'TYPE,UUID', 'connection', 'show', '--active'],
stdout=subprocess.PIPE)
output = subprocess.run(['nmcli', '--mode', 'tabular', '--terse', '--fields', 'TYPE,UUID', 'connection', 'show', '--active'], stdout=subprocess.PIPE)
output.check_returncode()
lines = output.stdout.decode('utf-8').split('\n')

Expand Down Expand Up @@ -644,10 +643,14 @@ def get_sudo(self):
resolution = QtWidgets.QDesktopWidget().screenGeometry()
sudo_dialog.move(int((resolution.width() / 2) - (sudo_dialog.frameSize().width() / 2)), int((resolution.height() / 2) - (sudo_dialog.frameSize().height() / 2)))
sudo_dialog.accept_box.accepted.connect(self.check_sudo)
sudo_dialog.accept_box.rejected.connect(sudo_dialog.close)
sudo_dialog.accept_box.rejected.connect(self.close_sudo_dialog)
QtCore.QMetaObject.connectSlotsByName(sudo_dialog)
return sudo_dialog

def close_sudo_dialog(self): # added to clear sudo password when cancel is pressed
self.sudo_password = None
self.sudo_dialog.close()

def check_sudo(self):
self.sudo_password = self.sudo_dialog.sudo_password.text()
try:
Expand Down Expand Up @@ -731,6 +734,8 @@ def disable_auto_connect(self):
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.text_label.setText("<html><head/><body><p>VPN Network Manager requires <span style=\" font-weight:600;\">sudo</span> permissions in order to remove the auto-connect script from the Network Manager directory. Please input the <span style=\" font-weight:600;\">sudo</span> Password or run the program with elevated priveledges.</p></body></html>")
self.sudo_dialog.exec_()
if not self.sudo_password: # dialog was canceled
return False
try:
p1 = subprocess.Popen(['echo', self.sudo_password], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p2 = subprocess.Popen(['sudo', '-S', 'rm', self.network_manager_path + 'auto_connect'], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down Expand Up @@ -759,7 +764,11 @@ def disable_auto_connect(self):
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()
if self.sudo_password:
self.set_auto_connect()
else:
self.auto_connect_box.setChecked(False)
return False

def set_kill_switch(self):

Expand Down Expand Up @@ -794,6 +803,8 @@ def set_kill_switch(self):
p6 = subprocess.Popen(['sudo', '-S', 'chmod', '744', self.network_manager_path + 'kill_switch'], stdin=p5.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p5.stdout.close()
p6.stdout.close()
self.config['SETTINGS']['kill_switch'] = 'True'
self.write_conf()

self.statusbar.showMessage('Kill switch activated', 2000)
self.repaint()
Expand All @@ -805,6 +816,10 @@ def disable_kill_switch(self):
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.text_label.setText("<html><head/><body><p>VPN Network Manager requires <span style=\" font-weight:600;\">sudo</span> permissions in order to remove the kill switch script from the Network Manager directory. Please input the <span style=\" font-weight:600;\">sudo</span> Password or run the program with elevated priveledges.</p></body></html>")
self.sudo_dialog.exec_()

if not self.sudo_password: # dialog was canceled
self.killswitch_btn.setChecked(False)
return False
try:
p1 = subprocess.Popen(['echo', self.sudo_password], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
p2 = subprocess.Popen(['sudo', '-S', 'rm', self.network_manager_path + 'kill_switch'], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down Expand Up @@ -835,6 +850,19 @@ def disable_kill_switch(self):
self.statusbar.showMessage('ERROR disabling kill switch', 2000)
self.repaint()

elif self.killswitch_btn.isChecked() and self.get_active_vpn() and self.sudo_password:
self.set_kill_switch()

elif self.killswitch_btn.isChecked() and self.get_active_vpn() and not self.sudo_password:
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.text_label.setText("<html><head/><body><p>VPN Network Manager requires <span style=\" font-weight:600;\">sudo</span> permissions in order to move the kill switch script to the Network Manager directory. Please input the <span style=\" font-weight:600;\">sudo</span> Password or run the program with elevated priveledges.</p></body></html>")
self.sudo_dialog.exec_()
if self.sudo_password:
self.set_kill_switch()
else:
self.killswitch_btn.setChecked(False)
return False

def check_connection_validity(self):
if self.server_type_select.currentText() == 'Double VPN': # perhaps add pop up to give user the choice
self.connection_type_select.setCurrentIndex(1) # set to TCP
Expand Down Expand Up @@ -876,8 +904,12 @@ def connect(self):
if self.auto_connect_box.isChecked() and not self.sudo_password: # prompt for sudo password
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.exec_()
self.set_auto_connect()

if self.sudo_password: #valid password exists
self.set_auto_connect()
else:
self.auto_connect_box.setChecked(False)
return False
elif self.auto_connect_box.isChecked() and self.sudo_password: # sudo password exists in memory
self.set_auto_connect()

Expand All @@ -893,13 +925,13 @@ def connect(self):
self.sudo_dialog = self.get_sudo()
self.sudo_dialog.text_label.setText("<html><head/><body><p>VPN Network Manager requires <span style=\" font-weight:600;\">sudo</span> permissions in order to move the kill switch script to the Network Manager directory. Please input the <span style=\" font-weight:600;\">sudo</span> Password or run the program with elevated priveledges.</p></body></html>")
self.sudo_dialog.exec_()
if not self.sudo_password: # dialog was closed
self.killswitch_btn.setChecked(False)
return False
self.set_kill_switch()
self.config['SETTINGS']['kill_switch'] = 'True'
self.write_conf()

elif self.killswitch_btn.isChecked() and self.sudo_password:
self.set_kill_switch()
self.config['SETTINGS']['kill_switch'] = 'True'
self.write_conf()

if self.get_active_vpn(): # if connection successful
self.connect_btn.hide()
Expand All @@ -908,10 +940,17 @@ def connect(self):

def disconnect_vpn(self):
if self.killswitch_btn.isChecked():
self.killswitch_btn.setChecked(False)
self.statusbar.showMessage("Disabling Killswitch...", 5000)
self.repaint()
self.disable_kill_switch()
time.sleep(5)
if self.auto_connect_box.isChecked():
self.auto_connect_box.setChecked(False)
self.statusbar.showMessage("Disabling auto-connect...", 1000)
self.disable_auto_connect()
self.disable_connection()
if not self.auto_connect_box.isChecked():
self.remove_connection()
self.remove_connection()
self.statusbar.clearMessage()
self.repaint()

Expand Down

0 comments on commit 0de190d

Please sign in to comment.