Example #1
0
def getwebdata(request):
    """
    获取数据信息在前端形成图表
    """
    webdata = ElasticSearch().get_webapps_num()
    product = ElasticSearch().get_zujian_num()
    return JsonResponse({"webdata": webdata, "product": product})
Example #2
0
def delete_sr_data(request):
    """
    删除一条数据
    :param request:
    :type request:
    :return:
    :rtype:
    """
    if not request.session.get("isLogin_manger"):
        return HttpResponse(status=404)
    ip = request.POST.get("ip")
    res = ElasticSearch()
    if res.delete_data(ip):
        return JsonResponse({"info": 0})
    else:
        return JsonResponse({"info": 1})
Example #3
0
def get_data(request):
    """
    管理员对数据的处理
    :param request:
    :type request:
    :return:
    :rtype:
    """
    if not request.session.get("isLogin_manger"):
        return HttpResponse(status=404)
    msg = request.GET.get("msg", "")
    msg.strip()
    page = request.GET.get("page", 0)
    try:
        page = int(page)
    except BaseException:
        page = 1
    # 分析语法、错误处理、语法是否合法尚 均在底层实现 这里只做简单的处理,去掉最后一个;
    msgs = msg.split(";")
    if msgs[-1] == "":
        msgs.pop()
    res = ElasticSearch().search(msgs, page=page)
    tag = msg
    try:
        total = res["hits"]["total"]
        hits_list = []
        for hit in res["hits"]["hits"]:
            hits_dict = {}
            hits_dict["ip"] = hit["_source"]["ip"]
            # hits_dict["read"] = hit["_source"]["read"]
            hits_dict["server"] = hit["_source"]["server"]
            hits_dict["prowerd"] = hit["_source"]["prower"]
            hits_dict["title"] = hit["_source"]["title"]
            hits_dict["timestamp"] = hit["_source"]["timestamp"]
            hits_list.append(hits_dict)
        return JsonResponse({
            "page": page,
            "total": total,
            "tag": tag,
            "all_hits": hits_list
        })
    except BaseException:
        return JsonResponse({
            "page": 0,
            "total": 0,
            "tag": tag,
            "all_hits": None
        })
Example #4
0
def dataanal(request):
    """
    渲染数据分析页面
    """
    res = ElasticSearch().getData_number()
    data_num = res["hits"]["total"]
    user_name = None
    if request.session.get("isLogin"):
        user_name = request.session.get("isLogin")
        # 判断用户是否被禁用(处理用户已登录的时候禁用的操作)
        from searchapp.models import search_user
        if search_user.objects.get(name=user_name).flag == 1:
            del request.session["isLogin"]
            return HttpResponseRedirect("/")
    return render(request, "searchapp/seh_dataAnal.html", {
        "data_num": data_num,
        "user_name": user_name
    })
Example #5
0
def detial(request):
    """
    获取详情页面
    :param request:
    :type request:
    :return:
    :rtype:
    """
    user_name = None
    if request.session.get("isLogin"):
        user_name = request.session.get("isLogin")
    else:
        return HttpResponseRedirect("/")
    # 判断用户是否被禁用(处理用户已登录的时候禁用的操作)
    from searchapp.models import search_user
    if search_user.objects.get(name=user_name).flag == 1:
        del request.session["isLogin"]
        return HttpResponseRedirect("/")
    from mysite.tools.Class_IPinfo import ipinfo
    ip = request.GET.get("ip")
    server = request.GET.get("server")
    prowerd = request.GET.get("prowerd")
    title = request.GET.get("title")

    data = ipinfo(ip).get_ipinfo()

    # ======老办法,速度慢=======
    # dom = DomainInfo(ip)
    # data = dom.getIpInfo()
    data["LN"] = data["location"]["latitude"]
    data["LE"] = data["location"]["longitude"]
    user_name = None
    if request.session.get("isLogin"):
        user_name = request.session.get("isLogin")
    data["user_name"] = user_name
    data["server"] = server
    data["prowerd"] = prowerd
    data["title"] = title
    data["read"] = ElasticSearch().getRead(ip)
    data["ip"] = ip
    return render(request, "searchapp/seh_detial.html", data)
Example #6
0
def getdata(request):
    """
    获取搜索的数据 一次去10条
    :param request:
    :type request:
    :return:
    :rtype:
    """
    # 判断用户是否存在
    user_name = None
    if request.session.get("isLogin"):
        user_name = request.session.get("isLogin")
    else:
        return HttpResponseRedirect("/")
    # 判断用户是否被禁用(处理用户已登录的时候禁用的操作)
    from searchapp.models import search_user
    if search_user.objects.get(name=user_name).flag == 1:
        del request.session["isLogin"]
        return HttpResponseRedirect("/")
    """
    获取主页请求数据并返回
    """
    msg = request.GET.get("search_msg")
    msg.strip()
    page = request.GET.get("page")
    try:
        page = int(page)
    except BaseException:
        page = 1
    # 分析语法、错误处理、语法是否合法尚未判断 均在底层实现 这里只做简单的处理,去掉最后一个;
    msgs = msg.split(";")
    if msgs[-1] == "":
        msgs.pop()
    start_time = time.time()
    res = ElasticSearch().search(msgs, page=page)
    end_time = time.time()
    search_time = float("%.2f" % (end_time - start_time))
    tag = msg
    try:
        total = res["hits"]["total"]
        hits_list = []
        for hit in res["hits"]["hits"]:
            hits_dict = {}
            hits_dict["ip"] = hit["_source"]["ip"]
            hits_dict["read"] = hit["_source"]["read"]
            hits_dict["server"] = hit["_source"]["server"]
            hits_dict["prowerd"] = hit["_source"]["prower"]
            hits_dict["title"] = hit["_source"]["title"]
            hits_dict["timestamp"] = hit["_source"]["timestamp"]
            hits_list.append(hits_dict)
        return render(
            request, "searchapp/seh_showData.html", {
                "page": page,
                "total": total,
                "time": search_time,
                "tag": tag,
                "all_hits": hits_list,
                "user_name": user_name
            })
    except BaseException:
        return render(
            request, "searchapp/seh_showData.html", {
                "page": 0,
                "total": 0,
                "time": search_time,
                "tag": tag,
                "all_hits": None,
                "user_name": user_name
            })
        write = write.replace("\'", "")
        reslut["data"]["write"] = write
        return reslut

    def set_http_head(self, head):
        """
        自定义 请求头
        """
        self._head = head


if __name__ == '__main__':
    import sys
    import os
    # import json
    sys.path.append(os.path.dirname(os.path.abspath(__file__)))
    test = Get_Banner(ip="106.15.200.166", port=80, timeout=20)
    # f = open("123.json","a")
    res = str(test.getbanner())
    # re.sub(r"(,?)(\w+?)\s*?:", r"\1'\2':",res)
    res = res.replace("\'", "\"")
    # res = res.replace("\\","")
    # print(res)
    # f.writelines(res)
    # f.close()

    # json.loads(res)
    print(res)
    from mysite.tools.Class_ElasticSearch import ElasticSearch
    e = ElasticSearch()
    e.insert_data([res])