#!/bin/bash ########################################################################## # Shellscript : User can get admin rights for a limited time # Autor : Andreas Vogel, macenterprise gmbh, 2020 ########################################################################## #Description # User kann über den Self Service Admin-Rechte einholen. Dabei ist die Begründung pflicht. # Die Begründung wird über das Echo im Jamf Log eingetragen und ist danach einsehbar. # Wird keine Begründung eingetragen, so werden auch keine Admin Rechte erteilt. # Sofern alles eingetragen ist, wird ein Daemon geschrieben. Dieses Startet exakt nach einer festgelegten Zeit. # Die Maximale Zeit kann über die Variable 4 gesetzt werden. Ist keine Zeit gesetzt, so wird die Zeit genommen, # die im Script festgeschrieben ist. Der Daemon startet ein Script, dass die Admin Rechte entfernt und den Daemon beendet. # User can obtain admin rights via the Self Service. The justification is mandatory. The reason is entered via the echo in # the Jamf Log and can then be viewed. If no reason is entered, no admin rights are granted. # If everything is entered, a daemon is written. This starts exactly after a set time. # The maximum time can be set via variable 4. If no time is set, the time that is set in the script is used. # The daemon starts a script that removes the admin rights and ends the daemon. ################################### Variablen ################################### currentUser=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2) ################################### Function ################################### ask () { osascript </dev/null tell application "SystemUIServer" activate text returned of (display dialog "$1" default answer "") end tell EOF } MessageBox() { osascript < /Library/LaunchDaemons/de.mac.remove.admin.plist Label de.mac.admintoremove.sh ProgramArguments /bin/bash /Library/Application Support/JAMF/de.mac.admintoremove.sh StartCalendarInterval Hour $hour Minute $minute EOB } ################################### Script ################################### RemoveAdminScript() { read -d '' RemoveAdmin<<"EOF" #!/bin/bash ##################################################################################### # Shellscript : # Autor : Andreas Vogel, macenterprise gmbh, ##################################################################################### currentUser=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2) if [[ $(dscl . read /Groups/admin GroupMembership | grep -o ${currentUser}) ]] then echo "${currentUser} is an admin" /usr/sbin/dseditgroup -o edit -d $currentUser -t user admin launchctl unload /Library/LaunchDaemons/de.mac.remove.admin.plist rm /Library/LaunchDaemons/de.mac.remove.admin.plist rm /Library/Application Support/JAMF/de.mac.admintoremove.sh fi EOF } ################################### Start and Load ################################### StartandLoad() { echo "$RemoveAdmin" > /Library/Application\ Support/JAMF/de.mac.admintoremove.sh # set ownership on LastWarningDaemon launch daemon /usr/sbin/chown root:wheel /Library/LaunchDaemons/de.mac.remove.admin.plist /bin/chmod 644 /Library/LaunchDaemons/de.mac.remove.admin.plist #load launchd launchctl load /Library/LaunchDaemons/de.mac.remove.admin.plist #set ownership for Script /usr/sbin/chown root:admin "/Library/Application Support/JAMF/de.mac.admintoremove.sh" /bin/chmod 755 "/Library/Application Support/JAMF/de.mac.admintoremove.sh" } ################################### Ausführung ################################### Button1=$(osascript -e 'display dialog "Do you really need admin rights?." with title "Do you need admin rights" buttons {"Yes", "No"} default button 2 ') Selection=$(echo $Button1 | cut -d : -f 2) if [[ "$Selection" = "Yes" ]] then Substantiation if [[ -z "$answer" ]] then MessageBox else RemoveAdminDaemon RemoveAdminScript StartandLoad CreateAdmin fi else echo "möchte nicht" fi