]> git.xolatile.top Git - emil-up.chud.cyou.git/commitdiff
nginx, in deployment
authorEmil Williams <emilemilemil@cock.li>
Sun, 6 Jul 2025 18:36:26 +0000 (18:36 +0000)
committerEmil Williams <emilemilemil@cock.li>
Sun, 6 Jul 2025 18:36:26 +0000 (18:36 +0000)
15 files changed:
Makefile [deleted file]
README.md
TODO.md [deleted file]
crontab [new file with mode: 0644]
example_frontend.html [deleted file]
example_frontend.lighttpd.conf [deleted file]
index.html [new file with mode: 0644]
lighttpd.conf [deleted file]
out/.gitkeep [new file with mode: 0644]
test/evil.tcl [deleted file]
test/test.png [deleted file]
test/test.txt [deleted file]
test/upload-test.sh [deleted file]
up.chud.cyou [new file with mode: 0644]
upchud.tcl

diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
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
index 073732ea559d2c03e181f9761392a35f2c12a85d..f30fac67cf29d4270c14650cf5e8db0ca7bcda37 100644 (file)
--- 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 (file)
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 (file)
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 (file)
index 137594e..0000000
+++ /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 (file)
index cdca761..0000000
+++ /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 (file)
index 0000000..b2279ab
--- /dev/null
@@ -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 (file)
index 921467d..0000000
+++ /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 (file)
index 0000000..e69de29
diff --git a/test/evil.tcl b/test/evil.tcl
deleted file mode 100755 (executable)
index 9060f7c..0000000
+++ /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 (file)
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 (file)
index 557db03..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Hello World
diff --git a/test/upload-test.sh b/test/upload-test.sh
deleted file mode 100755 (executable)
index 936e013..0000000
+++ /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 (file)
index 0000000..6d8232b
--- /dev/null
@@ -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;
+}
index 6e39fd685e0c6ec0f66d0366549f4dcdafb4dcef..823ca0989b9398a5eabfc88930d064be288ff84d 100755 (executable)
@@ -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:
 #