aboutsummaryrefslogtreecommitdiff
path: root/desktop/scripts/bridges/__init__.py
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2022-04-03 11:15:53 -0700
committerMicah Lee <micah@micahflee.com>2022-04-03 11:15:53 -0700
commit3fd96cd472c81e3a765b79adc0bcd104c4da42fe (patch)
treef76829485f28fb6a2c0ffbeb0a807ec38c964dd5 /desktop/scripts/bridges/__init__.py
parentee9a5269bb45499772a904616c7585f5318bf320 (diff)
downloadonionshare-3fd96cd472c81e3a765b79adc0bcd104c4da42fe.tar.gz
onionshare-3fd96cd472c81e3a765b79adc0bcd104c4da42fe.zip
Combine all get-tor scripts into a single get-tor.py
Diffstat (limited to 'desktop/scripts/bridges/__init__.py')
-rw-r--r--desktop/scripts/bridges/__init__.py74
1 files changed, 0 insertions, 74 deletions
diff --git a/desktop/scripts/bridges/__init__.py b/desktop/scripts/bridges/__init__.py
deleted file mode 100644
index f9d3c9a9..00000000
--- a/desktop/scripts/bridges/__init__.py
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-"""
-OnionShare | https://onionshare.org/
-
-Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-
-import os
-import requests
-
-
-class UpdateTorBridges:
- """
- Update the built-in Tor Bridges in OnionShare's torrc templates.
- """
-
- def __init__(self, root_path):
- self.root_path = root_path
- torrc_template_dir = os.path.join(
- self.root_path, os.pardir, "cli/onionshare_cli/resources"
- )
- endpoint = "https://bridges.torproject.org/moat/circumvention/builtin"
- r = requests.post(
- endpoint,
- headers={"Content-Type": "application/vnd.api+json"},
- )
- if r.status_code != 200:
- print(
- f"There was a problem fetching the latest built-in bridges: status_code={r.status_code}"
- )
- return False
-
- result = r.json()
-
- if "errors" in result:
- print(
- f"There was a problem fetching the latest built-in bridges: errors={result['errors']}"
- )
- return False
-
- for bridge_type in ["meek-azure", "obfs4", "snowflake"]:
- if result[bridge_type]:
- if bridge_type == "meek-azure":
- torrc_template_extension = "meek_lite_azure"
- else:
- torrc_template_extension = bridge_type
- torrc_template = os.path.join(
- self.root_path,
- torrc_template_dir,
- f"torrc_template-{torrc_template_extension}",
- )
-
- with open(torrc_template, "w") as f:
- f.write(f"# Enable built-in {bridge_type} bridge\n")
- bridges = result[bridge_type]
- # Sorts the bridges numerically by IP, since they come back in
- # random order from the API each time, and create noisy git diff.
- bridges.sort(key=lambda s: s.split()[1])
- for item in bridges:
- f.write(f"Bridge {item}\n")