#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/Attic/get_extra_rules,v 1.2 2004/02/02 14:19:14 bwhittak Exp $
#
# (C) Copyright Networks Associates Techonolgy Inc. 2003
#
# Called by the UI to add an extra.rule file obtained from user.
#
if [ -f $NETAWSS/.profile.vars ]; then
    . $NETAWSS/.profile.vars
else
    . /var/NAIENV/.profile.vars
fi
[[ "$PATH" == "$wsPATH":* || -z "$wsPATH" ]] || PATH=$wsPATH:$PATH

shopt -s extglob
shopt -s nullglob
. spam-functions

#Example output format
#echo "<ExtraRuleList>"
#echo "    <Rule name='EXTRA_RULE_1' installed='1723475464' signed='yes'/>"
#echo "    <Rule name='EXTRA_RULE_2' installed='1683626271' signed='no'/>"
#echo "</ExtraRuleList>"
#
# Where the installed attribute contains the ctime value for the extra rules install date
#
#or
#echo "<Error>Error text</Error>"

echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
echo "<ExtraRuleList>"
trap 'echo "</ExtraRuleList>"' EXIT

[[ $# -gt 0 ]] && rpms=( "$1"/*.rpm )
[[ ${#rpms[@]} -gt 0 ]] || rpms=( $SPAMRPMEXTRA/*.rpm )

for f in "${rpms[@]}"; do
    out=$(rpm -K -v $f 2>/dev/null) && [[ $out == *"gpg: Good signature"* ]] &&
	signed=yes || signed=no
    n=${f##*/}
    printf '    <Rule name="%s" installed="%s" signed="%s"/>\n' \
	"${n%.*.rpm}" "$(date -r "$f" '+%s')" $signed
done
