#!/bin/bash

. ${TOOLKIT}-functions.sh

module="roundcubemail"

version=$(jtconf $module.version) || exit_missing_define "$module.version"

# select proper install files
#
case $version in
 1.2*)	search_path_append "$MODRUNDIR/1.2" ;;
 1.6*)	search_path_append "$MODRUNDIR/1.6" ;;
esac

# session crypt keu: if not already defined
#
# generates 24chars key on the fly and and saves it into $CONFDIR
# to avoid changes each kusa-reconf lauch
#
des_key=$(jtconf $module.des_key 2>/dev/null) || :
deskeyfile="$CONFDIR/files/$module-des-key"

[ "X$des_key" = "X" ] && {
	putwarning "$module session crypt key" \
		"not defined ($module.des_key), generating random 24" \
		"chars key, and saving into $instdir/des-key"
	des_key=$(dd if=/dev/urandom bs=1 count=100 2>/dev/null \
		| uuencode -m - | sed -n -e '2p' | \
		awk '{ print substr($1,0,24) }')
	
	echo "# autocreated on $(date)"		>$deskeyfile
	echo "[$module]"			>>$deskeyfile
	echo "  des_key		$des_key"	>>$deskeyfile
}


# allowed ips
#
file=`filepath ku-$module.conf` || exit 1
allowed=`jtconf $module.allow` || exit_missing_define "$module.allow"

(
	echo "[temp]"
	echo "  allow	^^BLOCK^^"
	case $allowed in
	  [Aa][Ll][Ll]*) ;;
	  *) echo "		$(apache2_add_deny All)"
	esac
	for ip in $allowed
	do
		echo "		$(apache2_add_allow $ip)"
	done
	echo "^^BLOCK^^"
	echo
) >>$MODLOCALDB

exit 0
