]> jfr.im git - z_archive/shellstuff.git/blame - paste2
testing
[z_archive/shellstuff.git] / paste2
CommitLineData
0c8ad8a1
JR
1#!/usr/bin/perl
2
3# Usage:
4# (sh) paste2 perl Paste2 CLI script <paste2.pl
5# (vim) :w !paste2 perl Paste2 CLI script
6
7use URI::Escape;
8use IO::Socket::INET;
9
10my $lang, $desc;
11
12$lang = (shift or 'text');
13if (@ARGV) {
14 $desc = join ' ', @ARGV;
15} else {
16 $desc = '';
17}
18
19my $code = do {
20 local $/ = undef;
21 <STDIN>;
22};
23
24my @fields = (
25 'lang='.uri_escape($lang),
26 'description='.uri_escape($desc),
27 'code='.uri_escape($code),
28 'parent=0',
29);
30my $cont = join('&', @fields)."\r\n";
31my $len = length($cont);
32
33my $s = IO::Socket::INET->new('paste2.org:80');
34my $out = "";
35$out .= "POST /new-paste HTTP/1.1\r\n";
36$out .= "Host: paste2.org\r\n";
37$out .= "User-Agent: Paster/1.0\r\n";
38$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
39$out .= "Content-Length: $len\r\n";
40$out .= "Connection: Close\r\n";
41$out .= "\r\n";
42$out .= $cont;
43$out .= "\r\n";
44
45print $s $out;
46while (<$s>) {
47 if (s/^Location: //) {
48 print "http://paste2.org".$_;
49 last;
50 }
51}