Exemplo n.º 1
0
def redisphonecheckstatus(request):
    Description = "白名单有效检测"
    stat = []
    if request.method == "POST":
        jsondata = json.loads(request.body)
        print(jsondata)
        username = request.session.get("username")

        for data in jsondata:
            phone = data.get("phone")
            status = Gray(tenginehosts()[0]["host"],
                          tenginehosts()[0]["hostredisport"],
                          phone).checkstatus()
            if status is True:
                code = 0
            else:
                Gray(tenginehosts()[0]["host"],
                     tenginehosts()[0]["hostredisport"], phone).graydelphone()
                code = 1

                recordvalue = "删除手机号码: " + phone

                RecordLog(username=username,
                          recordclass=Description,
                          recordvalue=recordvalue).saveecord()

        return HttpResponseRedirect('/godzilla/cachemanager/grayadd')
Exemplo n.º 2
0
def matchingdel(request):
    Description = "缓存模糊删除"
    username = request.session.get('username')
    redisinfo = []
    if request.method == "POST":
        redis = request.body
        redisinfo = json.loads(redis)
        proxyip = redisinfo[0]["proxyip"]
        proxyport = redisinfo[0]["proxyport"]
        key = redisinfo[0]["key"]
        redis_del = cacheoperation
        redisdelvalue = redis_del(proxyip, proxyport, key).TheadPool()

        recordvalue = "模糊删除缓存 %s" % key

        RecordLog(username=username,
                  recordclass=Description,
                  recordvalue=recordvalue).saveecord()

        return HttpResponse(redisdelvalue)

    else:
        redisip = request.GET["redisip"]
        redis_port = request.GET["redisport"]
        redistable = RedisHost.objects.filter(redis_ip=redisip).filter(
            redis_port__exact=redis_port).values()

        for redis in redistable:
            redisinfo.append(redis)

        return render_to_response('matchingdel.html', {"redisinfo": redisinfo})
Exemplo n.º 3
0
def grayadd(request):
    Description = "添加灰度白名单"
    if request.method == "POST":
        grayrequest = request.body
        grayinfo = json.loads(grayrequest)
        grayphone = grayinfo[0]["phone"]
        duration = grayinfo[0]["duration"]
        username = request.session.get('username')
        dtime = datetime.datetime.now()
        un_time = time.mktime(dtime.timetuple())
        expirytime = int(un_time) + int(duration)
        expirytime = datetime.datetime.fromtimestamp(expirytime)
        createtime = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S').__str__()
        for gray in tenginehosts():
            Gray(gray.get("host"), gray.get("hostredisport"),
                 grayphone).grayaddredisphone(duration=duration)

        addphonestatus = Gray(tenginehosts()[0]["host"],
                              tenginehosts()[0]["hostredisport"],
                              grayphone).grayaddphone(username=username,
                                                      expirytime=expirytime,
                                                      createtime=createtime)

        recordvalue = "添加手机号 %s 到灰度白名单" % grayphone
        RecordLog(username=username,
                  recordclass=Description,
                  recordvalue=recordvalue).saveecord()

        return HttpResponse(addphonestatus)

    else:
        return render(request, "gray-add.html")
Exemplo n.º 4
0
def redisadd(request):
    Description = "添加缓存地址"
    if request.method == "POST":
        redis = request.body
        redisinfo = json.loads(redis)
        proxy_name  = redisinfo[0]["proxy_name"]
        proxy_ip  = redisinfo[0]["proxy_ip"]
        proxy_port  = redisinfo[0]["proxy_port"]
        admin_ip  = redisinfo[0]["admin_ip"]
        admin_port  = redisinfo[0]["admin_port"]
        typeid  = redisinfo[0]["typeid"]
        typename  = redisinfo[0]["typename"]
        owner  = redisinfo[0]["owner"]
        principal  = redisinfo[0]["principal"]
        username = request.session.get('username')

        try:
            redishost = RedisHost.objects.filter(redis_ip__exact=proxy_ip).filter(redis_port__exact=proxy_port)
            if  len(list(redishost)) == 0:
                try:
                    redistable = RedisHost.objects.create(redis_ip=proxy_ip,redis_port=proxy_port,proxy_name=proxy_name,admin_addr=admin_ip,admin_port=admin_port,
                                                         typeid=typeid,typename=typename,project_owner=owner,project_principal=principal)
                    redistable.save()

                    rediserror = "添加缓存 %s:%s 成功" % (proxy_ip,proxy_port)


                    RecordLog(username=username, recordclass=Description, recordvalue=rediserror).saveecord()

                except BaseException as e:
                    logger.error(e)
                    rediserror = "添加缓存 %s:%s 失败" % (proxy_ip, proxy_port)

                    RecordLog(username=username, recordclass=Description, recordvalue=rediserror).saveecord()

            else:
                rediserror = "缓存地址已存在无需重复添加"

        except BaseException as e:
            logger.error(e)
            rediserror = "数据库查询失败"

        return HttpResponse(rediserror)

    else:
        return  render_to_response('codis-add.html')
Exemplo n.º 5
0
def redisupdate(request):

    Description = "更新缓存地址"
    username = request.session.get('username')
    if request.method == "POST":
        redis = request.body
        redisinfo = json.loads(redis)
        rowid  = redisinfo[0]["rowid"]
        proxy_name  = redisinfo[0]["proxy_name"]
        ip  = redisinfo[0]["ip"]
        port  = redisinfo[0]["port"]
        typeid  = redisinfo[0]["typeid"]
        typename  = redisinfo[0]["typename"]
        owner  = redisinfo[0]["owner"]
        principal  = redisinfo[0]["principal"]

        try:
            RedisHost.objects.filter(id=rowid).update(redis_ip=ip,redis_port=port,proxy_name=proxy_name,
                                                         typeid=typeid,typename=typename,project_owner=owner,project_principal=principal)
            rediserror = "缓存信息更新成功"


            RecordLog(username=username, recordclass=Description, recordvalue=rediserror).saveecord()

        except BaseException as e:
            logger.error(e)
            rediserror = "缓存信息更新失败"
            RecordLog(username=username, recordclass=Description, recordvalue=rediserror).saveecord()

        return HttpResponse(rediserror)

    else:
        redisinfo = []
        rowid = request.GET["rowid"]
        redistable = RedisHost.objects.filter(id=rowid).values()

        for redis in redistable:
            redisinfo.append(redis)

        return  render_to_response('codis-edit.html',{"redisinfo":redisinfo})
Exemplo n.º 6
0
def redishostdel(request):
    username = request.session.get('username')
    Description = "删除缓存地址"
    if request.method == "POST":
        pass
    else:
        redis_ip = request.GET["redis_ip"]
        redis_port = request.GET["redis_port"]

        RedisHost.objects.filter(redis_ip__exact=redis_ip).filter(redis_port__exact=redis_port).delete()

        recordvalue = "删除缓存地址 %s:%s 成功 " % (redis_ip,redis_port)
        RecordLog(username=username, recordclass=Description, recordvalue=recordvalue).saveecord()

        return HttpResponseRedirect('/godzilla/platformconf/redislist')
Exemplo n.º 7
0
def delphone(request):
    Description = "删除灰度白名单"
    if request.method == "GET":
        grayphone = request.GET.get("phone")
        username = request.session.get("username")
        for gray in tenginehosts():
            Gray(gray.get("host"), gray.get("hostredisport"),
                 grayphone).graydelredisphone()

        graydelphone = Gray(tenginehosts()[0]["host"],
                            tenginehosts()[0]["hostredisport"],
                            grayphone).graydelphone()

        recordvalue = "从白名单中删除手机号" % grayphone
        RecordLog(username=username,
                  recordclass=Description,
                  recordvalue=recordvalue).saveecord()

        return HttpResponse(graydelphone)