ruby-jss 1.2.3 → 1.2.4a1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ruby-jss might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/jamf.rb +169 -0
- data/lib/jamf/api/abstract_classes/collection_resource.rb +422 -0
- data/lib/jamf/api/abstract_classes/generic_reference.rb +145 -0
- data/lib/jamf/api/abstract_classes/json_object.rb +1074 -0
- data/lib/jamf/api/abstract_classes/prestage.rb +219 -0
- data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +126 -0
- data/lib/jamf/api/abstract_classes/resource.rb +250 -0
- data/lib/jamf/api/abstract_classes/singleton_resource.rb +87 -0
- data/lib/jamf/api/attribute_classes/ip_address.rb +66 -0
- data/lib/jamf/api/attribute_classes/timestamp.rb +144 -0
- data/lib/jamf/api/connection.rb +734 -0
- data/lib/jamf/api/connection/api_error.rb +111 -0
- data/lib/jamf/api/connection/api_error_styleguide.rb +96 -0
- data/lib/jamf/api/connection/token.rb +220 -0
- data/lib/jamf/api/json_objects/account_prefs.rb +79 -0
- data/lib/jamf/api/json_objects/android_details.rb +139 -0
- data/lib/jamf/api/json_objects/appletv_details.rb +110 -0
- data/lib/jamf/api/json_objects/attachment.rb +68 -0
- data/lib/jamf/api/json_objects/cellular_network.rb +151 -0
- data/lib/jamf/api/json_objects/change_log_entry.rb +77 -0
- data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +67 -0
- data/lib/jamf/api/json_objects/country.rb +51 -0
- data/lib/jamf/api/json_objects/extension_attribute_value.rb +128 -0
- data/lib/jamf/api/json_objects/installed_application.rb +59 -0
- data/lib/jamf/api/json_objects/installed_certificate.rb +53 -0
- data/lib/jamf/api/json_objects/installed_configuration_profile.rb +67 -0
- data/lib/jamf/api/json_objects/installed_ebook.rb +58 -0
- data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +59 -0
- data/lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb +52 -0
- data/lib/jamf/api/json_objects/ios_details.rb +244 -0
- data/lib/jamf/api/json_objects/location.rb +95 -0
- data/lib/jamf/api/json_objects/md_prestage_name.rb +57 -0
- data/lib/jamf/api/json_objects/md_prestage_names.rb +82 -0
- data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +165 -0
- data/lib/jamf/api/json_objects/mobile_device_details.rb +219 -0
- data/lib/jamf/api/json_objects/mobile_device_security.rb +101 -0
- data/lib/jamf/api/json_objects/prestage_assignment.rb +61 -0
- data/lib/jamf/api/json_objects/prestage_location.rb +104 -0
- data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +132 -0
- data/lib/jamf/api/json_objects/prestage_scope.rb +54 -0
- data/lib/jamf/api/json_objects/prestage_sync_status.rb +63 -0
- data/lib/jamf/api/json_objects/purchasing_data.rb +125 -0
- data/lib/jamf/api/mixins/abstract.rb +58 -0
- data/lib/jamf/api/mixins/bulk_deletable.rb +39 -0
- data/lib/jamf/api/mixins/change_log.rb +136 -0
- data/lib/jamf/api/mixins/extendable.rb +75 -0
- data/lib/jamf/api/mixins/immutable.rb +39 -0
- data/lib/jamf/api/mixins/locatable.rb +124 -0
- data/lib/jamf/api/mixins/lockable.rb +48 -0
- data/lib/jamf/api/mixins/referable.rb +92 -0
- data/lib/jamf/api/mixins/searchable.rb +202 -0
- data/lib/jamf/api/mixins/uncreatable.rb +40 -0
- data/lib/jamf/api/mixins/undeletable.rb +40 -0
- data/lib/jamf/api/resources/collection_resources/account.rb +163 -0
- data/lib/jamf/api/resources/collection_resources/building.rb +114 -0
- data/lib/jamf/api/resources/collection_resources/category.rb +82 -0
- data/lib/jamf/api/resources/collection_resources/computer.rb +49 -0
- data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +80 -0
- data/lib/jamf/api/resources/collection_resources/department.rb +79 -0
- data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +45 -0
- data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +274 -0
- data/lib/jamf/api/resources/collection_resources/md_prestage.rb +139 -0
- data/lib/jamf/api/resources/collection_resources/mobile_device.rb +315 -0
- data/lib/jamf/api/resources/collection_resources/script.rb +190 -0
- data/lib/jamf/api/resources/collection_resources/site.rb +77 -0
- data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +131 -0
- data/lib/jamf/api/resources/singleton_resources/authorization.rb +88 -0
- data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +139 -0
- data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +95 -0
- data/lib/jamf/client.rb +301 -0
- data/lib/jamf/client/jamf_binary.rb +132 -0
- data/lib/jamf/client/jamf_helper.rb +298 -0
- data/lib/jamf/client/management_action.rb +114 -0
- data/lib/jamf/compatibility.rb +88 -0
- data/lib/jamf/composer.rb +190 -0
- data/lib/jamf/configuration.rb +281 -0
- data/lib/jamf/exceptions.rb +107 -0
- data/lib/jamf/ruby_extensions.rb +36 -0
- data/lib/jamf/ruby_extensions/array.rb +35 -0
- data/lib/jamf/ruby_extensions/array/predicates.rb +46 -0
- data/lib/jamf/ruby_extensions/array/utils.rb +47 -0
- data/lib/jamf/ruby_extensions/filetest.rb +32 -0
- data/lib/jamf/ruby_extensions/filetest/predicates.rb +46 -0
- data/lib/jamf/ruby_extensions/hash.rb +33 -0
- data/lib/jamf/ruby_extensions/hash/backports.rb +92 -0
- data/lib/jamf/ruby_extensions/ipaddr.rb +37 -0
- data/lib/jamf/ruby_extensions/ipaddr/utils.rb +95 -0
- data/lib/jamf/ruby_extensions/object.rb +30 -0
- data/lib/jamf/ruby_extensions/object/predicates.rb +51 -0
- data/lib/jamf/ruby_extensions/pathname.rb +39 -0
- data/lib/jamf/ruby_extensions/pathname/predicates.rb +50 -0
- data/lib/jamf/ruby_extensions/pathname/utils.rb +75 -0
- data/lib/jamf/ruby_extensions/string.rb +35 -0
- data/lib/jamf/ruby_extensions/string/backports.rb +66 -0
- data/lib/jamf/ruby_extensions/string/conversions.rb +65 -0
- data/lib/jamf/ruby_extensions/string/predicates.rb +47 -0
- data/lib/jamf/utility.rb +423 -0
- data/lib/jamf/validate.rb +224 -0
- data/lib/jamf/version.rb +32 -0
- data/lib/jpapi.rb +26 -0
- data/lib/jss/version.rb +1 -1
- metadata +104 -4
@@ -0,0 +1,139 @@
|
|
1
|
+
# Copyright 2019 Pixar
|
2
|
+
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "Apache License")
|
5
|
+
# with the following modification; you may not use this file except in
|
6
|
+
# compliance with the Apache License and the following modification to it:
|
7
|
+
# Section 6. Trademarks. is deleted and replaced with:
|
8
|
+
#
|
9
|
+
# 6. Trademarks. This License does not grant permission to use the trade
|
10
|
+
# names, trademarks, service marks, or product names of the Licensor
|
11
|
+
# and its affiliates, except as required to comply with Section 4(c) of
|
12
|
+
# the License and to reproduce the content of the NOTICE file.
|
13
|
+
#
|
14
|
+
# You may obtain a copy of the Apache License at
|
15
|
+
#
|
16
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
#
|
18
|
+
# Unless required by applicable law or agreed to in writing, software
|
19
|
+
# distributed under the Apache License with the above modification is
|
20
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
21
|
+
# KIND, either express or implied. See the Apache License for the specific
|
22
|
+
# language governing permissions and limitations under the Apache License.
|
23
|
+
#
|
24
|
+
#
|
25
|
+
|
26
|
+
module Jamf
|
27
|
+
|
28
|
+
# The client checkin settings for the Jamf Pro Server
|
29
|
+
#
|
30
|
+
class ClientCheckInSettings < Jamf::SingletonResource
|
31
|
+
|
32
|
+
# Mix-Ins
|
33
|
+
#####################################
|
34
|
+
|
35
|
+
extend Jamf::ChangeLog
|
36
|
+
include Jamf::ChangeLog
|
37
|
+
|
38
|
+
# Constants
|
39
|
+
#####################################
|
40
|
+
|
41
|
+
UPDATABLE = true
|
42
|
+
|
43
|
+
RSRC_VERSION = 'v1'.freeze
|
44
|
+
|
45
|
+
RSRC_PATH = 'check-in'.freeze
|
46
|
+
|
47
|
+
OBJECT_MODEL = {
|
48
|
+
|
49
|
+
# @!attribute checkInFrequency
|
50
|
+
# @return [integer]
|
51
|
+
checkInFrequency: {
|
52
|
+
class: :integer
|
53
|
+
},
|
54
|
+
|
55
|
+
# @!attribute isCreateHooks
|
56
|
+
# @return [Boolean]
|
57
|
+
isCreateHooks: {
|
58
|
+
class: :boolean
|
59
|
+
},
|
60
|
+
|
61
|
+
# @!attribute isHookLog
|
62
|
+
# @return [Boolean]
|
63
|
+
isHookLog: {
|
64
|
+
class: :boolean
|
65
|
+
},
|
66
|
+
|
67
|
+
# @!attribute isHookPolicies
|
68
|
+
# @return [Boolean]
|
69
|
+
isHookPolicies: {
|
70
|
+
class: :boolean
|
71
|
+
},
|
72
|
+
|
73
|
+
# @!attribute isHookHideRestore
|
74
|
+
# @return [Boolean]
|
75
|
+
isHookHideRestore: {
|
76
|
+
class: :boolean
|
77
|
+
},
|
78
|
+
|
79
|
+
# @!attribute isHookMCX
|
80
|
+
# @return [Boolean]
|
81
|
+
isHookMCX: {
|
82
|
+
class: :boolean
|
83
|
+
},
|
84
|
+
|
85
|
+
# @!attribute isBackgroundHooks
|
86
|
+
# @return [Boolean]
|
87
|
+
isBackgroundHooks: {
|
88
|
+
class: :boolean
|
89
|
+
},
|
90
|
+
|
91
|
+
# @!attribute isHookDisplayStatus
|
92
|
+
# @return [Boolean]
|
93
|
+
isHookDisplayStatus: {
|
94
|
+
class: :boolean
|
95
|
+
},
|
96
|
+
|
97
|
+
# @!attribute isCreateStartupScript
|
98
|
+
# @return [Boolean]
|
99
|
+
isCreateStartupScript: {
|
100
|
+
class: :boolean
|
101
|
+
},
|
102
|
+
|
103
|
+
# @!attribute isStartupLog
|
104
|
+
# @return [Boolean]
|
105
|
+
isStartupLog: {
|
106
|
+
class: :boolean
|
107
|
+
},
|
108
|
+
|
109
|
+
# @!attribute isStartupPolicies
|
110
|
+
# @return [Boolean]
|
111
|
+
isStartupPolicies: {
|
112
|
+
class: :boolean
|
113
|
+
},
|
114
|
+
|
115
|
+
# @!attribute isStartupSSH
|
116
|
+
# @return [Boolean]
|
117
|
+
isStartupSSH: {
|
118
|
+
class: :boolean
|
119
|
+
},
|
120
|
+
|
121
|
+
# @!attribute isStartupMCX
|
122
|
+
# @return [Boolean]
|
123
|
+
isStartupMCX: {
|
124
|
+
class: :boolean
|
125
|
+
},
|
126
|
+
|
127
|
+
# @!attribute isEnableLocalConfigurationProfiles
|
128
|
+
# @return [Boolean]
|
129
|
+
isEnableLocalConfigurationProfiles: {
|
130
|
+
class: :boolean
|
131
|
+
}
|
132
|
+
|
133
|
+
}.freeze # end OBJECT_MODEL
|
134
|
+
|
135
|
+
parse_object_model
|
136
|
+
|
137
|
+
end # class ClientCheckIn
|
138
|
+
|
139
|
+
end # module JAMF
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# Copyright 2019 Pixar
|
2
|
+
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "Apache License")
|
5
|
+
# with the following modification; you may not use this file except in
|
6
|
+
# compliance with the Apache License and the following modification to it:
|
7
|
+
# Section 6. Trademarks. is deleted and replaced with:
|
8
|
+
#
|
9
|
+
# 6. Trademarks. This License does not grant permission to use the trade
|
10
|
+
# names, trademarks, service marks, or product names of the Licensor
|
11
|
+
# and its affiliates, except as required to comply with Section 4(c) of
|
12
|
+
# the License and to reproduce the content of the NOTICE file.
|
13
|
+
#
|
14
|
+
# You may obtain a copy of the Apache License at
|
15
|
+
#
|
16
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
#
|
18
|
+
# Unless required by applicable law or agreed to in writing, software
|
19
|
+
# distributed under the Apache License with the above modification is
|
20
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
21
|
+
# KIND, either express or implied. See the Apache License for the specific
|
22
|
+
# language governing permissions and limitations under the Apache License.
|
23
|
+
#
|
24
|
+
#
|
25
|
+
|
26
|
+
module Jamf
|
27
|
+
|
28
|
+
# The device re-enrollment settings for the Jamf Pro Server
|
29
|
+
#
|
30
|
+
class ReEnrollmentSettings < Jamf::SingletonResource
|
31
|
+
|
32
|
+
# Mix-Ins
|
33
|
+
#####################################
|
34
|
+
|
35
|
+
include Jamf::ChangeLog
|
36
|
+
|
37
|
+
# Constants
|
38
|
+
#####################################
|
39
|
+
|
40
|
+
RSRC_VERSION = 'v1'.freeze
|
41
|
+
|
42
|
+
RSRC_PATH = 'reenrollment'.freeze
|
43
|
+
|
44
|
+
FLUSH_MDM_QUEUE_NOTHING = 'DELETE_NOTHING'.freeze
|
45
|
+
FLUSH_MDM_QUEUE_ERRORS = 'DELETE_ERRORS'.freeze
|
46
|
+
FLUSH_MDM_QUEUE_NOT_ACKD = 'DELETE_EVERYTHING_EXCEPT_ACKNOWLEDGED'.freeze
|
47
|
+
FLUSH_MDM_QUEUE_EVERYTHING = 'DELETE_EVERYTHING'.freeze
|
48
|
+
|
49
|
+
FLUSH_MDM_QUEUE_OPTIONS = [
|
50
|
+
FLUSH_MDM_QUEUE_NOTHING,
|
51
|
+
FLUSH_MDM_QUEUE_ERRORS,
|
52
|
+
FLUSH_MDM_QUEUE_NOT_ACKD,
|
53
|
+
FLUSH_MDM_QUEUE_EVERYTHING
|
54
|
+
].freeze
|
55
|
+
|
56
|
+
OBJECT_MODEL = {
|
57
|
+
|
58
|
+
# @!attribute isFlushPolicyHistoryEnabled
|
59
|
+
# @return [Boolean]
|
60
|
+
isFlushPolicyHistoryEnabled: {
|
61
|
+
class: :boolean
|
62
|
+
},
|
63
|
+
|
64
|
+
# @!attribute isFlushLocationInformationEnabled
|
65
|
+
# @return [Boolean]
|
66
|
+
isFlushLocationInformationEnabled: {
|
67
|
+
class: :boolean
|
68
|
+
},
|
69
|
+
|
70
|
+
# @!attribute isFlushLocationInformationHistoryEnabled
|
71
|
+
# @return [Boolean]
|
72
|
+
isFlushLocationInformationHistoryEnabled: {
|
73
|
+
class: :boolean
|
74
|
+
},
|
75
|
+
|
76
|
+
# @!attribute isFlushExtensionAttributesEnabled
|
77
|
+
# @return [Boolean]
|
78
|
+
isFlushExtensionAttributesEnabled: {
|
79
|
+
class: :boolean
|
80
|
+
},
|
81
|
+
|
82
|
+
# @!attribute flushMDMQueue
|
83
|
+
# @param [Symbol] a key from ReEnrollment::FLUSH_MDM_QUEUE_OPTIONS
|
84
|
+
# @return [Symbol]
|
85
|
+
flushMDMQueue: {
|
86
|
+
class: :string,
|
87
|
+
enum: FLUSH_MDM_QUEUE_OPTIONS
|
88
|
+
}
|
89
|
+
|
90
|
+
}.freeze # end OBJECT_MODEL
|
91
|
+
parse_object_model
|
92
|
+
|
93
|
+
end # class ReEnrollment
|
94
|
+
|
95
|
+
end # module JAMF
|
data/lib/jamf/client.rb
ADDED
@@ -0,0 +1,301 @@
|
|
1
|
+
### Copyright 2019 Pixar
|
2
|
+
|
3
|
+
###
|
4
|
+
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
5
|
+
### with the following modification; you may not use this file except in
|
6
|
+
### compliance with the Apache License and the following modification to it:
|
7
|
+
### Section 6. Trademarks. is deleted and replaced with:
|
8
|
+
###
|
9
|
+
### 6. Trademarks. This License does not grant permission to use the trade
|
10
|
+
### names, trademarks, service marks, or product names of the Licensor
|
11
|
+
### and its affiliates, except as required to comply with Section 4(c) of
|
12
|
+
### the License and to reproduce the content of the NOTICE file.
|
13
|
+
###
|
14
|
+
### You may obtain a copy of the Apache License at
|
15
|
+
###
|
16
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
###
|
18
|
+
### Unless required by applicable law or agreed to in writing, software
|
19
|
+
### distributed under the Apache License with the above modification is
|
20
|
+
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
21
|
+
### KIND, either express or implied. See the Apache License for the specific
|
22
|
+
### language governing permissions and limitations under the Apache License.
|
23
|
+
###
|
24
|
+
###
|
25
|
+
|
26
|
+
###
|
27
|
+
module JSS
|
28
|
+
|
29
|
+
# This class represents a Jamf/JSS Client computer, on which
|
30
|
+
# this code is running.
|
31
|
+
#
|
32
|
+
# Since the class represents the current machine, there's no need
|
33
|
+
# to make an instance of it, all methods are class methods.
|
34
|
+
#
|
35
|
+
# At the moment, only Macintosh computers are supported.
|
36
|
+
#
|
37
|
+
# TODO: convert this to a module, since that's how it's used.
|
38
|
+
#
|
39
|
+
class Client
|
40
|
+
|
41
|
+
# Constants
|
42
|
+
#####################################
|
43
|
+
|
44
|
+
# The Pathname to the preferences plist used by the jamf binary
|
45
|
+
JAMF_PLIST = Pathname.new '/Library/Preferences/com.jamfsoftware.jamf.plist'
|
46
|
+
|
47
|
+
# The Pathname to the JAMF support folder
|
48
|
+
JAMF_SUPPORT_FOLDER = Pathname.new '/Library/Application Support/JAMF'
|
49
|
+
|
50
|
+
# The JAMF receipts folder, where package installs are tracked.
|
51
|
+
RECEIPTS_FOLDER = JAMF_SUPPORT_FOLDER + 'Receipts'
|
52
|
+
|
53
|
+
# The JAMF downloads folder
|
54
|
+
DOWNLOADS_FOLDER = JAMF_SUPPORT_FOLDER + 'Downloads'
|
55
|
+
|
56
|
+
# The bin folder inside the Jamf support folder
|
57
|
+
SUPPORT_BIN_FOLDER = JAMF_SUPPORT_FOLDER + 'bin'
|
58
|
+
|
59
|
+
# The bin folder with the jamf binary and a few other things
|
60
|
+
USR_LOCAL_BIN_FOLDER = Pathname.new '/usr/local/jamf/bin'
|
61
|
+
|
62
|
+
# This command gives raw info about console users
|
63
|
+
CONSOLE_USERS_SCUTIL_CMD = 'echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil'.freeze
|
64
|
+
|
65
|
+
# ignore console user = root (loginwindow)
|
66
|
+
ROOT_USER = 'root'.freeze
|
67
|
+
|
68
|
+
# ignore primary console user loginwindow
|
69
|
+
LOGINWINDOW_USER = 'loginwindow'.freeze
|
70
|
+
|
71
|
+
# The end of the path to the Self Service Executable.
|
72
|
+
# Used to figure out who's running Self Service.app
|
73
|
+
SELF_SERVICE_EXECUTABLE_END = '/Self Service.app/Contents/MacOS/Self Service'.freeze
|
74
|
+
|
75
|
+
# the ps command used to figure out who's running Self Service
|
76
|
+
PS_USER_COMM = 'ps -A -o user,comm'.freeze
|
77
|
+
|
78
|
+
# the path to a users byhost folder from home
|
79
|
+
USER_PREFS_BYHOST_FOLDER = 'Library/Preferences/ByHost/'
|
80
|
+
|
81
|
+
# Class Methods
|
82
|
+
#####################################
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
# Get the current IP address as a String.
|
87
|
+
#
|
88
|
+
# This handy code doesn't acutally make a UDP connection,
|
89
|
+
# it just starts to set up the connection, then uses that to get
|
90
|
+
# the local IP.
|
91
|
+
#
|
92
|
+
# Lifted gratefully from
|
93
|
+
# http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
|
94
|
+
#
|
95
|
+
# @return [String] the current IP address.
|
96
|
+
#
|
97
|
+
def self.my_ip_address
|
98
|
+
# turn off reverse DNS resolution temporarily
|
99
|
+
# @note the 'socket' library has already been required by 'rest-client'
|
100
|
+
orig = Socket.do_not_reverse_lookup
|
101
|
+
Socket.do_not_reverse_lookup = true
|
102
|
+
|
103
|
+
UDPSocket.open do |s|
|
104
|
+
s.connect '192.168.0.0', 1
|
105
|
+
s.addr.last
|
106
|
+
end
|
107
|
+
ensure
|
108
|
+
Socket.do_not_reverse_lookup = orig
|
109
|
+
end
|
110
|
+
|
111
|
+
# Is the jamf binary installed?
|
112
|
+
#
|
113
|
+
# @return [Boolean] is the jamf binary installed?
|
114
|
+
#
|
115
|
+
def self.installed?
|
116
|
+
JAMF_BINARY.executable?
|
117
|
+
end
|
118
|
+
|
119
|
+
# What version of the jamf binary is installed?
|
120
|
+
#
|
121
|
+
# @return [String,nil] the version of the jamf binary installed on this client, nil if not installed
|
122
|
+
#
|
123
|
+
def self.jamf_version
|
124
|
+
installed? ? run_jamf(:version).chomp.split('=')[1] : nil
|
125
|
+
end
|
126
|
+
|
127
|
+
# the URL to the jss for this client
|
128
|
+
#
|
129
|
+
# @return [String] the url to the JSS for this client
|
130
|
+
#
|
131
|
+
def self.jss_url
|
132
|
+
@url = jamf_plist['jss_url']
|
133
|
+
return nil if @url.nil?
|
134
|
+
@url =~ %r{(https?)://(.+):(\d+)/}
|
135
|
+
@protocol = Regexp.last_match(1)
|
136
|
+
@server = Regexp.last_match(2)
|
137
|
+
@port = Regexp.last_match(3)
|
138
|
+
@url
|
139
|
+
end
|
140
|
+
|
141
|
+
# The JSS server hostname for this client
|
142
|
+
#
|
143
|
+
# @return [String] the JSS server for this client
|
144
|
+
#
|
145
|
+
def self.jss_server
|
146
|
+
jss_url
|
147
|
+
@server
|
148
|
+
end
|
149
|
+
|
150
|
+
# The protocol for JSS connections for this client
|
151
|
+
#
|
152
|
+
# @return [String] the protocol to the JSS for this client, "http" or "https"
|
153
|
+
#
|
154
|
+
def self.jss_protocol
|
155
|
+
jss_url
|
156
|
+
@protocol
|
157
|
+
end
|
158
|
+
|
159
|
+
# The port number for JSS connections for this client
|
160
|
+
#
|
161
|
+
# @return [Integer] the port to the JSS for this client
|
162
|
+
#
|
163
|
+
def self.jss_port
|
164
|
+
jss_url
|
165
|
+
@port
|
166
|
+
end
|
167
|
+
|
168
|
+
# The contents of the JAMF plist
|
169
|
+
#
|
170
|
+
# @return [Hash] the parsed contents of the JAMF_PLIST if it exists,
|
171
|
+
# an empty hash if not
|
172
|
+
#
|
173
|
+
def self.jamf_plist
|
174
|
+
return {} unless JAMF_PLIST.file?
|
175
|
+
JSS.parse_plist JAMF_PLIST
|
176
|
+
end
|
177
|
+
|
178
|
+
# All the JAMF receipts on this client
|
179
|
+
#
|
180
|
+
# @return [Array<Pathname>] an array of Pathnames for all regular files in the jamf receipts folder
|
181
|
+
#
|
182
|
+
def self.receipts
|
183
|
+
raise JSS::NoSuchItemError, "The JAMF Receipts folder doesn't exist on this computer." unless RECEIPTS_FOLDER.exist?
|
184
|
+
RECEIPTS_FOLDER.children.select(&:file?)
|
185
|
+
end
|
186
|
+
|
187
|
+
# Is the JSS available right now?
|
188
|
+
#
|
189
|
+
# @return [Boolean] is the JSS available now?
|
190
|
+
#
|
191
|
+
def self.jss_available?
|
192
|
+
run_jamf :checkJSSConnection, '-retry 1'
|
193
|
+
$CHILD_STATUS.exitstatus.zero?
|
194
|
+
end
|
195
|
+
|
196
|
+
# The JSS::Computer object for this computer
|
197
|
+
#
|
198
|
+
# @return [JSS::Computer,nil] The JSS record for this computer, nil if not in the JSS
|
199
|
+
#
|
200
|
+
def self.jss_record
|
201
|
+
JSS::Computer.fetch udid: udid
|
202
|
+
rescue JSS::NoSuchItemError
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
|
206
|
+
# The UUID for this computer via system_profiler
|
207
|
+
#
|
208
|
+
# @return [String] the UUID/UDID for this computer
|
209
|
+
#
|
210
|
+
def self.udid
|
211
|
+
hardware_data['platform_UUID']
|
212
|
+
end
|
213
|
+
|
214
|
+
# The serial number for this computer via system_profiler
|
215
|
+
#
|
216
|
+
# @return [String] the serial number for this computer
|
217
|
+
#
|
218
|
+
def self.serial_number
|
219
|
+
hardware_data['serial_number']
|
220
|
+
end
|
221
|
+
|
222
|
+
# The parsed HardwareDataType output from system_profiler
|
223
|
+
#
|
224
|
+
# @return [Hash] the HardwareDataType data from the system_profiler command
|
225
|
+
#
|
226
|
+
def self.hardware_data
|
227
|
+
raw = `/usr/sbin/system_profiler SPHardwareDataType -xml 2>/dev/null`
|
228
|
+
JSS.parse_plist(raw)[0]['_items'][0]
|
229
|
+
end
|
230
|
+
|
231
|
+
# Who's currently got an active GUI session? - might be
|
232
|
+
# more than one if Fast User Switching is in use.
|
233
|
+
#
|
234
|
+
# @return [Array<String>] The current users with GUI sessions
|
235
|
+
#
|
236
|
+
def self.console_users
|
237
|
+
output = `#{CONSOLE_USERS_SCUTIL_CMD}`
|
238
|
+
userlines = output.lines.select { |l| l =~ /SessionUserNameKey\s*:/ }
|
239
|
+
userlines.map! { |ul| ul.split(':').last.strip }
|
240
|
+
userlines.reject { |un| un == ROOT_USER }
|
241
|
+
end
|
242
|
+
|
243
|
+
# Which console user is using the primary GUI console?
|
244
|
+
# Returns nil if the primary GUI console is at the login window.
|
245
|
+
#
|
246
|
+
# @return [String,nil] The login name of the user is using the primary
|
247
|
+
# GUI console, or nil if at the login window.
|
248
|
+
#
|
249
|
+
def self.primary_console_user
|
250
|
+
`#{CONSOLE_USERS_SCUTIL_CMD}` =~ /^\s*Name : (\S+)$/
|
251
|
+
user = Regexp.last_match(1)
|
252
|
+
user == LOGINWINDOW_USER ? nil : user
|
253
|
+
end
|
254
|
+
|
255
|
+
# alias for primary_console_user
|
256
|
+
def self.console_user
|
257
|
+
primary_console_user
|
258
|
+
end
|
259
|
+
|
260
|
+
# Who's currently running Self Service.app? - might be
|
261
|
+
# more than one if Fast User Switching is in use.
|
262
|
+
#
|
263
|
+
# @return [Array<String>] The current users running Self Service.app
|
264
|
+
#
|
265
|
+
def self.self_service_users
|
266
|
+
ss_userlines = `#{PS_USER_COMM}`.lines.select { |l| l.include? SELF_SERVICE_EXECUTABLE_END }
|
267
|
+
ss_userlines.map { |ssl| ssl.split(' ').first }
|
268
|
+
end
|
269
|
+
|
270
|
+
# @param user[String, nil] The user to query, the current user if nil.
|
271
|
+
#
|
272
|
+
# @return [Boolean, nil] Is 'Do Not Disturb' enabled for the user?
|
273
|
+
# nil if unknown/not-applicable
|
274
|
+
#
|
275
|
+
def self.do_not_disturb?(user = nil)
|
276
|
+
home = user ? homedir(user) : Dir.home
|
277
|
+
myudid = udid
|
278
|
+
nc_prefs_file = Pathname.new "#{home}/#{USER_PREFS_BYHOST_FOLDER}/com.apple.notificationcenterui.#{myudid}.plist"
|
279
|
+
return nil unless nc_prefs_file.readable?
|
280
|
+
JSS.parse_plist(nc_prefs_file)['doNotDisturb']
|
281
|
+
end
|
282
|
+
|
283
|
+
# The home dir of the specified user, nil if
|
284
|
+
# no homedir in local dscl.
|
285
|
+
#
|
286
|
+
# @param user[String] the user whose homedir to look up
|
287
|
+
#
|
288
|
+
# @return [Pathname, nil] The user's homedir or nil if no such user
|
289
|
+
#
|
290
|
+
def self.homedir(user)
|
291
|
+
dir = `/usr/bin/dscl . -read /Users/#{user} NFSHomeDirectory 2>/dev/null`.chomp.split(': ').last
|
292
|
+
dir ? Pathname.new(dir) : nil
|
293
|
+
end
|
294
|
+
|
295
|
+
end # class Client
|
296
|
+
|
297
|
+
end # module
|
298
|
+
|
299
|
+
require 'jamf-client/jamf_binary'
|
300
|
+
require 'jamf-client/jamf_helper'
|
301
|
+
require 'jamf-client/management_action'
|