From: Roland Häder Date: Fri, 21 Jul 2023 05:08:57 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a3980dceabf56b58738ecf7a1be0f8f6c8d56113;p=fba.git Continued: - prepared for reverse-proxy, e.g. Apache/nginx - configuration keys "scheme" (newly added) and "hostname" are how your FBA instance is called from outside, I was not able to find any other way as url_for() was returning a http:// URL and not a https:// ... :-( --- diff --git a/config.defaults.json b/config.defaults.json index 6722c61..bee51f3 100644 --- a/config.defaults.json +++ b/config.defaults.json @@ -6,6 +6,7 @@ "useragent" : "Mozilla/5.0 (Windows NT 10.0; rv:113.0) Gecko/20100101 Firefox/113.0", "connection_timeout" : 30, "read_timeout" : 5, + "scheme" : "https", "hostname" : "example.org", "timestamp_format" : "%Y-%m-%d %H:%M", "nodeinfo_connection_timeout": 3, diff --git a/daemon.py b/daemon.py index d591fc0..817a6ef 100755 --- a/daemon.py +++ b/daemon.py @@ -258,12 +258,10 @@ def api_mutual(domains: list[str] = Query()): @router.get(config.get("base_url") + "/.well-known/nodeinfo", response_class=JSONResponse) def wellknown_nodeinfo(request: Request): - components = urlparse(str(request.url)) - return JSONResponse(status_code=200, content={ "links": ({ "rel" : "http://nodeinfo.diaspora.software/ns/schema/1.0", - "href": f"{components.scheme}://{config.get('hostname')}{config.get('base_url')}/nodeinfo/1.0" + "href": f"{config.get('scheme')}://{config.get('hostname')}{config.get('base_url')}/nodeinfo/1.0" }) }) @@ -369,7 +367,7 @@ def scoreboard(request: Request, mode: str, amount: int): raise HTTPException(status_code=response.status_code, detail=response.text) return templates.TemplateResponse("views/scoreboard.html", { - "base_url" : config.get("base_url"), + "base_url" : utils.base_url(), "slogan" : config.get("slogan"), "theme" : config.get("theme"), "request" : request, @@ -510,6 +508,7 @@ def rss(request: Request, domain: str = None): "request" : request, "timestamp": format_datetime(datetime.now()), "domain" : domain, + "scheme" : config.get("scheme"), "hostname" : config.get("hostname"), "blocks" : blocklist }, headers={ @@ -539,4 +538,4 @@ def index(request: Request): }) if __name__ == "__main__": - uvicorn.run("daemon:router", host=config.get("host"), port=config.get("port"), log_level=config.get("log_level")) + uvicorn.run("daemon:router", host=config.get("host"), port=config.get("port"), log_level=config.get("log_level"), proxy_headers=True) diff --git a/fba/helpers/domain.py b/fba/helpers/domain.py index a388479..dd4e214 100644 --- a/fba/helpers/domain.py +++ b/fba/helpers/domain.py @@ -51,10 +51,11 @@ def is_in_url(domain: str, url: str) -> bool: elif url == "": raise ValueError("Parameter 'url' is empty") - components = urlparse(url) punycode = domain.encode("idna").decode("utf-8") + components = urlparse(url) logger.debug("components[]='%s',punycode='%s'", type(components), punycode) + is_found = (punycode in [components.netloc, components.hostname]) logger.debug("is_found='%s' - EXIT!", is_found) diff --git a/fba/utils.py b/fba/utils.py index 95dcd73..d1cf021 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -23,6 +23,7 @@ import requests import validators from fba.helpers import blacklist +from fba.helpers import config from fba.helpers import domain as domain_helper from fba.helpers import tidyup @@ -185,3 +186,6 @@ def deobfuscate(domain: str, blocker: str, domain_hash: str = None) -> str: logger.debug("domain='%s' - EXIT!", domain) return domain + +def base_url() -> str: + return f"{config.get('scheme')}://{config.get('hostname')}{config.get('base_url')}" diff --git a/templates/base.html b/templates/base.html index 0316cad..eb4ce08 100644 --- a/templates/base.html +++ b/templates/base.html @@ -9,7 +9,7 @@ {% block rss %}{% endblock %} - + diff --git a/templates/views/index.html b/templates/views/index.html index aad268e..88024a9 100644 --- a/templates/views/index.html +++ b/templates/views/index.html @@ -7,9 +7,11 @@ {% block content %} - + + + diff --git a/templates/views/rss.xml b/templates/views/rss.xml index 477e562..84c6f36 100644 --- a/templates/views/rss.xml +++ b/templates/views/rss.xml @@ -9,7 +9,7 @@ {{block['blocker']}} has applied '{{block['block_level']}}' restriction to {{block['blocked']}} {{block['reason']}} - https://{{hostname}}/top?mode=reverse&value={{block['blocker']}} + {{scheme}}://{{hostname}}/top?mode=reverse&value={{block['blocker']}} {{block['first_seen']}} {% endfor %}
-

Choose an option

-
+

Choose an option

+