mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-25 23:39:43 -05:00
Use the CensorshipCircumvention methods to fetch bridges for the country/autodetection
This commit is contained in:
parent
c101536d90
commit
3f4cb6a02e
@ -127,6 +127,11 @@ class CensorshipCircumvention(object):
|
|||||||
endpoint = "https://bridges.torproject.org/moat/circumvention/settings"
|
endpoint = "https://bridges.torproject.org/moat/circumvention/settings"
|
||||||
data = {}
|
data = {}
|
||||||
if country:
|
if country:
|
||||||
|
self.common.log(
|
||||||
|
"CensorshipCircumvention",
|
||||||
|
"censorship_obtain_settings",
|
||||||
|
f"Trying to obtain bridges for country={country}",
|
||||||
|
)
|
||||||
data = {"country": country}
|
data = {"country": country}
|
||||||
if transports:
|
if transports:
|
||||||
data.append({"transports": transports})
|
data.append({"transports": transports})
|
||||||
|
@ -21,11 +21,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
from PySide2 import QtCore, QtWidgets, QtGui
|
from PySide2 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from onionshare_cli.settings import Settings
|
from onionshare_cli.settings import Settings
|
||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
|
from .threads import CensorshipCircumventionThread
|
||||||
from .gui_common import GuiCommon, ToggleCheckbox
|
from .gui_common import GuiCommon, ToggleCheckbox
|
||||||
from .tor_connection import TorConnectionWidget
|
from .tor_connection import TorConnectionWidget
|
||||||
|
|
||||||
@ -146,6 +148,22 @@ class AutoConnectTab(QtWidgets.QWidget):
|
|||||||
self.tor_con.show()
|
self.tor_con.show()
|
||||||
self.tor_con.start(self.curr_settings)
|
self.tor_con.start(self.curr_settings)
|
||||||
|
|
||||||
|
def _got_bridges(self):
|
||||||
|
# Try and connect again
|
||||||
|
self.common.log(
|
||||||
|
"AutoConnectTab",
|
||||||
|
"use_bridge_connect_clicked",
|
||||||
|
"Got bridges. Trying to reconnect to Tor",
|
||||||
|
)
|
||||||
|
self.active = False
|
||||||
|
self.tor_con.show()
|
||||||
|
self.tor_con.start()
|
||||||
|
|
||||||
|
def _got_no_bridges(self):
|
||||||
|
self.active = False
|
||||||
|
self.tor_con.fail.emit()
|
||||||
|
self.open_tor_settings()
|
||||||
|
|
||||||
def use_bridge_connect_clicked(self):
|
def use_bridge_connect_clicked(self):
|
||||||
"""
|
"""
|
||||||
Connect button in use bridge widget clicked.
|
Connect button in use bridge widget clicked.
|
||||||
@ -158,30 +176,18 @@ class AutoConnectTab(QtWidgets.QWidget):
|
|||||||
self.use_bridge_widget.hide_buttons()
|
self.use_bridge_widget.hide_buttons()
|
||||||
|
|
||||||
if self.use_bridge_widget.detect_automatic_radio.isChecked():
|
if self.use_bridge_widget.detect_automatic_radio.isChecked():
|
||||||
self.use_bridge_widget.start_autodetecting_location()
|
country = False
|
||||||
|
|
||||||
# TODO: In a separate thread, detect the country. When complete, call
|
|
||||||
# self.use_bridge_widget.stop_autodetecting_location() to stop the animation
|
|
||||||
pass
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# TODO: Connect using the selected country
|
country = self.use_bridge_widget.country_code
|
||||||
pass
|
|
||||||
|
|
||||||
# self.common.gui.meek.start()
|
t = CensorshipCircumventionThread(self.common, self.curr_settings, country)
|
||||||
# self.censorship_circumvention = CensorshipCircumvention(
|
t.got_bridges.connect(self._got_bridges)
|
||||||
# self.common, self.common.gui.meek
|
t.got_no_bridges.connect(self._got_no_bridges)
|
||||||
# )
|
t.start()
|
||||||
# bridge_settings = self.censorship_circumvention.request_settings(country="tm")
|
self.active = True
|
||||||
# self.common.gui.meek.cleanup()
|
while self.active:
|
||||||
|
time.sleep(0.1)
|
||||||
# if bridge_settings and self.censorship_circumvention.save_settings(
|
self.common.gui.qtapp.processEvents()
|
||||||
# self.settings, bridge_settings
|
|
||||||
# ):
|
|
||||||
# # Try and connect again
|
|
||||||
# self.start()
|
|
||||||
# else:
|
|
||||||
# self.fail.emit()
|
|
||||||
|
|
||||||
def back_clicked(self):
|
def back_clicked(self):
|
||||||
"""
|
"""
|
||||||
@ -419,28 +425,13 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
|
|||||||
self.back_button.show()
|
self.back_button.show()
|
||||||
self.configure_button.show()
|
self.configure_button.show()
|
||||||
|
|
||||||
def start_autodetecting_location(self):
|
|
||||||
# If we're automatically detecting it, randomly switch up the country
|
|
||||||
# dropdown until we detect the location
|
|
||||||
if self.detect_automatic_radio.isChecked():
|
|
||||||
self.task_label.show()
|
|
||||||
self.task_label.setText(strings._("gui_autoconnect_task_detect_location"))
|
|
||||||
|
|
||||||
self.autodetecting_timer = QtCore.QTimer()
|
|
||||||
self.autodetecting_timer.timeout.connect(self._autodetecting_timer_callback)
|
|
||||||
self.autodetecting_timer.start(200)
|
|
||||||
|
|
||||||
def stop_autodetecting_location(self):
|
|
||||||
self.task_label.hide()
|
|
||||||
self.autodetecting_timer.stop()
|
|
||||||
|
|
||||||
def _country_changed(self, index=None):
|
def _country_changed(self, index=None):
|
||||||
country_code = str(self.country_combobox.currentData()).lower()
|
self.country_code = str(self.country_combobox.currentData()).lower()
|
||||||
path = GuiCommon.get_resource_path(
|
path = GuiCommon.get_resource_path(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
"images",
|
"images",
|
||||||
"countries",
|
"countries",
|
||||||
f"{country_code}-{self.common.gui.color_mode}.png",
|
f"{self.country_code}-{self.common.gui.color_mode}.png",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.country_image_label.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(path)))
|
self.country_image_label.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(path)))
|
||||||
|
@ -39,6 +39,8 @@ from onionshare_cli.onion import (
|
|||||||
PortNotAvailable,
|
PortNotAvailable,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from onionshare_cli.censorship import CensorshipCircumvention
|
||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
|
|
||||||
|
|
||||||
@ -268,3 +270,33 @@ class OnionCleanupThread(QtCore.QThread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
self.common.log("OnionCleanupThread", "run")
|
self.common.log("OnionCleanupThread", "run")
|
||||||
self.common.gui.onion.cleanup()
|
self.common.gui.onion.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
class CensorshipCircumventionThread(QtCore.QThread):
|
||||||
|
got_bridges = QtCore.Signal()
|
||||||
|
got_no_bridges = QtCore.Signal()
|
||||||
|
|
||||||
|
def __init__(self, common, settings, country):
|
||||||
|
super(CensorshipCircumventionThread, self).__init__()
|
||||||
|
self.common = common
|
||||||
|
self.common.log("CensorshipCircumventionThread", "__init__")
|
||||||
|
self.settings = settings
|
||||||
|
self.country = country
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.common.log("CensorshipCircumventionThread", "run")
|
||||||
|
|
||||||
|
self.common.gui.meek.start()
|
||||||
|
self.censorship_circumvention = CensorshipCircumvention(
|
||||||
|
self.common, self.common.gui.meek
|
||||||
|
)
|
||||||
|
bridge_settings = self.censorship_circumvention.request_settings(
|
||||||
|
country=self.country
|
||||||
|
)
|
||||||
|
|
||||||
|
if bridge_settings and self.censorship_circumvention.save_settings(
|
||||||
|
self.settings, bridge_settings
|
||||||
|
):
|
||||||
|
self.got_bridges.emit()
|
||||||
|
else:
|
||||||
|
self.got_no_bridges.emit()
|
||||||
|
@ -39,7 +39,6 @@ from onionshare_cli.onion import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
from onionshare_cli.censorship import CensorshipCircumvention
|
|
||||||
|
|
||||||
|
|
||||||
class TorConnectionWidget(QtWidgets.QWidget):
|
class TorConnectionWidget(QtWidgets.QWidget):
|
||||||
|
@ -42,7 +42,9 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
tor_is_connected = QtCore.Signal()
|
tor_is_connected = QtCore.Signal()
|
||||||
tor_is_disconnected = QtCore.Signal()
|
tor_is_disconnected = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False):
|
def __init__(
|
||||||
|
self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False
|
||||||
|
):
|
||||||
super(TorSettingsTab, self).__init__()
|
super(TorSettingsTab, self).__init__()
|
||||||
|
|
||||||
self.common = common
|
self.common = common
|
||||||
@ -314,9 +316,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
self.autoconnect_checkbox = QtWidgets.QCheckBox(
|
self.autoconnect_checkbox = QtWidgets.QCheckBox(
|
||||||
strings._("gui_enable_autoconnect_checkbox")
|
strings._("gui_enable_autoconnect_checkbox")
|
||||||
)
|
)
|
||||||
self.autoconnect_checkbox.toggled.connect(
|
self.autoconnect_checkbox.toggled.connect(self.autoconnect_toggled)
|
||||||
self.autoconnect_toggled
|
|
||||||
)
|
|
||||||
left_column_settings = QtWidgets.QVBoxLayout()
|
left_column_settings = QtWidgets.QVBoxLayout()
|
||||||
connection_type_radio_group.setFixedHeight(300)
|
connection_type_radio_group.setFixedHeight(300)
|
||||||
left_column_settings.addWidget(connection_type_radio_group)
|
left_column_settings.addWidget(connection_type_radio_group)
|
||||||
@ -327,7 +327,6 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
left_column_setting_widget = QtWidgets.QWidget()
|
left_column_setting_widget = QtWidgets.QWidget()
|
||||||
left_column_setting_widget.setLayout(left_column_settings)
|
left_column_setting_widget.setLayout(left_column_settings)
|
||||||
|
|
||||||
|
|
||||||
# The Bridges options are not exclusive (enabling Bridges offers obfs4 or custom bridges)
|
# The Bridges options are not exclusive (enabling Bridges offers obfs4 or custom bridges)
|
||||||
connection_type_bridges_radio_group_layout = QtWidgets.QVBoxLayout()
|
connection_type_bridges_radio_group_layout = QtWidgets.QVBoxLayout()
|
||||||
connection_type_bridges_radio_group_layout.addWidget(self.bridges)
|
connection_type_bridges_radio_group_layout.addWidget(self.bridges)
|
||||||
@ -355,7 +354,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
|||||||
columns_wrapper.setLayout(columns_layout)
|
columns_wrapper.setLayout(columns_layout)
|
||||||
|
|
||||||
# Tor connection widget
|
# Tor connection widget
|
||||||
self.tor_con = TorConnectionWidget(self.common, self.status_bar, self.meek)
|
self.tor_con = TorConnectionWidget(self.common, self.status_bar)
|
||||||
self.tor_con.success.connect(self.tor_con_success)
|
self.tor_con.success.connect(self.tor_con_success)
|
||||||
self.tor_con.fail.connect(self.tor_con_fail)
|
self.tor_con.fail.connect(self.tor_con_fail)
|
||||||
self.tor_con.hide()
|
self.tor_con.hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user