#!/bin/sh #---------------------------------------------------------------------------------------- # /usr/bin/archimapcheck - check configuration file of IMAP archiver # # Copyright (c) 2001-2025 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2004-04-20 jed # Last Update: $Id$ # # Parameters: # # archimapcheck username - check configuration file # # 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. #---------------------------------------------------------------------------------------- # read eislib . /var/install/include/eislib # exec 2>./archimapcheck-trace-$$.log # set -x #---------------------------------------------------------------------------------------- # check default parameters # input: $1 - user name #---------------------------------------------------------------------------------------- check_parameters () { uname="$1" # get file version mecho "checking: # defaults - version:" head_line=`head -n 1 $list_file|sed 's/^# defaults - version://'` case $head_line in 1 ) # version number found d_archive_version=$head_line ;; * ) # no version number found - old type d_archive_version=0 ;; esac if [ $d_archive_version -eq 0 ] then mecho --error " - error: first line does not begin with '# defaults - version:'!" fi mecho "checking: ARCHIMAP_DEFAULT_ARCHIVE_FOLDER ..." if [ ! -z `grep "ARCHIMAP_DEFAULT_ARCHIVE_FOLDER=" "$list_file"` ] then # parameter found d_archive_folder=`grep "ARCHIMAP_DEFAULT_ARCHIVE_FOLDER=" "$list_file"|sed 's/ARCHIMAP_DEFAULT_ARCHIVE_FOLDER=//'` else # parameter not found mecho --error " - error: parameter couldn't be found!" fi mecho "checking: ARCHIMAP_DEFAULT_ARCHIVE_TYPE ..." if [ ! -z `grep "ARCHIMAP_DEFAULT_ARCHIVE_TYPE=" "$list_file"` ] then # parameter found d_archive_type=`grep "ARCHIMAP_DEFAULT_ARCHIVE_TYPE=" "$list_file"|sed 's/ARCHIMAP_DEFAULT_ARCHIVE_TYPE=//'` case $d_archive_type in default|yearly|monthly|daily ) ;; * ) # error mecho --error " - error: type not 'default', 'yearly', 'monthly' or 'daily': $d_archive_type" ;; esac else # parameter not found mecho --error " - error: parameter couldn't be found!" fi mecho "checking: ARCHIMAP_DEFAULT_ACTION ..." if [ ! -z `grep "ARCHIMAP_DEFAULT_ACTION=" "$list_file"` ] then # parameter found d_action=`grep "ARCHIMAP_DEFAULT_ACTION=" "$list_file"|sed 's/ARCHIMAP_DEFAULT_ACTION=//'` case $d_action in none|list|list-date|archive|archive-date|kill|kill-date|copy|copy-date ) ;; * ) # error mecho --error " - error: action not 'none', 'archive[-date]', 'copy[-date]', 'kill[-date]' or 'list[-date]': $d_action" ;; esac else # parameter not found mecho --error "error: parameter couldn't be found!" fi mecho "checking: ARCHIMAP_DEFAULT_TIMESPAN ..." if [ ! -z `grep "ARCHIMAP_DEFAULT_TIMESPAN=" "$list_file"` ] then # parameter found d_timespan=`grep "ARCHIMAP_DEFAULT_TIMESPAN=" "$list_file"|sed 's/ARCHIMAP_DEFAULT_TIMESPAN=//'` else # parameter not found mecho --error " - error: parameter couldn't be found!" fi mecho "checking: ARCHIMAP_RESULT_INFOMAIL ..." if [ ! -z `grep "ARCHIMAP_RESULT_INFOMAIL=" "$list_file"` ] then # parameter found d_infomail=`grep "ARCHIMAP_RESULT_INFOMAIL=" "$list_file"|sed 's/ARCHIMAP_RESULT_INFOMAIL=//'` case $d_infomail in yes ) if [ "$uname" = "imappublic" -o "$uname" = "imapshared" ] then # imappublic or imapshared user mecho "checking: ARCHIMAP_RESULT_INFOMAIL_SENDTO ..." if [ ! -z `grep "ARCHIMAP_RESULT_INFOMAIL_SENDTO=" "$list_file"` ] then # parameter found d_infomailsendto=`grep "ARCHIMAP_RESULT_INFOMAIL_SENDTO=" "$list_file"|sed 's/ARCHIMAP_RESULT_INFOMAIL_SENDTO=//'` # echo "$d_infomailsendto" | grep -q "@" # if [ $? -ne 0 ] # then # # invalid email address syntax # mecho --warn " - warning: invalid email address syntax '$d_infomailsendto'!" # fi else # parameter not found mecho --error " - error: parameter couldn't be found!" fi else mecho "skipping: ARCHIMAP_RESULT_INFOMAIL_SENDTO because it can only be used by 'imappublic' and 'imapshared' user ..." fi ;; no ) mecho "skipping: ARCHIMAP_RESULT_INFOMAIL_SENDTO ..." ;; * ) # error mecho --error " - error: parameter has not been set to 'yes' or 'no': $d_infomail" ;; esac else # parameter not found mecho --error "error: parameter couldn't be found!" fi mecho } #---------------------------------------------------------------------------------------- # check directory and file entries # $1 - line #---------------------------------------------------------------------------------------- check_line () { lline=$1 mecho "checking: $lline ..." errflag=0 OIFS=$IFS IFS=: # entry found set $lline dirfile=$1 dfname=$2 action=$3 days=$4 type=$5 comment=$6 # check dfname case $dirfile in dir ) if [ ! -d $dfname ] then mecho --error " - error: directory doesn't exist: $dfname" errflag=1 fi ;; file ) if [ ! -f $dfname ] then mecho --error " - error: file doesn't exist: $dfname" errflag=1 fi # check action case $action in none|list|list-date|archive|archive-date|kill|kill-date|copy|copy-date ) ;; * ) # error mecho --error " - error: action not 'none', 'archive[-date]', 'copy[-date]', 'kill[-date]' or 'list[-date]': $action" errflag=1 ;; esac # check days # check type case $type in default|yearly|monthly|daily ) ;; * ) # error mecho --error " - error: type not 'default', 'yearly', 'monthly' or 'daily': $type" errflag=1 ;; esac ;; * ) # error mecho --error " - error: line doesn't begin with 'dir:' or 'file: $dirfile" errflag=1 ;; esac if [ $errflag -gt 0 ] then mecho fi IFS=$OIFS } #======================================================================================== # main #======================================================================================== if [ $# -eq 0 ] then # get current user user=`whoami` if [ "${user}" = "root" ] then mecho --error "error: user 'root' isn't allowed" mecho mecho --error "use '${0} username' to set username" exit 1 fi else # set user user=${1} fi # get home directory if getent passwd ${user} >/dev/null 2>&1 then # account exists - get home directory list_file=`getent passwd ${user} | cut -d: -f6` > /dev/null else mecho --error "error: user couldn't be found: ${user}" mecho mecho --error "use '${0} username' to set username" exit 1 fi # add file name to path list_file="$list_file/.archimap-active" # get user defaults if [ -f "$list_file" ] then mecho "user: $user" mecho "file: $list_file" mecho check_parameters $user cat $list_file|sed -e '/^[#| |ARCHIMAP_].*/d' -e '/^$/d'| \ while read line do check_line "$line" done else # file not found mecho --error "error: file '$list_file' couldn't be found!" fi exit 0 #======================================================================================== # end #========================================================================================