diff options
| author | Emil Williams | 2025-07-06 18:36:26 +0000 |
|---|---|---|
| committer | Emil Williams | 2025-07-06 18:36:26 +0000 |
| commit | a9c95145e8b3d9a46a4597e4c4c5d4ac77ad18db (patch) | |
| tree | f2854e0b06f1222bd88c5268f2849b01abc52b69 | |
| parent | be96ef3c69aa497dd0a663de6cc3318fa7d77893 (diff) | |
| download | emil-up.chud.cyou-a9c95145e8b3d9a46a4597e4c4c5d4ac77ad18db.tar.xz emil-up.chud.cyou-a9c95145e8b3d9a46a4597e4c4c5d4ac77ad18db.tar.zst | |
nginx, in deployment
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | README.md | 64 | ||||
| -rw-r--r-- | TODO.md | 4 | ||||
| -rw-r--r-- | crontab | 1 | ||||
| -rw-r--r-- | example_frontend.html | 12 | ||||
| -rw-r--r-- | example_frontend.lighttpd.conf | 6 | ||||
| -rw-r--r-- | index.html | 43 | ||||
| -rw-r--r-- | lighttpd.conf | 28 | ||||
| -rw-r--r-- | out/.gitkeep | 0 | ||||
| -rwxr-xr-x | test/evil.tcl | 6 | ||||
| -rw-r--r-- | test/test.png | bin | 310382 -> 0 bytes | |||
| -rw-r--r-- | test/test.txt | 1 | ||||
| -rwxr-xr-x | test/upload-test.sh | 2 | ||||
| -rw-r--r-- | up.chud.cyou | 45 | ||||
| -rwxr-xr-x | upchud.tcl | 8 |
15 files changed, 102 insertions, 127 deletions
diff --git a/Makefile b/Makefile deleted file mode 100644 index b91412e..0000000 --- a/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -serve: - lighttpd -D -f lighttpd.conf - -front: - lighttpd -D -f example_frontend.lighttpd.conf - -clean: - -${RM} -frfr out/ - -${RM} errors.log @@ -1,61 +1,11 @@ -# Upchud -> File upload service; without stage 4 retardation. +Sane deployment of [anon's upchud](https://git.xolatile.top/anon/upchud) for nginx. -### Shilling points 🚀: -* Minimal dependencies -* CLI friendly -* Web friendly -* Optional random upload name mangling -* Easy to configure -* Small codebase -* Traubisoda +Things that need to change for deployment are the up.chud.cyou nginx file and crontab. -### Depedencies -* Lighttpd -* Tcl (base installation) - -### Files -| File | Description | -| :------------ | :---------- | -| lighttpd.conf | Master lighttpd configuration. Tip: set max upload size here. | -| upchud.tcl | Master CGI Tcl script. Tip: simply forked by lighttpd; set finer configurations here. | -| Makefile | Short-hands for common operations. | -| test/* | Scripts and files used during development. | -| example\_frontend.html | Simple web front-end for the service. | -| example\_frontend.lighttpd.conf | Serves the example front-end. Tip: you could merge this with the master configuration if you wanted one service. | - -### Usage -Lets get hello-world out-of the way: -```sh -$ make serve & -[1] 15225 -lighttpd -D -f lighttpd.conf -$ curl http://localhost:8080 --upload-file test/test.txt -http://localhost:8080/out//n6cru4.txt -$ curl http://localhost:8080/out//n6cru4.txt -Hello World -``` - -Alternatively I could run. -```sh -$ make serve & -[1] 23895 -lighttpd -D -f lighttpd.conf -$ make front & -[2] 24105 -lighttpd -D -f example_frontend.lighttpd.conf +The nginx & crontab files expect: +```tcl +set outdir "out/" +set keep_outdir 0 ``` -And I could use the web page (localhost:8081 by default) to perform the same task. - -The example frontend is perfectly functional, but is meant to be modified. -Alternatively, you could copy and embed it anywhere else on your site at large. - -To learn more about configuration, read the top of `upchud.tcl` and checkout `lighttpd.conf` -### Why? -Because every implementation of this extremely simple thing is flawed. -Common faults I witnessed are: -* CLI is second class with sloppy wrapper scripts and or HTML responses -* No web support, preventing phoneposting -* Horrifically convoluted configuration due to poor isolation of responsibilities -* 6 gorillion dependencies +keep_outdir is a patched in feature. diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 9ae4aff..0000000 --- a/TODO.md +++ /dev/null @@ -1,4 +0,0 @@ -* include some tmp file cleaner scripts or atleast leave recommendations -* by spoofing the request, it might be currently possible to upload files -to a parent dictionary; this should be tested and fixed, but should be fine -as long as the person running the service doesnt run it as root @@ -0,0 +1 @@ +@monthly find /var/www/up.chud.cyou/out/ -type f -mtime +28 -exec rm {} \; diff --git a/example_frontend.html b/example_frontend.html deleted file mode 100644 index 137594e..0000000 --- a/example_frontend.html +++ /dev/null @@ -1,12 +0,0 @@ -<div style="width: 400px;"> - <form action="http://localhost:8080" method="post" enctype="multipart/form-data"> - <fieldset> - <legend>Upload a file</legend> - <label> - Select file: - <input type="file" name="file" required> - </label> - <button type="submit">Upload</button> - </fieldset> - </form> -</div> diff --git a/example_frontend.lighttpd.conf b/example_frontend.lighttpd.conf deleted file mode 100644 index cdca761..0000000 --- a/example_frontend.lighttpd.conf +++ /dev/null @@ -1,6 +0,0 @@ -# @BAKE lighttpd -D -f $@ -server.document-root = var.CWD -server.port = "8081" - -server.modules += ( "mod_rewrite" ) -url.rewrite-once = ( ".*" => "/example_frontend.html" ) diff --git a/index.html b/index.html new file mode 100644 index 0000000..b2279ab --- /dev/null +++ b/index.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html prefix="og: http://ogp.me/ns#" lang="en"> + <head> + <link rel="canonical"> + <link rel="icon" type="image/png" sizes="32x32" href="/chud/img/favicon.png"> + <link rel="stylesheet" type="text/css" href="https://xolatile.top/style.css"> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=0.5"> + <title id="title">up.chud.cyou</title> + </head> + <body> + <div style="width: 50em;"> + <form action="https://up.chud.cyou/upchud.tcl" method="post" enctype="multipart/form-data"> + <fieldset> + <legend>Upload a file</legend> + <label> + Select file: + <input type="file" name="file" required> + </label> + <button type="submit">Upload</button> + </fieldset> + </form> + <p>You may upload files using the above form or the following command:</p> + <pre> + curl --upload-file 'file' https://up.chud.cyou/ + </pre> + <p> + Files are wiped monthly and may not be larger than 100 mebibytes. + </p> + <p> + Upchud is a FOSS file uploader service, originally developed for + <a href="https://up.chud.cyou/">up.chud.cyou</a> + </p> + <p> + Original source: + <a href="https://git.xolatile.top/anon/upchud">git.xolatile.top/anon/upchud</a> + <br /> + This deployment's source: + <a href="https://git.xolatile.top/emil/up.chud.cyou">git.xolatile.top/emil/up.chud.cyou</a> + </p> + </div> + </body> +</html> diff --git a/lighttpd.conf b/lighttpd.conf deleted file mode 100644 index 921467d..0000000 --- a/lighttpd.conf +++ /dev/null @@ -1,28 +0,0 @@ -# @BAKE lighttpd -D -f $@ -server.document-root = var.CWD -server.port = "8080" - -server.modules += ( "mod_rewrite" ) -url.rewrite-once = ( - "^/out/.*" => "$0", - ".*" => "/upchud.tcl" -) - -# This limits the maximum upload size (in kbytes). -server.max-request-size = 204800 # 200 MiB - -# This makes sure people cant inject Tcl scripts -server.modules += ( "mod_cgi" ) -$HTTP["url"] == "/upchud.tcl" { - cgi.assign = ( ".tcl" => "" ) -} - - -debug.log-request-header = 1 -debug.log-file-not-found = 1 -debug.log-condition-handling = 1 -debug.log-request-handling = 1 -debug.log-state-handling = 1 -debug.log-response-header = 1 - -server.errorlog = "errors.log" diff --git a/out/.gitkeep b/out/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/out/.gitkeep diff --git a/test/evil.tcl b/test/evil.tcl deleted file mode 100755 index 9060f7c..0000000 --- a/test/evil.tcl +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/tclsh - -set f [open "evil.txt" "w"] -close $f - -puts stderr "evil.txt created" diff --git a/test/test.png b/test/test.png Binary files differdeleted file mode 100644 index df5d578..0000000 --- a/test/test.png +++ /dev/null diff --git a/test/test.txt b/test/test.txt deleted file mode 100644 index 557db03..0000000 --- a/test/test.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World diff --git a/test/upload-test.sh b/test/upload-test.sh deleted file mode 100755 index 936e013..0000000 --- a/test/upload-test.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -curl --upload-file example.png http://localhost:8080/ diff --git a/up.chud.cyou b/up.chud.cyou new file mode 100644 index 0000000..6d8232b --- /dev/null +++ b/up.chud.cyou @@ -0,0 +1,45 @@ +map $http_user_agent $cli { + default 0; + ~*wget 1; + ~*curl 1; +} + +server { + server_name up.chud.cyou; + root /var/www/up.chud.cyou; + + listen 80; + listen [::]:80; + listen 443 ssl http2; + listen [::]:443 ssl http2; + + ssl_certificate ...; + ssl_certificate_key ...; + + error_page 404 https://up.chud.cyou/chud/404; + + location ~ /\.git { + deny all; + } + + client_max_body_size 100m; + + location ^~ /out/ { + autoindex on; + } + + location = /upchud.tcl { + # include authorized; + # deny all; + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param SCRIPT_FILENAME /var/www/up.chud.cyou/upchud.tcl; + } + + if ($cli) { + rewrite ^/.*$ /upchud.tcl last; + } + rewrite ^/$ /index.html last; + rewrite ^/upchud.tcl$ /upchud.tcl last; + rewrite ^/(.+)$ /out/$1; +} @@ -5,6 +5,7 @@ # --- # Directory to place the files to. set outdir "out/" +set keep_outdir 0 # The lenght of the random name every file is assigned. # Setting it to 0 disables random name mangling. set mangle_lenght 6 @@ -186,8 +187,11 @@ if { ![file isdirectory $outdir] } { file mkdir $outdir } set output_name [get_out_name $original_name] eval $write_file $output_name -send_success $output_name - +if { $keep_outdir } { + send_success $output_name +} else { + send_success [file tail $output_name] +} ## Notes # This is a very useful debug snippet: # |
