Skip to content

Commit

Permalink
Issue #46: Re-added default Obfs4 bridges, request via mail and reque…
Browse files Browse the repository at this point in the history
…st via Telegram.
  • Loading branch information
tladesignz committed Jan 17, 2023
1 parent 35cf544 commit d66f991
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Orbot Mac/EditAuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EditAuthViewController: NSViewController, NSWindowDelegate {

@IBOutlet weak var cancelBt: NSButton! {
didSet {
cancelBt.title = L10n.cancel
cancelBt.title = IPtProxyUI.L10n.cancel
}
}

Expand Down
4 changes: 2 additions & 2 deletions Orbot Mac/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MainViewController: NSViewController, NSWindowDelegate, NSToolbarItemValid
item.label = L10n.authCookies

case "bridges":
item.label = L10n.bridgeConf
item.label = IPtProxyUI.L10n.bridgeConfiguration

default:
break
Expand Down Expand Up @@ -132,7 +132,7 @@ class MainViewController: NSViewController, NSWindowDelegate, NSToolbarItemValid

let showError = { (error: Error) in
hud?.progress = 1
hud?.labelText = L10n.error
hud?.labelText = IPtProxyUI.L10n.error
hud?.detailsLabelText = error.localizedDescription
hud?.hide(true, afterDelay: 3)
}
Expand Down
2 changes: 1 addition & 1 deletion Orbot Mac/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class SettingsViewController: NSViewController {
alert.messageText = L10n.warning
alert.informativeText = L10n.settingsExplanation3
alert.addButton(withTitle: L10n.activate)
alert.addButton(withTitle: L10n.cancel)
alert.addButton(withTitle: IPtProxyUI.L10n.cancel)

let response = alert.runModal()

Expand Down
42 changes: 12 additions & 30 deletions Orbot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@
A01AB5F328A53465008A79EE /* Frameworks */,
A01AB5F428A53465008A79EE /* Resources */,
61AE61C4AE5791BF2DBDCC61 /* [CP] Embed Pods Frameworks */,
B8D8CA9AB89FD71BC834A5D8 /* [CP] Copy Pods Resources */,
A01AB6AC28A55706008A79EE /* Embed Foundation Extensions */,
A8CC658E10E591DC6C1D0A6E /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -826,7 +826,7 @@
A06D605C29019D33001A2E2C /* Embed Frameworks */,
A01AB69C28A55706008A79EE /* Frameworks */,
A01AB69D28A55706008A79EE /* Resources */,
390E15C770E5B4A49902D7F6 /* [CP] Copy Pods Resources */,
021E681CE032ED2489488CC7 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -848,7 +848,7 @@
A05B73AE24755CE600930C40 /* Resources */,
A0A735D9247561F200073C81 /* Embed Foundation Extensions */,
EA613F0B6D61304A533884FE /* [CP] Embed Pods Frameworks */,
ED8A4F585C565CFB646DACF1 /* [CP] Copy Pods Resources */,
329E559D33FDBA00740F2EDE /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -889,7 +889,6 @@
A06D605F29019D3B001A2E2C /* Embed Frameworks */,
A0A735CA247561F200073C81 /* Frameworks */,
A0A735CB247561F200073C81 /* Resources */,
16978536BCC6E5D81EE5DC54 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -1053,38 +1052,38 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
16978536BCC6E5D81EE5DC54 /* [CP] Copy Pods Resources */ = {
021E681CE032ED2489488CC7 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TorVPN/Pods-TorVPN-resources-${CONFIGURATION}-input-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TorVPN/Pods-TorVPN-resources-${CONFIGURATION}-output-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TorVPN/Pods-TorVPN-resources.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources.sh\"\n";
showEnvVarsInLog = 0;
};
390E15C770E5B4A49902D7F6 /* [CP] Copy Pods Resources */ = {
329E559D33FDBA00740F2EDE /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources-${CONFIGURATION}-input-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources-${CONFIGURATION}-output-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TorVPN Mac/Pods-TorVPN Mac-resources.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources.sh\"\n";
showEnvVarsInLog = 0;
};
409194A5E6D0FCFF456B4364 /* [CP] Check Pods Manifest.lock */ = {
Expand Down Expand Up @@ -1186,7 +1185,7 @@
shellPath = /bin/sh;
shellScript = "if [ -f /opt/homebrew/bin/bartycrouch ]; then\n /opt/homebrew/bin/bartycrouch update -x\n /opt/homebrew/bin/bartycrouch lint -x\nelse\n echo \"warning: BartyCrouch not installed. Download it form https://github.com/Flinesoft/BartyCrouch\"\nfi\n";
};
B8D8CA9AB89FD71BC834A5D8 /* [CP] Copy Pods Resources */ = {
A8CC658E10E591DC6C1D0A6E /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down Expand Up @@ -1264,23 +1263,6 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
ED8A4F585C565CFB646DACF1 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Orbot/Pods-Orbot-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
122 changes: 109 additions & 13 deletions Orbot/BridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,45 @@
import UIKit
import Eureka
import IPtProxyUI
import MessageUI

class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
class BridgesViewController: BaseFormViewController, BridgesConfDelegate, MFMailComposeViewControllerDelegate {

enum Option: String, CaseIterable {
case direct = "transport_none"
case obfs4 = "transport_obfs4"
case snowflake = "transport_snowflake"
case snowflakeAmp = "transport_snowflake_amp"
case request = "request"
case requestMail = "request_mail"
case requestTelegram = "request_telegram"
case custom = "transport_custom"

var localizedDescription: String {
switch self {
case .direct:
return NSLocalizedString("Direct connection to Tor", comment: "")

case .obfs4:
return NSLocalizedString("Well-known Obfs4 bridges", comment: "")

case .snowflake:
return NSLocalizedString("Snowflake", comment: "")

case .snowflakeAmp:
return NSLocalizedString("Snowflake (AMP rendezvous)", comment: "")

case .request:
return NSLocalizedString("Get a bridge from Tor (Obfs4)", comment: "")
return NSLocalizedString("Get bridges from Tor (Obfs4)", comment: "")

case .requestMail:
return NSLocalizedString("Get bridges via Mail", comment: "")

case .requestTelegram:
return NSLocalizedString("Get bridges via Telegram", comment: "")

case .custom:
return NSLocalizedString("Custom bridge", comment: "")
return NSLocalizedString("Custom bridges", comment: "")
}
}

Expand All @@ -43,12 +56,24 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
case .direct:
return NSLocalizedString("The best way to connect to Tor. Use if Tor is not blocked.", comment: "")

case .snowflake, .snowflakeAmp:
case .obfs4:
return NSLocalizedString("Blocked in some countries, but great otherwise when you don't trust the network you're in.", comment: "")

case .snowflake:
return NSLocalizedString("Connects through Tor volunteers. Gets around some Tor blocking.", comment: "")

case .snowflakeAmp:
return NSLocalizedString("Find Snowflake volunteers through another mechanism.", comment: "")

case .request:
return NSLocalizedString("Cloaks your traffic. Gets around some Tor blocking.", comment: "")

case .requestMail:
return NSLocalizedString("In case you cannot reach Tor's bridge distribution website, you can try via mail. Has to be from a Gmail or Riseup account.", comment: "")

case .requestTelegram:
return NSLocalizedString("If Telegram works for you, you can ask the Telgram Tor Bot for bridges. Tap on 'Start' or write '/start' or '/bridges' in the chat.", comment: "")

case .custom:
return NSLocalizedString("Most likely to keep you connected if Tor is severly blocked. Requires a bridge address from someone you trust.", comment: "")
}
Expand All @@ -59,17 +84,33 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
case .direct:
return Settings.transport == .none

case .obfs4:
return Settings.transport == .obfs4

case .snowflake:
return Settings.transport == .snowflake

case .snowflakeAmp:
return Settings.transport == .snowflakeAmp

case .request:
return false

case .custom:
return Settings.transport == .custom

default:
return false
}
}

var isEnabled: Bool {
switch self {
case .requestMail:
return MFMailComposeViewController.canSendMail()

case .requestTelegram:
return UIApplication.shared.canOpenURL(Constants.telegramBot)

default:
return true
}
}
}
Expand Down Expand Up @@ -103,7 +144,7 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
form
+++ section

for option in Option.allCases {
for option in Option.allCases.filter({ $0.isEnabled }) {
form.last!
<<< ListCheckRow<Option>() {
$0.cellStyle = .subtitle
Expand All @@ -125,30 +166,50 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {
+++ RoundedButtonRow()
.cellUpdate({ [weak self] _, row in
switch self?.section.selectedRow()?.value ?? .direct {
case .request, .custom:
case .request, .requestMail, .requestTelegram, .custom:
row.title = NSLocalizedString("Next", comment: "")

default:
row.title = NSLocalizedString("Save", bundle: .iPtProxyUI, comment: "#bc-ignore!")
row.title = IPtProxyUI.L10n.save
}
})
.onCellSelection({ [weak self] cell, row in
switch self?.section.selectedRow()?.value ?? .direct {
case .request:
let vc = CaptchaViewController.make()
vc.delegate = self

self?.navigationController?.pushViewController(vc, animated: true)

case .requestMail:
let vc = MFMailComposeViewController()
vc.mailComposeDelegate = self
vc.setToRecipients([Constants.emailRecipient])
vc.setSubject(Constants.emailSubjectAndBody)
vc.setMessageBody(Constants.emailSubjectAndBody, isHTML: false)

self?.present(vc, animated: true)

case .requestTelegram:
UIApplication.shared.open(Constants.telegramBot) { success in
guard success else {
return
}

self?.pushCustomBridgesVc()
}

case .custom:
let vc = CustomBridgesViewController.make()
vc.delegate = self
self?.navigationController?.pushViewController(vc, animated: true)
self?.pushCustomBridgesVc()

default:
switch self?.section.selectedRow()?.value ?? .direct {
case .direct:
self?.transport = .none

case .obfs4:
self?.transport = .obfs4

case .snowflake:
self?.transport = .snowflake

Expand Down Expand Up @@ -176,4 +237,39 @@ class BridgesViewController: BaseFormViewController, BridgesConfDelegate {

NotificationCenter.default.post(name: .vpnStatusChanged, object: nil)
}


// MARK: MFMailComposeViewControllerDelegate

public func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Error?)
{
controller.dismiss(animated: true) { [weak self] in
guard let self = self else {
return
}

switch result {
case .saved, .sent:
self.pushCustomBridgesVc()

case .failed:
AlertHelper.present(self, message: error?.localizedDescription)

default:
break
}
}
}


// MARK: Private Methods

private func pushCustomBridgesVc() {
let vc = CustomBridgesViewController.make()
vc.delegate = self

navigationController?.pushViewController(vc, animated: true)
}
}
4 changes: 2 additions & 2 deletions Orbot/CaptchaViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CaptchaViewController: UIViewController {

@IBOutlet weak var captchaIv: UIImageView! {
didSet {
captchaIv.accessibilityLabel = MoatViewController.captchaImageText
captchaIv.accessibilityLabel = IPtProxyUI.L10n.captchaImage
}
}

Expand All @@ -28,7 +28,7 @@ class CaptchaViewController: UIViewController {

@IBOutlet weak var saveBt: UIButton! {
didSet {
saveBt.setTitle(NSLocalizedString("Save", bundle: .iPtProxyUI, comment: "#bc-ignore!"))
saveBt.setTitle(IPtProxyUI.L10n.save)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Orbot/CustomBridgesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CustomBridgesViewController: UIViewController, UITextViewDelegate, ScanQrD

@IBOutlet weak var saveBt: UIButton! {
didSet {
saveBt.setTitle(NSLocalizedString("Save", bundle: .iPtProxyUI, comment: "#bc-ignore!"))
saveBt.setTitle(IPtProxyUI.L10n.save)
}
}

Expand Down
Loading

0 comments on commit d66f991

Please sign in to comment.