Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added possibility to import profiles even when app doesn't exist on y…
…our computer
  • Loading branch information
adku committed Aug 30, 2019
commit 74bbc63f9d75dc42625e360f65e87418a86cd623
16 changes: 14 additions & 2 deletions PPPC Utility.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
5F90EBDD2319934F00738D09 /* Array+appendIfNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F90EBDC2319934F00738D09 /* Array+appendIfNew.swift */; };
5F95AE0D23158AB5002E0A22 /* TCCProfileImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F95AE0C23158AB5002E0A22 /* TCCProfileImporter.swift */; };
5F95AE0F23158B2D002E0A22 /* TCCProfileImportError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F95AE0E23158B2D002E0A22 /* TCCProfileImportError.swift */; };
5F95AE1623158F03002E0A22 /* SwiftyCMSDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F95AE1523158F03002E0A22 /* SwiftyCMSDecoder.swift */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
5F90EBDC2319934F00738D09 /* Array+appendIfNew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+appendIfNew.swift"; sourceTree = "<group>"; };
5F95AE0C23158AB5002E0A22 /* TCCProfileImporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TCCProfileImporter.swift; sourceTree = "<group>"; };
5F95AE0E23158B2D002E0A22 /* TCCProfileImportError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TCCProfileImportError.swift; sourceTree = "<group>"; };
5F95AE1523158F03002E0A22 /* SwiftyCMSDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftyCMSDecoder.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,6 +101,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5F90EBDB2319931100738D09 /* Extensions */ = {
isa = PBXGroup;
children = (
5F90EBDC2319934F00738D09 /* Array+appendIfNew.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
5F95AE0B23158AB5002E0A22 /* TCCProfileImporter */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -180,6 +190,7 @@
6EC40A1E214EF89600BE4F17 /* View Controllers */,
6EC40A1D214EF87E00BE4F17 /* Model */,
5F95AE0B23158AB5002E0A22 /* TCCProfileImporter */,
5F90EBDB2319931100738D09 /* Extensions */,
);
path = Source;
sourceTree = "<group>";
Expand Down Expand Up @@ -344,6 +355,7 @@
files = (
5F95AE1623158F03002E0A22 /* SwiftyCMSDecoder.swift in Sources */,
6EB86F692151476500FBE634 /* JamfProClient.swift in Sources */,
5F90EBDD2319934F00738D09 /* Array+appendIfNew.swift in Sources */,
6EC40A14214DFB5800BE4F17 /* Model.swift in Sources */,
6EC40A1C214EF87800BE4F17 /* SigningIdentity.swift in Sources */,
6EC40A18214ECF2C00BE4F17 /* UploadViewController.swift in Sources */,
Expand Down Expand Up @@ -553,7 +565,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 483DWKW443;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = Resources/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -575,7 +587,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 483DWKW443;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = Resources/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
35 changes: 35 additions & 0 deletions Source/Extensions/Array+appendIfNew.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Array+appendIfNew.swift
// PPPC Utility
//
// MIT License
//
// Copyright (c) 2018 Jamf Software
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import Foundation
extension Array where Element: Equatable {
mutating func appendIfNew(_ item: Element) {
if !contains(item) {
append(item)
}
}
}
1 change: 1 addition & 0 deletions Source/Model/AppleEventRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AppleEventRule: NSObject {
}

init(source: Executable, destination: Executable, value: Bool) {
super.init()
self.source = source
self.destination = destination
if value{
Expand Down
31 changes: 30 additions & 1 deletion Source/Model/Executable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,38 @@ class Executable: NSObject {
@objc dynamic var displayName: String!
@objc dynamic var identifier: String!
@objc dynamic var codeRequirement: String!

@objc dynamic var policy: Policy = Policy()
@objc dynamic var appleEvents: [AppleEventRule] = []

override init() {
super.init()
}

init(tccPolicy: TCCPolicy, iconPath: String) {
super.init()

self.identifier = tccPolicy.identifier
self.codeRequirement = tccPolicy.codeRequirement
self.iconPath = iconPath
let partNames = tccPolicy.identifier.components(separatedBy: ".")
self.displayName = partNames.last ?? tccPolicy.identifier
}

init(identifier: String, codeRequirement: String, iconPath: String, _ displayName: String? = nil) {
super.init()

self.identifier = identifier
self.codeRequirement = codeRequirement
self.iconPath = iconPath
if let dName = displayName {
self.displayName = dName
} else {
let partNames = identifier.components(separatedBy: ".")
self.displayName = partNames.last ?? identifier
}
}

}


Expand Down
34 changes: 20 additions & 14 deletions Source/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension Model {
}
executable.iconPath = iconURL.path
} else {
executable.iconPath = resourcesURL.appendingPathComponent("AppIcon.icns").path
executable.iconPath = resourcesURL.appendingPathComponent("DefaultAppIcon.icns").path
}

if !FileManager.default.fileExists(atPath: executable.iconPath) {
Expand Down Expand Up @@ -163,19 +163,18 @@ extension Model {
func importProfile(tccProfile: TCCProfile) {
if let content = tccProfile.content.first {

self.removeExecutables()
self.removeSelectedExecutables()

for (key, policies) in content.services {
getExecutablesFromAllPolicies(policies: policies)

for policy in policies {
let executable = getExecutable(bundleIdentifier: policy.identifier)
let executable = getExecutableFromSelectedExecutables(bundleIdentifier: policy.identifier)
if key == ServicesKeys.appleEvents.rawValue {
if let source = executable, let receiverIdentifier = policy.receiverIdentifier,
let destination = findExecutableUsing(bundleIdentifier: receiverIdentifier) {

if let source = executable, let rIdentifier = policy.receiverIdentifier, let rCodeRequirement = policy.receiverCodeRequirement {
let destination = getExecutableFrom(identifier: rIdentifier, codeRequirement: rCodeRequirement)
let appleEvent = AppleEventRule(source: source, destination: destination, value: policy.allowed)
executable?.appleEvents.append(appleEvent)
executable?.appleEvents.appendIfNew(appleEvent)
}
} else {
if policy.allowed {
Expand All @@ -201,7 +200,7 @@ extension Model {
allowed: allowed)
}

func findExecutableUsing(bundleIdentifier: String) -> Executable? {
func findExecutableOnComputerUsing(bundleIdentifier: String) -> Executable? {
if let path = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleIdentifier) {
let pathForURL = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? path
if let fileURL = URL(string: "file://\(pathForURL)") {
Expand All @@ -214,15 +213,14 @@ extension Model {

func getExecutablesFromAllPolicies(policies: [TCCPolicy]) {
for tccPolicy in policies {
if let executable = findExecutableUsing(bundleIdentifier: tccPolicy.identifier) {
if getExecutable(bundleIdentifier: tccPolicy.identifier) == nil {
self.selectedExecutables.append(executable)
}
if getExecutableFromSelectedExecutables(bundleIdentifier: tccPolicy.identifier) == nil {
let executable = getExecutableFrom(identifier: tccPolicy.identifier, codeRequirement: tccPolicy.codeRequirement)
self.selectedExecutables.append(executable)
}
}
}

func getExecutable(bundleIdentifier: String) -> Executable? {
func getExecutableFromSelectedExecutables(bundleIdentifier: String) -> Executable? {
for executable in selectedExecutables {
if (executable.identifier == bundleIdentifier) {
return executable
Expand All @@ -231,7 +229,15 @@ extension Model {
return nil
}

func removeExecutables() {
func getExecutableFrom(identifier: String, codeRequirement: String) -> Executable {
var executable = Executable(identifier: identifier, codeRequirement: codeRequirement, iconPath: IconFilePath.application)
if let destExecutableFromComputer = findExecutableOnComputerUsing(bundleIdentifier: identifier) {
executable = destExecutableFromComputer
}
return executable
}

func removeSelectedExecutables() {
for executable in self.selectedExecutables {
executable.appleEvents = []
executable.policy = Policy()
Expand Down