From fce26c4286ee7a8368cc207534e2101f4ae35d80 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sun, 25 Feb 2018 19:42:38 +1100 Subject: [PATCH 1/2] Add ability to abort but not exit SettingsDialog/reconnect to Tor, on invalid settings. Do this for invalid bridges --- onionshare_gui/settings_dialog.py | 80 ++++++++++++++++--------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index e7bd2fae..5666400c 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -660,57 +660,58 @@ class SettingsDialog(QtWidgets.QDialog): common.log('SettingsDialog', 'save_clicked') settings = self.settings_from_fields() - settings.save() + if settings: + settings.save() - # If Tor isn't connected, or if Tor settings have changed, Reinitialize - # the Onion object - reboot_onion = False - if self.onion.is_authenticated(): - common.log('SettingsDialog', 'save_clicked', 'Connected to Tor') - def changed(s1, s2, keys): - """ - Compare the Settings objects s1 and s2 and return true if any values - have changed for the given keys. - """ - for key in keys: - if s1.get(key) != s2.get(key): - return True - return False + # If Tor isn't connected, or if Tor settings have changed, Reinitialize + # the Onion object + reboot_onion = False + if self.onion.is_authenticated(): + common.log('SettingsDialog', 'save_clicked', 'Connected to Tor') + def changed(s1, s2, keys): + """ + Compare the Settings objects s1 and s2 and return true if any values + have changed for the given keys. + """ + for key in keys: + if s1.get(key) != s2.get(key): + return True + return False - if changed(settings, self.old_settings, [ - 'connection_type', 'control_port_address', - 'control_port_port', 'socks_address', 'socks_port', - 'socket_file_path', 'auth_type', 'auth_password', - 'no_bridges', 'tor_bridges_use_obfs4', - 'tor_bridges_use_meek_lite_amazon', 'tor_bridges_use_meek_lite_azure', - 'tor_bridges_use_custom_bridges']): + if changed(settings, self.old_settings, [ + 'connection_type', 'control_port_address', + 'control_port_port', 'socks_address', 'socks_port', + 'socket_file_path', 'auth_type', 'auth_password', + 'no_bridges', 'tor_bridges_use_obfs4', + 'tor_bridges_use_meek_lite_amazon', 'tor_bridges_use_meek_lite_azure', + 'tor_bridges_use_custom_bridges']): + reboot_onion = True + + else: + common.log('SettingsDialog', 'save_clicked', 'Not connected to Tor') + # Tor isn't connected, so try connecting reboot_onion = True - else: - common.log('SettingsDialog', 'save_clicked', 'Not connected to Tor') - # Tor isn't connected, so try connecting - reboot_onion = True + # Do we need to reinitialize Tor? + if reboot_onion: + # Reinitialize the Onion object + common.log('SettingsDialog', 'save_clicked', 'rebooting the Onion') + self.onion.cleanup() - # Do we need to reinitialize Tor? - if reboot_onion: - # Reinitialize the Onion object - common.log('SettingsDialog', 'save_clicked', 'rebooting the Onion') - self.onion.cleanup() + tor_con = TorConnectionDialog(self.qtapp, settings, self.onion) + tor_con.start() - tor_con = TorConnectionDialog(self.qtapp, settings, self.onion) - tor_con.start() + common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor)) - common.log('SettingsDialog', 'save_clicked', 'Onion done rebooting, connected to Tor: {}'.format(self.onion.connected_to_tor)) + if self.onion.is_authenticated() and not tor_con.wasCanceled(): + self.settings_saved.emit() + self.close() - if self.onion.is_authenticated() and not tor_con.wasCanceled(): + else: self.settings_saved.emit() self.close() - else: - self.settings_saved.emit() - self.close() - def cancel_clicked(self): """ Cancel button clicked. @@ -839,6 +840,7 @@ class SettingsDialog(QtWidgets.QDialog): else: Alert(strings._('gui_settings_tor_bridges_invalid', True)) settings.set('no_bridges', True) + return False return settings From 35aaf8c675db1247ddb88ec97f9a02206106ba4a Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 26 Feb 2018 02:49:51 +1100 Subject: [PATCH 2/2] Alert wording change (we no longer 'ignore' invalid bridges, the user has to fix them) --- share/locale/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/locale/en.json b/share/locale/en.json index e3375b25..17778391 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -106,7 +106,7 @@ "gui_settings_tor_bridges_meek_lite_azure_radio_option_no_obfs4proxy": "Use built-in meek_lite (Azure) pluggable transports (requires obfs4proxy)", "gui_settings_tor_bridges_custom_radio_option": "Use custom bridges", "gui_settings_tor_bridges_custom_label": "You can get bridges from https://bridges.torproject.org", - "gui_settings_tor_bridges_invalid": "None of the bridges you supplied seem to be valid, so they've been ignored.\nPlease try again with valid bridges.", + "gui_settings_tor_bridges_invalid": "None of the bridges you supplied seem to be valid.\nPlease try again with valid bridges.", "gui_settings_button_save": "Save", "gui_settings_button_cancel": "Cancel", "gui_settings_button_help": "Help",