Skip to content

Commit 73ca010

Browse files
authored
Adding back warning about internal URL usage (#3341)
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.
1 parent 3360d1a commit 73ca010

File tree

4 files changed

+37
-56
lines changed

4 files changed

+37
-56
lines changed

Sources/App/Settings/Connection/ConnectionSettingsViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
156156
row.displayValueFor = { [server] _ in
157157
if server.info.connection.internalSSIDs?.isEmpty ?? true,
158158
server.info.connection.internalHardwareAddresses?.isEmpty ?? true,
159-
!server.info.connection.alwaysFallbackToInternalURL,
160-
!ConnectionInfo.shouldFallbackToInternalURL {
159+
!server.info.connection.alwaysFallbackToInternalURL {
161160
return "‼️ \(L10n.Settings.ConnectionSection.InternalBaseUrl.RequiresSetup.title)"
162161
} else {
163162
return server.info.connection.address(for: .internal)?.absoluteString ?? ""

Sources/App/Settings/Connection/ConnectionURLViewController.swift

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
232232
$0.tag = RowTag.internalURLWarning.rawValue
233233
if server.info.connection.internalSSIDs?.isEmpty ?? true,
234234
server.info.connection.internalHardwareAddresses?.isEmpty ?? true,
235-
!server.info.connection.alwaysFallbackToInternalURL,
236-
!ConnectionInfo.shouldFallbackToInternalURL {
235+
!server.info.connection.alwaysFallbackToInternalURL {
237236
#if targetEnvironment(macCatalyst)
238237
$0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidBssidRequired.title
239238
#else
@@ -297,41 +296,39 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
297296
}
298297
}
299298

300-
if !ConnectionInfo.shouldFallbackToInternalURL {
301-
form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer)
302-
<<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) {
303-
$0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title
304-
$0.value = server.info.connection.alwaysFallbackToInternalURL
299+
form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer)
300+
<<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) {
301+
$0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title
302+
$0.value = server.info.connection.alwaysFallbackToInternalURL
305303

306-
$0.cellUpdate { cell, _ in
307-
cell.switchControl.onTintColor = .red
308-
}
304+
$0.cellUpdate { cell, _ in
305+
cell.switchControl.onTintColor = .red
306+
}
309307

310-
$0.onChange { [weak self] row in
311-
if row.value ?? false {
312-
let alert = UIAlertController(
313-
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title,
314-
message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message,
315-
preferredStyle: .alert
316-
)
317-
alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in
318-
self?.server.info.connection.alwaysFallbackToInternalURL = false
308+
$0.onChange { [weak self] row in
309+
if row.value ?? false {
310+
let alert = UIAlertController(
311+
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title,
312+
message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message,
313+
preferredStyle: .alert
314+
)
315+
alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in
316+
self?.server.info.connection.alwaysFallbackToInternalURL = false
317+
row.value = false
318+
row.cellUpdate { _, row in
319319
row.value = false
320-
row.cellUpdate { _, row in
321-
row.value = false
322-
}
323-
row.reload()
324-
}))
325-
alert.addAction(UIAlertAction(
326-
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation
327-
.confirmButton,
328-
style: .destructive
329-
))
330-
self?.present(alert, animated: true)
331-
}
320+
}
321+
row.reload()
322+
}))
323+
alert.addAction(UIAlertAction(
324+
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation
325+
.confirmButton,
326+
style: .destructive
327+
))
328+
self?.present(alert, animated: true)
332329
}
333330
}
334-
}
331+
}
335332
}
336333

337334
private func locationPermissionSection() -> Section {

Sources/Shared/API/ConnectionInfo.swift

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import Communicator
66
#endif
77

88
public struct ConnectionInfo: Codable, Equatable {
9-
// TODO: Remove when location permission enforcement is in place
10-
/// Developer toggle used while enforcement of location permision is not ready
11-
/// Used as feature toggle
12-
public static var shouldFallbackToInternalURL = true
13-
149
private var externalURL: URL?
1510
private var internalURL: URL?
1611
private var remoteUIURL: URL?
@@ -205,19 +200,13 @@ public struct ConnectionInfo: Codable, Equatable {
205200
activeURLType = .internal
206201
url = internalURL
207202
} else {
208-
// TODO: Remove when location permission enforcement is in place
209-
if ConnectionInfo.shouldFallbackToInternalURL {
210-
activeURLType = .internal
211-
url = internalURL
212-
} else {
213-
activeURLType = .none
214-
url = nil
215-
/*
216-
No URL that can be used in this context is available
217-
This can happen when only internal URL is set and
218-
user tries to access the App remotely
219-
*/
220-
}
203+
activeURLType = .none
204+
url = nil
205+
/*
206+
No URL that can be used in this context is available
207+
This can happen when only internal URL is set and
208+
user tries to access the App remotely
209+
*/
221210
}
222211

223212
return url?.sanitized()

Tests/Shared/ConnectionInfo.test.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import Version
33
import XCTest
44

55
class ConnectionInfoTests: XCTestCase {
6-
override func setUp() async throws {
7-
ConnectionInfo.shouldFallbackToInternalURL = false
8-
}
9-
106
func testInternalOnlyURL() {
117
let url = URL(string: "http://example.com:8123")
128
var info = ConnectionInfo(

0 commit comments

Comments
 (0)