#!/bin/sh usage () { echo "Usage: admtool (interactive mode)" echo " admtool [-sehuq]" echo " admtool -a username [password]" echo " admtool -r username" echo "" echo " -h Show this screen." echo " -s Start admin server." echo " -q Query admin status" echo " -e Stop admin server." echo " -a Add a user." echo " -r Remove a user" echo " -u List users" echo "" exit 1 } interactive () { while [ 1 -eq 1 ]; do clear echo echo "1. Start admin server." echo "2. Stop admin server." echo "3. Admin server status." echo "4. Add a user." echo "5. Remove a user." echo "6. List users." echo "7. Quit." echo echo -n "Please choose one [7]: " read -r answer if [ "x$answer" = "x" ]; then exit 0 fi if [ "$answer" = "7" ]; then exit 0 elif [ "$answer" = "6" ]; then <>/admtool -u elif [ "$answer" = "5" ]; then echo -n "Enter the user name: "; read -r user if [ "$user" != "" ]; then <>/admtool -r $user fi elif [ "$answer" = "4" ]; then echo -n "Enter the user name: "; read -r user if [ "$user" != "" ]; then <>/admtool -a $user fi elif [ "$answer" = "3" ]; then <>/admtool -q elif [ "$answer" = "2" ]; then <>/admtool -e elif [ "$answer" = "1" ]; then <>/admtool -s else exit 0 fi echo echo -n "Press Enter to continue "; read -r done } # make sure we're root if [ -x /usr/bin/whoami ]; then user=`/usr/bin/whoami` if [ "$user" != "root" ]; then printf "admtool: must be root to run.\n" exit fi fi if [ "$#" -eq 0 ]; then interactive fi if [ "$1" = "-h" ]; then usage fi if [ "$#" -eq 1 ]; then if [ "$1" = "-s" ]; then echo Starting admin server. <>/admin/bin/admd -f <>/admin/conf/admd.conf >/dev/null <>/admin/bin/caspctrl startall >/dev/null echo Admin server has been started. exit 0 elif [ "$1" = "-e" ]; then if <>/admtool -q >/dev/null; then echo Stopping admin server. kill `cat <>/admin/logs/httpd.pid` <>/admin/bin/caspctrl stopall >/dev/null echo Admin server has been stopped. else echo Admin server is not started fi exit 0 elif [ "$1" = "-u" ]; then if grep : <>/admin/conf/service.pwd|awk -F ':' '{print $1}'; then echo -n else echo No users. fi exit 0 elif [ "$1" = "-q" ]; then if <>/admin/bin/caspctrl status > /dev/null 2>&1; then if [ -f "<>/admin/logs/httpd.pid" ]; then echo Admin server is running exit 0 else echo Admin server is stopped exit 1 fi else echo Admin server is stopped exit 1 fi fi fi if [ "$#" -eq 2 ]; then if [ "$1" = "-a" ]; then <>/admin/conf/htpasswd <>/admin/conf/service.pwd $2 exit 0 fi if [ "$1" = "-r" ]; then if grep $2: <>/admin/conf/service.pwd > /dev/null; then cp <>/admin/conf/service.pwd <>/admin/conf/.service.pwd.bak grep $2: -v <>/admin/conf/.service.pwd.bak > <>/admin/conf/service.pwd rm <>/admin/conf/.service.pwd.bak echo "User $2 removed" else echo User not found. fi exit 0 fi elif [ $# -eq 3 ]; then if [ "$1" = "-a" ]; then <>/admin/conf/htpasswd -b <>/admin/conf/service.pwd $2 $3 exit 0 fi fi usage