This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

paste: add upload page, fix trailing CRLF in form uploads

+31 -1
+31 -1
2configs/paste.nix
··· 6 6 ... 7 7 }: 8 8 9 + let 10 + uploadPage = pkgs.writeText "paste-upload.html" '' 11 + <!doctype html> 12 + <title>p.krebsco.de</title> 13 + <form action="/form" method="post" enctype="multipart/form-data"> 14 + <input type="file" name="file" required> 15 + <button>upload</button> 16 + </form> 17 + <p>or with curl:</p> 18 + <pre> 19 + curl --data-binary @file https://p.krebsco.de 20 + some-command | curl --data-binary @- https://p.krebsco.de 21 + </pre> 22 + ''; 23 + in 9 24 { 10 25 imports = [ 11 26 { ··· 77 92 if ($request_method = 'OPTIONS') { 78 93 return 204; 79 94 } 95 + if ($request_method ~ ^(GET|HEAD)$) { 96 + rewrite ^/$ /_upload last; 97 + } 80 98 client_max_body_size 4G; 81 99 proxy_set_header Host $host; 82 100 proxy_set_header X-Forwarded-Proto $scheme; 83 101 proxy_pass http://127.0.0.1:${toString config.krebs.htgen.paste.port}; 102 + ''; 103 + locations."= /_upload".extraConfig = '' 104 + internal; 105 + default_type text/html; 106 + alias ${uploadPage}; 84 107 ''; 85 108 locations."/form".extraConfig = '' 86 109 client_max_body_size 4G; ··· 133 156 (. ${pkgs.writeScript "paste-form" '' 134 157 case "$Method" in 135 158 'POST') 136 - ref=$(head -c $req_content_length | sed '0,/^\r$/d;$d' | curl -fSs --data-binary @- https://p.krebsco.de | sed '1d;s/^http:/https:/') 159 + # multipart body: part headers up to the first empty line, then the 160 + # file, then "\r\n--$boundary--\r\n" (length of boundary + 8 bytes) 161 + boundary=''${req_content_type-} 162 + boundary=''${boundary#*boundary=} 163 + boundary=''${boundary%%;*} 164 + boundary=''${boundary#\"} 165 + boundary=''${boundary%\"} 166 + 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:/') 137 167 138 168 printf 'HTTP/1.1 200 OK\r\n' 139 169 printf 'Content-Type: text/plain; charset=UTF-8\r\n'