robjschroeder / Elevate

Elevate is a script that can be ran from Jamf Pro to help elevate a standard user to admin for a specific amount of time
35 stars 5 forks source link

Add the ability to cancel admin during elevation #25

Open memile123 opened 1 year ago

memile123 commented 1 year ago

Great tool and thank you for the work on it! Not sure if this is in the pipeline but it would be nice if there could be a "cancel" or "remove privileges" button / function during an elevated session. It allow a user to cancel which will subsequently demote and exit.

memile123 commented 11 months ago

Thoughts on adding something like the below for this cancel option? Not the prettiest method ofcourse.

elevation_duration=300 # 5 minutes by default

loggedInUser=$(id -un)
originalPrimaryGroupID=$(id -gn $loggedInUser)

# Function to demote user from admin to standard
demote_user() {
    echo "Demoting $loggedInUser from admin to standard user..."
    dscl . -delete /Groups/admin GroupMembership $loggedInUser
    echo "$loggedInUser has been demoted to a standard user."
}

# Main loop for user interaction
while true; do
    echo "You are currently an admin. Choose an option:"
    echo "1. Continue with admin privileges (default)"
    echo "2. Cancel elevated session"
    echo "3. Demote account to standard user"
    read -p "Enter your choice (1-3): " user_choice

    case $user_choice in
        2)
            echo "Elevated session cancelled."
            break
            ;;
        3)
            read -p "Are you sure you want to demote your account? (yes/no): " confirm_demote
            if [[ $confirm_demote == "yes" ]]; then
                demote_user
                break
            else
                echo "Demotion cancelled."
            fi
            ;;
        *)
            echo "Continuing with admin privileges."
            sleep $elevation_duration
            ;;
    esac
done