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) = @_; |
162 |
delete $ant_ok_password->{$ant}; |
delete $ant_ok_password->{$ant}; |
163 |
} |
} |
164 |
|
|
|
my $once; |
|
|
|
|
|
sub once { |
|
|
my $m = join('', @_); |
|
|
$once->{$m}++; |
|
|
print $m if ($once->{$m} == 1); |
|
|
} |
|
|
|
|
165 |
my $status = ''; |
my $status = ''; |
166 |
|
|
167 |
sub status { |
sub status { |
203 |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
204 |
|
|
205 |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
206 |
my $seq_nr = $h->{'SEQ-NR'}; |
my $seq_nr = $1 if (defined $h->{'SEQ-NR'} && $h->{'SEQ-NR'} =~ m/^-*(\d)+/); |
207 |
#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); |
208 |
|
|
209 |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
238 |
once "$ant OK version $build", |
once "$ant OK version $build", |
239 |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
240 |
$ant_passwd->{$ant} ? ' password protected' : |
$ant_passwd->{$ant} ? ' password protected' : |
241 |
'', |
''; |
|
"\n"; |
|
242 |
|
|
243 |
$ant_flashing->{$ant} = 0; |
$ant_flashing->{$ant} = 0; |
244 |
# green|red|orange|flash|off |
# green|red|orange|flash|off |
245 |
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"); |
246 |
my $waiting = 0; |
my $waiting = 0; |
247 |
my $count = 0; |
my $count = 0; |
248 |
map { |
map { |
257 |
} |
} |
258 |
} |
} |
259 |
} else { |
} else { |
260 |
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"; |
261 |
|
} |
262 |
|
|
263 |
|
if ( $plugins ) { |
264 |
|
foreach my $plugin ( MDAP->plugins ) { |
265 |
|
warn "## calling $plugin\n" if $debug; |
266 |
|
if ( my $command = $plugin->check( $h ) ) { |
267 |
|
|
268 |
|
warn ">> $ant ", |
269 |
|
$h->{'ANT-NAME'}, " ", |
270 |
|
$h->{'_BUILD'}, " ", |
271 |
|
"\t:$command\n"; |
272 |
|
|
273 |
|
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"); } |
274 |
|
} |
275 |
} |
} |
276 |
|
|
277 |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
278 |
print "+ $type ", dump( $data ), "\n" if ($verbose); |
print "##<< $type\n$data\n" if $debug; |
279 |
if ( $seq_nr == 1 ) { |
if ( $seq_nr == 1 ) { |
280 |
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"); |
281 |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
282 |
|
} elsif ( $seq_nr < 0 ) { |
283 |
|
warn "EXEC-CLI failed: $data\n"; |
284 |
} |
} |
285 |
|
|
286 |
} else { |
} else { |
287 |
print "!! reply $type ignored ", dump( $h ), $/; |
print "!! reply $type ignored ", dump( $h ), $/; |
288 |
} |
} |