#!/bin/sh
#
# Configure aiguard.conf & avira.conf files
#
# Copyright (c) 2002-2004 AVIRA GmbH
#

PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin"

OS=`uname | tr "[:upper:]" "[:lower:]"`
OSREL="`uname -r`"

case "${OS}" in
	sunos)
		CLEAR="clear"
		ECHO="/usr/lib/AVIRA/echo_sunos"
		if [ ! -x "${ECHO}" ]
		then
			ECHO="echo"
		fi
		PSAX="ps -Af"
		;;
	*)
		CLEAR="clear"
		ECHO="echo"
		PSAX="ps ax"
		;;
esac

check_executables()
{
	for EXE in $EXELIST
	do
		if [ ! -x "`which $EXE`" ]
		then
			$ECHO ""
			$ECHO "This script requires '$EXE' to run."
			$ECHO " "
			exit 1
		fi
	done
}

set_defaults()
{
	NUMDAEMONS=3
	ACCESSMASK=3
	REPAIRINFECTED=0
	HANDLEINFECTED="l"
	MOVETODIR=""
	EMAILTO=""
	LOGTO=""
	INCLUDEPATH=":"
	EXCLUDEPATH=":"
	AUTOUPDATEFREQUENCY=""
	AUTOUPDATETIME=""
	ARCHIVESCAN=0
	ARCHIVEMAXSIZE=1073741824
	ARCHIVEMAXRECURSION=20
	ARCHIVEMAXRATIO=150
	PROXYSERVER=""
	PROXYPORT=8080
	PROXYUSERNAME=""
	PROXYPASSWORD=""
	SYSLOGFACILITY="user"
	SYSLOGPRIORITY="notice"
	GNUPGBINARY=""
	GNUPGOPTIONS=""
	SAPCARPROGRAM=""
	DETECTDIALER=0
	DETECTJOKE=0
	DETECTGAME=0
	DETECTSPR=0
	HEURISTICSMACRO=1
	HEURISTICSLEVEL=0
	UPDATERKEEPSBACKUPS=0
	EXTERNALPROGRAM=""
	GUISUPPORT=""
	GUICAFILE=""
	GUICERTFILE=""
	GUICERTPASS=""
}

set_recommend()
{
	REPAIRINFECTED=1
	INCLUDEPATH=":/home:/tmp:/var/tmp:"
	AUTOUPDATEFREQUENCY="2h"
}

bit_value()
{
	BITTEMP=$BITCHECK
	BITCOUNT=1
	while [ $BITCOUNT -lt $BIT ]
	do
		BITTEMP=`expr $BITTEMP / 2`
		BITCOUNT=`expr $BITCOUNT + 1`
	done

	return `expr $BITTEMP % 2`
}

reminder()
{
	$ECHO " "
	$ECHO "Here are some commands that you should remember..."
	$ECHO " "
	if [ $CONFIGGUARD -eq 1 ]
	then
		$ECHO "AiGuard"
		$ECHO "======="
		$ECHO "configure:  $AVDIR/configaiguard"
		$ECHO "start:      $AVDIR/aiguard start"
		$ECHO "stop:       $AVDIR/aiguard stop"
		$ECHO "check:      $AVDIR/aiguard status"
	else
		$ECHO "AVIRA"
		$ECHO "======="
		$ECHO "configure:  $AVDIR/configavira"
	fi

	if [ -f $AVDIR/aiupdater ]
	then
		$ECHO " "
		$ECHO "Automatic Internet Updater"
		$ECHO "=========================="
		$ECHO "start:      $AVDIR/aiupdater start"
		$ECHO "stop:       $AVDIR/aiupdater stop"
		$ECHO "check:      $AVDIR/aiupdater status"
	fi
	$ECHO " "
}

check_config()
{
	if [ $ACCESSMASK -eq 0 ]
	then
		WARNING=1
		$ECHO ""
		$ECHO "******************************************************************"
		$ECHO " AiGuard WARNING: NO SCANNING WILL OCCUR WITH THIS CONFIGURATION!"
		$ECHO "                  Scan on at least open or close."
		$ECHO "******************************************************************"
	fi
	if [ "$INCLUDEPATH" = ":" ]
	then
		WARNING=1
		$ECHO ""
		$ECHO "***********************************************************************"
		$ECHO " AiGuard WARNING: NO SCANNING WILL OCCUR WITH THIS CONFIGURATION!"
		$ECHO "                  Include at least one directory in the include paths."
		$ECHO "***********************************************************************"
	fi
}

show_config()
{
	if [ $CONFIGGUARD -eq 1 ]
	then
		$ECHO "number of daemons:            $NUMDAEMONS"
		INPUT=0
		$ECHO -n "scan on:                      "
		BITCHECK=$ACCESSMASK
		BIT=1
		bit_value
		if [ $? -eq 1 ]
		then
			if [ $INPUT -eq 1 ]
			then
				$ECHO -n "/"
			fi
			$ECHO -n "open"
			INPUT=1
		fi
		BIT=2
		bit_value
		if [ $? -eq 1 ]
		then
			if [ $INPUT -eq 1 ]
			then
				$ECHO -n "/"
			fi
			$ECHO -n "close"
			INPUT=1
		fi
		BIT=3
		bit_value
		if [ $? -eq 4 ]
		then
			if [ $INPUT -eq 1 ]
			then
				$ECHO -n "/"
			fi
			$ECHO -n "execute"
			INPUT=1
		fi
		$ECHO " "
		$ECHO -n "repair concerning files:      "
		if [ $REPAIRINFECTED -eq 0 ]
		then
			$ECHO "no"
		else
			$ECHO "yes"
		fi
		$ECHO -n "handling of concerning files: "
		case "$HANDLEINFECTED" in
			l)
				$ECHO "log only"
				;;
			r)
				$ECHO "rename"
				;;
			m)
				$ECHO "move to $MOVETODIR"
				;;
			*)
				$ECHO "?"
				;;
		esac
		CUT="`$ECHO $INCLUDEPATH | sed -e s/\^://`"
		CUT="`$ECHO $CUT | sed -e s/:\$//`"
		CUT="`$ECHO $CUT | sed -e s/\\\"//g`"
		$ECHO "include paths:                $CUT"
		CUT="`$ECHO $EXCLUDEPATH | sed -e s/\^://`"
		CUT="`$ECHO $CUT | sed -e s/:\$//`"
		CUT="`$ECHO $CUT | sed -e s/\\\"//g`"
		$ECHO "exclude paths:                $CUT"
		if [ $SERVER -eq 1 ]
		then
			$ECHO -n "scan archives:                "
			if [ $ARCHIVESCAN -eq 0 ]
			then
				$ECHO "no"
			else
				$ECHO "yes"
				$ECHO -n "max archive size:             "
				if [ $ARCHIVEMAXSIZE -eq 0 ]
				then
					$ECHO "unlimited"
				else
					$ECHO "$ARCHIVEMAXSIZE bytes"
				fi
				$ECHO -n "max archive recursion:        "
				if [ $ARCHIVEMAXRECURSION -eq 0 ]
				then
					$ECHO "unlimited"
				else
					$ECHO "$ARCHIVEMAXRECURSION levels"
				fi
				$ECHO -n "max archive ratio:            "
				if [ $ARCHIVEMAXRATIO -eq 0 ]
				then
					$ECHO "unlimited"
				else
					$ECHO "$ARCHIVEMAXRATIO:1"
				fi
			fi
		fi
	fi

	$ECHO -n "email notification:           "
	if [ -z "$EMAILTO" ]
	then
		$ECHO "no"
	else
		$ECHO "$EMAILTO"
	fi
	$ECHO -n "specific logfile:             "
	if [ -z "$LOGTO" ]
	then
		$ECHO "no"
	else
		$ECHO "$LOGTO"
	fi
	$ECHO -n "update frequency:             "
	case "$AUTOUPDATEFREQUENCY" in
		2h)
			$ECHO "every 2 hours (if aiupdater is running)"
			;;
		1d)
			$ECHO "daily (if aiupdater is running)"

			$ECHO -n "update time:                  "
			if [ -z "$AUTOUPDATETIME" ]
			then
				$ECHO "random (if aiupdater is running)"
			else
				$ECHO "$AUTOUPDATETIME (if aiupdater is running)"
			fi
			;;
		*)
			$ECHO "never"
			;;
	esac
	if [ ! -z "$PROXYSERVER" ]
	then
		$ECHO "http proxy server:            $PROXYSERVER:$PROXYPORT"
		if [ ! -z "$PROXYUSERNAME" ]
		then
			$ECHO "http proxy login:             $PROXYUSERNAME:$PROXYPASSWORD"
		fi
	fi
	$ECHO "syslog output:                $SYSLOGFACILITY.$SYSLOGPRIORITY"

	if [ $CONFIGGUARD -eq 1 ]
	then
		check_config
	fi
}

get_quoted_parameter()
{
	QUOTE=0
	INPUT=""
	OK=0

	set -- $PARAMS

	while [ $OK -eq 0 -a $# -gt 0 ]
	do
		if [ $QUOTE -eq 1 ]
		then
			CUT="`$ECHO $1 | sed -e s/\\\"\$//`"
			if [ "$CUT" != "$1" ]
			then
				#end quote
				INPUT="$INPUT $CUT"
				QUOTE=0
				OK=1
			else
				#middle quote
				INPUT="$INPUT $1"
			fi
		else
			CUT="`$ECHO $1 | sed -e s/\^\\\"//`"
			if [ "$CUT" != "$1" ]
			then
				#start quote
				INPUT="$CUT"
				QUOTE=1
			else
				#no quote
				INPUT="$1"
				OK=1
			fi
		fi

		shift
	done

	PARAMS="$*"
}

read_conf()
{
	if [ $HAVECONFIG -ne 1 ]
	then
		set_defaults

		HAVECONFIG=1
	fi

	if [ ! -f "$CONF_FILE" ]
	then
		return
	fi

	PARAMS=`grep \^[\^#].* $CONF_FILE`

	if [ -z "$PARAMS" ] 
	then
		return
	fi

	set -- $PARAMS

	QUOTE=0
	QUOTESTRING=""

	while [ $# -gt 0 ]
	do
		PARAMS="$*"
		get_quoted_parameter
		set -- $PARAMS

		case "$INPUT" in
			NumDaemons)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						if [ $1 -ge $MINDAEMONS -a $1 -le $MAXDAEMONS ]
						then
							NUMDAEMONS=$1
							shift
						fi
					fi
				fi
				;;
			AccessMask)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						ACCESSMASK=`expr $1 % 256`
						shift
					fi
				fi
				;;
			RepairConcerningFiles)
				REPAIRINFECTED=1
				;;
			LogOnly)
				HANDLEINFECTED="l"
				;;
			RenameConcerningFiles)
				HANDLEINFECTED="r"
				;;
			MoveConcerningFilesTo)
				if [ ! -z "$1" ]
				then
					PARAMS="$*"
					get_quoted_parameter
					set -- $PARAMS
					HANDLEINFECTED="m"
					MOVETODIR=$INPUT
				fi
				;;
			IncludePath)
				if [ ! -z "$1" ]
				then
					PARAMS="$*"
					get_quoted_parameter
					set -- $PARAMS
					INCLUDEPATH="$INCLUDEPATH$INPUT:"
				fi
				;;
			ExcludePath)
				if [ ! -z "$1" ]
				then
					PARAMS="$*"
					get_quoted_parameter
					set -- $PARAMS
					EXCLUDEPATH="$EXCLUDEPATH$INPUT:"
				fi
				;;
			ArchiveScan)
				ARCHIVESCAN=1
				;;
			ArchiveMaxSize)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						ARCHIVEMAXSIZE=$1
						shift
					fi
				fi
				;;
			ArchiveMaxRecursion)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						ARCHIVEMAXRECURSION=$1
						shift
					fi
				fi
				;;
			ArchiveMaxRatio)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						ARCHIVEMAXRATIO=$1
						shift
					fi
				fi
				;;
			EmailTo)
				if [ ! -z "$1" ]
				then
					EMAILTOTEMP1=`grep \^EmailTo $CONF_FILE`
					EMAILTO="`$ECHO $EMAILTOTEMP1 | sed -e s/\^EmailTo//`"
					EMAILTEMP2=""
					for EMAILTOTEMP1 in $EMAILTO
					do
						if [ -z "$EMAILTEMP2" ]
						then
							EMAILTOTEMP2="$EMAILTOTEMP1"
						else
							EMAILTOTEMP2="$EMAILTOTEMP2 $EMAILTOTEMP1"
						fi
					done
					EMAILTO="$EMAILTOTEMP2"
					shift
				fi
				;;
			LogTo)
				if [ ! -z "$1" ]
				then
					PARAMS="$*"
					get_quoted_parameter
					set -- $PARAMS
					LOGTO=$INPUT
				fi
				;;
			AutoUpdateEvery2Hours)
				AUTOUPDATEFREQUENCY="2h"
				;;
			AutoUpdateDaily)
				AUTOUPDATEFREQUENCY="1d"
				;;
			AutoUpdateTime)
				if [ ! -z "$1" ]
				then
					AUTOUPDATETIME=$1
				fi
				;;
			HTTPProxyServer)
				if [ ! -z "$1" ]
				then
					PROXYSERVER=$1
					shift
				fi
				;;
			HTTPProxyPort)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						PROXYPORT=$1
						shift
					fi
				fi
				;;
			HTTPProxyUsername)
				if [ ! -z "$1" ]
				then
					PROXYUSERNAME=$1
					shift
				fi
				;;
			HTTPProxyPassword)
				if [ ! -z "$1" ]
				then
					PARAMS="$*"
					get_quoted_parameter
					set -- $PARAMS
					PROXYPASSWORD=$INPUT
				fi
				;;
			SyslogFacility)
				if [ ! -z "$1" ]
				then
					SYSLOGFACILITY=$1
					shift
				fi
				;;
			SyslogPriority)
				if [ ! -z "$1" ]
				then
					SYSLOGPRIORITY=$1
					shift
				fi
				;;
			GnuPGBinary)
				if [ ! -z "$1" ]
				then
					GNUPGBINARY=$1
					shift
				fi
				;;
			GnuPGOptions)
				if [ ! -z "$1" ]
				then
					GNUPGOPTIONS=`grep \^GnuPGOptions $CONF_FILE`
					shift
				fi
				;;
			SapCarProgram)
				if [ ! -z "$1" ]
				then
					SAPCARPROGRAM=`grep \^SapCarProgram $CONF_FILE`
					shift
				fi
				;;
			DetectDialer)
				DETECTDIALER=1
				;;
			DetectJoke)
				DETECTJOKE=1
				;;
			DetectGame)
				DETECTGAME=1
				;;
			DetectPMS|DetectSPR)
				DETECTSPR=1
				;;
			HeuristicsMacro)
				HEURISTICSMACRO=1
				;;
			HeuristicsLevel)
				if [ ! -z "$1" ]
				then
					if [ -z "`$ECHO $1 | sed -e s/[0-9]//g`" ]
					then
						HEURISTICSLEVEL=$1
						shift
					fi
				fi
				;;
			UpdaterKeepsBackups)
				UPDATERKEEPSBACKUPS=1
				;;
			ExternalProgram)
				if [ ! -z "$1" ]
				then
					EXTERNALPROGRAM=`grep \^ExternalProgram $CONF_FILE`
					shift
				fi
				;;
			GuiSupport)
				if [ ! -z "$1" ]
				then
					GUISUPPORT=$1
					shift
				fi
				;;
			GuiCAFile)
				if [ ! -z "$1" ]
				then
					GUICAFILE=$1
					shift
				fi
				;;
			GuiCertFile)
				if [ ! -z "$1" ]
				then
					GUICERTFILE=$1
					shift
				fi
				;;
			GuiCertPass)
				if [ ! -z "$1" ]
				then
					GUICERTPASS=$1
					shift
				fi
				;;
		esac

		while [ -z "$PARAMS" -a $# -ne 0 ]
		do
			shift
		done
	done
}

save_guard_conf()
{
	if [ ! -w $CONF_FILE ]
	then
		return 1
	fi

	$ECHO "#" > $CONF_FILE

	$ECHO "# AiGuard configuration file" >> $CONF_FILE
	$ECHO "#" >> $CONF_FILE
	$ECHO "# automatically generated by configaiguard" >> $CONF_FILE
	$ECHO "# `date`" >> $CONF_FILE
	$ECHO "#" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# Number of aiguard daemons to be launched at once." >> $CONF_FILE
	$ECHO "# A workstation typically does not require more than" >> $CONF_FILE
	$ECHO "# 3 daemons. File/HTTP servers may require more." >> $CONF_FILE
	$ECHO "# Possible values are $MINDAEMONS .. $MAXDAEMONS, default is 3." >> $CONF_FILE
	$ECHO "# A value of 0 disables aiguard." >> $CONF_FILE
	$ECHO "NumDaemons $NUMDAEMONS" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# AccessMask selects which events invoke the scanner." >> $CONF_FILE
	$ECHO "# The different events are:" >> $CONF_FILE
	$ECHO "#  1 = scan on file open" >> $CONF_FILE
	$ECHO "#  2 = scan on file close" >> $CONF_FILE
	$ECHO "#  4 = scan on file execute" >> $CONF_FILE
	$ECHO "# Sum the numbers of the events you want. For example, an" >> $CONF_FILE
	$ECHO "# AccessMask value of 3 will scan files when they are" >> $CONF_FILE
	$ECHO "# opened and when they are closed. The default value is" >> $CONF_FILE
	$ECHO "# to scan on open and close (3)." >> $CONF_FILE
	$ECHO "AccessMask $ACCESSMASK" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# RepairConcerningFiles - try to remove the problem from the" >> $CONF_FILE
	$ECHO "# file being accessed. If this is sucessfully done, the desired" >> $CONF_FILE
	$ECHO "# access will be granted. If it fails, file access will be" >> $CONF_FILE
	$ECHO "# blocked. By default, this is not enabled." >> $CONF_FILE
	if [ $REPAIRINFECTED -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "RepairConcerningFiles" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# If the option "RepairConcerningFiles" was not set or the problem is" >> $CONF_FILE
	$ECHO "# note removeable then do one of the following with the concerning" >> $CONF_FILE
	$ECHO "# file. Please use only one of the following options as the last one" >> $CONF_FILE
	$ECHO "# will be taken. Default is LogOnly. For "MoveConcerningFilesTo" a" >> $CONF_FILE
	$ECHO "# parameter is required that specifies the directory where the" >> $CONF_FILE
	$ECHO "# files will be moved to. The directory will be created if it" >> $CONF_FILE
	$ECHO "# does not already exist." >> $CONF_FILE
	if [ $HANDLEINFECTED != "l" ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "LogOnly" >> $CONF_FILE
	if [ $HANDLEINFECTED != "r" ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "RenameConcerningFiles" >> $CONF_FILE
	if [ $HANDLEINFECTED != "m" ]
	then
		$ECHO "#MoveConcerningFilesTo /home/unwanted" >> $CONF_FILE
	else
		CUT="`$ECHO $MOVETODIR | sed -e s/\ //g`"
		if [ "$CUT" != "$MOVETODIR" ]
		then
			$ECHO "MoveConcerningFilesTo \"$MOVETODIR\"" >> $CONF_FILE
		else
			$ECHO "MoveConcerningFilesTo $MOVETODIR" >> $CONF_FILE
		fi
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# Directories where files may be scanned are specified using" >> $CONF_FILE
	$ECHO "# IncludePath. Only one path per directive is allowed. (this" >> $CONF_FILE
	$ECHO "# includes all subdirectories)" >> $CONF_FILE
	$ECHO "#IncludePath /home" >> $CONF_FILE
	$ECHO "#IncludePath /var/tmp" >> $CONF_FILE
	$ECHO "#IncludePath /tmp" >> $CONF_FILE
	if [ "$INCLUDEPATH" != ":" ]
	then
		OLDIFS=$IFS
		IFS=":"
		for ITEM in $INCLUDEPATH
		do
			ITEM="`$ECHO $ITEM | sed -e s/\^\\\"//`"
			ITEM="`$ECHO $ITEM | sed -e s/\\\"\$//`"
			CUT="`$ECHO $ITEM | sed -e s/\^\\\///`"
			if [ "$CUT" != "$ITEM" ]
			then
				CUT="`$ECHO $ITEM | sed -e s/\ //g`"
				if [ "$CUT" != "$ITEM" ]
				then
					$ECHO "IncludePath \"$ITEM\"" >> $CONF_FILE
				else
					$ECHO "IncludePath $ITEM" >> $CONF_FILE
				fi
			fi
		done
		IFS=$OLDIFS
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# Directories where files will NOT be scanned are specified" >> $CONF_FILE
	$ECHO "# using ExcludePath. Only one path per directive is allowed." >> $CONF_FILE
	$ECHO "# (this includes all subdirectories) Any directories that" >> $CONF_FILE
	$ECHO "# are not specified using the IncludePath directive, are" >> $CONF_FILE
	$ECHO "# already not being scanned." >> $CONF_FILE
	$ECHO "#ExcludePath /home/log" >> $CONF_FILE
	$ECHO "#ExcludePath /pub/log" >> $CONF_FILE
	if [ "$EXCLUDEPATH" != ":" ]
	then
		OLDIFS=$IFS
		IFS=":"
		for ITEM in $EXCLUDEPATH
		do
			ITEM="`$ECHO $ITEM | sed -e s/\^\\\"//`"
			ITEM="`$ECHO $ITEM | sed -e s/\\\"\$//`"
			CUT="`$ECHO $ITEM | sed -e s/\^\\\///`"
			if [ "$CUT" != "$ITEM" ]
			then
				CUT="`$ECHO $ITEM | sed -e s/\ //g`"
				if [ "$CUT" != "$ITEM" ]
				then
					$ECHO "ExcludePath \"$ITEM\"" >> $CONF_FILE
				else
					$ECHO "ExcludePath $ITEM" >> $CONF_FILE
				fi
			fi
		done
		IFS=$OLDIFS
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# Compressed files can be scanned on access if the" >> $CONF_FILE
	$ECHO "# ArchiveScan directive is given. Default is not" >> $CONF_FILE
	$ECHO "# to scan compressed files on access." >> $CONF_FILE
	$ECHO "# This option is available in the Server Edition only." >> $CONF_FILE
	if [ $ARCHIVESCAN -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "ArchiveScan" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# If compressed files are being scanned, a maximum" >> $CONF_FILE
	$ECHO "# size (in bytes) can be set. Files (or compressed" >> $CONF_FILE
	$ECHO "# contents) larger than this size will not be scanned." >> $CONF_FILE
	$ECHO "# A value of 0 means no maximum size. Default is" >> $CONF_FILE
	$ECHO "# 1 gigabyte (1073741824)" >> $CONF_FILE
	$ECHO "# This option is available in the Server Edition only." >> $CONF_FILE
	if [ $ARCHIVESCAN -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "ArchiveMaxSize $ARCHIVEMAXSIZE" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# If compressed files are being scanned, a maximum" >> $CONF_FILE
	$ECHO "# uncompression recursion limit can be set. A value" >> $CONF_FILE
	$ECHO "# of 0 means no limit. Default is 20." >> $CONF_FILE
	$ECHO "# This option is available in the Server Edition only." >> $CONF_FILE
	if [ $ARCHIVESCAN -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "ArchiveMaxRecursion $ARCHIVEMAXRECURSION" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# If compressed files are being scanned, a maximum" >> $CONF_FILE
	$ECHO "# uncompression ratio limit can be set. A value" >> $CONF_FILE
	$ECHO "# of 0 means no limit. Default is 150." >> $CONF_FILE
	$ECHO "# This option is available in the Server Edition only." >> $CONF_FILE
	if [ $ARCHIVESCAN -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "ArchiveMaxRatio $ARCHIVEMAXRATIO" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# Run an external program for each concerning file found. You may" >> $CONF_FILE
	$ECHO "# use macros to pass as arguments for the program." >> $CONF_FILE
	$ECHO "# %h - path to file (may contain spaces)" >> $CONF_FILE
	$ECHO "# %f - filename only (may contain spaces)" >> $CONF_FILE
	$ECHO "# %p - full name of file (%h/%f) (may contain spaces)" >> $CONF_FILE
	$ECHO "# %U - UID of file" >> $CONF_FILE
	$ECHO "# %G - GID of file" >> $CONF_FILE
	$ECHO "# %s - size of file" >> $CONF_FILE
	$ECHO "# %m - mode of file" >> $CONF_FILE
	$ECHO "# %De - event type" >> $CONF_FILE
	$ECHO "# %DF - device" >> $CONF_FILE
	$ECHO "# %Dp - operation PID" >> $CONF_FILE
	$ECHO "# %Du - operation UID" >> $CONF_FILE
	$ECHO "# %Df - operation flags" >> $CONF_FILE
	$ECHO "# %Dm - operation mode" >> $CONF_FILE
	$ECHO "# %Sn - name of alert" >> $CONF_FILE
	$ECHO "# %Sa - additional alert information" >> $CONF_FILE
	$ECHO "# Note: Dazuko 2.0.0 or higher is required in order to use this" >> $CONF_FILE
	$ECHO "#       feature." >> $CONF_FILE
	if [ -z "$EXTERNALPROGRAM" ]
	then
		$ECHO "#ExternalProgram /usr/bin/logger -- blocking access to %p (%Sn)" >> $CONF_FILE
	else
		$ECHO "$EXTERNALPROGRAM" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# Enable and configure GUI support" >> $CONF_FILE
	if [ -z "$GUISUPPORT" ]
	then
		$ECHO "GuiSupport  no" >> $CONF_FILE
	else
		$ECHO "GuiSupport  $GUISUPPORT" >> $CONF_FILE
	fi
	if [ -z "$GUICAFILE" ]
	then
		$ECHO "#GuiCAFile   /usr/lib/AVIRA/gui/cert/cacert.pem" >> $CONF_FILE
	else
		$ECHO "GuiCAFile   $GUICAFILE" >> $CONF_FILE
	fi
	if [ -z "$GUICERTFILE" ]
	then
		$ECHO "#GuiCertFile /usr/lib/AVIRA/gui/cert/server.pem" >> $CONF_FILE
	else
		$ECHO "GuiCertFile $GUICERTFILE" >> $CONF_FILE
	fi
	if [ -z "$GUICERTPASS" ]
	then
		$ECHO "#GuiCertPass avira_default" >> $CONF_FILE
	else
		$ECHO "GuiCertPass $GUICERTPASS" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	return 0
}

save_avira_conf()
{
	LICENSELINES=""

	if [ -f $CONF_FILE ]
	then
		LICENSELINES=`grep \^License $CONF_FILE`
	fi

	if [ ! -w $CONF_FILE ]
	then
		return 1
	fi

	$ECHO "#" > $CONF_FILE

	$ECHO "# AVIRA configuration file" >> /etc/avira.conf
	$ECHO "#" >> $CONF_FILE
	$ECHO "# automatically generated by configaiguard" >> $CONF_FILE
	$ECHO "# `date`" >> $CONF_FILE
	$ECHO "#" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# You can receive email notifications of alerts using this" >> $CONF_FILE
	$ECHO "# directive. You must specify the email address to which the" >> $CONF_FILE
	$ECHO "# notification will be sent. There is no default value for" >> $CONF_FILE
	$ECHO "# this directive." >> $CONF_FILE
	if [ -z "$EMAILTO" ]
	then
		$ECHO "#EmailTo root@localhost" >> $CONF_FILE
	else
		$ECHO "EmailTo $EMAILTO" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# Concerning activity may also be logged to a specified file" >> $CONF_FILE
	$ECHO "# (in addition to syslog). You must specify the file. There" >> $CONF_FILE
	$ECHO "# is no default value for this directive." >> $CONF_FILE
	if [ -z "$LOGTO" ]
	then
		$ECHO "#LogTo /var/log/avira.log" >> $CONF_FILE
	else
		CUT="`$ECHO $LOGTO | sed -e s/\ //g`"
		if [ "$CUT" != "$LOGTO" ]
		then
			$ECHO "LogTo \"$LOGTO\"" >> $CONF_FILE
		else
			$ECHO "LogTo $LOGTO" >> $CONF_FILE
		fi
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# New engine and data files can be automatically" >> $CONF_FILE
	$ECHO "# updated via the internet. Please use only one of the" >> $CONF_FILE
	$ECHO "# following options as the last one will be taken. You" >> $CONF_FILE
	$ECHO "# can choose to have the automatic updates be every 2 hours" >> $CONF_FILE
	$ECHO "# or once a day. If neither directive is given, the" >> $CONF_FILE
	$ECHO "# automatic internet updater will be disabled." >> $CONF_FILE
	$ECHO "# Note: Internet updates can also be done manually using" >> $CONF_FILE
	$ECHO "#       the --update parameter with the command line" >> $CONF_FILE
	$ECHO "#       scanner." >> $CONF_FILE
	if [ "$AUTOUPDATEFREQUENCY" != "2h" ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "AutoUpdateEvery2Hours" >> $CONF_FILE
	if [ "$AUTOUPDATEFREQUENCY" != "1d" ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "AutoUpdateDaily" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# If automatic updates are done daily, you can specify" >> $CONF_FILE
	$ECHO "# at what time of day the updates should be done." >> $CONF_FILE
	if [ ! -z "$AUTOUPDATETIME" -a "$AUTOUPDATEFREQUENCY" = "1d" ]
	then
		$ECHO "AutoUpdateTime $AUTOUPDATETIME" >> $CONF_FILE
	else
		$ECHO "#AutoUpdateTime 4:23" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# If your machine uses an HTTP proxy server, you must" >> $CONF_FILE
	$ECHO "# specify the proxy configuration settings in order to" >> $CONF_FILE
	$ECHO "# make internet updates." >> $CONF_FILE
	if [ -z "$PROXYSERVER" ]
	then
		$ECHO "#HTTPProxyServer proxy.domain.com" >> $CONF_FILE
		$ECHO "#HTTPProxyPort 8080" >> $CONF_FILE
	else
		$ECHO "HTTPProxyServer $PROXYSERVER" >> $CONF_FILE
		$ECHO "HTTPProxyPort $PROXYPORT" >> $CONF_FILE
	fi
	if [ -z "$PROXYUSERNAME" -o -z "$PROXYSERVER" ]
	then
		$ECHO "#HTTPProxyUsername username" >> $CONF_FILE
		$ECHO "#HTTPProxyPassword password" >> $CONF_FILE
	else
		$ECHO "HTTPProxyUsername $PROXYUSERNAME" >> $CONF_FILE
		$ECHO "HTTPProxyPassword $PROXYPASSWORD" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# Regardless of the above configuration settings, AVIRA" >> $CONF_FILE
	$ECHO "# will always log important information using syslog. It" >> $CONF_FILE
	$ECHO "# is possible to specify which syslog facility and" >> $CONF_FILE
	$ECHO "# priority you would like AVIRA to use. If not given," >> $CONF_FILE
	$ECHO "# default values are facility:user priority:notice." >> $CONF_FILE
	if [ -z "$SYSLOGFACILITY" ]
	then
		$ECHO "#SyslogFacility user" >> $CONF_FILE
	else
		$ECHO "SyslogFacility $SYSLOGFACILITY" >> $CONF_FILE
	fi
	if [ -z "$SYSLOGPRIORITY" ]
	then
		$ECHO "#SyslogPriority notice" >> $CONF_FILE
	else
		$ECHO "SyslogPriority $SYSLOGPRIORITY" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# AVIRA supports GnuPG (http://www.gnupg.org) in order" >> $CONF_FILE
	$ECHO "# to verify the authenticity of internet update files." >> $CONF_FILE
	$ECHO "# In order for the updater to utilize GnuPG, it must know" >> $CONF_FILE
	$ECHO "# where the executable is located. If you choose to take" >> $CONF_FILE
	$ECHO "# advantage of GnuPG, be aware that all updates will fail" >> $CONF_FILE
	$ECHO "# until the AVIRA public key (avira.gpg) has been" >> $CONF_FILE
	$ECHO "# added to your keyring and signed." >> $CONF_FILE
	if [ -z "$GNUPGBINARY" ]
	then
		$ECHO "#GnuPGBinary /usr/local/bin/gpg" >> $CONF_FILE
	else
		$ECHO "GnuPGBinary $GNUPGBINARY" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# If you are utilizing GnuPG, you may also specify" >> $CONF_FILE
	$ECHO "# options that your particular setup might need." >> $CONF_FILE
	$ECHO "# Normally no options are required." >> $CONF_FILE
	if [ -z "$GNUPGOPTIONS" ]
	then
		$ECHO "#GnuPGOptions" >> $CONF_FILE
	else
		$ECHO "$GNUPGOPTIONS" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	$ECHO "# These settings allow for the detection of certain categories" >> $CONF_FILE
	$ECHO "# of software which are not viruses but might not be wanted." >> $CONF_FILE
	if [ $DETECTDIALER -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "DetectDialer" >> $CONF_FILE
	if [ $DETECTJOKE -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "DetectJoke" >> $CONF_FILE
	if [ $DETECTGAME -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "DetectGame" >> $CONF_FILE
	if [ $DETECTSPR -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "DetectSPR" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# AVIRA is capable of using heuristics to determine if a file" >> $CONF_FILE
	$ECHO "# may be malicious. This allows new or unknown malicious code to" >> $CONF_FILE
	$ECHO "# be detected before you have had a chance to perform an update." >> $CONF_FILE
	$ECHO "# There are two types of heuristics that AVIRA uses. The" >> $CONF_FILE
	$ECHO "# first, HeuristicsMacro, only deals with macros in office" >> $CONF_FILE
	$ECHO "# documents. This can be disabled by commenting out the directive." >> $CONF_FILE
	$ECHO "# The second, HeuristicsLevel, deals with all types of files and" >> $CONF_FILE
	$ECHO "# can be set to a certain level of intensity (0-3). 0 means" >> $CONF_FILE
	$ECHO "# disabled and 3 means full intensity." >> $CONF_FILE
	$ECHO "# Note: Be aware that setting the HeuristicsLevel too high could" >> $CONF_FILE
	$ECHO "#       result in false alerts." >> $CONF_FILE
	if [ $HEURISTICSMACRO -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "HeuristicsMacro" >> $CONF_FILE
	$ECHO "HeuristicsLevel $HEURISTICSLEVEL" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# By default the updater drops the new software right into place." >> $CONF_FILE
	$ECHO "# Should you wish to keep previous versions of the replaced files" >> $CONF_FILE
	$ECHO "# then activate this option.  When enabled the old versions will" >> $CONF_FILE
	$ECHO "# be kept inside \"updater-backup-YYYYmmdd-HHMMSS\" subdirectories." >> $CONF_FILE
	$ECHO "# Note: You may need to schedule cleanup jobs when using this" >> $CONF_FILE
	$ECHO "#       feature so that your disk does not fill up." >> $CONF_FILE
	if [ $UPDATERKEEPSBACKUPS -eq 0 ]
	then
		$ECHO -n "#" >> $CONF_FILE
	fi
	$ECHO "UpdaterKeepsBackups" >> $CONF_FILE
	$ECHO "" >> $CONF_FILE

	$ECHO "# AVIRA is capable of scanning the contents of sapcar archives." >> $CONF_FILE
	$ECHO "# This requires the SAPCAR program from SAP." >> $CONF_FILE
	if [ -z "$SAPCARPROGRAM" ]
	then
		$ECHO "#SapCarProgram /usr/local/bin/SAPCAR" >> $CONF_FILE
	else
		$ECHO "$SAPCARPROGRAM" >> $CONF_FILE
	fi
	$ECHO "" >> $CONF_FILE

	if [ "$VARIANT" = "AIEN" ]
	then
		$ECHO "# Once you have registered your AVIRA product, you will receive" >> $CONF_FILE
		$ECHO "# a registration code. To use the code, it needs to be specified" >> $CONF_FILE
		$ECHO "# using the License directive. After you have received your" >> $CONF_FILE
		$ECHO "# registration code, you may activate your product. Once you" >> $CONF_FILE
		$ECHO "# have activated the product, you will receive an activation key." >> $CONF_FILE
		$ECHO "# To use the key, it must also be specified using the License" >> $CONF_FILE
		$ECHO "# directive. It should be on the same line as the corresponding" >> $CONF_FILE
		$ECHO "# registration code." >> $CONF_FILE
		$ECHO "#License registration_code" >> $CONF_FILE
		$ECHO "#License registration_code activation_key" >> $CONF_FILE
		if [ ! -z "$LICENSELINES" ]
		then
			$ECHO "$LICENSELINES" >> $CONF_FILE
		fi
		$ECHO "" >> $CONF_FILE
	fi

	return 0
}

read_directory()
{
	read INPUT
	if [ -z "$INPUT" ]
	then
		return 0
	fi

	NEWINPUT="`$ECHO $INPUT | sed -e s/\\\"//g`"
	CUT="`$ECHO $NEWINPUT | sed -e s/\^\\\///`"

	if [ "$CUT" = "$NEWINPUT" ]
	then
		return 2
	fi

	return 1
}

question()
{
	$ECHO -n "[$QDEFAULT] "
	read INPUT

	if [ -z "$INPUT" ]
	then
		INPUT="$QDEFAULT"
	fi

	NUM=1
	for CHOICE in $QCHOICES
	do
		if [ "$INPUT" = $CHOICE ]
		then
			OK=1
			return $NUM
		fi
		NUM=`expr $NUM + 1`
	done

	return $NUM
}

ynquestion()
{
	test $YNQDEFAULTTEST
	ANS=$?

	if [ $ANS -eq 0 ]
	then
		QDEFAULT="y"
	else
		QDEFAULT="n"
	fi

	QCHOICES="y n"

	question
	ANS=$?

	return $ANS
}

config_numdaemons()
{
	$CLEAR
	$ECHO "NumDaemons                                                      ($PAGE of $TOTALPAGES)"
	$ECHO "=========="
	$ECHO "Files that are accessed by multiple processes at the same time can be"
	$ECHO "scanned by AiGuard in parallel. This is accomplished by running multiple"
	$ECHO "scanning daemons, which allows your machine to run AiGuard with the least"
	$ECHO "amount of performance reduction."
	$ECHO " "
	$ECHO "A typical workstation only requires 3 daemons for optimal performance. If"
	$ECHO "you are running additional servers (such as file, http, ftp, etc) then it"
	$ECHO "is recommended that more daemons are used. You can disable AiGuard by"
	$ECHO "setting a value of 0 here."
	$ECHO " "
	$ECHO "available options: $MINDAEMONS-$MAXDAEMONS"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "
	
		QDEFAULT=$NUMDAEMONS
		QCHOICES=""
		NUM=$MINDAEMONS
		while [ $NUM -le $MAXDAEMONS ]
		do
			QCHOICES="$QCHOICES $NUM"
			NUM=`expr $NUM + 1`
		done

		$ECHO -n "How many daemons would you like to run? "
		question
		ANS=$?

		if [ $ANS -ge $MINDAEMONS -a $ANS -le $MAXDAEMONS ]
		then
			NUMDAEMONS=`expr $ANS - 1`
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_accessmask1()
{
	$CLEAR
	$ECHO "AccessMask(1)                                                   ($PAGE of $TOTALPAGES)"
	$ECHO "============="
	$ECHO "Files may be scanned as they are opened. This is useful for preventing"
	$ECHO "users from accessing concerning files. This includes opening, reading"
	$ECHO "and copying concerning files."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		BITCHECK=$ACCESSMASK
		BIT=1
		bit_value
		YNQDEFAULTTEST="$? -eq 1"

		$ECHO -n "Would you like to scan files as they are opened? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			bit_value
			if [ $? -ne 1 ]
			then
				ACCESSMASK=`expr $ACCESSMASK + 1`
			fi
		elif [ $ANS -eq 2 ]
		then
			bit_value
			if [ $? -eq 1 ]
			then
				ACCESSMASK=`expr $ACCESSMASK - 1`
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_accessmask2()
{
	$CLEAR
	$ECHO "AccessMask(2)                                                   ($PAGE of $TOTALPAGES)"
	$ECHO "============="
	$ECHO "Files may be scanned as they are closed. This is useful for preventing"
	$ECHO "users from creating concerning files. This includes saving, downloading"
	$ECHO "and copying concerning files."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		BITCHECK=$ACCESSMASK
		BIT=2
		bit_value
		YNQDEFAULTTEST="$? -eq 1"

		$ECHO -n "Would you like to scan files as they are closed? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			bit_value
			if [ $? -ne 1 ]
			then
				ACCESSMASK=`expr $ACCESSMASK + 2`
			fi
		elif [ $ANS -eq 2 ]
		then
			bit_value
			if [ $? -eq 1 ]
			then
				ACCESSMASK=`expr $ACCESSMASK - 2`
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_accessmask4()
{
	$CLEAR
	$ECHO "AccessMask(4)                                                   ($PAGE of $TOTALPAGES)"
	$ECHO "============="
	$ECHO "Files may be scanned as they are executed. This is useful for preventing"
	$ECHO "users from running concerning programs."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		BITCHECK=$ACCESSMASK
		BIT=3
		bit_value
		YNQDEFAULTTEST="$? -eq 1"

		$ECHO -n "Would you like to scan files as they are executed? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			bit_value
			if [ $? -ne 1 ]
			then
				ACCESSMASK=`expr $ACCESSMASK + 4`
			fi
		elif [ $ANS -eq 2 ]
		then
			bit_value
			if [ $? -eq 1 ]
			then
				ACCESSMASK=`expr $ACCESSMASK - 4`
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_repairinfected()
{
	$CLEAR
	$ECHO "RepairConcerningFiles"
	$ECHO "====================="
	$ECHO "If a concerning file is found, AiGuard can try to remove the problem. If"
	$ECHO "the problem cannot be removed, access to the file will still be blocked."
	$ECHO "However, if the problem can be removed, the user will be allowed normal"
	$ECHO "access."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		YNQDEFAULTTEST="$REPAIRINFECTED -eq 1"

		$ECHO -n "Would you like to try to repair concerning files? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			REPAIRINFECTED=1
		elif [ $ANS -eq 2 ]
		then
			REPAIRINFECTED=0
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_logonly()
{
	$CLEAR
	$ECHO "LogOnly/Rename/MoveConcerningFilesTo                                   ($PAGE of $TOTALPAGES)"
	$ECHO "===================================="
	if [ $REPAIRINFECTED -eq 0 ]
	then
		$ECHO "When an alert is found, there are several ways in which AiGuard can"
		$ECHO "respond."
	else
		$ECHO "When an alert is found and cannot be removed, there are several ways in"
		$ECHO "which AiGuard can respond."
	fi
	$ECHO " "
	$ECHO "        log only - the name of the concerning file will only"
	$ECHO "                   be logged using syslog"
	$ECHO " "
	$ECHO "        rename   - the concerning file will be renamed to have"
	$ECHO "                   a .XXX extension"
	$ECHO " "
	$ECHO "        move     - the concerning file will be moved to a"
	$ECHO "                   directory of your choice"
	$ECHO " "
	$ECHO "Regardless of which option you choose, the event involving the concerning"
	$ECHO "file will be logged using syslog and access to the file will be blocked."
	$ECHO " "
	$ECHO "available options: l r m"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		QDEFAULT=$HANDLEINFECTED
		QCHOICES="l r m"

		$ECHO -n "How should concerning files be handled? "
		question
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			HANDLEINFECTED="l"
		elif [ $ANS -eq 2 ]
		then
			HANDLEINFECTED="r"
		elif [ $ANS -eq 3 ]
		then
			$ECHO -n "Which directory should they be moved to? [$MOVETODIR] "

			OK=0
			read_directory
			RET=$?

			if [ $RET -eq 0 -a ! -z "$MOVETODIR" ]
			then
				RET=1
				INPUT=$MOVETODIR
			fi

			if [ $RET -eq 1 ]
			then
				HANDLEINFECTED="m"
				MOVETODIR=$INPUT
				OK=1
			fi

			if [ $OK -eq 0 ]
			then
				$ECHO "invalid directory: $INPUT"
				$ECHO "path must be absolute (beginning with '/')"
			fi
		else
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_emailto()
{
	$CLEAR
	$ECHO "EmailTo                                                         ($PAGE of $TOTALPAGES)"
	$ECHO "======="
	$ECHO "You may set AVIRA to send out an email message every time a concerning"
	$ECHO "file is accessed. The message will also list the action that was taken"
	$ECHO "to handle the file."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		test ! -z "$EMAILTO"
		YNQDEFAULTTEST="$? -eq 0"

		$ECHO -n "Would you like email notification of alerts? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO -n "What email address will receive notifications? [$EMAILTO] "
			read INPUT

			if [ ! -z "$INPUT" ]
			then
				EMAILTO="$INPUT"
			fi

			if [ -z "$EMAILTO" ]
			then
				OK=0
			fi
		elif [ $ANS -eq 2 ]
		then
			EMAILTO=""
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_logto()
{
	$CLEAR
	$ECHO "LogTo                                                           ($PAGE of $TOTALPAGES)"
	$ECHO "====="
	$ECHO "In addition to logging concerning activity through syslog, you may"
	$ECHO "als specify your own log file. This can make it simpler to review"
	$ECHO "past concerning activity without having to sift through syslog files."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		if [ ! -z "$LOGTO" ]
		then
			QDEFAULT="y"
		else
			QDEFAULT="n"
		fi

		QCHOICES="y n"

		$ECHO -n "Would you like AVIRA to log to a custom file? "
		question
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO "What will be the log file name with absolute path (it must begin with '/')"
			$ECHO -n "? [$LOGTO] "

			OK=0
			read_directory
			RET=$?

			if [ $RET -eq 0 -a ! -z "$LOGTO" ]
			then
				RET=1
				INPUT=$LOGTO
			fi

			if [ $RET -eq 1 ]
			then
				LOGTO=$INPUT
				OK=1
			fi
		elif [ $ANS -eq 2 ]
		then
			LOGTO=""
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_includepath()
{
	$CLEAR
	$ECHO "IncludePath                                                     ($PAGE of $TOTALPAGES)"
	$ECHO "==========="
	$ECHO "AiGuard gives you the option of specifying the paths from which files"
	$ECHO "will be scanned. All sub-directories of specified paths will also be"
	$ECHO "scanned as files are accessed. You must specify at least one path."
	$ECHO " "
	if [ "$INCLUDEPATH" = ":" ]
	then
		CUT="NONE"
	else
		CUT="`$ECHO $INCLUDEPATH | sed -e s/\^://`"
		CUT="`$ECHO $CUT | sed -e s/:\$//`"
		CUT="`$ECHO $CUT | sed -e s/\\\"//g`"
	fi
	$ECHO "Current include paths = $CUT"
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		if [ "$INCLUDEPATH" = ":" ]
		then
			QDEFAULT="y"
		else
			QDEFAULT="n"
		fi

		QCHOICES="y n"

		$ECHO -n "Would you like to specify new include paths? "
		question
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO " "
			$ECHO "Type in the paths one at time, pressing ENTER after each path. All paths"
			$ECHO "must be absolute (beginning with '/'). When you are finished, simply"
			$ECHO "enter a blank line."
			$ECHO " "
			OK=0
			COUNT=1
			INCLUDEPATH=":"
			while [ $OK -eq 0 ]
			do
				$ECHO -n "[IncludePath $COUNT] "
				read_directory
				RET=$?

				if [ $RET -eq 0 ]
				then
					OK=1
				elif [ $RET -eq 1 ]
				then
					INCLUDEPATH="$INCLUDEPATH$INPUT:"

					COUNT=`expr $COUNT + 1`
				else
					$ECHO "invalid directory: $INPUT"
					$ECHO "path must be absolute (beginning with '/')"
					$ECHO " "
				fi

				if [ "$INCLUDEPATH" = ":" ]
				then
					$ECHO "you must specify at least one include path"
					$ECHO " "
					OK=0
				fi
			done
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_exclude_path()
{
	$CLEAR
	$ECHO "ExcludePath                                                     ($PAGE of $TOTALPAGES)"
	$ECHO "==========="
	$ECHO "Unless under the specified included paths, files will not be scanned."
	$ECHO "You may also want that particular sub-directories within the included"
	$ECHO "paths are also not scanned."
	$ECHO " "
	$ECHO "For example, perhaps you want the entire /home directory scanned except"
	$ECHO "for /home/bill. AiGuard allows you to specify sub-directories of the"
	$ECHO "included paths that will not be scanned. These sub-directories are called"
	$ECHO "exclude paths. In this example /home/bill would be an exclude path."
	if [ ! -z "`$PSAX | grep aigated`" -o ! -z "`$PSAX | grep avira.*[-]-mailgate`" ]
	then
		$ECHO ""
		$ECHO "WARNING: AiMailGate has been detected on this system. Make sure you"
		$ECHO "         add the AiMailGate SpoolDir and TemporaryDir to the AiGuard"
		$ECHO "         ExcludePath or else AiMailGate will not work properly."
	fi
	$ECHO " "
	if [ "$EXCLUDEPATH" = ":" ]
	then
		CUT="NONE"
	else
		CUT="`$ECHO $EXCLUDEPATH | sed -e s/\^://`"
		CUT="`$ECHO $CUT | sed -e s/:\$//`"
		CUT="`$ECHO $CUT | sed -e s/\\\"//g`"
	fi
	$ECHO "Current exclude paths = $CUT"
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		YNQDEFAULTTEST="0 -eq 1"

		$ECHO -n "Would you like to specify new exclude paths? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			OK=0
			COUNT=1
			EXCLUDEPATH=":"
			while [ $OK -eq 0 ]
			do
				$ECHO -n "[ExcludePath $COUNT] "
				read_directory
				RET=$?

				if [ $RET -eq 0 ]
				then
					OK=1
				elif [ $RET -eq 1 ]
				then
					EXCLUDEPATH="$EXCLUDEPATH$INPUT:"

					COUNT=`expr $COUNT + 1`
				else
					$ECHO "invalid directory: $INPUT"
					$ECHO "path must be absolute (beginning with '/')"
					$ECHO " "
				fi
			done
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	PAGE=`expr $PAGE + 1`
}

config_autoupdatetime()
{
	$CLEAR
	$ECHO "AutoUpdateTime                                                ($PAGE-2 of $TOTALPAGES)"
	$ECHO "=============="
	$ECHO "The Automatic Internet Updater can be set to always check for updates"
	$ECHO "at a particular time of day. This is specified in a HH:MM format"
	$ECHO "(where HH is the hour and MM is the minutes). If you do not have a"
	$ECHO "permanent connection, you may set it to a time when you are usually"
	$ECHO "online. You may also let AVIRA choose a random time (r)."
	$ECHO " "
	$ECHO "If you have a permanent connection then a random time may be preferred"
	$ECHO "because it will help to disperse the times when other users are"
	$ECHO "getting updates."
	$ECHO " "
	$ECHO "available options: HH:MM r"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		$ECHO -n "What time should updates be done? "
		if [ -z "$AUTOUPDATETIME" ]
		then
			$ECHO -n "[RANDOM] "
		else
			$ECHO -n "[$AUTOUPDATETIME] "
		fi

		read INPUT

		if [ -z "$INPUT" ]
		then
			OK=1
		else
			HH=""
			MM=""
			OLDIFS=$IFS
			IFS=":"
			for ITEM in $INPUT
			do
				if [ -z "$HH" ]
				then
					HH=$ITEM
				elif [ -z "$MM" ]
				then
					MM=$ITEM
				fi
			done
			IFS=$OLDIFS

			#check if it is a valid time

			if [ ! -z "$HH" -a ! -z "$MM" ]
			then
				if [ -z "`$ECHO $HH | sed -e s/[0-9]//g`" ]
				then
					if [ $HH -ge 0 -a $HH -le 23 ]
					then
						if [ -z "`$ECHO $MM | sed -e s/[0-9]//g`" ]
						then
							if [ $MM -ge 0 -a $MM -le 59 ]
							then
								if [ $HH -lt 10 ]
								then
									HH="`$ECHO $HH | sed -e s/0//g`"
									if [ -z "$HH" ]
									then
										HH="0"
									fi
									HH="0$HH"
								fi

								if [ $MM -lt 10 ]
								then
									MM="`$ECHO $MM | sed -e s/0//g`"
									if [ -z "$MM" ]
									then
										MM="0"
									fi
									MM="0$MM"
								fi

								AUTOUPDATETIME="$HH:$MM"
								OK=1
							fi
						fi
					fi
				fi
			elif [ "$INPUT" = "r" ]
			then
				AUTOUPDATETIME=""
				OK=1
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

config_autoupdatedaily()
{
	$CLEAR
	$ECHO "AutoUpdateEvery2Hours/AutoUpdateDaily                           ($PAGE of $TOTALPAGES)"
	$ECHO "====================================="
	$ECHO "AVIRA is equipped with an Automatic Internet Updater. At specified"
	$ECHO "intervals, AVIRA will connect to an updater server to check for newer"
	$ECHO "versions of the AVIRA engine or the data files. If a newer"
	$ECHO "version is available, AVIRA will automatically download and install"
	$ECHO "the updates without requiring any special attention. This allows AVIRA"
	$ECHO "to be kept current against attacks and problems."
	$ECHO " "
	$ECHO "AVIRA can be configured to check for updates every 2 hours (2) or"
	$ECHO "once a day (d). You can also choose to have the Automatic Internet"
	$ECHO "Updater never check (n)."
	$ECHO " "
	$ECHO "available options: 2 d n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		case "$AUTOUPDATEFREQUENCY" in
			2h)
				QDEFAULT=2
				;;
			1d)
				QDEFAULT=d
				;;
			*)
				QDEFAULT=n
				;;
		esac
		QCHOICES="2 d n"

		$ECHO -n "How often should AVIRA check for updates? "
		question
		ANS=$?

		case "$ANS" in
			1)
				AUTOUPDATEFREQUENCY="2h"
				;;
			2)
				AUTOUPDATEFREQUENCY="1d"
				;;
			3)
				AUTOUPDATEFREQUENCY=""
				;;
			*)
				$ECHO "invalid answer: $INPUT"
				;;
		esac
	done

	if [ "$AUTOUPDATEFREQUENCY" = "1d" ]
	then
		config_autoupdatetime
	fi

	PAGE=`expr $PAGE + 1`
}

config_archivemaxsize()
{
	$CLEAR
	$ECHO "ArchiveMaxSize                                                ($PAGE-2 of $TOTALPAGES)"
	$ECHO "=============="
	$ECHO "In order to scan the contents of compressed files, the files must be"
	$ECHO "decompressed. For very large compressed files it could take a long time"
	$ECHO "to decompress everything. For this reason, you may wish you put a size"
	$ECHO "limit for compressed files that will be scanned. The size limit is given"
	$ECHO "in bytes. For example, 1 gigabyte = 1073741824 bytes. You may set this"
	$ECHO "value to 0 to have no limit on the size of scanned compressed files."
	$ECHO " "
	$ECHO "available options: 0-??"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		$ECHO "What is the maximum size compressed file (in bytes)"
		$ECHO -n "to be scanned? "
	
		if [ $ARCHIVEMAXSIZE -eq 0 ]
		then
			$ECHO -n "[UNLIMITED] "
		else
			$ECHO -n "[$ARCHIVEMAXSIZE] "
		fi

		read INPUT

		if [ -z "$INPUT" ]
		then
			OK=1
		else
			if [ -z "`$ECHO $INPUT | sed -e s/[0-9]//g`" ]
			then
				ARCHIVEMAXSIZE=$INPUT
				OK=1
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

config_archivemaxrecursion()
{
	$CLEAR
	$ECHO "ArchiveMaxRecursion                                           ($PAGE-3 of $TOTALPAGES)"
	$ECHO "==================="
	$ECHO "It is possible that a compressed file has many compressed files as"
	$ECHO "contents. For example, inside of filename.zip there may be a file1.zip"
	$ECHO "file. Each compressed file within a compressed file is referred to as"
	$ECHO "a recursion level. If AiGuard should decompress filename.zip it must scan"
	$ECHO "recursion level 1. If it is supposed to also decompress file1.zip, it"
	$ECHO "must scan recursion level 2."
	$ECHO " "
	$ECHO "Since decompressing takes extra time, you may wish to set a limit on"
	$ECHO "the recursion level that will be scanned. A value of 0 means that there"
	$ECHO "will be no limit."
	$ECHO " "
	$ECHO "available options: 0-??"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "
	
		$ECHO "What is the maximum recursion level in compressed files"
		$ECHO -n "to be scanned? "

		if [ $ARCHIVEMAXRECURSION -eq 0 ]
		then
			$ECHO -n "[UNLIMITED] "
		else
			$ECHO -n "[$ARCHIVEMAXRECURSION] "
		fi

		read INPUT

		if [ -z "$INPUT" ]
		then
			OK=1
		else
			if [ -z "`$ECHO $INPUT | sed -e s/[0-9]//g`" ]
			then
				ARCHIVEMAXRECURSION=$INPUT
				OK=1
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

config_archivemaxratio()
{
	$CLEAR
	$ECHO "ArchiveMaxRatio                                               ($PAGE-4 of $TOTALPAGES)"
	$ECHO "==============="
	$ECHO "Compressed files are usually smaller than the original files. The amount"
	$ECHO "that the files are reduced in size is called the compression ratio. If"
	$ECHO "an archive has a compression ratio of 5, this means that the decompressed"
	$ECHO "contents of the archive take up 5 times the amount of space as the archive."
	$ECHO "It is possible that a compressed file has many compressed files as"
	$ECHO " "
	$ECHO "Sometimes the compression ratio for files can be very large. These types"
	$ECHO "of files can cause an enormous strain on system resources if they are"
	$ECHO "decompressed. For this reason, you may will to set a limit on the"
	$ECHO "compression ratio. A value of 0 means that there will be no limit."
	$ECHO " "
	$ECHO "available options: 0-??"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "
	
		$ECHO "What is the maximum allowed ratio for compressed files"
		$ECHO -n "to be scanned? "

		if [ $ARCHIVEMAXRATIO -eq 0 ]
		then
			$ECHO -n "[UNLIMITED] "
		else
			$ECHO -n "[$ARCHIVEMAXRATIO] "
		fi

		read INPUT

		if [ -z "$INPUT" ]
		then
			OK=1
		else
			if [ -z "`$ECHO $INPUT | sed -e s/[0-9]//g`" ]
			then
				ARCHIVEMAXRATIO=$INPUT
				OK=1
			fi
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

config_archivescan()
{
	$CLEAR
	$ECHO "ArchiveScan                                                   ($PAGE of $TOTALPAGES)"
	$ECHO "==========="
	$ECHO "There may be alerts hiding within compressed files (.zip, .gz, .tar, etc)."
	$ECHO "You may configure AiGuard so that these compressed files are decompressed"
	$ECHO "and searched for concerning files. This will help to ensure that your server"
	$ECHO "is free from unwanted files."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		YNQDEFAULTTEST="$ARCHIVESCAN -eq 1"

		$ECHO -n "Would you like to scan compressed files? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			ARCHIVESCAN=1
		elif [ $ANS -eq 2 ]
		then
			ARCHIVESCAN=0
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	if [ $SERVER -eq 1 -a $ARCHIVESCAN -eq 1 ]
	then
		config_archivemaxsize
		config_archivemaxrecursion
		config_archivemaxratio
	fi

	PAGE=`expr $PAGE + 1`
}

config_proxyusername()
{
	$CLEAR
	$ECHO "HTTPProxyUsername/HTTPProxyPassword                           ($PAGE of $TOTALPAGES)"
	$ECHO "==================================="
	$ECHO "Proxy servers may be configured to require a username and password. If"
	$ECHO "the HTTP proxy server for this machine requires a username and password"
	$ECHO "AVIRA needs to be appropriately configured."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		test ! -z "$PROXYUSERNAME"
		YNQDEFAULTTEST="$? -eq 0"

		$ECHO -n "Does the HTTP proxy server require a username/password? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO -n "What is the HTTP proxy username? [$PROXYUSERNAME] "

			OK=0
			read INPUT

			if [ ! -z "$INPUT" ]
			then
				PROXYUSERNAME="$INPUT"
			fi

			if [ ! -z "$PROXYUSERNAME" ]
			then
				$ECHO -n "What is the HTTP proxy password? [$PROXYPASSWORD] "
				read INPUT

				if [ ! -z "$INPUT" ]
				then
					PROXYPASSWORD="$INPUT"
				fi

				if [ ! -z "$PROXYPASSWORD" ]
				then
					OK=1
				fi
			fi
		elif [ $ANS -eq 2 ]
		then
			PROXYUSERNAME=""
			OK=1
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

config_proxyserver()
{
	$CLEAR
	$ECHO "HTTPProxyServer/HTTPProxyPort                                 ($PAGE of $TOTALPAGES)"
	$ECHO "============================="
	$ECHO "If this machine is sitting behind an HTTP proxy server, you will need to"
	$ECHO "configure AVIRA with the appropriate proxy settings.  Internet access"
	$ECHO "is required in order to make updates."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		test ! -z "$PROXYSERVER"
		YNQDEFAULTTEST="$? -eq 0"

		$ECHO -n "Does this machine use an HTTP proxy server? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO -n "What is the HTTP proxy server name? [$PROXYSERVER] "

			OK=0
			read INPUT

			if [ ! -z "$INPUT" ]
			then
				PROXYSERVER="$INPUT"
			fi

			if [ ! -z "$PROXYSERVER" ]
			then
				$ECHO -n "Which port number does the HTTP proxy server use? [$PROXYPORT] "
				read INPUT

				if [ -z "$INPUT" ]
				then
					INPUT="$PROXYPORT"
				fi

				if [ ! -z "$INPUT" ]
				then
					if [ -z "`$ECHO $INPUT | sed -e s/[0-9]//g`" ]
					then
						PROXYPORT=$INPUT
						OK=1
					fi
				fi
			fi
		elif [ $ANS -eq 2 ]
		then
			PROXYSERVER=""
			OK=1
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	if [ ! -z "$PROXYSERVER" ]
	then
		config_proxyusername
	fi

	PAGE=`expr $PAGE + 1`
}

config_syslogfacility()
{
	$CLEAR
	$ECHO "SyslogFacility/SyslogPriority                                 ($PAGE of $TOTALPAGES)"
	$ECHO "============================="
	$ECHO "Regardless of the other configuration options, AVIRA will always log"
	$ECHO "important information using syslog. Syslog uses two values to classify"
	$ECHO "the information to log: facility and priority. Facility specifies the"
	$ECHO "type of program making the log entry. Priority specifies the importance"
	$ECHO "of the log entry."
	$ECHO " "
	$ECHO "If you are unfamiliar with syslog then you may simply accept the default"
	$ECHO "values. However, it is encouraged that you learn about syslog since it"
	$ECHO "is used by many services to log important events."
	$ECHO " "
	$ECHO "available FACILITIES: authpriv cron daemon kern lpr mail news syslog user uucp"
	$ECHO "                      local0 local1 local2 local3 local4 local5 local6 local7"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		QDEFAULT=$SYSLOGFACILITY
		QCHOICES="authpriv cron daemon kern lpr mail news syslog user uucp local0 local1 local2 local3 local4 local5 local6 local7"

		$ECHO -n "Which syslog FACILITY should AVIRA use? "
		question
		ANS=$?

		if [ $OK -eq 1 ]
		then
			SYSLOGFACILITY="$INPUT"
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done

	$ECHO " "
	$ECHO " "
	$ECHO "available PRIORITIES: emerg alert crit err warning notice info debug"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		QDEFAULT=$SYSLOGPRIORITY
		QCHOICES="emerg alert crit err warning notice info debug"

		$ECHO -n "Which syslog PRIORITY should AVIRA use? "
		question
		ANS=$?

		if [ $OK -eq 1 ]
		then
			SYSLOGPRIORITY="$INPUT"
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

config_results()
{
	$CLEAR
	$ECHO "AVIRA Configuration"
	$ECHO "====================="
	$ECHO "Here are the configuration settings you have specified. Look them over"
	$ECHO "to make sure they are correct."
	$ECHO " "
	WARNING=0
	show_config
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		YNQDEFAULTTEST="$WARNING -eq 0"

		$ECHO -n "Save configuration settings? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO " "

			if [ $CONFIGGUARD -eq 1 ]
			then
				CONF_FILE="/etc/aiguard.conf"
				$ECHO -n "saving configuration to $CONF_FILE ... "
				save_guard_conf
				RET=$?
				sleep 1

				if [ $RET -eq 0 ]
				then
					$ECHO "done"
				else
					$ECHO "FAILED"
					$ECHO " "
					$ECHO "Unable to save configuration file."
					$ECHO "Make sure you are able to write to $CONF_FILE"
					$ECHO "and rerun the configuration utility with"
					$ECHO "$AVDIR/configaiguard"
					$ECHO " "
					exit 1
				fi
			fi

			CONF_FILE="/etc/avira.conf"
			$ECHO -n "saving configuration to $CONF_FILE ... "
			save_avira_conf
			RET=$?
			sleep 1

			if [ $RET -eq 0 ]
			then
				$ECHO "done"
			else
				$ECHO "FAILED"
				$ECHO " "
				$ECHO "Unable to save configuration file."
				$ECHO "Make sure you are able to write to $CONF_FILE"
				$ECHO "and rerun the configuration utility with"
				$ECHO "$AVDIR/configaiguard"
				$ECHO " "
				exit 1
			fi

			MAINLOOP=0
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

run_aiupdater()
{
	$CLEAR
	$ECHO "Running Automatic Internet Updater"
	$ECHO "=================================="
	$ECHO "In order for the Automatic Internet Updater to be active on your"
	$ECHO "system, you must run the software. This can be done manually each"
	$ECHO "time the system is booted with the command:"
	$ECHO " "
	$ECHO "$AVDIR/aiupdater start"
	$ECHO " "
	$ECHO "You can have it start automatically by adding aiupdater to your"
	$ECHO "startup scripts. Depending on your Linux distribution, this"
	$ECHO "can vary. Consult your Linux distribution documentation on startup"
	$ECHO "scripts."
	$ECHO " "
	$ECHO "During the installation, you had the option to set it to"
	$ECHO "start automatically."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		YNQDEFAULTTEST="1 -eq 1"

		MODSTAT="`$PSAX | grep avira.*[-]-updater-daemon`"

		$ECHO -n "Would you like to "
		if [ ! -z "$MODSTAT" ]
		then
			$ECHO -n "re"
		fi
		$ECHO -n "start the updater using the new configuration? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO " "
			if [ ! -z "$MODSTAT" ]
			then
				$AVDIR/aiupdater stop
			fi
			$AVDIR/aiupdater start
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}

run_aiguard()
{
	$CLEAR
	$ECHO "Running AiGuard"
	$ECHO "==============="
	$ECHO "In order for AiGuard to be active on your system, you must run the"
	$ECHO "AiGuard software. This can be done manually each time the system is"
	$ECHO "booted with the command:"
	$ECHO " "
	$ECHO "$AVDIR/aiguard start"
	$ECHO " "
	$ECHO "You can have AiGuard start automatically by adding aiguard to"
	$ECHO "your startup scripts. Depending on your Linux distribution, this"
	$ECHO "can vary. Consult your Linux distribution documentation on startup"
	$ECHO "scripts."
	$ECHO " "
	$ECHO "During the installation, you had the option to set AiGuard to"
	$ECHO "start automatically."
	$ECHO " "
	$ECHO "available options: y n"
	OK=0
	while [ $OK -eq 0 ]
	do
		$ECHO " "

		YNQDEFAULTTEST="1 -eq 1"

		if [ $SERVER -eq 1 ]
		then
			GUARD_TYPE="server"
		else
			GUARD_TYPE="workstation"
		fi
		MODSTAT="`$PSAX | grep avira.*[-]-$GUARD_TYPE`"

		$ECHO -n "Would you like to "
		if [ ! -z "$MODSTAT" ]
		then
			$ECHO -n "re"
		fi
		$ECHO -n "start AiGuard using the new configuration? "
		ynquestion
		ANS=$?

		if [ $ANS -eq 1 ]
		then
			$ECHO " "
			if [ ! -z "$MODSTAT" ]
			then
				$AVDIR/aiguard stop
			fi
			$AVDIR/aiguard start
		fi

		if [ $OK -eq 0 ]
		then
			$ECHO "invalid answer: $INPUT"
		fi
	done
}


# main()

AVDIR="/usr/lib/AVIRA"
MINDAEMONS=0
MAXDAEMONS=20
SERVER=0
HAVECONFIG=0
CHECK=0
MAINLOOP=1
CONFIGGUARD=0
VARIANT="AIEN"
EXELIST="which clear sleep grep date ps"

check_executables

CUT="`$ECHO $0 | sed -e s/configaiguard\$//`"
if [ "$0" != "$CUT" ]
then
	CONFIGGUARD=1
fi

if [ $CONFIGGUARD -eq 1 ]
then
	for ITEM in $@
	do
		case "$ITEM" in
			"--check-conf")
				CHECK=1
				CONF_FILE="/etc/avira.conf"
				read_conf
				CONF_FILE="/etc/aiguard.conf"
				read_conf
				check_config
				if [ -f $AVDIR/aiguard ]
				then
					$ECHO " "
					$AVDIR/aiguard status
				fi
				reminder
				exit 0
				;;
		esac
	done
fi


if [ ! -f /etc/avira.conf -a ! -f "/etc/aiguard.conf" ]
then
	set_recommend
fi
CONF_FILE="/etc/avira.conf"
read_conf
CONF_FILE="/etc/aiguard.conf"
read_conf

TOTALPAGES=4

if [ $CONFIGGUARD -eq 1 ]
then
	TOTALPAGES=`expr $TOTALPAGES + 8`
	if [ $SERVER -eq 1 ]
	then
		TOTALPAGES=`expr $TOTALPAGES + 1`
	fi
fi

if [ -f $AVDIR/aiupdater ]
then
	TOTALPAGES=`expr $TOTALPAGES + 1`
fi

while [ $MAINLOOP -eq 1 ]
do
	PAGE=1

	if [ $CONFIGGUARD -eq 1 ]
	then
		config_numdaemons
		if [ $NUMDAEMONS -gt 0 ]
		then
			config_accessmask1
			config_accessmask2
			config_accessmask4
			config_repairinfected
			config_logonly
			config_includepath
			config_exclude_path

			if [ $SERVER -eq 1 ]
			then
				config_archivescan
			fi
		else
			TOTALPAGES=`expr $TOTALPAGES - 6`

			if [ $SERVER -eq 1 ]
			then
				TOTALPAGES=`expr $TOTALPAGES - 1`
			fi
		fi
	fi

	if [ -f $AVDIR/aiupdater ]
	then
		config_autoupdatedaily
	fi

	config_emailto
	config_logto
	config_proxyserver
	config_syslogfacility

	HAVECONFIG=1

	config_results
done

if [ ! -z "`ls $AVDIR | grep -i \.key`" ]
then
	if [ $CONFIGGUARD -eq 1 ]
	then
		run_aiguard
	fi

	if [ -f $AVDIR/aiupdater ]
	then
		run_aiupdater
	fi
fi

$CLEAR
$ECHO "Configuration Complete"
$ECHO "======================"
$ECHO " "
show_config
$ECHO " "
$ECHO " "
$ECHO -n "Press <ENTER> to continue."
read INPUT
$CLEAR
$ECHO " "

if [ -f $AVDIR/aiguard -a $CONFIGGUARD -eq 1 ]
then
	$AVDIR/aiguard status
fi

if [ -f $AVDIR/aiupdater ]
then
	$AVDIR/aiupdater status
fi

reminder

exit 0
