| version 1.29, 2007/02/01 17:58:33 | version 1.38, 2007/02/06 16:22:46 | 
|  |  | 
| package Net::Telnet::Trango; | package Net::Telnet::Trango; | 
| # $RedRiver: Trango.pm,v 1.28 2007/02/01 17:10:07 mike Exp $ |  | 
| use strict; | # $RedRiver: Trango.pm,v 1.37 2007/02/05 23:09:59 andrew Exp $ | 
| use warnings; | use strict; | 
| use base 'Net::Telnet'; | use warnings; | 
|  | use base 'Net::Telnet'; | 
| =pod |  | 
|  | =pod | 
| =head1 NAME |  | 
|  | =head1 NAME | 
| Net::Telnet::Trango |  | 
| - Perl extension for accessing the Trango telnet interface | Net::Telnet::Trango | 
|  | - Perl extension for accessing the Trango telnet interface | 
| =head1 SYNOPSIS |  | 
|  | =head1 SYNOPSIS | 
| use Net::Telnet::Trango; |  | 
| my $t = new Net::Telnet::Trango ( Timeout => 5 ); | use Net::Telnet::Trango; | 
|  | my $t = new Net::Telnet::Trango ( Timeout => 5 ); | 
| $t->open( Host => $fox ) or die "Error connecting: $!"; |  | 
|  | $t->open( Host => $fox ) or die "Error connecting: $!"; | 
| $t->login('password') or die "Couldn't log in: $!"; |  | 
|  | $t->login('password') or die "Couldn't log in: $!"; | 
| # Do whatever |  | 
|  | # Do whatever | 
| $t->exit; |  | 
| $t->close; | $t->exit; | 
|  | $t->close; | 
| =head1 DESCRIPTION |  | 
|  | =head1 DESCRIPTION | 
| Perl access to the telnet interface on Trango Foxes, SUs and APs. |  | 
|  | Perl access to the telnet interface on Trango Foxes, SUs and APs. | 
| Another handy feature is that it will parse the output from certain |  | 
| commands that is in the format "[key1] value1 [key2] value2" and put | Another handy feature is that it will parse the output from certain | 
| those in a hashref that is returned.  This makes using the output from | commands that is in the format "[key1] value1 [key2] value2" and put | 
| things like sysinfo very easy to do. | those in a hashref that is returned.  This makes using the output from | 
|  | things like sysinfo very easy to do. | 
| =head2 EXPORT |  | 
|  | =head2 EXPORT | 
| None |  | 
|  | None | 
| =head1 METHODS |  | 
|  | =head1 METHODS | 
| =over |  | 
|  | =cut | 
| =cut |  | 
|  | our $VERSION = '0.01'; | 
| our $VERSION = '0.01'; |  | 
|  | my $EMPTY = q{}; | 
| my %PRIVATE = ( | my $SPACE = q{ }; | 
| is_connected => 0, |  | 
| logged_in => 0, | my %PRIVATE = ( | 
| ); | is_connected => 0, | 
|  | logged_in    => 0, | 
| =pod | ); | 
|  |  | 
| =item B<new> | =pod | 
|  |  | 
| - Creates a new Net::Telnet::Trango object. | =head2 B<new> - Creates a new Net::Telnet::Trango object. | 
|  |  | 
| new([Options from Net::Telnet,] | new([Options from Net::Telnet,] | 
| [Decode => 0,]); | [Decode => 0,]); | 
|  |  | 
| Same as new from L<Net::Telnet> but sets the default Trango Prompt: | Same as new from L<Net::Telnet> but sets the default Trango Prompt: | 
| '/#> *$/' | '/#> *$/' | 
|  |  | 
| It also takes an optional parameter 'Decode'.  If not defined it | It also takes an optional parameter 'Decode'.  If not defined it | 
| defaults to 1, if it is set to 0, it will not decode the output and | defaults to 1, if it is set to 0, it will not decode the output and | 
| instead return a reference to an array of the lines that were returned | instead return a reference to an array of the lines that were returned | 
| from the command. | from the command. | 
|  |  | 
| =cut | =cut | 
|  |  | 
| sub new | sub new { | 
| { | my $class = shift; | 
| my $class = shift; |  | 
|  | my %args; | 
| my %args; | if ( @_ == 1 ) { | 
| if (@_ == 1) { | $args{'Host'} = shift; | 
| $args{'Host'} = shift; | } | 
| } else { | else { | 
| %args = @_; | %args = @_; | 
| } | } | 
|  |  | 
| $args{'Prompt'}  ||= '/#> *$/'; | $args{'Prompt'} ||= '/#> *$/'; | 
|  |  | 
| foreach my $key (keys %args) { | foreach my $key ( keys %args ) { | 
| $PRIVATE{$key} = $args{$key}; | $PRIVATE{$key} = $args{$key}; | 
| } | } | 
| $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; | $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; | 
| delete $args{'Decode'}; | delete $args{'Decode'}; | 
|  |  | 
| my $self = $class->SUPER::new(%args); | my $self = $class->SUPER::new(%args); | 
| bless $self if ref $self; | bless $self if ref $self; | 
|  |  | 
| return $self; | return $self; | 
| } | } | 
|  |  | 
| #  _password <new password> <new password> | #  _password <new password> <new password> | 
| #  ? [command] | #  ? [command] | 
| #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]... | #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]... | 
| #  arp -bcast <on|off> | #  arp -bcast <on|off> | 
| #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ... | #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ... | 
| #  bye | #  bye | 
| #  cf2cf ap [default|<size>] | #  cf2cf ap [default|<size>] | 
| #  date | #  date | 
| #  date <month> <day> <year> | #  date <month> <day> <year> | 
| #  freq scantable | #  freq scantable | 
| #  freq channeltable | #  freq channeltable | 
| #  freq writescan [<ch#> <h|v>] | #  freq writescan [<ch#> <h|v>] | 
| #  freq writechannel [<ch#> <freq>] ... | #  freq writechannel [<ch#> <freq>] ... | 
| #  freq <ch #> <h|v> | #  freq <ch #> <h|v> | 
| #  help [command] | #  help [command] | 
| #  heater [<on temp> <off temp>] | #  heater [<on temp> <off temp>] | 
| #  ipconfig [<new ip> <new subnet mask> <new gateway>] | #  ipconfig [<new ip> <new subnet mask> <new gateway>] | 
| #  log [<# of entries, 1..179>] | #  log [<# of entries, 1..179>] | 
| #  log <sum> <# of entries, 1..179> | #  log <sum> <# of entries, 1..179> | 
| #  logout | #  logout | 
| #  opmode [ap [y]] | #  opmode [ap [y]] | 
| #  password | #  password | 
| #  ping <ip addr> | #  ping <ip addr> | 
| #  polar <h|v> | #  polar <h|v> | 
| #  power <setism|setunii> <max|min|<dBm>> | #  power <setism|setunii> <max|min|<dBm>> | 
| #  reboot | #  reboot | 
| #  restart | #  restart | 
| #  remarks [<str>] | #  remarks [<str>] | 
| #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>] | #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>] | 
| #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>] | #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>] | 
| #  sysinfo | #  sysinfo | 
| #  set suid <id> | #  set suid <id> | 
| #  set apid <id> | #  set apid <id> | 
| #  set baseid <id> | #  set baseid <id> | 
| #  set defaultopmode [<ap|su> <min,0..10>] | #  set defaultopmode [<ap|su> <min,0..10>] | 
| #  set defaultopmode off | #  set defaultopmode off | 
| #  set snmpcomm [<read | write | trap (id or setall)> <str>] | #  set snmpcomm [<read | write | trap (id or setall)> <str>] | 
| #  set mir [on|off] | #  set mir [on|off] | 
| #  set mir threshold <kbps> | #  set mir threshold <kbps> | 
| #  set rssitarget [<ism|unii> <dBm>] | #  set rssitarget [<ism|unii> <dBm>] | 
| #  set serviceradius [<ism | unii> <miles>] | #  set serviceradius [<ism | unii> <miles>] | 
| #  ssrssi <ch #> <h|v> | #  ssrssi <ch #> <h|v> | 
| #  su [<suid>|all] | #  su [<suid>|all] | 
| #  su changechannel <all|suid> <ch#> <h|v> | #  su changechannel <all|suid> <ch#> <h|v> | 
| #  su ipconfig <suid> <new ip> <new subnet> <new gateway> | #  su ipconfig <suid> <new ip> <new subnet> <new gateway> | 
| #  su [live|poweroff|priority] | #  su [live|poweroff|priority] | 
| #  su <ping|info|status> <suid> | #  su <ping|info|status> <suid> | 
| #  su powerleveling <all|suid> | #  su powerleveling <all|suid> | 
| #  su reboot <all|suid> | #  su reboot <all|suid> | 
| #  su restart <all|suid> | #  su restart <all|suid> | 
| #  su testrflink <all|suid> [r] | #  su testrflink <all|suid> [r] | 
| #  su testrflink <setlen> [64..1600] | #  su testrflink <setlen> [64..1600] | 
| #  su testrflink <aptx> [20..100] | #  su testrflink <aptx> [20..100] | 
| #  su sw <suid|all> <sw #> <on|off> | #  su sw <suid|all> <sw #> <on|off> | 
| #  sudb [dload | view] | #  sudb [dload | view] | 
| #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex> | #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex> | 
| #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex> | #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex> | 
| #  sudb delete <all|<suid>> | #  sudb delete <all|<suid>> | 
| #  sudb modify <suid> <cir|mir> <kbps> | #  sudb modify <suid> <cir|mir> <kbps> | 
| #  sudb modify <suid> <su2su> <group id,hex> | #  sudb modify <suid> <su2su> <group id,hex> | 
| #  sudb view | #  sudb view | 
| #  sulog [lastmins | sampleperiod <1..60>] | #  sulog [lastmins | sampleperiod <1..60>] | 
| #  sulog [<# of entry,1..18>] | #  sulog [<# of entry,1..18>] | 
| #  survey <ism|unii> <time, sec> <h|v> | #  survey <ism|unii> <time, sec> <h|v> | 
| #  sw [<sw #> <on|off>] | #  sw [<sw #> <on|off>] | 
| #  temp | #  temp | 
| #  tftpd [on|off] | #  tftpd [on|off] | 
| #  time | #  time | 
| #  time <hour> <min> <sec> | #  time <hour> <min> <sec> | 
| #  save <mainimage|fpgaimage> <current chksum> <new chksum> | #  save <mainimage|fpgaimage> <current chksum> <new chksum> | 
| #  save <systemsetting|sudb> | #  save <systemsetting|sudb> | 
| #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum> | #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum> | 
| #  updateflash <systemsetting|sudb> | #  updateflash <systemsetting|sudb> | 
|  |  | 
| =pod | =pod | 
|  |  | 
| =back | =head1 ACCESSORS | 
|  |  | 
| =head2 ACCESSORS | These are usually only set internally. | 
|  |  | 
| These are usually only set internally. | =head2 B<firmware_version> - returns the firmware version | 
|  |  | 
| =over | Returns the firmware version if available, otherwise undef. | 
|  |  | 
| =item B<firmware_version> | It should be available after a successful open(). | 
|  |  | 
| - returns the firmware version | =head2 B<host_type> - return the type of host you are connected to. | 
|  |  | 
| Returns the firmware version if available, otherwise undef. | returns the type of host from the login banner for example M5830S or M5300S. | 
|  |  | 
| It should be available after a successful open(). | Should be available after a successful open(). | 
|  |  | 
| =item B<host_type> | =head2 B<is_connected> - Status of the connection to host. | 
|  |  | 
| - return the type of host you are connected to. | returns 1 when connected, undef otherwise. | 
|  |  | 
| returns the type of host from the login banner for example M5830S or M5300S. | =head2 B<logged_in> - Status of being logged in to the host. | 
|  |  | 
| Should be available after a successful open(). | returns 1 after a successful login(), 0 if it failed and undef if | 
|  | login() was never called. | 
| =item B<is_connected> |  | 
|  | =head2 B<login_banner> - The banner when first connecting to the host. | 
| - Status of the connection to host. |  | 
|  | returns the banner that is displayed when first connected at login. | 
| returns 1 when connected, undef otherwise. | Only set after a successful open(). | 
|  |  | 
| =item B<logged_in> | =head2 B<last_lines> - The last lines of output from the last cmd(). | 
|  |  | 
| - Status of being logged in to the host. | returns, as an array ref, the output from the last cmd() that was run. | 
|  |  | 
| returns 1 after a successful login(), 0 if it failed and undef if | =head2 B<last_error> - A text output of the last error that was encountered. | 
| login() was never called. |  | 
|  | returns the last error reported.  Probably contains the last entry in | 
| =item B<login_banner> | last_lines. | 
|  |  | 
| - The banner when first connecting to the host. | =head1 ALIASES | 
|  |  | 
| returns the banner that is displayed when first connected at login. | =head2 B<bye> - alias of exit() | 
| Only set after a successful open(). |  | 
|  | Does the same as exit() | 
| =item B<last_lines> |  | 
|  | =head2 B<restart> - alias of reboot() | 
| - The last lines of output from the last cmd(). |  | 
|  | Does the same as reboot() | 
| returns, as an array ref, the output from the last cmd() that was run. |  | 
|  | =head2 B<save_systemsetting> - alias of save_ss() | 
| =item B<last_error> |  | 
|  | Does the same as save_ss() | 
| - A text output of the last error that was encountered. |  | 
|  | =head1 COMMANDS | 
| returns the last error reported.  Probably contains the last entry in |  | 
| last_lines. | Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>, | 
|  | as such they accept the same options as C<cmd()>. | 
| =back | Specifically they take a named paramater "args", for example: | 
|  | C<tftpd(args =E<gt> 'on')> would enable tftpd | 
| =head2 ALIASES |  | 
|  | =head2 B<tftpd> - The output from the tftpd command | 
| =over |  | 
|  | Returns a hash ref of the decoded output from the | 
| =item B<bye> | command. | 
|  |  | 
| - alias of L<exit()>. | Also see enable_tftpd() and disable_tftpd() as those check that it was | 
|  | successfully changed. | 
| =item B<restart> |  | 
|  | =head2 B<ver> - The output from the ver command | 
| - alias of L<reboot()>. |  | 
|  | Returns a hash ref of the decoded output from the | 
| =back | command. | 
|  |  | 
| =head2 COMMANDS | =head2 B<sysinfo> - The output from the sysinfo command | 
|  |  | 
| Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>, | Returns a hash ref of the decoded output from the | 
| as such they accept the same options as C<cmd()>. | command. | 
| Specifically they take a named paramater "args", for example: |  | 
| C<tftpd(args =E<gt> 'on')> would enable tftpd | =head2 B<exit> - Exits the connection | 
|  |  | 
| =over | exits the command session with the Trango and closes | 
|  | the connection | 
| =item B<tftpd> |  | 
|  | =head2 B<reboot> - Sends a reboot command | 
| - Returns a hash ref of the decoded output from the |  | 
| command. | reboots the Trango and closes the connection | 
|  |  | 
| Also see enable_tftpd() and disable_tftpd() as those check that it was | =head2 B<remarks> - Set or retrieve the remarks. | 
| successfully changed. |  | 
|  | Takes an optional argument, which sets the remarks. | 
| =item B<ver> | If there is no argument, returns the current remarks. | 
|  |  | 
| - Returns a hash ref of the decoded output from the | my $old_remarks = $t->remarks(); | 
| command. | $t->remarks($new_remarks); | 
|  |  | 
| =item B<sysinfo> | =head2 B<sulog> - The output from the sulog command | 
|  |  | 
| - Returns a hash ref of the decoded output from the | Returns an array ref of hashes containing each log | 
| command. | line. | 
|  |  | 
| =item B<exit> | =head2 B<save_sudb> - saves the sudb | 
|  |  | 
| - exits the command session with the Trango and closes | Returns true on success, undef on failure | 
| the connection |  | 
|  | =head2 B<syslog> - The output from the sulog command | 
| =item B<reboot> |  | 
|  | Returns a hashref of the output from the syslog command | 
| - reboots the Trango and closes the connection |  | 
|  | =head2 B<pipe> - the pipe command | 
| =item B<remarks> |  | 
|  | Returns the output from the pipe command | 
| - Set or retrieve the remarks. |  | 
|  | =head2 B<maclist> - retrieves the maclist | 
| Takes an optional argument, which sets the remarks. |  | 
| If there is no argument, returns the current remarks. | Returns the output from the maclist command | 
|  |  | 
| my $old_remarks = $t->remarks(); | =head2 B<maclist_reset> - resets the maclist. | 
| $t->remarks($new_remarks); |  | 
|  | No useful output. | 
| =item B<sulog> |  | 
|  | =head2 B<eth_list> - eth list command | 
| - returns an array ref of hashes containing each log |  | 
| line. | Returns the output from the eth list command | 
|  |  | 
| =item B<save_sudb> |  | 
|  | =head2 B<su_info> - gets the su info | 
| - returns true on success, undef on failure |  | 
|  | Returns information about the SU. | 
| =item B<syslog> |  | 
|  | You need to pass in the $suid and it will return the info for that suid. | 
| - returns the output from the syslog command |  | 
|  | $t->su_info($suid); | 
| =item B<pipe> |  | 
|  | =head2 B<su_testrflink> - tests the RF Link to an su | 
| - returns the output from the pipe command |  | 
|  | $t->su_testrflink($suid|'all'); | 
| =item B<maclist> |  | 
|  | =head2 B<save_ss> - saves the config. | 
| -  returns the output from the maclist command |  | 
|  | Returns 1 on success, undef on failure. | 
| =item B<maclist_reset> |  | 
|  | =head2 B<opmode> - sets opmode ap y or returns the opmode | 
| - resets the maclist. |  | 
|  | $t->opmode([ap y]); | 
| No useful output. |  | 
|  | =cut | 
| =item B<eth_list> |  | 
|  | my $success  = 'Success\\.'; | 
| - returns the output from the eth list command | my %COMMANDS = ( | 
|  | tftpd       => { decode    => 'all',       expect          => $success }, | 
| =item B<su_info> | ver         => { decode    => 'all' }, | 
|  | sysinfo     => { decode    => 'all',       expect          => $success }, | 
| - returns information about the SU. | updateflash => { decode    => 'all',       expect          => $success }, | 
|  | sulog       => { decode    => 'sulog',     expect          => $success }, | 
| You need to pass in the $suid and it will return the info for that suid. | 'exit'      => { no_prompt => 1,           cmd_disconnects => 1 }, | 
|  | reboot      => { no_prompt => 1,           cmd_disconnects => 1 }, | 
| $t->su_info($suid); | remarks     => { decode    => 'all',       expect          => $success }, | 
|  | save_sudb   => { String    => 'save sudb', expect          => $success }, | 
| =item B<save_ss> | syslog      => { expect    => $success }, | 
|  | 'pipe'      => {},                        # XXX needs a special decode | 
| - saves the config. | maclist     => { decode => 'maclist' }, | 
|  | maclist_reset => { String => 'maclist reset', expect       => 'done' }, | 
| Returns 1 on success, undef on failure. | eth_link    => { String => 'eth link',     expect          => $success }, | 
|  | su_info     => | 
| =cut | { String => 'su info',  decode => 'all', expect          => $success }, | 
|  | su_testrflink => | 
|  | { String => 'su testrflink', decode => 'each', expect    => $success }, | 
| my $success = 'Success\\.'; | save_ss     => { String => 'save ss',      expect          => $success }, | 
| my %COMMANDS = ( | opmode      => { decode => 'all',          expect          => $success }, | 
| tftpd       => { decode => 'all',   expect => $success }, | ); | 
| ver         => { decode => 'all' }, |  | 
| sysinfo     => { decode => 'all',   expect => $success }, | my %ALIASES = ( | 
| updateflash => { decode => 'all',   expect => $success }, | bye     => 'exit', | 
| sulog       => { decode => 'sulog', expect => $success }, | restart => 'reboot', | 
| 'exit'      => { no_prompt => 1, cmd_disconnects => 1 }, | Host    => 'host', | 
| reboot      => { no_prompt => 1, cmd_disconnects => 1 }, | save_systemseting => 'save_ss', | 
| remarks     => { decode => 'all', expect => $success }, | ); | 
| save_sudb   => { String => 'save sudb', expect => $success }, |  | 
| syslog      => { expect => $success }, | my %ACCESS = map { $_ => 1 } qw( | 
| 'pipe'      => { }, # XXX needs a special decode | firmware_version | 
| maclist     => { decode => 'maclist' }, | host_type | 
| maclist_reset => { String => 'maclist reset', expect => 'done' }, | is_connected | 
| eth_link    => { String => 'eth link', expect => $success }, | logged_in | 
| su_info     => { String => 'su info', decode => 'all', expect => $success }, | login_banner | 
| save_ss     => { String => 'save ss', expect => $success }, | Timeout | 
| opmode      => { decode => 'all',   expect => $success }, | last_lines | 
| # eth r, w and reset??? | last_vals | 
| #su password??? | last_error | 
| #_bootloader | Decode | 
| #temp | ); | 
| #heater |  | 
| ); | sub AUTOLOAD { | 
|  | my $self = shift; | 
| my %ALIASES = ( |  | 
| bye     => 'exit', | my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/ | 
| restart => 'reboot', | or die "Weird: $AUTOLOAD"; | 
| Host    => 'host', |  | 
| ); | if ( exists $ALIASES{$method} ) { | 
|  | $method = $ALIASES{$method}; | 
| my %ACCESS = map { $_ => 1 } qw( | return $self->$method(@_); | 
| firmware_version | } | 
| host_type |  | 
| is_connected | if ( exists $COMMANDS{$method} ) { | 
| logged_in | my %cmd; | 
| login_banner | foreach my $k ( keys %{ $COMMANDS{$method} } ) { | 
| Timeout | $cmd{$k} = $COMMANDS{$method}{$k}; | 
| last_lines | } | 
| last_vals | $cmd{'String'} ||= $method; | 
| last_error | $cmd{'args'} .= $SPACE . shift if ( @_ == 1 ); | 
| Decode | return $self->cmd( %cmd, @_ ); | 
| ); | } | 
|  |  | 
| sub AUTOLOAD | if ( exists $ACCESS{$method} ) { | 
| { | my $prev = $PRIVATE{$method}; | 
| my $self = shift; | ( $PRIVATE{$method} ) = @_ if @_; | 
|  | return $prev; | 
| my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/ | } | 
| or die "Weird: $AUTOLOAD"; |  | 
|  | $method = "SUPER::$method"; | 
| if (exists $ALIASES{$method}) { | return $self->$method(@_); | 
| $method = $ALIASES{$method}; | } | 
| return $self->$method(@_); |  | 
| } | =pod | 
|  |  | 
| if (exists $COMMANDS{$method}) { | =head2 B<open> - Open a connection to a Trango AP. | 
| $COMMANDS{$method}{'String'} ||= $method; |  | 
| $COMMANDS{$method}{'args'} .= ' ' . shift if (@_ == 1); | Calls Net::Telnet::open() then makes sure you get a password prompt so | 
| return $self->cmd(%{ $COMMANDS{$method} }, @_); | you are ready to login() and parses the login banner so you can get | 
| } | host_type() and firmware_version() | 
|  |  | 
| if (exists $ACCESS{$method}) { | =cut | 
| my $prev = $PRIVATE{$method}; |  | 
| ($PRIVATE{$method}) = @_ if @_; | sub open { | 
| return $prev; | my $self = shift; | 
| } |  | 
|  | unless ( $self->SUPER::open(@_) ) { | 
| $method = "SUPER::$method"; | $self->last_error( "Couldn't connect to " . $self->host . ":  $!" ); | 
| return $self->$method(@_); | return; | 
| } | } | 
|  |  | 
| =pod | ## Get to login prompt | 
|  | unless ( | 
| =item B<open> | $self->waitfor( | 
|  | -match   => '/password: ?$/i', | 
| - Open a connection to a Trango AP. | -errmode => "return", | 
|  | ) | 
| Calls Net::Telnet::open() then makes sure you get a password prompt so | ) | 
| you are ready to login() and parses the login banner so you can get | { | 
| host_type() and firmware_version() | $self->last_error( "problem connecting to host (" | 
|  | . $self->host . "): " | 
| =cut | . $self->lastline ); | 
|  | return; | 
| sub open | } | 
| { |  | 
| my $self = shift; | $self->parse_login_banner( $self->lastline ); | 
|  |  | 
| unless ( $self->SUPER::open(@_) ) { | $self->is_connected(1); | 
| $self->last_error("Couldn't connect to " . $self->host . ":  $!"); |  | 
| return; | return $self->is_connected; | 
| } | } | 
|  |  | 
| ## Get to login prompt | =pod | 
| unless ($self->waitfor( |  | 
| -match => '/password: ?$/i', | =head2 B<login> - Login to the AP. | 
| -errmode => "return", |  | 
| ) ) { | Calls open() if not already connected, then sends the password and sets | 
| $self->last_error("problem connecting to host (" . $self->host . "): " . | logged_in() if successful | 
| $self->lastline); |  | 
| return; | =cut | 
| } |  | 
|  | sub login { | 
| $self->parse_login_banner($self->lastline); | my $self = shift; | 
|  |  | 
| $self->is_connected(1); | unless ( $self->is_connected ) { | 
|  | $self->open or return; | 
| return $self->is_connected; | } | 
| } |  | 
|  | my $password = shift; | 
| =pod |  | 
|  | $self->print($password); | 
| =item B<login> | unless ( | 
|  | $self->waitfor( | 
| - Login to the AP. | -match   => $self->prompt, | 
|  | -errmode => "return", | 
| Calls open() if not already connected, then sends the password and sets | ) | 
| logged_in() if successful | ) | 
|  | { | 
| =cut | $self->last_error( "login ($self->host) failed: " . $self->lastline ); | 
|  | return; | 
| sub login | } | 
| { |  | 
| my $self = shift; | $self->logged_in(1); | 
|  |  | 
| unless ($self->is_connected) { | return $self->logged_in; | 
| $self->open or return; | } | 
| } |  | 
|  | =pod | 
| my $password = shift; |  | 
|  | =head2 B<parse_login_banner> - Converts the login_banner to something useful. | 
| $self->print($password); |  | 
| unless ($self->waitfor( | Takes a login banner (what you get when you first connect to the Trango) | 
| -match => $self->prompt, | or reads what is already in login_banner() then parses it and sets | 
| -errmode => "return", | host_type() and firmware_version() as well as login_banner() | 
| ) ) { |  | 
| $self->last_error("login ($self->host) failed: " . $self->lastline); | =cut | 
| return; |  | 
| } | sub parse_login_banner { | 
|  | my $self = shift; | 
| $self->logged_in(1); |  | 
|  | if (@_) { | 
| return $self->logged_in; | $self->login_banner(@_); | 
| } | } | 
|  |  | 
| =pod | my $banner = $self->login_banner; | 
|  |  | 
| =item B<parse_login_banner> | my ( $type, $sep1, $subtype, $sep2, $ver ) = | 
|  | $banner =~ | 
| - Converts the login_banner to some useful | /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i; | 
| variables. |  | 
|  | $type .= $sep1 . $subtype; | 
| Takes a login banner (what you get when you first connect to the Trango) | $ver = $subtype . $sep2 . $ver; | 
| or reads what is already in login_banner() then parses it and sets |  | 
| host_type() and firmware_version() as well as login_banner() | $self->login_banner($banner); | 
|  | $self->host_type($type); | 
| =cut | $self->firmware_version($ver); | 
|  |  | 
| sub parse_login_banner | return 1; | 
| { | } | 
| my $self = shift; |  | 
|  | =pod | 
| if (@_) { |  | 
| $self->login_banner(@_); | =head2 B<su_password> - Set the password on SUs connected to the AP. | 
| } |  | 
|  | su_password('new_password'[, 'suid']) If no suid is specified, | 
| my $banner = $self->login_banner; | the default is "all". | 
|  |  | 
| my ($type, $sep1, $subtype, $sep2, $ver) = $banner =~ | $t->su_password('good_pass', 5); | 
| /Welcome to Trango Broadband Wireless (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i; |  | 
|  | =cut | 
| $type .= $sep1 . $subtype; |  | 
| $ver = $subtype . $sep2 . $ver; | sub su_password { | 
|  | my $self     = shift; | 
| $self->login_banner($banner); | my $new_pass = shift || $EMPTY; | 
| $self->host_type($type); | my $su       = shift || 'all'; | 
| $self->firmware_version($ver); |  | 
|  | unless ( defined $new_pass ) { | 
| return 1; | $self->last_error("No new password"); | 
| } |  | 
|  | #return; | 
| =pod | } | 
|  |  | 
| =item B<su_password> | return $self->cmd( | 
|  | String => 'su password ' . $su . $SPACE . $new_pass . $SPACE . $new_pass, | 
| - Set the password on SUs connected to the AP. | expect => $success, | 
|  | ); | 
| su_password('new_password'[, 'suid']) If no suid is specified, | } | 
| the default is "all". |  | 
|  | =pod | 
| $t->su_password('good_pass', 5); |  | 
|  | =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP. | 
| =cut |  | 
|  | su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' ) | 
| sub su_password |  | 
| { | $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' ); | 
| my $self     = shift; |  | 
| my $new_pass = shift || ''; | =cut | 
| my $su       = shift || 'all'; |  | 
|  | sub su_ipconfig { | 
| unless (defined $new_pass) { | my $self = shift; | 
| $self->last_error("No new password"); |  | 
| #return; | my $suid        = shift; | 
| } | my $new_ip      = shift; | 
|  | my $new_subnet  = shift; | 
| return $self->cmd(String => 'su password ' . | my $new_gateway = shift; | 
| $su . ' ' . |  | 
| $new_pass . ' ' . | if ( $suid =~ /\D/ ) { | 
| $new_pass, | $self->last_error("Invalid suid '$suid'"); | 
| expect => $success, | return; | 
| ); | } | 
| } | unless ($new_ip) { | 
|  | $self->last_error("no new_ip passed"); | 
| =pod | return; | 
|  | } | 
| =item B<su_ipconfig> | unless ($new_subnet) { | 
|  | $self->last_error("no new_subnet passed"); | 
| - Change IP configuration on SUs connected to | return; | 
| the AP. | } | 
|  | unless ($new_gateway) { | 
| su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' ) | $self->last_error("no new_gateway passed"); | 
|  | return; | 
| $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' ); | } | 
|  |  | 
| =cut | # su ipconfig <suid> <new ip> <new subnet> <new gateway> | 
|  | return $self->cmd( | 
| sub su_ipconfig | String => 'su ipconfig ' . $suid . $SPACE . $new_ip . $SPACE | 
| { | . $new_subnet . $SPACE | 
| my $self        = shift; | . $new_gateway, | 
|  | expect => $success, | 
| my $suid        = shift; | ); | 
| my $new_ip      = shift; | } | 
| my $new_subnet  = shift; |  | 
| my $new_gateway = shift; | =pod | 
|  |  | 
| if ($suid =~ /\D/) { | =head2 B<sudb_view> - Returns the output from the sudb view command | 
| $self->last_error("Invalid suid '$suid'"); |  | 
| return; | returns a reference to an array of hashes each containing these keys | 
| } | 'suid', 'type', 'cir', 'mir' and 'mac' | 
| unless ($new_ip) { |  | 
| $self->last_error("no new_ip passed"); | =cut | 
| return; |  | 
| } | sub sudb_view { | 
| unless ($new_subnet) { | my $self = shift; | 
| $self->last_error("no new_subnet passed"); |  | 
| return; | my $lines = $self->cmd( String => 'sudb view', expect => $success ) || []; | 
| } |  | 
| unless ($new_gateway) { | return unless @{$lines}; | 
| $self->last_error("no new_gateway passed"); |  | 
| return; | unless ( $PRIVATE{'Decode'} ) { | 
| } | return $lines; | 
|  | } | 
| # su ipconfig <suid> <new ip> <new subnet> <new gateway> |  | 
| return $self->cmd(String => 'su ipconfig ' . | my @sus; | 
| $suid       . ' ' . | foreach ( @{$lines} ) { | 
| $new_ip     . ' ' . | next unless $_; | 
| $new_subnet . ' ' . | if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { | 
| $new_gateway, | my %s = ( | 
| expect => $success, | suid => $1, | 
| ); | type => $2, | 
| } | cir  => $3, | 
|  | mir  => $4, | 
| =pod | mac  => $5, | 
|  | ); | 
| =item B<sudb_view> |  | 
|  | $s{'mac'} =~ s/\s//g; | 
| - Returns the output from the sudb view command | $s{'mac'} = uc( $s{'mac'} ); | 
|  |  | 
| returns a reference to an array of hashes each containing these keys | push @sus, \%s; | 
| 'suid', 'type', 'cir', 'mir' and 'mac' | } | 
|  | } | 
| =cut |  | 
|  | return \@sus; | 
| sub sudb_view | } | 
| { |  | 
| my $self = shift; | =pod | 
|  |  | 
| my $lines = $self->cmd( String => 'sudb view', expect => $success ) || []; | =head2 B<sudb_add> - Adds an su to the sudb | 
|  |  | 
| return unless @{ $lines }; | Takes the following paramaters | 
|  |  | 
| unless ($PRIVATE{'Decode'}) { | suid : numeric, | 
| return $lines; | type : (reg|pr) | 
| } | cir  : numeric, | 
|  | mir  : numeric, | 
| my @sus; | mac  : Almost any format, it will be reformatted, | 
| foreach (@{ $lines }) { |  | 
| next unless $_; | and returns true on success or undef otherwise. | 
| if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { |  | 
| my %s = ( | $t->sudb_add($suid, 'reg', $cir, $mir, $mac); | 
| suid => $1, |  | 
| type => $2, | You should save_sudb() after calling this, or your changes  will be lost | 
| cir  => $3, | when the AP is rebooted. | 
| mir  => $4, |  | 
| mac  => $5, | =cut | 
| ); |  | 
|  | sub sudb_add { | 
| $s{'mac'} =~ s/\s//g; | my $self = shift; | 
| $s{'mac'} = uc($s{'mac'}); | my $suid = shift; | 
|  | my $type = shift; | 
| push @sus, \%s; | my $cir  = shift; | 
| } | my $mir  = shift; | 
| } | my $mac  = shift; | 
|  |  | 
| return \@sus; | if ( $suid =~ /\D/ ) { | 
| } | $self->last_error("Invalid suid '$suid'"); | 
|  | return; | 
| =pod | } | 
|  |  | 
| =item B<sudb_add> | unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) { | 
|  | $self->last_error("Invalid type '$type'"); | 
| Takes the following paramaters | return; | 
|  | } | 
| suid : numeric, |  | 
| type : (reg|pr) | if ( $cir =~ /\D/ ) { | 
| cir  : numeric, | $self->last_error("Invalid CIR '$cir'"); | 
| mir  : numeric, | return; | 
| mac  : Almost any format, it will be reformatted, | } | 
|  |  | 
| and returns true on success or undef otherwise. | if ( $mir =~ /\D/ ) { | 
|  | $self->last_error("Invalid MIR '$mir'"); | 
| $t->sudb_add($suid, 'reg', $cir, $mir, $mac); | return; | 
|  | } | 
| You should save_sudb() after calling this, or your changes  will be lost |  | 
| when the AP is rebooted. | my $new_mac = $mac; | 
|  | $new_mac =~ s/[^0-9A-Fa-f]//; | 
| =cut | unless ( length $new_mac == 12 ) { | 
|  | $self->last_error("Invalid MAC '$mac'"); | 
| sub sudb_add | return; | 
| { | } | 
| my $self = shift; | $new_mac = join $SPACE, $new_mac =~ /../g; | 
| my $suid = shift; |  | 
| my $type = shift; | my $string = | 
| my $cir  = shift; | 'sudb add ' . $suid . $SPACE . $type . $SPACE . $cir . $SPACE . $mir . $SPACE | 
| my $mir  = shift; | . $new_mac; | 
| my $mac  = shift; |  | 
|  | return $self->cmd( String => $string, expect => $success ); | 
| if ($suid =~ /\D/) { | } | 
| $self->last_error("Invalid suid '$suid'"); |  | 
| return; | =pod | 
| } |  | 
|  | =head2 B<sudb_delete> - removes an su from the sudb | 
| unless (lc($type) eq 'reg' || lc($type) eq 'pr') { |  | 
| $self->last_error("Invalid type '$type'"); | Takes either 'all' or the  suid of the su to delete | 
| return; | and returns true on success or undef otherwise. | 
| } |  | 
|  | $t->sudb_delete($suid); | 
| if ($cir =~ /\D/) { |  | 
| $self->last_error("Invalid CIR '$cir'"); | You should save_sudb() after calling this, or your changes  will be lost | 
| return; | when the AP is rebooted. | 
| } |  | 
|  | =cut | 
| if ($mir =~ /\D/) { |  | 
| $self->last_error("Invalid MIR '$mir'"); | sub sudb_delete { | 
| return; | my $self = shift; | 
| } | my $suid = shift; | 
|  |  | 
| my $new_mac = $mac; | #if (lc($suid) ne 'all' || $suid =~ /\D/) { | 
| $new_mac =~ s/[^0-9A-Fa-f]//; | if ( $suid =~ /\D/ ) { | 
| unless (length $new_mac == 12) { | $self->last_error("Invalid suid '$suid'"); | 
| $self->last_error("Invalid MAC '$mac'"); | return; | 
| return; | } | 
| } |  | 
| $new_mac = join ' ', $new_mac =~ /../g; | return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); | 
|  | } | 
| my $string = 'sudb add ' . |  | 
| $suid . ' ' . | =pod | 
| $type . ' ' . |  | 
| $cir  . ' ' . | =head2 B<sudb_modify> - changes the su information in the sudb | 
| $mir  . ' ' . |  | 
| $new_mac; | Takes either the  suid of the su to change | 
|  | as well as what you are changing, either "cir, mir or su2su" | 
|  | and returns true on success or undef otherwise. | 
| return $self->cmd( String => $string, expect => $success ); |  | 
| } | cir and mir also take a value to set the cir/mir to. | 
|  |  | 
| =pod | su2su takes a group id parameter that is in hex. | 
|  |  | 
| =item B<sudb_delete> | $t->sudb_modify($suid, 'cir', 512); | 
|  |  | 
| Takes either 'all' or the  suid of the su to delete | You should save_sudb() after calling this, or your changes  will be lost | 
| and returns true on success or undef otherwise. | when the AP is rebooted. | 
|  |  | 
| $t->sudb_delete($suid); | =cut | 
|  |  | 
| You should save_sudb() after calling this, or your changes  will be lost | sub sudb_modify { | 
| when the AP is rebooted. | my $self  = shift; | 
|  | my $suid  = shift; | 
| =cut | my $opt   = shift; | 
|  | my $value = shift; | 
| sub sudb_delete |  | 
| { | if ( $suid =~ /\D/ ) { | 
| my $self = shift; | $self->last_error("Invalid suid '$suid'"); | 
| my $suid = shift; | return; | 
|  | } | 
| #if (lc($suid) ne 'all' || $suid =~ /\D/) { |  | 
| if ($suid =~ /\D/) { | if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) { | 
| $self->last_error("Invalid suid '$suid'"); | if ( $value =~ /\D/ ) { | 
| return; | $self->last_error("Invalid $opt '$value'"); | 
| } | return; | 
|  | } | 
| return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); | } | 
| } | elsif ( lc($opt) eq 'su2su' ) { | 
|  | if ( $value =~ /[^0-9A-Za-f]/ ) { | 
| =pod | $self->last_error("Invalid MAC '$value'"); | 
|  | return; | 
| =item B<sudb_modify> | } | 
|  | } | 
| Takes either the  suid of the su to change | else { | 
| as well as what you are changing, either "cir, mir or su2su" | $self->last_error("Invalid option '$opt'"); | 
| and returns true on success or undef otherwise. | return; | 
|  | } | 
| cir and mir also take a value to set the cir/mir to. |  | 
|  | my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value; | 
| su2su takes a group id parameter that is in hex. |  | 
|  | return $self->cmd( String => $string, expect => $success ); | 
| $t->sudb_modify($suid, 'cir', 512); | } | 
|  |  | 
| You should save_sudb() after calling this, or your changes  will be lost | =pod | 
| when the AP is rebooted. |  | 
|  | =head2 B<enable_tftpd> - enable the TFTP server | 
| =cut |  | 
|  | runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing | 
| sub sudb_modify |  | 
| { | =cut | 
| my $self  = shift; |  | 
| my $suid  = shift; | sub enable_tftpd { | 
| my $opt   = shift; | my $self = shift; | 
| my $value = shift; |  | 
|  | my $vals = $self->tftpd( args => 'on' ); | 
| if ($suid =~ /\D/) { |  | 
| $self->last_error("Invalid suid '$suid'"); | if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) { | 
| return; | return $vals; | 
| } | } | 
|  | else { | 
| if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { | return; | 
| if ($value =~ /\D/) { | } | 
| $self->last_error("Invalid $opt '$value'"); | } | 
| return; |  | 
| } | =pod | 
| } elsif (lc($opt) eq 'su2su') { |  | 
| if ($value =~ /[^0-9A-Za-f]/) { | =head2 B<disable_tftpd> - disable the TFTP server | 
| $self->last_error("Invalid MAC '$value'"); |  | 
| return; | runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled' | 
| } |  | 
| } else { | =cut | 
| $self->last_error("Invalid option '$opt'"); |  | 
| return; | sub disable_tftpd { | 
| } | my $self = shift; | 
|  |  | 
| my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; | my $vals = $self->tftpd( args => 'off' ); | 
|  |  | 
| return $self->cmd( String => $string, expect => $success ); | if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) { | 
| } | return $vals; | 
|  | } | 
| =pod | else { | 
|  | return; | 
| =item B<enable_tftpd> | } | 
|  | } | 
| - enable the TFTP server |  | 
|  | =pod | 
| runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing |  | 
|  | =head2 B<cmd> - runs a command on the AP. | 
| =cut |  | 
|  | This does most of the work.  At the heart, it calls Net::Telnet::cmd() | 
| sub enable_tftpd | but it also does some special stuff for Trango. | 
| { |  | 
| my $self = shift; | Normally returns the last lines from from the command | 
|  |  | 
| my $vals = $self->tftpd( args => 'on' ); | If you are using this, rather than one of the "easy" methods above, | 
|  | you probably want to read through the source of this module to see how | 
| if ($vals->{'Tftpd'} eq 'listen') { | some of the other commands are called. | 
| return $vals; |  | 
| } else { | In addition to the Net::Telnet::cmd() options, it also accepts these: | 
| return; |  | 
| } | I<decode> | 
| } | - if this is true, then it will send the output lines to _decode_lines() | 
|  | and then returns the decoded output | 
| =pod |  | 
|  | I<no_prompt> | 
| =item B<disable_tftpd> | - if this is true, it does not wait for a prompt, so you are not stuck | 
|  | waiting for something that will never happen. | 
| - disable the TFTP server |  | 
|  | I<cmd_disconnects> | 
| runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled' | - if this is true, it then sets logged_in() to false, then it will | 
|  | close() the connection and set is_connected() to false | 
| =cut |  | 
|  | I<expect> | 
| sub disable_tftpd | - if this is set (usually to 'Success.') it will check for that in the | 
| { | last line of output and if it does not, will return undef because the | 
| my $self = shift; | command probably failed | 
|  |  | 
| my $vals = $self->tftpd( args => 'off' ); | I<args> | 
|  | - a string containing the command line options that are passed to the | 
| if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') { | command | 
| return $vals; |  | 
| } else { | $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 ); | 
| return; |  | 
| } | =cut | 
| } |  | 
|  | sub cmd { | 
| =pod | my $self = shift; | 
|  |  | 
| =item B<cmd> | my @valid_net_telnet_opts = qw( | 
|  | String | 
| - runs a command on the AP. | Output | 
|  | Cmd_remove_mode | 
| This does most of the work.  At the heart, it calls Net::Telnet::cmd() | Errmode | 
| but it also does some special stuff for Trango. | Input_record_separator | 
|  | Ors | 
| Normally returns the last lines from from the command | Output_record_separator | 
|  | Prompt | 
| If you are using this, rather than one of the "easy" methods above, | Rs | 
| you probably want to read through the source of this module to see how | Timeout | 
| some of the other commands are called. | ); | 
|  |  | 
| In addition to the Net::Telnet::cmd() options, it also accepts these: | my %cfg; | 
|  | if ( @_ == 1 ) { | 
| I<decode> | $cfg{'String'} = shift; | 
|  | } | 
| - if this is true, then it will send the output lines to _decode_lines() | elsif ( @_ > 1 ) { | 
| and then returns the decoded output | %cfg = @_; | 
|  | } | 
| I<no_prompt> |  | 
|  | $cfg{'Timeout'} ||= $self->Timeout; | 
| - if this is true, it does not wait for a prompt, so you are not stuck |  | 
| waiting for something that will never happen. | unless ( $cfg{'String'} ) { | 
|  | $self->last_error("No command passed"); | 
| I<cmd_disconnects> | return; | 
|  | } | 
| - if this is true, it then sets logged_in() to false, then it will |  | 
| close() the connection and set is_connected() to false | unless ( $self->is_connected ) { | 
|  | $self->last_error("Not connected"); | 
| I<expect> | return; | 
|  | } | 
| - if this is set (usually to 'Success.') it will check for that in the |  | 
| last line of output and if it does not, will return undef because the | unless ( $self->logged_in ) { | 
| command probably failed | $self->last_error("Not logged in"); | 
|  | return; | 
| I<args> | } | 
|  |  | 
| - a string containing the command line options that are passed to the | my %cmd; | 
| command | foreach (@valid_net_telnet_opts) { | 
|  | if ( exists $cfg{$_} ) { | 
| $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 ); | $cmd{$_} = $cfg{$_}; | 
|  | } | 
| =cut | } | 
|  | if ( $cfg{'args'} ) { | 
| sub cmd | $cmd{'String'} .= $SPACE . $cfg{'args'}; | 
| { | } | 
| my $self = shift; |  | 
|  | my @lines; | 
| my @valid_net_telnet_opts = qw( | if ( $cfg{'no_prompt'} ) { | 
| String | $self->print( $cmd{'String'} ); | 
| Output | @lines = $self->lastline; | 
| Cmd_remove_mode | } | 
| Errmode | else { | 
| Input_record_separator | @lines = $self->SUPER::cmd(%cmd); | 
| Ors | } | 
| Output_record_separator |  | 
| Prompt | $self->last_lines( \@lines ); | 
| Rs |  | 
| Timeout | my $vals = 1; | 
| ); | if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) { | 
|  | if ( $cfg{'decode'} eq 'each' ) { | 
| my %cfg; | $vals = _decode_each_line(@lines); | 
| if (@_ == 1) { | } | 
| $cfg{'String'} = shift; | elsif ( $cfg{'decode'} eq 'sulog' ) { | 
| } elsif (@_ > 1) { | $vals = _decode_sulog(@lines); | 
| %cfg = @_; | } | 
| } | elsif ( $cfg{'decode'} eq 'maclist' ) { | 
|  | $vals = _decode_maclist(@lines); | 
| $cfg{'Timeout'} ||= $self->Timeout; | } | 
|  | else { | 
| unless ($cfg{'String'}) { | $vals = _decode_lines(@lines); | 
| $self->last_error("No command passed"); | } | 
| return; | } | 
| } |  | 
|  | $self->last_vals($vals); | 
| unless ($self->is_connected) { |  | 
| $self->last_error("Not connected"); | my $last = $self->lastline; | 
| return; |  | 
| } | if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) { | 
|  | if ( $cfg{'cmd_disconnects'} ) { | 
| unless ($self->logged_in) { | $self->logged_in(0); | 
| $self->last_error("Not logged in"); | $self->close; | 
| return; | $self->is_connected(0); | 
| } | } | 
|  |  | 
|  | if ( $PRIVATE{'Decode'} && $cfg{'decode'} ) { | 
| my %cmd; | return $vals; | 
| foreach (@valid_net_telnet_opts) { | } | 
| if (exists $cfg{$_}) { | else { | 
| $cmd{$_} = $cfg{$_}; | return \@lines; | 
| } | } | 
| } | } | 
| if ($cfg{'args'}) { | else { | 
| $cmd{'String'} .= ' ' . $cfg{'args'}; | my $err; | 
| } | if (grep { /\[ERR\]/ } @lines) { | 
| my @lines; | $err = _decode_lines(@lines); | 
| unless ($cfg{'no_prompt'}) { | } | 
| @lines = $self->SUPER::cmd(%cmd); |  | 
| } else { | if (ref $err eq 'HASH' && $err ->{ERR}) { | 
| $self->print($cmd{'String'}); | $self->last_error($err->{ERR} ); | 
| @lines = $self->lastline; | } else { | 
| } | $self->last_error("Error with command ($cfg{'String'}): $last"); | 
|  | } | 
| $self->last_lines(\@lines); | return; | 
|  | } | 
| my $vals = 1; | } | 
| if ($PRIVATE{'Decode'} && $cfg{'decode'}) { |  | 
| if ($cfg{'decode'} eq 'each') { | #=item _decode_lines | 
| $vals = _decode_each_line(@lines); |  | 
| } elsif ($cfg{'decode'} eq 'sulog') { | sub _decode_lines { | 
| $vals = _decode_sulog(@lines); | my @lines = @_; | 
| } elsif ($cfg{'decode'} eq 'maclist') { |  | 
| $vals = _decode_maclist(@lines); | my %conf; | 
| } else { |  | 
| $vals = _decode_lines(@lines); | my $key = $EMPTY; | 
| } | my $val = undef; | 
| } | my @vals; | 
|  | my $in_key = 0; | 
| $self->last_vals($vals); | my $in_val = 1; | 
|  |  | 
|  | foreach my $line (@lines) { | 
| my $last = $self->lastline; | next if $line =~ /$success$/; | 
|  |  | 
| if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) { | my @chars = split //, $line; | 
| if ($cfg{'cmd_disconnects'}) { |  | 
| $self->logged_in(0); | my $last_key = $EMPTY; | 
| $self->close; | foreach my $c (@chars) { | 
| $self->is_connected(0); |  | 
| } | if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) { | 
|  | if ( $c eq '[' ) { | 
| if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | $in_key = 1; | 
| return $vals; | $in_val = 0; | 
| } else { | } | 
| return \@lines; | else { | 
| } | $in_key = 0; | 
| } else { | $in_val = 1; | 
| $self->last_error("Error with command ($cfg{'String'}): $last"); | } | 
| return; |  | 
| } | if ($key) { | 
| } | $key =~ s/^\s+//; | 
|  | $key =~ s/\s+$//; | 
| #=item _decode_lines |  | 
|  | if ($val) { | 
| sub _decode_lines | $val =~ s/^\s+//; | 
| { | $val =~ s/\s+$//; | 
| my @lines = @_; | } | 
|  |  | 
| my %conf; | if ( $key eq 'Checksum' && $last_key ) { | 
|  |  | 
| my $key = ''; | # Special case for these bastids. | 
| my $val = undef; | my $new = $last_key; | 
| my @vals; | $new =~ s/\s+\S+$//; | 
| my $in_key = 0; | $key = $new . $SPACE . $key; | 
| my $in_val = 1; | } | 
|  |  | 
| foreach my $line (@lines) { | $conf{$key} = $val; | 
| next if $line =~ /$success$/; | $last_key   = $key; | 
|  | $key        = $EMPTY; | 
| my @chars = split //, $line; | } | 
|  | elsif ($val) { | 
| my $last_key = ''; | push @vals, $val; | 
| foreach my $c (@chars) { | } | 
|  | $val = $EMPTY; | 
| if ($c eq '[' || $c eq "\r" || $c eq "\n") { |  | 
| if ($c eq '[') { | } | 
| $in_key = 1; | elsif ( $c eq ']' ) { | 
| $in_val = 0; | $in_val = 1; | 
| } else { | $in_key = 0; | 
| $in_key = 0; | $c      = shift @chars; | 
| $in_val = 1; |  | 
| } | } | 
|  | elsif ($in_key) { | 
| if ($key) { | $key .= $c; | 
| $key =~ s/^\s+//; |  | 
| $key =~ s/\s+$//; | } | 
|  | elsif ($in_val) { | 
| if ($val) { | $val .= $c; | 
| $val =~ s/^\s+//; | } | 
| $val =~ s/\s+$//; | } | 
| } | } | 
|  |  | 
| if ($key eq 'Checksum' && $last_key) { | unless ($key) { | 
| # Special case for these bastids. | push @vals, $val; | 
| my $new = $last_key; | } | 
| $new =~ s/\s+\S+$//; |  | 
| $key = $new . " " . $key; | if ( @vals == 1 ) { | 
| } | $val = $vals[0]; | 
|  | } | 
| $conf{$key} = $val; | elsif (@vals) { | 
| $last_key = $key; | $val = \@vals; | 
| $key = ''; | } | 
| } elsif ($val) { | else { | 
| push @vals, $val; | $val = undef; | 
| } | } | 
| $val = ''; |  | 
|  | if (%conf) { | 
| } elsif ($c eq ']') { | $conf{_pre} = $val if $val; | 
| $in_val = 1; | return \%conf; | 
| $in_key = 0; | } | 
| $c = shift @chars; | else { | 
|  | return $val; | 
| } elsif ($in_key) { | } | 
| $key .= $c; | } | 
|  |  | 
| } elsif ($in_val) { | #=item _decode_each_line | 
| $val .= $c; |  | 
| } | sub _decode_each_line { | 
| } | my @lines = @_; | 
| } | my @decoded; | 
|  | foreach my $line (@lines) { | 
| unless ($key) { | my $decoded = _decode_lines($line); | 
| push @vals, $val; | push @decoded, $decoded if defined $decoded; | 
| } | } | 
|  | return \@decoded; | 
| if (@vals == 1) { | } | 
| $val = $vals[0]; |  | 
| } elsif (@vals) { | #=item _decode_sulog | 
| $val= \@vals; |  | 
| } else { | sub _decode_sulog { | 
| $val = undef; | my @lines = @_; | 
| } | my @decoded; | 
|  | my $last_tm; | 
| if (%conf) { | foreach my $line (@lines) { | 
| $conf{_pre} = $val if $val; | my $decoded = _decode_lines($line); | 
| return \%conf; |  | 
| } else { | if ( defined $decoded ) { | 
| return $val; | if ( $decoded->{'tm'} ) { | 
| } | $last_tm = $decoded->{'tm'}; | 
| } | next; | 
|  | } | 
| #=item _decode_each_line | else { | 
|  | $decoded->{'tm'} = $last_tm; | 
| sub _decode_each_line | } | 
| { | next unless $last_tm; | 
| my @lines = @_; |  | 
| my @decoded; | push @decoded, $decoded if defined $decoded; | 
| foreach my $line (@lines) { | } | 
| my $decoded = _decode_lines($line); | } | 
| push @decoded, $decoded if defined $decoded; | return \@decoded; | 
| } | } | 
| return \@decoded; |  | 
| } | #=item _decode_maclist | 
|  |  | 
| #=item _decode_sulog | sub _decode_maclist { | 
|  | my @lines = @_; | 
| sub _decode_sulog | my @decoded; | 
| { | my $total_entries = 0; | 
| my @lines = @_; | my $current_tm    = 0; | 
| my @decoded; | foreach my $line (@lines) { | 
| my $last_tm; | $line =~ s/\r?\n$//; | 
| foreach my $line (@lines) { | my ( $mac, $loc, $tm ) = $line =~ / | 
| my $decoded = _decode_lines($line); | ([0-9a-fA-F ]{17})\s+ | 
|  | (.*)\s+ | 
| if (defined $decoded) { | tm\s+ | 
| if ($decoded->{'tm'}) { | (\d+) | 
| $last_tm = $decoded->{'tm'}; | /x; | 
| next; |  | 
| } else { | if ($mac) { | 
| $decoded->{'tm'} = $last_tm; | $mac =~ s/\s+//g; | 
| } | $loc =~ s/^\s+//; | 
| next unless $last_tm; | $loc =~ s/\s+$//; | 
|  |  | 
| push @decoded, $decoded if defined $decoded; | my $suid = undef; | 
| } | if ( $loc =~ /suid\s+=\s+(\d+)/ ) { | 
| } | $suid = $1; | 
| return \@decoded; | $loc  = undef; | 
| } | } | 
|  |  | 
| #=item _decode_maclist | push @decoded, | 
|  | { | 
| sub _decode_maclist | mac  => $mac, | 
| { | loc  => $loc, | 
| my @lines = @_; | tm   => $tm, | 
| my @decoded; | suid => $suid, | 
| my $total_entries = 0; | }; | 
| my $current_tm = 0; | } | 
| foreach my $line (@lines) { | elsif ( $line =~ /(\d+)\s+entries/ ) { | 
| $line =~ s/\r?\n$//; | $total_entries = $1; | 
| my ($mac, $loc, $tm) = $line =~ / | } | 
| ([0-9a-fA-F ]{17})\s+ | elsif ( $line =~ /current tm = (\d+)\s+sec/ ) { | 
| (.*)\s+ | $current_tm = $1; | 
| tm\s+ | } | 
| (\d+) | } | 
| /x; |  | 
|  | map { $_->{'cur_tm'} = $current_tm } @decoded; | 
| if ($mac) { |  | 
| $mac =~ s/\s+//g; | if ( scalar @decoded == $total_entries ) { | 
| $loc =~ s/^\s+//; | return \@decoded; | 
| $loc =~ s/\s+$//; | } | 
|  | else { | 
| my $suid = undef; |  | 
| if ($loc =~ /suid\s+=\s+(\d+)/) { | # XXX we should have a way to set last error, not sure why we don't | 
| $suid = $1; | return; | 
| $loc = undef; | } | 
| } | } | 
|  |  | 
| push @decoded, { | 1;    # End of Net::Telnet::Trango | 
| mac  => $mac, | __END__ | 
| loc  => $loc, |  | 
| tm   => $tm, | =head1 SEE ALSO | 
| suid => $suid, |  | 
| }; | Trango Documentation - | 
| } elsif ($line =~ /(\d+)\s+entries/) { | L<http://www.trangobroadband.com/support/product_docs.htm> | 
| $total_entries = $1; |  | 
| } elsif ($line =~ /current tm = (\d+)\s+sec/) { | L<Net::Telnet> | 
| $current_tm = $1 |  | 
| } | =head1 TODO | 
| } |  | 
|  | There are still a lot of commands that are not accessed directly.  If | 
| map { $_->{'cur_tm'} = $current_tm } @decoded; | you call them (as cmd("command + args") or whatever) and it works, | 
|  | please send me examples that work and I will try to get it incorporated | 
| if (scalar @decoded == $total_entries) { | into the next version of the script. | 
| return \@decoded; |  | 
| } else { | I also want to be able to parse the different types of output from | 
| # XXX we should have a way to set last error, not sure why we don't | commands like su, sudb all and anything else that would be better | 
| return; | available as a perl datastructure. | 
| } |  | 
| } | =head1 AUTHOR | 
|  |  | 
| 1; | Andrew Fresh E<lt>andrew@rraz.netE<gt> | 
| __END__ |  | 
|  | =head1 SUPPORT | 
| =back |  | 
|  | You can find documentation for this module with the perldoc command. | 
| =head1 SEE ALSO |  | 
|  | perldoc Net::Telnet::Trango | 
| Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm |  | 
|  | You can also look for information at: | 
| L<Net::Telnet> |  | 
|  | =over 4 | 
| =head1 TODO |  | 
|  | =item * AnnoCPAN: Annotated CPAN documentation | 
| There are still a lot of commands that are not accessed directly.  If |  | 
| you call them (as cmd("command + args") or whatever) and it works, | L<http://annocpan.org/dist/Net-Telnet-Trango> | 
| please send me examples that work and I will try to get it incorporated |  | 
| into the next version of the script. | =item * CPAN Ratings | 
|  |  | 
| I also want to be able to parse the different types of output from | L<http://cpanratings.perl.org/d/Net-Telnet-Trango> | 
| commands like su, sudb all and anything else that would be better |  | 
| available as a perl datastructure. | =item * RT: CPAN's request tracker | 
|  |  | 
| =head1 AUTHOR | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Telnet-Trango> | 
|  |  | 
| Andrew Fresh E<lt>andrew@rraz.netE<gt> | =item * Search CPAN | 
|  |  | 
| =head1 COPYRIGHT AND LICENSE | L<http://search.cpan.org/dist/Net-Telnet-Trango> | 
|  |  | 
| Copyright (C) 2005,2006,2007 by Andrew Fresh | =back | 
|  |  | 
| This library is free software; you can redistribute it and/or modify | =head1 COPYRIGHT AND LICENSE | 
| it under the same terms as Perl itself, either Perl version 5.8.7 or, |  | 
| at your option, any later version of Perl 5 you may have available. | Copyright (C) 2005,2006,2007 by Andrew Fresh | 
|  |  | 
| =cut | This program is free software; you can redistribute it and/or modify it | 
|  | under the same terms as Perl itself. | 
|  |  | 
|  | =cut |