From 78f68a5345ad43783cd882e3374fa02405801411 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 9 Jun 2023 06:12:38 +0200 Subject: [PATCH] Continued: - renamed originator -> command --- api.py | 16 ++++++++-------- blocks_empty.db | Bin 32768 -> 32768 bytes fba/instances.py | 18 +++++++++--------- templates/views/index.html | 2 +- templates/views/scoreboard.html | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/api.py b/api.py index 3add50d..0fb839e 100644 --- a/api.py +++ b/api.py @@ -47,7 +47,7 @@ def info(): } @router.get(config.get("base_url") + "/api/top.json", response_class=JSONResponse) -def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, originator: int = None, error_code: int = None): +def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, command: int = None, error_code: int = None): if blocked is not None: if blocked > 500: raise HTTPException(status_code=400, detail="Too many results") @@ -64,10 +64,10 @@ def top(blocked: int = None, blockers: int = None, reference: int = None, softwa if software > 500: raise HTTPException(status_code=400, detail="Too many results") fba.cursor.execute("SELECT software, COUNT(domain) FROM instances WHERE software IS NOT NULL GROUP BY software ORDER BY COUNT(domain) DESC, software ASC LIMIT ?", [software]) - elif originator is not None: - if originator > 500: + elif command is not None: + if command > 500: raise HTTPException(status_code=400, detail="Too many results") - fba.cursor.execute("SELECT originator, COUNT(domain) FROM instances WHERE originator IS NOT NULL GROUP BY originator ORDER BY COUNT(domain) DESC, originator ASC LIMIT ?", [originator]) + fba.cursor.execute("SELECT command, COUNT(domain) FROM instances WHERE command IS NOT NULL GROUP BY command ORDER BY COUNT(domain) DESC, command ASC LIMIT ?", [command]) elif error_code is not None: if error_code > 500: raise HTTPException(status_code=400, detail="Too many results") @@ -154,7 +154,7 @@ def mutual(domains: list[str] = Query()): return JSONResponse(status_code=200, content={}) @router.get(config.get("base_url") + "/scoreboard") -def scoreboard(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, originator: int = None, error_code: int = None): +def scoreboard(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, command: int = None, error_code: int = None): if blockers is not None and blockers > 0: response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?blockers={blockers}") elif blocked is not None and blocked > 0: @@ -163,8 +163,8 @@ def scoreboard(request: Request, blockers: int = None, blocked: int = None, refe response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?reference={reference}") elif software is not None and software > 0: response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?software={software}") - elif originator is not None and originator > 0: - response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?originator={originator}") + elif command is not None and command > 0: + response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?command={command}") elif error_code is not None and error_code > 0: response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?error_code={error_code}") else: @@ -184,7 +184,7 @@ def scoreboard(request: Request, blockers: int = None, blocked: int = None, refe "blocked" : blocked, "reference" : reference, "software" : software, - "originator": originator, + "command" : command, "error_code": error_code, "scores" : fba.json_from_response(response) }) diff --git a/blocks_empty.db b/blocks_empty.db index 9e4a4a22ce5f88f22410505f3226faed62ac8f5e..7d4e8870814c368ac2ddb88ed6c07ad30560232d 100644 GIT binary patch delta 94 zcmZo@U}|V!njkIsoq>UY1BhY3YNC#@^mhh5?}@zJn;6*H4>R!1<$cF~nCmy!bS@?S qshb4_+}MFqOf4}2?BeqBjGgS8PqE7|vM1-~<|gK)Z2rI@P!0eAz8DGs delta 94 zcmZo@U}|V!njkIsje&uI1BhY3a-xp0^fv}Q?}@zJn;6*H4>0h}<$cF~fa^EcbS@?S rshb4_+}OEV;sw~n<>eVWc{iVBmto|}FUm~M%u6iEFWUTpL!cZ02U-}d diff --git a/fba/instances.py b/fba/instances.py index e002fb3..f31cad3 100644 --- a/fba/instances.py +++ b/fba/instances.py @@ -172,8 +172,8 @@ def update_last_blocked(domain: str): # DEBUG: print("DEBUG: EXIT!") -def add(domain: str, origin: str, originator: str, path: str = None): - # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',originator='{originator}',path='{path}' - CALLED!") +def add(domain: str, origin: str, command: str, path: str = None): + # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}' - CALLED!") if not isinstance(domain, str): raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'") elif domain == "": @@ -182,10 +182,10 @@ def add(domain: str, origin: str, originator: str, path: str = None): raise ValueError(f"origin[]={type(origin)} is not 'str'") elif origin == "": raise ValueError("Parameter 'origin' is empty") - elif not isinstance(originator, str): - raise ValueError(f"originator[]={type(originator)} is not 'str'") - elif originator == "": - raise ValueError("Parameter 'originator' is empty") + elif not isinstance(command, str): + raise ValueError(f"command[]={type(command)} is not 'str'") + elif command == "": + raise ValueError("Parameter 'command' is empty") elif not validators.domain(domain.split("/")[0]): raise ValueError(f"Bad domain name='{domain}'") elif origin is not None and not validators.domain(origin.split("/")[0]): @@ -195,7 +195,7 @@ def add(domain: str, origin: str, originator: str, path: str = None): elif domain.find("/profile/") > 0 or domain.find("/users/") > 0: raise Exception(f"domain='{domain}' is a single user") - # DEBUG: print("DEBUG: domain,origin,originator,path:", domain, origin, originator, path) + # DEBUG: print("DEBUG: domain,origin,command,path:", domain, origin, command, path) software = fba.determine_software(domain, path) # DEBUG: print("DEBUG: Determined software:", software) if domain.find("/c/") > 0 and software == "lemmy": @@ -207,11 +207,11 @@ def add(domain: str, origin: str, originator: str, path: str = None): print(f"INFO: Adding instance domain='{domain}' (origin='{origin}',software='{software}')") try: fba.cursor.execute( - "INSERT INTO instances (domain, origin, originator, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)", + "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)", ( domain, origin, - originator, + command, fba.get_hash(domain), software, time.time() diff --git a/templates/views/index.html b/templates/views/index.html index 8a4db26..24f0f0b 100644 --- a/templates/views/index.html +++ b/templates/views/index.html @@ -29,7 +29,7 @@ defederated instances / referencing instances / used software / - originators / + commands / error codes

{% endblock %} diff --git a/templates/views/scoreboard.html b/templates/views/scoreboard.html index bf5852d..f5fd8a7 100644 --- a/templates/views/scoreboard.html +++ b/templates/views/scoreboard.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block title %}scoreboard - {% if software %}TOP {{software}} used software{% elif originator %}TOP {{originator}} scripts{% elif reference %}TOP {{reference}} referencing instances{% elif blocked %}TOP {{blocked}} deferated instances{% elif blockers %}TOP {{blockers}} deferating instances{% endif %}{% endblock %} +{% block title %}scoreboard - {% if software %}TOP {{software}} used software{% elif command %}TOP {{command}} scripts{% elif reference %}TOP {{reference}} referencing instances{% elif blocked %}TOP {{blocked}} deferated instances{% elif blockers %}TOP {{blockers}} deferating instances{% endif %}{% endblock %} {% block header %} {% if blockers %} @@ -11,8 +11,8 @@

Top {{reference}} referencing instances

{% elif software %}

Top {{software}} used software

- {% elif originator %} -

TOP {{originator}} scripts

+ {% elif command %} +

TOP {{command}} scripts

{% elif error_code %}

TOP {{error_code}} error codes

{% endif %} @@ -32,7 +32,7 @@ {{loop.index}} - {% if software or originator or error_code %} + {% if software or command or error_code %} {{entry['domain']}} {% elif entry['domain'] == None %} - -- 2.39.5