Skip to content

Commit 9aec350

Browse files
committed
Add MDM URL detection
1 parent 89eca0e commit 9aec350

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

SupportCompanion.xcodeproj/project.pbxproj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
F60FAB742CE8D40A00ECAC53 /* AlertToast in Frameworks */ = {isa = PBXBuildFile; productRef = F60FAB732CE8D40A00ECAC53 /* AlertToast */; };
1111
F60FAB872CEA108A00ECAC53 /* SidebarConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = F60FAB862CEA108A00ECAC53 /* SidebarConfig.swift */; };
1212
F64927372CF9EA8D00C34D90 /* com.github.macadmins.SupportCompanion.helper in CopyFiles */ = {isa = PBXBuildFile; fileRef = F6F8AE7D2CE345A8009B0A1F /* com.github.macadmins.SupportCompanion.helper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
13+
F6575A992D117108007DBC83 /* ExecutionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6F8AE9C2CE34E54009B0A1F /* ExecutionService.swift */; };
14+
F6575A9A2D117114007DBC83 /* HelperRemoteProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6F8AE9E2CE34E72009B0A1F /* HelperRemoteProvider.swift */; };
15+
F6575A9D2D117141007DBC83 /* SupportCompanionErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6F8AE952CE34B81009B0A1F /* SupportCompanionErrors.swift */; };
1316
F6890EEB2CFF326D00244985 /* SupportCompanionCLI in CopyFiles */ = {isa = PBXBuildFile; fileRef = F6890EE22CFF308F00244985 /* SupportCompanionCLI */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
1417
F6890EEC2CFF330D00244985 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E4D1D42CE4CE1E003EB8C0 /* Preferences.swift */; };
1518
F6890EED2CFF331400244985 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6A4E0F62CEC9DFC002B4D74 /* Constants.swift */; };
@@ -118,6 +121,16 @@
118121
);
119122
target = F6F8AE7C2CE345A8009B0A1F /* com.github.macadmins.SupportCompanion.helper */;
120123
};
124+
F6575A9C2D117133007DBC83 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
125+
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
126+
membershipExceptions = (
127+
HelperConstans.swift,
128+
HelperProtocol.swift,
129+
"OSStatus+Extensions.swift",
130+
RemoteApplicationProtocol.swift,
131+
);
132+
target = F6890EE12CFF308F00244985 /* SupportCompanionCLI */;
133+
};
121134
F6890EEF2CFF332200244985 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
122135
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
123136
membershipExceptions = (
@@ -129,6 +142,7 @@
129142
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
130143
membershipExceptions = (
131144
Logger.swift,
145+
MDMHelpers.swift,
132146
);
133147
target = F6890EE12CFF308F00244985 /* SupportCompanionCLI */;
134148
};
@@ -208,7 +222,7 @@
208222
F6E4D2842CE781B9003EB8C0 /* Components */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Components; sourceTree = "<group>"; };
209223
F6E72E642CE3DEC300D78336 /* Models */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (F6890EEF2CFF332200244985 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Models; sourceTree = "<group>"; };
210224
F6EB39E72CE1EE2800517FCD /* ViewModels */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (F6A4E0E52CEBD7D8002B4D74 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = ViewModels; sourceTree = "<group>"; };
211-
F6F8AE7E2CE345A8009B0A1F /* Helper */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (F6A4E0E82CEBD7F8002B4D74 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, F649281C2CFA02C000C34D90 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Helper; sourceTree = "<group>"; };
225+
F6F8AE7E2CE345A8009B0A1F /* Helper */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (F6A4E0E82CEBD7F8002B4D74 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, F649281C2CFA02C000C34D90 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, F6575A9C2D117133007DBC83 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Helper; sourceTree = "<group>"; };
212226
/* End PBXFileSystemSynchronizedRootGroup section */
213227

214228
/* Begin PBXFrameworksBuildPhase section */
@@ -469,6 +483,9 @@
469483
buildActionMask = 2147483647;
470484
files = (
471485
F6890EEC2CFF330D00244985 /* Preferences.swift in Sources */,
486+
F6575A9D2D117141007DBC83 /* SupportCompanionErrors.swift in Sources */,
487+
F6575A992D117108007DBC83 /* ExecutionService.swift in Sources */,
488+
F6575A9A2D117114007DBC83 /* HelperRemoteProvider.swift in Sources */,
472489
F6890EED2CFF331400244985 /* Constants.swift in Sources */,
473490
);
474491
runOnlyForDeploymentPostprocessing = 0;

SupportCompanion/Helpers/MDMHelpers.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ func getMDMEnrollmentTime() async -> String {
3131
return "Unknown"
3232
}
3333

34+
func getMDMUrl() async -> String {
35+
do {
36+
let commandOutput = try await ExecutionService.executeCommand(
37+
"/usr/bin/profiles",
38+
with: ["status", "-type", "enrollment"]
39+
)
40+
41+
// Process the command output
42+
let lines = commandOutput.split(separator: "\n")
43+
for line in lines {
44+
if line.contains("MDM server") {
45+
let url = line.split(separator: "https://").last?.trimmingCharacters(in: .whitespacesAndNewlines)
46+
return url ?? "Unknown"
47+
}
48+
}
49+
} catch {
50+
Logger.shared.logError("Error getting MDM URL: \(error)")
51+
}
52+
53+
return "Unknown"
54+
}
55+
3456
func getMDMStatus() async -> [String: String] {
3557
var mdmDetails: [String: String] = ["ABM": "", "Enrolled": "", "EnrollmentDate": ""]
3658

SupportCompanion/Preferences.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ class Preferences: ObservableObject {
134134

135135
@AppStorage("ElevationSeverity") var elevationSeverity: Int = 6 // Default to "Informational"
136136

137+
var mdm: String = "Unknown"
138+
137139
init() {
138140
ensureDefaultsInitialized()
139-
141+
140142
NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification)
141143
.sink { [weak self] _ in
142144
guard let self = self else { return }
@@ -155,11 +157,12 @@ class Preferences: ObservableObject {
155157
self?.loadHiddenActions()
156158
self?.loadDesktopInfoHideItems()
157159
}
158-
159-
detectModeAndSetLogFolders()
160+
Task {
161+
await detectModeAndSetLogFolders()
162+
}
160163
}
161164

162-
private func detectModeAndSetLogFolders() {
165+
private func detectModeAndSetLogFolders() async {
163166
//if !logFolders.isEmpty {
164167
// Logger.shared.logDebug("Log folders already initialized: \(logFolders)")
165168
// return
@@ -173,12 +176,23 @@ class Preferences: ObservableObject {
173176
let fileManager = FileManager.default
174177
let companyPortalExists = fileManager.fileExists(atPath: Constants.AppPaths.companyPortal)
175178
let mscExists = fileManager.fileExists(atPath: Constants.AppPaths.MSC)
179+
let mdmUrl = await getMDMUrl()
180+
181+
print(mdmUrl)
176182

183+
if mdmUrl != "Unknown" {
184+
Logger.shared.logDebug("MDM URL detected: \(mdmUrl)")
185+
if mdmUrl.contains("i.manage.microsoft.com") {
186+
Logger.shared.logDebug("MDM URL contains i.manage.microsoft.com, setting mdm to Intune.")
187+
mdm = "Intune"
188+
}
189+
}
190+
177191
if companyPortalExists && mscExists {
178192
Logger.shared.logDebug("Both Munki and Company Portal paths exist, defaulting to Munki mode.")
179193
mode = Constants.modes.munki
180194
logFolders = ["/Library/Managed Installs/Logs", "/Library/Logs/Microsoft"]
181-
} else if companyPortalExists {
195+
} else if companyPortalExists && mdm == "Intune" {
182196
Logger.shared.logDebug("Company Portal path exists, setting mode to Intune.")
183197
mode = Constants.modes.intune
184198
logFolders = ["/Library/Logs/Microsoft"]
@@ -322,7 +336,10 @@ class Preferences: ObservableObject {
322336
executeShellCommand(command: writeCommand)
323337
}
324338

325-
detectModeAndSetLogFolders()
339+
Task {
340+
await detectModeAndSetLogFolders()
341+
}
342+
326343
Logger.shared.logDebug("Defaults have been reset using defaults write.")
327344
}
328345

0 commit comments

Comments
 (0)