From 01b51e94bf8916fa5b2120045068067990ab8e07 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 17 Oct 2021 14:26:56 -0700 Subject: [PATCH] Save/load moat bridges to/from settings --- cli/onionshare_cli/settings.py | 2 + cli/tests/test_cli_settings.py | 2 + desktop/src/onionshare/tor_settings_dialog.py | 43 +++++++++++++++---- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/cli/onionshare_cli/settings.py b/cli/onionshare_cli/settings.py index 37c00bb6..29b59c80 100644 --- a/cli/onionshare_cli/settings.py +++ b/cli/onionshare_cli/settings.py @@ -109,6 +109,8 @@ class Settings(object): "tor_bridges_use_obfs4": False, "tor_bridges_use_meek_lite_azure": False, "tor_bridges_use_snowflake": False, + "tor_bridges_use_moat": False, + "tor_bridges_use_moat_bridges": "", "tor_bridges_use_custom_bridges": "", "persistent_tabs": [], "locale": None, # this gets defined in fill_in_defaults() diff --git a/cli/tests/test_cli_settings.py b/cli/tests/test_cli_settings.py index 1e00f22d..b44ddbec 100644 --- a/cli/tests/test_cli_settings.py +++ b/cli/tests/test_cli_settings.py @@ -33,6 +33,8 @@ class TestSettings: "tor_bridges_use_obfs4": False, "tor_bridges_use_meek_lite_azure": False, "tor_bridges_use_snowflake": False, + "tor_bridges_use_moat": False, + "tor_bridges_use_moat_bridges": "", "tor_bridges_use_custom_bridges": "", "persistent_tabs": [], "theme": 0, diff --git a/desktop/src/onionshare/tor_settings_dialog.py b/desktop/src/onionshare/tor_settings_dialog.py index b6495830..477758c2 100644 --- a/desktop/src/onionshare/tor_settings_dialog.py +++ b/desktop/src/onionshare/tor_settings_dialog.py @@ -150,7 +150,6 @@ class TorSettingsDialog(QtWidgets.QDialog): self.bridge_moat_textbox.setMaximumHeight(100) self.bridge_moat_textbox.setReadOnly(True) self.bridge_moat_textbox.setWordWrapMode(QtGui.QTextOption.NoWrap) - self.bridge_moat_textbox.hide() bridge_moat_textbox_options_layout = QtWidgets.QVBoxLayout() bridge_moat_textbox_options_layout.addWidget(self.bridge_moat_button) bridge_moat_textbox_options_layout.addWidget(self.bridge_moat_textbox) @@ -417,6 +416,7 @@ class TorSettingsDialog(QtWidgets.QDialog): self.bridge_obfs4_radio.setChecked(False) self.bridge_meek_azure_radio.setChecked(False) self.bridge_snowflake_radio.setChecked(False) + self.bridge_moat_radio.setChecked(False) self.bridge_custom_radio.setChecked(False) else: self.bridge_none_radio.setChecked(False) @@ -429,14 +429,23 @@ class TorSettingsDialog(QtWidgets.QDialog): self.bridge_snowflake_radio.setChecked( self.old_settings.get("tor_bridges_use_snowflake") ) + self.bridge_moat_radio.setChecked( + self.old_settings.get("tor_bridges_use_moat") + ) + moat_bridges = self.old_settings.get("tor_bridges_use_moat_bridges") + self.bridge_moat_textbox.document().setPlainText(moat_bridges) + if len(moat_bridges.strip()) > 0: + self.bridge_moat_textbox.show() + else: + self.bridge_moat_textbox.hide() - if self.old_settings.get("bridge_custom_bridges"): + if self.old_settings.get("tor_bridges_use_custom_bridges"): self.bridge_custom_radio.setChecked(True) # Remove the 'Bridge' lines at the start of each bridge. # They are added automatically to provide compatibility with # copying/pasting bridges provided from https://bridges.torproject.org new_bridges = [] - bridges = self.old_settings.get("bridge_custom_bridges").split( + bridges = self.old_settings.get("tor_bridges_use_custom_bridges").split( "Bridge " ) for bridge in bridges: @@ -654,7 +663,7 @@ class TorSettingsDialog(QtWidgets.QDialog): "no_bridges", "tor_bridges_use_obfs4", "tor_bridges_use_meek_lite_azure", - "bridge_custom_bridges", + "tor_bridges_use_custom_bridges", ], ): @@ -761,30 +770,46 @@ class TorSettingsDialog(QtWidgets.QDialog): settings.set("tor_bridges_use_obfs4", False) settings.set("tor_bridges_use_meek_lite_azure", False) settings.set("tor_bridges_use_snowflake", False) - settings.set("bridge_custom_bridges", "") + settings.set("tor_bridges_use_moat", False) + settings.set("tor_bridges_use_custom_bridges", "") if self.bridge_obfs4_radio.isChecked(): settings.set("no_bridges", False) settings.set("tor_bridges_use_obfs4", True) settings.set("tor_bridges_use_meek_lite_azure", False) settings.set("tor_bridges_use_snowflake", False) - settings.set("bridge_custom_bridges", "") + settings.set("tor_bridges_use_moat", False) + settings.set("tor_bridges_use_custom_bridges", "") if self.bridge_meek_azure_radio.isChecked(): settings.set("no_bridges", False) settings.set("tor_bridges_use_obfs4", False) settings.set("tor_bridges_use_meek_lite_azure", True) settings.set("tor_bridges_use_snowflake", False) - settings.set("bridge_custom_bridges", "") + settings.set("tor_bridges_use_moat", False) + settings.set("tor_bridges_use_custom_bridges", "") if self.bridge_snowflake_radio.isChecked(): settings.set("no_bridges", False) settings.set("tor_bridges_use_obfs4", False) settings.set("tor_bridges_use_meek_lite_azure", False) settings.set("tor_bridges_use_snowflake", True) - settings.set("bridge_custom_bridges", "") + settings.set("tor_bridges_use_moat", False) + settings.set("tor_bridges_use_custom_bridges", "") + if self.bridge_moat_radio.isChecked(): + settings.set("no_bridges", False) + settings.set("tor_bridges_use_obfs4", False) + settings.set("tor_bridges_use_meek_lite_azure", False) + settings.set("tor_bridges_use_snowflake", False) + settings.set("tor_bridges_use_moat", True) + settings.set( + "tor_bridges_use_moat_bridges", self.bridge_moat_textbox.toPlainText() + ) + settings.set("tor_bridges_use_custom_bridges", "") if self.bridge_custom_radio.isChecked(): settings.set("no_bridges", False) settings.set("tor_bridges_use_obfs4", False) settings.set("tor_bridges_use_meek_lite_azure", False) settings.set("tor_bridges_use_snowflake", False) + settings.set("tor_bridges_use_moat", False) + settings.set("tor_bridges_use_moat_bridges", "") # Insert a 'Bridge' line at the start of each bridge. # This makes it easier to copy/paste a set of bridges @@ -814,7 +839,7 @@ class TorSettingsDialog(QtWidgets.QDialog): if bridges_valid: new_bridges = "".join(new_bridges) - settings.set("bridge_custom_bridges", new_bridges) + settings.set("tor_bridges_use_custom_bridges", new_bridges) else: Alert(self.common, strings._("gui_settings_tor_bridges_invalid")) settings.set("no_bridges", True)