Trango.pm

filter: Statementstmt 28.1% 118 / 419 Branchbran 21.2% 45 / 212 Conditioncond 11.5% 8 / 69 MC/DCmcdc 4.6% 2 / 43 Subroutinesub 32.0% 8 / 25 Podpod 100% 15 / 15 totaltotal 25.0% 196 / 783 CC 143 SCAR 54.1
CC
143
Cov
24%
cmd
992.0
sudb_view
110.0
_decode_lines
93.9
CRAP 223.8
↑ Summary Trango/ConfigData.pm »
1 package Net::Telnet::Trango;
2  
3 # $RedRiver: Trango.pm,v 1.60 2009/07/31 21:46:07 andrew Exp $
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use base 'Net::Telnet';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =pod
9  
10 =head1 NAME
11  
12 Net::Telnet::Trango
13 - Perl extension for accessing the Trango telnet interface
14  
15 =head1 SYNOPSIS
16  
17 use Net::Telnet::Trango;
18 my $t = new Net::Telnet::Trango ( Timeout => 5 );
19  
20 $t->open( Host => $ap ) or die "Error connecting: $!";
21  
22 $t->login('password') or die "Couldn't log in: $!";
23  
24 # Do whatever
25  
26 $t->exit;
27 $t->close;
28  
29 =head1 DESCRIPTION
30  
31 Perl access to the telnet interface on Trango APs and SUs.
32  
33 A handy feature is that it will parse the output from certain commands that is
34 in the format "[key1] value1 [key2] value2" and put those in a hashref that is
35 returned. This makes using the output from things like sysinfo very easy to
36 do.
37  
38 =head2 EXPORT
39  
40 None
41  
42 =head1 METHODS
43  
44 =cut
45  
46 12 our $VERSION = '0.05';
47  
48 12 my $EMPTY = q{};
49 12 my $SPACE = q{ };
50  
51 =pod
52  
53 =head2 B<new> - Creates a new Net::Telnet::Trango object.
54  
55 new([Options from Net::Telnet,]
56 [Decode => 0,]);
57  
58 Same as new from L<Net::Telnet> but sets the default Trango Prompt:
59 '/[\$#]>\s*\Z/'
60  
61 It also takes an optional parameter 'Decode'. If not defined it
62 defaults to 1, if it is set to 0, it will not decode the output and
63 instead return a reference to an array of the lines that were returned
64 from the command.
65  
66 =cut
67  
68 6 ▶sub new {
Subroutine new: called CC=5 SCAR=16.6
Pod documented
69 6 my $class = shift;
70  
71 6 my %args = ();
72 6 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 6 6
73 0 $args{'Host'} = shift;
74 }
75 else {
76 6 %args = @_;
77 }
78  
79 6 ▶ $args{'Prompt'} ||= '/[\$#]>\s*\r?\n?$/';
Condition50%1/2
$args{"Prompt"} ||= "/[\\\$#]>\\s*\\r?\\n?\$/"
l!l
06
MC/DC0%0/1
$args{"Prompt"} ||= "/[\\\$#]>\\s*\\r?\\n?\$/"
$args{"Prompt"}
Truth table50%1/2
A
A= $args{"Prompt"}
Aresult
11
00
80  
81 6 my $decode = $args{'Decode'};
82 6 delete $args{'Decode'};
83  
84 6 my $self = $class->SUPER::new(%args);
85 6 ▶ bless $self if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 6 0 6
86  
87 6 ▶ $args{Decode} = defined $decode ? $decode : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $decode ? : 0 6 6
88 6 $args{is_connected} = 0;
89 6 $args{logged_in} = 0;
90  
91 6 *$self->{net_telnet_trango} = \%args;
92  
93 6 return $self;
94 }
95  
96 # _password <new password> <new password>
97 # ? [command]
98 # apsearch <secs> <ch#> <h|v> [<ch#> <h|v>]...
99 # arp -bcast <on|off>
100 # bcastscant <all|suid> <ch#> <h|v> [<ch#> <h|v> ...
101 # bye
102 # cf2cf ap [default|<size>]
103 # date
104 # date <month> <day> <year>
105 # freq scantable
106 # freq channeltable
107 # freq writescan [<ch#> <h|v>]
108 # freq writechannel [<ch#> <freq>] ...
109 # freq <ch #> <h|v>
110 # help [command]
111 # heater [<on temp> <off temp>]
112 # ipconfig [<new ip> <new subnet mask> <new gateway>]
113 # linktest <suid> [<pkt len, bytes> [<# of pkts> [<# of cycle>]]]
114 # log [<# of entries, 1..179>]
115 # log <sum> <# of entries, 1..179>
116 # logout
117 # opmode [ap [y]]
118 # password
119 # ping <ip addr>
120 # polar <h|v>
121 # power <setism|setunii> <max|min|<dBm>>
122 # reboot
123 # restart
124 # remarks [<str>]
125 # rfrxthreshold [<ism|unii> <-90|-85|-80|-75|-70|-65>]
126 # rfrxth [<ism|unii> <-90|-85|-80|-75|-70|-65>]
127 # sysinfo
128 # set suid <id>
129 # set apid <id>
130 # set baseid <id>
131 # set defaultopmode [<ap|su> <min,0..10>]
132 # set defaultopmode off
133 # set snmpcomm [<read | write | trap (id or setall)> <str>]
134 # set mir [on|off]
135 # set mir threshold <kbps>
136 # set rssitarget [<ism|unii> <dBm>]
137 # set serviceradius [<ism | unii> <miles>]
138 # ssrssi <ch #> <h|v>
139 # su [<suid>|all]
140 # su changechannel <all|suid> <ch#> <h|v>
141 # su ipconfig <suid> <new ip> <new subnet> <new gateway>
142 # su [live|poweroff|priority]
143 # su <ping|info|status> <suid>
144 # su powerleveling <all|suid>
145 # su reboot <all|suid>
146 # su restart <all|suid>
147 # su testrflink <all|suid> [r]
148 # su testrflink <setlen> [64..1600]
149 # su testrflink <aptx> [20..100]
150 # su sw <suid|all> <sw #> <on|off>
151 # sudb [dload | view]
152 # sudb add <suid> pr <cir,kbps> <mir,kbps> <device id,hex>
153 # sudb add <suid> reg <cir,kbps> <mir,kbps> <device id,hex>
154 # sudb delete <all|<suid>>
155 # sudb modify <suid> <cir|mir> <kbps>
156 # sudb modify <suid> <su2su> <group id,hex>
157 # sudb view
158 # sulog [lastmins | sampleperiod <1..60>]
159 # sulog [<# of entry,1..18>]
160 # survey <ism|unii> <time, sec> <h|v>
161 # sw [<sw #> <on|off>]
162 # temp
163 # tftpd [on|off]
164 # time
165 # time <hour> <min> <sec>
166 # save <mainimage|fpgaimage> <current chksum> <new chksum>
167 # save <systemsetting|sudb>
168 # updateflash <mainimage|fpgaimage> <current chksum> <new chksum>
169 # updateflash <systemsetting|sudb>
170  
171 =pod
172  
173 =head1 ACCESSORS
174  
175 These are usually only set internally.
176  
177 =head2 B<firmware_version> - returns the firmware version
178  
179 Returns the firmware version if available, otherwise undef.
180  
181 It should be available after a successful open().
182  
183 =head2 B<host_type> - return the type of host you are connected to.
184  
185 returns the type of host from the login banner for example M5830S or M5300S.
186  
187 Should be available after a successful open().
188  
189 =head2 B<is_connected> - Status of the connection to host.
190  
191 returns 1 when connected, undef otherwise.
192  
193 =head2 B<logged_in> - Status of being logged in to the host.
194  
195 returns 1 after a successful login(), 0 if it failed and undef if
196 login() was never called.
197  
198 =head2 B<login_banner> - The banner when first connecting to the host.
199  
200 returns the banner that is displayed when first connected at login.
201 Only set after a successful open().
202  
203 =head2 B<last_lines> - The last lines of output from the last cmd().
204  
205 returns, as an array ref, the output from the last cmd() that was run.
206  
207 =head2 B<last_error> - A text output of the last error that was encountered.
208  
209 returns the last error reported. Probably contains the last entry in
210 last_lines.
211  
212 =head1 ALIASES
213  
214 =head2 B<bye> - alias of exit()
215  
216 Does the same as exit()
217  
218 =head2 B<restart> - alias of reboot()
219  
220 Does the same as reboot()
221  
222 =head2 B<save_systemsetting> - alias of save_ss()
223  
224 Does the same as save_ss()
225  
226 =head1 COMMANDS
227  
228 Most of these are just shortcuts to C<cmd(String =E<gt> METHOD)>,
229 as such they accept the same options as C<cmd()>.
230 Specifically they take a named paramater "args", for example:
231 C<tftpd(args =E<gt> 'on')> would enable tftpd
232  
233 =head2 B<tftpd> - The output from the tftpd command
234  
235 Returns a hash ref of the decoded output from the
236 command.
237  
238 Also see enable_tftpd() and disable_tftpd() as those check that it was
239 successfully changed.
240  
241 =head2 B<ver> - The output from the ver command
242  
243 Returns a hash ref of the decoded output from the
244 command.
245  
246 =head2 B<sysinfo> - The output from the sysinfo command
247  
248 Returns a hash ref of the decoded output from the
249 command.
250  
251 =head2 B<exit> - Exits the connection
252  
253 exits the command session with the Trango and closes
254 the connection
255  
256 =head2 B<reboot> - Sends a reboot command
257  
258 reboots the Trango and closes the connection
259  
260 =head2 B<reset> <all|0..2> - Sends a reset command
261  
262 resets settings to default
263  
264 =head2 B<remarks> - Set or retrieve the remarks.
265  
266 Takes an optional argument, which sets the remarks.
267 If there is no argument, returns the current remarks.
268  
269 my $old_remarks = $t->remarks();
270 $t->remarks($new_remarks);
271  
272 =head2 B<sulog> - The output from the sulog command
273  
274 Returns an array ref of hashes containing each log
275 line.
276  
277 =head2 B<save_sudb> - saves the sudb
278  
279 Returns true on success, undef on failure
280  
281 =head2 B<syslog> - The output from the sulog command
282  
283 Returns a hashref of the output from the syslog command
284  
285 =head2 B<pipe> - the pipe command
286  
287 Returns the output from the pipe command
288  
289 =head2 B<maclist> - retrieves the maclist
290  
291 Returns the output from the maclist command
292  
293 =head2 B<maclist_reset> - resets the maclist.
294  
295 No useful output.
296  
297 =head2 B<eth_link> - eth link command
298  
299 Returns the output from the eth link command
300  
301 This command seems to cause some weird issues. It often will cause the
302 command after it to appear to fail. I am not sure why.
303  
304 =head2 B<su_info> - gets the su info
305  
306 Returns information about the SU.
307  
308 You need to pass in the $suid and it will return the info for that suid.
309  
310 $t->su_info($suid);
311  
312 =head2 B<su_testrflink> - tests the RF Link to an su
313  
314 $t->su_testrflink($suid|'all');
315  
316 =head2 B<save_ss> - saves the config.
317  
318 Returns 1 on success, undef on failure.
319  
320 =head2 B<set_baseid> - sets baseid
321  
322 $t->set_baseid($baseid);
323  
324 =head2 B<set_suid> - sets baseid
325  
326 $t->set_suid($baseid);
327  
328 =head2 B<set_defaultopmode> - sets default opmode
329  
330 $t->set_defaultopmode(ap|su);
331  
332 =head2 B<opmode> - sets or returns the opmode
333  
334 $t->opmode([ap y|su y]);
335  
336 =head2 B<freq> - sets or returns the freq
337  
338 $channel = '11 v';
339 $t->freq([$channel]);
340  
341 =head2 B<freq_writescan> - sets the freq writescan
342  
343 $channels = '11 v 11 h 12 v 12 h';
344 $t->freq_writescan($channels);
345  
346 =head2 B<freq_scantable> - returns the freq scantable
347  
348 $channels = $t->freq_scantable();
349 # now $channels eq '11 v 11 h 12 v 12 h';
350  
351  
352 =cut
353  
354 12 my $success = 'Success\\.';
355 12 my %COMMANDS = (
356 _clear => { String => "\n" },
357 tftpd => { decode => 'all', expect => $success },
358 ver => { decode => 'all' },
359 sysinfo => { decode => 'all', expect => $success },
360 updateflash => { decode => 'all', expect => $success },
361 sulog => { decode => 'sulog', expect => $success },
362 'exit' => { no_prompt => 1, cmd_disconnects => 1 },
363 reboot => { no_prompt => 1, cmd_disconnects => 1 },
364 'reset' => {},
365 remarks => { decode => 'all', expect => $success },
366 save_sudb => { String => 'save sudb', expect => $success },
367 syslog => { expect => $success },
368 'pipe' => {}, # XXX needs a special decode
369 maclist => { decode => 'maclist' },
370 maclist_reset => { String => 'maclist reset', expect => 'done' },
371 eth_link => { String => 'eth link', expect => $success },
372 su_info => { String => 'su info', decode => 'all', expect => $success },
373 su_testrflink =>
374 { String => 'su testrflink', decode => 'each', expect => $success },
375 save_ss => { String => 'save ss', expect => $success },
376 set_baseid => {
377 String => 'set baseid',
378 decode => 'all',
379 expect => $success
380 },
381 set_suid => {
382 String => 'set suid',
383 decode => 'all',
384 expect => $success
385 },
386 set_defaultopmode => {
387 String => 'set defaultopmode',
388 decode => 'all',
389 expect => $success
390 },
391 opmode => { decode => 'all', expect => $success },
392 freq => { decode => 'freq', expect => $success },
393 freq_writescan =>
394 { String => 'freq writescan', decode => 'all', expect => $success },
395 freq_scantable =>
396 { String => 'freq scantable', decode => 'all', expect => $success },
397 arq => { decode => 'all' },
398 );
399  
400 12 my %ALIASES = (
401 bye => 'exit',
402 restart => 'reboot',
403 Host => 'host',
404 save_systemseting => 'save_ss',
405 );
406  
407 12 my %ACCESS = map { $_ => 1 } qw(
408 firmware_version
409 host_type
410 is_connected
411 logged_in
412 login_banner
413 Timeout
414 last_lines
415 last_vals
416 last_error
417 Decode
418 );
419  
420 42 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=9 SCAR=31.8
421 42 my $self = shift;
422  
423 42 ▶ my ($method) = ( our $AUTOLOAD ) =~ /^.*::(\w+)$/
Branch: 1 branch
BranchTrueFalseTotal
my($method) = our $AUTOLOAD =~ /^.*::(\w+)$/ or die "Weird: $Net::Telnet::Trango::AUTOLOAD" 42 0 42
424 or die "Weird: $AUTOLOAD";
425  
426 42 ▶ if ( exists $ALIASES{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ALIASES{$method}) 0 42 42
427 0 $method = $ALIASES{$method};
428 0 return $self->$method(@_);
429 }
430  
431 42 ▶ if ( exists $COMMANDS{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $COMMANDS{$method}) 0 42 42
432 0 my %cmd;
433 0 foreach my $k ( keys %{ $COMMANDS{$method} } ) {
434 0 $cmd{$k} = $COMMANDS{$method}{$k};
435 }
436 0 ▶ $cmd{'String'} ||= $method;
Condition0%0/3
$cmd{"String"} ||= $method
l!l&&r!l&&!r
000
MC/DC0%0/2
$cmd{"String"} ||= $method
$cmd{"String"} $method
Truth table0%0/3
A ||= B
A= $cmd{"String"}B= $method
ABresult
1X1
011
000
437 0 ▶ $cmd{'args'} .= $SPACE . shift if ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
438 0 return $self->cmd( %cmd, @_ );
439 }
440  
441 42 ▶ if ( exists $ACCESS{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ACCESS{$method}) 42 0 42
442 42 my $s = *$self->{net_telnet_trango};
443 42 my $prev = $s->{$method};
444 42 ▶ ( $s->{$method} ) = @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 24 18 42
445 42 return $prev;
446 }
447  
448 0 $method = "SUPER::$method";
449 0 return $self->$method(@_);
450 }
451  
452 =pod
453  
454 =head2 B<open> - Open a connection to a Trango AP.
455  
456 Calls Net::Telnet::open() then makes sure you get a password prompt so
457 you are ready to login() and parses the login banner so you can get
458 host_type() and firmware_version()
459  
460 =cut
461  
462 0 ▶sub open {
Subroutine open: not called CC=3 SCAR=24.8
Pod documented
463 0 my $self = shift;
464  
465 0 ▶ unless ( $self->SUPER::open(@_) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->SUPER::open(@_)) 0 0 0
466 0 $self->last_error( "Couldn't connect to " . $self->host . ": $!" );
467 0 return;
468 }
469  
470 ## Get to login prompt
471 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->waitfor("-match", "/password: ?\$/i", "-errmode", "return")) 0 0 0
472 $self->waitfor(
473 -match => '/password: ?$/i',
474 -errmode => "return",
475 )
476 )
477 {
478 0 $self->last_error( "problem connecting to host ("
479 . $self->host . "): "
480 . $self->lastline );
481 0 return;
482 }
483  
484 0 $self->parse_login_banner( $self->lastline );
485  
486 0 $self->is_connected(1);
487  
488 0 return $self->is_connected;
489 }
490  
491 =pod
492  
493 =head2 B<login> - Login to the AP.
494  
495 Calls open() if not already connected, then sends the password and sets
496 logged_in() if successful
497  
498 =cut
499  
500 0 ▶sub login {
Subroutine login: not called CC=4 SCAR=30.0
Pod documented
501 0 my $self = shift;
502  
503 0 ▶ unless ( $self->is_connected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_connected) 0 0 0
504 0 ▶ $self->open or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->open or return 0 0 0
505 }
506  
507 0 my $password = shift;
508  
509 0 $self->print($password);
510 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->waitfor("-match", $self->prompt, "-errmode", "return")) 0 0 0
511 $self->waitfor(
512 -match => $self->prompt,
513 -errmode => "return",
514 )
515 )
516 {
517 0 $self->last_error( "login ($self->host) failed: " . $self->lastline );
518 0 return;
519 }
520  
521 0 $self->logged_in(1);
522  
523 0 return $self->logged_in;
524 }
525  
526 =pod
527  
528 =head2 B<parse_login_banner> - Converts the login_banner to something useful.
529  
530 Takes a login banner (what you get when you first connect to the Trango)
531 or reads what is already in login_banner() then parses it and sets
532 host_type() and firmware_version() as well as login_banner()
533  
534 =cut
535  
536 6 ▶sub parse_login_banner {
Subroutine parse_login_banner: called CC=2 SCAR=6.9
Pod documented
537 6 my $self = shift;
538  
539 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 0 6
540 6 $self->login_banner(@_);
541 }
542  
543 6 my $banner = $self->login_banner;
544  
545 6 my ( $type, $sep1, $subtype, $sep2, $ver )
546 = $banner
547 =~ /Welcome to Trango Broadband Wireless,? (\S+)([\s-]+)(\S+)([\s-]+)(.+)$/i;
548  
549 6 $type .= $sep1 . $subtype;
550 6 $ver = $subtype . $sep2 . $ver;
551  
552 6 $self->login_banner($banner);
553 6 $self->host_type($type);
554 6 $self->firmware_version($ver);
555  
556 6 return 1;
557 }
558  
559 =pod
560  
561 =head2 B<linktest> - Link test to SU
562  
563 linktest('suid'[, 'pkt len, bytes'[, '# of pkts'[, '# of cycles']]]);
564  
565 Returns a hash reference to the results of the test
566  
567 =cut
568  
569 0 ▶sub linktest {
Subroutine linktest: not called CC=5 SCAR=34.0
Pod documented
570 0 my $self = shift;
571 0 my $suid = shift;
572  
573 # These numbers are what I found as defaults when running the command
574 0 ▶ my $pkt_len = shift || 1600;
Condition0%0/2
shift() || 1600
l!l
00
MC/DC0%0/1
shift() || 1600
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
575 0 ▶ my $pkt_cnt = shift || 500;
Condition0%0/2
shift() || 500
l!l
00
MC/DC0%0/1
shift() || 500
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
576 0 ▶ my $cycles = shift || 10;
Condition0%0/2
shift() || 10
l!l
00
MC/DC0%0/1
shift() || 10
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
577  
578 0 my %config = @_;
579  
580 # * 2, one for the FromAP, one FromSU. Then / 1000 to get to ms.
581 # XXX This might need to be changed, this makes the default timeout the
582 # same as $pkt_len, and that might not be enough at slower speeds.
583 0 ▶ $config{Timeout} ||= int( ( $pkt_len * $pkt_cnt * $cycles * 2 ) / 1000 );
Condition0%0/3
$config{"Timeout"} ||= int $pkt_len * $pkt_cnt * $cycles * 2 / 1000
l!l&&r!l&&!r
000
MC/DC0%0/2
$config{"Timeout"} ||= int $pkt_len * $pkt_cnt * $cycles * 2 / 1000
$config{"Timeout"} int $pkt_len * $pkt_cnt * $cycles * 2 / 1000
Truth table0%0/3
A ||= B
A= $config{"Timeout"}B= int $pkt_len * $pkt_cnt * $cycles * 2 / 1000
ABresult
1X1
011
000
584  
585 0 my $string = join $SPACE, 'linktest', $suid, $pkt_len, $pkt_cnt, $cycles;
586 0 return $self->cmd(
587 %config,
588 String => $string,
589 decode => 'linktest',
590 );
591  
592 }
593  
594 =pod
595  
596 =head2 B<su_password> - Set the password on SUs connected to the AP.
597  
598 su_password('new_password'[, 'suid']) If no suid is specified,
599 the default is "all".
600  
601 $t->su_password('good_pass', 5);
602  
603 =cut
604  
605 0 ▶sub su_password {
Subroutine su_password: not called CC=4 SCAR=30.0
Pod documented
606 0 my $self = shift;
607 0 ▶ my $new_pass = shift || $EMPTY;
Condition0%0/3
shift() || $EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $EMPTY
shift() $EMPTY
Truth table0%0/3
A || B
A= shift()B= $EMPTY
ABresult
1X1
011
000
608 0 ▶ my $su = shift || 'all';
Condition0%0/2
shift() || 'all'
l!l
00
MC/DC0%0/1
shift() || 'all'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
609  
610 0 ▶ unless ( defined $new_pass ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_pass) 0 0 0
611 0 $self->last_error("No new password");
612  
613 #return;
614 }
615  
616 0 return $self->cmd(
617 String => 'su password '
618 . $su
619 . $SPACE
620 . $new_pass
621 . $SPACE
622 . $new_pass,
623 expect => $success,
624 );
625 }
626  
627 =pod
628  
629 =head2 B<ipconfig> - Change IP configuration
630  
631 ipconfig( 'new_ip', 'new_subnet', 'new_gateway' )
632  
633 $t->ipconfig( '10.0.1.5', '255.255.255.0', '10.0.1.1' );
634  
635 =cut
636  
637 0 ▶sub ipconfig {
Subroutine ipconfig: not called CC=4 SCAR=30.0
Pod documented
638 0 my $self = shift;
639  
640 0 my $string = join $SPACE, 'ipconfig', @_;
641  
642 0 ▶ if ( @_ == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) 0 0 0
643 0 $self->print($string);
644 0 my @lines = $self->waitfor( Match => '/save\s+and\s+activate/', );
645 0 $self->print('y');
646  
647 0 $self->logged_in(0);
648 0 $self->is_connected(0);
649  
650 0 foreach my $line (@lines) {
651 0 ▶ if ( $line =~ s/New \s configuration:\s+//xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/New \s configuration:\s+//msx) 0 0 0
652 0 return _decode_lines($line);
653 }
654 }
655  
656 0 return {};
657 }
658  
659 # ipconfig [ <new ip> <new subnet> <new gateway> ]
660 0 return $self->cmd( String => $string, expect => $success );
661 }
662  
663 =pod
664  
665 =head2 B<su_ipconfig> - Change IP configuration on SUs connected to the AP.
666  
667 su_ipconfig( 'suid', 'new_ip', 'new_subnet', 'new_gateway' )
668  
669 $t->su_ipconfig( 5, '10.0.1.5', '255.255.255.0', '10.0.1.1' );
670  
671 =cut
672  
673 0 ▶sub su_ipconfig {
Subroutine su_ipconfig: not called CC=5 SCAR=34.0
Pod documented
674 0 my $self = shift;
675  
676 0 my $suid = shift;
677 0 my $new_ip = shift;
678 0 my $new_subnet = shift;
679 0 my $new_gateway = shift;
680  
681 0 ▶ if ( $suid =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suid =~ /\D/) 0 0 0
682 0 $self->last_error("Invalid suid '$suid'");
683 0 return;
684 }
685 0 ▶ unless ($new_ip) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_ip) 0 0 0
686 0 $self->last_error("no new_ip passed");
687 0 return;
688 }
689 0 ▶ unless ($new_subnet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_subnet) 0 0 0
690 0 $self->last_error("no new_subnet passed");
691 0 return;
692 }
693 0 ▶ unless ($new_gateway) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_gateway) 0 0 0
694 0 $self->last_error("no new_gateway passed");
695 0 return;
696 }
697  
698 # su ipconfig <suid> <new ip> <new subnet> <new gateway>
699 0 return $self->cmd(
700 String => 'su ipconfig '
701 . $suid
702 . $SPACE
703 . $new_ip
704 . $SPACE
705 . $new_subnet
706 . $SPACE
707 . $new_gateway,
708 expect => $success,
709 );
710 }
711  
712 =pod
713  
714 =head2 B<sudb_view> - Returns the output from the sudb view command
715  
716 returns a reference to an array of hashes each containing these keys
717 'suid', 'su2su', 'type', 'cir', 'mir' and 'mac'
718  
719 =cut
720  
721 0 ▶sub sudb_view {
Subroutine sudb_view: not called CC=10 SCAR=47.0
Pod documented
722 0 my $self = shift;
723  
724 0 ▶ my $lines = $self->cmd( String => 'sudb view', expect => $success ) || [];
Condition0%0/2
$self->cmd('String', 'sudb view', 'expect', $success) || []
l!l
00
MC/DC0%0/1
$self->cmd('String', 'sudb view', 'expect', $success) || []
$self->cmd('String', 'sudb view', 'expect', $success)
Truth table0%0/2
A
A= $self->cmd('String', 'sudb view', 'expect', $success)
Aresult
11
00
725  
726 0 ▶ return unless @{$lines};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$lines;} 0 0 0
727  
728 0 my $s = *$self->{net_telnet_trango};
729 0 ▶ return $lines if !$s->{'Decode'};
Branch: 1 branch
BranchTrueFalseTotal
unless $s->{"Decode"} 0 0 0
730  
731 0 my @sus;
732 0 foreach ( @{$lines} ) {
733 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
734 0 ▶ if (/^
Branch: 1 branch
BranchTrueFalseTotal
if (/^ \[(\d+)\] \s+ [[:xdigit:]]{2} ([[:xdigit:]]) ([[:xdigit:]]) \s+ (\d+) \s+ (\d+) \s+ ([[:xdigit:]\s]+) $/imsx) 0 0 0
735 \[(\d+)\]
736 \s+
737 [[:xdigit:]]{2}
738 ([[:xdigit:]])
739 ([[:xdigit:]])
740 \s+
741 (\d+)
742 \s+
743 (\d+)
744 \s+
745 ([[:xdigit:]\s]+)
746 $/ixms
747 )
748 {
749 0 ▶ my %s = (
Branch: 3 branches
BranchTrueFalseTotal
$2 ? : 0 0 0
$3 == 1 ? : 0 0 0
$3 == 5 ? : 0 0 0
750 suid => $1,
751 su2su => $2 ? $2 : undef,
752 type => $3 == 1 ? 'reg' : $3 == 5 ? 'pri' : $3,
753 cir => $4,
754 mir => $5,
755 mac => $6,
756 );
757  
758 0 $s{'mac'} =~ s/\s//gxms;
759 0 $s{'mac'} = uc( $s{'mac'} );
760  
761 0 push @sus, \%s;
762 }
763 }
764  
765 0 return \@sus;
766 }
767  
768 =pod
769  
770 =head2 B<sudb_add> - Adds an su to the sudb
771  
772 Takes the following paramaters
773  
774 suid : numeric,
775 type : (reg|pr)
776 cir : numeric,
777 mir : numeric,
778 mac : Almost any format, it will be reformatted,
779  
780 and returns true on success or undef otherwise.
781  
782 $t->sudb_add($suid, 'reg', $cir, $mir, $mac);
783  
784 You should save_sudb() after calling this, or your changes will be lost
785 when the AP is rebooted.
786  
787 =cut
788  
789 0 ▶sub sudb_add {
Subroutine sudb_add: not called CC=7 SCAR=40.3
Pod documented
790 0 my $self = shift;
791 0 my $suid = shift;
792 0 my $type = shift;
793 0 my $cir = shift;
794 0 my $mir = shift;
795 0 my $mac = shift;
796  
797 0 ▶ if ( $suid =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suid =~ /\D/) 0 0 0
798 0 $self->last_error("Invalid suid '$suid'");
799 0 return;
800 }
801  
802 0 ▶ unless ( lc($type) eq 'reg' || lc($type) eq 'pr' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (lc $type eq "reg" or lc $type eq "pr") 0 0 0
Condition0%0/3
lc $type eq "reg" or lc $type eq "pr"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $type eq "reg" or lc $type eq "pr"
lc $type eq "reg" lc $type eq "pr"
Truth table0%0/3
A or B
A= lc $type eq "reg"B= lc $type eq "pr"
ABresult
1X1
011
000
803 0 $self->last_error("Invalid type '$type'");
804 0 return;
805 }
806  
807 0 ▶ if ( $cir =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cir =~ /\D/) 0 0 0
808 0 $self->last_error("Invalid CIR '$cir'");
809 0 return;
810 }
811  
812 0 ▶ if ( $mir =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mir =~ /\D/) 0 0 0
813 0 $self->last_error("Invalid MIR '$mir'");
814 0 return;
815 }
816  
817 0 my $new_mac = $mac;
818 0 $new_mac =~ s/[^0-9A-Fa-f]//g;
819 0 ▶ unless ( length $new_mac == 12 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $new_mac == 12) 0 0 0
820 0 $self->last_error("Invalid MAC '$mac'");
821 0 return;
822 }
823 0 $new_mac = join $SPACE, $new_mac =~ /../g;
824  
825 0 my $string
826 = 'sudb add '
827 . $suid
828 . $SPACE
829 . $type
830 . $SPACE
831 . $cir
832 . $SPACE
833 . $mir
834 . $SPACE
835 . $new_mac;
836  
837 0 return $self->cmd( String => $string, expect => $success );
838 }
839  
840 =pod
841  
842 =head2 B<sudb_delete> - removes an su from the sudb
843  
844 Takes either 'all' or the suid of the su to delete
845 and returns true on success or undef otherwise.
846  
847 $t->sudb_delete($suid);
848  
849 You should save_sudb() after calling this, or your changes will be lost
850 when the AP is rebooted.
851  
852 =cut
853  
854 0 ▶sub sudb_delete {
Subroutine sudb_delete: not called CC=2 SCAR=17.9
Pod documented
855 0 my $self = shift;
856 0 my $suid = shift;
857  
858 #if (lc($suid) ne 'all' || $suid =~ /\D/) {
859 0 ▶ if ( $suid =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suid =~ /\D/) 0 0 0
860 0 $self->last_error("Invalid suid '$suid'");
861 0 return;
862 }
863  
864 0 return $self->cmd( String => 'sudb delete ' . $suid, expect => $success );
865 }
866  
867 =pod
868  
869 =head2 B<sudb_modify> - changes the su information in the sudb
870  
871 Takes either the suid of the su to change
872 as well as what you are changing, either "cir, mir or su2su"
873 and returns true on success or undef otherwise.
874  
875 cir and mir also take a value to set the cir/mir to.
876  
877 su2su takes a group id parameter that is in hex.
878  
879 $t->sudb_modify($suid, 'cir', 512);
880  
881 You should save_sudb() after calling this, or your changes will be lost
882 when the AP is rebooted.
883  
884 =cut
885  
886 0 ▶sub sudb_modify {
Subroutine sudb_modify: not called CC=7 SCAR=40.3
Pod documented
887 0 my $self = shift;
888 0 my $suid = shift;
889 0 my $opt = shift;
890 0 my $value = shift;
891  
892 0 ▶ if ( $suid =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suid =~ /\D/) 0 0 0
893 0 $self->last_error("Invalid suid '$suid'");
894 0 return;
895 }
896  
897 0 ▶ if ( lc($opt) eq 'cir' or lc($opt) eq 'mir' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $opt eq 'cir' or lc $opt eq 'mir') { } 0 0 0
elsif (lc $opt eq 'su2su') { } 0 0 0
Condition0%0/3
lc $opt eq "cir" or lc $opt eq "mir"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $opt eq "cir" or lc $opt eq "mir"
lc $opt eq "cir" lc $opt eq "mir"
Truth table0%0/3
A or B
A= lc $opt eq "cir"B= lc $opt eq "mir"
ABresult
1X1
011
000
898 0 ▶ if ( $value =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\D/) 0 0 0
899 0 $self->last_error("Invalid $opt '$value'");
900 0 return;
901 }
902 }
903 elsif ( lc($opt) eq 'su2su' ) {
904 0 ▶ if ( $value =~ /[^0-9A-Za-f]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /[^0-9A-Za-f]/) 0 0 0
905 0 $self->last_error("Invalid MAC '$value'");
906 0 return;
907 }
908 }
909 else {
910 0 $self->last_error("Invalid option '$opt'");
911 0 return;
912 }
913  
914 0 my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value;
915  
916 0 return $self->cmd( String => $string, expect => $success );
917 }
918  
919 =pod
920  
921 =head2 B<enable_tftpd> - enable the TFTP server
922  
923 runs C<tftpd(args =E<gt> 'on')> and makes sure that Tftpd is now 'listen'ing
924  
925 =cut
926  
927 0 ▶sub enable_tftpd {
Subroutine enable_tftpd: not called CC=3 SCAR=24.8
Pod documented
928 0 my $self = shift;
929  
930 0 my $vals = $self->tftpd( args => 'on' );
931  
932 0 ▶ if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'listen' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vals eq 'HASH' and $vals->{'Tftpd'} eq 'listen') { } 0 0 0
Condition0%0/3
ref $vals eq "HASH" and $vals->{"Tftpd"} eq "listen"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $vals eq "HASH" and $vals->{"Tftpd"} eq "listen"
ref $vals eq "HASH" $vals->{"Tftpd"} eq "listen"
Truth table0%0/3
A and B
A= ref $vals eq "HASH"B= $vals->{"Tftpd"} eq "listen"
ABresult
0X0
100
111
933 0 return $vals;
934 }
935 else {
936 0 return;
937 }
938 }
939  
940 =pod
941  
942 =head2 B<disable_tftpd> - disable the TFTP server
943  
944 runs C<tftpd(args =E<gt> 'off')> and makes sure that Tftpd is now 'disabled'
945  
946 =cut
947  
948 0 ▶sub disable_tftpd {
Subroutine disable_tftpd: not called CC=3 SCAR=24.8
Pod documented
949 0 my $self = shift;
950  
951 0 my $vals = $self->tftpd( args => 'off' );
952  
953 0 ▶ if ( ref $vals eq 'HASH' && $vals->{'Tftpd'} eq 'disabled' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vals eq 'HASH' and $vals->{'Tftpd'} eq 'disabled') { } 0 0 0
Condition0%0/3
ref $vals eq "HASH" and $vals->{"Tftpd"} eq "disabled"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $vals eq "HASH" and $vals->{"Tftpd"} eq "disabled"
ref $vals eq "HASH" $vals->{"Tftpd"} eq "disabled"
Truth table0%0/3
A and B
A= ref $vals eq "HASH"B= $vals->{"Tftpd"} eq "disabled"
ABresult
0X0
100
111
954 0 return $vals;
955 }
956 else {
957 0 return;
958 }
959 }
960  
961 =pod
962  
963 =head2 B<cmd> - runs a command on the AP.
964  
965 This does most of the work. At the heart, it calls Net::Telnet::cmd()
966 but it also does some special stuff for Trango.
967  
968 Normally returns the last lines from from the command
969  
970 If you are using this, rather than one of the "easy" methods above,
971 you probably want to read through the source of this module to see how
972 some of the other commands are called.
973  
974 In addition to the Net::Telnet::cmd() options, it also accepts these:
975  
976 I<decode>
977 - if this is true, then it will send the output lines to _decode_lines()
978 and then returns the decoded output
979  
980 I<no_prompt>
981 - if this is true, it does not wait for a prompt, so you are not stuck
982 waiting for something that will never happen.
983  
984 I<cmd_disconnects>
985 - if this is true, it then sets logged_in() to false, then it will
986 close() the connection and set is_connected() to false
987  
988 I<expect>
989 - if this is set (usually to 'Success.') it will check for that in the
990 last line of output and if it does not, will return undef because the
991 command probably failed
992  
993 I<args>
994 - a string containing the command line options that are passed to the
995 command
996  
997 $t->cmd( String => 'exit', no_prompt => 1, cmd_disconnects => 1 );
998  
999 =cut
1000  
1001 0 ▶sub cmd {
Subroutine cmd: not called CC=31 SCAR=69.0
Pod documented
1002 0 my $self = shift;
1003 0 my $s = *$self->{net_telnet_trango};
1004  
1005 0 my @valid_net_telnet_opts = qw(
1006 String
1007 Output
1008 Cmd_remove_mode
1009 Errmode
1010 Input_record_separator
1011 Ors
1012 Output_record_separator
1013 Prompt
1014 Rs
1015 Timeout
1016 );
1017  
1018 0 my %cfg;
1019 0 ▶ if ( @_ == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ > 1) { } 0 0 0
1020 0 $cfg{'String'} = shift;
1021 }
1022 elsif ( @_ > 1 ) {
1023 0 %cfg = @_;
1024 }
1025  
1026 0 ▶ $cfg{'Timeout'} ||= $self->Timeout;
Condition0%0/3
$cfg{"Timeout"} ||= $self->Timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$cfg{"Timeout"} ||= $self->Timeout
$cfg{"Timeout"} $self->Timeout
Truth table0%0/3
A ||= B
A= $cfg{"Timeout"}B= $self->Timeout
ABresult
1X1
011
000
1027  
1028 0 ▶ unless ( $cfg{'String'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cfg{"String"}) 0 0 0
1029 0 $self->last_error("No command passed");
1030 0 return;
1031 }
1032  
1033 0 ▶ unless ( $self->is_connected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_connected) 0 0 0
1034 0 $self->last_error("Not connected");
1035 0 return;
1036 }
1037  
1038 0 ▶ unless ( $self->logged_in ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->logged_in) 0 0 0
1039 0 $self->last_error("Not logged in");
1040 0 return;
1041 }
1042  
1043 0 my %cmd;
1044 0 foreach (@valid_net_telnet_opts) {
1045 0 ▶ if ( exists $cfg{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cfg{$_}) 0 0 0
1046 0 $cmd{$_} = $cfg{$_};
1047 }
1048 }
1049 0 ▶ if ( $cfg{'args'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg{"args"}) 0 0 0
1050 0 $cmd{'String'} .= $SPACE . $cfg{'args'};
1051 }
1052  
1053 #print "Running cmd $cmd{String}\n";
1054 0 my @lines;
1055 0 ▶ if ( $cfg{'no_prompt'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg{'no_prompt'}) { } 0 0 0
1056 0 $self->print( $cmd{'String'} );
1057 0 @lines = $self->lastline;
1058 }
1059 else {
1060 0 @lines = $self->SUPER::cmd(%cmd);
1061 }
1062  
1063 0 $self->last_lines( \@lines );
1064  
1065 0 my $last = $self->lastline;
1066 0 my $prompt = $self->prompt;
1067 0 $prompt =~ s{^/}{}xms;
1068 0 $prompt =~ s{/[gixms]*$}{}xms;
1069 0 ▶ while ( @lines && $last =~ qr($prompt) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines and $last =~ qr/$prompt/) 0 0 0
Condition0%0/3
@lines and $last =~ qr/$prompt/
!ll&&!rl&&r
000
MC/DC0%0/2
@lines and $last =~ qr/$prompt/
@lines $last =~ qr/$prompt/
Truth table0%0/3
A and B
A= @linesB= $last =~ qr/$prompt/
ABresult
0X0
100
111
1070 0 pop @lines;
1071 0 $last = $lines[-1];
1072 }
1073 0 $self->last_error($EMPTY);
1074  
1075 0 my $vals = 1;
1076 0 ▶ if ( $s->{'Decode'} && $cfg{'decode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"Decode"} and $cfg{"decode"}) 0 0 0
Condition0%0/3
$s->{"Decode"} and $cfg{"decode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$s->{"Decode"} and $cfg{"decode"}
$s->{"Decode"} $cfg{"decode"}
Truth table0%0/3
A and B
A= $s->{"Decode"}B= $cfg{"decode"}
ABresult
0X0
100
111
1077 0 ▶ if ( $cfg{'decode'} eq 'each' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($cfg{'decode'} eq 'each') { } 0 0 0
elsif ($cfg{'decode'} eq 'sulog') { } 0 0 0
elsif ($cfg{'decode'} eq 'maclist') { } 0 0 0
elsif ($cfg{'decode'} eq 'linktest') { } 0 0 0
elsif ($cfg{'decode'} eq 'freq') { } 0 0 0
1078 0 $vals = _decode_each_line(@lines);
1079 }
1080 elsif ( $cfg{'decode'} eq 'sulog' ) {
1081 0 $vals = _decode_sulog(@lines);
1082 }
1083 elsif ( $cfg{'decode'} eq 'maclist' ) {
1084 0 $vals = _decode_maclist(@lines);
1085 0 ▶ if ( !$vals ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vals) 0 0 0
1086 0 $self->last_error("Error decoding maclist");
1087 }
1088 }
1089 elsif ( $cfg{'decode'} eq 'linktest' ) {
1090 0 $vals = _decode_linktest(@lines);
1091 0 ▶ if ( !$vals ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vals) 0 0 0
1092 0 $self->last_error("Error decoding linktest");
1093 }
1094 }
1095 elsif ( $cfg{'decode'} eq 'freq' ) {
1096 0 $vals = _decode_freq(@lines);
1097 }
1098 else {
1099 0 $vals = _decode_lines(@lines);
1100 }
1101 }
1102 0 ▶ if ( ref $vals eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vals eq "HASH") 0 0 0
1103 0 $vals->{_raw} = join q{}, @lines;
1104 }
1105 0 $self->last_vals($vals);
1106  
1107 0 ▶ if ( ( not $cfg{'expect'} ) || $last =~ /$cfg{'expect'}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $cfg{'expect'} or $last =~ /$cfg{'expect'}$/) { } 0 0 0
Condition0%0/3
not $cfg{"expect"} or $last =~ /$cfg{"expect"}$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $cfg{"expect"} or $last =~ /$cfg{"expect"}$/
not $cfg{"expect"} $last =~ /$cfg{"expect"}$/
Truth table0%0/3
not(A) or B
A= not $cfg{"expect"}B= $last =~ /$cfg{"expect"}$/
ABresult
1X1
011
000
1108 0 ▶ if ( $cfg{'cmd_disconnects'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg{"cmd_disconnects"}) 0 0 0
1109 0 $self->logged_in(0);
1110 0 $self->close;
1111 0 $self->is_connected(0);
1112 }
1113  
1114 0 ▶ if ( $s->{'Decode'} && $cfg{'decode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'Decode'} and $cfg{'decode'}) { } 0 0 0
Condition0%0/3
$s->{"Decode"} and $cfg{"decode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$s->{"Decode"} and $cfg{"decode"}
$s->{"Decode"} $cfg{"decode"}
Truth table0%0/3
A and B
A= $s->{"Decode"}B= $cfg{"decode"}
ABresult
0X0
100
111
1115 0 return $vals;
1116 }
1117 else {
1118 0 return \@lines;
1119 }
1120 }
1121 else {
1122 0 my $err;
1123 0 ▶ if ( grep {/\[ERR\]/} @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/\[ERR\]/;} @lines) 0 0 0
1124 0 $err = _decode_lines(@lines);
1125 }
1126  
1127 0 ▶ if ( ref $err eq 'HASH' && $err->{ERR} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $err eq 'HASH' and $err->{'ERR'}) { } 0 0 0
Condition0%0/3
ref $err eq "HASH" and $err->{"ERR"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $err eq "HASH" and $err->{"ERR"}
ref $err eq "HASH" $err->{"ERR"}
Truth table0%0/3
A and B
A= ref $err eq "HASH"B= $err->{"ERR"}
ABresult
0X0
100
111
1128 0 $self->last_error( $err->{ERR} );
1129 }
1130 else {
1131 0 $self->last_error("Error with command ($cmd{'String'}): $last");
1132 }
1133 0 return;
1134 }
1135 }
1136  
1137 #=item _decode_lines
1138  
1139 20 ▶sub _decode_lines {
Subroutine _decode_lines: called CC=31 SCAR=45.4
1140 20 my @lines = @_;
1141  
1142 20 my %conf;
1143  
1144 20 my $key = $EMPTY;
1145 20 my $val = undef;
1146 20 my @vals;
1147 20 my $in_key = 0;
1148 20 my $in_val = 1;
1149  
1150 20 ▶LINE: while ( my $line = shift @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @lines) 20 20 40
1151 20 ▶ next LINE if $line =~ /$success\Z/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$success\Z/ 0 20 20
1152 20 ▶ next LINE if $line =~ /^ \*+ \s+ \d+ \s+ \*+ \Z/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^ \*+ \s+ \d+ \s+ \*+ \Z/msx 0 20 20
1153  
1154 # Special decode for sysinfo on a TrangoLink 45
1155 20 ▶ if ( $line =~ /^(.* Channel \s+ Table):\s*(.*)\Z/xms ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^(.* Channel \s+ Table):\s*(.*)\Z/msx) { } 0 20 20
elsif ($line =~ /^ RF \s Band \s \# (\d+) \s+ \( ([^\)]+) \) \s* (.*)$ /msx) { } 0 20 20
1156 0 my $key = $1;
1157 0 my $note = $2;
1158  
1159 0 my %vals;
1160 0 ▶ while ( $line = shift @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line = shift @lines) 0 0 0
1161 0 ▶ if ( $line =~ /^\Z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\Z/) 0 0 0
1162 0 $conf{$key} = \%vals;
1163 0 $conf{$key}{note} = $note;
1164 0 next LINE;
1165 }
1166  
1167 0 my $decoded = _decode_lines($line);
1168 0 ▶ if ($decoded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoded) 0 0 0
1169 0 %vals = ( %vals, %{$decoded} );
1170 }
1171 }
1172 }
1173  
1174 # Another special decode for the TrangoLink
1175 elsif (
1176 $line =~ /^
1177 RF \s Band \s \#
1178 (\d+) \s+
1179 \( ([^\)]+) \) \s*
1180 (.*)$
1181 /xms
1182 )
1183 {
1184 0 my $num = $1;
1185 0 my $band = $2;
1186 0 my $extra = $3;
1187  
1188 0 ▶ if ( $extra =~ /\[/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra =~ /\[/) { } 0 0 0
1189 0 my $decoded = _decode_lines($extra);
1190 0 $conf{'RF Band'}{$num} = $decoded;
1191 }
1192 else {
1193 0 $conf{'RF Band'}{$num}{$extra} = 1;
1194 }
1195 0 next LINE;
1196 }
1197  
1198 20 my @chars = split //, $line;
1199  
1200 20 my $last_key = $EMPTY;
1201 20 foreach my $c (@chars) {
1202  
1203 655 ▶ if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($c eq '[' or $c eq "\r" or $c eq "\n") { } 63 592 655
elsif ($c eq ']') { } 43 549 592
elsif ($in_key) { } 348 201 549
elsif ($in_val) { } 201 0 201
Condition83%5/6
$c eq "[" or $c eq "\r" or $c eq "\n"
l!l&&r!l&&!r
4320592
$c eq "[" or $c eq "\r"
l!l&&r!l&&!r
430612
MC/DC66%2/3
$c eq "[" or $c eq "\r" or $c eq "\n"
$c eq "[" $c eq "\r" $c eq "\n"
Truth table75%3/4
A or B or C
A= $c eq "["B= $c eq "\r"C= $c eq "\n"
ABCresult
1XX1
01X1
0011
0000
1204 63 ▶ if ( $c eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '[') { } 43 20 63
1205 43 $in_key = 1;
1206 43 $in_val = 0;
1207 }
1208 else {
1209 20 $in_key = 0;
1210 20 $in_val = 1;
1211 }
1212  
1213 63 ▶ if ($key) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key) { } 43 20 63
elsif ($val) { } 0 20 20
1214 43 $key =~ s/^\s+//;
1215 43 $key =~ s/\s+$//;
1216  
1217 43 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 38 5 43
1218 38 $val =~ s/^\s+//;
1219 38 $val =~ s/\s+\.*$//;
1220 }
1221  
1222 43 ▶ if ( $key eq 'Checksum' && $last_key ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "Checksum" and $last_key) 0 43 43
Condition33%1/3
$key eq "Checksum" and $last_key
!ll&&!rl&&r
4300
MC/DC0%0/2
$key eq "Checksum" and $last_key
$key eq "Checksum" $last_key
Truth table33%1/3
A and B
A= $key eq "Checksum"B= $last_key
ABresult
0X0
100
111
1223  
1224 # Special case for these bastids.
1225 0 my $new = $last_key;
1226 0 $new =~ s/\s+\S+$//;
1227 0 $key = $new . $SPACE . $key;
1228 }
1229  
1230 43 $conf{$key} = $val;
1231 43 $last_key = $key;
1232 43 $key = $EMPTY;
1233 }
1234 elsif ($val) {
1235 0 push @vals, $val;
1236 }
1237 63 $val = $EMPTY;
1238  
1239 }
1240 elsif ( $c eq ']' ) {
1241 43 $in_val = 1;
1242 43 $in_key = 0;
1243 43 $c = shift @chars;
1244  
1245 }
1246 elsif ($in_key) {
1247 348 $key .= $c;
1248  
1249 }
1250 elsif ($in_val) {
1251 201 $val .= $c;
1252 }
1253 }
1254 }
1255  
1256 20 ▶ unless ($key) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key) 20 0 20
1257 20 push @vals, $val;
1258 }
1259  
1260 20 foreach my $val (@vals) {
1261 20 ▶ if ( defined $val && length $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and length $val) 0 20 20
Condition33%1/3
defined $val and length $val
!ll&&!rl&&r
0200
MC/DC0%0/2
defined $val and length $val
defined $val length $val
Truth table33%1/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
1262 0 $val =~ s/^\s+//;
1263 0 $val =~ s/\s+\.*$//;
1264 }
1265 }
1266  
1267 20 ▶ if ( @vals == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@vals == 1) { } 20 0 20
elsif (@vals) { } 0 0 0
1268 20 $val = $vals[0];
1269 }
1270 elsif (@vals) {
1271 0 $val = \@vals;
1272 }
1273 else {
1274 0 $val = undef;
1275 }
1276  
1277 20 ▶ if (%conf) {
Branch: 1 branch
BranchTrueFalseTotal
if (%conf) { } 15 5 20
1278 15 ▶ $conf{_pre} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 0 15 15
1279 15 return \%conf;
1280 }
1281 else {
1282 5 return $val;
1283 }
1284 }
1285  
1286 #=item _decode_each_line
1287  
1288 0 ▶sub _decode_each_line {
Subroutine _decode_each_line: not called CC=4 SCAR=30.0
1289 0 my @lines = @_;
1290 0 my @decoded;
1291 0 foreach my $line (@lines) {
1292 0 my $decoded = _decode_lines($line);
1293 0 ▶ push @decoded, $decoded if defined $decoded && length $decoded;
Branch: 1 branch
BranchTrueFalseTotal
if defined $decoded and length $decoded 0 0 0
Condition0%0/3
defined $decoded and length $decoded
!ll&&!rl&&r
000
MC/DC0%0/2
defined $decoded and length $decoded
defined $decoded length $decoded
Truth table0%0/3
A and B
A= defined $decodedB= length $decoded
ABresult
0X0
100
111
1294 }
1295 0 return \@decoded;
1296 }
1297  
1298 #=item _decode_linktest
1299  
1300 1 ▶sub _decode_linktest {
Subroutine _decode_linktest: called CC=7 SCAR=19.5
1301 1 my @lines = @_;
1302 1 my %decoded;
1303 1 foreach my $line (@lines) {
1304  
1305 20 ▶ if ( $line =~ s/^(\d+) \s+ //xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^(\d+) \s+ //msx) { } 5 15 20
1306 5 my $line_id = $1;
1307 5 my ( $tm, $rt );
1308 5 ▶ if ( $line =~ s/\s+ (\d+ \s+ \w+) \s* $//xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/\s+ (\d+ \s+ \w+) \s* $//msx) 5 0 5
1309 5 $rt = $1;
1310 }
1311 5 ▶ if ( $line =~ s/\s+ (\d+ \s+ \w+) \s* $//xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/\s+ (\d+ \s+ \w+) \s* $//msx) 5 0 5
1312 5 $tm = $1;
1313 }
1314  
1315 5 my $d = _decode_lines( $line . "\n" );
1316 5 $decoded{tests}[$line_id] = $d;
1317 5 $decoded{tests}[$line_id]{'time'} = $tm;
1318 5 $decoded{tests}[$line_id]{rate} = $rt;
1319 }
1320  
1321 else {
1322 15 my $d = _decode_lines( $line . "\n" );
1323 15 ▶ if ($d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d) 10 5 15
1324 10 ▶ while ( my ( $k, $v ) = each %{$d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$d;}) 13 10 23
1325 13 $decoded{$k} = $v;
1326 }
1327 }
1328 }
1329  
1330 }
1331 1 return \%decoded;
1332 }
1333  
1334 #=item _decode_sulog
1335  
1336 0 ▶sub _decode_sulog {
Subroutine _decode_sulog: not called CC=6 SCAR=37.4
1337 0 my @lines = @_;
1338 0 my @decoded;
1339 my $last_tm;
1340 0 foreach my $line (@lines) {
1341 0 my $decoded = _decode_lines($line);
1342  
1343 0 ▶ if ( defined $decoded ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded) 0 0 0
1344 0 ▶ if ( $decoded->{'tm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoded->{'tm'}) { } 0 0 0
1345 0 $last_tm = $decoded->{'tm'};
1346 0 next;
1347 }
1348 else {
1349 0 $decoded->{'tm'} = $last_tm;
1350 }
1351 0 ▶ next unless $last_tm;
Branch: 1 branch
BranchTrueFalseTotal
unless $last_tm 0 0 0
1352  
1353 0 ▶ push @decoded, $decoded if defined $decoded;
Branch: 1 branch
BranchTrueFalseTotal
if defined $decoded 0 0 0
1354 }
1355 }
1356 0 return \@decoded;
1357 }
1358  
1359 #=item _decode_maclist
1360  
1361 0 ▶sub _decode_maclist {
Subroutine _decode_maclist: not called CC=7 SCAR=40.3
1362 0 my @lines = @_;
1363 0 my @decoded;
1364 0 my $total_entries = 0;
1365 0 my $current_tm = 0;
1366 0 foreach my $line (@lines) {
1367 0 $line =~ s/\r?\n$//;
1368 0 my ( $mac, $loc, $tm ) = $line =~ /
1369 ([0-9a-fA-F ]{17})\s+
1370 (.*)\s+
1371 tm\s+
1372 (\d+)
1373 /x;
1374  
1375 0 ▶ if ($mac) {
Branch: 3 branches
BranchTrueFalseTotal
if ($mac) { } 0 0 0
elsif ($line =~ /(\d+)\s+entries/) { } 0 0 0
elsif ($line =~ /current tm = (\d+)\s+sec/) { } 0 0 0
1376 0 $mac =~ s/\s+//g;
1377 0 $loc =~ s/^\s+//;
1378 0 $loc =~ s/\s+$//;
1379  
1380 0 my $suid = undef;
1381 0 ▶ if ( $loc =~ /suid\s+=\s+(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc =~ /suid\s+=\s+(\d+)/) 0 0 0
1382 0 $suid = $1;
1383 0 $loc = undef;
1384 }
1385  
1386 0 push @decoded,
1387 {
1388 mac => $mac,
1389 loc => $loc,
1390 tm => $tm,
1391 suid => $suid,
1392 };
1393 }
1394 elsif ( $line =~ /(\d+)\s+entries/ ) {
1395 0 $total_entries = $1;
1396 }
1397 elsif ( $line =~ /current tm = (\d+)\s+sec/ ) {
1398 0 $current_tm = $1;
1399 }
1400 }
1401  
1402 0 map { $_->{'cur_tm'} = $current_tm } @decoded;
1403  
1404 0 ▶ if ( scalar @decoded == $total_entries ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @decoded == $total_entries) { } 0 0 0
1405 0 return \@decoded;
1406 }
1407 else {
1408 0 return;
1409 }
1410 }
1411  
1412 #=item _decode_freq
1413  
1414 0 ▶sub _decode_freq {
Subroutine _decode_freq: not called CC=5 SCAR=34.0
1415 0 my @lines = @_;
1416 0 my $decoded = _decode_lines(@lines);
1417  
1418 0 ▶ if ( $decoded && $decoded->{ERR} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoded and $decoded->{"ERR"}) 0 0 0
Condition0%0/3
$decoded and $decoded->{"ERR"}
!ll&&!rl&&r
000
MC/DC0%0/2
$decoded and $decoded->{"ERR"}
$decoded $decoded->{"ERR"}
Truth table0%0/3
A and B
A= $decodedB= $decoded->{"ERR"}
ABresult
0X0
100
111
1419 0 return $decoded;
1420 }
1421  
1422 0 LINE: foreach my $line (@lines) {
1423 0 ▶ if (my ( $channel, $polarity, $freq )
Branch: 1 branch
BranchTrueFalseTotal
if (() = $line =~ / Ch \s+ \#(\d+) \s+ (\w+) \s+ \[ (\d+) \s+ MHz\] /imsx) 0 0 0
1424 = $line =~ /
1425 Ch \s+ \#(\d+)
1426 \s+
1427 (\w+)
1428 \s+
1429 \[ (\d+) \s+ MHz\]
1430 /ixms
1431 )
1432 {
1433 0 $decoded = {
1434 channel => $channel,
1435 polarity => $polarity,
1436 frequency => $freq,
1437 };
1438 0 last LINE;
1439 }
1440 }
1441 0 return $decoded;
1442 }
1443  
1444 12 1; # End of Net::Telnet::Trango
1445 __END__
↑ Summary Trango/ConfigData.pm »