-
Notifications
You must be signed in to change notification settings - Fork 2
/
attwifi.pl
70 lines (59 loc) · 1.42 KB
/
attwifi.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl -w
use strict;
use warnings;
use WWW::Mechanize;
use File::Basename;
# very simple logging
use constant DEBUG => 1;
sub debug;
our $Debug_Handle;
our $Program_Name = basename $0;
BEGIN {
if ( DEBUG ) {
# passing undefined var to open only works in newer perl
open $Debug_Handle, ">", "/var/log/attwifi.log";
select $Debug_Handle; $| = 1;
}
}
our( $SSID, $IF, $STATUS );
chomp( $SSID = `/sbin/iwgetid --raw` );
$IF = shift // '';
$STATUS = shift // '';
debug "SSID: $SSID; IF: $IF; STATUS: $STATUS";
sub main {
return unless $STATUS eq 'up';
return unless $IF eq 'wlan0';
return unless $SSID eq 'attwifi';
my $mech = new WWW::Mechanize;
$mech->get( 'http://www.google.com/' );
unless ( $mech->success ) {
debug "Failed to get google.com";
return;
}
if ( $mech->form_with_fields( 'aupAgree' ) ) {
debug "Found form with field aupAgree";
$mech->submit(
button => 'connect',
fields => { aupAgree => 1 }
);
if ( $mech->success ) {
debug "Submitted form success";
}
else {
debug $mech->res->as_string;
}
}
else {
debug "Form not found";
}
}
END {
debug "Finished";
close $Debug_Handle;
}
sub debug {
return unless DEBUG;
print $Debug_Handle "[" . localtime()
. "] $Program_Name". "[$$] ", @_, "\n";
}
main();