]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 21 Jul 2023 05:08:57 +0000 (07:08 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Jul 2023 06:21:54 +0000 (08:21 +0200)
- 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:// ... :-(

config.defaults.json
daemon.py
fba/helpers/domain.py
fba/utils.py
templates/base.html
templates/views/index.html
templates/views/rss.xml

index 6722c61566a0242d066b9d25d830fb8f4f4bbe72..bee51f3b924bbdcebd2ec18971458e2178c33850 100644 (file)
@@ -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,
index d591fc0ab9f03924427a2b664173bcd9dc3796ae..817a6ef19183bc3bc630611fe5915e379efc7321 100755 (executable)
--- 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)
index a38847963c7ebcc71e36906341a35980688fd020..dd4e214c62ad543fea15e09f05358980594fac59 100644 (file)
@@ -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)
index 95dcd73e4d9c3959b6fe2382d148affd7708d4a6..d1cf021fe3781e65d154215f49352fdd34d43274 100644 (file)
@@ -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')}"
index 0316cad14dde929b1610f6748e591320cf12a312..eb4ce0807ce6846cfbc015534a210a842278c4b0 100644 (file)
@@ -9,7 +9,7 @@
     <link rel="alternate" type="application/rss+xml" title="RSS Feed for latest blocked instances" href="rss" />
     {% block rss %}{% endblock %}
 
-    <link rel="stylesheet" type="text/css" href="{{ url_for('static', path='css/' + theme + '.css') }}?v=0.0.2" media="all" />
+    <link rel="stylesheet" type="text/css" href="static/css/{{theme}}.css?v=0.0.2" media="all" />
 </head>
 
 <body>
index aad268ea2e560065685970a1e742fea48ea1e98b..88024a9c93029d69c79544433eb9beea6d6e8ac3 100644 (file)
@@ -7,9 +7,11 @@
 {% block content %}
     <table class="index-table">
     <thead>
-        <th colspan="2">
-            <h3>Choose an option</h3>
-        </th>
+        <tr>
+            <th colspan="2">
+                <h3>Choose an option</h3>
+            </th>
+        </tr>
     </thead>
 
     <tbody>
index 477e5627f91f5416c11b68121ca92ade9cfa4b2f..84c6f362297298474b71136fadab02d8bd2982c1 100644 (file)
@@ -9,7 +9,7 @@
  <item>
   <title>{{block['blocker']}} has applied '{{block['block_level']}}' restriction to {{block['blocked']}}</title>
   <description>{{block['reason']}}</description>
-  <link>https://{{hostname}}/top?mode=reverse&amp;value={{block['blocker']}}</link>
+  <link>{{scheme}}://{{hostname}}/top?mode=reverse&amp;value={{block['blocker']}}</link>
   <pubDate>{{block['first_seen']}}</pubDate>
  </item>
  {% endfor %}