line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::starbucksloginator; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$App::starbucksloginator::VERSION = '0.0012'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Access the wireless at Starbucks (via AT&T) |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
109905
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1111
|
use Getopt::Long qw/ GetOptions /; |
|
1
|
|
|
|
|
11178
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
951
|
use Getopt::Usaginator <<_END_; |
|
1
|
|
|
|
|
36613
|
|
|
1
|
|
|
|
|
8
|
|
13
|
|
|
|
|
|
|
Usage: starbucksloginator |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
--agent The agent to pass the loginator off as (user agent string). |
16
|
|
|
|
|
|
|
Windows Firefox by default |
17
|
|
|
|
|
|
|
_END_ |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
1331
|
use WWW::Mechanize; |
|
1
|
|
|
|
|
166738
|
|
|
1
|
|
|
|
|
498
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $__agent__ = WWW::Mechanize->new; |
22
|
|
|
|
|
|
|
$__agent__->agent( "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6" ); |
23
|
0
|
|
|
0
|
0
|
|
sub agent { $__agent__ } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub try { |
26
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
27
|
0
|
|
|
|
|
|
my $site = shift; |
28
|
0
|
|
|
|
|
|
my $response = agent->get( "http://$site" ); |
29
|
0
|
|
|
|
|
|
my $success = $response->decoded_content !~ m/[^<]*Starbucks.*?
|
30
|
0
|
|
|
|
|
|
return ( $success, $response ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub try_to_get_out { |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
my ( $success, $response ); |
36
|
0
|
|
|
|
|
|
for my $site ( qw/ google.com example.com bing.com yahoo.com / ) { |
37
|
0
|
|
|
|
|
|
( $success, $response ) = $self->try( $site ); |
38
|
0
|
0
|
|
|
|
|
return ( $success, $response ) unless $success; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
return ( $success, $response ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub say { |
44
|
0
|
|
|
0
|
0
|
|
print "> ", @_, "\n"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub run { |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my @arguments = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my ( $help, $agent ); |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
|
local @ARGV = @arguments; |
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
GetOptions( |
55
|
|
|
|
|
|
|
'agent=s' => \$agent, |
56
|
|
|
|
|
|
|
'help|h|?' => \$help, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
usage 0 if $help; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
agent->agent( $agent ) if defined $agent; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my ( $connected, $response ); |
65
|
0
|
|
|
|
|
|
( $connected, $response ) = $self->try_to_get_out; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ( $connected ) { |
68
|
0
|
|
|
|
|
|
say "It looks like you can already get out -- Cancelling login"; |
69
|
0
|
|
|
|
|
|
exit 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
|
say "Unable to get out -- Attempting to login"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if ( agent->form_number( 1 ) ) { |
76
|
0
|
|
|
|
|
|
say "Attempting to connect"; |
77
|
0
|
|
|
|
|
|
$response = agent->submit_form( |
78
|
|
|
|
|
|
|
fields => { |
79
|
|
|
|
|
|
|
aupAgree => 1, |
80
|
|
|
|
|
|
|
}, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
|
say "Unable to find connect form -- Cancelling login"; |
85
|
0
|
|
|
|
|
|
print $response->as_string; |
86
|
0
|
|
|
|
|
|
exit -1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
( $connected ) = $self->try_to_get_out; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( $connected ) { |
92
|
0
|
|
|
|
|
|
say "Connected -- Login successful"; |
93
|
0
|
|
|
|
|
|
exit 0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
say "Unable to get out -- Login failed"; |
97
|
0
|
|
|
|
|
|
print $response->as_string; |
98
|
0
|
|
|
|
|
|
exit -1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |