1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
|
|
3 |
|
use warnings; |
4 |
use strict; |
use strict; |
5 |
use IO::Socket::Multicast; |
use IO::Socket::Multicast; |
6 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
7 |
use Getopt::Long; |
use Getopt::Long; |
8 |
|
|
9 |
|
use lib './lib'; |
10 |
|
use MDAP; |
11 |
|
|
12 |
my $GROUP = '224.0.0.103'; |
my $GROUP = '224.0.0.103'; |
13 |
my $PORT = '3235'; |
my $PORT = '3235'; |
14 |
|
|
17 |
my $verbose = 0; |
my $verbose = 0; |
18 |
my $credentials = 0; |
my $credentials = 0; |
19 |
|
|
20 |
|
my $plugins = 1; |
21 |
|
|
22 |
my $resend_search_delay = 3; |
my $resend_search_delay = 3; |
23 |
my $tftp_path = '/srv/tftp/'; |
my $tftp_path = '/srv/tftp/'; |
24 |
|
|
25 |
|
my $flashed_cmd = 'system config led=flash'; |
26 |
|
|
27 |
GetOptions( |
GetOptions( |
28 |
"port=i" => \$PORT, |
"port=i" => \$PORT, |
29 |
"group=s" => \$GROUP, |
"group=s" => \$GROUP, |
33 |
"search=i" => \$resend_search_delay, |
"search=i" => \$resend_search_delay, |
34 |
"tftp=s" => \$tftp_path, |
"tftp=s" => \$tftp_path, |
35 |
"credentials" => \$credentials, |
"credentials" => \$credentials, |
36 |
|
"exec=s" => \$flashed_cmd, |
37 |
|
'plugins!' => \$plugins, |
38 |
); |
); |
39 |
|
|
40 |
$quiet = 0 if $verbose; |
$quiet = 0 if $verbose; |
51 |
while(<$fh>) { |
while(<$fh>) { |
52 |
chomp; |
chomp; |
53 |
next if /^#/ || /^$/ || /^\s+$/; |
next if /^#/ || /^$/ || /^\s+$/; |
54 |
if (/^\S+\s\S+$/) { |
if (/^\S+\s+\S+$/) { |
55 |
push @try_accounts, $_; |
push @try_accounts, $_; |
56 |
} else { |
} else { |
57 |
warn "invalid $passwd_path entry: $_\n"; |
warn "invalid $passwd_path entry: $_\n"; |
58 |
} |
} |
59 |
} |
} |
60 |
print "found ", $#try_accounts + 1, " accounts to try on password protected ants\n"; |
print "found ", $#try_accounts + 1, " accounts to try on password protected ants", |
61 |
|
$credentials ? " and display credentials" : "", "\n"; |
62 |
} |
} |
63 |
|
|
64 |
warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; |
warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\nflashed to current version: $flashed_cmd\n"; |
65 |
|
|
66 |
sub fw { |
sub fw { |
67 |
my ($board, $offset,$len) = @_; |
my ($board, $offset,$len) = @_; |
211 |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
212 |
|
|
213 |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
214 |
my $seq_nr = $h->{'SEQ-NR'}; |
my $seq_nr = $1 if (defined $h->{'SEQ-NR'} && $h->{'SEQ-NR'} =~ m/^-*(\d)+/); |
215 |
#warn "SEQ-NR: $seq_nr ok: ",$ant_ok_password->{$ant},"\n" if ($seq_nr); |
#warn "SEQ-NR: $seq_nr ok: ",$ant_ok_password->{$ant},"\n" if ($seq_nr); |
216 |
|
|
217 |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
241 |
if ( $build ne $new_build ) { |
if ( $build ne $new_build ) { |
242 |
print "+ $ant version $build -> $new_build\n"; |
print "+ $ant version $build -> $new_build\n"; |
243 |
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
244 |
|
$ant_flashing->{$ant}++; |
245 |
} else { |
} else { |
246 |
once "$ant OK version $build", |
once "$ant OK version $build", |
247 |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
248 |
$ant_ok_password->{$ant} ? ' password protected' : |
$ant_passwd->{$ant} ? ' password protected' : |
249 |
'', |
'', |
250 |
"\n"; |
"\n"; |
251 |
|
|
252 |
$ant_flashing->{$ant} = 0; |
$ant_flashing->{$ant} = 0; |
253 |
# green|red|orange|flash|off |
# green|red|orange|flash|off |
254 |
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:system config led=flash\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:$flashed_cmd\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
255 |
my $waiting = 0; |
my $waiting = 0; |
256 |
my $count = 0; |
my $count = 0; |
257 |
map { |
map { |
268 |
} else { |
} else { |
269 |
once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n"; |
once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n"; |
270 |
} |
} |
271 |
|
|
272 |
|
if ( $plugins ) { |
273 |
|
foreach my $plugin ( MDAP->plugins ) { |
274 |
|
warn "## calling $plugin\n" if $debug; |
275 |
|
if ( my $command = $plugin->check( $h ) ) { |
276 |
|
warn "## plugin $plugin sending $command to $ant\n"; |
277 |
|
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:$command\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); } |
278 |
|
} |
279 |
|
} |
280 |
|
|
281 |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
282 |
|
print "+ $type\n$data\n" if ($verbose); |
283 |
if ( $seq_nr == 1 ) { |
if ( $seq_nr == 1 ) { |
|
print "+ $ant bootp mode re-flash started\n" if ($verbose); |
|
284 |
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nSEQ-NR:2\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nSEQ-NR:2\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
285 |
forget_ant( $ant ); |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
286 |
$ant_flashing->{$ant}++; |
} elsif ( $seq_nr < 0 ) { |
287 |
} elsif ( $seq_nr == 2 ) { |
warn "EXEC-CLI failed\n"; |
|
print "+ $ant led\n" if ($verbose); |
|
288 |
} |
} |
289 |
|
|
290 |
} else { |
} else { |
291 |
print "!! reply $type ignored ", dump( $h ), $/; |
print "!! reply $type ignored ", dump( $h ), $/; |
292 |
} |
} |