Skip to content

Commit 4313964

Browse files
authored
Merge pull request #618 from macadmins/development
v2.0.5 pt2
2 parents 62ba9b7 + 7038593 commit 4313964

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

CHANGELOG.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@ Requires macOS 12.0 and higher.
1515
- macOS device is 14.2: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-08 00:00:00 +0000
1616
- macOS device is 14.3: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-08 00:00:00 +0000
1717
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-08 00:00:00 +0000
18-
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-15 00:00:00 +0000
18+
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.5 requiredInstallationDate of 2024-06-03 00:00:00 +0000
1919
- This device's requiredInstallationDate is different than the others as there is no active exploit on 14.4.1
2020
- macOS device is 14.5: Required OS: 14.5 - Fully updated
2121
- Ex: `minorVersionRecalculationThreshold` is set to 2 and SOFA feed has macOS 14.5 available
2222
- macOS device is 14.0: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
2323
- macOS device is 14.1: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
2424
- macOS device is 14.2: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
2525
- macOS device is 14.3: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
26-
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-03-21 00:00:00 +0000
27-
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-04-15 00:00:00 +0000
26+
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-04-08 00:00:00 +0000
27+
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-06-03 00:00:00 +0000
28+
- macOS device is 14.5: Required OS: 14.5 - Fully updated
29+
- Ex: `minorVersionRecalculationThreshold` is set to 3 and SOFA feed has macOS 14.5 available
30+
- macOS device is 14.0: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
31+
- macOS device is 14.1: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
32+
- macOS device is 14.2: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
33+
- macOS device is 14.3: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-02-22 00:00:00 +0000
34+
- macOS device is 14.4: Required OS: 14.5 - Target macOS 14.4 requiredInstallationDate of 2024-04-08 00:00:00 +0000
35+
- macOS device is 14.4.1: Required OS: 14.5 - Target macOS 14.4.1 requiredInstallationDate of 2024-06-03 00:00:00 +0000
2836
- macOS device is 14.5: Required OS: 14.5 - Fully updated
2937
- Addresses [612](https://github.com/macadmins/nudge/issues/612)
38+
- To ease testing, you can now pass `-simulate-date` as an argument to override the built-in date check.
39+
- Ex: `-simulate-date "2024-07-25T00:00:00Z"`
3040

3141
### Changed
3242
- The `Actively Exploited` logic internally within Nudge and the UI on the left sidebar will show `True` if any previous updates missing on the device had active exploits.
@@ -36,6 +46,7 @@ Requires macOS 12.0 and higher.
3646
- Addresses [610](https://github.com/macadmins/nudge/issues/610) and [613](https://github.com/macadmins/nudge/issues/613)
3747
- When `showRequiredDate` is set to `True` and the admin is using the default values for `requiredInstallationDisplayFormat`, Nudge will attempt to understand the current locale and display the menu item appropriately.
3848
- Addresses [615](https://github.com/macadmins/nudge/issues/615)
49+
- Banned shortcut keys - including the ability to quit the application - are now allowed when passing `-simulate-os-version` or `-simulate-hardware-id` or `-simulate-date`
3950

4051
### Fixed
4152
- Several components in the Github Actions were triggering deprecation warnings. These have been addressed by updating to the latest version of these components

Nudge/UI/Main.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
155155
if nudgePrimaryState.shouldExit {
156156
return .terminateNow
157157
} else {
158+
if (CommandLineUtilities().simulateOSVersion() != nil) || (CommandLineUtilities().simulateHardwareID() != nil) || (CommandLineUtilities().simulateDate() != nil) {
159+
LogManager.warning("Attempt to exit Nudge was allowed due to simulation arguments.", logger: uiLog)
160+
return .terminateNow
161+
}
158162
// Log the attempt to exit the application if it should not exit yet
159163
LogManager.warning("Attempt to exit Nudge was prevented.", logger: uiLog)
160164
return .terminateCancel
@@ -231,9 +235,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
231235
})
232236

233237
// Filter versions with the same major version as the current installed version
234-
let minorVersions = VersionManager().removeDuplicates(from: filteredVersions.filter { version in
238+
var minorVersions = VersionManager().removeDuplicates(from: filteredVersions.filter { version in
235239
VersionManager.getMajorVersion(from: version) == currentMajorVersion
236240
})
241+
// Remove the current installed version from minorVersions
242+
minorVersions.removeAll { $0 == currentInstalledVersion }
237243

238244
// Count actively exploited CVEs in the filtered versions
239245
LogManager.notice("Assessing macOS version range for active exploits: \(filteredVersions) ", logger: sofaLog)
@@ -283,13 +289,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
283289
if minorVersions.isEmpty {
284290
requiredInstallationDate = selectedOS!.releaseDate?.addingTimeInterval(slaExtension) ?? DateManager().getCurrentDate().addingTimeInterval(TimeInterval(90 * 86400))
285291
} else {
292+
LogManager.notice("Assessing macOS version range for recalculation: \(minorVersions)", logger: sofaLog)
286293
let safeIndex = max(0, minorVersions.count - (OSVersionRequirementVariables.minorVersionRecalculationThreshold + 1)) // Ensure the index is within bounds
287294
let targetVersion = minorVersions[safeIndex]
288295
var foundVersion = false
289296
LogManager.notice("minorVersionRecalculationThreshold is set to \(OSVersionRequirementVariables.minorVersionRecalculationThreshold) - Current Version: \(currentInstalledVersion) - Targeting version \(targetVersion) requiredInstallationDate via SOFA", logger: sofaLog)
290297
for osVersion in macOSSOFAAssets {
291-
for securityRelease in osVersion.securityReleases.reversed() {
292-
if VersionManager.versionGreaterThanOrEqual(currentVersion: securityRelease.productVersion, newVersion: targetVersion) && VersionManager.versionLessThanOrEqual(currentVersion: currentInstalledVersion, newVersion: targetVersion) {
298+
for securityRelease in osVersion.securityReleases {
299+
if securityRelease.productVersion == targetVersion {
293300
requiredInstallationDate = securityRelease.releaseDate?.addingTimeInterval(slaExtension) ?? DateManager().getCurrentDate().addingTimeInterval(TimeInterval(90 * 86400))
294301
LogManager.notice("Found target macOS version \(targetVersion) - releaseDate is \(securityRelease.releaseDate!), slaExtension is \(LoggerUtilities().printTimeInterval(slaExtension))", logger: sofaLog)
295302
foundVersion = true
@@ -531,6 +538,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
531538
}
532539

533540
private func detectBannedShortcutKeys(with event: NSEvent) -> Bool {
541+
if (CommandLineUtilities().simulateOSVersion() != nil) || (CommandLineUtilities().simulateHardwareID() != nil) || (CommandLineUtilities().simulateDate() != nil) { return false }
534542
guard NSApplication.shared.isActive else { return false }
535543
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
536544
// Disable CMD + H - Hides Nudge

Nudge/Utilities/Logger.swift

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class LogState {
6161
var hasLoggedRequireMajorUgprade = false
6262
var hasLoggedScreenshotIconMode = false
6363
var hasLoggedSimpleMode = false
64+
var hasLoggedSimulatedDate = false
6465
var hasLoggedUnitTestingMode = false
6566
}
6667

Nudge/Utilities/Utils.swift

+25-1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ struct CommandLineUtilities {
431431
return argumentPassed
432432
}
433433

434+
func simulateDate() -> String? {
435+
return valueForArgument("-simulate-date")
436+
}
437+
434438
func simulateHardwareID() -> String? {
435439
return valueForArgument("-simulate-hardware-id")
436440
}
@@ -592,11 +596,31 @@ struct DateManager {
592596
}
593597

594598
func getCurrentDate() -> Date {
595-
switch Calendar.current.identifier {
599+
let dateFormatterISO8601 = ISO8601DateFormatter()
600+
601+
if (CommandLineUtilities().simulateDate() != nil) {
602+
// Try to parse the provided ISO8601 string
603+
if let date = dateFormatterISO8601.date(from: CommandLineUtilities().simulateDate()!) {
604+
if !nudgeLogState.hasLoggedSimulatedDate {
605+
LogManager.notice("Simulated Date set via -simulated-date, returning \(CommandLineUtilities().simulateDate()!)", logger: uiLog)
606+
nudgeLogState.hasLoggedSimulatedDate = true
607+
}
608+
return date
609+
} else {
610+
if !nudgeLogState.hasLoggedSimulatedDate {
611+
LogManager.error("Failed to parse -simulated-date, returning current date.", logger: uiLog)
612+
nudgeLogState.hasLoggedSimulatedDate = true
613+
}
614+
return Date()
615+
}
616+
} else {
617+
// If no string is provided, return the current date based on calendar
618+
switch Calendar.current.identifier {
596619
case .buddhist, .japanese, .gregorian, .coptic, .ethiopicAmeteMihret, .hebrew, .iso8601, .indian, .islamic, .islamicCivil, .islamicTabular, .islamicUmmAlQura, .persian:
597620
return dateFormatterISO8601.date(from: dateFormatterISO8601.string(from: Date())) ?? Date()
598621
default:
599622
return Date()
623+
}
600624
}
601625
}
602626

0 commit comments

Comments
 (0)