-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enable_Lost_Mode_for_Group.py
82 lines (65 loc) · 2.82 KB
/
Enable_Lost_Mode_for_Group.py
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
#!/usr/bin/env python3
# Matthew Prins 2023
# https://github.com/MatthewPrins/Jamf/
# put all mobile devices in a group in Lost Mode
# pip install requests if not already done
import json
import requests
from datetime import datetime
############################
# Editable variables
# Jamf credentials
username="xxxxxx"
password="xxxxxx"
jamfurl="https://xxxxxx.jamfcloud.com"
# mobile device group ID number -- found in URL on group's page
groupid="123"
# Information to appear on Lost Mode screen on devices
lm_message = "lost mode message here"
lm_phone = "000-000-0000"
lm_footnote = "footnote here"
############################
# definition for fetching API token
def fetchtoken():
response = requests.post(url=jamfurl + "/api/v1/auth/token", headers={'Accept': 'application/json'}, auth=(username, password))
print("new token fetched\n")
return response.json()['token'], datetime.strptime(response.json()['expires'], '%Y-%m-%dT%H:%M:%S.%fZ')
# definition for invalidating API token
def invalidatetoken():
response = requests.post(url=jamfurl + "/api/v1/auth/invalidate-token", headers={'Authorization': 'Bearer ' + token})
############################
# get initial token
token,tokenexpiration = fetchtoken()
# get group information
response = requests.get(url=jamfurl + "/JSSResource/mobiledevicegroups/id/" + str(groupid), headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
groupinfo=json.loads(response.text)['mobile_device_group']
#populate list of IDs
IDlist = []
for member in groupinfo['mobile_devices']:
IDlist.append(member['id'])
#get approval to put all devices in Lost Mode
print("Mobile Device Group ID: " + str(groupinfo['id']))
print("Name: " + str(groupinfo['name']))
print("Number of Members: " + str(len(IDlist)) + "\n")
print("Type YES (all caps) to put all devices in the group in Lost Mode, anything else to quit:")
approval = input()
print()
if approval != "YES":
print("ok, exiting")
exit()
#start iterating through mobile device ID list
for ID in IDlist:
#from mobile device ID, get device UUID
response = requests.get(url=jamfurl + "/api/v2/mobile-devices/" + str(ID), headers={'Accept': 'application/json','Authorization': 'Bearer ' + token})
uuid=json.loads(response.text)['managementId']
#put device in Lost Mode
commandpayload = { "commandData": { "commandType": "ENABLE_LOST_MODE", "lostModeMessage": lm_message, "lostModePhone": lm_phone, "lostModeFootnote": lm_footnote }, "clientData": [{ "managementId": uuid }] }
response = requests.post(url=jamfurl + "/api/preview/mdm/commands", json=commandpayload, headers={"Accept": "application/json", "content-type": "application/json",'Authorization': 'Bearer ' + token})
#return success or fail
try:
temp=json.loads(response.text)[0]['href']
print(str(ID) + ": success")
except:
print(str(ID) + ": fail")
print(response.text)
exit()