feat: Add more replace options
All checks were successful
Build Docker / Build Docker (push) Successful in 29s

This commit is contained in:
Nathan Woodburn 2024-03-01 17:26:32 +11:00
parent b065530cad
commit 37379e4255
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 7 additions and 2 deletions

View File

@ -1,3 +1,4 @@
PROXY=http://nathanwoodburn:5000/ PROXY=http://nathanwoodburn:5000/
TLD=woodburn TLD=woodburn
RESTRICTED=["admin"] RESTRICTED=["admin"]
REPLACE=["https://nathan.woodburn.au/"]

View File

@ -4,4 +4,4 @@ Environment variables:
- `PROXY` - The proxy to use for restricted TLDs. Example: `http://localhost:3128` - `PROXY` - The proxy to use for restricted TLDs. Example: `http://localhost:3128`
- `TLD` - The TLD to restrict. Example: `g` - `TLD` - The TLD to restrict. Example: `g`
- `RESTRICTED` - List of restricted paths. Example: `["path1", "path2"]` will require the user to have a .g domain to access `path1/*`, `path2/*` - `RESTRICTED` - List of restricted paths. Example: `["path1", "path2"]` will require the user to have a .g domain to access `path1/*`, `path2/*`
- `REPLACE` - List of urls to replace with the host to fix redirects and links

View File

@ -14,6 +14,8 @@ RESTRICTED = os.getenv('RESTRICTED')
RESTRICTED = json.loads(RESTRICTED) RESTRICTED = json.loads(RESTRICTED)
RESTRICTED = [f'{i.lower()}/' for i in RESTRICTED] RESTRICTED = [f'{i.lower()}/' for i in RESTRICTED]
TLD = os.getenv('TLD') TLD = os.getenv('TLD')
REPLACEMENT = os.getenv('REPLACE')
REPLACEMENT = json.loads(REPLACEMENT)
# Load cookies # Load cookies
cookies = [] cookies = []
@ -118,6 +120,8 @@ def catch_all(path):
if 'text/html' in res.headers['Content-Type']: if 'text/html' in res.headers['Content-Type']:
content = res.content.decode('utf-8') content = res.content.decode('utf-8')
content = content.replace(URL, request.host_url) content = content.replace(URL, request.host_url)
for i in REPLACEMENT:
content = content.replace(i, request.host_url)
response = make_response(content, res.status_code, headers) response = make_response(content, res.status_code, headers)
return response return response