#!/usr/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/apache2-webalizer-web-user # # Creation: 2013-03-23 hb # Last Update: $Id$ # # Copyright (c) 2014-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # include config . /etc/config.d/apache2 . /etc/config.d/apache2_webalizer # include passwdlib . /var/lib/apache2_webalizer/passwdlib debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi ASK='/var/install/bin/ask' CHOOSE='/var/install/bin/choose' MKTEMP='/bin/mktemp' # set echo line, for allways equal echo_line=" ----------------------------" # --------------------------------------------------------------------------- # select project # --------------------------------------------------------------------------- select_project() { AW_TITLE='Select the project to change the user settings' AW_FLAGS='--indent 12 --spread' AW_CAPTION_1='--info "Hostname"' AW_CAPTION_2='--info "alias"' AW_COLS='30 10' AW_ROWS=0 export AW_TITLE export AW_FLAGS export AW_CAPTION_1 export AW_CAPTION_2 export AW_COLS unset AW_SUBTITLE if [ "${APACHE2_WEBALIZER_VHOSTS_RUN_ALL}" = 'yes' ] then vhost_ac_auth=${APACHE2_WEBALIZER_VHOSTS_ACCESS_AUTH} if [ "${vhost_ac_auth}" = "yes" ] then idx=1 while [ "${idx}" -le "${APACHE2_VHOST_N}" ] do eval active='${APACHE2_VHOST_'${idx}'_ACTIVE}' if [ "${active}" != "yes" ] then idx=$( /usr/bin/expr ${idx} + 1 ) continue fi AW_ROWS=$( expr ${AW_ROWS} + 1 ) eval srv_${AW_ROWS}='"${APACHE2_VHOST_'${idx}'_SERVER_NAME}"' eval alias_${AW_ROWS}="${APACHE2_WEBALIZER_VHOSTS_ALIAS}" eval AW_${AW_ROWS}_1='\"${APACHE2_VHOST_'${idx}'_SERVER_NAME}\"' eval AW_${AW_ROWS}_2=\"${APACHE2_WEBALIZER_VHOSTS_ALIAS}\" export AW_${AW_ROWS}_1 export AW_${AW_ROWS}_2 idx=$( /usr/bin/expr ${idx} + 1 ) done fi fi idx=1 while [ "${idx}" -le "${APACHE2_WEBALIZER_HOST_N}" ] do eval active='${APACHE2_WEBALIZER_HOST_'${idx}'_ACTIVE}' if [ "${active}" != "yes" ] then idx=$( /usr/bin/expr ${idx} + 1 ) continue fi AW_ROWS=$( expr ${AW_ROWS} + 1 ) eval srv_${AW_ROWS}='"${APACHE2_WEBALIZER_HOST_'${idx}'_HOST_NAME}"' eval alias_${AW_ROWS}='"${APACHE2_WEBALIZER_HOST_'${idx}'_ALIAS}"' eval AW_${AW_ROWS}_1='\"${APACHE2_WEBALIZER_HOST_'${idx}'_HOST_NAME}\"' eval AW_${AW_ROWS}_2='\"${APACHE2_WEBALIZER_HOST_'${idx}'_ALIAS}\"' export AW_${AW_ROWS}_1 export AW_${AW_ROWS}_2 idx=$( /usr/bin/expr ${idx} + 1 ) done AW_QUESTION='Select' export AW_QUESTION export AW_ROWS _ask_tmpfile=$(/bin/mktemp -t XXXXXXXXXXXXX) ${CHOOSE} AW 1 > ${_ask_tmpfile} rc=${?} read answer < ${_ask_tmpfile} rm -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then answer=0 fi case ${answer} in '') exit 0 ;; 0) exit 127 ;; *) eval server='$srv_'${answer} eval alias='$alias_'${answer} ;; esac unset AW_CAPTION_1 unset AW_CAPTION_2 select_to_work } # --------------------------------------------------------------------------- # select to work # --------------------------------------------------------------------------- select_to_work() { # entry:action:message:para action_entry="show user:user_list:yes add user:user_action:Add user to:-b remove user:user_action:Remove user from:-D alter password:user_action:Alter password for user from:-a" AW_TITLE='Select the action for project' AW_SUBTITLE="\n ${server} ${alias}" AW_FLAGS='--indent 12 --spread' AW_COLS='20' AW_ROWS=0 export AW_TITLE export AW_SUBTITLE export AW_FLAGS export AW_COLS idx=1 _entry_tmpfile=$(/bin/mktemp -t XXXXXXXXXXXXX) echo "${action_entry}" >${_entry_tmpfile} while read line do _entry="$( echo "${line}" | awk -F':' '{print $1}' )" AW_ROWS=$( expr ${AW_ROWS} + 1 ) eval AW_${AW_ROWS}_1='\"${_entry}\"' export AW_${AW_ROWS}_1 idx=$( /usr/bin/expr ${idx} + 1 ) done < ${_entry_tmpfile} rm -rf ${_entry_tmpfile} AW_QUESTION='Select' export AW_QUESTION export AW_ROWS _ask_tmpfile=$( /bin/mktemp -t XXXXXXXXXXXXX ) ${CHOOSE} AW 1 > ${_ask_tmpfile} rc=${?} read answer < ${_ask_tmpfile} rm -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then answer=0 fi case ${answer} in '') active_project='' select_project ;; 0) exit 127 ;; *) # get action line action_line="$( echo "${action_entry}"| sed -n "${answer}p" | sed 's/^ *//' )" action="$( echo "${action_line}" | awk -F':' '{print $2}' )" message="$( echo "${action_line}" | awk -F':' '{print $3}' )" para="$( echo "${action_line}" | awk -F':' '{print $4}' )" # user_action # user_list # ${2} ${3} ${4} ${action} "${message}" "${para}" ;; esac } # --------------------------------------------------------------------------- # user add, remove or alter password to htpasswd file # --------------------------------------------------------------------------- user_action() { # htpasswd_exec="/var/lib/trac/htdigest.sh" action_string="${1}" action_flag="${2}" # write existing user to tty, without answer_line user_show # anykey # echo # mecho -n "${action_string} project " # mecho --info "'${server} ${alias}}'" # echo AW_TITLE="${action_string} project" AW_SUBTITLE="\n ${server} ${alias}" AW_CAPTION_1='--info "User in project"' AW_FLAGS='--indent 12 --spread ' export AW_TITLE export AW_SUBTITLE export AW_CAPTION_1 export AW_FLAGS AW_QUESTION="Select" export AW_QUESTION _ask_tmpfile=$( /bin/mktemp -t XXXXXXXXXXXXX ) ${CHOOSE} AW 1 > ${_ask_tmpfile} rc=${?} read answer < ${_ask_tmpfile} rm -f ${_ask_tmpfile} # _ask_tmpfile=$(/bin/mktemp -t XXXXXXXXXXXXX) # ${ASK} "Name of user (ENTER=Return, 0=Exit)" "" "*" >${_ask_tmpfile} # rc=${?} # UserName=$(cat ${_ask_tmpfile}) # rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then answer=0 fi if ! echo "${action_string}" | grep -q "Remove" then _used_project=${_selected_project} fi case ${answer} in '') select_to_work ;; 0) exit 0 ;; *) # add, remove or alter password ${htpasswd_exec} ${action_flag} \ --file ${trac_path}/${_selected_project}.htpasswd \ --realm ${_used_project} --user ${UserName} # set rights # chown wwwrun ${trac_path}/${_selected_project}.htpasswd # chmod 0600 ${trac_path}/${_selected_project}.htpasswd ;; esac } # --------------------------------------------------------------------------- # user list # --------------------------------------------------------------------------- user_list() { # answer_line=${1} AW_TITLE='Existing user in project' AW_SUBTITLE="\n ${server} ${alias}" AW_CAPTION_1='--info "User"' AW_FLAGS='--indent 12 --spread --list' export AW_TITLE export AW_SUBTITLE export AW_CAPTION_1 export AW_FLAGS user_show AW_QUESTION='View' export AW_QUESTION _ask_tmpfile=$( /bin/mktemp -t XXXXXXXXXXXXX ) ${CHOOSE} AW 1 > ${_ask_tmpfile} rc=${?} read answer < ${_ask_tmpfile} rm -f ${_ask_tmpfile} unset AW_CAPTION_1 if [ ${rc} = 255 ] then answer=0 fi case ${answer} in '') select_to_work ;; 0) exit 0 ;; esac } # --------------------------------------------------------------------------- # user list # --------------------------------------------------------------------------- user_show() { AW_COLS='20' AW_ROWS=0 export AW_COLS idx=1 _entry_tmpfile=$( /bin/mktemp -t .XXXXXXXXXXXXX ) cat ${webalizer_path}/${server}.${alias}.htpasswd | sort >${_entry_tmpfile} while read line #user passwd do _entry="$( echo "${line}" | awk -F':' '{print $1}' )" AW_ROWS=$( expr ${AW_ROWS} + 1 ) eval AW_${AW_ROWS}_1='\"${_entry}\"' export AW_${AW_ROWS}_1 idx=$( /usr/bin/expr ${idx} + 1 ) done < ${_entry_tmpfile} rm -f ${_entry_tmpfile} export AW_ROWS # if [ ${answer_line:-yes} != no ] # then # AW_QUESTION='View' # export AW_QUESTION# # # _ask_tmpfile=$( /bin/mktemp -t XXXXXXXXXXXXX ) # ${CHOOSE} AW 1 > ${_ask_tmpfile} # rc=${?} # read answer < ${_ask_tmpfile} # rm -f ${_ask_tmpfile} # unset AW_CAPTION_1### # # if [ ${rc} = 255 ] # then # answer=0 # fi ## # case ${answer} in # '') select_to_work ;; # 0) exit 0 ;; # esac # fi } # --------------------------------------------------------------------------- # select passwort action # --------------------------------------------------------------------------- select_pw_action() { _ask_tmpfile=$( ${MKTEMP} -t .XXXXXXXXXXXXX ) ${ASK} "Create password with pwgen" "yes" >${_ask_tmpfile} rc=${?} read _passwd_pwgen < ${_ask_tmpfile}) ${RM} -f ${_ask_tmpfile} if [ ${rc} = 255 ] then exit 127 fi if [ "${_passwd_pwgen}" = "yes" ] then # check is pwgen installed /var/install/bin/check-package -p "pwgen" -v "2.2.0" retvar="${?}" if [ ${retvar} -ne 0 ] then get_paswd else # create password # pwgen --help # retuzrn password get_pwgen_passwd # password="$(${PWGEN} -1s 12)" fi else # get password from cmdline get_passwd fi # create the password-file entry line # return _passwd_entry get_digest_entry _ask_tmpfile=$( ${MKTEMP} -t .XXXXXXXXXXXXX ) ${ASK} "Send e-mail to user '${_user}'" "yes" >${_ask_tmpfile} rc=${?} read _send_mail < ${_ask_tmpfile}) ${RM} -f ${_ask_tmpfile} if [ ${rc} = 255 ] then exit 127 fi if [ "${_send_mail}" = "yes" ] then _mail_to="${_user}" else _mail_to="root" fi send_passwd } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- while true do clrhome # if [ ${TRAC_PROJ_N} -eq 0 ] # then # echo # mecho --info "Error: There are no projects defined on this server!" # anykey # exit 1 # fi active_project='' select_project echo _ask_tmpfile=$(/bin/mktemp -t XXXXXXXXXXXXX) ${ASK} "One more action?" "no" >${_ask_tmpfile} rc=${?} more_action=$(cat ${_ask_tmpfile}) rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then more_action=no fi case ${more_action} in no) exit 0 ;; esac done exit 0 # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------