01 #!/usr/local/bin/perl -w 02 ############################# 03 # splash - Traverse WiFi 04 # Splash Pages 05 # Mike Schilli, 2010 06 # (m@perlmeister.com) 07 ############################# 08 use strict; 09 use SplashJumper; 10 use WWW::Mechanize; 11 use Log::Log4perl qw(:easy); 12 13 my $url = 14 "http://www.google.com"; 15 16 Log::Log4perl->easy_init( 17 $DEBUG); 18 19 my $sj = SplashJumper->new(); 20 21 my @ways = (); 22 23 for 24 my $plugin ($sj->plugins()) 25 { 26 27 if ( 28 !$plugin->can("register")) 29 { 30 ERROR "$plugin can't do", 31 " register()"; 32 next; 33 } 34 35 my ($algo, $order) = 36 $plugin->register(); 37 38 push @ways, 39 [ $algo, $plugin, 40 $order ]; 41 } 42 43 # sort by plugin priority 44 @ways = sort { 45 $a->[2] <=> $b->[2] 46 } @ways; 47 48 my $mech = 49 WWW::Mechanize->new(); 50 $mech->timeout(5); 51 52 # wait until network is up 53 { 54 INFO "Trying $url"; 55 eval { $mech->get($url); }; 56 if ($@) { 57 INFO 58 "Connection down, retrying"; 59 sleep 5; 60 redo; 61 } 62 } 63 64 # try to get past splash page 65 for my $ways (@ways) { 66 eval { $mech->get($url); }; 67 68 my $current_url = 69 $mech->response->request 70 ->uri; 71 72 if ($current_url eq $url) { 73 INFO "Link is up."; 74 last; 75 } else { 76 INFO "Link still down"; 77 } 78 79 my ($algo, $plugin, $order) 80 = @$ways; 81 82 eval { 83 INFO "Processing splash ", 84 "page $current_url ", 85 "with algo $algo"; 86 $plugin->process($mech); 87 }; 88 89 if ($@) { 90 ERROR 91 "Algo $algo failed ($@)"; 92 } else { 93 INFO 94 "Plugin $algo succeeded"; 95 } 96 }