Yanopaste

From TykWiki
Jump to navigationJump to search

Yanopaste is a pastebin (not unlike many others). The following is a Perl script that can paste from stdin to a Yanopaste pastebin.

#!/usr/local/bin/perl
use strict;
##############################
# pastebin script for yanopaste
# set the yanopaste url below
#
#  /Tykling, october 2010
##############################

#configuration
my $pasteurl="http://p.tyk.nu";
my $name="tykling";
my $language="text";

#declare variables
my $htmloutput="";
my $href="";
my @hrefs;

#get input from stdin and write it to temp file
my @inputlines=(<>) ;
open (MYFILE, '>/tmp/tykpaste');
print MYFILE @inputlines;
close (MYFILE); 

#run curl to make the paste
my $htmloutput=`curl -s --url $pasteurl --data-urlencode name=$name --data-urlencode language=$language --data-urlencode content\@/tmp/tykpaste`;

#delete temp file
unlink "/tmp/tykpaste";

#parse html output, find all HREF links
@hrefs=($htmloutput =~ m|href\s*=\s*\"([^\"]+)\"|ig);
foreach $href (@hrefs) {
	#find the link to the new paste (contains the id= parameter)
	if ($href =~ m/id=/) {
		#link found, output to user
		print "Pasted to url: $href\n";
		exit 0;
	}
}
print "Error, paste unsuccessful. cURL output below:\n";
print $htmloutput;