Skip to content

Commit

Permalink
Expose app logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Jul 26, 2022
1 parent 017801c commit 6654b91
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
14 changes: 14 additions & 0 deletions Pareto/AppHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ class AppHandlers: NSObject, NetworkHandlerObserver {
welcomeWindow!.makeKeyAndOrderFront(nil)
}

func copyLogs() {
NSPasteboard.general.clearContents()
if let data = try? AppInfo.logEntries().joined(separator: "\n") {
NSPasteboard.general.setString(data, forType: .string)
}
let alert = NSAlert()
alert.messageText = "Logs have been copied to the clipboard."
alert.alertStyle = NSAlert.Style.informational
alert.addButton(withTitle: "OK")
alert.runModal()
}

func copyDebug(_ onlyCheck: String) {
var data = ""
for claim in Claims.sorted {
Expand Down Expand Up @@ -457,6 +469,8 @@ class AppHandlers: NSObject, NetworkHandlerObserver {
case "debug":
let check = url.queryParams()["check"] ?? ""
copyDebug(check)
case "logs":
copyLogs()
case "runChecks":
NSApp.sendAction(#selector(runChecks), to: nil, from: nil)
NSApp.activate(ignoringOtherApps: true)
Expand Down
25 changes: 23 additions & 2 deletions Pareto/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum AppInfo {

static let bugReportURL = { () -> URL in
let baseURL = "https://paretosecurity.com/report-bug?"
let logs = logEntries().joined(separator: "\n").addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
let logs = try? logEntries().joined(separator: "\n").addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
let versions = getVersions().addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
if let url = URL(string: baseURL + "&logs=" + logs! + "&version=" + versions!) {
return url
Expand All @@ -119,7 +119,28 @@ enum AppInfo {
logs.append("Build: \(AppInfo.utmSource)")

logs.append("\nLogs:")
logs.append("Please copy the logs from the Console app by searching for the ParetoSecurity.")

if #available(macOS 12.0, *) {
let logStore = try OSLogStore(scope: .currentProcessIdentifier)
// Get all the logs from the last hour.
let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600))

// Fetch log objects.
let allEntries = try logStore.getEntries(at: oneHourAgo)

// Filter the log to be relevant for our specific subsystem
// and remove other elements (signposts, etc).
for log in allEntries
.compactMap({ $0 as? OSLogEntryLog })
.filter({ entry in
entry.subsystem == "niteo.co.Pareto"
}) {
logs.append("\(log.subsystem): \(log.composedMessage)")
}
} else {
logs.append("Please copy the logs from the Console app by searching for the ParetoSecurity.")
}

return logs
}

Expand Down
2 changes: 1 addition & 1 deletion Pareto/Checks/Access Security/SSHKeysStrength.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SSHKeysStrengthCheck: ParetoCheck {
func isKeyStrong(withKey path: String) -> Bool {
let output = runCMD(app: "/usr/bin/ssh-keygen", args: ["-l", "-f", path])
let info = KeyInfo(stringLiteral: output.strip())
os_log("%s has %d", log: Log.check, path, info.strength)
os_log("%{public}s has %d", log: Log.check, path, info.strength)
// https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-57pt3r1.pdf
switch info.cipher {
case .RSA:
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>4863</string>
<string>4870</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions Pareto/StatusBar/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ class StatusBarController: NSObject, NSMenuDelegate {
Team.update(withReport: report).response { response in
switch response.result {
case .success:
os_log("Check status was updated", log: Log.app)
os_log("Team status was updated", log: Log.app)
case let .failure(err):
os_log("Check status update failed: %s", log: Log.app, err.localizedDescription)
os_log("Team status update failed: %s", log: Log.app, err.localizedDescription)
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions Pareto/Teams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,29 @@ enum Team {
let headers: HTTPHeaders = [
"X-Device-Auth": Defaults[.teamAuth]
]
let url = base + "/\(Defaults[.teamID])/device"
os_log("Requesting %{public}s", url)
return AF.request(
base + "/\(Defaults[.teamID])/device",
url,
method: .put,
parameters: device,
encoder: JSONParameterEncoder.default,
headers: headers
).validate().cURLDescription { cmd in
debugPrint(cmd)
}.response(queue: queue) { data in
os_log("%s", log: Log.api, data.debugDescription)
os_log("%{public}s", log: Log.api, data.debugDescription)
}
}

static func update(withReport report: Report) -> DataRequest {
let headers: HTTPHeaders = [
"X-Device-Auth": Defaults[.teamAuth]
]
let url = base + "/\(Defaults[.teamID])/device"
os_log("Requesting %{public}s", url)
return AF.request(
base + "/\(Defaults[.teamID])/device",
url,
method: .patch,
parameters: report,
encoder: JSONParameterEncoder.default,
Expand All @@ -188,7 +192,7 @@ enum Team {
os_log("Move detected, ticket parsing failed", log: Log.api)
}
} else {
os_log("%s", log: Log.api, data.debugDescription)
os_log("%{public}s", log: Log.api, data.debugDescription)
}
}
}
Expand Down

0 comments on commit 6654b91

Please sign in to comment.