#!/bin/sh
#
#    Copyright (c) 2003 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   configSslNoti
#
#    Script to trigger HTTPD notifier when SSL setting
#	 is changed
#
export PATH=/bin:/fabos/libexec

ECHO="/bin/echo"
GREP="/bin/grep"
WEBDRESTART=/fabos/libexec/webdcfghandler
SECCERT_NOTIFY=/fabos/libexec/seccert_notify
SSL_CERT_CONF_KEY="ssl.certfile"
SSL_ROOTCERT_CONF_KEY="ssl.root.certfile"
SSL_CERT_NONE="ssl.certfile:none"
SSL_ROOTCERT_NONE="ssl.root.certfile:none"

findkey()
{
	certOprn="ADD"
	$ECHO $key | $GREP $SSL_CERT_CONF_KEY > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		certpkey="BRCD_HTTPS_SW"
		if [ "$key" == $SSL_CERT_NONE ]; then
			certOprn="DELETE"
		fi
		return 0
	else
		$ECHO $key | $GREP $SSL_ROOTCERT_CONF_KEY > /dev/null 2>&1
		if [ $? -eq 0 ]; then
			certpkey="BRCD_HTTPS_CA"
	        if [ "$key" == $SSL_ROOTCERT_NONE ]; then
    	        certOprn="DELETE"
	        fi
			return 0
		else
			return 1
		fi
	fi
}


# Make sure there's exactly 1 argument
if ! [ $# -eq 1 ]; then
#	echo Invalid number of arguments: $#
	exit
fi

$WEBDRESTART $1

#Notify Maps on the certificate being configured
key="$1"
certpkey=""
findkey

if [ $? -eq 0 ]; then
	$SECCERT_NOTIFY "notify" "$certOprn" "$certpkey"
fi
