This repository has no description
5.7 kB
189 lines
1{
2 config,
3 lib,
4 pkgs,
5 self,
6 ...
7}:
8
9let
10 stockholmPkgs = self.inputs.stockholm.packages.${pkgs.stdenv.hostPlatform.system};
11
12 uploadPage = pkgs.writeText "paste-upload.html" ''
13 <!doctype html>
14 <title>p.krebsco.de</title>
15 <form action="/form" method="post" enctype="multipart/form-data">
16 <input type="file" name="file" required>
17 <button>upload</button>
18 </form>
19 <p>or with curl:</p>
20 <pre>
21 curl --data-binary @file https://p.krebsco.de
22 some-command | curl --data-binary @- https://p.krebsco.de
23 </pre>
24 '';
25in
26{
27
28 services.nginx.virtualHosts.cyberlocker = {
29 serverAliases = [ "c.r" ];
30 locations."/".extraConfig = ''
31 client_max_body_size 4G;
32 proxy_set_header Host $host;
33 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.cyberlocker.port};
34 '';
35 extraConfig = ''
36 add_header Access-Control-Allow-Origin * always;
37 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
38 '';
39 };
40 services.nginx.virtualHosts.paste = {
41 serverAliases = [ "p.r" ];
42 locations."/".extraConfig = ''
43 client_max_body_size 4G;
44 proxy_set_header Host $host;
45 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.paste.port};
46 '';
47 locations."/image".extraConfig = # nginx
48 ''
49 client_max_body_size 40M;
50
51 proxy_set_header Host $host;
52 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
53 proxy_set_header X-Forwarded-Proto $scheme;
54
55 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.imgur.port};
56 proxy_pass_header Server;
57 '';
58 extraConfig = ''
59 add_header 'Access-Control-Allow-Origin' '*';
60 add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
61 '';
62 };
63 services.nginx.virtualHosts."c.krebsco.de" = {
64 enableACME = true;
65 addSSL = true;
66 serverAliases = [ "c.krebsco.de" ];
67 locations."/".extraConfig = ''
68 if ($request_method != GET) {
69 return 403;
70 }
71 proxy_set_header Host $host;
72 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.cyberlocker.port};
73 '';
74 extraConfig = ''
75 add_header Access-Control-Allow-Origin * always;
76 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
77 '';
78 };
79 services.nginx.virtualHosts."p.krebsco.de" = {
80 enableACME = true;
81 addSSL = true;
82 serverAliases = [ "p.krebsco.de" ];
83 locations."/".extraConfig = ''
84 if ($request_method = 'OPTIONS') {
85 return 204;
86 }
87 if ($request_method ~ ^(GET|HEAD)$) {
88 rewrite ^/$ /_upload last;
89 }
90 client_max_body_size 4G;
91 proxy_set_header Host $host;
92 proxy_set_header X-Forwarded-Proto $scheme;
93 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.paste.port};
94 '';
95 locations."= /_upload".extraConfig = ''
96 internal;
97 default_type text/html;
98 alias ${uploadPage};
99 '';
100 locations."/form".extraConfig = ''
101 client_max_body_size 4G;
102 proxy_set_header Host $host;
103 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.paste-form.port};
104 '';
105 locations."/image".extraConfig = ''
106 proxy_set_header Host $host;
107 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
108 proxy_set_header X-Forwarded-Proto $scheme;
109
110 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.imgur.port};
111 proxy_pass_header Server;
112 '';
113 extraConfig = ''
114 add_header Access-Control-Allow-Headers Authorization always;
115 add_header Access-Control-Allow-Origin * always;
116 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
117 '';
118 };
119
120 krebs.htgen.paste = {
121 port = 9081;
122 script = # sh
123 ''
124 (. ${stockholmPkgs.htgen-paste}/bin/htgen-paste)
125 '';
126 };
127
128 systemd.services.paste-gc = {
129 startAt = "daily";
130 serviceConfig = {
131 ExecStart = ''
132 ${pkgs.findutils}/bin/find /var/lib/htgen-paste/items -type f -mtime '+30' -exec rm {} \;
133 '';
134 User = "htgen-paste";
135 };
136 };
137
138 krebs.htgen.paste-form = {
139 port = 7770;
140 script = # sh
141 ''
142 export PATH=${
143 lib.makeBinPath [
144 pkgs.curl
145 pkgs.gnused
146 ]
147 }:$PATH
148 (. ${pkgs.writeScript "paste-form" ''
149 case "$Method" in
150 'POST')
151 # multipart body: part headers up to the first empty line, then the
152 # file, then "\r\n--$boundary--\r\n" (length of boundary + 8 bytes)
153 boundary=''${req_content_type-}
154 boundary=''${boundary#*boundary=}
155 boundary=''${boundary%%;*}
156 boundary=''${boundary#\"}
157 boundary=''${boundary%\"}
158 ref=$(head -c $req_content_length | sed '0,/^\r$/d' | head -c -$(expr ''${#boundary} + 8) | curl -fSs --data-binary @- https://p.krebsco.de | sed '1d;s/^http:/https:/')
159
160 printf 'HTTP/1.1 200 OK\r\n'
161 printf 'Content-Type: text/plain; charset=UTF-8\r\n'
162 printf 'Server: %s\r\n' "$Server"
163 printf 'Connection: close\r\n'
164 printf 'Content-Length: %d\r\n' $(expr ''${#ref} + 1)
165 printf '\r\n'
166 printf '%s\n' "$ref"
167
168 exit
169 ;;
170 esac
171 ''})
172 '';
173 };
174 krebs.htgen.imgur = {
175 port = 7771;
176 script = # sh
177 ''
178 (. ${stockholmPkgs.htgen-imgur}/bin/htgen-imgur)
179 '';
180 };
181 krebs.htgen.cyberlocker = {
182 port = 7772;
183 script = # sh
184 ''
185 (. ${stockholmPkgs.htgen-cyberlocker}/bin/htgen-cyberlocker)
186 '';
187 };
188 networking.firewall.interfaces.retiolum.allowedTCPPorts = [ 80 ];
189}