#!/bin/sh

##########################################################################
#   Script description:
#       Common admin tasks
#       
#   History:
#   Date        Name        Modification
#   2016-01-01  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Function description:
#       Pause until user presses return
##########################################################################

pause()
{
    local junk
    
    printf "Press return to continue..."
    read junk
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

# Prevent user from running a Trojan as root in the case their account
# was compromised
absolute="$(which $0)"
# Don't count on -e being set at this point
if ! auto-file-secure "$absolute"; then
    exit 1
fi

if ! auto-root-check $0; then
    printf "Root "
    # exec quotes '$absolute --flag', causing usage error
    # Assigning to cmd works around the problem
    cmd="$absolute $@"
    exec su -m root -c "$cmd"
fi

while true
do
    clear
    auto-admin-banner
    cat << EOM

1.. Enable auto-logout
2.. Enable password quality checking
3.. Set password expiration
Q.. Quit

EOM

    printf "Selection? "
    read resp
    case 0$resp in
    01)
	printf "Maximum idle time in minutes? "
	read minutes
	auto-enable-autologout $minutes
	;;
    
    02)
	auto-enable-passwdqc
	;;
    
    03)
	printf "User name? "
	read user_name
	printf "Days to expiration? "
	read days
	auto-passwd-user-expiration $user_name $days
	;;
    
    0Q|0q)
	exit 0
	;;

    *)
	printf "Invalid option: $resp\n"
    esac
    pause
done
