22#
33# Author : Perry Driscoll - https://github.com/PezzaD84
44# Created : 11/8/2023
5- # Updated : 25/9 /2023
6- # Version : v0.2
5+ # Updated : 3/10 /2023
6+ # Version : v1
77#
88# ########################################################################################
99# Description:
2222# JAMF Script Variables
2323# $4: JSS URL
2424# $5: Encoded API Credentials
25+ # $6: Slack URL
26+ # $7: Teams URL
27+ # $8: Service Desk URL
2528#
2629# ########################################################################################
2730
31+ # ###########################################################################
32+ # Variables
33+ # ###########################################################################
34+
35+ CURRENT_USER=$( ls -l /dev/console | awk ' { print $3 }' )
36+ DEVICE=` hostname`
37+ SERVICEDESK=$8
38+
2839# #############################################################
2940# Functions
3041# #############################################################
8394 sleep 3
8495fi
8596
97+ # ###########################################################################
98+ # API Credentials
99+ # ###########################################################################
100+
86101# Get Bearer token
87102URL=" $4 "
88103password=" $5 "
89104
90105token=$( curl -s -H " Content-Type: application/json" -H " Authorization: Basic ${password} " -X POST " $URL /api/v1/auth/token" | plutil -extract token raw -)
91106
92- # Get Device name
107+ # ###########################################################################
108+ # Pop up for Device name
109+ # ###########################################################################
110+
93111message=$( dialog \
94112--title " JAMF LAPS UI" \
95113--icon " https://github.com/PezzaD84/JAMF-LAPS-UI/blob/main/lock%20icon.png?raw=true" --iconsize 100 \
96- --message " Please enter the name of the device you wish to see the LAPS password for. \n\n You must also provide a reason for viewing the LAPS Password for auditing." \
114+ --message " Please enter the name or serial of the device you wish to see the LAPS password for. \n\n You must also provide a reason for viewing the LAPS Password for auditing." \
97115--messagefont " name=Arial,size=17" \
98116--button1text " Continue" \
99117--button2text " Quit" \
100- --textfield " Device name ,required" \
118+ --textfield " Device,required" \
101119--textfield " Reason,required" \
120+ --selecttitle " Serial or Hostname" ,required \
121+ --selectvalues " Serial Number,Hostname" \
122+ --selectdefault " Hostname" \
102123--ontop \
103124--regular \
104125--json \
105126--moveable
106127)
107-
108- name1=$( echo $message | awk -F ' "Device name" : "' ' {print$2}' | awk -F ' "' ' {print$1}' )
128+
129+ DROPDOWN=$( echo $message | awk -F ' "SelectedOption" : "' ' {print$2}' | awk -F ' "' ' {print$1}' )
130+ name1=$( echo $message | awk -F ' "Device" : "' ' {print$2}' | awk -F ' "' ' {print$1}' )
109131reason=$( echo $message | awk -F ' "Reason" : "' ' {print$2}' | awk -F ' "' ' {print$1}' ) # Thanks to ons-mart https://github.com/ons-mart
110132
111133if [[ $name1 == " " ]] || [[ $reason == " " ]]; then
112134 echo " Aborting"
113135 exit 1
114136fi
115137
116- name=$( echo $name1 | sed -e ' s#’#%E2%80%99#g' -e ' s# #%20#g' )
117-
138+ # ###########################################################################
118139# Get Device ID
119- ID= $( curl -s -X GET " $URL /JSSResource/computers/name/ $name " -H ' Accept: application/json ' -H " Authorization:Bearer ${token} " | plutil -extract " computer " . " general " . " id " raw - )
140+ # ###########################################################################
120141
142+ if [[ $DROPDOWN == " Hostname" ]]; then
143+ echo " User selected Hostname"
144+
145+ name=$( echo $name1 | sed -e ' s#’#%E2%80%99#g' -e ' s# #%20#g' )
146+
147+ # Get Device ID
148+ ID=$( curl -s -X GET " $URL /JSSResource/computers/name/$name " -H ' Accept: application/json' -H " Authorization:Bearer ${token} " | plutil -extract " computer" ." general" ." id" raw -)
149+ else
150+ echo " User selected Serial"
151+
152+ # Get Device ID
153+ ID=$( curl -s -X GET " $URL /JSSResource/computers/serialnumber/$name1 " -H ' Accept: application/json' -H " Authorization:Bearer ${token} " | plutil -extract " computer" ." general" ." id" raw -)
154+ fi
155+
156+ # ###########################################################################
121157# Get JAMF Management ID
158+ # ###########################################################################
159+
122160MANAGEID=$( curl -s -X " GET" " $URL /api/v1/computers-inventory-detail/$ID " -H " Accept: application/json" -H " Authorization:Bearer ${token} " | plutil -extract " general" ." managementId" raw -)
123161
162+ # ###########################################################################
124163# Get LAPS Username
164+ # ###########################################################################
165+
125166LAPSUSER=$( curl -s -X " GET" " $URL /api/v2/local-admin-password/$MANAGEID /accounts" -H " Accept: application/json" -H " Authorization:Bearer ${token} " | plutil -extract " results" .0." username" raw -)
126167
168+ # ###########################################################################
127169# Get Password
170+ # ###########################################################################
171+
128172PASSWD=$( curl -s -X " GET" " $URL /api/v2/local-admin-password/$MANAGEID /account/$LAPSUSER /password" -H " Accept: application/json" -H " Authorization:Bearer ${token} " | plutil -extract password raw -)
129173
174+ # ###########################################################################
130175# View LAPS Account and Password
176+ # ###########################################################################
177+
131178dialog \
132179--title " JAMF LAPS UI" \
133180--icon " https://github.com/PezzaD84/JAMF-LAPS-UI/blob/main/Open%20Lock%20Icon.png?raw=true" --iconsize 100 \
@@ -136,3 +183,113 @@ dialog \
136183--timer \
137184--ontop \
138185--moveable
186+
187+ # ###########################################################################
188+ # Slack notification
189+ # ###########################################################################
190+
191+ if [[ $6 == " " ]]; then
192+ echo " No slack URL configured"
193+ else
194+ if [[ $SERVICEDESK == " " ]]; then
195+ SERVICEDESK=" https://www.slack.com"
196+ fi
197+ echo " Sending Slack WebHook"
198+ curl -s -X POST -H ' Content-type: application/json' \
199+ -d \
200+ ' {
201+ "blocks": [
202+ {
203+ "type": "header",
204+ "text": {
205+ "type": "plain_text",
206+ "text": "JAMF LAPS Password Requested:closed_lock_with_key:",
207+ }
208+ },
209+ {
210+ "type": "divider"
211+ },
212+ {
213+ "type": "section",
214+ "fields": [
215+ {
216+ "type": "mrkdwn",
217+ "text": ">*Device Name:*\n>' " $name1 " ' "
218+ },
219+ {
220+ "type": "mrkdwn",
221+ "text": ">*Requested by:*\n>' " $CURRENT_USER " ' on ' " $DEVICE " ' "
222+ },
223+ {
224+ "type": "mrkdwn",
225+ "text": ">*Reason for Request:*\n>' " $reason " ' "
226+ },
227+ ]
228+ },
229+ {
230+ "type": "actions",
231+ "elements": [
232+ {
233+ "type": "button",
234+ "text": {
235+ "type": "plain_text",
236+ "text": "Challenge Request",
237+ "emoji": true
238+ },
239+ "style": "danger",
240+ "action_id": "actionId-0",
241+ "url": "' " $SERVICEDESK " ' "
242+ }
243+ ]
244+ }
245+ ]
246+ }' \
247+ $6
248+ fi
249+
250+ # ###########################################################################
251+ # Teams notification (Credit to https://github.com/nirvanaboi10 for the Teams code)
252+ # ###########################################################################
253+
254+ if [[ $7 == " " ]]; then
255+ echo " No teams Webhook configured"
256+ else
257+ if [[ $SERVICEDESK == " " ]]; then
258+ SERVICEDESK=" https://www.microsoft.com/en-us/microsoft-teams/"
259+ fi
260+ echo " Sending Teams WebHook"
261+ jsonPayload=' {
262+ "@type": "MessageCard",
263+ "@context": "http://schema.org/extensions",
264+ "themeColor": "0076D7",
265+ "summary": "Admin has been used",
266+ "sections": [{
267+ "activityTitle": "JAMF LAPS Password Requested",
268+ "activityImage": "https://raw.githubusercontent.com/PezzaD84/macOSLAPS/main/Icons/Open%20Lock%20Icon.png",
269+ "facts": [{
270+ "name": "Device Name:",
271+ "value": "' " $name1 " ' "
272+ }, {
273+ "name": "Requested by:",
274+ "value": "' " $CURRENT_USER " ' on ' " $DEVICE " ' "
275+ }, {
276+ "name": "Reason",
277+ "value": "' " $reason " ' "
278+ }],
279+ "markdown": true
280+ }],
281+ "potentialAction": [{
282+ "@type": "OpenUri",
283+ "name": "Challenge Request",
284+ "targets": [{
285+ "os": "default",
286+ "uri":
287+ "' " $SERVICEDESK " ' "
288+ }]
289+ }]
290+ }'
291+
292+ # Send the JSON payload using curl
293+ curl -s -X POST -H " Content-Type: application/json" -d " $jsonPayload " " $7 "
294+ fi
295+
0 commit comments