diff --git a/CaddyfileDev b/CaddyfileDev index a0d64a2..dc9ee4e 100644 --- a/CaddyfileDev +++ b/CaddyfileDev @@ -6,98 +6,106 @@ handle_path /android-chrome-192x192.png { root * ./static/android-chrome-192x192.png - file_server + file_server } handle_path /android-chrome-512x512.png { root * ./static/android-chrome-512x512.png - file_server + file_server } handle_path /apple-touch-icon.png { root * ./static/apple-touch-icon.png - file_server + file_server } handle_path /browserconfig.xml { root * ./static/browserconfig.xml - file_server + file_server } handle_path /favicon-16x16.png { root * ./static/favicon-16x16.png - file_server + file_server } handle_path /favicon-32x32.png { root * ./static/favicon-32x32.png - file_server + file_server } handle_path /favicon.ico { root * ./static/favicon.ico - file_server + file_server } handle_path /humans.txt { root * ./static/humans.txt - file_server + file_server } handle_path /mstile-144x144.png { root * ./static/mstile-144x144.png - file_server + file_server } handle_path /mstile-150x150.png { root * ./static/mstile-150x150.png - file_server + file_server } handle_path /mstile-310x150.png { root * ./static/mstile-310x150.png - file_server + file_server } handle_path /mstile-310x310.png { root * ./static/mstile-310x310.png - file_server + file_server } handle_path /mstile-70x70.png { root * ./static/mstile-70x70.png - file_server + file_server } handle_path /robots.txt { root * ./static/robots.txt - file_server + file_server } handle_path /safari-pinned-tab.svg { root * ./static/safari-pinned-tab.svg - file_server + file_server } handle_path /security.txt { root * ./static/security.txt - file_server + file_server } handle_path /site.webmanifest { root * ./static/site.webmanifest - file_server + file_server } handle_path /sitemap.xml { root * ./static/sitemap.xml - file_server + file_server } handle_path /websocket { respond "Access denied" 403 } + handle_path /meta.json { + respond "Access denied" 403 + } + + handle_path /cdn-cgi/challenge-platform/scripts/jsd/main.js { + respond "Access denied" 403 + } + handle_path /cdn-cgi/rum { respond "Access denied" 403 } @@ -162,7 +170,6 @@ respond "Access denied" 403 } - route /* { reverse_proxy web:7080 } diff --git a/CaddyfileProd b/CaddyfileProd index dfe260b..89003aa 100644 --- a/CaddyfileProd +++ b/CaddyfileProd @@ -7,98 +7,106 @@ freedium.cfd { handle_path /android-chrome-192x192.png { root * ./static/android-chrome-192x192.png - file_server + file_server } handle_path /android-chrome-512x512.png { root * ./static/android-chrome-512x512.png - file_server + file_server } handle_path /apple-touch-icon.png { root * ./static/apple-touch-icon.png - file_server + file_server } handle_path /browserconfig.xml { root * ./static/browserconfig.xml - file_server + file_server } handle_path /favicon-16x16.png { root * ./static/favicon-16x16.png - file_server + file_server } handle_path /favicon-32x32.png { root * ./static/favicon-32x32.png - file_server + file_server } handle_path /favicon.ico { root * ./static/favicon.ico - file_server + file_server } handle_path /humans.txt { root * ./static/humans.txt - file_server + file_server } handle_path /mstile-144x144.png { root * ./static/mstile-144x144.png - file_server + file_server } handle_path /mstile-150x150.png { root * ./static/mstile-150x150.png - file_server + file_server } handle_path /mstile-310x150.png { root * ./static/mstile-310x150.png - file_server + file_server } handle_path /mstile-310x310.png { root * ./static/mstile-310x310.png - file_server + file_server } handle_path /mstile-70x70.png { root * ./static/mstile-70x70.png - file_server + file_server } handle_path /robots.txt { root * ./static/robots.txt - file_server + file_server } handle_path /safari-pinned-tab.svg { root * ./static/safari-pinned-tab.svg - file_server + file_server } handle_path /security.txt { root * ./static/security.txt - file_server + file_server } handle_path /site.webmanifest { root * ./static/site.webmanifest - file_server + file_server } handle_path /sitemap.xml { root * ./static/sitemap.xml - file_server + file_server } handle_path /websocket { respond "Access denied" 403 } + handle_path /meta.json { + respond "Access denied" 403 + } + + handle_path /cdn-cgi/challenge-platform/scripts/jsd/main.js { + respond "Access denied" 403 + } + handle_path /cdn-cgi/rum { respond "Access denied" 403 } diff --git a/README.md b/README.md index ca3003b..42e9a2b 100644 --- a/README.md +++ b/README.md @@ -61,3 +61,6 @@ sudo docker-compose -f docker-compose-dev.yml up ``` And now you can access local instance of Freedium by opening browser and type `http://localhost:6752`. + +## TODO: +- Integrate library notifiers - https://github.com/liiight/notifiers diff --git a/scripts/generate_caddy_rules.py b/scripts/generate_caddy_rules.py index 8253c97..da269b4 100644 --- a/scripts/generate_caddy_rules.py +++ b/scripts/generate_caddy_rules.py @@ -1,54 +1,91 @@ from os import listdir from os.path import isfile, join - +from typing import List, Dict from jinja2 import Template -OUTPUT_RULES = [] +# Constants +STATIC_DIR = "./static" +ACCESS_DENIED_PATHS: List[str] = [ + "websocket", + "meta.json", + "cdn-cgi/challenge-platform/scripts/jsd/main.js", + "cdn-cgi/rum", + "graphql/websocket", + "onboarding/*", + "wp-*", + ".env", + "api*", + "apple-touch-icon-precomposed.png", + "rss.xml", + ".git/*", + "apple-touch-icon-120x120.png", + "apple-touch-icon-120x120-precomposed.png", + "apple-touch-icon-152x152.png", + "apple-touch-icon-152x152-precomposed.png", + ".well-known/*", + "cdn-cgi/challenge-platform/h/b/orchestrate/chl_page/v1", + "cdn-cgi/challenge-platform/h/g/orchestrate/chl_page/v1", +] - -static_files = [f for f in listdir("./static") if isfile(join("./static", f))] - -static_file_template = """ - handle_path /{{ file }} { - root * ./static/{{ file }} - file_server - } -""" -static_file_template_jinja = Template(static_file_template) - -for file in static_files: - file_template = static_file_template_jinja.render(file=file) - OUTPUT_RULES.append(file_template) - - -ACCESS_DENIED_PATHS = ["websocket", "cdn-cgi/rum", "graphql/websocket", "onboarding/*", "wp-*", ".env", "api*", "apple-touch-icon-precomposed.png", "rss.xml", ".git/*", "apple-touch-icon-120x120.png", "apple-touch-icon-120x120-precomposed.png", "apple-touch-icon-152x152.png", "apple-touch-icon-152x152-precomposed.png", ".well-known/*", "cdn-cgi/challenge-platform/h/b/orchestrate/chl_page/v1", "cdn-cgi/challenge-platform/h/g/orchestrate/chl_page/v1"] - -access_denied_paths_template = """ - handle_path /{{ file }} { - respond "Access denied" 403 - } -""" - -access_denied_paths_template_jinja = Template(access_denied_paths_template) - -for denied_path in ACCESS_DENIED_PATHS: - denied_path_template = access_denied_paths_template_jinja.render(file=denied_path) - OUTPUT_RULES.append(denied_path_template) - -HUMAN_OUTPUT_RULES = "\n".join(OUTPUT_RULES) - -# with open("scripts/output_rules.txt", "w") as file: -# file.write(HUMAN_OUTPUT_RULES) - -caddy_file_templates = { +CADDY_FILE_TEMPLATES: Dict[str, str] = { "CaddyfileDevTemplate": "CaddyfileDev", "CaddyfileProdTemplate": "CaddyfileProd", } -for caddy_file_template, output_caddy_file_template in caddy_file_templates.items(): - with open(caddy_file_template) as file: - caddy_file = Template(file.read()) - caddy_file_rendered = caddy_file.render(template=HUMAN_OUTPUT_RULES) - with open(output_caddy_file_template, "w") as file: - file.write(caddy_file_rendered) +def get_static_files(directory: str) -> List[str]: + return [f for f in listdir(directory) if isfile(join(directory, f))] + + +def generate_static_file_rules(files: List[str]) -> List[str]: + template = Template( + """ + handle_path /{{ file }} { + root * ./static/{{ file }} + file_server + } + """ + ) + return [template.render(file=file) for file in files] + + +def generate_access_denied_rules(paths: List[str]) -> List[str]: + template = Template( + """ + handle_path /{{ file }} { + respond "Access denied" 403 + } + """ + ) + return [template.render(file=path) for path in paths] + + +def generate_caddy_rules() -> str: + static_files = get_static_files(STATIC_DIR) + static_rules = generate_static_file_rules(static_files) + denied_rules = generate_access_denied_rules(ACCESS_DENIED_PATHS) + return "\n".join(static_rules + denied_rules) + + +def render_caddy_file(template_path: str, output_path: str, rules: str) -> None: + try: + with open(template_path, "r") as file: + template = Template(file.read()) + + rendered_content = template.render(template=rules) + + with open(output_path, "w") as file: + file.write(rendered_content) + except IOError as e: + print(f"Error processing {template_path}: {e}") + + +def main() -> None: + rules = generate_caddy_rules() + + for template_file, output_file in CADDY_FILE_TEMPLATES.items(): + render_caddy_file(template_file, output_file, rules) + + +if __name__ == "__main__": + main() diff --git a/server/templates/base.html b/server/templates/base.html index 3c0d721..2b9c428 100644 --- a/server/templates/base.html +++ b/server/templates/base.html @@ -1,108 +1,126 @@ - - - - - {{ title or "Breaking Medium paywall!" }} - Freedium - {% if creator %}{% endif %} - - - - - - - - - - - - - - - - - + + + + + {{ title or "Breaking Medium paywall!" }} - Freedium + {% if creator %} + {% endif %} + + - - -
- - -
+ + + + + + + + + + + + + + + + + + +
+ + +
- -