line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Rafb; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
WWW::Rafb - Perl interface for rafb pasting site ( rafb.net/paste ) |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# create object with the paste information |
12
|
|
|
|
|
|
|
my $paste = WWW::Rafb->new( 'language' => 'perl', |
13
|
|
|
|
|
|
|
'nickname' => 'Di42lo', |
14
|
|
|
|
|
|
|
'description' => 'my first script in perl', |
15
|
|
|
|
|
|
|
'tabs' => 'No', |
16
|
|
|
|
|
|
|
'file' => "~/first.pl"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# do the http request ( the paste itself ) |
19
|
|
|
|
|
|
|
$paste->paste(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# print the url |
22
|
|
|
|
|
|
|
print "You can get $paste->{file} at url: $paste->{URL}\n"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
"WWW::Rafb" provides object interface for pasting any text file/source file |
27
|
|
|
|
|
|
|
into the the rafb site with the needed information. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module requires B and B |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 INTERFACE |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#use strict; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
534
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
38
|
|
|
|
|
|
|
$VERSION = "0.02"; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
|
7105
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
121354
|
|
|
1
|
|
|
|
|
37
|
|
41
|
1
|
|
|
1
|
|
10
|
use URI::Escape; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
830
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _agent { |
44
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# creates LWP::UserAgent object |
47
|
0
|
|
|
|
|
0
|
my $agent = LWP::UserAgent->new; |
48
|
0
|
|
|
|
|
0
|
$agent->timeout(10); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
$agent->agent('Mozilla/5.0'); # fake agent |
51
|
0
|
|
|
|
|
0
|
$agent->default_header('Keep-Alive' => 300); |
52
|
0
|
|
|
|
|
0
|
$agent->default_header('Connection' => 'keep-alive'); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
$self->{AGENT} = $agent; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
new( [ARGS] ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Used to set the pasting information about the file and create a new |
64
|
|
|
|
|
|
|
Object of the WWW::Rafb module. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Arguments: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
language - The file type. One of this types: |
69
|
|
|
|
|
|
|
note: you should write the value (in the () ) and not the full name. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
C89 (c89) |
72
|
|
|
|
|
|
|
C99 (c) |
73
|
|
|
|
|
|
|
C++ (c++) |
74
|
|
|
|
|
|
|
C# (c#) |
75
|
|
|
|
|
|
|
Java (java) |
76
|
|
|
|
|
|
|
Pascal (pascal) |
77
|
|
|
|
|
|
|
Perl (perl) |
78
|
|
|
|
|
|
|
PHP (php) |
79
|
|
|
|
|
|
|
PL/I (pl/i) |
80
|
|
|
|
|
|
|
Python (python) |
81
|
|
|
|
|
|
|
Ruby (ruby) |
82
|
|
|
|
|
|
|
SQL (sql) |
83
|
|
|
|
|
|
|
Visual Basic (vb) |
84
|
|
|
|
|
|
|
Plain Text (plain text) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
nickname - the nickname of the script/file publisher |
87
|
|
|
|
|
|
|
description' => 'my first script in perl', |
88
|
|
|
|
|
|
|
tabs - values: No/2/4/6/8 |
89
|
|
|
|
|
|
|
file - path of the file we want to upload. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
NOTES: Returns a blessed object with the information. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my %types = ( |
96
|
|
|
|
|
|
|
"C89" => "c89", |
97
|
|
|
|
|
|
|
"C99" => "c", |
98
|
|
|
|
|
|
|
"C++" => "c++", |
99
|
|
|
|
|
|
|
"C#" => "c#", |
100
|
|
|
|
|
|
|
"Java" => "java", |
101
|
|
|
|
|
|
|
"Pascal" => "pascal", |
102
|
|
|
|
|
|
|
"Perl" => "perl", |
103
|
|
|
|
|
|
|
"PHP" => "php", |
104
|
|
|
|
|
|
|
"PL/I" => "pl/i", |
105
|
|
|
|
|
|
|
"Python" => "python", |
106
|
|
|
|
|
|
|
"Ruby" => "ruby)", |
107
|
|
|
|
|
|
|
"SQL" => "sql", |
108
|
|
|
|
|
|
|
"Visual Basic" => "vb", |
109
|
|
|
|
|
|
|
"Plain Text" => "plain text" |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub new { |
113
|
1
|
|
|
1
|
0
|
12
|
my $class = shift; |
114
|
1
|
|
|
|
|
7
|
my %args = @_; |
115
|
1
|
|
|
|
|
3
|
my $self; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# inserts args into class |
118
|
1
|
|
|
|
|
3
|
foreach (keys %args) { |
119
|
5
|
|
|
|
|
15
|
$self->{uc($_)} = $args{$_}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# check args |
123
|
1
|
50
|
33
|
|
|
12
|
$self->{LANGUAGE} = "C++" unless ($self->{LANGUAGE} && $types{"$self->{LANGUAGE}"}); |
124
|
|
|
|
|
|
|
|
125
|
1
|
50
|
33
|
|
|
36
|
$self->{TABS} = "No" if ($self->{TABS} < 2 || $self->{TABS} > 8); |
126
|
|
|
|
|
|
|
|
127
|
1
|
50
|
|
|
|
|
open(FH, "< $self->{FILE}") || die ("Cant open file for pasting!\n"); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# escape our form values |
130
|
0
|
|
|
|
|
|
$self->{SOURCE} .= $_ while (); |
131
|
0
|
|
|
|
|
|
close (FH); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$self->{SOURCE} =~ s/ /+/g; |
134
|
0
|
|
|
|
|
|
$self->{SOURCE} = URI::Escape::uri_escape_utf8($self->{SOURCE}); |
135
|
0
|
|
|
|
|
|
$self->{SOURCE} =~ s/%2B/+/g; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$self->{NICKNAME} =~ s/ /+/g; |
138
|
0
|
|
|
|
|
|
$self->{NICKNAME} = URI::Escape::uri_escape_utf8($self->{NICKNAME}); |
139
|
0
|
|
|
|
|
|
$self->{NICKNAME} =~ s/%2B/+/g; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$self->{DESCRIPTION} =~ s/ /+/g; |
142
|
0
|
|
|
|
|
|
$self->{DESCRIPTION} = URI::Escape::uri_escape_utf8($self->{DESCRIPTION}); |
143
|
0
|
|
|
|
|
|
$self->{DESCRIPTION} =~ s/%2B/+/g; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$self->{SITE} = "http://www.rafb.net/paste"; |
146
|
|
|
|
|
|
|
# return the object |
147
|
0
|
|
|
|
|
|
return bless $self, $class; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=pod |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
paste() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns the object with the URL of the file in the |
156
|
|
|
|
|
|
|
rafb.net/paste site and the other informations. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
No Arguments. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub paste { |
163
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$self->_agent(); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Create and send the request |
168
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( POST => $self->{SITE} ."/paste.php"); |
169
|
0
|
|
|
|
|
|
$req->content_type('application/x-www-form-urlencoded'); |
170
|
0
|
|
|
|
|
|
$req->content( "lang=" . $self->{LANGUAGE} . "&". |
171
|
|
|
|
|
|
|
"nick=" . $self->{NICKNAME} . "&" . |
172
|
|
|
|
|
|
|
"desc=" . $self->{DESCRIPTION} . "&" . |
173
|
|
|
|
|
|
|
"cvt_tabs=" . $self->{TABS} . "&" . |
174
|
|
|
|
|
|
|
"text=" . $self->{SOURCE}); |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
my $res = $self->{AGENT}->request($req); |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
$self->{URL} = "http://www.rafb.net/" . $res->header("Location"); |
179
|
0
|
|
|
|
|
|
return $self; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=pod |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 LINKS |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
http://www.rafb.net/paste |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 NOTES |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Don't run this script too much times, the site has protection from that. |
192
|
|
|
|
|
|
|
to solve that - sleep(10) between the pastes. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This module was written by |
197
|
|
|
|
|
|
|
Amit Sides C<< >> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 Copyright |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Copyright (c) 2006 Amit Sides. All rights reserved. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 LICENSE |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
206
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |