3 # Copyright (C) 2009 Andy Spencer
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # Remove url codings form stdin
17 sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
20 # Extract an uploaded file from standard input
21 # $1 is the boundary delimiter for the file
27 /^\\r$/ && st==1 {st=2};
29 # Remove trailing ^M's that come with CGI
32 # Format a file for viewing
34 [ -f "$1" ] && input="$1" || input="db/$1"
36 modeline="$(echo $QUERY_STRING | urldecode)"
38 # I have some plugins in ~/.vim
40 # Run vimhi.sh in screen to trick it into thinking
41 # that it has a real terminal, not that we also have to
42 # set term=xterm-256color in vimrc
44 screen -D -m ./vimhi.sh "$input" "$output" "$modeline"
51 output="$(mktemp db/XXXXX)"
52 uri="$SCRIPT_URI$(basename "$output")"
53 cut_file "$1" > "$output"
63 <pre> cat foo | curl -F 'x=<-' $SCRIPT_URI</pre>
66 <li><a href="index.cgi?ft=sh">index.cgi</a>
67 <li><a href="vimhi.sh?ft=sh">vimhi.sh</a>
68 <li><a href="vimrc?ft=vim">vimrc</a>
69 <li><a href="htaccess?ft=apache">htaccess</a>
71 <p>Latest uploads:</p><ul>
72 $(for i in $(ls -t db | head -n 5); do
74 echo "<li><a href='$uri'>$uri</a>"
83 pathinfo="${SCRIPT_URL/*vpaste\/}"
84 boundary="${CONTENT_TYPE/*boundary\=/}"
86 # Print out a generic header
87 echo Content-Type: text/html; charset=UTF-8
90 if [ "$pathinfo" ]; then
92 elif [ "$CONTENT_TYPE" ]; then