def jla_search1(request):
    data = request.data

    instance = dict(
        type=data["type"] if "type" in data.keys() else "remote_addr",
        # accesslog_table=LocalAccessLogTable,
        daysdelta=int(data["daysdelta"]) if "daysdelta" in data.keys() else 90,
        limit=int(data["limit"]) if "limit" in data.keys() else 100,
        start_time=data["start_time"] if "start_time" in data.keys() else None,
        end_time=data["end_time"] if "end_time" in data.keys() else None,
    )
    query_sql, _types = get_jl_accsslog(**instance)
    if instance["type"] not in _types:
        return Response({"stat": False}, {"reason": "输入类型错误"})
    # print(query_sql)
    try:
        _objs = from_sql_get_data(query_sql)["data"]
    except:
        return Response(data={"ERROR": query_sql}, status=206)
    pager = int(data["page"]) if "page" in data.keys() else 1
    p = Paginator(_objs, 10)
    all_counts = p.count  # 对象总数
    page_count = p.num_pages  # 总页数
    pj = p.page(pager)
    objs = pj.object_list

    return Response({
        "search_params": data,
        "res": objs,
        "page_count": page_count,
        "pager": pager,
        "all_counts": all_counts
    })
Exemplo n.º 2
0
def jls_search(request):
    data = request.data
    instance = dict(
        request_method=data["request_method"] if "request_method" in data.keys() else None,
        request_version=data["request_version"] if "request_version" in data.keys() else None,
        src_host=data["src_host"] if "src_host" in data.keys() else None,
        src_ip=data["src_ip"] if "src_ip" in data.keys() else None,
        request_url=data["request_url"] if "request_url" in data.keys() else None,
        category=data["category"] if "category" in data.keys() else None,  # 分类
        content_type=data["content_type"] if "content_type" in data.keys() else None,
        resp_code=int(data["resp_code"]) if "resp_code" in data.keys() else None,
        limit=int(data["limit"]) if "limit" in data.keys() else 100,
        start_time=data["start_time"] if "start_time" in data.keys() else None,
        end_time=data["end_time"] if "end_time" in data.keys() else None,
    )

    from ..utils.seclog_search import seclog_search2
    _objs = from_sql_get_data(seclog_search2(**instance))["data"]
    # return Response(_objs)
    ### 开始准备分页

    pager = int(data["page"]) if "page" in data.keys() else 1
    p = Paginator(_objs, 10)
    all_counts = p.count  # 对象总数
    page_count = p.num_pages  # 总页数
    pj = p.page(pager)
    objs = pj.object_list

    return Response(
        {"search_params": data, "res": objs, "page_count": page_count, "pager": pager, "all_counts": all_counts})
Exemplo n.º 3
0
def jla_search2(request):
    data = request.data

    instance = dict(
        limit_bytes=int(data["limit_bytes"]) if "limit_bytes" in data.keys() else 10240,
        limit_vtimes=int(data["limit_vtimes"]) if "limit_vtimes" in data.keys() else 10240,
        remote_addrs=data["remote_addrs"] if "remote_addrs" in data.keys() else None,
        split_type=data["split_type"] if "split_type" in data.keys() else "date",

        # accesslog_table=LocalAccessLogTable,

        daysdelta=int(data["daysdelta"]) if "daysdelta" in data.keys() else 90,
        limit=int(data["limit"]) if "limit" in data.keys() else 100,
        start_time=data["start_time"] if "start_time" in data.keys() else None,
        end_time=data["end_time"] if "end_time" in data.keys() else None,
        extra=data["extra"] if "extra" in data.keys() else None,
    )
    query_sql = tj_bytes_timedelta(**instance).replace("\n", " ")
    try:
        _objs = from_sql_get_data(query_sql)["data"]
    except:
        return Response(data={"ERROR":query_sql}, status=206)
    pager = int(data["page"]) if "page" in data.keys() else 1
    p = Paginator(_objs, 10)
    all_counts = p.count  # 对象总数
    page_count = p.num_pages  # 总页数
    pj = p.page(pager)
    objs = pj.object_list

    return Response(
        {"search_params": data, "res": objs, "page_count": page_count, "pager": pager, "all_counts": all_counts})
def get_data_from_sqls(key, limit=15):

    return [
        x[key] for x in from_sql_get_data(
            """select {key}, count({key}) as c from {table} group by {key} order by c desc limit {limit};"""
            .format(table=WAF_ACCESS_LOG_SQL_TABLE, limit=limit, key=key))
        ["data"]
    ]
def get_waf_access_log_columns(reject_list=("id", "remote_user")):
    datas = from_sql_get_data("desc waf_access_log")["data"]
    fields = [x['Field'] for x in datas]
    for key in reject_list:
        try:
            fields.remove(key)
        except:
            pass
    return fields
Exemplo n.º 6
0
def get_all_info_dependon_auditid2(audit_logid):
    from xsqlmb.src.ltool.sqlconn import from_sql_get_data
    _sql = """select * from {alertlog_detaild} where audit_logid='{audit_logid}';""".format(
        alertlog_detaild=WAF_ALERT_LOG_DETAILED_SQL_TABLE,
        audit_logid=audit_logid)
    _data = from_sql_get_data(_sql)["data"]
    if len(_data) > 0:
        return _data[0]["detaild"]
    return None
def get_waf_alert_log_columns(reject_list=("id", )):
    datas = from_sql_get_data("desc waf_alert_log")["data"]
    fields = [x['Field'] for x in datas]
    for key in reject_list:
        try:
            fields.remove(key)
        except:
            pass
    return fields
    #return "`" + "`, `".join(fields) + "`"
Exemplo n.º 8
0
 def get_sqldata(self):
     _sqlstr = self.groupy()
     try:
         from xsqlmb.src.ltool.sqlconn import from_sql_get_data
         _sqldata = from_sql_get_data(_sqlstr)["data"]
         for x in _sqldata:
             print(x)
         print(_sqlstr)
     except:
         print(_sqlstr)
Exemplo n.º 9
0
    def test_wrapped():
        _sqlstr = WrapperFilter(**WrapperFilter.get_self_demo_json())._wraped_sqlstr()

        try:
            from xsqlmb.src.ltool.sqlconn import from_sql_get_data
            _sqldata = from_sql_get_data(_sqlstr)["data"]
            for x in _sqldata:
                print(x)
            print(_sqlstr)
        except:
            print(_sqlstr)