# User Admin helper script
# 2007-01, Rick Armstrong

if [ "$1" = "find" ]
then
    omsearch  -s | grep  -i $2
    # omshowpdl -l all | grep -i $2
    # omshowu -m all -I | grep -i $2
elif [ "$1" = "findu" ]
then
    omshowu -n $2

elif [ "$1" = "lists" ]
then
    omshowpdl -l all

elif [ "$1" = "listswho" ]
then
    omshowpdl -l all | awk -F"/" '{ print "echo "$1"/"$2":; omshowpdln -l \""$1"/"$2"\" 2> /dev/null; EXIT_CODE=$?;  if [ $EXIT_CODE -ne 0 ]; then echo \"[ empty or non-unique list name ]\"; fi; echo " }' | sh

elif [ "$1" = "showdesignations" ]
then
    omshowu -m all | awk -F"/" '{ print "ommapiperms -u \""$1"/"$2"\" | grep -A 10 DES | grep \"No\" > /dev/null; EXIT_CODE=$?; if [ $EXIT_CODE -ne 0 ]; then echo "$1"/"$2":; ommapiperms -u \""$1"/"$2"\" | grep -A 10 DES; echo; fi;" }' | sh

elif [ "$1" = "purgetemp" ]
then
    echo "  # folders .../scalix/../s/tmp, .../scalix/../temp may need pruning"
    echo "  find . -atime +60 -exec sh -c \"ls -l {};\" \;"

elif [ "$1" = "ds" ]
then
    omstat -s | grep -i Sync

elif [ "$1" = "dsoff" ]
then
        omoff -w -d 0 dirsync

elif [ "$1" = "dson" ]
then
        omon -w dirsync

elif [ "$1" = "listdom" ]
then
        omshowmn -m all


elif [ "$1" = "bbs" ]
then
        omstat -s | grep -i Bull

elif [ "$1" = "bbsoff" ]
then
        omoff -w -d 0 bbs

elif [ "$1" = "bbson" ]
then
        omon -w bbs

elif [ "$1" = "listbbs" ]
then
    omlistbbsa

elif [ "$1" = "showbbs" ]
then
    omlistbbs -d 0

elif [ "$1" = "space" ]
then
        omscan -u
        omscan -b

elif [ "$1" = "routes" ]
then
        omshowrt -q all

elif [ "$1" = "listds" ]
then
    echo "Export:"
        omlistds -e
    echo "Import:"
        omlistds -i
    echo "Misc:"
        omlistds -n
    echo "All Nodes:"
        omshowmnmp

elif [ "$1" = "useradd" ]
then
        if [ "$2x" = "x" ]
        then
                help="show"
        elif [ "$3x" = "x" ]
        then
                help="show"
        elif [ "$4x" = "x" ]
        then
                help="show"
        elif [ "$5x" = "x" ]
        then
                help="show"
        else
                echo "omaddu -n \"$2 $3/$4\" -p $5"
        # omaddu -n  "$2 $3/$4" -p $5
        fi

elif [ "$1" = "authmod" ]
then
    if [ "$2x" = "x" ]
    then
        help="show"
    else
        echo "ommodu -o \"$2 $3/$4\" --authid=\"$5@$6\""
    fi

elif [ "$1" = "showmod" ]
then
        if [ "$2x" = "x" ]
        then
                help="show"
        elif [ "$3x" = "x" ]
        then
                help="show"
        elif [ "$4x" = "x" ]
        then
                help="show"
        elif [ "$5x" = "x" ]
        then
                help="show"
        else
                echo "ommodu -o \"$2 $3/$4\" -n \"$2 $3/$4/IA=\\\"$2 $3\\\" <$2.$3$5>$6\""
                # omaddu -n "$2 $3/$4" -p $5
        fi

elif [ "$1" = "liveu" ]
then
    omstat -u all
    echo
    omstat -u pc -c

elif [ "$1" = "listfqdn" ]
then
#    omsearch -s -m CN/HOST-FQDN -v
    omsearch -s -m HOST-FQDN/IA/CN

elif [ "$1" = "serverhelp" ]
then
    man scalix-server

else
        help="show"
fi

if [ $help ]
then
        echo "Usage: $0 [cmd] ..."
        echo "  find [pattern]"
        echo "  listdom | showdesignations"
        echo "  useradd [first name] [surname] [dom] [password]"
        echo "  showmod [first name] [surname] [dom] [@scalix.com] [Internet alias]"
        echo "  authmod [first name] [surname] [dom] [flast] [@SCALIX.LOCAL]"
        echo "  lists | listswho"
    echo "  space | routes"
    echo "  purgetemp"
        echo "  ds | listds | dson | dsoff"
        echo "  bbs | listbbs | showbbs | bbson | bbsoff"
    echo "  liveu | listfqdn | serverhelp"
fi