From bb352489cc6ea4e0087bcb3c78dbc5e6008ea841 Mon Sep 17 00:00:00 2001 From: Johnny Lin Date: Thu, 14 Apr 2022 18:55:20 -0700 Subject: [PATCH] FIX: BlockLog date issue --- LockdowniOS.xcodeproj/project.pbxproj | 24 ++++++++++++------------ ProtectedFileAccess.swift | 25 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/LockdowniOS.xcodeproj/project.pbxproj b/LockdowniOS.xcodeproj/project.pbxproj index 98fcfdc..f9e3485 100644 --- a/LockdowniOS.xcodeproj/project.pbxproj +++ b/LockdowniOS.xcodeproj/project.pbxproj @@ -2398,7 +2398,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2435,7 +2435,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2528,7 +2528,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2566,7 +2566,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2717,7 +2717,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -2756,7 +2756,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -2801,7 +2801,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2844,7 +2844,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2880,7 +2880,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = "Lockdown Blocker/Info.plist"; @@ -2910,7 +2910,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = "Lockdown Blocker/Info.plist"; @@ -2942,7 +2942,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2999,7 +2999,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = V8J3Z26F6Z; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/ProtectedFileAccess.swift b/ProtectedFileAccess.swift index 095b4a5..bbad1f2 100644 --- a/ProtectedFileAccess.swift +++ b/ProtectedFileAccess.swift @@ -11,8 +11,9 @@ import CocoaLumberjackSwift func flushBlockLog( log: (String) -> Void) { - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + let logFileDateFormatter = DateFormatter() + logFileDateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + logFileDateFormatter.timeZone = TimeZone(abbreviation: "UTC") let lastFlushDateKey = "lastBlockLogFlushTimeInterval" @@ -50,14 +51,24 @@ func flushBlockLog( log: (String) -> Void) { } entryDateString.removeLast() entryDateString.removeFirst() + + let host = String(splitLine[2]) + if (host == testFirewallDomain) { + // skip this + continue + } // 2022-04-14 22:23:12 - if let entryDate = dateFormatter.date(from: entryDateString) { - // if we have flushed logs more recently than the time on this log line, skip this log line - if entryDate.timeIntervalSince1970 < lastFlushDate { + if let entryDate = logFileDateFormatter.date(from: entryDateString) { + // only log entries that are newer than lastFlushDate +// log("entry line: \(blockedEntry)") +// log("comparing entrydatetime \(entryDate.timeIntervalSince1970) to lastFlushDate \(lastFlushDate)") +// log("comparing entrydatetime \(entryDate) to lastFlushDate \(Date(timeIntervalSince1970: lastFlushDate))") + if entryDate.timeIntervalSince1970 <= lastFlushDate { + // log("entryDate is older, not logging it") continue } - // TODO: use the timestamp instead of current time - updateMetrics(.incrementAndLog(host: String(splitLine[2])), rescheduleNotifications: .withEnergySaving) + //log("entryDate is newer, logging it") + updateMetrics(.incrementAndLog(host: host), rescheduleNotifications: .withEnergySaving) } else { log("ERROR: couldnt format entryDateString: \(entryDateString)")