]>
Commit | Line | Data |
---|---|---|
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 | ||
7 | use URI::Escape; | |
8 | use IO::Socket::INET; | |
9 | ||
10 | my $lang, $desc; | |
11 | ||
12 | $lang = (shift or 'text'); | |
13 | if (@ARGV) { | |
14 | $desc = join ' ', @ARGV; | |
15 | } else { | |
16 | $desc = ''; | |
17 | } | |
18 | ||
19 | my $code = do { | |
20 | local $/ = undef; | |
21 | <STDIN>; | |
22 | }; | |
23 | ||
24 | my @fields = ( | |
25 | 'lang='.uri_escape($lang), | |
26 | 'description='.uri_escape($desc), | |
27 | 'code='.uri_escape($code), | |
28 | 'parent=0', | |
29 | ); | |
30 | my $cont = join('&', @fields)."\r\n"; | |
31 | my $len = length($cont); | |
32 | ||
33 | my $s = IO::Socket::INET->new('paste2.org:80'); | |
34 | my $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 | ||
45 | print $s $out; | |
46 | while (<$s>) { | |
47 | if (s/^Location: //) { | |
48 | print "http://paste2.org".$_; | |
49 | last; | |
50 | } | |
51 | } |