report format test done + fix reports filter

This commit is contained in:
Jordan Blasenhauer 2024-08-12 21:50:22 +02:00
parent df2b963b8d
commit acb8ad605f
8 changed files with 78 additions and 185 deletions

View file

@ -1,6 +1,3 @@
from enum import Enum
from .utils.widgets import (
input_widget,
select_widget,

View file

@ -22,7 +22,7 @@ columns = [
]
def instances_filter(healths: Healths, types: list = [], methods: list = []) -> list:
def instances_filter(healths: str, types: list = [], methods: list = []) -> list: # healths = "up", "down", "loading"
filters = [
{
"type": "like",

View file

@ -1,5 +1,5 @@
from builder.utils.table import add_column, format_field
from builder.utils.widgets import datepicker_widget, text_widget, tabulator_widget
from .utils.table import add_column, format_field
from .utils.widgets import datepicker_widget, text_widget, tabulator_widget
reports_columns = [
add_column(title="Date", field="date", formatter="fields"),
@ -55,7 +55,7 @@ def reports_filters(reasons: list = [], countries: list = [], methods: list = []
},
]
if reasons.length >= 2:
if len(reasons) >= 2:
reports_filters.append(
{
"type": "=",
@ -73,7 +73,7 @@ def reports_filters(reasons: list = [], countries: list = [], methods: list = []
}
)
if countries.length >= 2:
if len(countries) >= 2:
reports_filters.append(
{
"type": "=",
@ -91,7 +91,7 @@ def reports_filters(reasons: list = [], countries: list = [], methods: list = []
}
)
if methods.length >= 2:
if len(methods) >= 2:
reports_filters.append(
{
"type": "=",
@ -109,7 +109,7 @@ def reports_filters(reasons: list = [], countries: list = [], methods: list = []
}
)
if codes.length >= 2:
if len(codes) >= 2:
reports_filters.append(
{
"type": "=",
@ -130,7 +130,8 @@ def reports_filters(reasons: list = [], countries: list = [], methods: list = []
return reports_filters
def report_item(id: int, date_timestamp: int, ip: str, country: str, method: str, url: str, code: str, user_agent: str, reason: str, data: str) -> dict:
# date = timestamp
def report_item(id: int, date: int, ip: str, country: str, method: str, url: str, code: str, user_agent: str, reason: str, data: str) -> dict:
return (
{
"date": format_field(
@ -139,8 +140,7 @@ def report_item(id: int, date_timestamp: int, ip: str, country: str, method: str
name=f"datepicker-date-{id}",
label="reports_date", # keep it (a18n)
hideLabel=True,
inputType="datepicker",
value=date_timestamp,
value=date,
disabled=True, # Readonly
)
),
@ -157,7 +157,7 @@ def report_item(id: int, date_timestamp: int, ip: str, country: str, method: str
def reports_builder(reports: list, reasons: list = [], countries: list = [], methods: list = [], codes: list = []) -> str:
reports_items = [report_item(**report) for report in reports]
reports_items = [report_item(**report, id=index) for index, report in enumerate(reports)]
return [
{
"type": "card",

View file

@ -1,165 +0,0 @@
import json
import base64
from builder.utils.widgets import button, button_group, title, text, tabulator, fields, upload, datepicker
# TODO : REMOVE operation by custom endpoint
reports_columns = [
{"title": "Date", "field": "date", "formatter": "fields"}, # datepicker
{"title": "IP", "field": "ip", "formatter": "text"},
{"title": "Country", "field": "country", "formatter": "text"},
{"title": "Server name", "field": "server_name", "formatter": "text"},
{"title": "Method", "field": "method", "formatter": "text"},
{"title": "URL", "field": "url", "formatter": "text"},
{"title": "Code", "field": "code", "formatter": "text"},
{"title": "User agent", "field": "user_agent", "formatter": "text"},
{"title": "Reason", "field": "reason", "formatter": "text"},
{"title": "Data", "field": "data", "formatter": "text"},
]
reports_filters = [
{
"type": "like",
"fields": ["ip"],
"setting": {
"id": "input-search-ip",
"name": "input-search-ip",
"label": "reports_search_ip", # keep it (a18n)
"value": "",
"inpType": "input",
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
{
"type": "=",
"fields": ["reason"],
"setting": {
"id": "select-reason",
"name": "select-reason",
"label": "reports_select_reason", # keep it (a18n)
"value": "all", # keep "all"
"values": {"all"}, # keep "all" and add your reasons
"inpType": "select",
"onlyDown": True,
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
{
"type": "like",
"fields": ["url"],
"setting": {
"id": "input-search-url",
"name": "input-search-url",
"label": "reports_search_url", # keep it (a18n)
"value": "",
"inpType": "input",
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
{
"type": "like",
"fields": ["user_agent", "data"],
"setting": {
"id": "input-search-misc",
"name": "input-search-misc",
"label": "reports_search_misc", # keep it (a18n)
"value": "",
"inpType": "input",
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
{
"type": "=",
"fields": ["country"],
"setting": {
"id": "select-country",
"name": "select-country",
"label": "reports_select_country", # keep it (a18n)
"value": "all", # keep "all"
"values": {"all"}, # keep "all" and add your countries
"inpType": "select",
"onlyDown": True,
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
{
"type": "=",
"fields": ["method"],
"setting": {
"id": "select-method",
"name": "select-method",
"label": "reports_select_method", # keep it (a18n)
"value": "all", # keep "all"
"values": {"all"}, # keep "all" and add your methods
"inpType": "select",
"onlyDown": True,
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
{
"type": "=",
"fields": ["code"],
"setting": {
"id": "select-code",
"name": "select-code",
"label": "reports_select_code", # keep it (a18n)
"value": "all", # keep "all"
"values": {"all"}, # keep "all" and add your codes
"inpType": "select",
"onlyDown": True,
"columns": {"pc": 3, "tablet": 4, " mobile": 12},
},
},
]
reports_items = [
{
"date": datepicker(
id="datepicker-date-id", # replace id by unique id
name="datepicker-date-id", # replace by unique id
label="reports_date", # keep it (a18n)
hideLabel=True,
inputType="datepicker",
value="my_date", # replace my_date by timestamp value
disabled=True, # Readonly
)["data"],
"ip": text(text="IP")["data"],
"country": text(text="Country")["data"],
"method": text(text="Method")["data"],
"url": text(text="URL")["data"],
"code": text(text="Code")["data"],
"user_agent": text(text="User agent")["data"],
"reason": text(text="Reason")["data"],
"data": text(text="Data")["data"],
},
]
builder = [
{
"type": "card",
"display": ["main", 1],
"widgets": [
tabulator(
id="table-core-plugins",
columns=reports_columns,
items=reports_items,
filters=reports_filters,
),
],
},
]
with open("reports2.json", "w") as f:
f.write(json.dumps(builder))
output_base64_bytes = base64.b64encode(bytes(json.dumps(builder), "utf-8"))
output_base64_string = output_base64_bytes.decode("ascii")
with open("reports2.txt", "w") as f:
f.write(output_base64_string)

View file

@ -32,7 +32,7 @@ remains = ["all", "hour(s)", "day(s)"]
builder = bans_builder(bans, reasons, remains)
print("builder", builder)
with open("bans2.json", "w") as f:
with open("test_bans2.json", "w") as f:
json.dump(builder, f, indent=4)
output_base64_bytes = base64.b64encode(bytes(json.dumps(builder), "utf-8"))
@ -40,5 +40,5 @@ output_base64_bytes = base64.b64encode(bytes(json.dumps(builder), "utf-8"))
output_base64_string = output_base64_bytes.decode("ascii")
with open("bans2.txt", "w") as f:
with open("test_bans2.txt", "w") as f:
f.write(output_base64_string)

View file

@ -29,12 +29,12 @@ config_types = ["http", "https", "socks4", "socks5"]
builder = configs_builder(configs, config_types)
print("builder", builder)
with open("configs2.json", "w") as f:
with open("test_configs2.json", "w") as f:
json.dump(builder, f, indent=4)
output_base64_bytes = base64.b64encode(bytes(json.dumps(builder), "utf-8"))
output_base64_string = output_base64_bytes.decode("ascii")
with open("configs2.txt", "w") as f:
with open("test_configs2.txt", "w") as f:
f.write(output_base64_string)

View file

@ -27,11 +27,11 @@ healths = ["up", "down", "loading"]
builder = instances_builder(instances)
# store on a file
with open("instances2.json", "w") as f:
with open("test_instances2.json", "w") as f:
json.dump(builder, f, indent=4)
output_base64_bytes = base64.b64encode(bytes(json.dumps(builder), "utf-8"))
output_base64_string = output_base64_bytes.decode("ascii")
with open("instances2.txt", "w") as f:
with open("test_instances2.txt", "w") as f:
f.write(output_base64_string)

View file

@ -0,0 +1,61 @@
import json
import base64
from pages.reports2 import reports_builder
reports = [
{
"date": 1723491739954,
"ip": "127.0.0.1",
"country": "EN",
"method": "POST",
"url": "/admin",
"code": "400",
"user_agent": "Mozilla/5.0",
"reason": "antibot",
"data": "lore ipsum ad vitam aeternam",
},
{
"date": 1723491738000,
"ip": "127.0.0.2",
"country": "EN",
"method": "GET",
"url": "/etc?",
"code": "300",
"user_agent": "Mozilla/0.1",
"reason": "unknown",
"data": "",
},
]
# define a set
countries = set()
methods = set()
codes = set()
reasons = set()
for report in reports:
countries.add(report["country"])
methods.add(report["method"])
codes.add(report["code"])
reasons.add(report["reason"])
# convert set to list
countries = list(countries)
methods = list(methods)
codes = list(codes)
reasons = list(reasons)
builder = reports_builder(reports, reasons, countries, methods, codes)
print("builder", builder)
with open("test_reports2.json", "w") as f:
json.dump(builder, f, indent=4)
output_base64_bytes = base64.b64encode(bytes(json.dumps(builder), "utf-8"))
output_base64_string = output_base64_bytes.decode("ascii")
with open("test_reports2.txt", "w") as f:
f.write(output_base64_string)