Skip to content

Commit

Permalink
Adding back warning about internal URL usage (#3341)
Browse files Browse the repository at this point in the history
This adds back a warning about the internal URL usage.
User needs to provide location permission "Always" so the App is able to
determine if the internal URL should be used or not, which also prevent
wrong usage on public network.

Within this warning there is also an option to disregard this security
concern and always use the internal URL when no other URL is available
at that moment.
  • Loading branch information
bgoncal authored Jan 17, 2025
1 parent 3360d1a commit 73ca010
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
row.displayValueFor = { [server] _ in
if server.info.connection.internalSSIDs?.isEmpty ?? true,
server.info.connection.internalHardwareAddresses?.isEmpty ?? true,
!server.info.connection.alwaysFallbackToInternalURL,
!ConnectionInfo.shouldFallbackToInternalURL {
!server.info.connection.alwaysFallbackToInternalURL {
return "‼️ \(L10n.Settings.ConnectionSection.InternalBaseUrl.RequiresSetup.title)"
} else {
return server.info.connection.address(for: .internal)?.absoluteString ?? ""
Expand Down
61 changes: 29 additions & 32 deletions Sources/App/Settings/Connection/ConnectionURLViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
$0.tag = RowTag.internalURLWarning.rawValue
if server.info.connection.internalSSIDs?.isEmpty ?? true,
server.info.connection.internalHardwareAddresses?.isEmpty ?? true,
!server.info.connection.alwaysFallbackToInternalURL,
!ConnectionInfo.shouldFallbackToInternalURL {
!server.info.connection.alwaysFallbackToInternalURL {
#if targetEnvironment(macCatalyst)
$0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidBssidRequired.title
#else
Expand Down Expand Up @@ -297,41 +296,39 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
}
}

if !ConnectionInfo.shouldFallbackToInternalURL {
form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer)
<<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) {
$0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title
$0.value = server.info.connection.alwaysFallbackToInternalURL
form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer)
<<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) {
$0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title
$0.value = server.info.connection.alwaysFallbackToInternalURL

$0.cellUpdate { cell, _ in
cell.switchControl.onTintColor = .red
}
$0.cellUpdate { cell, _ in
cell.switchControl.onTintColor = .red
}

$0.onChange { [weak self] row in
if row.value ?? false {
let alert = UIAlertController(
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title,
message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message,
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in
self?.server.info.connection.alwaysFallbackToInternalURL = false
$0.onChange { [weak self] row in
if row.value ?? false {
let alert = UIAlertController(
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title,
message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message,
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in
self?.server.info.connection.alwaysFallbackToInternalURL = false
row.value = false
row.cellUpdate { _, row in
row.value = false
row.cellUpdate { _, row in
row.value = false
}
row.reload()
}))
alert.addAction(UIAlertAction(
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation
.confirmButton,
style: .destructive
))
self?.present(alert, animated: true)
}
}
row.reload()
}))
alert.addAction(UIAlertAction(
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation
.confirmButton,
style: .destructive
))
self?.present(alert, animated: true)
}
}
}
}
}

private func locationPermissionSection() -> Section {
Expand Down
25 changes: 7 additions & 18 deletions Sources/Shared/API/ConnectionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import Communicator
#endif

public struct ConnectionInfo: Codable, Equatable {
// TODO: Remove when location permission enforcement is in place
/// Developer toggle used while enforcement of location permision is not ready
/// Used as feature toggle
public static var shouldFallbackToInternalURL = true

private var externalURL: URL?
private var internalURL: URL?
private var remoteUIURL: URL?
Expand Down Expand Up @@ -205,19 +200,13 @@ public struct ConnectionInfo: Codable, Equatable {
activeURLType = .internal
url = internalURL
} else {
// TODO: Remove when location permission enforcement is in place
if ConnectionInfo.shouldFallbackToInternalURL {
activeURLType = .internal
url = internalURL
} else {
activeURLType = .none
url = nil
/*
No URL that can be used in this context is available
This can happen when only internal URL is set and
user tries to access the App remotely
*/
}
activeURLType = .none
url = nil
/*
No URL that can be used in this context is available
This can happen when only internal URL is set and
user tries to access the App remotely
*/
}

return url?.sanitized()
Expand Down
4 changes: 0 additions & 4 deletions Tests/Shared/ConnectionInfo.test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import Version
import XCTest

class ConnectionInfoTests: XCTestCase {
override func setUp() async throws {
ConnectionInfo.shouldFallbackToInternalURL = false
}

func testInternalOnlyURL() {
let url = URL(string: "http://example.com:8123")
var info = ConnectionInfo(
Expand Down

0 comments on commit 73ca010

Please sign in to comment.