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