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