2021-12-15 00:10:06 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
let
|
|
|
|
|
tarotPort = 7407;
|
|
|
|
|
tarotFiles = pkgs.fetchzip {
|
|
|
|
|
url = "https://c.krebsco.de/tarot.zip";
|
|
|
|
|
sha256 = "0jl5vdwlj17pqp94yj02xgsb1gyvs9i08m83kac0jdnhfjl2f75a";
|
|
|
|
|
stripRoot = false;
|
|
|
|
|
};
|
2021-12-15 15:01:19 +01:00
|
|
|
tarotKey = builtins.fetchurl {
|
|
|
|
|
url = "http://c.krebsco.de/tarot.pdf";
|
2021-12-16 00:19:28 +01:00
|
|
|
sha256 = "1n2m53kjg2vj9dbr70b9jrsbqwdfrcb48l4wswn21549fi24g6dx";
|
2021-12-15 15:01:19 +01:00
|
|
|
};
|
2021-12-15 00:10:06 +01:00
|
|
|
in
|
|
|
|
|
{
|
2022-02-08 00:47:10 +01:00
|
|
|
imports = [ <stockholm/krebs/3modules/htgen.nix> ];
|
|
|
|
|
|
2021-12-15 00:10:06 +01:00
|
|
|
krebs.htgen.tarot = {
|
|
|
|
|
port = tarotPort;
|
|
|
|
|
user.name = "radio";
|
|
|
|
|
script = ''. ${pkgs.writers.writeDash "tarot" ''
|
|
|
|
|
case "$Method $Request_URI" in
|
|
|
|
|
"GET /")
|
2021-12-15 15:00:46 +01:00
|
|
|
if item=$(${pkgs.findutils}/bin/find ${toString tarotFiles} -type f | ${pkgs.coreutils}/bin/shuf -n1); then
|
|
|
|
|
card=$(mktemp --tmpdir tarot.XXX)
|
|
|
|
|
trap 'rm $card' EXIT
|
|
|
|
|
reverse=$(${pkgs.coreutils}/bin/shuf -i0-1 -n1)
|
|
|
|
|
if [ "$reverse" -eq 1 ]; then
|
|
|
|
|
${pkgs.imagemagick}/bin/convert -rotate 180 "$item" "$card"
|
|
|
|
|
else
|
|
|
|
|
${pkgs.coreutils}/bin/cp "$item" "$card"
|
|
|
|
|
fi
|
2021-12-15 00:10:06 +01:00
|
|
|
printf 'HTTP/1.1 200 OK\r\n'
|
2021-12-15 15:00:46 +01:00
|
|
|
printf 'Content-Type: %s\r\n' "$(${pkgs.file}/bin/file -ib "$card")"
|
2021-12-15 00:10:06 +01:00
|
|
|
printf 'Server: %s\r\n' "$Server"
|
|
|
|
|
printf 'Connection: close\r\n'
|
2021-12-15 15:00:46 +01:00
|
|
|
printf 'Content-Length: %d\r\n' $(${pkgs.coreutils}/bin/wc -c < "$card")
|
2021-12-15 00:10:06 +01:00
|
|
|
printf '\r\n'
|
2021-12-15 15:00:46 +01:00
|
|
|
cat "$card"
|
2021-12-15 00:10:06 +01:00
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
''}'';
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-15 12:37:41 +01:00
|
|
|
services.nginx.virtualHosts."tarot.kmein.de" = {
|
|
|
|
|
enableACME = true;
|
|
|
|
|
forceSSL = true;
|
2021-12-15 15:01:19 +01:00
|
|
|
locations = {
|
|
|
|
|
"/".proxyPass = "http://127.0.0.1:${toString tarotPort}";
|
|
|
|
|
"/files/" = {
|
|
|
|
|
root = pkgs.linkFarm "tarot" [
|
|
|
|
|
{ name = "files/key.pdf"; path = tarotKey; }
|
|
|
|
|
{ name = "files/cards"; path = tarotFiles; }
|
|
|
|
|
];
|
|
|
|
|
extraConfig = ''
|
|
|
|
|
autoindex on;
|
|
|
|
|
charset UTF-8;
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
2021-12-15 00:10:06 +01:00
|
|
|
};
|
|
|
|
|
}
|