#!/usr/bin/perl ## Script for posting output from commands directly from command line. ## i wrote this script to be able use it on solaris operating system without ## installing any exotic or not core perl modules (.pm) ## ## script has just one dependency: wget with option post-file= .. ## ## author: dpecka[at]opensuse[dot]org ## enjoy !! ## use strict; use warnings; sub usage() { print << 'EOF'; Usage: foo | pastebin.sh [-f] [-t type] [-d description] [-n name] -f exploit pastebin.ca even if input have less then 5 lines -t expects one from types listed below -d short paste description -n alternate nick, default is your $USER enviroment variable -h this help message escape white characters in name and description string .. Types: action ada apache asm asp asterisk bash c c# c++ css delphi diff html java javascript lisp lua mirc nasm net objc pascal patch perl php pli python raw ruby scheme sql vbs xml EOF exit 2; }; ## several checks .. we need to know if we have sufficient wget my $wpath; sub checks() { chomp($wpath = `which wget 2>/dev/null`); die "can't find wget within your \$PATH, it's over ..\n" if ! -x "$wpath"; chomp(my $winfo = `$wpath --help | grep post-file=`); die "it seems like your wget has not option --post-file=, it's over ..\n" if ! "$winfo"; }; ## parses cli and assigns a base vars my($pforc, $ptype, $pdesc, $puser); $pforc = "false"; $ptype = 33; $pdesc = ""; $puser = $ENV{"USER"}; sub parse_cli() { return 0 if ! @ARGV; while(@ARGV) { $_=shift(@ARGV); if(/^-f$/) { $pforc="true"; next; }; if(/^-t$/) { $ptype = shift(@ARGV); $ptype =~ y/[A-Z]/[a-z]/; my %types = ( raw => "1", asterisk => "2", c => "3", "c++" => "4", php => "5", perl => "6", java => "7", vbs => "8", "c#" => "9", ruby => "10", python => "11", pascal => "12", mirc => "13", pli => "14", xml => "15", sql => "16", scheme => "17", action => "18", ada => "19", apache => "20", nasm => "21", asp => "22", bash => "23", css => "24", delphi => "25", html => "26", javascript => "27", lisp => "28", lua => "29", asm => "30", objc => "31", net => "32", diff => "33", patch => "33", ); die "bad type: $ptype\nchoose one from: ", join(" ", sort(keys(%types))), "\n" if ! grep(/^$ptype$/, keys(%types)); $ptype = $types{"$ptype"}; next; }; if(/^-d$/) { $pdesc = shift(@ARGV); $pdesc =~ s/%/%25/g; $pdesc =~ s/&/%26/g; $pdesc =~ s/\+/%2B/g; next; }; if(/^-n$/) { $puser=shift(@ARGV); next; }; usage() if(/^(-h|--help)$/); print "bad option: $_\n"; usage(); }; }; ## build and upload tmp file .. sub build_upload_file() { my $pfile; open($pfile, ">", "/tmp/pastebin.pl.tmp"); print $pfile "name=$puser&type=$ptype&description=$pdesc&expiry=&s=Submit+Post&content="; while(<>) { s/%/%25/g; s/&/%26/g; s/\+/%2B/g; print $pfile "$_"; }; close($pfile); }; my $pastebinkey = "4g64jruLaAtRJt8XvjDn1Qt3jsQTgCmx"; sub upload_file() { chomp(my @wget_output = `$wpath -O - --tries=5 --timeout=60 --post-file=/tmp/pastebin.pl.tmp http://pastebin.ca/quiet-paste.php?api=$pastebinkey 2>&1`) || die "can't upload file:"; foreach(@wget_output) { next if ! /SUCCESS:/; print "$_\n" if s#^.*:([0-9][0-9]*).*#http://pastebin.ca/$1#; }; }; ### Body from here: checks(); parse_cli(); build_upload_file(); upload_file(); unlink "/tmp/pastebin.pl.tmp"; #print << "EOF"; #pforce: $pforc #ptype: $ptype #pdesc: $pdesc #puser: $puser #EOF exit 0;