{
    "name"  : "检测用户地址是否配置屏蔽上网",
    "problems" : {
        "ipDeny" : {
            "desc"      : "【问题】该用户配置了deny属性",
            "advice"    : "【建议】请将该IP地址从禁止用户中删除"
        },
        "ipDenyGlobal" : {
            "desc"      : "【问题】设备开启了全局屏蔽模式",
            "advice"    : "【建议】请将需要放行的IP地址配置为白名单用户"
        }
    }
}

---------------------------code-------------------------------
ipCheck = precondition('ipCheck')

reg = /[\r\n]\s*.+?\,([\d\s\.\/\-]+)/g
response = cli('show su deny')
result = response.match(reg)
if result != null :
    foreach item in result :
        reg = /[\r\n]\s*.+?\,([\d\s\.\/\-]+)/
        ipInfo = item.match(reg)
        ipInfo = ipInfo[1]
        ipInfo = ipInfo.replace(/\s/g,'')
        if ipInfo.search(/\-/) != -1 :
            ipArr = ipInfo.split(/\-/)
            ipStart = ipArr[0]
            ipEnd = ipArr[1]
            if isIpInSpecifiedRange(ipStart,ipEnd,ipCheck) == true :
                add_problem('ipDeny')
                return 'warn'
            end
        else if ipInfo.search(/\//) != -1 :
            ipmask = ipInfo.split(/\//)
            ip = ipmask[0]
            mask = ipmask[1]
            if isSameIpseg(ip,ipCheck,mask) == true :
                add_problem('ipDeny')
                return 'warn'
            end
        else :
            if ipInfo == ipCheck :
                add_problem('ipDeny')
                return 'warn'
            end
        end
    end
end

reg = /layer23\sdeny\smode\sis\soff/i
response = cli('show layer23 deny-mode')
result = response.match(reg)
if !result :
    reg = /[\r\n]\s*.+?\,([\d\s\.\/\-]+)/g
    response = cli('show su release')
    result = response.match(reg)
    isConf = false
    if result != null :
        foreach item in result :
            reg = /[\r\n]\s*.+?\,([\d\s\.\/\-]+)/
            ipInfo = item.match(reg)
            ipInfo = ipInfo[1]
            ipInfo = ipInfo.replace(/\s/g,'')
            if ipInfo.search(/\-/) != -1 :
                ipArr = ipInfo.split(/\-/)
                ipStart = ipArr[0]
                ipEnd = ipArr[1]
                if isIpInSpecifiedRange(ipStart,ipEnd,ipCheck) == true :
                    isConf = true
                    break
                end
            else if ipInfo.search(/\//) != -1 :
                ipmask = ipInfo.split(/\//)
                ip = ipmask[0]
                mask = ipmask[1]
                if isSameIpseg(ip,ipCheck,mask) == true :
                    isConf = true
                    break
                end
            else :
                if ipInfo == ipCheck :
                    isConf = true
                    break
                end
            end
        end
    end
    if isConf == false :
        add_problem('ipDenyGlobal')
        return 'warn'
    end
end

return 'success'


