| version 1.9, 2006/07/14 02:17:29 | version 1.20, 2006/09/12 03:20:39 | 
|  |  | 
| package Net::Telnet::Trango; | package Net::Telnet::Trango; | 
| # $RedRiver: Trango.pm,v 1.8 2006/06/29 00:39:52 andrew Exp $ | # $RedRiver: Trango.pm,v 1.19 2006/09/12 02:16:43 andrew Exp $ | 
| use strict; | use strict; | 
| use warnings; | use warnings; | 
| use base 'Net::Telnet'; | 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; | use Net::Telnet::Trango; | 
| my $t = new Net::Telnet::Trango ( Timeout => 5 ); | 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->exit; | 
| $t->close; | $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 those in a hashref that is returned.  This makes using the output from things like sysinfo very easy to do. | Another handy feature is that it will parse the output from certain | 
|  | commands that is in the format "[key1] value1 [key2] value2" and put | 
| =head2 EXPORT | those in a hashref that is returned.  This makes using the output from | 
|  | things like sysinfo very easy to do. | 
| None |  | 
|  | =head2 EXPORT | 
| =cut |  | 
|  | None | 
| our $VERSION = '0.01'; |  | 
|  | =cut | 
| my %PRIVATE = ( |  | 
| is_connected => 0, | our $VERSION = '0.01'; | 
| logged_in => 0, |  | 
| ); | my %PRIVATE = ( | 
|  | is_connected => 0, | 
| =pod | logged_in => 0, | 
|  | ); | 
| =item new |  | 
|  | =pod | 
| Same as new from L<Net::Telnet> but has defaults for the trango 'Prompt' |  | 
|  | =item new | 
| 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 | Same as new from L<Net::Telnet> but has defaults for the trango 'Prompt' | 
| instead return an array of the lines that were returned from the |  | 
| command. | 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 | 
| =cut | instead return an array of the lines that were returned from the | 
|  | command. | 
| sub new |  | 
| { | =cut | 
| my $class = shift; |  | 
|  | sub new | 
| my %args; | { | 
| if (@_ == 1) { | my $class = shift; | 
| $args{'Host'} = shift; |  | 
| } else { | my %args; | 
| %args = @_; | if (@_ == 1) { | 
| } | $args{'Host'} = shift; | 
|  | } else { | 
| $args{'Prompt'}  ||= '/#> *$/'; | %args = @_; | 
|  | } | 
| foreach my $key (keys %args) { |  | 
| $PRIVATE{$key} = $args{$key}; | $args{'Prompt'}  ||= '/#> *$/'; | 
| } |  | 
| $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; | foreach my $key (keys %args) { | 
| delete $args{'Decode'}; | $PRIVATE{$key} = $args{$key}; | 
|  | } | 
| my $self = $class->SUPER::new(%args); | $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; | 
| bless $self if ref $self; | delete $args{'Decode'}; | 
|  |  | 
| return $self; | my $self = $class->SUPER::new(%args); | 
| } | bless $self if ref $self; | 
|  |  | 
| #  _password <new password> <new password> | return $self; | 
| #  ? [command] | } | 
| #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]... |  | 
| #  arp -bcast <on|off> | #  _password <new password> <new password> | 
| #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ... | #  ? [command] | 
| #  bye | #  apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]... | 
| #  cf2cf ap [default|<size>] | #  arp -bcast <on|off> | 
| #  date | #  bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ... | 
| #  date <month> <day> <year> | #  bye | 
| #  freq scantable | #  cf2cf ap [default|<size>] | 
| #  freq channeltable | #  date | 
| #  freq writescan [<ch#> <h|v>] | #  date <month> <day> <year> | 
| #  freq writechannel [<ch#> <freq>] ... | #  freq scantable | 
| #  freq <ch #> <h|v> | #  freq channeltable | 
| #  help [command] | #  freq writescan [<ch#> <h|v>] | 
| #  heater [<on temp> <off temp>] | #  freq writechannel [<ch#> <freq>] ... | 
| #  ipconfig [<new ip> <new subnet mask> <new gateway>] | #  freq <ch #> <h|v> | 
| #  log [<# of entries, 1..179>] | #  help [command] | 
| #  log <sum> <# of entries, 1..179> | #  heater [<on temp> <off temp>] | 
| #  logout | #  ipconfig [<new ip> <new subnet mask> <new gateway>] | 
| #  opmode [ap [y]] | #  log [<# of entries, 1..179>] | 
| #  password | #  log <sum> <# of entries, 1..179> | 
| #  ping <ip addr> | #  logout | 
| #  polar <h|v> | #  opmode [ap [y]] | 
| #  power <setism|setunii> <max|min|<dBm>> | #  password | 
| #  reboot | #  ping <ip addr> | 
| #  restart | #  polar <h|v> | 
| #  remarks [<str>] | #  power <setism|setunii> <max|min|<dBm>> | 
| #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>] | #  reboot | 
| #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>] | #  restart | 
| #  sysinfo | #  remarks [<str>] | 
| #  set suid <id> | #  rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>] | 
| #  set apid <id> | #  rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>] | 
| #  set baseid <id> | #  sysinfo | 
| #  set defaultopmode [<ap|su> <min,0..10>] | #  set suid <id> | 
| #  set defaultopmode off | #  set apid <id> | 
| #  set snmpcomm [<read | write | trap (id or setall)> <str>] | #  set baseid <id> | 
| #  set mir [on|off] | #  set defaultopmode [<ap|su> <min,0..10>] | 
| #  set mir threshold <kbps> | #  set defaultopmode off | 
| #  set rssitarget [<ism|unii> <dBm>] | #  set snmpcomm [<read | write | trap (id or setall)> <str>] | 
| #  set serviceradius [<ism | unii> <miles>] | #  set mir [on|off] | 
| #  ssrssi <ch #> <h|v> | #  set mir threshold <kbps> | 
| #  su [<suid>|all] | #  set rssitarget [<ism|unii> <dBm>] | 
| #  su changechannel <all|suid> <ch#> <h|v> | #  set serviceradius [<ism | unii> <miles>] | 
| #  su ipconfig <suid> <new ip> <new subnet> <new gateway> | #  ssrssi <ch #> <h|v> | 
| #  su [live|poweroff|priority] | #  su [<suid>|all] | 
| #  su <ping|info|status> <suid> | #  su changechannel <all|suid> <ch#> <h|v> | 
| #  su powerleveling <all|suid> | #  su ipconfig <suid> <new ip> <new subnet> <new gateway> | 
| #  su reboot <all|suid> | #  su [live|poweroff|priority] | 
| #  su restart <all|suid> | #  su <ping|info|status> <suid> | 
| #  su testrflink <all|suid> [r] | #  su powerleveling <all|suid> | 
| #  su testrflink <setlen> [64..1600] | #  su reboot <all|suid> | 
| #  su testrflink <aptx> [20..100] | #  su restart <all|suid> | 
| #  su sw <suid|all> <sw #> <on|off> | #  su testrflink <all|suid> [r] | 
| #  sudb [dload | view] | #  su testrflink <setlen> [64..1600] | 
| #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex> | #  su testrflink <aptx> [20..100] | 
| #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex> | #  su sw <suid|all> <sw #> <on|off> | 
| #  sudb delete <all|<suid>> | #  sudb [dload | view] | 
| #  sudb modify <suid> <cir|mir> <kbps> | #  sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex> | 
| #  sudb modify <suid> <su2su> <group id,hex> | #  sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex> | 
| #  sudb view | #  sudb delete <all|<suid>> | 
| #  sulog [lastmins | sampleperiod <1..60>] | #  sudb modify <suid> <cir|mir> <kbps> | 
| #  sulog [<# of entry,1..18>] | #  sudb modify <suid> <su2su> <group id,hex> | 
| #  survey <ism|unii> <time, sec> <h|v> | #  sudb view | 
| #  sw [<sw #> <on|off>] | #  sulog [lastmins | sampleperiod <1..60>] | 
| #  temp | #  sulog [<# of entry,1..18>] | 
| #  tftpd [on|off] | #  survey <ism|unii> <time, sec> <h|v> | 
| #  time | #  sw [<sw #> <on|off>] | 
| #  time <hour> <min> <sec> | #  temp | 
| #  save <mainimage|fpgaimage> <current chksum> <new chksum> | #  tftpd [on|off] | 
| #  save <systemsetting|sudb> | #  time | 
| #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum> | #  time <hour> <min> <sec> | 
| #  updateflash <systemsetting|sudb> | #  save <mainimage|fpgaimage> <current chksum> <new chksum> | 
|  | #  save <systemsetting|sudb> | 
| =pod | #  updateflash <mainimage|fpgaimage> <current chksum> <new chksum> | 
|  | #  updateflash <systemsetting|sudb> | 
| =head1 METHODS |  | 
|  | =pod | 
| =head2 ACCESSORS |  | 
|  | =head1 METHODS | 
| =over |  | 
|  | =head2 ACCESSORS | 
| =item Host |  | 
|  | =over | 
| returns the name of the host that you are accessing |  | 
|  | =item Host | 
| =item firmware_version |  | 
|  | returns the name of the host that you are accessing | 
| returns the firmware version on the trango if available otherwise undef. |  | 
| Available after a successful open() | =item firmware_version | 
| This is usually only set internally |  | 
|  | returns the firmware version on the trango if available otherwise undef. | 
| =item host_type | Available after a successful open() | 
|  | This is usually only set internally | 
| returns the type of host from the login banner for example M5830S or M5300S. |  | 
| Available after a successful open() | =item host_type | 
| This is usually only set internally |  | 
|  | returns the type of host from the login banner for example M5830S or M5300S. | 
| =item is_connected | Available after a successful open() | 
|  | This is usually only set internally | 
| returns 1 after a successful open() otherwise undef |  | 
| This is usually only set internally | =item is_connected | 
|  |  | 
| =item logged_in | returns 1 after a successful open() otherwise undef | 
|  | This is usually only set internally | 
| returns 1 after a successful login() 0 if it failed and undef if |  | 
| login() was never called | =item logged_in | 
| This is usually only set internally |  | 
|  | returns 1 after a successful login() 0 if it failed and undef if | 
| =item login_banner | login() was never called | 
|  | This is usually only set internally | 
| returns the banner that is displayed when first connected at login.  Only set after a successful open() |  | 
|  | =item login_banner | 
| This is usually only set internally |  | 
|  | returns the banner that is displayed when first connected at login. | 
| =item last_lines | Only set after a successful open() | 
|  |  | 
| returns the output from the last cmd() that was run as an array ref | This is usually only set internally | 
| This is usually only set internally |  | 
|  | =item last_lines | 
| =back |  | 
|  | returns the output from the last cmd() that was run as an array ref | 
| =head2 ALIASES | This is usually only set internally | 
|  |  | 
| =over | =back | 
|  |  | 
| =item bye | =head2 ALIASES | 
|  |  | 
| alias of exit() | =over | 
|  |  | 
| =item restart | =item bye | 
|  |  | 
| alias of reboot() | alias of exit() | 
|  |  | 
| =back | =item restart | 
|  |  | 
| =head2 COMMANDS | alias of reboot() | 
|  |  | 
| Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>, as such they accept the same options as C<cmd()>.  Specifically they take a named paramater "args", for example: | =back | 
| C<tftpd(args =E<gt> 'on')> would enable tftpd |  | 
|  | =head2 COMMANDS | 
| =over |  | 
|  | Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>, | 
| =item tftpd | as such they accept the same options as C<cmd()>. | 
|  | Specifically they take a named paramater "args", for example: | 
| Returns a hash ref of the decoded output from the command. | C<tftpd(args =E<gt> 'on')> would enable tftpd | 
|  |  | 
| Also see enable_tftpd() and disable_tftpd() as those check for correct output | =over | 
|  |  | 
| =item ver | =item tftpd | 
|  |  | 
| Returns a hash ref of the decoded output from the command. | Returns a hash ref of the decoded output from the command. | 
|  |  | 
| =item sysinfo | Also see enable_tftpd() and disable_tftpd() as those check for correct output | 
|  |  | 
| Returns a hash ref of the decoded output from the command. | =item ver | 
|  |  | 
| =item exit | Returns a hash ref of the decoded output from the command. | 
|  |  | 
| exits the command session with the trango and closes the connection | =item sysinfo | 
|  |  | 
| =item reboot | Returns a hash ref of the decoded output from the command. | 
|  |  | 
| reboots the trango and closes the connection | =item exit | 
|  |  | 
| =item sulog | exits the command session with the trango and closes the connection | 
|  |  | 
| returns an array ref of hashes containing each log line. | =item reboot | 
|  |  | 
| =item save_sudb | reboots the trango and closes the connection | 
|  |  | 
| returns true on success, undef on failure | =item remarks | 
|  |  | 
| =item syslog | Takes an optional argument, which sets the remarks. | 
|  | If there is no argument, returns the current remarks. | 
| returns the output from the syslog command |  | 
|  | =item sulog | 
| =item pipe |  | 
|  | returns an array ref of hashes containing each log line. | 
| returns the output from the pipe command |  | 
|  | =item save_sudb | 
| =item maclist |  | 
|  | returns true on success, undef on failure | 
| returns the output from the maclist command |  | 
|  | =item syslog | 
| =item eth_list |  | 
|  | returns the output from the syslog command | 
| returns the output from the eth list command |  | 
|  | =item pipe | 
| =cut |  | 
|  | returns the output from the pipe command | 
|  |  | 
| my $success = 'Success.'; | =item maclist | 
| my %COMMANDS = ( |  | 
| tftpd       => { decode => 'all',   expect => $success }, | returns the output from the maclist command | 
| ver         => { decode => 'all' }, |  | 
| sysinfo     => { decode => 'all',   expect => $success }, | =item maclist_reset | 
| updateflash => { decode => 'all',   expect => $success }, |  | 
| sulog       => { decode => 'sulog', expect => $success }, | resets the maclist.  No useful output. | 
| 'exit'      => { no_prompt => 1, cmd_disconnects => 1 }, |  | 
| reboot      => { no_prompt => 1, cmd_disconnects => 1 }, | =item eth_list | 
| save_sudb   => { String => "save sudb", expect => $success }, |  | 
| syslog      => { expect => $success }, | returns the output from the eth list command | 
| 'pipe'      => { }, # XXX needs a special decode |  | 
| maclist     => { }, # XXX needs a special decode and a special expect | =item su_info | 
| eth_link    => { String => "eth link", expect => $success }, |  | 
| # eth r, w and reset??? | You need to pass in args => <suid> and it will return the info for that suid. | 
| #su password??? |  | 
| #_bootloader | =item save_ss | 
| #temp |  | 
| #heater | saves the config.  Returns 1 on success, undef on failure. | 
| ); |  | 
|  | =cut | 
| my %ALIASES = ( |  | 
| bye     => 'exit', |  | 
| restart => 'reboot', | my $success = 'Success.'; | 
| ); | my %COMMANDS = ( | 
|  | tftpd       => { decode => 'all',   expect => $success }, | 
| my %ACCESS = map { $_ => 1 } qw( | ver         => { decode => 'all' }, | 
| firmware_version | sysinfo     => { decode => 'all',   expect => $success }, | 
| host_type | updateflash => { decode => 'all',   expect => $success }, | 
| Host | sulog       => { decode => 'sulog', expect => $success }, | 
| is_connected | 'exit'      => { no_prompt => 1, cmd_disconnects => 1 }, | 
| logged_in | reboot      => { no_prompt => 1, cmd_disconnects => 1 }, | 
| login_banner | remarks     => { decode => 'all', expect => $success }, | 
| Timeout | save_sudb   => { String => 'save sudb', expect => $success }, | 
| last_lines | syslog      => { expect => $success }, | 
| last_vals | 'pipe'      => { }, # XXX needs a special decode | 
| ); | maclist     => { decode => 'maclist' }, | 
|  | maclist_reset => { String => 'maclist reset', expect => 'done' }, | 
| sub AUTOLOAD | eth_link    => { String => 'eth link', expect => $success }, | 
| { | su_info     => { String => 'su info', decode => 'all', expect => $success }, | 
| my $self = shift; | save_ss     => { String => 'save ss', expect => $success }, | 
|  | # eth r, w and reset??? | 
| my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/ | #su password??? | 
| or die "Weird: $AUTOLOAD"; | #_bootloader | 
|  | #temp | 
| if (exists $ALIASES{$method}) { | #heater | 
| $method = $ALIASES{$method}; | ); | 
| return $self->$method(@_); |  | 
| } | my %ALIASES = ( | 
|  | bye     => 'exit', | 
| if (exists $COMMANDS{$method}) { | restart => 'reboot', | 
| $method = shift if (@_ == 1); | ); | 
| $COMMANDS{$method}{'String'} ||= $method; |  | 
| return $self->cmd(%{ $COMMANDS{$method} }, @_); | my %ACCESS = map { $_ => 1 } qw( | 
| } | firmware_version | 
|  | host_type | 
| if (exists $ACCESS{$method}) { | Host | 
| my $prev = $PRIVATE{$method}; | is_connected | 
| ($PRIVATE{$method}) = @_ if @_; | logged_in | 
| return $prev; | login_banner | 
| } | Timeout | 
|  | last_lines | 
| $method = "SUPER::$method"; | last_vals | 
| return $self->$method(@_); | ); | 
| } |  | 
|  | sub AUTOLOAD | 
| =pod | { | 
|  | my $self = shift; | 
| =item open |  | 
|  | my ($method) = (our $AUTOLOAD) =~ /^.*::(\w+)$/ | 
| 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() | or die "Weird: $AUTOLOAD"; | 
|  |  | 
| =cut | if (exists $ALIASES{$method}) { | 
|  | $method = $ALIASES{$method}; | 
| sub open | return $self->$method(@_); | 
| { | } | 
| my $self = shift; |  | 
|  | if (exists $COMMANDS{$method}) { | 
| unless ( $self->SUPER::open(@_) ) { | $COMMANDS{$method}{'String'} ||= $method; | 
| #$! = "Couldn't connect to " . $self->Host . ":  $!"; | $COMMANDS{$method}{'args'} .= ' ' . shift if (@_ == 1); | 
| return undef; | return $self->cmd(%{ $COMMANDS{$method} }, @_); | 
| } | } | 
|  |  | 
| ## Get to login prompt | if (exists $ACCESS{$method}) { | 
| unless ($self->waitfor( | my $prev = $PRIVATE{$method}; | 
| -match => '/password: ?$/i', | ($PRIVATE{$method}) = @_ if @_; | 
| -errmode => "return", | return $prev; | 
| ) ) { | } | 
| #$! = "problem connecting to host (" . $self->Host . "): " . |  | 
| #    $self->lastline; | $method = "SUPER::$method"; | 
| return undef; | return $self->$method(@_); | 
| } | } | 
|  |  | 
| $self->parse_login_banner($self->lastline); | =pod | 
|  |  | 
| $self->is_connected(1); | =item open | 
|  |  | 
| return $self->is_connected; | 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() | 
| =pod |  | 
|  | =cut | 
| =item login |  | 
|  | sub open | 
| Calls open() if not already connected, then sends the password and sets logged_in() if successful | { | 
|  | my $self = shift; | 
| =cut |  | 
|  | unless ( $self->SUPER::open(@_) ) { | 
| sub login | #$! = "Couldn't connect to " . $self->Host . ":  $!"; | 
| { | return undef; | 
| my $self = shift; | } | 
|  |  | 
| unless ($self->is_connected) { | ## Get to login prompt | 
| $self->open or return undef; | unless ($self->waitfor( | 
| } | -match => '/password: ?$/i', | 
|  | -errmode => "return", | 
| my $password = shift; | ) ) { | 
|  | #$! = "problem connecting to host (" . $self->Host . "): " . | 
| $self->print($password); | #    $self->lastline; | 
| unless ($self->waitfor( | return undef; | 
| -match => $self->prompt, | } | 
| -errmode => "return", |  | 
| ) ) { | $self->parse_login_banner($self->lastline); | 
| #$! = "login ($self->Host) failed: " . $self->lastline; |  | 
| return undef; | $self->is_connected(1); | 
| } |  | 
|  | return $self->is_connected; | 
| $self->logged_in(1); | } | 
|  |  | 
| return $self->logged_in; | =pod | 
| } |  | 
|  | =item login | 
| =pod |  | 
|  | Calls open() if not already connected, then sends the password and sets | 
| =item parse_login_banner | logged_in() if successful | 
|  |  | 
| Takes a login banner (what you get when you first connect to the Trango) or reads what is already in login_banner() then parses it and sets host_type() and firmware_version() as well as login_banner() | =cut | 
|  |  | 
| =cut | sub login | 
|  | { | 
| sub parse_login_banner | my $self = shift; | 
| { |  | 
| my $self = shift; | unless ($self->is_connected) { | 
|  | $self->open or return undef; | 
| if (@_) { | } | 
| $self->login_banner(@_); |  | 
| } | my $password = shift; | 
|  |  | 
| my $banner = $self->login_banner; | $self->print($password); | 
|  | unless ($self->waitfor( | 
| my ($type, $ver) = $banner =~ | -match => $self->prompt, | 
| /Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i; | -errmode => "return", | 
|  | ) ) { | 
| $self->login_banner($banner); | #$! = "login ($self->Host) failed: " . $self->lastline; | 
| $self->host_type($type); | return undef; | 
| $self->firmware_version($ver); | } | 
|  |  | 
| return 1; | $self->logged_in(1); | 
| } |  | 
|  | return $self->logged_in; | 
| =pod | } | 
|  |  | 
| =item su_password | =pod | 
|  |  | 
| C<su_password('all'|suid, 'new_password')> | =item parse_login_banner | 
|  |  | 
| =cut | Takes a login banner (what you get when you first connect to the Trango) | 
|  | or reads what is already in login_banner() then parses it and sets | 
| sub su_password | host_type() and firmware_version() as well as login_banner() | 
| { |  | 
| my $self     = shift; | =cut | 
| my $su       = shift || '!'; |  | 
| my $new_pass = shift || ''; | sub parse_login_banner | 
|  | { | 
| unless (defined $su) { | my $self = shift; | 
| warn "No su passed!" |  | 
| #return undef; | if (@_) { | 
| } | $self->login_banner(@_); | 
|  | } | 
| unless (defined $new_pass) { |  | 
| warn "No new password!" | my $banner = $self->login_banner; | 
| #return undef; |  | 
| } | my ($type, $ver) = $banner =~ | 
|  | /Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i; | 
| return $self->cmd(String => 'su password ' . |  | 
| $su . ' ' . | $self->login_banner($banner); | 
| $new_pass . ' ' . | $self->host_type($type); | 
| $new_pass, | $self->firmware_version($ver); | 
| expect => $success, |  | 
| ); | return 1; | 
| } | } | 
|  |  | 
| =pod | =pod | 
|  |  | 
| =item sudb_view | =item su_password | 
|  |  | 
| returns a reference to an array of hashes each containing: | C<su_password('all'|suid, 'new_password')> | 
|  |  | 
| suid | =cut | 
| type |  | 
| cir | sub su_password | 
| mir | { | 
| mac | my $self     = shift; | 
|  | my $su       = shift || '!'; | 
| =cut | my $new_pass = shift || ''; | 
|  |  | 
| sub sudb_view | unless (defined $su) { | 
| { | warn "No su passed!" | 
| my $self = shift; | #return undef; | 
|  | } | 
| my @lines = $self->cmd( String => 'sudb view', expect => $success ); |  | 
|  | unless (defined $new_pass) { | 
| return undef unless @lines; | warn "No new password!" | 
|  | #return undef; | 
| unless ($PRIVATE{'Decode'}) { | } | 
| return @lines; |  | 
| } | return $self->cmd(String => 'su password ' . | 
|  | $su . ' ' . | 
| my @sus; | $new_pass . ' ' . | 
| foreach (@lines) { | $new_pass, | 
| next unless $_; | expect => $success, | 
| if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { | ); | 
| my %s = ( | } | 
| suid => $1, |  | 
| type => $2, | =pod | 
| cir  => $3, |  | 
| mir  => $4, | =item su_ipconfig | 
| mac  => $5, |  | 
| ); | C<su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )> | 
|  |  | 
| $s{'mac'} =~ s/\s//g; | =cut | 
| $s{'mac'} = uc($s{'mac'}); |  | 
|  | sub su_ipconfig | 
| push @sus, \%s; | { | 
| } | my $self        = shift; | 
| } |  | 
|  | my $suid        = shift; | 
| return \@sus; | my $new_ip      = shift; | 
| } | my $new_subnet  = shift; | 
|  | my $new_gateway = shift; | 
| =pod |  | 
|  | return undef unless $suid =~ /^\d+$/; | 
| =item sudb_add | return undef unless $new_ip; | 
|  | return undef unless $new_subnet; | 
| Takes the following paramaters | return undef unless $new_gateway; | 
|  |  | 
| suid : numeric, | # su ipconfig <suid> <new ip> <new subnet> <new gateway> | 
| type : (reg|pr) | return $self->cmd(String => 'su ipconfig ' . | 
| cir  : numeric, | $suid       . ' ' . | 
| mir  : numeric, | $new_ip     . ' ' . | 
| mac  : Almost any format, it will be reformatted, | $new_subnet . ' ' . | 
|  | $new_gateway, | 
| and returns true on success or undef otherwise. | expect => $success, | 
|  | ); | 
| You should save_sudb() after calling this, or your changes  will be lost | } | 
| when the AP is rebooted. |  | 
|  | =pod | 
| =cut |  | 
|  | =item sudb_view | 
| sub sudb_add |  | 
| { | returns a reference to an array of hashes each containing: | 
| my $self = shift; |  | 
| my $suid = shift; | suid | 
| my $type = shift; | type | 
| my $cir  = shift; | cir | 
| my $mir  = shift; | mir | 
| my $mac  = shift; | mac | 
|  |  | 
| if ($suid =~ /\D/) { | =cut | 
| return undef; |  | 
| } | sub sudb_view | 
|  | { | 
| unless (lc($type) eq 'reg' || lc($type) eq 'pr') { | my $self = shift; | 
| warn "Invalid type '$type'!"; |  | 
| return undef; | my @lines = $self->cmd( String => 'sudb view', expect => $success ); | 
| } |  | 
|  | return undef unless @lines; | 
| if ($cir =~ /\D/) { |  | 
| warn "Invalid CIR '$cir'!"; | unless ($PRIVATE{'Decode'}) { | 
| return undef; | return @lines; | 
| } | } | 
|  |  | 
| if ($mir =~ /\D/) { | my @sus; | 
| warn "Invalid MIR '$mir'!"; | foreach (@lines) { | 
| return undef; | next unless $_; | 
| } | if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { | 
|  | my %s = ( | 
| my $new_mac = $mac; | suid => $1, | 
| $new_mac =~ s/[^0-9A-Fa-f]//; | type => $2, | 
| unless (length $new_mac == 12) { | cir  => $3, | 
| warn "Invalid MAC '$mac'!"; | mir  => $4, | 
| return undef; | mac  => $5, | 
| } | ); | 
| $new_mac = join ' ', $new_mac =~ /../g; |  | 
|  | $s{'mac'} =~ s/\s//g; | 
| my $string = 'sudb add ' . | $s{'mac'} = uc($s{'mac'}); | 
| $suid . ' ' . |  | 
| $type . ' ' . | push @sus, \%s; | 
| $cir  . ' ' . | } | 
| $mir  . ' ' . | } | 
| $new_mac; |  | 
|  | return \@sus; | 
|  | } | 
| return $self->cmd( String => $string, expect => $success ); |  | 
| } | =pod | 
|  |  | 
| =pod | =item sudb_add | 
|  |  | 
| =item sudb_delete | Takes the following paramaters | 
|  |  | 
| Takes either 'all' or the  suid of the su to delete | suid : numeric, | 
| and returns true on success or undef otherwise. | type : (reg|pr) | 
|  | cir  : numeric, | 
| You should save_sudb() after calling this, or your changes  will be lost | mir  : numeric, | 
| when the AP is rebooted. | mac  : Almost any format, it will be reformatted, | 
|  |  | 
| =cut | and returns true on success or undef otherwise. | 
|  |  | 
| sub sudb_delete | You should save_sudb() after calling this, or your changes  will be lost | 
| { | when the AP is rebooted. | 
| my $self = shift; |  | 
| my $suid = shift; | =cut | 
|  |  | 
| if (lc($suid) ne 'all' || $suid =~ /\D/) { | sub sudb_add | 
| return undef; | { | 
| } | my $self = shift; | 
|  | my $suid = shift; | 
| return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); | my $type = shift; | 
| } | my $cir  = shift; | 
|  | my $mir  = shift; | 
| =pod | my $mac  = shift; | 
|  |  | 
| =item sudb_modify | if ($suid =~ /\D/) { | 
|  | return undef; | 
| Takes either the  suid of the su to delete | } | 
| as well as what you are changing, either "cir, mir or su2su" |  | 
| and returns true on success or undef otherwise. | unless (lc($type) eq 'reg' || lc($type) eq 'pr') { | 
|  | warn "Invalid type '$type'!"; | 
| cir and mir also take a value to set the cir/mir to. | return undef; | 
|  | } | 
| su2su takes a group id parameter that is in hex. |  | 
|  | if ($cir =~ /\D/) { | 
| You should save_sudb() after calling this, or your changes  will be lost | warn "Invalid CIR '$cir'!"; | 
| when the AP is rebooted. | return undef; | 
|  | } | 
| =cut |  | 
|  | if ($mir =~ /\D/) { | 
| sub sudb_modify | warn "Invalid MIR '$mir'!"; | 
| { | return undef; | 
| my $self  = shift; | } | 
| my $suid  = shift; |  | 
| my $opt   = shift; | my $new_mac = $mac; | 
| my $value = shift; | $new_mac =~ s/[^0-9A-Fa-f]//; | 
|  | unless (length $new_mac == 12) { | 
| if ($suid =~ /\D/) { | warn "Invalid MAC '$mac'!"; | 
| return undef; | return undef; | 
| } | } | 
|  | $new_mac = join ' ', $new_mac =~ /../g; | 
| if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { |  | 
| if ($value =~ /\D/) { | my $string = 'sudb add ' . | 
| return undef; | $suid . ' ' . | 
| } | $type . ' ' . | 
| } elsif (lc($opt) eq 'su2su') { | $cir  . ' ' . | 
| if ($value =~ /[^0-9A-Za-f]/) { | $mir  . ' ' . | 
| return undef; | $new_mac; | 
| } |  | 
| } else { |  | 
| return undef; | return $self->cmd( String => $string, expect => $success ); | 
| } | } | 
|  |  | 
| my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; | =pod | 
|  |  | 
| return $self->cmd( String => $string, expect => $success ); | =item sudb_delete | 
| } |  | 
|  | Takes either 'all' or the  suid of the su to delete | 
| =pod | and returns true on success or undef otherwise. | 
|  |  | 
| =item enable_tftpd | You should save_sudb() after calling this, or your changes  will be lost | 
|  | when the AP is rebooted. | 
| runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing |  | 
|  | =cut | 
| =cut |  | 
|  | sub sudb_delete | 
| sub enable_tftpd | { | 
| { | my $self = shift; | 
| my $self = shift; | my $suid = shift; | 
|  |  | 
| my $vals = $self->tftpd( args => 'on' ); | if (lc($suid) ne 'all' || $suid =~ /\D/) { | 
|  | return undef; | 
| if ($vals->{'Tftpd'} eq 'listen') { | } | 
| return $vals; |  | 
| } else { | return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); | 
| return undef; | } | 
| } |  | 
| } | =pod | 
|  |  | 
| =pod | =item sudb_modify | 
|  |  | 
| =item disable_tftpd | Takes either the  suid of the su to delete | 
|  | as well as what you are changing, either "cir, mir or su2su" | 
| runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled' | and returns true on success or undef otherwise. | 
|  |  | 
| =cut | cir and mir also take a value to set the cir/mir to. | 
|  |  | 
| sub disable_tftpd | su2su takes a group id parameter that is in hex. | 
| { |  | 
| my $self = shift; | You should save_sudb() after calling this, or your changes  will be lost | 
|  | when the AP is rebooted. | 
| my $vals = $self->tftpd( args => 'off' ); |  | 
|  | =cut | 
| if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') { |  | 
| return $vals; | sub sudb_modify | 
| } else { | { | 
| return undef; | my $self  = shift; | 
| } | my $suid  = shift; | 
| } | my $opt   = shift; | 
|  | my $value = shift; | 
| =pod |  | 
|  | if ($suid =~ /\D/) { | 
| =item cmd | return undef; | 
|  | } | 
| This does most of the work.  At the heart, it calls Net::Telnet::cmd() but it also does some special stuff for Trango. |  | 
|  | if (lc($opt) eq 'cir' or lc($opt) eq 'mir') { | 
| Normally returns the last lines from from the command | if ($value =~ /\D/) { | 
|  | return undef; | 
| Also accepts these options: | } | 
|  | } elsif (lc($opt) eq 'su2su') { | 
| I<decode> | if ($value =~ /[^0-9A-Za-f]/) { | 
| - if this is true, then it will send the output lines to _decode_lines() and then returns the decoded output | return undef; | 
|  | } | 
| I<cmd_disconnects> | } else { | 
| - if this is true, it then sets logged_in() to false, then it will close() the connection and then sets is_connected() to false | return undef; | 
|  | } | 
| I<expect> |  | 
| - 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 command probably failed | my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; | 
|  |  | 
| I<args> | return $self->cmd( String => $string, expect => $success ); | 
| - a string containing the command line options that are passed to the command | } | 
|  |  | 
| =cut | =pod | 
|  |  | 
| sub cmd | =item enable_tftpd | 
| { |  | 
| my $self = shift; | runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing | 
|  |  | 
| my @valid_net_telnet_opts = qw( | =cut | 
| String |  | 
| Output | sub enable_tftpd | 
| Cmd_remove_mode | { | 
| Errmode | my $self = shift; | 
| Input_record_separator |  | 
| Ors | my $vals = $self->tftpd( args => 'on' ); | 
| Output_record_separator |  | 
| Prompt | if ($vals->{'Tftpd'} eq 'listen') { | 
| Rs | return $vals; | 
| Timeout | } else { | 
| ); | return undef; | 
|  | } | 
| my %cfg; | } | 
| if (@_ == 1) { |  | 
| $cfg{'String'} = shift; | =pod | 
| } elsif (@_ > 1) { |  | 
| %cfg = @_; | =item disable_tftpd | 
| } |  | 
|  | runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled' | 
| $cfg{'Timeout'} ||= $self->Timeout; |  | 
|  | =cut | 
| unless ($cfg{'String'}) { |  | 
| #$! = "No command passed"; | sub disable_tftpd | 
| #warn "No command passed\n"; | { | 
| return undef; | my $self = shift; | 
| } |  | 
|  | my $vals = $self->tftpd( args => 'off' ); | 
| unless ($self->is_connected) { |  | 
| #$! = "Not connected"; | if (ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled') { | 
| #warn "Not connected\n"; | return $vals; | 
| return undef; | } else { | 
| } | return undef; | 
|  | } | 
| unless ($self->logged_in) { | } | 
| #$! = "Not logged in"; |  | 
| #warn "Not logged in\n"; | =pod | 
| return undef; |  | 
| } | =item cmd | 
|  |  | 
|  | This does most of the work.  At the heart, it calls Net::Telnet::cmd() | 
| my %cmd; | but it also does some special stuff for Trango. | 
| foreach (@valid_net_telnet_opts) { |  | 
| if (exists $cfg{$_}) { | Normally returns the last lines from from the command | 
| $cmd{$_} = $cfg{$_}; |  | 
| } | Also accepts these options: | 
| } |  | 
| if ($cfg{'args'}) { | I<decode> | 
| $cmd{'String'} .= ' ' . $cfg{'args'}; | - if this is true, then it will send the output lines to _decode_lines() | 
| } | and then returns the decoded output | 
| my @lines; |  | 
| unless ($cfg{'no_prompt'}) { | I<cmd_disconnects> | 
| @lines = $self->SUPER::cmd(%cmd); | - if this is true, it then sets logged_in() to false, then it will | 
| } else { | close() the connection and then sets is_connected() to false | 
| $self->print($cmd{'String'}); |  | 
| @lines = $self->lastline; | I<expect> | 
| } | - 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 | 
| $self->last_lines(\@lines); | command probably failed | 
|  |  | 
| my $vals = 1; | I<args> | 
| if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | - a string containing the command line options that are passed to the | 
| if ($cfg{'decode'} eq 'each') { | command | 
| $vals = _decode_each_line(@lines); |  | 
| } elsif ($cfg{'decode'} eq 'sulog') { | =cut | 
| $vals = _decode_sulog(@lines); |  | 
| } else { | sub cmd | 
| $vals = _decode_lines(@lines); | { | 
| } | my $self = shift; | 
| } |  | 
|  | my @valid_net_telnet_opts = qw( | 
| $self->last_vals($vals); | String | 
|  | Output | 
|  | Cmd_remove_mode | 
| my $last = $self->lastline; | Errmode | 
|  | Input_record_separator | 
| if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) { | Ors | 
| if ($cfg{'cmd_disconnects'}) { | Output_record_separator | 
| $self->logged_in(0); | Prompt | 
| $self->close; | Rs | 
| $self->is_connected(0); | Timeout | 
| } | ); | 
|  |  | 
| if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | my %cfg; | 
| return $vals; | if (@_ == 1) { | 
| } else { | $cfg{'String'} = shift; | 
| return @lines; | } elsif (@_ > 1) { | 
| } | %cfg = @_; | 
| } else { | } | 
| #$! = "Error with command ($cfg{'string'}): $last"; |  | 
| return undef; | $cfg{'Timeout'} ||= $self->Timeout; | 
| } |  | 
| } | unless ($cfg{'String'}) { | 
|  | #$! = "No command passed"; | 
| #=item _decode_lines | #warn "No command passed\n"; | 
|  | return undef; | 
| sub _decode_lines | } | 
| { |  | 
| my @lines = @_; | unless ($self->is_connected) { | 
|  | #$! = "Not connected"; | 
| my %conf; | #warn "Not connected\n"; | 
|  | return undef; | 
| my $key = ''; | } | 
| my $val = ''; |  | 
| my $in_key = 0; | unless ($self->logged_in) { | 
| my $in_val = 0; | #$! = "Not logged in"; | 
|  | #warn "Not logged in\n"; | 
| foreach my $line (@lines) { | return undef; | 
| next if $line =~ /$success$/; | } | 
|  |  | 
| my @chars = split //, $line; |  | 
|  | my %cmd; | 
| my $last_key = ''; | foreach (@valid_net_telnet_opts) { | 
| foreach my $c (@chars) { | if (exists $cfg{$_}) { | 
|  | $cmd{$_} = $cfg{$_}; | 
| if ($c eq '[' || $c eq "\r" || $c eq "\n") { | } | 
| if ($c eq '[') { | } | 
| $in_key = 1; | if ($cfg{'args'}) { | 
| $in_val = 0; | $cmd{'String'} .= ' ' . $cfg{'args'}; | 
| } else { | } | 
| $in_key = 0; | my @lines; | 
| $in_val = 0; | unless ($cfg{'no_prompt'}) { | 
| } | @lines = $self->SUPER::cmd(%cmd); | 
|  | } else { | 
| if ($key) { | $self->print($cmd{'String'}); | 
| $key =~ s/^\s+//; | @lines = $self->lastline; | 
| $key =~ s/\s+$//; | } | 
|  |  | 
| $val =~ s/^\s+//; | $self->last_lines(\@lines); | 
| $val =~ s/\s+$//; |  | 
|  | my $vals = 1; | 
| if ($key eq 'Checksum' && $last_key) { | if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | 
| # Special case for these bastids. | if ($cfg{'decode'} eq 'each') { | 
| my $new = $last_key; | $vals = _decode_each_line(@lines); | 
| $new =~ s/\s+\S+$//; | } elsif ($cfg{'decode'} eq 'sulog') { | 
| $key = $new . " " . $key; | $vals = _decode_sulog(@lines); | 
| } | } elsif ($cfg{'decode'} eq 'maclist') { | 
|  | $vals = _decode_maclist(@lines); | 
| $last_key = $key; | } else { | 
| $conf{$key} = $val; | $vals = _decode_lines(@lines); | 
| $key = ''; | } | 
| $val = ''; | } | 
| } |  | 
|  | $self->last_vals($vals); | 
| } elsif ($c eq ']') { |  | 
| $in_val = 1; |  | 
| $in_key = 0; | my $last = $self->lastline; | 
| $c = shift @chars; |  | 
|  | if ((not $cfg{'expect'}) || $last =~ /$cfg{'expect'}$/) { | 
| } elsif ($in_key) { | if ($cfg{'cmd_disconnects'}) { | 
| $key .= $c; | $self->logged_in(0); | 
|  | $self->close; | 
| } elsif ($in_val) { | $self->is_connected(0); | 
| $val .= $c; | } | 
| } |  | 
| } | if ($PRIVATE{'Decode'} && $cfg{'decode'}) { | 
| } | return $vals; | 
|  | } else { | 
| if (%conf) { | return @lines; | 
| return \%conf; | } | 
| } else { | } else { | 
| return undef; | #$! = "Error with command ($cfg{'string'}): $last"; | 
| } | return undef; | 
| } | } | 
|  | } | 
| #=item _decode_each_line |  | 
|  | #=item _decode_lines | 
| sub _decode_each_line |  | 
| { | sub _decode_lines | 
| my @lines = @_; | { | 
| my @decoded; | my @lines = @_; | 
| foreach my $line (@lines) { |  | 
| my $decoded = _decode_lines($line); | my %conf; | 
| push @decoded, $decoded if defined $decoded; |  | 
| } | my $key = ''; | 
| return \@decoded; | my $val = undef; | 
| } | my $in_key = 0; | 
|  | my $in_val = 1; | 
| #=item _decode_sulog |  | 
|  | foreach my $line (@lines) { | 
| sub _decode_sulog | next if $line =~ /$success$/; | 
| { |  | 
| my @lines = @_; | my @chars = split //, $line; | 
| my @decoded; |  | 
| my $last_tm; | my $last_key = ''; | 
| foreach my $line (@lines) { | foreach my $c (@chars) { | 
| my $decoded = _decode_lines($line); |  | 
|  | if ($c eq '[' || $c eq "\r" || $c eq "\n") { | 
| if (defined $decoded) { | if ($c eq '[') { | 
| if ($decoded->{'tm'}) { | $in_key = 1; | 
| $last_tm = $decoded->{'tm'}; | $in_val = 0; | 
| next; | } else { | 
| } else { | $in_key = 0; | 
| $decoded->{'tm'} = $last_tm; | $in_val = 1; | 
| } | } | 
| next unless $last_tm; |  | 
|  | if ($key) { | 
| push @decoded, $decoded if defined $decoded; | $key =~ s/^\s+//; | 
| } | $key =~ s/\s+$//; | 
| } |  | 
| return \@decoded; | if (defined $val) { | 
| } | $val =~ s/^\s+//; | 
|  | $val =~ s/\s+$//; | 
| 1; | } | 
| __END__ |  | 
|  | if ($key eq 'Checksum' && $last_key) { | 
| =back | # Special case for these bastids. | 
|  | my $new = $last_key; | 
| =head1 SEE ALSO | $new =~ s/\s+\S+$//; | 
|  | $key = $new . " " . $key; | 
| Trango Documentation - http://www.trangobroadband.com/support/product_docs.htm | } | 
|  |  | 
| L<Net::Telnet> | $last_key = $key; | 
|  | $conf{$key} = $val; | 
| =head1 TODO | $key = ''; | 
|  | $val = ''; | 
| 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, please send me examples that work and I will try to get it incorporated into the next version of the script. | } | 
|  |  | 
| I also want to be able to parse the different types of output from commands like su, sudb all and anything else that would be better available as a perl datastructure. | } elsif ($c eq ']') { | 
|  | $in_val = 1; | 
| =head1 AUTHOR | $in_key = 0; | 
|  | $c = shift @chars; | 
| Andrew Fresh E<lt>andrew@rraz.netE<gt> |  | 
|  | } elsif ($in_key) { | 
| =head1 COPYRIGHT AND LICENSE | $key .= $c; | 
|  |  | 
| Copyright (C) 2005 by Andrew Fresh | } elsif ($in_val) { | 
|  | $val .= $c; | 
| This library is free software; you can redistribute it and/or modify | } | 
| 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. | } | 
|  |  | 
|  | if (%conf) { | 
| =cut | return \%conf; | 
|  | } else { | 
|  | return $val; | 
|  | } | 
|  | } | 
|  |  | 
|  | #=item _decode_each_line | 
|  |  | 
|  | sub _decode_each_line | 
|  | { | 
|  | my @lines = @_; | 
|  | my @decoded; | 
|  | foreach my $line (@lines) { | 
|  | my $decoded = _decode_lines($line); | 
|  | push @decoded, $decoded if defined $decoded; | 
|  | } | 
|  | return \@decoded; | 
|  | } | 
|  |  | 
|  | #=item _decode_sulog | 
|  |  | 
|  | sub _decode_sulog | 
|  | { | 
|  | my @lines = @_; | 
|  | my @decoded; | 
|  | my $last_tm; | 
|  | foreach my $line (@lines) { | 
|  | my $decoded = _decode_lines($line); | 
|  |  | 
|  | if (defined $decoded) { | 
|  | if ($decoded->{'tm'}) { | 
|  | $last_tm = $decoded->{'tm'}; | 
|  | next; | 
|  | } else { | 
|  | $decoded->{'tm'} = $last_tm; | 
|  | } | 
|  | next unless $last_tm; | 
|  |  | 
|  | push @decoded, $decoded if defined $decoded; | 
|  | } | 
|  | } | 
|  | return \@decoded; | 
|  | } | 
|  |  | 
|  | #=item _decode_maclist | 
|  |  | 
|  | sub _decode_maclist | 
|  | { | 
|  | my @lines = @_; | 
|  | my @decoded; | 
|  | my $total_entries = 0; | 
|  | my $current_tm = 0; | 
|  | foreach my $line (@lines) { | 
|  | $line =~ s/\r?\n$//; | 
|  | my ($mac, $loc, $tm) = $line =~ / | 
|  | ([0-9a-fA-F ]{17})\s+ | 
|  | (.*)\s+ | 
|  | tm\s+ | 
|  | (\d+) | 
|  | /x; | 
|  |  | 
|  | if ($mac) { | 
|  | $mac =~ s/\s+//g; | 
|  | $loc =~ s/^\s+//; | 
|  | $loc =~ s/\s+$//; | 
|  |  | 
|  | my $suid = undef; | 
|  | if ($loc =~ /suid\s+=\s+(\d+)/) { | 
|  | $suid = $1; | 
|  | $loc = undef; | 
|  | } | 
|  |  | 
|  | push @decoded, { | 
|  | mac  => $mac, | 
|  | loc  => $loc, | 
|  | tm   => $tm, | 
|  | suid => $suid, | 
|  | }; | 
|  | } elsif ($line =~ /(\d+)\s+entries/) { | 
|  | $total_entries = $1; | 
|  | } elsif ($line =~ /current tm = (\d+)\s+sec/) { | 
|  | $current_tm = $1 | 
|  | } | 
|  | } | 
|  |  | 
|  | map { $_->{'cur_tm'} = $current_tm } @decoded; | 
|  |  | 
|  | if (scalar @decoded == $total_entries) { | 
|  | return \@decoded; | 
|  | } else { | 
|  | # XXX we should have a way to set last error, not sure why we don't | 
|  | return undef; | 
|  | } | 
|  | } | 
|  |  | 
|  | 1; | 
|  | __END__ | 
|  |  | 
|  | =back | 
|  |  | 
|  | =head1 SEE ALSO | 
|  |  | 
|  | Trango Documentation - | 
|  | http://www.trangobroadband.com/support/product_docs.htm | 
|  |  | 
|  | L<Net::Telnet> | 
|  |  | 
|  | =head1 TODO | 
|  |  | 
|  | 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, | 
|  | please send me examples that work and I will try to get it incorporated | 
|  | into the next version of the script. | 
|  |  | 
|  | I also want to be able to parse the different types of output from | 
|  | commands like su, sudb all and anything else that would be better | 
|  | available as a perl datastructure. | 
|  |  | 
|  | =head1 AUTHOR | 
|  |  | 
|  | Andrew Fresh E<lt>andrew@rraz.netE<gt> | 
|  |  | 
|  | =head1 COPYRIGHT AND LICENSE | 
|  |  | 
|  | Copyright (C) 2005 by Andrew Fresh | 
|  |  | 
|  | This library is free software; you can redistribute it and/or modify | 
|  | 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. | 
|  |  | 
|  |  | 
|  | =cut |