summaryrefslogtreecommitdiff
path: root/release/src/router/busybox/networking/httpd_post_upload.txt
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-01-03 13:58:15 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2015-01-03 13:58:15 +0100
commit4aca87515a5083ae0e31ce3177189fd43b6d05ac (patch)
tree7b1d9a31393ca090757dc6f0d3859b4fcd93f271 /release/src/router/busybox/networking/httpd_post_upload.txt
parent008d0be72b2f160382c6e880765e96b64a050c65 (diff)
downloadtomato-4aca87515a5083ae0e31ce3177189fd43b6d05ac.tar.gz
tomato-4aca87515a5083ae0e31ce3177189fd43b6d05ac.tar.bz2
patch to Vanilla Tomato 1.28
Diffstat (limited to 'release/src/router/busybox/networking/httpd_post_upload.txt')
-rw-r--r--release/src/router/busybox/networking/httpd_post_upload.txt76
1 files changed, 76 insertions, 0 deletions
diff --git a/release/src/router/busybox/networking/httpd_post_upload.txt b/release/src/router/busybox/networking/httpd_post_upload.txt
new file mode 100644
index 00000000..a53b1146
--- /dev/null
+++ b/release/src/router/busybox/networking/httpd_post_upload.txt
@@ -0,0 +1,76 @@
+POST upload example:
+
+post_upload.htm
+===============
+<html>
+<body>
+<form action=/cgi-bin/post_upload.cgi method=post enctype=multipart/form-data>
+File to upload: <input type=file name=file1> <input type=submit>
+</form>
+
+
+post_upload.cgi
+===============
+#!/bin/sh
+
+# POST upload format:
+# -----------------------------29995809218093749221856446032^M
+# Content-Disposition: form-data; name="file1"; filename="..."^M
+# Content-Type: application/octet-stream^M
+# ^M <--------- headers end with empty line
+# file contents
+# file contents
+# file contents
+# ^M <--------- extra empty line
+# -----------------------------29995809218093749221856446032--^M
+
+# Beware: bashism $'\r' is used to handle ^M
+
+file=/tmp/$$-$RANDOM
+
+# CGI output must start with at least empty line (or headers)
+printf '\r\n'
+
+IFS=$'\r'
+read -r delim_line
+
+IFS=''
+delim_line="${delim_line}--"$'\r'
+
+while read -r line; do
+ test "$line" = '' && break
+ test "$line" = $'\r' && break
+done
+
+# This will not work well for binary files: bash 3.2 is upset
+# by reading NUL bytes and loses chunks of data.
+# If you are not bothered by having junk appended to the uploaded file,
+# consider using simple "cat >file" instead of the entire
+# fragment below.
+
+while read -r line; do
+
+ while test "$line" = $'\r'; do
+ read -r line
+ test "$line" = "$delim_line" && {
+ # Aha! Empty line + delimiter! All done
+ cat <<EOF
+<html>
+<body>
+File upload has been accepted
+EOF
+ exit 0
+ }
+ # Empty line + NOT delimiter. Save empty line,
+ # and go check next line
+ printf "%s\n" $'\r' -vC >&3
+ done
+ # Not empty line - just save
+ printf "%s\n" "$line" -vC >&3
+done 3>"$file"
+
+cat <<EOF
+<html>
+<body>
+File upload was not terminated with '$delim_line' - ??!
+EOF