Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Jan 3, 2024
1 parent 0c8e812 commit 6b48418
Show file tree
Hide file tree
Showing 33 changed files with 146 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Pareto/AppInfo.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ParetoApp.swift
// AppInfo.swift
// Pareto
//
// Created by Janez Troha on 12/07/2021.
Expand Down
4 changes: 2 additions & 2 deletions Pareto/Checks/Access Security/PasswordtoUnlock.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PasswordFromLock.swift.swift
// PasswordFromLock.swift
// PasswordtoUnlock.swift
// PasswordtoUnlock.swift
//
// Created by Janez Troha on 17/08/2021.
//
Expand Down
4 changes: 2 additions & 2 deletions Pareto/Checks/Access Security/SSHKeysStrength.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct KeyInfo: Equatable, ExpressibleByStringLiteral {
// MARK: - Equatable Methods

public static func == (lhs: KeyInfo, rhs: KeyInfo) -> Bool {
return (lhs.signature == rhs.signature)
return lhs.signature == rhs.signature
}

// MARK: - ExpressibleByStringLiteral Methods
Expand Down Expand Up @@ -77,7 +77,7 @@ class SSHKeysStrengthCheck: SSHCheck {
}
return "SSH key \(sshKey) is using weak encryption"
}

func isKeyStrong(withKey path: String) -> Bool {
let output = runCMD(app: getSSHKeygenPath(), args: ["-l", "-f", path])
let info = KeyInfo(stringLiteral: output.strip())
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/Firewall and Sharing/InternetSharing.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// InternetShare.swift
// InternetSharing.swift
// InternetShare
//
// Created by Janez Troha on 21/09/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/Firewall and Sharing/RemoteManagment.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// RemoteManagementCheck.swift
// RemoteManagment.swift
// RemoteManagementCheck
//
// Created by Janez Troha on 08/09/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/LibreOffice.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// GoogleChrome.swift
// LibreOffice.swift
// Pareto Security
//
// Created by Janez Troha on 11/11/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/ParetoCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MenuItemCheck.swift
// ParetoCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/Software Updates/AdobeReader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Docker.swift
// AdobeReader.swift
// Pareto Security
//
// Created by Janez Troha on 11/11/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/System Integrity/FileVault.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Firewall.swift
// FileVault.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
49 changes: 44 additions & 5 deletions Pareto/Checks/System Integrity/NoUnusedUsers.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//
// Firewall.swift
// NoUnusedUsers.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
//

import Foundation

class NoUnusedUsers: ParetoCheck {
static let sharedInstance = NoUnusedUsers()
override var UUID: String {
Expand All @@ -18,16 +20,53 @@ class NoUnusedUsers: ParetoCheck {
override var TitleOFF: String {
"Unrequired user accounts are present(" + accounts.joined(separator: ",") + ")"
}

var accounts: [String] {
let output = runCMD(app: "/usr/bin/dscl", args: [".", "-list", "/Users"]).components(separatedBy: "\n")
let local = output.filter { u in
return !u.hasPrefix("_") && u.count > 1 && u != "root" && u != "nobody" && u != "daemon"
!u.hasPrefix("_") && u.count > 1 && u != "root" && u != "nobody" && u != "daemon"
}
return local
}


func lastLoginRecent(user: String) -> Bool {
let output = runCMD(app: "/usr/bin/last", args: ["-w", "-y", user]).components(separatedBy: "\n")
let log = output.filter { u in
u.contains(user)
}

let entry = log.first?.components(separatedBy: " ").filter { i in
i.count > 1
}
if (log.first?.contains("still logged in")) != nil {
return true
}
// parse string to date
if entry?.count ?? 0 > 1 {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX") // Use a POSIX locale
dateFormatter.dateFormat = "EEE MMM d yyyy HH:mm"

if let date = dateFormatter.date(from: entry![2]) {
let currentDate = Date()
let calendar = Calendar.current

let components = calendar.dateComponents([.month], from: date, to: currentDate)

if let monthDifference = components.month, monthDifference <= 1 {
return true
} else {
return false
}
}
}

return false
}

override func checkPasses() -> Bool {
return accounts.count == 1
return accounts.allSatisfy { u in
lastLoginRecent(user: u)
}
}
}
2 changes: 1 addition & 1 deletion Pareto/Checks/System Integrity/OpenWiFi.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// OpenWIFI.swift
// OpenWiFi.swift
// Pareto Security
//
// Created by Janez Troha on 28/09/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/System Integrity/SecureiTerm.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SecureTerminal.swift
// SecureiTerm.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/VSCode.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SublimeText.swift
// VSCode.swift
// Pareto Security
//
// Created by Janez Troha on 11/11/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/Zoom.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// GoogleChrome.swift
// Zoom.swift
// Pareto Security
//
// Created by Janez Troha on 11/11/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/macOS Updates/AutoUpdateAppCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AppStoreAppsUpdatesCheck.swift
// AutoUpdateAppCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/macOS Updates/AutoUpdateCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AppStoreUpdatesCheck.swift
// AutoUpdateCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/macOS Updates/AutomaticDownloadCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AutoUpdateCheck.swift
// AutomaticDownloadCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/macOS Updates/AutomaticInstallCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AutoUpdateCheck.swift
// AutomaticInstallCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/macOS Updates/SecurityUpdateCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AutoUpdateCheck.swift
// SecurityUpdateCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/macOS Updates/SystemUpdatesCheck.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AppStoreUpdatesCheck.swift
// SystemUpdatesCheck.swift
// Pareto Security
//
// Created by Janez Troha on 15/07/2021.
Expand Down
16 changes: 9 additions & 7 deletions Pareto/Defaults.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// Settings.swift
// Defaults.swift
// Settings
//
// Created by Janez Troha on 27/07/2021.
//

import AppKit
import Combine
import Defaults
import Foundation
import AppKit
import SwiftUI

enum ReportingRoles: String, Defaults.Serializable {
Expand Down Expand Up @@ -88,25 +88,27 @@ public extension Defaults {
Defaults[.lastUpdateCheck] = Date().currentTimeMs()
Defaults[.updateNag] = false
}

static func OKColor() -> NSColor {
if Defaults[.alternativeColor] {
let light = NSColor.init(red: 255, green: 179, blue: 64, alpha: 1)
let dark = NSColor.init(red: 255, green: 179, blue: 64, alpha: 1)
let light = NSColor(red: 255, green: 179, blue: 64, alpha: 1)
let dark = NSColor(red: 255, green: 179, blue: 64, alpha: 1)
let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark"
return isDark ? dark : light
}
return NSColor.systemGreen
}

static func FailColor() -> NSColor {
if Defaults[.alternativeColor] {
let light = NSColor.init(red: 64, green: 156, blue: 255, alpha: 1)
let dark = NSColor.init(red: 64, green: 156, blue: 255, alpha: 1)
let light = NSColor(red: 64, green: 156, blue: 255, alpha: 1)
let dark = NSColor(red: 64, green: 156, blue: 255, alpha: 1)
let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark"
return isDark ? dark : light
}
return NSColor.systemOrange
}

static func shouldAskForHWAllow() -> Bool {
return Defaults[.lastHWAsk] + Date.HourInMs * 24 * 7 * 30 * 6 < Date().currentTimeMs()
}
Expand Down
12 changes: 6 additions & 6 deletions Pareto/Extensions/SSHCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import Foundation
import os.log

class SSHCheck: ParetoCheck {
internal let sshPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".ssh").resolvingSymlinksInPath()
let sshPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".ssh").resolvingSymlinksInPath()
private var sshKeygenPath = ""

func itExists(_ path: String) -> Bool {
FileManager.default.fileExists(atPath: path)
}

func getSSHKeygenPath() -> String {
if !sshKeygenPath.isEmpty {
return sshKeygenPath
}

if itExists("/opt/homebrew/bin/ssh-keygen") {
sshKeygenPath = "/opt/homebrew/bin/ssh-keygen"
} else {
sshKeygenPath = "/usr/bin/ssh-keygen"
}

return sshKeygenPath
}

override var isRunnable: Bool {
if !itExists(getSSHKeygenPath()) {
os_log("Not found /opt/homebrew/bin/ssh-keygen or /usr/bin/ssh-keygen, check disabled", log: Log.check)
Expand Down
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>5292</string>
<string>5310</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Teams.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Team.swift
// Teams.swift
// Team
//
// Created by Janez Troha on 16/09/2021.
Expand Down
2 changes: 1 addition & 1 deletion Pareto/Views/Settings/ChecksSettingsView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CheckSettingsView.swift
// ChecksSettingsView.swift
// CheckSettingsView
//
// Created by Janez Troha on 10/09/2021.
Expand Down
Loading

0 comments on commit 6b48418

Please sign in to comment.