Skip to content

Commit 0de190d

Browse files
committed
fixed numerous bugs relating to the sudo dialog and Network manager scripts
1 parent 360d78a commit 0de190d

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

nord_nm_gui.py

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,7 @@ def randomize_mac(self):
577577
try:
578578
self.statusbar.showMessage("Randomizing MAC Address", 2000)
579579
self.repaint()
580-
output = subprocess.run(['nmcli', '--mode', 'tabular', '--terse', '--fields', 'TYPE,UUID', 'connection', 'show', '--active'],
581-
stdout=subprocess.PIPE)
580+
output = subprocess.run(['nmcli', '--mode', 'tabular', '--terse', '--fields', 'TYPE,UUID', 'connection', 'show', '--active'], stdout=subprocess.PIPE)
582581
output.check_returncode()
583582
lines = output.stdout.decode('utf-8').split('\n')
584583

@@ -644,10 +643,14 @@ def get_sudo(self):
644643
resolution = QtWidgets.QDesktopWidget().screenGeometry()
645644
sudo_dialog.move(int((resolution.width() / 2) - (sudo_dialog.frameSize().width() / 2)), int((resolution.height() / 2) - (sudo_dialog.frameSize().height() / 2)))
646645
sudo_dialog.accept_box.accepted.connect(self.check_sudo)
647-
sudo_dialog.accept_box.rejected.connect(sudo_dialog.close)
646+
sudo_dialog.accept_box.rejected.connect(self.close_sudo_dialog)
648647
QtCore.QMetaObject.connectSlotsByName(sudo_dialog)
649648
return sudo_dialog
650649

650+
def close_sudo_dialog(self): # added to clear sudo password when cancel is pressed
651+
self.sudo_password = None
652+
self.sudo_dialog.close()
653+
651654
def check_sudo(self):
652655
self.sudo_password = self.sudo_dialog.sudo_password.text()
653656
try:
@@ -731,6 +734,8 @@ def disable_auto_connect(self):
731734
self.sudo_dialog = self.get_sudo()
732735
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>")
733736
self.sudo_dialog.exec_()
737+
if not self.sudo_password: # dialog was canceled
738+
return False
734739
try:
735740
p1 = subprocess.Popen(['echo', self.sudo_password], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
736741
p2 = subprocess.Popen(['sudo', '-S', 'rm', self.network_manager_path + 'auto_connect'], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -759,7 +764,11 @@ def disable_auto_connect(self):
759764
elif self.auto_connect_box.isChecked() and self.get_active_vpn() and not self.sudo_password:
760765
self.sudo_dialog = self.get_sudo()
761766
self.sudo_dialog.exec_()
762-
self.set_auto_connect()
767+
if self.sudo_password:
768+
self.set_auto_connect()
769+
else:
770+
self.auto_connect_box.setChecked(False)
771+
return False
763772

764773
def set_kill_switch(self):
765774

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

798809
self.statusbar.showMessage('Kill switch activated', 2000)
799810
self.repaint()
@@ -805,6 +816,10 @@ def disable_kill_switch(self):
805816
self.sudo_dialog = self.get_sudo()
806817
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>")
807818
self.sudo_dialog.exec_()
819+
820+
if not self.sudo_password: # dialog was canceled
821+
self.killswitch_btn.setChecked(False)
822+
return False
808823
try:
809824
p1 = subprocess.Popen(['echo', self.sudo_password], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
810825
p2 = subprocess.Popen(['sudo', '-S', 'rm', self.network_manager_path + 'kill_switch'], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -835,6 +850,19 @@ def disable_kill_switch(self):
835850
self.statusbar.showMessage('ERROR disabling kill switch', 2000)
836851
self.repaint()
837852

853+
elif self.killswitch_btn.isChecked() and self.get_active_vpn() and self.sudo_password:
854+
self.set_kill_switch()
855+
856+
elif self.killswitch_btn.isChecked() and self.get_active_vpn() and not self.sudo_password:
857+
self.sudo_dialog = self.get_sudo()
858+
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>")
859+
self.sudo_dialog.exec_()
860+
if self.sudo_password:
861+
self.set_kill_switch()
862+
else:
863+
self.killswitch_btn.setChecked(False)
864+
return False
865+
838866
def check_connection_validity(self):
839867
if self.server_type_select.currentText() == 'Double VPN': # perhaps add pop up to give user the choice
840868
self.connection_type_select.setCurrentIndex(1) # set to TCP
@@ -876,8 +904,12 @@ def connect(self):
876904
if self.auto_connect_box.isChecked() and not self.sudo_password: # prompt for sudo password
877905
self.sudo_dialog = self.get_sudo()
878906
self.sudo_dialog.exec_()
879-
self.set_auto_connect()
880907

908+
if self.sudo_password: #valid password exists
909+
self.set_auto_connect()
910+
else:
911+
self.auto_connect_box.setChecked(False)
912+
return False
881913
elif self.auto_connect_box.isChecked() and self.sudo_password: # sudo password exists in memory
882914
self.set_auto_connect()
883915

@@ -893,13 +925,13 @@ def connect(self):
893925
self.sudo_dialog = self.get_sudo()
894926
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>")
895927
self.sudo_dialog.exec_()
928+
if not self.sudo_password: # dialog was closed
929+
self.killswitch_btn.setChecked(False)
930+
return False
896931
self.set_kill_switch()
897-
self.config['SETTINGS']['kill_switch'] = 'True'
898-
self.write_conf()
932+
899933
elif self.killswitch_btn.isChecked() and self.sudo_password:
900934
self.set_kill_switch()
901-
self.config['SETTINGS']['kill_switch'] = 'True'
902-
self.write_conf()
903935

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

909941
def disconnect_vpn(self):
910942
if self.killswitch_btn.isChecked():
943+
self.killswitch_btn.setChecked(False)
944+
self.statusbar.showMessage("Disabling Killswitch...", 5000)
945+
self.repaint()
911946
self.disable_kill_switch()
947+
time.sleep(5)
948+
if self.auto_connect_box.isChecked():
949+
self.auto_connect_box.setChecked(False)
950+
self.statusbar.showMessage("Disabling auto-connect...", 1000)
951+
self.disable_auto_connect()
912952
self.disable_connection()
913-
if not self.auto_connect_box.isChecked():
914-
self.remove_connection()
953+
self.remove_connection()
915954
self.statusbar.clearMessage()
916955
self.repaint()
917956

0 commit comments

Comments
 (0)