#!/bin/sh

log() {
    logger -p local4.info -t macblacklist -- "$*"
}

log "update MAC blacklist"
cd /usr/local/univnautes/sp
for ctx in $(./manage.py configxml get cpnames); do
    /sbin/ipfw -x $ctx -fq delete 666
    for MAC in $(./manage.py configxml get blacklist macaddresses | sed 's/#.*$//'); do
        # sanitize
        MAC=`echo $MAC | tr -dc 0-9a-fA-F:`
        if test -n "$MAC"; then
            if /sbin/ipfw -x $ctx -fq add 666 deny MAC $MAC any; then
                log "added: $MAC in $ctx"
            else
                log "ERROR can't add: $MAC (incorrect MAC address ?)"
            fi
        fi
    done
done

exit 0
