![]() |
|||||||||||
![]() ![]() |
![]() |
![]() |
Listing 5
#! /bin/bash - # FILENAME: sendhtpwd # DESCRIPTION: Sends an httpd password to relevant usernames. Data are # stored in a file with the following format: # # username:clear_password:crypted_password:mailaddr # # USAGE: sendhtpwd [-H] [-f file] [-h file] [-n name ] [-u url ] # [-s sender] [-v] # OPTIONS: # -H - Prints help message # -f file - File usernames are stored in # -n name - Name of restricted area of httpd server # -s addr - Mailaddr messages appear to be sent # -u url - URL of restricted area of httpd server # -v - Produces verbose output # # LABEN S.p.A. - 09-jan-1998 # # HISTORY: # 0.0 Luca Salvadori <[email protected]> 09-jan-1998 # - Functions and behaviour # # ########################## S U B R O U T I N E S ########################### # Initialization of global variables # Program Information AUTHOR="Luca Salvadori <[email protected]>" VERSION="0.0" DATE="09-jan-1998" # End of program information DEF_NAME="Reports Gestionali" # Default name of restricted httpd area DEF_URL="http://www.laben.it/p_c" # URL of the above [email protected] # Address messages appear coming from DEF_FILE=~/work/utils/htpasswd # Default data file MASK="600" # Default protection mask for data file # WARNING! It contains clear passwords! VERBOSE=0 # Brief output is default # Options string OPTS=":-H -f: -n: -u: -s: -v" # Default options DEFOPT="-f $DEF_FILE -n \"$DEF_NAME\" -u $DEF_URL -s $DEF_SENDER" # End of global variables initialization ##################### E N D O F S U B R O U T I N E S #################### function helpmsg() { echo "" 1>&2 echo " `basename $0` Version $VERSION - $DATE" 1>&2 echo " Author: $AUTHOR" 1>&2 echo "" 1>&2 echo " USAGE: `basename $0` [-H] [-f file] [-n name ] [-u url ] [-s sender] [-v]" 1>&2 echo " OPTIONS:" 1>&2 echo " -H - Prints help message" 1>&2 echo " -f file - File usernames are stored in" 1>&2 echo " -n name - Name of restricted area of httpd server" 1>&2 echo " -u url - URL of restricted area of httpd server" 1>&2 echo " -s addr - Mailaddr messages appear to be sent" 1>&2 echo " -v - Produces verbose output" 1>&2 echo "" 1>&2 } ########### M A I N P R O G R A M ########### # Parsing input parameters and assigning default if needed options=`echo $*` [ "$options" = "" ] && { $0 $DEFOPT ; exit } # Parsing options and setting defaults if needed while [ $OPTIND -le $# ] do getopts "$OPTS" option case $option in H) helpmsg exit 0 ;; f) FILE=$OPTARG ;; n) NAME=$OPTARG ;; u) URL=$OPTARG ;; s) SENDER=$OPTARG ;; v) VERBOSE=1 ;; "?") echo "`basename $0` - ERROR: Option -$OPTARG requires an argument or is unknown." 1>&2 echo "Run `basename $0` -H for help." 1>&2 exit 3 ;; *) echo "`basename $0` - ERROR: Unknown option -$OPTARG." 1>&2 echo "Run `basename $0` -H for help." 1>&2 exit 2 ;; esac case $OPTARG in -*) echo "`basename $0` - ERROR: Option -$option requires an argument." 1>&2 echo "Invalid argument $OPTARG." 1>&2 echo "Run `basename $0` -H for help." 1>&2 exit 3 ;; esac done # Setting defaults for unselected options NAME=${NAME:-$DEF_NAME} URL=${URL:-$DEF_URL} SENDER=${SENDER:-$DEF_SENDER} FILE=${FILE:-$DEF_FILE} # Perform sanity checks, just in case [ ! -f $FILE ] && { echo "`basename $0` - ERROR: Data file $FILE does not exist." 1>&2 ; echo "Run `basename $0` -H for help." 1>&2 ; exit 6 } # Here begins the real stuff # Setting protection to data file, just in case... [ -f $FILE ] && chmod $MASK $FILE # Looping for all usernames for line in `cat $FILE` do # Getting parameters user=`echo $line | cut -d":" -f1` pwd=`echo $line | cut -d":" -f2` cpwd=`echo $line | cut -d":" -f3` mailaddr=`echo $line | cut -d":" -f4` # Verbose output [ $VERBOSE -eq 1 ] && echo -n "Sending message to $user ($mailaddr)..." # Sending message echo \ "Subject: Password per $NAME QUESTO E' UN MESSAGGIO GENERATO AUTOMATICAMENTE DAL SISTEMA. NON EFFETTUARE REPLY. Di seguito le informazioni per accedere all'area $NAME ($URL) del Web Aziendale: USERNAME: $user PASSWORD: $pwd Le informazioni di cui sopra sono da considerarsi riservate, pertanto si invita a non comunicarle a chicchessia. Nel caso si ritenesse che la password sia giunta a conoscenza di altri, si prega di segnalarlo immediatamente inviando una mail a $SENDER. La password puo' essere modificata mediante l'apposita utility disponibile nella pagina delle Intranet Utilities (http://www.laben.it/utilities). Per ulteriori dettagli si prega di consultare le Network News (http://www.laben.it/utilities/news.html) nel Newsgroup \"LABEN Web\", Articolo n. 12 dal titolo \"Reporting Direzionale su Intranet\". Cordialmente $SENDER " | sendmail -f"$SENDER" $mailaddr # Verbose output [ $VERBOSE -eq 1 ] && echo "Done." done # Happily exit exit ##################### E N D O F M A I N P R O G R A M ###################
|
![]() |
© 2003 CMP Media Inc. All Rights Reserved. |