-
Notifications
You must be signed in to change notification settings - Fork 3
/
integrations.gs
119 lines (97 loc) · 3.09 KB
/
integrations.gs
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
function invokeMunkiInstall(udid) {
if ( !udid ) {
var device = getDeviceDataForSelectedRow();
if ( device ) {
var udid = device["udid"];
if ( udid ) {
var serial = device["serial_number"];
var tag = device["asset_tag"];
var template = HtmlService.createTemplateFromFile('munki.html');
template.tag = tag;
template.serial = serial;
template.udid = udid;
var html = template.evaluate()
.setWidth(500)
.setHeight(400)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, ' ');
} else {
var ui = SpreadsheetApp.getUi();
ui.alert('Unable to determine device UUID.', 'Please make sure a device row is selected, and the device is currently enrolled.', ui.ButtonSet.OK);
return;
}
} else {
var ui = SpreadsheetApp.getUi();
ui.alert('Unable to determine device UUID.', 'Please make sure a device row is selected, and the device is currently enrolled.', ui.ButtonSet.OK);
return;
}
}
}
function startMDMInvokedInstall(form) {
var udid = form.udid;
var pkg = form.pkg;
if ( !pkg ) {
return;
}
var properties = PropertiesService.getScriptProperties();
var mdmInvoked = properties.getProperty('MDM_INVOKED');
if ( mdmInvoked ) {
mdmInvoked = JSON.parse(mdmInvoked);
} else {
mdmInvoked = {};
}
if ( mdmInvoked[udid] ) {
mdmInvoked[udid].push(pkg);
} else {
mdmInvoked[udid] = [pkg];
}
properties.setProperty('MDM_INVOKED', JSON.stringify(mdmInvoked));
var response = installApplication(SERVER_URL + "/repo/MDM_Invoked_Munki_Software_Install.plist", udid);
}
function processInstallApplicationRequest(parameters) {
var udid = parameters["udid"];
if ( udid ) {
udid = udid[0];
}
var serial = parameters["serial"];
if ( serial ) {
serial = serial[0];
}
var vpp = parameters["vpp"];
if ( vpp ) {
for ( var i=0; i<vpp.length; i++ ) {
if ( vpp[i] == "all_assigned" ) {
if ( !serial ) {
var serial = getSerialForUDID(udid);
}
if ( serial ) {
var response = installAllVppAppsForDevice(serial);
} else {
var response = {"udid": udid, "status": "error", "message": "unable to find serial for udid"};
}
} else {
var response = installVPPApplication(udid, Number(vpp[i]));
}
}
}
return response;
}
function processGetMDMInvokedRequest(parameters) {
var udid = parameters["udid"];
if ( udid ) {
udid = udid[0];
}
var properties = PropertiesService.getScriptProperties();
var mdmInvoked = properties.getProperty('MDM_INVOKED');
if ( mdmInvoked ) {
mdmInvoked = JSON.parse(mdmInvoked);
var response = "";
var titles = mdmInvoked[udid];
for ( var i=0; i<titles.length; i++ ) {
response += titles[i] + '\n';
}
delete mdmInvoked[udid];
properties.setProperty('MDM_INVOKED', JSON.stringify(mdmInvoked));
}
return response || "nothing requested";
}