From 572c39c3b4cf45ae8b2619a150f3f770a4c0f8d1 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Tue, 6 Oct 2009 11:13:47 +0000 Subject: [PATCH] adding vpaste and some docs --- .htaccess | 6 ++++ htaccess | 1 + index.cgi | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vimhi.sh | 17 ++++++++++ vimrc | 14 ++++++++ 5 files changed, 134 insertions(+) create mode 100644 .htaccess create mode 120000 htaccess create mode 100755 index.cgi create mode 100755 vimhi.sh create mode 100644 vimrc diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..73b6223 --- /dev/null +++ b/.htaccess @@ -0,0 +1,6 @@ +# Public domain + +AddHandler cgi-script .cgi +Options +ExecCGI +RewriteEngine on +RewriteRule ^.*$ "index.cgi" diff --git a/htaccess b/htaccess new file mode 120000 index 0000000..79eb93b --- /dev/null +++ b/htaccess @@ -0,0 +1 @@ +.htaccess \ No newline at end of file diff --git a/index.cgi b/index.cgi new file mode 100755 index 0000000..e8c14f1 --- /dev/null +++ b/index.cgi @@ -0,0 +1,96 @@ +#!/bin/bash + +# Copyright (C) 2009 Andy Spencer +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# Remove url codings form stdin +function urldecode { + sed -e 's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e +} + +# Extract an uploaded file from standard input +# $1 is the boundary delimiter for the file +function cut_file { + awk " + /--$1/ {st=1}; + st==2 {print \$0}; + /$1--/ {st=0}; + /^\\r$/ && st==1 {st=2}; + " | head -c -2 + # Remove trailing ^M's that come with CGI +} + +# Format a file for viewing +function do_print { + [ -f "$1" ] && input="$1" || input="db/$1" + output="$(mktemp)" + modeline="$(echo $QUERY_STRING | urldecode)" + + # I have some plugins in ~/.vim + # + # Run vimhi.sh in screen to trick it into thinking + # that it has a real terminal, not that we also have to + # set term=xterm-256color in vimrc + HOME=/home/andy \ + screen -D -m ./vimhi.sh "$input" "$output" "$modeline" + cat "$output" +} + + +# Upload handler +function do_upload { + output="$(mktemp db/XXXXX)" + uri="$SCRIPT_URI$(basename "$output")" + cut_file "$1" > "$output" + echo "$uri" +} + +# Default index page +function do_help { +cat - < + +

Usage:

+
   cat foo | curl -F 'x=<-' $SCRIPT_URI
+

Source:

+ +

Latest uploads:

+ + +EOF +} + +# Main +pathinfo="${SCRIPT_URL/*vpaste\/}" +boundary="${CONTENT_TYPE/*boundary\=/}" + +# Print out a generic header +echo Content-Type: text/html; charset=UTF-8 +echo + +if [ "$pathinfo" ]; then + do_print "$pathinfo" +elif [ "$CONTENT_TYPE" ]; then + do_upload "$boundary" +else + do_help +fi diff --git a/vimhi.sh b/vimhi.sh new file mode 100755 index 0000000..7daefe2 --- /dev/null +++ b/vimhi.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Copyright (C) 2009 Andy Spencer - Public domain + +input="$1" +output="$2" +modeline="$3" + +# Add the modeline inline to the file then +# remove it after the file is loaded. +ex -u vimrc \ + "+1d" \ + "+TOhtml" \ + "+sav! $output" \ + "+qall!" \ + <(echo "vim: $modeline"; cat "$input") \ + 2>/dev/null 1>&2 diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..fd487fa --- /dev/null +++ b/vimrc @@ -0,0 +1,14 @@ +" Copyright (C) 2009 Andy Spencer - Public domain + +set nocompatible +set encoding=utf-8 +set foldtext=getline(v:foldstart) +set term=xterm-256color + +filetype plugin indent on +syntax on +colorscheme grey + +let html_use_css = 1 +let html_use_encoding = "utf8" +"let use_xhtml = 1 -- 2.43.2