#!/usr/local/bin/perl #File: /tmp_mnt/fractal.nmt.edu/administratium/accounts/k/kscott/work/src/modems/modem_tweak/modem_tweak #Author: K. Scott Rowe #Time-stamp: <12/15/1999 09:16:07 kscott@pescado.tcct.nmt.edu> use lib::Telnet () ; $ENABLE_PASSWD= ; $SECURITY_PASSWD= ; $USERNAME= ; $PASSWD= ; sub Version { print "Version$Id: modem_tweak,v 1.11 1998/07/02 15:17:18 kscott Exp kscott $null\n" ; exit ; } sub Usage { print "Usage: $0 [-h] [-V] [-v] [-d] [-l] [-T] [-L]\n" ; exit ; } sub PrintList { foreach $key (keys %$class_choice) { print "$terminal_server$terminal_line.$key=$$class_choice{$key}\n" ; } } sub LoadConf { local($conf_file) = shift ; open(CONF_FILE,"<$conf_file") || die "cant open $conf_file: $! " ; while() { s/#.*//g ; # nuke comments s/^\s*//g ; s/\s*$//g ; if (/^(.*):\s*(.*)$/) # find a name of a class { if ($1) { $working_class=$1 ; if ($2) { @classlist = split(' ',$2) ; # subclasses to chase down foreach $class (@classlist) { while( ($key, $val) = each %$class) { $$working_class{$key}=$val ; } } } } } if (/^([^=]*)\s*=\s*(.*)$/) # find variables in a class { $$working_class{$1}=$2 ; # print "adding $1 and $2\n" ; } } close(CONF_FILE) ; $class_choice=$terminal_server.$terminal_line ; if(! %$class_choice) # is there a specific line, or do we default { $class_choice=$terminal_server ; } } sub OpenCloseModemLine() # $server, $line, $action { local($server) = @_[0] ; local($line) = @_[1] ; local($action) = @_[2] ; # open or close the modem line local($port) = 2000 + $line ; $t = new Net::Telnet (Timeout => 10) ; print "connecting to $terminal_server... " if $verbose ; $t->open("$server"); print "Done\n" if $verbose ; $t->login(Password => $SECURITY_PASSWD, Prompt => "/$server>/"); print "enable\n" if $debug ; @lines = $t->cmd(Prompt => "/Password:/", String => "enable"); print @lines if $debug ; print "$ENABLE_PASSWD\n" if $debug ; @lines = $t->cmd(Prompt => "/$server#/", String => "$ENABLE_PASSWD"); print @lines if $debug ; print "configure terminal\n" if $debug ; @lines = $t->cmd(Prompt => "/$server.*/", String => "configure terminal"); print @lines if $debug ; print "line $line\n" if $debug ; @lines = $t->cmd(Prompt => "/$server.*/", String => "line $line"); print @lines if $debug ; print "$action\n" if $debug ; @lines = $t->cmd(Prompt => "/$server.*/", String => "$action"); print @lines if $debug ; } sub SetModemSettings() { local($port)=2000 + $terminal_line ; $t = new Net::Telnet (Timeout => 10, Prompt => '/.*OK$/', Port => $port); print "connecting to $terminal_server port $port... " if $verbose ; $t->open("$terminal_server"); print "Done\n" if $verbose ; $t->login(Name => $USERNAME, Password => $PASSWD); foreach $command (@at_commands) { print "executing $command..." if $verbose ; @lines = $t->cmd("$command"); print "Done\n" if $verbose ; print @lines if $debug ; } print "disconnecting $terminal_server port $port..." if $verbose ; $t->close ; print "Done\n" if $verbose ; } sub GetATCommands() { # Push special beginning function if($$class_choice{'AT_factory'}) { push(@at_commands, delete($$class_choice{'AT_factory'})) ; print "AT_factory=$$class_choice{'AT_factory'}\n" if $verbose ; } # store special ending function $AT_store_config=delete($$class_choice{'AT_store_config'}) ; # push all the commands foreach $key (keys %$class_choice) { print "$key=$$class_choice{$key}\n" if $verbose ; if($key =~ /AT_.*$/) { if($$class_choice{$key} ne '') { push(@at_commands, $$class_choice{$key}) ; } } } # push special ending command if($AT_store_config) { push(@at_commands, $AT_store_config) ; print "AT_store_config=$AT_store_config\n" ; } } ##############################Main Program############################## if (! @ARGV) { &Usage ; } while ($_ = shift(@ARGV)) { if (/^-h/) { &Usage ; } elsif (/^-V/) { &Version ; } elsif (/^-T(.*)/) { $terminal_server=$1 ; } elsif (/^-L([0-9]*)/) { $terminal_line=$1 ; } elsif (/^-v/) { $verbose=1 ; } elsif (/^-d/) { $debug=1 ; } # elsif (/^-f/) { $fake=1 ; } elsif (/^-l/) { $listonly=1 ; } else { &Usage ; } } &LoadConf("../conf/modem_tweak.conf") ; if($listonly) { if( ($terminal_server) && !($terminal_line) ) # do we need to itirate { &LoadConf("../conf/modem_tweak.conf") ; &PrintList ; for ($i = 1 ; $i <= $$class_choice{'numoflines'} ; $i++) { $terminal_line = $i ; &LoadConf("../conf/modem_tweak.conf") ; &PrintList ; } exit ; } else # or just print one modem line { &PrintList ; exit ; } } if( ($terminal_server) && !($terminal_line) ) # do we need to itirate { for ($i = 1 ; $i <= $$class_choice{'numoflines'} ; $i++) { $terminal_line=$i ; &LoadConf("../conf/modem_tweak.conf") ; &GetATCommands ; &OpenCloseModemLine($terminal_server, $terminal_line, $$class_choice{enable_telnet}) ; &SetModemSettings ; &OpenCloseModemLine($terminal_server, $terminal_line, $$class_choice{disable_telnet}) ; } } else # or just set one modem line { &LoadConf("../conf/modem_tweak.conf") ; &GetATCommands ; &OpenCloseModemLine($terminal_server, $terminal_line, $$class_choice{enable_telnet}) ; &SetModemSettings ; &OpenCloseModemLine($terminal_server, $terminal_line, $$class_choice{disable_telnet}) ; } exit ;