From b16de242e0f1560c42d14b71dccc0858d70643ec Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 10 Aug 2022 14:40:50 +0200 Subject: l paste: add /form endpoint for form posts --- lass/2configs/paste.nix | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lass/2configs/paste.nix') diff --git a/lass/2configs/paste.nix b/lass/2configs/paste.nix index affc3530..101899e9 100644 --- a/lass/2configs/paste.nix +++ b/lass/2configs/paste.nix @@ -61,6 +61,11 @@ with import ; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:${toString config.krebs.htgen.paste.port}; ''; + locations."/form".extraConfig = '' + client_max_body_size 4G; + proxy_set_header Host $host; + proxy_pass http://127.0.0.1:${toString config.krebs.htgen.paste-form.port}; + ''; locations."/image".extraConfig = '' proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -86,6 +91,33 @@ with import ; ". ${pkgs.htgen}/examples/paste" ]; }; + + krebs.htgen.paste-form = { + port = 7770; + script = /* sh */ '' + export PATH=${makeBinPath [ + pkgs.curl + pkgs.gnused + ]}:$PATH + (. ${pkgs.writeScript "paste-form" '' + case "$Method" in + 'POST') + ref=$(head -c $req_content_length | sed '0,/^\r$/d;$d' | curl -fSs --data-binary @- https://p.krebsco.de | sed '1d;s/^http:/https:/') + + printf 'HTTP/1.1 200 OK\r\n' + printf 'Content-Type: text/plain; charset=UTF-8\r\n' + printf 'Server: %s\r\n' "$Server" + printf 'Connection: close\r\n' + printf 'Content-Length: %d\r\n' $(expr ''${#ref} + 1) + printf '\r\n' + printf '%s\n' "$ref" + + exit + ;; + esac + ''}) + ''; + }; krebs.htgen.imgur = { port = 7771; script = /* sh */ '' -- cgit v1.2.3 From 7ce87f5fdb602de7638b2df237e891e6038907ac Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 10 Aug 2022 14:41:04 +0200 Subject: l paste: gc after 30 days --- lass/2configs/paste.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lass/2configs/paste.nix') diff --git a/lass/2configs/paste.nix b/lass/2configs/paste.nix index 101899e9..cfd7f557 100644 --- a/lass/2configs/paste.nix +++ b/lass/2configs/paste.nix @@ -92,6 +92,16 @@ with import ; ]; }; + systemd.services.paste-gc = { + startAt = "daily"; + serviceConfig = { + ExecStart = '' + ${pkgs.findutils}/bin/find /var/lib/htgen-paste/items -type f -mtime '+30' -exec rm {} \; + ''; + User = "htgen-paste"; + }; + }; + krebs.htgen.paste-form = { port = 7770; script = /* sh */ '' -- cgit v1.2.3