#!/usr/bin/perl use strict; use warnings "all"; use Fcntl; my $str = ''; my $DIR = '/tmp/paste'; my $fsize = 262144; # assume GET request if (defined($ARGV[0])){ if ($ARGV[0] eq 'e'){ $str = 'Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain Content-Disposition: attachment; filename="e"; #!/bin/bash usage() { description | fmt -s >&2 } description() { cat << HERE DESCRIPTION Upload data and fetch URL from the pastebin http://p.dafuq.ru/ USAGE $0 filename.txt $0 text string $0 < filename.txt piped_data | $0 NOTES -------------------------------------------------------------------------- * INPUT METHODS * $0 can accept piped data, STDIN redirection [&2 if [ "$*" ]; then echo Arguments present... >&2 if [ -f "$*" ]; then echo Uploading the contents of "$*"... >&2 cat "$*" else echo Uploading the text: \""$*"\"... >&2 echo "$*" fi | curl -F "exs=<-" http://p.dafuq.ru/ else echo No arguments found, printing USAGE and exiting. >&2 usage fi else echo Using input from a pipe or STDIN redirection... >&2 while read -r line ; do echo $line done | curl -F "exs=<-" http://p.dafuq.ru/ fi '; syswrite STDOUT, $str; exit 0; } if ($ARGV[0] eq 'd'){ $str = 'Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain Content-Disposition: attachment; filename="d"; #!/usr/bin/env bash if [[ "$1" == "--help" ]]; then echo "Usage: $0 < file" echo " echo foo | $0" elif [[ -f "$1" ]]; then curl -F "exs=<-" "http://p.dafuq.ru" <"$1" else curl -F "exs=<-" "http://p.dafuq.ru" fi exit 0 '; syswrite STDOUT, $str; exit 0; } if (-f "$DIR/$ARGV[0]") { $str .= 'Status: 200 OK Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-Type: text/plain; charset=UTF-8 '; open DATA, "$DIR/$ARGV[0]"; while(){ $str .= $_; } close DATA; }else{ $str .= "Status: 404 Not Found Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain http://p.dafuq.ru/$ARGV[0] Not found. "; } # assume POST(?) request }else{ if ((defined($ENV{'CONTENT_LENGTH'})) and $ENV{'CONTENT_LENGTH'} < $fsize){ my $host; if ((defined $ENV{'HTTP_HOST'})){ $host = $ENV{'HTTP_HOST'}; } elsif (defined ($ENV{'SERVER_NAME'})){ $host = $ENV{'SERVER_NAME'}; } else { # ??? No required environment variables, this script intended to run under proper http/cgi $str = 'Status: 400 Bad Request Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain '; } my $fname; for(my $i = 0;$i < 3; $i++){ $fname .= ('a'..'z', 'A'..'Z')[int rand length(join('',('a'..'z', 'A'..'Z')))]; } my $c = 0; my $delim = ''; my $header = ''; my $char = ''; while(read(STDIN, $char, 1)){ # looks like this case is obviously sic, but... :) if($c >= $ENV{'CONTENT_LENGTH'}){ $str = 'Status: 400 Bad Request Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain '; } last if ($char eq "\n"); $delim .= $char; $c++; } read(DATA, $char, 1); while(read(STDIN, $char, 1)){ if($c >= $ENV{'CONTENT_LENGTH'}){ $str = 'Status: 400 Bad Request Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain '; } last if ($char eq "\n"); $header .= $char; $c++; } unless ($header =~ /Content-Disposition: form-data; name=.exs./) { $str = 'Status: 400 Bad Request Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain Form should be multipart and parameter/field should be exs.'; syswrite STDOUT, $str; exit 0; } read(STDIN, $char, 2); my $datalen = $ENV{'CONTENT_LENGTH'} - (length($delim) + 2 + length($header) + 4 + length($delim) + 3); my $paste = ''; read(STDIN, $paste, $datalen); # read one nl+cr read(STDIN, $char, 1); # read last delimiter my $checkstr; read(STDIN, $checkstr, (length($delim))); # compare first delimiter and last one chop($delim); chop($checkstr); unless ($delim eq $checkstr){ $str .= 'Status: 400 Bad Request Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain '; } sysopen(DATA, "$DIR/$fname", O_WRONLY|O_CREAT|O_TRUNC); syswrite DATA, $paste; close(DATA); $str = "Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/plain http://$host/$fname "; }else{ $str .= 'Pragma: no-cache Cache-Control: no-cache Content-Language: en, ru Content-type: text/html; charset=UTF-8 Slack paste.

Slack Paste


Console client can be found here: http://p.dafuq.ru/e    thanks sprunge.us for their client :)
More minimalist console client can be found here: http://p.dafuq.ru/d

2015

'; } } syswrite STDOUT, $str; __END__