=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.7 retrieving revision 1.11 diff -u -r1.7 -r1.11 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2006/06/28 23:33:18 1.7 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2006/08/23 01:37:20 1.11 @@ -1,5 +1,5 @@ package Net::Telnet::Trango; -# $RedRiver: Trango.pm,v 1.6 2006/06/28 22:00:15 andrew Exp $ +# $RedRiver: Trango.pm,v 1.10 2006/07/31 22:16:52 andrew Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -49,6 +49,11 @@ Same as new from L but has defaults for the trango 'Prompt' +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 +instead return an array of the lines that were returned from the +command. + =cut sub new @@ -67,6 +72,8 @@ foreach my $key (keys %args) { $PRIVATE{$key} = $args{$key}; } + $PRIVATE{'Decode'} = 1 unless defined $PRIVATE{'Decode'}; + delete $args{'Decode'}; my $self = $class->SUPER::new(%args); bless $self if ref $self; @@ -243,6 +250,30 @@ returns an array ref of hashes containing each log line. +=item save_sudb + +returns true on success, undef on failure + +=item syslog + +returns the output from the syslog command + +=item pipe + +returns the output from the pipe command + +=item maclist + +returns the output from the maclist command + +=item maclist_reset + +resets the maclist. No useful output. + +=item eth_list + +returns the output from the eth list command + =cut @@ -255,7 +286,13 @@ sulog => { decode => 'sulog', expect => $success }, 'exit' => { no_prompt => 1, cmd_disconnects => 1 }, reboot => { no_prompt => 1, cmd_disconnects => 1 }, - sudb_save => { String => "sudb save", expect => $success }, + save_sudb => { String => 'save sudb', expect => $success }, + syslog => { expect => $success }, + 'pipe' => { }, # XXX needs a special decode + maclist => { decode => 'maclist' }, + maclist_reset => { String => 'maclist reset', expect => 'done' }, + eth_link => { String => 'eth link', expect => $success }, + # eth r, w and reset??? #su password??? #_bootloader #temp @@ -433,7 +470,6 @@ ); } - =pod =item sudb_view @@ -456,8 +492,13 @@ return undef unless @lines; + unless ($PRIVATE{'Decode'}) { + return @lines; + } + my @sus; foreach (@lines) { + next unless $_; if (/^\[(\d+)\]\s+(\d+)\s+(\d+)\s+(\d+)\s+([0-9A-Fa-f\s]+)$/) { my %s = ( suid => $1, @@ -491,7 +532,7 @@ and returns true on success or undef otherwise. -You should sudb_save() after calling this, or your changes will be lost +You should save_sudb() after calling this, or your changes will be lost when the AP is rebooted. =cut @@ -550,7 +591,7 @@ Takes either 'all' or the suid of the su to delete and returns true on success or undef otherwise. -You should sudb_save() after calling this, or your changes will be lost +You should save_sudb() after calling this, or your changes will be lost when the AP is rebooted. =cut @@ -567,7 +608,6 @@ return $self->cmd( String => 'sudb delete ' . $suid, expect => $success ); } - =pod =item sudb_modify @@ -580,7 +620,7 @@ su2su takes a group id parameter that is in hex. -You should sudb_save() after calling this, or your changes will be lost +You should save_sudb() after calling this, or your changes will be lost when the AP is rebooted. =cut @@ -697,9 +737,9 @@ ); my %cfg; - if (@_ == 2) { + if (@_ == 1) { $cfg{'String'} = shift; - } elsif (@_ > 2) { + } elsif (@_ > 1) { %cfg = @_; } @@ -744,11 +784,13 @@ $self->last_lines(\@lines); my $vals = 1; - if ($cfg{'decode'}) { + if ($PRIVATE{'Decode'} && $cfg{'decode'}) { if ($cfg{'decode'} eq 'each') { $vals = _decode_each_line(@lines); } elsif ($cfg{'decode'} eq 'sulog') { $vals = _decode_sulog(@lines); + } elsif ($cfg{'decode'} eq 'maclist') { + $vals = _decode_maclist(@lines); } else { $vals = _decode_lines(@lines); } @@ -766,7 +808,7 @@ $self->is_connected(0); } - if ($cfg{'decode'}) { + if ($PRIVATE{'Decode'} && $cfg{'decode'}) { return $vals; } else { return @lines; @@ -884,6 +926,51 @@ } } return \@decoded; +} + +#=item _decode_maclist + +sub _decode_maclist +{ + my @lines = @_; + my @decoded; + my $total_entries = 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; + } + } + 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;