From: Emil Williams Date: Sun, 6 Jul 2025 18:36:26 +0000 (+0000) Subject: nginx, in deployment X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;h=a9c95145e8b3d9a46a4597e4c4c5d4ac77ad18db;p=emil-up.chud.cyou.git nginx, in deployment --- 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 diff --git a/README.md b/README.md index 073732e..f30fac6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/crontab b/crontab new file mode 100644 index 0000000..7666084 --- /dev/null +++ b/crontab @@ -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 @@ -
-
-
- Upload a file - - -
-
-
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 @@ + + + + + + + + + up.chud.cyou + + +
+
+
+ Upload a file + + +
+
+

You may upload files using the above form or the following command:

+
+        curl --upload-file 'file' https://up.chud.cyou/
+      
+

+ Files are wiped monthly and may not be larger than 100 mebibytes. +

+

+ Upchud is a FOSS file uploader service, originally developed for + up.chud.cyou +

+

+ Original source: + git.xolatile.top/anon/upchud +
+ This deployment's source: + git.xolatile.top/emil/up.chud.cyou +

+
+ + 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 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 deleted file mode 100644 index df5d578..0000000 Binary files a/test/test.png and /dev/null differ 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; +} diff --git a/upchud.tcl b/upchud.tcl index 6e39fd6..823ca09 100755 --- a/upchud.tcl +++ b/upchud.tcl @@ -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: #