From b6c65ae09c853471d29d46ba6576599e57046590 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Wed, 7 Oct 2009 07:02:41 +0000 Subject: [PATCH] upload form --- index.cgi | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/index.cgi b/index.cgi index 0c5eeba..1c26eff 100755 --- a/index.cgi +++ b/index.cgi @@ -35,14 +35,8 @@ function cut_file { } # Print out a generic header -function start_html { - echo "Content-Type: text/html; charset=UTF-8" - echo -} - -# Print out a generic header -function start_text { - echo "Content-Type: text/plain; charset=UTF-8" +function header { + echo "Content-Type: $1; charset=UTF-8" echo } @@ -54,8 +48,8 @@ function do_print { input="db/$1" trim='1d' # sed command to remove cruft else - echo "Status: 404" - start_text + echo "Status: 404 Not Found" + header text/plain echo "File '$1' not found" return fi @@ -75,16 +69,17 @@ function do_print { HOME=/home/andy \ screen -D -m ex -u vimrc \ '+$d|'$trim \ + '+%s/ //g' \ '+TOhtml' \ "+sav! $output" \ '+qall!' \ "$tmp" - start_html + header text/html cat "$output" rm "$tmp" "$output" else - start_text + header text/plain sed "$trim" "$input" fi } @@ -93,10 +88,12 @@ function do_print { # Upload handler function do_upload { output="$(mktemp db/XXXXX)" - uri="$SCRIPT_URI$(basename "$output")" + uri="$SCRIPT_URI$(basename "$output")${QUERY_STRING:+"?"}" (get_modeline; cut_file "$1") > "$output" - start_text - echo "$uri${QUERY_STRING:+"?"}" + echo "Status: 302 Found" + echo "Location: $uri" + header text/plain + echo "$uri" } # Default index page @@ -107,7 +104,7 @@ filetypes=$( ) uploads=$(ls -t db | head -n 5 | sed "s!^!$SCRIPT_URI!") -start_html +header text/html cat - < @@ -121,6 +118,21 @@ cat - < +
+ +
+ + +
+
+

NAME

vpaste: Vim enabled pastebin

@@ -137,7 +149,7 @@ cat - <OPTIONS
ft, filetype={filetype}
-
A filetype to use for highlighting, see FILETYPES
+
A filetype to use for highlighting, see above menu for supported types
bg, background={light|dark}
Background color to use for the page
et, expandtab
@@ -161,9 +173,6 @@ cat - <$(for uri in ${uploads[@]}; do echo "
  • $uri" done) - -

    FILETYPES

    -
    $filetypes
    EOF @@ -171,12 +180,11 @@ EOF # Main pathinfo="${SCRIPT_URL/*vpaste\/}" -boundary="${CONTENT_TYPE/*boundary\=/}" if [ "$pathinfo" ]; then do_print "$pathinfo" elif [ "$CONTENT_TYPE" ]; then - do_upload "$boundary" + do_upload ${CONTENT_TYPE/*boundary\=/} else do_help fi -- 2.43.2