#!/bin/sh

dump()
{
	echo "[$DUMP_HEADER]" >> $DUMP_FILE
	echo $ECHO_E "$DUMP_BODY" >> $DUMP_FILE
}

sys_info()
{
	# linux distro
	if [ $OS = "Linux" ]
	then
		DUMP_HEADER="Linux Distribution"
		for file in $(ls /etc/*{-,_}{release,version} 2>/dev/null) # this one is for bash  only
		do
			DUMP_BODY=$DUMP_BODY$file"\n"$(cat $file 2>&1)"\n"
		done
		DUMP_BODY=$(echo "$DUMP_BODY" | sed '/^$/d'  2>&1)
		dump
	fi

	# kernel
	DUMP_HEADER="Kernel :: uname -a"
	DUMP_BODY=$(uname -a 2>&1)
	dump

	# gcc
	DUMP_HEADER="Gcc :: gcc -v"
	DUMP_BODY=$(gcc -v 2>&1)
	dump

	# glibc
	if [ $OS = "Linux" ]
	then
		DUMP_HEADER="Gnu C Library :: libc.so.6"
		DUMP_BODY=""
		[ -x /lib/libc.so.6 ] && \
			DUMP_BODY=$(/lib/libc.so.6 | grep "release version" 2>&1)
		[ -x /lib/x86_64-linux-gnu/libc.so.6 ] && \
			DUMP_BODY=$(/lib/x86_64-linux-gnu/libc.so.6 | grep "release version" 2>&1)
		dump
	fi

	# ld
	DUMP_HEADER="Gnu Linker :: ld -v"
	DUMP_BODY=$(ld -v 2>&1)
	dump

	# installed packages
	DUMP_HEADER="Installed packages ::"
	DUMP_BODY=
	for CMD in 'rpm -qa' 'dpkg --list' 'erm -qa' 'pkg_info' 'ls -1 /var/log/packages/' 'ls /var/db/pkg/*/* | grep -v ":"'
	do
		which `echo $CMD | awk '{print $1}'` >/dev/null 2>&1
		if [ $? = 0 ]
		then
			TMP=$($CMD 2>/dev/null)
			if [ $? -eq 0 ] && [ -n "$TMP" ]
			then
				DUMP_HEADER=$DUMP_HEADER" "$CMD
				DUMP_BODY=$DUMP_BODY$(echo "$TMP" | sort 2>&1)
			fi
		fi
	done
	echo "[$DUMP_HEADER]" >> packages
	echo $ECHO_E "$DUMP_BODY" >> packages

	# cpuinfo
	if [ $OS = "Linux" ]
	then
		# CPU
		DUMP_HEADER="Cpu :: /proc/cpuinfo"
		DUMP_BODY=$(cat /proc/cpuinfo 2>&1)
		dump

		# mem
		DUMP_HEADER="Memory :: /proc/meminfo"
		DUMP_BODY=$(cat /proc/meminfo 2>&1)
		dump
	fi

	# sysctl
	if [ $OS = "FreeBSD" ]
	then
		# sysctl stuff
		DUMP_HEADER="Kernel details :: sysctl"
		DUMP_BODY=$(sysctl hw.machine hw.model hw.physmem hw.usermem kern.maxproc kern.maxfiles kern.maxfilesperproc kern.maxprocperuid kern.openfiles vm.vmtotal hw.clockrate 2>&1)
		dump
	fi

	# dmesg
	DUMP_HEADER="Bootup Messages :: dmesg"
	DUMP_BODY=$(dmesg 2>&1)
	dump

	# mount
	DUMP_HEADER="Mounted FileSystems :: mount"
	DUMP_BODY=$(mount 2>&1)
	dump

	# disk space
	DUMP_HEADER="Disk Space Usage :: df -h"
	DUMP_BODY=$(df -h 2>&1)
	dump

	# disk indodes
	DUMP_HEADER="Disk Inodes Usage :: df -i"
	DUMP_BODY=$(df -i 2>&1)
	dump

	# env
	DUMP_HEADER="Environment :: env"
	DUMP_BODY=$(env 2>&1)
	dump

	# date
	DUMP_HEADER="System Date :: date"
	DUMP_BODY=$(date 2>&1)" - "$(date +%s 2>&1)
	dump

	# ps
	DUMP_HEADER="Running Processes :: "
	DUMP_BODY=$(ps auxHww 2>&1)
	if [ $? = 1 ]
	then
		DUMP_BODY=$(ps axHww 2>&1)
		if [ $? = 1 ]
		then
			DUMP_BODY=$(ps auxww 2>&1)
			DUMP_HEADER=$DUMP_HEADER"ps auxww"
		else
			DUMP_HEADER=$DUMP_HEADER"ps axHww"
		fi
		else
		DUMP_HEADER=$DUMP_HEADER"ps auxHww"
	fi
	dump

	# netstat
	DUMP_HEADER="Network Connections :: "
	DUMP_BODY=$(netstat -anpe 2>&1)
	if [ $? = 1 ]
	then
		# FreeBSD
		DUMP_BODY=$(netstat -an 2>&1)
		DUMP_HEADER=$DUMP_HEADER"netstat -an"
	else
		DUMP_HEADER=$DUMP_HEADER"netstat -anpe"
	fi
	dump
}

bd_srv_info()
{
	# bd info
	DUMP_HEADER="BD Info"
	DUMP_BODY=$($BD_PATH/bin/bd info 2>&1)
	dump

	# bd status
	DUMP_HEADER="BD Status"
	DUMP_BODY=$($BD_PATH/bin/bd status 2>&1)
	dump

	# bd stats
	DUMP_HEADER="BD Stats"
	DUMP_BODY=$($BD_PATH/bin/bd stats 2>&1)
	dump

	# changed WL/BL locations to reflect current versions (2.x)
	# antispam wl
	if [ -f $BD_PATH/etc/as_wlist ]; then
		DUMP_HEADER="Antispam WL :: as_wlist"
		DUMP_BODY=$(cat $BD_PATH/etc/as_wlist 2>&1)
		dump
	fi

	if [ -f $BD_PATH/etc/as_Default_whitelist ]; then
		DUMP_HEADER="Antispam WL :: as_Default_whitelist"
		DUMP_BODY=$(cat $BD_PATH/etc/as_Default_whitelist 2>&1)
		dump
	fi

	# antispam bl
	if [ -f $BD_PATH/etc/as_blist ]; then
		DUMP_HEADER="Antispam BL :: as_blist"
		DUMP_BODY=$(cat $BD_PATH/etc/as_blist 2>&1)
		dump
	fi

	if [ -f $BD_PATH/etc/as_Default_blacklist ]; then
		DUMP_HEADER="Antispam BL :: as_Default_blacklist"
		DUMP_BODY=$(cat $BD_PATH/etc/as_Default_blacklist 2>&1)
		dump
	fi

	DUMP_HEADER="BD Content Filter :: $BD_HOME/etc/cf"
	DUMP_BODY=$(for f in $BD_PATH/etc/cf/*; do echo "** $f"; cat $f; done)
	dump

	# ls -alR
	DUMP_HEADER="BD_PATH File List :: ls -alR BD_PATH"
	DUMP_BODY=$(ls -alR $BD_PATH 2>&1)
	dump

	# ls -al /etc/BitDefender
	if [ $OS = "Linux" ]
	then
		DUMP_HEADER="BD_ETC Directory :: ls -al BD_ETC"
		DUMP_BODY=$(ls -al /etc/BitDefender 2>&1)
		dump
	fi

	# /var/run/BitDefender
	DUMP_HEADER="BD_VAR_RUN File List :: ls -al BD_VAR_RUN"
	DUMP_BODY=$(ls -al /var/run/BitDefender 2>&1)
	dump

	# /var/tmp
	DUMP_HEADER="BD_VAR_TMP File List :: ls -al BD_VAR_TMP"
	DUMP_BODY=$(ls -al /var/tmp 2>&1)
	dump

	# id
	DUMP_HEADER="BD User :: id BD_USER"
	BD_USER="bitdefender"
	DUMP_BODY=$(id $BD_USER 2>&1)
	dump

	# lsof
	if [ $OS = "Linux" ]
	then
		LSOF_BIN=$(which lsof 2>/dev/null)
		if [ "x$LSOF_BIN" = "x" ] || [ ! -x "$LSOF_BIN" ]
		then
			DUMP_HEADER="BD Opened Files :: ls -l /proc/<pid>/fd"
			DUMP_BODY=""
			for d in bdregd bdmond bdlogd bdlived bdscand bdsnmpd bdmaild bdmilterd bdcgated bdcourier bdqmail bdradmind
			do
				P=$(pgrep $d)
				[ "x$P" = "x" ] || \
					DUMP_BODY="$DUMP_BODY"$(echo "** $d"; ls -l /proc/$P/fd 2>&1; echo " ")
			done
		else
			DUMP_HEADER="BD Opened Files :: lsof -u $BD_USER"
			DUMP_BODY=$(lsof -u $BD_USER 2>&1)
		fi
		dump
	fi
}

milter_info()
{
	# product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender for Sendmail Milter -> $BD_PATH"
	dump

	# sendmail.cf
	DUMP_HEADER="Sendmail Configuration :: sendmail.cf"
	DUMP_BODY=$(cat $CONF_PATH/sendmail.cf 2>&1)
	dump

	# sendmail info
	DUMP_HEADER="Sendmail Details :: sendmail -d0.1"
	DUMP_BODY=$(sendmail -d0.1 </dev/null 2>&1)
	dump
}

postfix_info()
{
	# product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender for Postfix -> $BD_PATH"
	dump

	# main.cf
	DUMP_HEADER="Postfix Configuration :: main.cf"
	DUMP_BODY=$(cat $CONF_PATH/main.cf 2>&1)
	dump

	# master.cf
	DUMP_HEADER="Postfix Configuration :: master.cf"
	DUMP_BODY=$(cat $CONF_PATH/master.cf 2>&1)
	dump
}

qmail_info()
{
	# product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender for Qmail -> $BD_PATH"
	dump

	# ls -al qmail/bin/
	DUMP_HEADER="QM_BIN_PATH File List :: ls -al QM_BIN_PATH"
	QM_BIN_PATH=$(dirname `grep -A 1 "QmailQueuePath" /opt/BitDefender/etc/bdsettings.xml | grep -v "QmailQueuePath" | sed 's/<keydata>//' | sed \
's/<\/keydata>//' 2>&1`)
	DUMP_BODY=$(ls -al  $QM_BIN_PATH/ 2>&1)
	dump

	# softlimit
	DUMP_HEADER="Qmail Softlimit -> $BD_PATH"
	DUMP_BODY=""
	i=0
	QM_PATH=$(dirname $QM_BIN_PATH 2>&1)
	for file in `find $QM_PATH /service -type f 2>&1`
	do
		if [ "$(grep softlimit $file 2>/dev/null)" ]
		then
			i=$(expr $i + 1)
			DUMP_BODY=$DUMP_BODY"File $i : $file\n  $(grep softlimit $file 2>&1)\n"
		fi
	done
	dump
}

smtp_info()
{
	#product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender SMTP Proxy -> $BD_PATH"
	dump
}

# get courier information
courier_info()
{
	# product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender for Courier -> $BD_PATH"
	dump

	# ls -al bdsubmint
	DUMP_HEADER="CR_BIN_PATH File List ls -al CR_BIN_PATH"
	CR_BIN_PATH=$(dirname `grep -A 1 "SubmitPath" /opt/BitDefender/etc/bdsettings.xml | grep -v "SubmitPath" | sed \
's/<keydata>//' | sed 's/<\/keydata>//' 2>&1` 2>/dev/null)
	DUMP_BODY=$(ls -al  $CR_BIN_PATH 2>&1)
	dump
}

cgate_info()
{
	# product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender for Communigate -> $BD_PATH"
	dump

	# Main.settings
	DUMP_HEADER="Communigate Configuration :: Main.settings"
	DUMP_BODY=$(cat $CONF_PATH/Main.settings 2>&1)
	dump

	# Rules.settings
	DUMP_HEADER="Communigate Configuration :: Rules.settings"
	DUMP_BODY=$(cat $CONF_PATH/Rules.settings 2>&1)
	dump
}

axigen_info()
{
	# product
	DUMP_HEADER="BD Product"
	DUMP_BODY="BitDefender for Axigen -> $BD_PATH"
	dump

	# axigen.cfg
	DUMP_HEADER="Axigen Configuration :: axigen.cfg"
	DUMP_BODY=$(cat $CONF_PATH/run/axigen.cfg)
	dump

	# smtpFilters.script
	DUMP_HEADER="Axigen Configuration :: smtpFilters.script"
	DUMP_BODY=$(cat $CONF_PATH/filters/smtpFilters.script)
	dump
}

get_os()
{
	echo_style
	OS=`uname 2>&1`
	if [ $(echo $OS | grep -i linux) ]
	then
		OS="Linux"
	elif [ $(echo $OS | grep -i freebsd) ]
	then
		OS="FreeBSD"
	else
		echo
		echo
		echo "${CC_BOLD}Please select the Operating System you are using${CC_RST}"
		echo
		echo "${CC_BOLD}[${CC_RST}1${CC_BOLD}]${CC_RST} Linux "
		echo "${CC_BOLD}[${CC_RST}2${CC_BOLD}]${CC_RST} FreeBSD "
		echo
		echo $ECHO_N "The Operating System you are using ${CC_BOLD}(${CC_RST}1/2${CC_BOLD})${CC_RST} : $ECHO_C "
		read OS

		# make sure we've got a numerical value here
		OS=$(echo $OS | awk '{ret+=$1; print ret}' 2>&1)

		while [ $OS -lt 1 ] || [ $OS -gt 2 ]
		do
			echo
			echo "The only possible selections are : ${CC_BOLD}1, 2${CC_RST} "
			echo $ECHO_N "The Operating Systems product that you are using ${CC_BOLD}(${CC_RST}1/2${CC_BOLD})${CC_RST} : $ECHO_C"
			read OS

			# make sure we've got a numerical value here
			OS=$(echo $OS | awk '{ret+=$1; print ret}' 2>&1)
		done

		case $OS in
			1)
				OS="Linux"
			;;
			2)
				OS="FreeBSD"
			;;
		esac
		return 1
	fi
	return 0
}

get_bd_path()
{
	echo_style
	if [ -d /usr/local/bitdefender ];
	then
		BD_PATH=/usr/local/bitdefender
	else
		if [ -L /etc/BitDefender ];
		then
			BD_PATH=$(readlink /etc/BitDefender 2>/dev/null)
			if [ "$?" -ne 0 ]; then
				BD_PATH=`ls -l "/etc/BitDefender" | sed -re 's/.* ->.(.*)/\1/'`
			fi
			BD_PATH=${BD_PATH%\/}
			BD_PATH=${BD_PATH%\/etc}
		fi
	fi

	if [ "$BD_PATH" = '' ];
	then
		if [ -e /etc/init.d/bd ]
		then
			BD_PATH=$(stat /etc/init.d/bd | head -1 | awk -F "\`" '{print $3}' | awk -F "bin/bd" '{print $1}')
		elif [ -e /etc/rc.d/rc.bd ]
		then
			BD_PATH=$(stat /etc/rc.d/rc.bd | head -1 | awk -F "\`" '{print $3}' | awk -F "bin/bd" '{print $1}')
		fi
	fi

	if [ "$BD_PATH" = '' ];
	then
		if [ $OS = "Linux" ]
		then
			BD_PATH_DEF="/opt/BitDefender/"
		elif [ $OS = "FreeBSD" ]
		then
			BD_PATH_DEF="/usr/local/bitdefender/"
		fi

		echo
		echo
		echo "${CC_BOLD}Please enter the BitDefender installation directory${CC_RST}"
		echo

		while [ 1 ];
		do
			echo $ECHO_N "The BitDefender installation directory ${CC_BOLD}[${CC_RST}${BD_PATH_DEF}${CC_BOLD}]${CC_RST} : $ECHO_C"
			read BD_PATH
			if [ -d "$BD_PATH" ] ;
			then
				break
			elif [ "$BD_PATH" = ''  ] && [ -d $BD_PATH_DEF ];
			then
				BD_PATH=$BD_PATH_DEF
				break
			fi
		done
		return 1
	fi
	return 0
}

get_bd_prod()
{
	echo_style

	FUSER=$(fuser -v -n tcp 25 2>&1|awk '/25/ {print $5}')

	if [ -n "$FUSER" ]
	then
		case $FUSER in
			sendmail)
				BD_PROD=1
			;;
			master)
				BD_PROD=2
			;;
			tcpserver)
				BD_PROD=3
			;;
			bdsmtpd)
				BD_PROD=4
			;;
			couriertcpd)
				BD_PROD=5
			;;
			CGServer)
				BD_PROD=6
			;;
			axigen)
				BD_PROD=7
			;;
		esac
	else
		echo
		echo
		echo "${CC_BOLD}Please select the BitDefender for Linux product that you are using${CC_RST} "
		echo
		echo "${CC_BOLD}[${CC_RST}1${CC_BOLD}]${CC_RST} BitDefender for Sendmail Milter"
		echo "${CC_BOLD}[${CC_RST}2${CC_BOLD}]${CC_RST} BitDefender for Postfix"
		echo "${CC_BOLD}[${CC_RST}3${CC_BOLD}]${CC_RST} BitDefender for Qmail"
		echo "${CC_BOLD}[${CC_RST}4${CC_BOLD}]${CC_RST} BitDefender SMTP Proxy"
		echo "${CC_BOLD}[${CC_RST}5${CC_BOLD}]${CC_RST} BitDefender for Courier"
		echo "${CC_BOLD}[${CC_RST}6${CC_BOLD}]${CC_RST} BitDefender for Communigate"
		echo "${CC_BOLD}[${CC_RST}7${CC_BOLD}]${CC_RST} BitDefender for Axigen"
		echo "${CC_BOLD}[${CC_RST}8${CC_BOLD}]${CC_RST} BitDefender for Samba"
		echo "${CC_BOLD}[${CC_RST}18/28/38/48/58/68/78(the first digit corresponds to one of the above options)${CC_BOLD}]${CC_RST} BitDefender for Mail and BitDefender for Samba"

		echo
		echo $ECHO_N "The BitDefender product that you are using ${CC_BOLD}(${CC_RST}1/2/3/4/5/6/7/8/18/28/38/48/58/68/78${CC_BOLD})${CC_RST} : $ECHO_C "
		read BD_PROD

		return 1
	fi
	return 0
}

check_for_zero_size_variable()
{
	echo_style
	if [ -z $BD_PROD ]
	then
		echo
		echo $ECHO_N "Please enter your choice here: "
		read BD_PROD
		return 1
	fi
	return 0
}

os_differentiated_stream_editor()
{
	if [ $OS = "Linux" ]; then
		SED='sed -n /^[0-7]\?[8]\?$/p'
	elif [ $OS = "FreeBSD" ];then
		SED='sed -E -n /^[0-7]?[8]?$/p'
	else
		SED='sed -n /^[0-7]\?[8]\?$/p'
	fi
}

check_for_correct_product_number()
{
	echo_style
	BD_PROD=$(echo $BD_PROD | $SED)

	if [ -z "$BD_PROD" ]
	then
		echo
		echo "The only possible selections are : ${CC_BOLD}1, 2, 3, 4, 5, 6, 7, 8, 18, 28, 38, 48, 58, 68, 78${CC_RST} "
		echo $ECHO_N "The BitDefender product that you are using ${CC_BOLD}(${CC_RST}1/2/3/4/5/6/7/8/18/28/38/48/58/68/78${CC_BOLD})${CC_RST} : $ECHO_C"
		read BD_PROD
		return 1
	fi
	return 0
}

get_conf()
{
	echo_style
	CONF_PATH=''
	case $1 in
		'Sendmail' )
			if [ -e /etc/mail/sendmail.cf ]
			then
				CONF_PATH=/etc/mail/
			elif [ -e /etc/sendmail.cf ]
			then
				CONF_PATH=/etc/
			fi
		;;
		'Postfix')
			if [ -e /etc/postfix/main.cf ] && [ -e /etc/postfix/master.cf ]
			then
				CONF_PATH=/etc/postfix
			fi
		;;
		'Communigate')
			if [ -e /var/CommuniGate/Settings/Main.settings ] && [ -e /var/CommuniGate/Settings/Rules.settings ]
			then
				CONF_PATH=/var/CommuniGate/Settings/
			fi
		;;
		'Axigen')
			if [ -e /var/opt/axigen/run/axigen.cfg ]
			then
				CONF_PATH=/var/opt/axigen/
			elif [ -e /var/axigen/run/axigen.cfg ]
			then
				CONF_PATH=/var/axigen/
			fi
		;;
	esac
	if [ "$CONF_PATH" = '' ]
	then
		echo
		echo
		echo "${CC_BOLD}Please enter the directory containing $1's configuration files${CC_RST}"
		echo
		while [ "$CONF_PATH" = '' ]
		do
			echo $ECHO_N "The directory with $1's configuration files : $ECHO_C"
			read CONF_PATH
			if [ -e "$CONF_PATH" ]
			then
				break
			else
				CONF_PATH=''
			fi
		done
		return 1
	fi
	return 0
}

rot_progr_start()
{
	while [ 1 ]
	do
		for i in  '|' '/' '-' '\'
		do
			# if the parent dies we also ...
			STAT=$(ps -p $$ -o ppid | wc -l)
			if [ $STAT = 2 ]
			then
				printf "\010$i"
				sleep 1
			else
				return
			fi
		done
	done
}

rot_progr_stop()
{
	exec 3>&1
	exec 4>&2
	exec 1>/dev/null
	exec 2>/dev/null
	kill $!
	wait $!
	exec 1>&3
	exec 2>&4
	printf "\010$1"
}

#
# MAIN
#

clear

# test color change style
if [ -t 1 ];
then
	CC_BOLD="[1m"
	CC_RST="[0m"
fi

# test echo style

echo_style()
{
	case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
		*c*,-n*) ECHO_N= ECHO_C='' ;;
		*c*,*  ) ECHO_N=-n ECHO_C= ;;
		*)       ECHO_N= ECHO_C='\c' ;;
	esac

	case `echo -e` in
		-e*) ECHO_E='' ;;
		*) ECHO_E='-e' ;;
	esac
}

echo_style

DUMP_FILE=$(mktemp bdsysinfo.XXXXXX)
if [ $? -ne 0 ]
then
	echo
	echo
	echo "${CC_BOLD}Can not create temporary file. Exiting ... ${CC_RST}"
	echo
	echo
	exit 1
fi

# always get system info
echo
echo
echo $ECHO_N "${CC_BOLD} >> Gathering general system information ... ${CC_RST} $ECHO_C"

# determine the OS
get_os
if [ $? = 1 ]
then
	echo
	echo $ECHO_N "${CC_BOLD} >> Gathering general system information ... ${CC_RST} $ECHO_C"
fi

rot_progr_start &

# get OS common information
sys_info
rot_progr_stop "done"

echo
echo
echo
echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"

# bd installation details
get_bd_path
if [ $? = 1 ]
then
	echo
	echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
fi

get_bd_prod
if [ $? = 1 ]
then
	echo
	while [ 1 ]
	do check_for_zero_size_variable
		if [ $? = 1 ]
		then
			continue
		fi
		os_differentiated_stream_editor
		check_for_correct_product_number
		if [ $? = 0 ]
		then
			break
		fi
	done
	echo
	echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
fi

rot_progr_start &

bd_srv_info

# product specific info
case $BD_PROD in
	1)
		rot_progr_stop " "
		get_conf 'Sendmail'
		if [ $? = 1 ]
		then
			echo
			echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
		fi
		rot_progr_start &
		milter_info
		rot_progr_stop "done"
	;;
	2)
		rot_progr_stop " "
		get_conf 'Postfix'
		if [ $? = 1 ]
		then
			echo
			echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
		fi
		rot_progr_start &
		postfix_info
		rot_progr_stop "done"
	;;
	3)
		qmail_info
		rot_progr_stop "done"
	;;
	4)
		smtp_info
		rot_progr_stop "done"
	;;
	5)
		courier_info
		rot_progr_stop "done"
	;;
	6)
		rot_progr_stop " "
		get_conf 'Communigate'
		if [ $? = 1 ]
		then
			echo
			echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
		fi
		rot_progr_start &
		cgate_info
		rot_progr_stop "done"
	;;
	7)
		rot_progr_stop " "
		get_conf 'Axigen'
		if [ $? = 1 ]
		then
			echo
			echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
		fi
		rot_progr_start &
		axigen_info
		rot_progr_stop "done"
	;;
	8)
		rot_progr_stop " "
		get_conf 'Samba'
		if [ $? = 1 ]
		then
			echo
			echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
		fi
		rot_progr_start &
		rot_progr_stop "done"
	;;
	18|28|38|48|58|68|78)
		rot_progr_stop " "
		get_conf 'Samba'
		if [ $? = 1 ]
		then
			echo
			echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
		fi
		rot_progr_start &
		BD_MAIL_PROD=$(echo $BD_PROD|sed -e 's/.$//')
		case $BD_MAIL_PROD in
			1)
				rot_progr_stop " "
				get_conf 'Sendmail'
				if [ $? = 1 ]
				then
					echo
					echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
				fi
				rot_progr_start &
				milter_info
				rot_progr_stop "done"
			;;
			2)
				rot_progr_stop " "
				get_conf 'Postfix'
				if [ $? = 1 ]
				then
					echo
					echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
				fi
				rot_progr_start &
				postfix_info
				rot_progr_stop "done"
			;;
			3)
				qmail_info
				rot_progr_stop "done"
			;;
			4)
				smtp_info
				rot_progr_stop "done"
			;;
			5)
				courier_info
				rot_progr_stop "done"
			;;
			6)
				rot_progr_stop " "
				get_conf 'Communigate'
				if [ $? = 1 ]
				then
					echo
					echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
				fi
				rot_progr_start &
				cgate_info
				rot_progr_stop "done"
			;;
			7)
				rot_progr_stop " "
				get_conf 'Axigen'
				if [ $? = 1 ]
				then
					echo
					echo $ECHO_N "${CC_BOLD} >> Gathering Bitdefender specific information ... ${CC_RST} $ECHO_C"
				fi
				rot_progr_start &
				axigen_info
				rot_progr_stop "done"
			;;
		esac
	;;
esac

# zip it!

echo
echo
echo
echo $ECHO_N "${CC_BOLD} >> Generating report file 'bdsysinfo.tar.gz' ...  ${CC_RST}" $ECHO_C

rot_progr_start &

# the list of packages and the bdsettings files
# are now standalone for better readability
# also added some logs
mkdir logs
cp -p $BD_PATH/etc/bdsettings.xml bdsettings_.xml
cp -rf $BD_PATH/var/log/* logs/ || true
if [ -e $BD_PATH/etc/cf/Default-cf.conf ]
then
	cp -p /$BD_PATH/etc/cf/Default-cf.conf Default-cf_.conf
fi

if [ -e /var/log/maillog ]
then
	cp -p /var/log/maillog logs/system_mail.log
elif [ -e /var/log/mail ]
then
	cp -p /var/log/mail logs/system_mail.log
elif [ -e /var/log/mail.log ]
then
	cp -p /var/log/mail.log logs/system_mail.log
fi

$(tar -czf bdsysinfo.tar.gz $DUMP_FILE bdradmind_.conf bdsettings_.xml packages Default-cf_.conf logs/* >/dev/null 2>&1)
rm -rf logs
rm -f packages
rm -f bdsettings_.xml
rm -f bdradmind_.conf
rm -f Default-cf_.conf
rot_progr_stop "done"

if [ $? -ne 0 ];
then
	echo
	echo
	echo "${CC_BOLD}An error occurred during archiving gathered information. Exiting ... ${CC_RST}"
	echo
	echo
	exit 1
fi

echo
echo
echo
echo "${CC_BOLD} >> Finished ${CC_RST}"
echo
echo

rm -f $DUMP_FILE

exit 0
