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 # $2 is the name of the input to extract
28 bnd="${CONTENT_TYPE/*boundary\=/}"
29 awk -v "want=$1" -v "bnd=$bnd" '
32 # reset based on boundaries
33 $0 == "--"bnd"" { st=1; next; }
34 $0 == "--"bnd"--" { st=0; next; }
35 $0 == "--"bnd"--\r" { st=0; next; }
37 # search for wanted file
38 st == 1 && $0 ~ "^Content-Disposition:.* name=\""want"\"" { st=2; next; }
39 st == 1 && $0 == "" { st=9; next; }
41 # wait for newline, then start printing
42 st == 2 && $0 == "" { st=3; next; }
44 ' | head -c $((128*1024)) # Limit size to 128K
47 # Print out a generic header
49 echo "Content-Type: $1; charset=UTF-8"
53 # List previous pastes
58 for i in $(ls -t db/*); do
60 basename $i | sed 's/./-/g'
61 sed '1,/^$/d; /^\s*$/d' $i | sed -n '1,5s/\(.\{0,60\}\).*/\1/p'
71 # Format a file for viewing
73 if [ -f "./$1" ]; then
75 elif [ -f "db/$1" ]; then
77 trim='1,/^$/d' # sed command to remove cruft
79 echo "Status: 404 Not Found"
81 echo "File '$1' not found"
86 if [[ "$REQUEST_URI" == *'?'* ]]; then
87 # Create a temp file with the provided modeline
90 sed "1a$(get_modeline)" "$input" > "$tmp"
92 # - I have some plugins in ~/.vim
93 # - Run ex in screen to trick it into thinking that it
94 # has a real terminal, note that we also have to set
95 # term=xterm-256color in vimrc
97 screen -D -m ex -nXZ -i NONE -u vimrc \
98 '+sil! set fde= fdt= fex= inde= inex= key= pa= pexpr=' \
99 '+sil! set iconstring= ruf= stl= tal=' \
100 "+sil! set titlestring=$1\ -\ vpaste.net" \
122 spam=$(echo -n "$body" | cut_file "ignoreme")
123 text=$(echo -n "$body" | cut_file "(text|x)")
124 if [ ! -z "$spam" ]; then
129 if [ -z "$text" ]; then
131 echo "No text pasted"
134 output="$(mktemp db/XXXXX)"
135 uri="$url$(basename "$output")${QUERY_STRING:+"?"}"
137 # Format, spam check, and save message
140 echo "Date: $(date -R)"
141 echo "From: $REMOTE_ADDR"
144 ) | HOME=/home/vpaste spamc -E > "$output"
147 if [ "$?" -ne 0 ]; then
150 echo "Your post has been marked as spam!"
151 echo "Spam test results are as folllows.. "
157 echo "Status: 302 Found"
158 echo "Location: $uri"
167 ls /usr/share/vim/vim*/syntax/ /home/andy/.vim/syntax/ |
168 sed -n '/^\(syntax\|manual\|synload\|2html\|colortest\|hitest\).vim$/d; s/.vim$//p' |
171 uploads=$(ls -t db | head -n 5)
175 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
176 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
177 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
179 <title>vpaste.net - Vim based pastebin</title>
180 <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
181 <meta name="description" content="vpaste: Vim based pastebin" />
182 <meta name="keywords" content="vpaste,paste,pastebin,vim" />
183 <style type="text/css">
184 * { margin:0; padding:0; }
186 h4 { margin:1em 0 0 0; }
187 blockquote,dd,dl,p,pre,ul { margin:0 0 0 2em; }
188 dt { font-weight:bold; padding:0.5em 0 0 0; }
189 blockquote { width:50em; font-size:small; }
190 span { font-family:monospace; }
194 <form id="form" method="post" action="?" enctype="multipart/form-data">
195 <div style="margin:0 0 1.5em 0;">
196 <input style="display:none" type="text" name="ignoreme" value="">
197 <textarea name="text" cols="80" rows="25" style="width:100%; height:20em;"></textarea>
198 <select onchange="document.getElementById('form').action =
199 document.location + '?ft=' + this.value;">
200 <option value="" selected="selected" disabled="disabled">Filetype</option>
201 <option value="">None</option>
202 $(for ft in $filetypes; do
203 echo "<option>$ft</option>"
206 <input type="submit" value="Paste" />
211 <p>vpaste: Vim based pastebin</p>
215 <pre> vpaste file [option=value,..]</pre>
216 <pre> <command> | vpaste [option=value,..]</pre>
218 <pre> <command> | curl -F 'text=<-' $url[?option=value,..]</pre>
220 <pre> :map vp :exec "w !vpaste ft=".&ft<CR></pre>
221 <pre> :vmap vp <ESC>:exec "'<,'>w !vpaste ft=".&ft<CR></pre>
225 <p>Add <b>?[option[=value],..]</b> to make your text a rainbow.</p>
226 <p>Options specified when uploading are used as defaults.</p>
230 <dt>ft, filetype={filetype}</dt>
231 <dd>A filetype to use for highlighting, see above menu for supported types</dd>
232 <dt>bg, background={light|dark}</dt>
233 <dd>Background color to use for the page</dd>
234 <dt>et, expandtab</dt>
235 <dd>Expand tabs to spaces</dd>
236 <dt>ts, tabstop=[N]</dt>
237 <dd>Number of spaces to use for tabs when <b>et</b> is set</dd>
239 <dd>See :help modeline for more information</dd>
244 <li>Using strange filetypes (ft=2html) may result in strange output.</li>
245 <li><a href="mailto:andy753421@gmail.com?subject=vpaste bug">Other?</a></li>
250 <li><a href="vpaste?ft=sh">vpaste</a></li>
251 <li><a href="index.cgi?ft=sh">index.cgi</a>
252 <a href="vimrc?ft=vim">vimrc</a>
253 <a href="htaccess?ft=apache">htaccess</a>
254 <a href="robots.txt?ft=robots">robots.txt</a>
255 <a href="sitemap.xml?ft=xml">sitemap.xml</a></li>
256 <li><a href="2html.patch?ft=diff">2html.patch</a></li>
257 <li><a href="https://lug.rose-hulman.edu/svn/misc/trunk/htdocs/vpaste/">Subversion</a></li>
260 <h4>LATEST UPLOADS</h4>
261 <ul>$(for upload in ${uploads[@]}; do
263 echo -n "<span>$upload</span> "
264 echo -n "<a href='$upload'>text</a> "
265 echo -n "<a href='$upload?'>rainbow</a>"
269 <p><a href="ls">list all</a></p>
270 <p><a href="head">sample all</a></p>
277 url="http://$HTTP_HOST${REQUEST_URI/\?*}"
278 pathinfo="${REQUEST_URI/*\/}"
279 pathinfo="${pathinfo/\?*}"
281 if [ "$pathinfo" = ls ]; then
283 elif [ "$pathinfo" = head ]; then
285 elif [ "$pathinfo" ]; then
287 elif [ "$CONTENT_TYPE" ]; then