-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjamf_controller.php
executable file
·351 lines (310 loc) · 10.5 KB
/
jamf_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
/**
* Jamf module class
*
* @package munkireport
* @author tuxudo
**/
class jamf_controller extends Module_controller
{
public function __construct()
{
// No authentication, the client needs to get here
// Store module path
$this->module_path = dirname(__FILE__);
// Add local config
configAppendFile(__DIR__ . '/config.php');
}
public function index()
{
echo "You've loaded the Jamf module!";
}
// Add the admin page
public function admin()
{
$obj = new View();
$obj->view('jamf_admin', [], $this->module_path.'/views/');
}
/**
* Get enrolled via DEP info
*
* @author tuxudo
**/
public function get_enrolled_via_dep()
{
$sql = "SELECT COUNT(CASE WHEN `enrolled_via_dep` = '1' THEN 1 END) AS Yes,
COUNT(CASE WHEN `enrolled_via_dep` = '0' THEN 1 END) AS No
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get user approved enrollment info
*
* @author tuxudo
**/
public function get_user_approved_enrollment()
{
$sql = "SELECT COUNT(CASE WHEN `user_approved_enrollment` = '1' THEN 1 END) AS Yes,
COUNT(CASE WHEN `user_approved_enrollment` = '0' THEN 1 END) AS No
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get user approved mdm info
*
* @author tuxudo
**/
public function get_user_approved_mdm()
{
$sql = "SELECT COUNT(CASE WHEN `user_approved_mdm` = '1' THEN 1 END) AS Yes,
COUNT(CASE WHEN `user_approved_mdm` = '0' THEN 1 END) AS No
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get mdm capable user info
*
* @author tuxudo
**/
public function get_mdm_capable()
{
$sql = "SELECT COUNT(CASE WHEN `mdm_capable` = '1' THEN 1 END) AS Yes,
COUNT(CASE WHEN `mdm_capable` = '0' THEN 1 END) AS No
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get purchased info
*
* @author tuxudo
**/
public function get_purchased_leased()
{
$sql = "SELECT COUNT(CASE WHEN `is_purchased` = '1' THEN 1 END) AS Purchased,
COUNT(CASE WHEN `is_leased` = '1' THEN 1 END) AS Leased
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get pending failed info
*
* @author tuxudo
**/
public function get_pending_failed()
{
$sql = "SELECT COUNT(CASE WHEN `comands_completed` = '1' THEN 1 END) AS Completed,
COUNT(CASE WHEN `comands_pending` = '1' THEN 1 END) AS Pending,
COUNT(CASE WHEN `comands_failed` = '1' THEN 1 END) AS Failed
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get automatic login info
*
* @author tuxudo
**/
public function get_automatic_login_disabled()
{
$sql = "SELECT COUNT(CASE WHEN `disable_automatic_login` = '1' THEN 1 END) AS Yes,
COUNT(CASE WHEN `disable_automatic_login` = '0' THEN 1 END) AS No
FROM `jamf`
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView(current($queryobj->query($sql)));
}
/**
* Get XProtect version for widget
*
* @return void
* @author tuxudo
**/
public function get_xprotect_version()
{
$sql = "SELECT COUNT(CASE WHEN xprotect_version <> '' AND xprotect_version IS NOT NULL THEN 1 END) AS count, xprotect_version
FROM jamf
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY xprotect_version
ORDER BY count DESC";
$out = [];
$queryobj = new Jamf_model;
foreach ($queryobj->query($sql) as $obj) {
if ("$obj->count" !== "0") {
$obj->xprotect_version = $obj->xprotect_version ? $obj->xprotect_version : 'Unknown';
$out[] = $obj;
}
}
jsonView($out);
}
/**
* Get Jamf version for widget
*
* @return void
* @author tuxudo
**/
public function get_jamf_version()
{
$sql = "SELECT COUNT(CASE WHEN jamf_version <> '' AND jamf_version IS NOT NULL THEN 1 END) AS count, jamf_version
FROM jamf
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY jamf_version
ORDER BY count DESC";
$out = [];
$queryobj = new Jamf_model;
foreach ($queryobj->query($sql) as $obj) {
if ("$obj->count" !== "0") {
$obj->jamf_version = $obj->jamf_version ? $obj->jamf_version : 'Unknown';
$out[] = $obj;
}
}
jsonView($out);
}
/**
* Get departments for widget
*
* @return void
* @author tuxudo
**/
public function get_jamf_departments()
{
$sql = "SELECT COUNT(CASE WHEN department <> '' AND department IS NOT NULL THEN 1 END) AS count, department
FROM jamf
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY department
ORDER BY count DESC";
$out = [];
$queryobj = new Jamf_model;
foreach ($queryobj->query($sql) as $obj) {
if ("$obj->count" !== "0") {
$obj->department = $obj->department ? $obj->department : 'Unknown';
$out[] = $obj;
}
}
jsonView($out);
}
/**
* Get buildings for widget
*
* @return void
* @author tuxudo
**/
public function get_jamf_buildings()
{
$sql = "SELECT COUNT(CASE WHEN building <> '' AND building IS NOT NULL THEN 1 END) AS count, building
FROM jamf
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY building
ORDER BY count DESC";
$out = [];
$queryobj = new Jamf_model;
foreach ($queryobj->query($sql) as $obj) {
if ("$obj->count" !== "0") {
$obj->building = $obj->building ? $obj->building : 'Unknown';
$out[] = $obj;
}
}
jsonView($out);
}
/**
* REST API for retrieving last checkin data for widget
* @tuxudo
*
**/
public function get_last_checkin()
{
$currentdate = date_timestamp_get(date_create());
$week = $currentdate - 604800;
$month = $currentdate - 2592000;
$sql = "SELECT COUNT( CASE WHEN ".$month." >= last_contact_time_epoch THEN 1 END) AS red,
COUNT( CASE WHEN ".$week." >= last_contact_time_epoch AND last_contact_time_epoch > ".$month." THEN 1 END) AS yellow,
COUNT( CASE WHEN last_contact_time_epoch > ".$week." AND last_contact_time_epoch > 0 THEN 1 END) AS green
FROM jamf
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$queryobj = new Jamf_model();
jsonView($queryobj->query($sql));
}
/**
* Pull in Jamf data for all serial numbers :D
*
* @return void
* @author tuxudo
**/
public function pull_all_jamf_data($incoming_serial = '')
{
// Check if we are returning a list of all serials or processing a serial
// Returns either a list of all serial numbers in MunkiReport OR
// a JSON of what serial number was just ran with the status of the run
if ( $incoming_serial == ''){
// Get all the serial numbers in an object
$machine = new Jamf_model();
$filter = get_machine_group_filter();
$sql = "SELECT machine.serial_number
FROM machine
LEFT JOIN reportdata USING (serial_number)
$filter";
// Loop through each serial number for processing
$out = array();
foreach ($machine->query($sql) as $serialobj) {
$out[] = $serialobj->serial_number;
}
jsonView($out);
} else {
$jamf = new Jamf_model($incoming_serial);
$jamf_status = $jamf->run_jamf_stats();
// Check if machine exists in Jamf
if ($jamf_status->rs['jamf_id'] == 0 ){
$out = array("serial"=>$incoming_serial,"status"=>"Machine not found in Jamf!");
} else {
$out = array("serial"=>$incoming_serial,"status"=>"Machine processed");
}
jsonView($out);
}
}
/**
* Force data pull from Jamf
*
* @return void
* @author tuxudo
**/
public function recheck_jamf($serial = '')
{
if (authorized_for_serial($serial)) {
$jamf = new Jamf_model($serial);
$jamf->run_jamf_stats();
}
redirect("clients/detail/$serial#tab_jamf-tab");
}
/**
* Get Jamf information for serial_number
*
* @param string $serial serial number
**/
public function get_data($serial_number = '')
{
$jamf = new Jamf_model($serial_number);
jsonView($jamf->rs);
}
} // End class jamf_module