
{
    "name"  : "无感知认证配置命令是否正确",
    "problems" : {
        "JJ_bypassConfig" : {
            "desc"      : "【问题】无感知认证功能不生效 ${0}",
            "advice"    : "【建议】增加配置${1}。"
        }
    }
}

---------------------------code-------------------------------
result='pass'
response = get_share_value('log_versionDetail')
if response.indexOf('N18000') == -1 :
	return 'skip'
end
log_run = get_share_value('log_showrun')
if log_run.indexOf('auth-mode gateway') == -1:
	return 'skip'
end

config = ''
port = ''
restore_cmd = []
reback_cmd = []

reg_aaa = /aaa authentication [^ ]+ default group/
r_aaa = log_run.match(reg_aaa)
if !r_aaa :
	result = 'fail'
	config = 'aaa authentication xxx default group xxx' 
end

reg = /interface\s+(\w+\s+[^ ]+)/
log_runList = log_run.split("\r\n")
if log_run.indexOf('dot1x mac-auth-bypass') > -1:
	foreach data in log_runList:
		r = data.match(reg)
		if r!= null :
		    intf = r[1]
			log_r = getLog(intf,log_runList)
			if log_r.indexOf('dot1x mac-auth-bypass') == -1 && log_r.indexOf('dot1x port-control auto') > -1:
				result = 'fail'
				port = port + intf + '、'
				config = config + 'dot1x mac-auth-bypass ;' 
				restore_cmd.push('config')
				restore_cmd.push('dot1x mac-auth-bypass')
				restore_cmd.push('end')
			end
			if log_r.indexOf('dot1x mac-auth-bypass') > -1 && log_r.indexOf('dot1x port-control auto') == -1:
				result = 'fail'
				port = port + intf + '、'
				config = config + 'dot1x port-control auto ;' 
				restore_cmd.push('config')
				restore_cmd.push('dot1x port-control auto')
				restore_cmd.push('end')
			end
		end
	end
end
if result =='fail':
	change_title('无感知认证配置错误')
	add_problem('JJ_bypassConfig',[port,config],restore_cmd)
    return 'warn'
end
return 'success'



def getLog(intf,strList):
	isBegin = 0
	log = ''
	intf_line = 'interface '+intf
	foreach data in strList:
		if data.indexOf(intf_line) > -1:
			isBegin = 1
		end
		if isBegin && data.indexOf('!') > -1':
			isBegin = 0
		end
		if isBegin:
			log = log + "\r\n" + data
		end
	end
	return log
end



