Skip to content

Commit

Permalink
fix: Check for lock screen or screensaver
Browse files Browse the repository at this point in the history
0 is also valid screensaver time  it now means immediately.

ref: teamniteo/pareto#489
  • Loading branch information
dz0ny committed Oct 21, 2024
1 parent 9b1c8a3 commit f541ca8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
28 changes: 23 additions & 5 deletions Pareto/Checks/Access Security/Screensaver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,38 @@ class ScreensaverCheck: ParetoCheck {
}

override var TitleON: String {
"Screensaver shows in under 20min"
"Screensaver or screen lock shows in under 20min"
}

override var TitleOFF: String {
"Screensaver shows in more than 20min"
"Screensaver or screen lock shows in more than 20min"
}

override public var showSettingsWarnEvents: Bool {
return true
}

override func checkPasses() -> Bool {
func checkScreensaver() -> Bool {
let script = "tell application \"System Events\" to tell screen saver preferences to get delay interval"
let out = Int(runOSA(appleScript: script)?.trim() ?? "0") ?? 0
return out > 0 && out <= 60 * 20
return out >= 0 && out <= 60 * 20
}

// https://github.com/usnistgov/macos_security/blob/e22bb0bc02290c54cb968bc3749942fa37ad752b/rules/os/os_screensaver_timeout_loginwindow_enforce.yaml#L4
func checkLock() -> Bool {
let script = """
function run() {
let timeout = ObjC.unwrap($.NSUserDefaults.alloc.initWithSuiteName('com.apple.screensaver')\
.objectForKey('loginWindowIdleTime'))
return timeout;
}
""";
let val = runOSAJS(appleScript: script)
let out = Int(val?.trim() ?? "0") ?? 0
return out >= 0 && out <= 60 * 20
}

override func checkPasses() -> Bool {
return checkScreensaver() && checkLock()
}
}
2 changes: 1 addition & 1 deletion Pareto/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>5462</string>
<string>5474</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
5 changes: 5 additions & 0 deletions Pareto/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func runOSA(appleScript: String) -> String? {
return out
}

func runOSAJS(appleScript: String) -> String? {
let out = runCMD(app: "/usr/bin/osascript", args: ["-l", "JavaScript", "-e", appleScript])
return out
}

func lsof(withCommand cmd: String, withPort port: Int) -> Bool {
let out = runCMD(app: "/usr/sbin/lsof", args: ["-i", "TCP:\(port)", "-P", "+L", "-O", "-T", "+c", "0", "-nPM"])
for line in out.components(separatedBy: "\n") {
Expand Down

0 comments on commit f541ca8

Please sign in to comment.