Beispiel #1
0
def add_white_ip(request):
    form = WhiteList_Add(data=request.GET)
    if form.is_valid():
        newwhiteip = WhiteIp(   user = Userinfo.objects.get(user=request.user),
                                ip=form.cleaned_data['white_ip'],
                                addtime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        newwhiteip.save()
        add_success = True
        whiteip = request.GET.get('white_ip')
        ipflow = request.GET.get('flow')
        if ipflow == "上行":
            ipflow = "0"
        else:
            ipflow = "1"
        print "ipflow",ipflow,"whiteip",whiteip

        resips = ResIp.objects.filter(Q(sip=whiteip,flow="0")|Q(dip=whiteip,flow="1"))
        print "resips",resips
        for i in resips:
            i.iswhite = True
            i.save()
        add_success = True
        return HttpResponseRedirect('/user_statistic/ip/')
    else:
        return render_to_response('error.html',locals(), context_instance = RequestContext(request))
Beispiel #2
0
def white_ip(request):
    title = u'IP白名单管理'

    if request.method == "POST":
        form = WhiteList_Add(data=request.POST)
        if form.is_valid():
            add_success = True
            if not WhiteIp.objects.filter(user=Userinfo.objects.get(user=request.user),ip=form.cleaned_data['white_ip']):
                newwhiteip = WhiteIp(   user = Userinfo.objects.get(user=request.user),
                                    ip=form.cleaned_data['white_ip'],
                                    addtime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                newwhiteip.save()
                try:
                    whiteips = ResIp.objects.filter(user=Userinfo.objects.get(user=request.user),suspiciousip=form.cleaned_data['white_ip'])
                    for i in whiteips:
                        i.iswhite = True
                        i.save()
                    add = True
                except:
                    add = True
            return render_to_response('usersettings/white_ip.html',locals(), context_instance = RequestContext(request))
        else:
            return render_to_response('error.html',locals(), context_instance = RequestContext(request))

    return render_to_response('usersettings/white_ip.html',locals(), context_instance = RequestContext(request))