#!/bin/sh

#############
# CHANGELOG
#############
# 2011/01/05    CRMS00284302    Thanh lam NGUYEN
#               fix "vlan filter" display
#############

esc=$'\x1b' attr="$esc[32m" default="$esc[0m"

OFF=off
ON=blocking
FILTER="voice vlan filtering"

#######################
: "Function definition"
#######################
help() {
    local scriptname=${0##*/}
    echo ""
    echo "Syntax: $scriptname [-h|--help]"
    echo ""
    echo "This script return the current status of the pc port security."
    echo "It can be:"
    echo "  $ON"
    echo "  $OFF"
    echo "  $FILTER"
    echo ""
}

: "${attr}Read system configuration${default}"
source /etc/functions
source $DEBUGBINPATH/.functions

: "${attr}Read current configuration${default}"
readCurrentConfig

: "${attr}Getting status${default}"
RET=$OK

: "${attr}Command line arguments processing...${default}"
while [[ x$1 != x ]]; do
    case "$1" in
        -h|--help)
            help
            RET=$OK
            EXITSCRIPT
        ;;
        *)
            # allow the overwritting of SECUCFG_PC_PORT only if DEBUG is set 
            [[ ${DEBUG-nodebug} != nodebug ]] && SECUCFG_PC_PORT=$1
        ;;
    esac
    shift
done

: "${attr}SECUCFG_PC_PORT=$SECUCFG_PC_PORT${default}"
case "$SECUCFG_PC_PORT" in
    [Ff][Aa][Ll][Ss][Ee])
        security=$OFF
# CRMS00284302
        case "$SECUCFG_PC_PORT_VLAN_FILTER" in
            [Tt][Rr][Uu][Ee])
                security=$FILTER
            ;;
        esac
# CRMS00284302 END
    ;;
    [Tt][Rr][Uu][Ee]) 
        security=$ON
    ;;
    *) security=UNKNOWN RET=$NOK;;
esac
echo "protection: $security"

[[ $RET -eq $OK ]] && { EXITOK; } || { EXITNOK; }
