#!perl # # Script to log onto the ADSL route and print out the # # # # If you are getting Interal server error messages, # use the code below to pipe script errors to the browser use CGI::Carp ( fatalsToBrowser); use IO::Socket; &setDate(); my $sock = IO::Socket::INET->new(PeerAddr => '192.168.7.1', PeerPort => 23, Proto => 'tcp', Timeout => 5000 ); $opFileName ="adsl.log"; open ( OP ,">>$opFileName") || &file_error( OP , $opFileName ); # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "ADSL dump of SOLWISE 715\n"; print "

ADSL dump of SOLWISE 715

\n"; print "
\n" ;

print "==================================\n";
print $date ."\n";
print "==================================\n";
print( "fileno: STDIN = ".fileno( "STDIN"  )."\n");
print( "fileno: STDOUT = ".fileno( "STDOUT" )."\n");
print( "fileno: STDERR = ".fileno("STDERR")."\n");
print( "fileno: SOCK = ".fileno($sock)."\n");
print( "fileno: OP = ".fileno(OP)."\n");
print "==================================\n";

my $bitArray = 0;
vec( $bitArray,2,1 );
print( "bitArray: ".$bitArray ."\n");
print "==================================\n";

#
# if connect failed, end script
#

if ( $sock ) {
  print ( "Connected .. attempting to log on..\n");
} else {
  print ( "

failed to Connect to ADSL router

\n"); print ''; if ( defined OP ) { print OP "==================================\n"; print OP $date ."\n"; print OP "failed to Connect to ADSL router \n"; print OP "==================================\n"; close( OP ); } exit; } # # if connect failed, end script # if ( $sock->connected ) { print ( "Connected .. attempting to log on..\n"); } else { print ( "

failed to Connect to ADSL router

\n"); print ''; if ( defined OP ) { print OP "==================================\n"; print OP $date ."\n"; print OP "failed to Connect to ADSL router \n"; print OP "==================================\n"; close( OP ); } exit; } # my $rto = $sock->connected; # print( "connected: ".$rto."\n"); my $rto = $sock->socktype(); print( "socktype: ".$rto."\n"); my $rto = $sock->timeout(); print( "timeout: ".$rto."\n"); my $rto = $sock->sockopt(SO_RCVTIMEO); print( "sockopt: ".$rto."\n"); my $rto = $sock->sockopt(SO_RCVTIMEO); print( "sockopt: ".$rto."\n"); my $rto = $sock->sockopt(SO_SNDTIMEO); print( "sockopt: ".$rto."\n"); # my $rto = $sock->sockopt("SO_RCVTIMEO"); # my $sto = $sock->sockopt("SO_SNDTIMEO"); # print( $rto ." ". $sto ); # print $sock "Hello there!\n"; print "adsl.pl - a script to log onto the Solwise 715 router!\n"; # # I do not understand why this works. # # $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print "line 1\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print "line 2\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print $sock "admin\r\n" ; print "line 3\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print $sock "admin\r\n" ; print "line 4\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; #print $sock "admin\r\n" ; print "line 5\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print "line 6\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print "line 7\n"; print OP "==================================\n"; print OP $date ."\n"; print OP "==================================\n"; $ip=<$sock>; print "state: ".$state." ip:".$ip."|\n"; print $sock "adsl show defects\r\n" ; print OP "adsl show defects\r\n\n" ; print "line 8\n"; $state = 3; $commandCount = 0; $cmdPtr=0; # # log data # @cmds = ( 'adsl show error', "\r\n", 'adsl up', 'adsl show id', 'adsl show rate', 'adsl show channel', 'transports list', 'pppoa list transports', 'ipoa list transports', 'rfc1483 list transports', 'pppoa show transport ppp-0', "\r\n", 'adsl show id', '', # # if adsl show id finds ADSL disconnected then bounce it. # 'adsl down', 'adsl up', '?', '', '' ); $openForIP = 0; while($ip=<$sock>) { chop($ip); # print $_; print "state: ".$state." ip:".$ip."|\n"; if( $state == 1 ) { if ( $ip =~ /-->/gi ) { print $sock "user logout\r\n"; $nextState = 2; }; } if( $state == 2 ) { if ( $ip =~ /Logging out/gi ) { print "Clossing socket...."; $sock->close(); if ( defined OP ) { print OP "----------------------------------\n"; print OP $date ."\n"; print OP "==================================\n"; close( OP ); } exit; }; } # ============================================= if( $state == 3 ) { if ( $ip =~ /-->/gi ) { print "command line:\n"; print $sock "adsl show rate\r\n"; print OP "adsl show channel\n"; $nextState = 4; $openForIP = 0; }; } if( $state == 4 ) { # # look for ATM status in output from 'adsl show id', # #-> adsl up # #--> adsl show id #DSL is not connect # #--> #--> adsl show id #DSL is not connect # # #--> # #DSL CONNECT/G.DMT/Interleaved/DS=3776K/US=448K #adsl show id #RT ANSI Vendor ID : 39 #RT Revision Number : 0 #RT ITU Vendor country code : b50 #RT ITU Vendor ID : TSTC #RT Revision Number : 0 # #--> #--> adsl up # #DSL already connected! # #--> if ( $ip =~ /DSL is not connect/gi ) { print "Status: " . $ip . "\n"; $openForIP = 2; print "ADSL down ...." . $ip . "\n"; } if ( $ip =~ /DSL already connected!/gi ) { print "Status: " . $ip . "\n"; $openForIP = 1; print "ADSL up ...." . $ip . "\n"; } if ( $ip =~ /-->/gi ) { print "\n\n=====================================\n\nlastCmd: $nextCmd \n"; $nextCmd = $cmds[$cmdPtr] ; $cmdPtr++; # # Run commands until blank command # if ( $nextCmd ne '' ){ print "command line:\n"; print $sock $nextCmd . "\r\n"; print OP $nextCmd . "\n"; $nextState = 4; } else { # # # if( $openForIP == 2) { # IP found to be disconnected, so bounce it print "Bouncing ADSL ....\n"; print "Bouncing ADSL ....\n"; print "Bouncing ADSL ....\n"; print "Bouncing ADSL ....\n"; print "Bouncing ADSL ....\n"; $nextState = 5; } else { print "Commands finished ....\n"; $nextState = 1; } } } } # # run commands to bounce ADSL links # if( $state == 5 ) { print "State: " . $state . "\n"; if ( $ip =~ /-->/gi ) { $nextCmd = $cmds[$cmdPtr] ; $cmdPtr++; if ( $nextCmd ne '' ){ print "command line:\n"; print $sock $nextCmd . "\r\n"; print OP $nextCmd . "\n"; $nextState = 5; } else { print $sock "system reset\r\n"; print "System reset Clossing socket...."; $sock->close(); if ( defined OP ) { print OP "Resetting router\n"; print OP "----------------------------------\n"; print OP $date ."\n"; print OP "==================================\n"; close( OP ); } exit; } }; } if( $state == 6 ) { # # look for ATM status in output from 'adsl show id', # if ( $ip =~ /DSL is not connect/gi ) { print "Status: " . $ip . "\n"; $openForIP = 2; print "ADSL down ...." . $ip . "\n"; } if ( $ip =~ /-->/gi ) { print "\n\n=====================================\n\nlastCmd: $nextCmd \n"; $nextCmd = $cmds[$cmdPtr] ; $cmdPtr++; # # Run commands until blank command # if ( $nextCmd ne '' ){ print "command line:\n"; print $sock $nextCmd . "\r\n"; print OP $nextCmd . "\n"; $nextState = 4; } else { print "Commands finished ....\n"; $nextState = 1; } } } print $ip ; print OP $ip . "\n"; $state = $nextState; } $sock->close(); &setDate(); if ( defined OP ) { print OP "----------------------------------\n"; print OP $date ."\n"; print OP "==================================\n"; close( OP ); } print "
"; exit; ####################### # Subroutines # file_error - call if problems opening files sub file_error { local( $FH, $fileName ) = @_; # Print Beginning of HTML print "Content-Type: text/html\n\n"; print "Thank You\n"; print "

Error Opening File $fileName:, press back

\n"; print "Your data has not been added, press back

\n"; print "If you can log into the server, check file permissions\n"; print ''; exit; } ################################################################ # setDate setup $date to string that javascript can parse using: now= new Date( postedOn ) # sub setDate { # Get the Date for Entry # output date so that the web pages can be use the javascript: now= new Date( postedOn ) #IE 5 formats toUTCString(): Tue, 25 Jun 2002 05:47:32 UTC #Netscape Navigator toUTCString(): Tue, 25 Jun 2002 05:49:59 GMT #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # 0 1 2 3 4 5 6 7 8 @t = localtime(); @days= ('Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun'); @months=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $fullYear=1900+$t[5]; #toUTCString(): #Tue, 25 Jun 2002 05:47:32 UTC $date = "$days[$t[6]], $t[3] $months[$t[4]] $fullYear ".substr("0".$t[2],-2,2).":".substr("0".$t[1],-2,2).":".substr("0".$t[0],-2,2)." UTC+0100"; }