11 |
my $debug = 0; |
my $debug = 0; |
12 |
my $quiet = 1; |
my $quiet = 1; |
13 |
my $verbose = 0; |
my $verbose = 0; |
14 |
|
my $credentials = 0; |
15 |
|
|
16 |
my $resend_search_delay = 3; |
my $resend_search_delay = 3; |
17 |
my $tftp_path = '/srv/tftp/'; |
my $tftp_path = '/srv/tftp/'; |
18 |
|
|
19 |
|
my $flashed_cmd = 'system config led=flash'; |
20 |
|
|
21 |
GetOptions( |
GetOptions( |
22 |
"port=i" => \$PORT, |
"port=i" => \$PORT, |
23 |
"group=s" => \$GROUP, |
"group=s" => \$GROUP, |
26 |
"verbose!" => \$verbose, |
"verbose!" => \$verbose, |
27 |
"search=i" => \$resend_search_delay, |
"search=i" => \$resend_search_delay, |
28 |
"tftp=s" => \$tftp_path, |
"tftp=s" => \$tftp_path, |
29 |
|
"credentials" => \$credentials, |
30 |
|
"exec=s" => \$flashed_cmd, |
31 |
); |
); |
32 |
|
|
33 |
$quiet = 0 if $verbose; |
$quiet = 0 if $verbose; |
34 |
|
$credentials = 1 if $debug; |
35 |
|
|
36 |
# tab-delimited list of user id/passwd to try on ants |
# tab-delimited list of user id/passwd to try on ants |
37 |
my @try_accounts = ( "Administrator\t" ); |
my @try_accounts = ( "Administrator\t" ); |
44 |
while(<$fh>) { |
while(<$fh>) { |
45 |
chomp; |
chomp; |
46 |
next if /^#/ || /^$/ || /^\s+$/; |
next if /^#/ || /^$/ || /^\s+$/; |
47 |
if (/^\S+\t\S+$/) { |
if (/^\S+\s+\S+$/) { |
48 |
push @try_accounts, $_; |
push @try_accounts, $_; |
49 |
} else { |
} else { |
50 |
warn "invalid $passwd_path entry: $_\n"; |
warn "invalid $passwd_path entry: $_\n"; |
51 |
} |
} |
52 |
} |
} |
53 |
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", |
54 |
|
$credentials ? " and display credentials" : "", "\n"; |
55 |
} |
} |
56 |
|
|
57 |
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"; |
58 |
|
|
59 |
sub fw { |
sub fw { |
60 |
my ($board, $offset,$len) = @_; |
my ($board, $offset,$len) = @_; |
103 |
|
|
104 |
$sock->mcast_send( $data, "${GROUP}:${PORT}" ); |
$sock->mcast_send( $data, "${GROUP}:${PORT}" ); |
105 |
if ($debug) { |
if ($debug) { |
106 |
warn ">> ", dump( $data ), $/; |
warn ">> ${GROUP}:${PORT} >> ", dump( $data ), $/; |
107 |
} elsif( ! $quiet ) { |
} elsif( ! $quiet ) { |
108 |
$data =~ s/\s+/ /gi; |
$data =~ s/\s+/ /gi; |
109 |
warn ">> ", substr($data,0,70), $/; |
warn ">> ", substr($data,0,70), $/; |
111 |
} |
} |
112 |
|
|
113 |
my $ant_passwd; |
my $ant_passwd; |
114 |
|
my $ant_unknown_password; |
115 |
|
my $ant_ok_password; |
116 |
|
my $ant_flashing; |
117 |
|
|
118 |
sub ant_credentials { |
sub ant_credentials { |
119 |
my $ant = shift || die "no ant?"; |
my $ant = shift || die "no ant?"; |
123 |
return ($user_id,$user_pwd); |
return ($user_id,$user_pwd); |
124 |
} |
} |
125 |
|
|
|
my $ant_unknown_password; |
|
|
my $ant_ok_password; |
|
|
|
|
126 |
sub ant_unknown_password { |
sub ant_unknown_password { |
127 |
my $ant = shift || die "no ant?"; |
my $ant = shift || die "no ant?"; |
128 |
if ( $ant_unknown_password->{$ant} ) { |
if ( $ant_unknown_password->{$ant} ) { |
135 |
my $ant = shift || die "no ant?"; |
my $ant = shift || die "no ant?"; |
136 |
|
|
137 |
return 0 if ant_unknown_password( $ant ); |
return 0 if ant_unknown_password( $ant ); |
138 |
|
return 0 if $ant_ok_password->{$ant}; |
139 |
|
|
140 |
$ant_passwd->{$ant}++; |
$ant_passwd->{$ant}++; |
141 |
|
|
148 |
return 1; |
return 1; |
149 |
} |
} |
150 |
|
|
151 |
|
sub forget_ant { |
152 |
|
my $ant = shift || die "no ant?"; |
153 |
|
delete $ant_unknown_password->{$ant}; |
154 |
|
delete $ant_passwd->{$ant}; |
155 |
|
delete $ant_ok_password->{$ant}; |
156 |
|
} |
157 |
|
|
158 |
my $once; |
my $once; |
159 |
|
|
160 |
sub once { |
sub once { |
163 |
print $m if ($once->{$m} == 1); |
print $m if ($once->{$m} == 1); |
164 |
} |
} |
165 |
|
|
166 |
|
my $status = ''; |
167 |
|
|
168 |
|
sub status { |
169 |
|
my $m = join('', @_); |
170 |
|
if ($m ne $status) { |
171 |
|
print $m; |
172 |
|
$status = $m; |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
local $SIG{ALRM} = sub { |
local $SIG{ALRM} = sub { |
177 |
mdap_send("ANT-SEARCH MDAP/1.1\r\n"); |
mdap_send("ANT-SEARCH MDAP/1.1\r\n"); |
178 |
alarm( $resend_search_delay ); |
alarm( $resend_search_delay ); |
197 |
|
|
198 |
print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet; |
print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet; |
199 |
|
|
200 |
warn dump($h),$/ if ($debug); |
warn dump( $data, $h ),$/ if ($debug); |
201 |
|
|
202 |
# we are getting our own messages (since our source port |
# we are getting our own messages (since our source port |
203 |
# is same as destination) |
# is same as destination) |
214 |
} elsif ($type eq 'REPLY-INFO') { |
} elsif ($type eq 'REPLY-INFO') { |
215 |
|
|
216 |
if ( $seq_nr < 0 ) { |
if ( $seq_nr < 0 ) { |
217 |
if ( $ant_ok_password ) { |
# if ( $ant_ok_password ) { |
218 |
$ant_ok_password->{$ant} = 0; |
# $ant_ok_password->{$ant} = 0; |
219 |
} elsif ( ant_another_passwd( $ant ) ) { |
# } elsif ( ant_another_passwd( $ant ) ) { |
220 |
|
if ( ant_another_passwd( $ant ) ) { |
221 |
($user_id,$user_pwd) = ant_credentials( $ant ); |
($user_id,$user_pwd) = ant_credentials( $ant ); |
222 |
mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
223 |
} |
} |
224 |
next; |
next; |
225 |
} else { |
} else { |
226 |
$ant_ok_password->{$ant}++; |
$ant_ok_password->{$ant}++; |
227 |
|
print "$ant credentials $user_id $user_pwd\n" if ( $credentials && $ant_ok_password->{$ant} == 1 ) || $debug; |
228 |
} |
} |
229 |
|
|
230 |
my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?"; |
my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?"; |
234 |
if ( $build ne $new_build ) { |
if ( $build ne $new_build ) { |
235 |
print "+ $ant version $build -> $new_build\n"; |
print "+ $ant version $build -> $new_build\n"; |
236 |
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"); |
237 |
|
$ant_flashing->{$ant}++; |
238 |
} else { |
} else { |
239 |
once "$ant OK version $build", |
once "$ant OK version $build", |
240 |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
241 |
$ant_ok_password->{$ant} ? ' password protected' : |
$ant_passwd->{$ant} ? ' password protected' : |
242 |
'', |
'', |
243 |
"\n"; |
"\n"; |
244 |
|
|
245 |
|
$ant_flashing->{$ant} = 0; |
246 |
|
# green|red|orange|flash|off |
247 |
|
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"); |
248 |
|
my $waiting = 0; |
249 |
|
my $count = 0; |
250 |
|
map { |
251 |
|
$waiting++ if ($ant_flashing->{$_}); |
252 |
|
$count++; |
253 |
|
} keys %$ant_flashing; |
254 |
|
if ($waiting == 0) { |
255 |
|
status "ALL $count ANTS FLASHED to $build\n"; |
256 |
|
$ant_flashing = undef; |
257 |
|
} else { |
258 |
|
status "$waiting of $count ants still flasing upto $build\n"; |
259 |
|
} |
260 |
} |
} |
261 |
} else { |
} else { |
262 |
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"; |
263 |
} |
} |
264 |
} elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) { |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
265 |
print "+ $ant bootp mode re-flash started\n"; |
print "+ $type\n$data\n" if ($verbose); |
266 |
|
if ( $seq_nr == 1 ) { |
267 |
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"); |
268 |
$ant_unknown_password->{$ant} = 0; |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
269 |
$ant_passwd->{$ant} = 0; |
} |
270 |
$ant_ok_password->{$ant} = 0; |
|
271 |
} else { |
} else { |
272 |
print "!! reply ignored ", dump( $h ), $/; |
print "!! reply $type ignored ", dump( $h ), $/; |
273 |
} |
} |
274 |
|
|
275 |
} else { |
} else { |