Disable block & ignore filter during recording
This commit is contained in:
@@ -23,6 +23,11 @@ enum PrefsShared {
|
|||||||
get { Int("AutoDeleteLogsDays") }
|
get { Int("AutoDeleteLogsDays") }
|
||||||
set { Int("AutoDeleteLogsDays", newValue) }
|
set { Int("AutoDeleteLogsDays", newValue) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static var CurrentlyRecording: Bool {
|
||||||
|
get { Bool("CurrentlyRecording") }
|
||||||
|
set { Bool("CurrentlyRecording", newValue) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,14 @@ class SimulatorVPN {
|
|||||||
|
|
||||||
@objc static func insertRandom() {
|
@objc static func insertRandom() {
|
||||||
//QLog.Debug("Inserting 1 periodic log entry")
|
//QLog.Debug("Inserting 1 periodic log entry")
|
||||||
let domain = "\(arc4random() % 5).count.test.com"
|
let rand = arc4random() % 8
|
||||||
|
let domain: String
|
||||||
|
switch rand {
|
||||||
|
case 6: domain = "tmp.b.test.com"
|
||||||
|
case 7: domain = "tmp.i.test.com"
|
||||||
|
case 8: domain = "tmp.bi.test.com"
|
||||||
|
default: domain = "\(rand).count.test.com"
|
||||||
|
}
|
||||||
let kill = hook.processDNSRequest(domain)
|
let kill = hook.processDNSRequest(domain)
|
||||||
if kill { QLog.Info("Blocked: \(domain)") }
|
if kill { QLog.Info("Blocked: \(domain)") }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,4 +157,8 @@ struct VPNAppMessage {
|
|||||||
static func notificationSettingsChanged() -> Self {
|
static func notificationSettingsChanged() -> Self {
|
||||||
.init("notify-prefs-change:1")
|
.init("notify-prefs-change:1")
|
||||||
}
|
}
|
||||||
|
/// Triggered whenever user taps on the start/stop recording button
|
||||||
|
static func isRecording(_ state: Bool) -> Self {
|
||||||
|
.init("recording-now:\(state ? 1 : 0)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class GlassVPNHook {
|
|||||||
private var filterOptions: [(block: Bool, ignore: Bool, customA: Bool, customB: Bool)]!
|
private var filterOptions: [(block: Bool, ignore: Bool, customA: Bool, customB: Bool)]!
|
||||||
private var autoDeleteTimer: Timer? = nil
|
private var autoDeleteTimer: Timer? = nil
|
||||||
private var cachedNotify: CachedConnectionAlert!
|
private var cachedNotify: CachedConnectionAlert!
|
||||||
|
private var currentlyRecording: Bool = false
|
||||||
|
|
||||||
init() { reset() }
|
init() { reset() }
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ class GlassVPNHook {
|
|||||||
reloadDomainFilter()
|
reloadDomainFilter()
|
||||||
setAutoDelete(PrefsShared.AutoDeleteLogsDays)
|
setAutoDelete(PrefsShared.AutoDeleteLogsDays)
|
||||||
cachedNotify = CachedConnectionAlert()
|
cachedNotify = CachedConnectionAlert()
|
||||||
|
currentlyRecording = PrefsShared.CurrentlyRecording
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invalidate auto-delete timer and release stored properties. You should nullify this instance afterwards.
|
/// Invalidate auto-delete timer and release stored properties. You should nullify this instance afterwards.
|
||||||
@@ -25,6 +27,7 @@ class GlassVPNHook {
|
|||||||
autoDeleteTimer?.fire() // one last time before we quit
|
autoDeleteTimer?.fire() // one last time before we quit
|
||||||
autoDeleteTimer?.invalidate()
|
autoDeleteTimer?.invalidate()
|
||||||
cachedNotify = nil
|
cachedNotify = nil
|
||||||
|
currentlyRecording = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this method from `PacketTunnelProvider.handleAppMessage(_:completionHandler:)`
|
/// Call this method from `PacketTunnelProvider.handleAppMessage(_:completionHandler:)`
|
||||||
@@ -43,6 +46,9 @@ class GlassVPNHook {
|
|||||||
case "notify-prefs-change":
|
case "notify-prefs-change":
|
||||||
cachedNotify = CachedConnectionAlert()
|
cachedNotify = CachedConnectionAlert()
|
||||||
return
|
return
|
||||||
|
case "recording-now":
|
||||||
|
currentlyRecording = value == "1"
|
||||||
|
return
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,18 +63,19 @@ class GlassVPNHook {
|
|||||||
/// - Returns: `true` if the request shoud be blocked.
|
/// - Returns: `true` if the request shoud be blocked.
|
||||||
func processDNSRequest(_ domain: String) -> Bool {
|
func processDNSRequest(_ domain: String) -> Bool {
|
||||||
let i = filterIndex(for: domain)
|
let i = filterIndex(for: domain)
|
||||||
// TODO: disable ignore & block during recordings
|
|
||||||
let (block, ignore, cA, cB) = (i<0) ? (false, false, false, false) : filterOptions[i]
|
let (block, ignore, cA, cB) = (i<0) ? (false, false, false, false) : filterOptions[i]
|
||||||
if ignore {
|
if ignore, !currentlyRecording {
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
let blockActive = block && !currentlyRecording
|
||||||
queue.async {
|
queue.async {
|
||||||
do { try AppDB?.logWrite(domain, blocked: block) }
|
do { try AppDB?.logWrite(domain, blocked: blockActive) }
|
||||||
catch { NSLog("[VPN.WARN] Couldn't write: \(error)") }
|
catch { NSLog("[VPN.WARN] Couldn't write: \(error)") }
|
||||||
}
|
}
|
||||||
|
// TODO: disable notifications during recording?
|
||||||
cachedNotify.postOrIgnore(domain, blck: block, custA: cA, custB: cB)
|
cachedNotify.postOrIgnore(domain, blck: block, custA: cA, custB: cB)
|
||||||
// TODO: wait for notify response to block or allow connection
|
// TODO: wait for notify response to block or allow connection
|
||||||
return block
|
return blockActive
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build binary tree for reverse DNS lookup
|
/// Build binary tree for reverse DNS lookup
|
||||||
|
|||||||
@@ -64,8 +64,11 @@ class VCRecordings: UIViewController, UINavigationControllerDelegate {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentRecording = RecordingsDB.startNew()
|
currentRecording = RecordingsDB.startNew()
|
||||||
|
QLog.Debug("start recording #\(currentRecording!.id)")
|
||||||
startTimer(animate: true)
|
startTimer(animate: true)
|
||||||
|
notifyVPN(setRecording: true)
|
||||||
} else {
|
} else {
|
||||||
|
notifyVPN(setRecording: false)
|
||||||
stopTimer(animate: true)
|
stopTimer(animate: true)
|
||||||
RecordingsDB.stop(¤tRecording!)
|
RecordingsDB.stop(¤tRecording!)
|
||||||
let editVC = (children.first as! TVCPreviousRecords)
|
let editVC = (children.first as! TVCPreviousRecords)
|
||||||
@@ -74,6 +77,11 @@ class VCRecordings: UIViewController, UINavigationControllerDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func notifyVPN(setRecording state: Bool) {
|
||||||
|
PrefsShared.CurrentlyRecording = state
|
||||||
|
GlassVPN.send(.isRecording(state))
|
||||||
|
}
|
||||||
|
|
||||||
private func startTimer(animate: Bool) {
|
private func startTimer(animate: Bool) {
|
||||||
guard let r = currentRecording, r.stop == nil else {
|
guard let r = currentRecording, r.stop == nil else {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user