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::ChangeIP; |
11 |
|
|
12 |
my $GROUP = '224.0.0.103'; |
my $GROUP = '224.0.0.103'; |
13 |
my $PORT = '3235'; |
my $PORT = '3235'; |
14 |
|
|
20 |
my $resend_search_delay = 3; |
my $resend_search_delay = 3; |
21 |
my $tftp_path = '/srv/tftp/'; |
my $tftp_path = '/srv/tftp/'; |
22 |
|
|
23 |
|
my $flashed_cmd = 'system config led=flash'; |
24 |
|
|
25 |
GetOptions( |
GetOptions( |
26 |
"port=i" => \$PORT, |
"port=i" => \$PORT, |
27 |
"group=s" => \$GROUP, |
"group=s" => \$GROUP, |
31 |
"search=i" => \$resend_search_delay, |
"search=i" => \$resend_search_delay, |
32 |
"tftp=s" => \$tftp_path, |
"tftp=s" => \$tftp_path, |
33 |
"credentials" => \$credentials, |
"credentials" => \$credentials, |
34 |
|
"exec=s" => \$flashed_cmd, |
35 |
); |
); |
36 |
|
|
37 |
$quiet = 0 if $verbose; |
$quiet = 0 if $verbose; |
54 |
warn "invalid $passwd_path entry: $_\n"; |
warn "invalid $passwd_path entry: $_\n"; |
55 |
} |
} |
56 |
} |
} |
57 |
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", |
58 |
|
$credentials ? " and display credentials" : "", "\n"; |
59 |
} |
} |
60 |
|
|
61 |
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"; |
62 |
|
|
63 |
sub fw { |
sub fw { |
64 |
my ($board, $offset,$len) = @_; |
my ($board, $offset,$len) = @_; |
208 |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
209 |
|
|
210 |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
211 |
my $seq_nr = $h->{'SEQ-NR'}; |
my $seq_nr = $1 if (defined $h->{'SEQ-NR'} && $h->{'SEQ-NR'} =~ m/^-*(\d)+/); |
212 |
#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); |
213 |
|
|
214 |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
248 |
|
|
249 |
$ant_flashing->{$ant} = 0; |
$ant_flashing->{$ant} = 0; |
250 |
# green|red|orange|flash|off |
# green|red|orange|flash|off |
251 |
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"); |
252 |
my $waiting = 0; |
my $waiting = 0; |
253 |
my $count = 0; |
my $count = 0; |
254 |
map { |
map { |
265 |
} else { |
} else { |
266 |
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"; |
267 |
} |
} |
268 |
|
|
269 |
|
if ( my $command = CWMP::ChangeIP::check( $h ) ) { |
270 |
|
warn "## sending $command to $ant\n"; |
271 |
|
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"); |
272 |
|
} |
273 |
|
|
274 |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
275 |
print "+ $type ", dump( $data ), "\n" if ($verbose); |
print "+ $type\n$data\n" if ($verbose); |
276 |
if ( $seq_nr == 1 ) { |
if ( $seq_nr == 1 ) { |
277 |
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"); |
278 |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
279 |
|
} elsif ( $seq_nr < 0 ) { |
280 |
|
warn "EXEC-CLI failed\n"; |
281 |
} |
} |
282 |
|
|
283 |
} else { |
} else { |
284 |
print "!! reply $type ignored ", dump( $h ), $/; |
print "!! reply $type ignored ", dump( $h ), $/; |
285 |
} |
} |