From b31fd3e7c4c2c4dcaf8e70724f648df025524556 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 18 Dec 2024 15:18:46 +0100 Subject: [PATCH 01/16] [postgres][miniflux] Permit local connections. --- postgres/pg_hba.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/postgres/pg_hba.conf b/postgres/pg_hba.conf index 9feaea8..c2b6b1e 100755 --- a/postgres/pg_hba.conf +++ b/postgres/pg_hba.conf @@ -95,6 +95,8 @@ local mail_db dovecot trust host mail_db dovecot ::1/128 trust host mail_db dkim ::1/128 trust host analytics_db rsyslog ::1/128 trust +host rss_db miniflux ::1/128 trust +local rss_db miniflux trust local analytics_db analytics_reader trust local gym_db gym_tracker trust local matrix_db synapse_user trust -- 2.39.5 From 8594e9d2f72e24eb3eb95088d908c66348a6eeb5 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 18 Dec 2024 15:33:05 +0100 Subject: [PATCH 02/16] [miniflux] Customize configuration and add license. --- miniflux/miniflux.conf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miniflux/miniflux.conf b/miniflux/miniflux.conf index ec6028a..ab42455 100644 --- a/miniflux/miniflux.conf +++ b/miniflux/miniflux.conf @@ -1,3 +1,7 @@ -# See https://miniflux.app/docs/configuration.html +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. +DATABASE_URL=user=miniflux dbname=${RSS_DB} +LOG_LEVEL=error +PORT=4080 RUN_MIGRATIONS=1 -- 2.39.5 From 87ff13f6567b8258c75549c19dbda2b7b397a3c2 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 18 Dec 2024 15:42:38 +0100 Subject: [PATCH 03/16] [miniflux] Configure nginx. --- miniflux/rss.conf | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 miniflux/rss.conf diff --git a/miniflux/rss.conf b/miniflux/rss.conf new file mode 100644 index 0000000..dbe0a09 --- /dev/null +++ b/miniflux/rss.conf @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. + +server { + server_name rss.${private_domain}; + + listen [::]:443 ssl http2; + listen 443 ssl http2; + + ssl_certificate ${private_ssl_cert_dir}/fullchain.pem; + ssl_certificate_key ${private_ssl_cert_dir}/privkey.pem; + + ssl_client_certificate ${ca_dir}/ca.pem; + ssl_verify_client on; + + root ${prod_dir}/${rss}; + + location / { + proxy_pass http://127.0.0.1:4080; + proxy_redirect off; + proxy_set_header Host ${dollar}host; + proxy_set_header X-Real-IP ${dollar}remote_addr; + proxy_set_header X-Forwarded-For ${dollar}proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto ${dollar}scheme; + } +} + +server { + server_name rss.${private_domain}; + + listen [::]:80; + listen 80; + + if (${dollar}host = rss.${private_domain}) { + return 301 https://${dollar}host${dollar}request_uri; + } + + return 404; +} -- 2.39.5 From d73abfead2923dd1ccfca7f2982f375e9a9983c7 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 18 Dec 2024 16:34:10 +0100 Subject: [PATCH 04/16] [miniflux] Create database. --- databases/rss/miniflux_db_create.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 databases/rss/miniflux_db_create.sql diff --git a/databases/rss/miniflux_db_create.sql b/databases/rss/miniflux_db_create.sql new file mode 100644 index 0000000..633bd96 --- /dev/null +++ b/databases/rss/miniflux_db_create.sql @@ -0,0 +1,20 @@ +-- Copyright (c) 2024 Jakub Czajka +-- License: 0BSD. + +DO $$ +BEGIN + IF NOT EXISTS (SELECT * FROM pg_user WHERE usename = 'miniflux') + THEN + CREATE USER miniflux; + END IF; +END$$; + +CREATE DATABASE rss_db + ENCODING 'UTF8' + LC_COLLATE='C' + LC_CTYPE='C' + TEMPLATE=template0 + OWNER miniflux; + +-- See https://miniflux.app/docs/database.html. +EXECUTE FORMAT('CREATE EXTENSION IF NOT EXISTS HSTORE') -- 2.39.5 From 9a7656669db43e5f5f260b4b3b2f5f8ef31f3d83 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 18 Dec 2024 16:58:41 +0100 Subject: [PATCH 05/16] [miniflux] Download entries with ydlpd. --- miniflux/download.sh | 27 +++++++++++++++++++++++++++ miniflux/rss.conf | 20 ++++++++++++++++++++ miniflux/ydlpd.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 miniflux/download.sh create mode 100755 miniflux/ydlpd.sh diff --git a/miniflux/download.sh b/miniflux/download.sh new file mode 100755 index 0000000..88d62a5 --- /dev/null +++ b/miniflux/download.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. +# +# Clicking on the "Download" button on entry's page sends a POST request to +# /entry/download/. This script resolves the to an +# and redirects the client to /ydlpd?url= with HTTP 303 See Other [1]. This +# causes the client to automatically send a GET request to that address. +# +# [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303 + +. /etc/environment + +VIDEO=$(/usr/bin/psql --user=miniflux \ + --dbname=${RSS_DB} \ + --tuples-only \ + --no-align \ + --command=" +SELECT url +FROM entries +WHERE id = ${ENTRY_ID}") + +echo "HTTP/1.1 303 See Other" +echo "Location: /ydlpd?url=${VIDEO}" +echo "Content-Type: text/html; charset=UTF-8" +echo "Content-Length: 0" +echo "" diff --git a/miniflux/rss.conf b/miniflux/rss.conf index dbe0a09..9cc60e6 100644 --- a/miniflux/rss.conf +++ b/miniflux/rss.conf @@ -15,6 +15,26 @@ server { root ${prod_dir}/${rss}; + location ~ ^/entry/download/(\d+)$ { + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + + fastcgi_read_timeout 30; + + fastcgi_param ENTRY_ID ${dollar}1; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/download.sh; + } + + location ~ ^/ydlpd(.*)$ { + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + + fastcgi_read_timeout 30; + + fastcgi_param URL ${dollar}arg_url; + fastcgi_param SCRIPT_FILENAME ${dollar}document_root/ydlpd.sh; + } + location / { proxy_pass http://127.0.0.1:4080; proxy_redirect off; diff --git a/miniflux/ydlpd.sh b/miniflux/ydlpd.sh new file mode 100755 index 0000000..3f3b3fa --- /dev/null +++ b/miniflux/ydlpd.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. +# +# If user downloads entry's page, miniflux embeds the HTML. The response needs to +# have the following format [1]: +# +# { +# "content": "", +# "reading_time": "" +# } +# +# Moreover, the HTML embeded in JSON needs to have '\n' instead of new lines. +# This script returns a HTML form to select the format for download and passes +# it alongside video's URL to ydlpd for download. +# +# [1] https://github.com/miniflux/v2/blob/main/internal/ui/static/js/app.js#L355 + +. /etc/environment + +PAGE=$(echo "\ +
+
+ +
+ + +
+
+
" | sed 's/^[ \t]*//g') + +echo "HTTP/1.1 200 OK" +echo "Content-type: text/json" +echo "" +echo -n "{\"content\": \"${PAGE}\"" | sed --null-data 's/\n/\\n/g' +echo -n ", \"reading_time\": \"1\"}" -- 2.39.5 From 14ba38185c092e59f08258a04136c3554ca99869 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Wed, 18 Dec 2024 17:02:55 +0100 Subject: [PATCH 06/16] [miniflux] Style ydlpd integration with CSS. --- miniflux/rss.conf | 4 ++++ miniflux/ydlpd.css | 24 ++++++++++++++++++++++++ miniflux/ydlpd.sh | 3 +++ 3 files changed, 31 insertions(+) create mode 100644 miniflux/ydlpd.css diff --git a/miniflux/rss.conf b/miniflux/rss.conf index 9cc60e6..76d7856 100644 --- a/miniflux/rss.conf +++ b/miniflux/rss.conf @@ -35,6 +35,10 @@ server { fastcgi_param SCRIPT_FILENAME ${dollar}document_root/ydlpd.sh; } + location = /ydlpd.css { + try_files /ydlpd.css =404; + } + location / { proxy_pass http://127.0.0.1:4080; proxy_redirect off; diff --git a/miniflux/ydlpd.css b/miniflux/ydlpd.css new file mode 100644 index 0000000..bd3baef --- /dev/null +++ b/miniflux/ydlpd.css @@ -0,0 +1,24 @@ +#ydlpd { + width: 100%; +} +#ydlpd fieldset { + background-color: #7fa99b; + border: solid; + display: flex; + flex-direction: column; + justify-content: space-evenly; + row-gap: 5px; + width: 100%; +} +#ydlpd input { + width: 100%; +} +#ydlpd select, button { + font-size: .7em; + height: 100%; + padding: 5px; +} +#ydlpd .container { + display: flex; + justify-content: space-evenly; +} diff --git a/miniflux/ydlpd.sh b/miniflux/ydlpd.sh index 3f3b3fa..48fbb69 100755 --- a/miniflux/ydlpd.sh +++ b/miniflux/ydlpd.sh @@ -18,7 +18,10 @@ . /etc/environment +# Miniflux page's configuration does not permit defining CSS in