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 from stdin
16 function get_modeline {
18 echo "$QUERY_STRING" |
19 sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g; s/[,&]/ /g' |
25 # Extract an uploaded file from standard input
26 # $1 is the boundary delimiter for the file
29 if ($0 == "--"bnd"\r") { st=1; }
30 if ($0 == "--"bnd"--\r") { st=0; }
31 if (st == 2) { print $0; }
32 if ($0 == "\r" && st == 1) { st=2; }
33 }' | head -c -2 | head -c $((128*1024))
34 # Remove trailing ^M's that come with CGI
38 # Print out a generic header
40 echo "Content-Type: $1; charset=UTF-8"
44 # Format a file for viewing
46 if [ -f "./$1" ]; then
48 elif [ -f "db/$1" ]; then
50 trim='1d' # sed command to remove cruft
52 echo "Status: 404 Not Found"
54 echo "File '$1' not found"
59 if [[ "$REQUEST_URI" == *'?'* ]]; then
60 # Create a temp file with the provided modeline
63 sed "1a$(get_modeline)" "$input" > "$tmp"
65 # - I have some plugins in ~/.vim
66 # - Run ex in a pty to trick it into thinking that it
67 # has a real terminal, note that we also have to set
68 # term=xterm-256color in vimrc
70 /home/andy/bin/pty ex -nXZ -i NONE -u vimrc \
71 '+set bexpr= fde= fdt= fex= inde= inex= key= pa= pexpr' \
72 '+set iconstring= ruf= stl= tal=' \
73 "+set titlestring=$1\ -\ vpaste.net" \
80 "$tmp" </dev/null >/dev/null 2>&1
95 if [ -z "$text" ]; then
100 output="$(mktemp db/XXXXX)"
101 uri="$url$(basename "$output")${QUERY_STRING:+"?"}"
102 (get_modeline; echo "$text") > "$output"
103 echo "Status: 302 Found"
104 echo "Location: $uri"
112 ls /usr/share/vim/vim*/syntax/ /home/andy/.vim/syntax/ |
113 sed -n '/^\(syntax\|manual\|synload\|2html\|colortest\|hitest\).vim$/d; s/.vim$//p' |
116 uploads=$(ls -t db | head -n 5)
120 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
121 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
122 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
124 <title>vpaste.net - Vim based pastebin</title>
125 <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
126 <meta name="description" content="vpaste: Vim based pastebin" />
127 <meta name="keywords" content="vpaste,paste,pastebin,vim" />
128 <style type="text/css">
129 * { margin:0; padding:0; }
131 h4 { margin:1em 0 0 0; }
132 blockquote,dd,dl,p,pre,ul { margin:0 0 0 2em; }
133 dt { font-weight:bold; padding:0.5em 0 0 0; }
134 blockquote { width:50em; font-size:small; }
135 span { font-family:monospace; }
139 <form id="form" method="post" action="?" enctype="multipart/form-data">
140 <div style="margin:0 0 1.5em 0;">
141 <textarea name="text" cols="80" rows="25" style="width:100%; height:20em;"></textarea>
142 <select onchange="document.getElementById('form').action =
143 document.location + '?ft=' + this.value;">
144 <option value="" selected="selected" disabled="disabled">Filetype</option>
145 <option value="">None</option>
146 $(for ft in $filetypes; do
147 echo "<option>$ft</option>"
150 <input type="submit" value="Paste" />
155 <p>vpaste: Vim based pastebin</p>
159 <pre> vpaste file [option=value,..]</pre>
160 <pre> <command> | vpaste [option=value,..]</pre>
162 <pre> <command> | curl -F 'x=<-' $url[?option=value,..]</pre>
164 <pre> :map vp :exec "w !vpaste ft=".&ft<CR></pre>
165 <pre> :vmap vp <ESC>:exec "'<,'>w !vpaste ft=".&ft<CR></pre>
169 <p>Add <b>?[option[=value],..]</b> to make your text a rainbow.</p>
170 <p>Options specified when uploading are used as defaults.</p>
174 <dt>ft, filetype={filetype}</dt>
175 <dd>A filetype to use for highlighting, see above menu for supported types</dd>
176 <dt>bg, background={light|dark}</dt>
177 <dd>Background color to use for the page</dd>
178 <dt>et, expandtab</dt>
179 <dd>Expand tabs to spaces</dd>
180 <dt>ts, tabstop=[N]</dt>
181 <dd>Number of spaces to use for tabs when <b>et</b> is set</dd>
183 <dd>See :help modeline for more information</dd>
188 <li>Using strange filetypes (ft=2html) may result in strange output.</li>
189 <li><a href="mailto:andy753421@gmail.com?subject=vpaste bug">Other?</a></li>
194 <li><a href="vpaste?ft=sh">vpaste</a></li>
195 <li><a href="index.cgi?ft=sh">index.cgi</a>
196 <a href="vimrc?ft=vim">vimrc</a>
197 <a href="htaccess?ft=apache">htaccess</a>
198 <a href="robots.txt?ft=robots">robots.txt</a>
199 <a href="sitemap.xml?ft=xml">sitemap.xml</a></li>
200 <li><a href="2html.patch?ft=diff">2html.patch</a></li>
201 <li><a href="https://lug.rose-hulman.edu/svn/misc/trunk/htdocs/vpaste/">Subversion</a></li>
204 <h4>LATEST UPLOADS</h4>
205 <ul>$(for upload in ${uploads[@]}; do
207 echo -n "<span>$upload</span> "
208 echo -n "<a href='$upload'>text</a> "
209 echo -n "<a href='$upload?'>rainbow</a>"
218 url="http://$HTTP_HOST${REQUEST_URI/\?*}"
219 pathinfo="${REQUEST_URI/*\/}"
220 pathinfo="${pathinfo/\?*}"
222 if [ "$pathinfo" ]; then
224 elif [ "$CONTENT_TYPE" ]; then
225 do_upload "${CONTENT_TYPE/*boundary\=/}"