rendered paste body#!/usr/bin/php<?phprequire_once('Console/Getopt.php');$short_options = 'f:n:x:l:d:';$con = new Console_Getopt();$args = $con->readPHPArgv();array_shift($args);$opts = $con->getopt2($args, $short_options);// If no valid options were passed then show the helpif (empty($opts[0])){ die ("Usage: pastebin --file filename [options]\n -f The filename of the file to upload -n Name to attach to post [=me] -l The lexer to use for highlighting [=1] Valid options are: 1 => Raw 2 => Asterisk Configuration 3 => C Source 4 => C++ Source 5 => PHP Source 6 => Perl Source 7 => Java Source 8 => Visual Basic Source 9 => C# Source 10 => Ruby Source 11 => Python Source 12 => Pascal Source 13 => mIRC Script 14 => PL/I Source 15 => XML Document 16 => SQL Statement 17 => Scheme Source 18 => Action Script 19 => Ada Source 20 => Apache Configuration 21 => Assembly (NASM) 23 => BASH Script 24 => CSS 25 => Delphi Source 26 => HTML 4.0 Strict 27 => JavaScript 28 => LISP Source 29 => Lua Source 30 => Microprocessor ASM 31 => Objective C 32 => Visual Basic .NET -x Time to live [=1 day] Valid times are: 0 (Never) 5 minutes 10 minutes 15 minutes 30 minutes 45 minutes 1 hour 2 hours 4 hours 8 hours 12 hours 1 day 2 days 3 days 1 week 2 weeks 3 weeks 1 month 2 months 3 months 4 months 5 months 6 months 1 year -d Descrption of uploadExample: ./pastebin -f awesome.php -l 5 -n Sid -x 0 -d \"the description\"\n");}$opts = $opts[0];// Check for the obligatory 'f' parameter$found = false;foreach ($opts as $opt){ if ($opt[0] === 'f') { $found = $opt[1]; break; }}if ($found === false){ die ("The mandatory -f parameter has not been entered\n");}//Read the file that we're meant to upload$file = file_get_contents($found);if (!$file){ die("Unable to read file that is meant for uploading\n");}// We're all set to go$short_options = split(':',$short_options);array_pop($short_options);// Make the real array with the real key names$arguments = array();$arguments['content'] = $file;$arguments['s'] = 'Submit Post';$arguments = insert_arg('n','name','me',$opts,$arguments);$arguments = insert_arg('l','type','1',$opts,$arguments);$arguments = insert_arg('x','expiry','1 day',$opts,$arguments);$arguments = insert_arg('d','description','',$opts,$arguments);// Now we need to fix expiry becasue it can be an arrayif (is_array($arguments['expiry'])){ $arguments['expiry'] = $arguments['expiry'][1];}//Also if zero we set it to blank.if ($arguments['expiry'] == 0){ $arguments['expiry'] = '';}// Now we need to fix descirption becasue it can be an arrayif (is_array($arguments['description'])){ $arguments['description'] = $arguments['description'][1];}$fp = fsockopen("pastebin.ca", 80);if (!$fp){ die("Error connecting to pastebin.ca\n");}else{ $arguments = data_encode($arguments); $out = "POST /index.php HTTP/1.1\r\n"; $out .= "Host: www.pastebin.ca\r\n"; $out .= "User-Agent: PHP submitter v0.2\r\n"; $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; $out .= "Content-Length: ".strlen($arguments)."\r\n\r\n"; $out .= $arguments."\r\n"; fwrite($fp, $out); $reply = ''; while (!feof($fp)) { $reply .= fgets($fp, 256); } fclose($fp);}// Time to parse the url out of there$matches = array();preg_match("/http:\/\/www\.pastebin\.ca\/(\d+)/",$reply, $matches);echo $matches[0]."\n";function insert_arg($short_name, $full_name, $default, $getopt_args, $final_args){ $x = in_arrayr($short_name,$getopt_args); if ($x=== false) { $final_args[$full_name] = $default; } else { $final_args[$full_name] = $x[1]; } return $final_args;}/** recurive in_array */function in_arrayr($needle, $haystack) { foreach ($haystack as $v) { if ($needle == $v) return true; elseif (is_array($v)) { if (in_arrayr($needle, $v) === true) return $v; } } return false;}function data_encode($data){ $o = ''; foreach ($data as $key => $val) { $o .= urlencode($key) . '=' . urlencode($val) . '&'; } return substr($o,0,-1);}?>