#!/bin/bash
set +x
#нڵ
G_INSPECT_MMLPATH="/opt/huawei/snas/script/inspect_mml"
. $G_INSPECT_MMLPATH/CheckItems
CurInspectNum="319"
CurInspectFun=`GetInspectType $CurInspectNum`
RESULTFILE="/tmp/tmpResult${CurInspectFun}"
>$RESULTFILE

isPass=0

function main()
{
    #/usr/local/bin/MmlBatch 4016 "cm  licensecfg"
    #InfoAllocator,InfoLocker,InfoStamper 
    #ĳڵValid = 1, Cfged = 1ʹãûʹá
    local openstatus="Valid = 1, Cfged = 1"
    local strCmdOut=""
    local iRet=0
    strCmdOut=$( /usr/local/bin/MmlBatch 988 "show globalvar" )
    iRet=$?
    if [ $iRet -ne 0 ]; then
        echo "[ERR]INFO:Failed to execute command(MmlBatch 988 'show globalvar')." >>${RESULTFILE} 2>&1
        isPass=1
    fi

    globalvar=$( echo "${strCmdOut}" | egrep "g_pstSnapSwitch|g_pstQuotaSwitch|g_pstWormSwitch" )
    SnapSwitch=$( echo "${globalvar}" | grep g_pstSnapSwitch )
    if [[ ${SnapSwitch} =~ "${openstatus}" ]];then  
        InfoStamper="yes"
    else
        InfoStamper="no"
    fi
    QuotaSwitch=$( echo "${globalvar}" | grep g_pstQuotaSwitch )
    if [[ ${QuotaSwitch} =~ "${openstatus}" ]];then  
        InfoAllocator="yes"
    else
        InfoAllocator="no"
    fi
    
    WormSwitch=$( echo "${globalvar}" | grep g_pstWormSwitch )
    if [[ ${WormSwitch} =~ "${openstatus}" ]];then  
        InfoLocker="yes"
    else
        InfoLocker="no"
    fi
    
    #SecureVideo Switch is ROʾݴ
    #SecureVideo Switch is RWʾдݴ
    #Ƕдݴ----ݴʾΪnoùδ
    #SecureVideo Switch is off  --- ùδ
    strCmdOut=$( /usr/local/bin/MmlBatch 988 "show securevideo" )
    iRet=$?
    if [ $iRet -ne 0 ]; then
        echo "[ERR]INFO:Failed to execute command(MmlBatch 988 'show securevideo')." >>${RESULTFILE} 2>&1
        isPass=1
    fi
    SecureVideo=$( echo "${strCmdOut}" | grep "SecureVideo" )
    securevalue=$(echo ${SecureVideo} | awk '{print $4}')
    if [ "off" == "${securevalue}" ];then
        InfoRevive="no"
    else
        InfoRevive="yes"
        echo "[ERR]INFO:${SecureVideo}" >>${RESULTFILE} 2>&1
        isPass=1
    fi
    
    #policy cntΪ0û÷ּԣ 
    #policy cntΪ1acPolicyNameΪdefaultpolicyPolicy IdΪ128ĬϲԲҪּǨƣзּ
    #policy cntΪ1,зּ
    strCmdOut=$( /usr/local/bin/MmlBatch 988 "monc tsp 0" )
    iRet=$?
    if [ $iRet -ne 0 ]; then
        echo "[ERR]INFO:Failed to execute command(MmlBatch 988 'monc tsp 0')." >>${RESULTFILE} 2>&1
        isPass=1
    fi
    policyinfo=$( echo "${strCmdOut}" |egrep "policy cnt|Policy Id|acPolicyName" )
    policycnt=$(echo "${policyinfo}" | grep "policy cnt" | awk -F":" '{print $2}')
    if [ "X0" == "X${policycnt}" ];then
        InfoTier="no"
    else
        InfoTier="yes"
    fi
    
    #InfoScanner
    Scanner=$( sqlite3 /opt/huawei/etc/ccdb/nas_av_db_0/nas_av_db "select * from tbl_av_config where id=65" | awk -F"|" '{print $3}' )
    if [ "X0" == "X${Scanner}" ];then
        InfoScanner="no"
    else
        InfoScanner="yes"
    fi 
    #ӡϢ
    echo "InfoAllocator:${InfoAllocator}||InfoStamper:${InfoStamper}||InfoLocker:${InfoLocker}||InfoRevive:${InfoRevive}||InfoTier:${InfoTier}||InfoScanner:${InfoScanner}" >${RESULTFILE} 2>&1 
     
}
 
main
echo "${CurInspectFun}_Pass $isPass" >>${RESULTFILE} 2>&1
exit 0



