From 193546fcde04778db7992f282cfae0854c3e1a5f Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 31 Dec 2023 13:59:13 +0100 Subject: [PATCH] Implement dynamic service rendering with Flask Refactored the website to serve dynamic content using Flask, replacing static HTML pages. This allows for the centralized management of service data through a JSON file. Optimizations include: - Added a .gitignore file to exclude Python and Flask-specific temporary files. - Migrated static assets into an organized directory structure to facilitate Flask's static file serving. - Removed redundant HTML files and created Flask template versions with dynamic content rendering. - Introduced Caddy server configuration for the new Flask architecture, including headers for security and CORS policy, and reverse proxy settings for route handling. With these changes, website maintenance and updates are simplified, allowing for service information to be updated in a single location (`services.json`), which then propagates to the user-facing pages automatically. --- .gitignore | 3 + Caddyfile | 26 ++ {dist => assets/dist}/css/bootstrap.min.css | 0 .../dist}/css/bootstrap.min.css.map | 0 .../dist}/js/bootstrap.bundle.min.js | 0 .../dist}/js/bootstrap.bundle.min.js.map | 0 {dist => assets/dist}/js/jquery.min.js | 0 {dist => assets/dist}/js/popper.min.js | 0 index.html | 360 ------------------ main.py | 23 ++ privatecoffee.ini | 14 + requirements.txt | 2 + services.json | 220 ++++++++++- simple.html | 30 -- templates/index.html | 179 +++++++++ legal.html => templates/legal.html | 14 +- privacy.html => templates/privacy.html | 14 +- templates/simple.html | 22 ++ terms.html => templates/terms.html | 14 +- 19 files changed, 508 insertions(+), 413 deletions(-) create mode 100644 .gitignore create mode 100644 Caddyfile rename {dist => assets/dist}/css/bootstrap.min.css (100%) rename {dist => assets/dist}/css/bootstrap.min.css.map (100%) rename {dist => assets/dist}/js/bootstrap.bundle.min.js (100%) rename {dist => assets/dist}/js/bootstrap.bundle.min.js.map (100%) rename {dist => assets/dist}/js/jquery.min.js (100%) rename {dist => assets/dist}/js/popper.min.js (100%) delete mode 100644 index.html create mode 100644 main.py create mode 100644 privatecoffee.ini create mode 100644 requirements.txt delete mode 100644 simple.html create mode 100644 templates/index.html rename legal.html => templates/legal.html (88%) rename privacy.html => templates/privacy.html (95%) create mode 100644 templates/simple.html rename terms.html => templates/terms.html (95%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25636a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv/ +*.pyc +__pycache__/ \ No newline at end of file diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..608e070 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,26 @@ +private.coffee www.private.coffee { + header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" + + header Access-Control-Allow-Origin https://element.private.coffee + header Access-Control-Allow-Methods "GET" + header Access-Control-Allow-Headers "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range" + header Access-Control-Expose-Headers "Content-Length,Content-Range" + + header /.well-known/matrix/* Content-Type application/json + header /.well-known/matrix/* Access-Control-Allow-Origin * + respond /.well-known/matrix/server `{"m.server": "matrix.private.coffee:443"}` + respond /.well-known/matrix/client `{"m.homeserver":{"base_url":"https://matrix.private.coffee"}}` + + @html { + path_regexp html /(.*).html + } + + reverse_proxy @html localhost:9810 + + @assets { + path assets /assets/* + } + + file_server + root @assets /srv/private.coffee +} diff --git a/dist/css/bootstrap.min.css b/assets/dist/css/bootstrap.min.css similarity index 100% rename from dist/css/bootstrap.min.css rename to assets/dist/css/bootstrap.min.css diff --git a/dist/css/bootstrap.min.css.map b/assets/dist/css/bootstrap.min.css.map similarity index 100% rename from dist/css/bootstrap.min.css.map rename to assets/dist/css/bootstrap.min.css.map diff --git a/dist/js/bootstrap.bundle.min.js b/assets/dist/js/bootstrap.bundle.min.js similarity index 100% rename from dist/js/bootstrap.bundle.min.js rename to assets/dist/js/bootstrap.bundle.min.js diff --git a/dist/js/bootstrap.bundle.min.js.map b/assets/dist/js/bootstrap.bundle.min.js.map similarity index 100% rename from dist/js/bootstrap.bundle.min.js.map rename to assets/dist/js/bootstrap.bundle.min.js.map diff --git a/dist/js/jquery.min.js b/assets/dist/js/jquery.min.js similarity index 100% rename from dist/js/jquery.min.js rename to assets/dist/js/jquery.min.js diff --git a/dist/js/popper.min.js b/assets/dist/js/popper.min.js similarity index 100% rename from dist/js/popper.min.js rename to assets/dist/js/popper.min.js diff --git a/index.html b/index.html deleted file mode 100644 index 1aef9b5..0000000 --- a/index.html +++ /dev/null @@ -1,360 +0,0 @@ - - - - - - Private.coffee - - - - - - - - - - - - -
-
-

Welcome to Private.coffee

-

- Private.coffee is a collection of services that respect your privacy. -

-

- Click on a service to go to it. Some services are also available using - Tor and/or I2P. Click the arrow behind the "Go to" link to see all - available versions. -

- -
-
-

Matrix

-

- Private.coffee runs a Matrix server. You can use it to chat with - other people at Private.coffee or around the world. -

- Go to Element (Matrix client) -
-
-

CryptPad

-

- CryptPad is a private, encrypted, zero-knowledge, realtime - collaborative editor, similar to Google Docs and Office 365. -

- Go to CryptPad -
-
-

Invidious

-

Watch YouTube videos without Google tracking you. -

- Go to Invidious -
-
-

Mastodon

-

- Mastodon is a decentralized social network. You can use it to - follow people, post messages, and more. Private.coffee hosts two - Mastodon instances: skrt.social and cuddly.space -

- Go to skrt.social - Go to cuddly.space -
-
-

Gothub

-

- Gothub is an alternative GitHub interface that respects your - privacy. It is currently in alpha, but you can browse and download - repositories, and you can also clone them using git+https - (although the text on the main page would disagree). -

- Go to Gothub -
-
-

AllTube

-

- AllTube is a video downloader powered by yt-dlp. It allows you to - download videos from YouTube, Vimeo, and many other sites. You can - also stream the download through our server for extra privacy. -

- Go to AllTube -
-
-

Indestructables

-

- Indestructables allows you to browse Instructables without being - tracked. (N.B.: We forked this project, our instance does not use - the original code.) -

- Go to Indestructables -
-
-

NocoDB

-

- NocoDB is an open-source tool that turns any database into a smart - spreadsheet similar to Airtable. It provides an interface to - perform CRUD operations and to build intuitive dashboards. (Note: - If you are unable to create tables upon registration, simply wait - a minute or two, log out and then log in again.) -

- Go to NocoDB -
-
-

Penpot

-

- Penpot is an open-source design and prototyping platform meant for - cross-domain teams. Non-dependent on operating systems, Penpot is - web-based and works with open web standards (SVG). -

- Go to Penpot -
-
-

YOURLS

-

- Use our URL shortener at private.cf to turn long, complicated URLs - into something more handy. -

- Go to private.cf -
-
-

Rallly

-

- Rallly is a free collaborative scheduling service. It allows you - to create polls and vote on them, similar to Doodle. -

- Go to Rallly -
-
-

LibreY

-

- LibreY is an open-source, privacy-friendly metasearch engine. It - allows you to search for web, image, video, torrents, and more, - and it can also search onion sites. -

- Go to LibreY -
-
-

Overleaf

-

- Overleaf is a collaborative LaTeX editor. It allows you to write - LaTeX documents in your browser and share them with others. -

- Go to Overleaf -
-
-

Libreddit

-

- Use Reddit without Reddit tracking you. Currently unstable due to - API changes introduced by Reddit... -

-
- Go to Libreddit - - - -
-
-
-

Nitter

-

- Use Twitter without Twitter tracking you. Currently broken because - Elon. -

-
- Go to Nitter - - - -
-
-
-

Hosting

-

- Need hosting for your privacy-related, social or wholesome - project? We might be able to share our resources with you for - free! -

- Get in touch! -
-
-

More?

-

- We are working on more services. If you have any suggestions, - please let us know! -

- Get in touch! -
-
-
-
- - - - diff --git a/main.py b/main.py new file mode 100644 index 0000000..f553ac2 --- /dev/null +++ b/main.py @@ -0,0 +1,23 @@ +from flask import Flask, render_template, send_from_directory +from jinja2 import TemplateNotFound + +import json +import pathlib + +app = Flask(__name__) + +@app.route('/assets/') +def send_assets(path): + return send_from_directory('assets', path) + +@app.route('/', defaults={'path': 'index'}) +@app.route('/.html') +def catch_all(path): + try: + services = json.loads((pathlib.Path(__file__).parent / "services.json").read_text()) + return render_template(f'{path}.html', services=services) + except TemplateNotFound: + return "404 Not Found", 404 + +if __name__ == '__main__': + app.run(port=9810) diff --git a/privatecoffee.ini b/privatecoffee.ini new file mode 100644 index 0000000..ea32542 --- /dev/null +++ b/privatecoffee.ini @@ -0,0 +1,14 @@ +[uwsgi] +module = main:app + +uid = %n +gid = %n +master = true +processes = 5 + +plugins = python3 +virtualenv = /srv/%n/venv/ +chdir = /srv/%n/ + +http-socket = /var/run/uwsgi/%n.sock +chown-socket = caddy \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..98731bb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +jinja2 \ No newline at end of file diff --git a/services.json b/services.json index 21df388..eb1d293 100644 --- a/services.json +++ b/services.json @@ -1,14 +1,230 @@ { "services": [ + { + "name": "Matrix", + "url": "https://element.private.coffee", + "short_description": "Matrix is an open network for secure, decentralized communication.", + "long_description": "Private.coffee runs a Matrix server. You can use it to chat with other people at Private.coffee or around the world. Use it with a client of your choice, with https://matrix.private.coffee as the homeserver, or use our web client.", + "status": "OK", + "links": [ + { + "name": "Go to Element (Web client)", + "url": "https://element.private.coffee" + } + ], + "exclude_from_simple": true + }, + { + "name": "CryptPad", + "url": "https://cryptpad.private.coffee", + "short_description": "Private, encrypted, real-time collaborative editor.", + "long_description": "CryptPad is a private, encrypted, zero-knowledge, realtime collaborative editor, similar to Google Docs and Office 365.", + "status": "OK", + "links": [ + { + "name": "Go to CryptPad", + "url": "https://cryptpad.private.coffee" + } + ], + "exclude_from_simple": false + }, { "name": "Invidious", "url": "https://invidious.private.coffee", - "description": "Watch YouTube videos without Google tracking you." + "short_description": "Watch YouTube videos without Google tracking.", + "long_description": "Invidious is an alternative front-end to YouTube. It allows you to watch YouTube videos without Google tracking you.", + "status": "OK", + "links": [ + { + "name": "Go to Invidious", + "url": "https://invidious.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "Mastodon", + "url": "https://cuddly.space", + "short_description": "Mastodon is a decentralized social network.", + "long_description": "Mastodon is a decentralized social network. You can use it to post short messages, follow other people, and more.", + "status": "OK", + "links": [ + { + "name": "Go to Cuddly Space", + "url": "https://cuddly.space" + }, + { + "name": "Go to Skrt Social", + "url": "https://skrt.social" + } + ], + "exclude_from_simple": false + }, + { + "name": "GotHub", + "url": "https://gothub.private.coffee", + "short_description": "Alternative GitHub interface that respects privacy.", + "long_description": "Gothub is an alternative GitHub interface that respects your privacy. It is currently in alpha, but you can browse and download repositories, and you can also clone them using git+https (although the text on the main page would disagree).", + "status": "OK", + "links": [ + { + "name": "Go to GotHub", + "url": "https://gothub.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "redlib", + "url": "https://redlib.private.coffee", + "short_description": "redlib is a privacy-friendly alternative front-end to Reddit.", + "long_description": "redlib is a privacy-friendly alternative front-end to Reddit. It allows you to browse Reddit without being tracked.", + "status": "OK", + "links": [ + { + "name": "Go to Libreddit", + "url": "https://libreddit.private.coffee", + "alternatives": [ + { + "name": "Tor (.onion)", + "url": "http://libreddit.coffee2m3bjsrrqqycx6ghkxrnejl2q6nl7pjw2j4clchjj6uk5zozad.onion/" + } + ] + } + ], + "exclude_from_simple": true + }, + { + "name": "AllTube", + "url": "https://alltube.private.coffee", + "short_description": "Download videos from YouTube, Vimeo, and more.", + "long_description": "AllTube is a video downloader powered by yt-dlp. It allows you to download videos from YouTube, Vimeo, and many other sites. You can also stream the download through our server for extra privacy.", + "status": "OK", + "links": [ + { + "name": "Go to AllTube", + "url": "https://alltube.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "Indestructables", + "url": "https://indestructables.private.coffee", + "short_description": "Browse Instructables without being tracked.", + "long_description": "Indestructables allows you to browse Instructables without being tracked. (N.B.: We forked this project, our instance does not use the original code.)", + "status": "OK", + "links": [ + { + "name": "Go to Indestructables", + "url": "https://indestructables.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "NocoDB", + "url": "https://nocodb.private.coffee", + "short_description": "NocoDB is a self-hosted alternative to Airtable.", + "long_description": "NocoDB is a self-hosted alternative to Airtable. It allows you to create databases and tables, and to view and edit them in a spreadsheet-like interface. (Note: If you are unable to create tables upon registration, simply wait a minute or two, log out and then log in again.)", + "status": "OK", + "links": [ + { + "name": "Go to NocoDB", + "url": "https://nocodb.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "Penpot", + "url": "https://penpot.private.coffee", + "short_description": "Penpot is an open-source design and prototyping platform.", + "long_description": "Penpot is an open-source design and prototyping platform. It allows you to create designs and prototypes, and to collaborate with others.", + "status": "OK", + "links": [ + { + "name": "Go to Penpot", + "url": "https://penpot.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "YOURLS", + "url": "https://private.cf", + "short_description": "URL shortener for creating handy links.", + "long_description": "Use our URL shortener at private.cf to turn long, complicated URLs into something more handy.", + "status": "OK", + "links": [ + { + "name": "Go to private.cf", + "url": "https://private.cf" + } + ], + "exclude_from_simple": false + }, + { + "name": "Rallly", + "url": "https://rallly.private.coffee", + "short_description": "Rallly is a free collaborative scheduling service for voting and polls.", + "long_description": "Rallly is a free collaborative scheduling service. It allows you to create polls and vote on them, similar to Doodle.", + "status": "OK", + "links": [ + { + "name": "Go to Rallly", + "url": "https://rallly.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "LibreY", + "url": "https://librey.private.coffee", + "short_description": "Privacy-friendly metasearch engine.", + "long_description": "LibreY is an open-source, privacy-friendly metasearch engine. It allows you to search for web, image, video, torrents, and more, and it can also search onion sites.", + "status": "OK", + "links": [ + { + "name": "Go to LibreY", + "url": "https://librey.private.coffee" + } + ], + "exclude_from_simple": false + }, + { + "name": "Overleaf", + "url": "https://overleaf.private.coffee", + "short_description": "Overleaf is an online LaTeX editor for writing and sharing documents.", + "long_description": "Overleaf is an online LaTeX editor for writing and sharing documents. It allows you to write documents in LaTeX, and to collaborate with others.", + "status": "OK", + "links": [ + { + "name": "Go to Overleaf", + "url": "https://overleaf.private.coffee" + } + ], + "exclude_from_simple": false }, { "name": "Nitter", "url": "https://nitter.private.coffee", - "description": "Use Twitter without Twitter tracking you." + "short_description": "Nitter is a privacy-friendly alternative front-end to Twitter.", + "long_description": "Nitter is a privacy-friendly alternative front-end to Twitter. It allows you to browse Twitter without being tracked. Currently broken.", + "status": "NOK", + "links": [ + { + "name": "Go to Nitter", + "url": "https://nitter.private.coffee", + "alternatives": [ + { + "name": "Tor (.onion)", + "url": "http://nitter.coffee2m3bjsrrqqycx6ghkxrnejl2q6nl7pjw2j4clchjj6uk5zozad.onion/" + } + ] + } + ], + "exclude_from_simple": true } ] } \ No newline at end of file diff --git a/simple.html b/simple.html deleted file mode 100644 index b911f58..0000000 --- a/simple.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - -Private.coffee - - -
-

Welcome to Private.coffee

-

Thanks for using our Element instance. Private.coffee is a collection of services that respect your privacy, here are some others:

-
    -
  • CryptPad - Private, encrypted, real-time collaborative editor.
  • -
  • Invidious - Watch YouTube videos without Google tracking.
  • -
  • Mastodon - skrt.social - Decentralized social network instance.
  • -
  • Mastodon - cuddly.space - Decentralized social network instance.
  • -
  • Gothub - Alternative GitHub interface that respects privacy.
  • -
  • AllTube - Video downloader for sites like YouTube and Vimeo.
  • -
  • Indestructables - Browse Instructables without being tracked.
  • -
  • NocoDB - Open-source tool turning databases into smart spreadsheets.
  • -
  • Penpot - Open-source design and prototyping platform.
  • -
  • YOURLS - URL shortener for creating handy links.
  • -
  • Rallly - Collaborative scheduling service for polls and voting.
  • -
  • LibreY - Privacy-friendly metasearch engine.
  • -
  • Overleaf - Collaborative LaTeX editor for writing and sharing documents.
  • -
-

For hosting inquiries for privacy-related, social, or wholesome projects, get in touch!

-
- - diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..dd7a10e --- /dev/null +++ b/templates/index.html @@ -0,0 +1,179 @@ + + + + + + Private.coffee + + + + + + + + + + + + +
+
+

Welcome to Private.coffee

+

+ Private.coffee is a collection of services that respect your privacy. +

+

+ Click on a service to go to it. Some services are also available using + Tor and/or I2P. Click the arrow behind the "Go to" link to see all + available versions. +

+ +
+ {% for service in services.services %} +
+

{{ service.name }}

+

+ {{ service.long_description }} +

+ {% for link in service.links %} +
+ {{ link.name }} + {% if link.alternatives %} + + + {% endif %} +
+ {% endfor %} +
+ {% endfor %} + +
+

Hosting

+

+ Need hosting for your privacy-related, social or wholesome + project? We might be able to share our resources with you for + free! +

+ Get in touch! +
+
+

More?

+

+ We are working on more services. If you have any suggestions, + please let us know! +

+ Get in touch! +
+
+
+
+ + + + diff --git a/legal.html b/templates/legal.html similarity index 88% rename from legal.html rename to templates/legal.html index 6fd60df..cb0982e 100644 --- a/legal.html +++ b/templates/legal.html @@ -8,12 +8,12 @@ Private.coffee - - - - - - + + + + + + @@ -21,7 +21,7 @@ Private.coffee logo Private.coffee diff --git a/privacy.html b/templates/privacy.html similarity index 95% rename from privacy.html rename to templates/privacy.html index ff65afb..2381cde 100644 --- a/privacy.html +++ b/templates/privacy.html @@ -8,12 +8,12 @@ Private.coffee - - - - - - + + + + + + @@ -21,7 +21,7 @@ Private.coffee logo Private.coffee diff --git a/templates/simple.html b/templates/simple.html new file mode 100644 index 0000000..d319dac --- /dev/null +++ b/templates/simple.html @@ -0,0 +1,22 @@ + + + + + +Private.coffee + + +
+

Welcome to Private.coffee

+

Thanks for using our Element instance. Private.coffee is a collection of services that respect your privacy, here are some others:

+
+

For hosting inquiries for privacy-related, social, or wholesome projects, get in touch!

+
+ + diff --git a/terms.html b/templates/terms.html similarity index 95% rename from terms.html rename to templates/terms.html index 3a98024..7feb501 100644 --- a/terms.html +++ b/templates/terms.html @@ -8,12 +8,12 @@ Private.coffee - - - - - - + + + + + + @@ -21,7 +21,7 @@ Private.coffee logo Private.coffee