示例#1
0
文件: web.py 项目: Blaskyy/DevOps
def do_white_list(ips_tmp, ports_tmp):
    #ips_tmp=request.forms.get('ips')
    #ports_tmp=request.forms.get('ports')
    json_data=get_data()
    response.content_type = 'application/json'
    white_list={}
    white_list['data']={}
    if ips_tmp!='' and ports_tmp!='':
        ips=ips_tmp.split('-')
        ports=[int(i) for i in ports_tmp.split('|')]
        if len(ips)==1:
            if ip_num.isIP(ips[0]) == False:
                return 'Wrong IP'
            content={}
            content['ip']=ips[0]
            content['port']=[]
            for i in json_data['ips']:
                if i['ip']==ips[0]:
                    for j in i['port']:
                        if j not in ports:
                            content['port'].append(j)
            return json.dumps(content,
                    sort_keys=True, indent=2, separators=(',', ': '))

        if False == (ip_num.isIP(ips[0]) and ip_num.isIP(ips[1])):
            return 'Wrong IP'
        if ip_num.ip2num(ips[0])>ip_num.ip2num(ips[1]):
            ips[0],ips[1]=ips[1],ips[0]
        for ip in range(ip_num.ip2num(ips[0]),ip_num.ip2num(ips[1]) + 1):
            for i in json_data['ips']:
                if i['ip']==ip_num.num2ip(ip):
                    content={}
                    content[i['ip']]={}
                    content[i['ip']]['port']=[]
                    for j in i['port']:
                        if j not in ports:
                            content[i['ip']]['port'].append(j)
                    white_list['data']=dict(white_list['data'], **content)
        return json.dumps(white_list,
                sort_keys=True, indent=2, separators=(',', ': '))
    return "Wrong Input"
示例#2
0
文件: web.py 项目: Blaskyy/DevOps
def do_filter():
    ip_tmp = request.forms.get('ips')
    port_tmp = request.forms.get('ports')
    if ip_tmp != '' and port_tmp == '':
        ips = ip_tmp.split('-')
        if len(ips) == 1:
            if ip_num.isIP(ips[0]):
                redirect("/filter_ip/%s/%s" % (ips[0],ips[0]))
            else:
                return 'Wrong IP'
        elif len(ips) == 2:
            if ip_num.isIP(ips[0]) & ip_num.isIP(ips[1]):
                redirect("/filter_ip/%s/%s" % (ips[0],ips[1]))
            else:
                return "Wrong IP"
        else:
            return 'Wrong IP'
    elif ip_tmp == '' and port_tmp != '':
        ports = port_tmp.split('-')
        if len(ports) ==1:
            if ip_num.isPort(ports[0]):
                redirect("/filter_port/%s/%s" % (ports[0],ports[0]))
            else:
                return 'Wrong port'
        elif len(ports) == 2:
            if ip_num.isPort(ports[0]) and ip_num.isPort(ports[1]):
                redirect("/filter_port/%s/%s" % (ports[0],ports[1]))
            else:
                return 'Wrong port'
        else:
            return 'Wrong port'

    elif ip_tmp != '' and port_tmp != '':
        redirect('/white_list/%s/%s' % (ip_tmp, port_tmp))
    else:
        return 'Wrong input'