#!/bin/bash
# 
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
# 
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 ("License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.zimbra.com/license
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is: Zimbra Collaboration Suite Server.
# 
# The Initial Developer of the Original Code is Zimbra, Inc.
# Portions created by Zimbra are Copyright (C) 2005, 2006 Zimbra, Inc.
# All Rights Reserved.
# 
# Contributor(s):
# 
# ***** END LICENSE BLOCK *****
# 

# snmp_notify 1|0
# snmp_trap_host <hostname|ip>
# smtp_notify 1|0
# smtp_source <email address>
# smtp_destination <email address>

source "/opt/zimbra/bin/zmshutil" || exit 1
zmsetvars \
	zimbra_server_hostname \
	snmp_notify \
	smtp_notify 

if [ ${snmp_notify} = "1" ]; then
	zmsetvars \
		snmp_trap_host 
	SOURCEFILE=/opt/zimbra/snmp/share/snmp/snmpd.conf.in
	FILE=/opt/zimbra/conf/snmpd.conf
	echo creating $FILE
	cat ${SOURCEFILE} | sed -e "s/@@SNMPHOST@@/${snmp_trap_host}/g" > ${FILE}
fi

# Many backslashes to make sure '@' gets quoted in final perl

if [ ${smtp_notify} = "1" ]; then
	zmsetvars \
		smtp_source \
		smtp_destination

	smtp_source=`echo ${smtp_source} | sed -e 's/@/\\\\\\\@/'`

	smtp_destination=`echo ${smtp_destination} | sed -e 's/@/\\\\\\\@/'`
fi

SWFILE=/opt/zimbra/conf/swatchrc

echo creating $SWFILE
cat ${SWFILE}.in | \
	sed -e "s/@@DOSNMPNOTIFICATIONS@@/${snmp_notify}/g" \
	-e "s/@@DOSMTPNOTIFICATIONS@@/${smtp_notify}/g" \
	-e "s/@@ADMINEMAIL@@/${smtp_source}/g" \
	-e "s/@@PHCEMAIL@@/${smtp_destination}/g" \
	-e "s/@@HOSTNAME@@/${zimbra_server_hostname}/g" \
	> ${SWFILE}
