/[mdap]/mdap-server.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /mdap-server.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 28 by dpavlin, Tue Apr 24 10:01:22 2007 UTC revision 41 by dpavlin, Fri Nov 16 10:25:01 2007 UTC
# Line 1  Line 1 
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/;
# Line 11  my $PORT  = '3235'; Line 12  my $PORT  = '3235';
12  my $debug = 0;  my $debug = 0;
13  my $quiet = 1;  my $quiet = 1;
14  my $verbose = 0;  my $verbose = 0;
15    my $credentials = 0;
16    
17  my $resend_search_delay = 3;  my $resend_search_delay = 3;
18  my $tftp_path = '/srv/tftp/';  my $tftp_path = '/srv/tftp/';
19    
20    my $flashed_cmd = 'system config led=flash';
21    
22  GetOptions(  GetOptions(
23          "port=i"        => \$PORT,          "port=i"        => \$PORT,
24          "group=s"       => \$GROUP,          "group=s"       => \$GROUP,
# Line 23  GetOptions( Line 27  GetOptions(
27          "verbose!"      => \$verbose,          "verbose!"      => \$verbose,
28          "search=i"      => \$resend_search_delay,          "search=i"      => \$resend_search_delay,
29          "tftp=s"        => \$tftp_path,          "tftp=s"        => \$tftp_path,
30            "credentials"   => \$credentials,
31            "exec=s"        => \$flashed_cmd,
32  );  );
33    
34  $quiet = 0 if $verbose;  $quiet = 0 if $verbose;
35    $credentials = 1 if $debug;
36    
37  # tab-delimited list of user id/passwd to try on ants  # tab-delimited list of user id/passwd to try on ants
38  my @try_accounts = ( "Administrator\t" );  my @try_accounts = ( "Administrator\t" );
# Line 38  if (-e $passwd_path) { Line 45  if (-e $passwd_path) {
45          while(<$fh>) {          while(<$fh>) {
46                  chomp;                  chomp;
47                  next if /^#/ || /^$/ || /^\s+$/;                  next if /^#/ || /^$/ || /^\s+$/;
48                  if (/^\S+\t\S+$/) {                  if (/^\S+\s+\S+$/) {
49                          push @try_accounts, $_;                          push @try_accounts, $_;
50                  } else {                  } else {
51                          warn "invalid $passwd_path entry: $_\n";                          warn "invalid $passwd_path entry: $_\n";
52                  }                  }
53          }          }
54          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",
55                    $credentials ? " and display credentials" : "", "\n";
56  }  }
57    
58  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";
59    
60  sub fw {  sub fw {
61          my ($board, $offset,$len) = @_;          my ($board, $offset,$len) = @_;
# Line 96  sub mdap_send { Line 104  sub mdap_send {
104    
105          $sock->mcast_send( $data, "${GROUP}:${PORT}" );          $sock->mcast_send( $data, "${GROUP}:${PORT}" );
106          if ($debug) {          if ($debug) {
107                  warn ">> ", dump( $data ), $/;                  warn ">> ${GROUP}:${PORT} >> ", dump( $data ), $/;
108          } elsif( ! $quiet ) {          } elsif( ! $quiet ) {
109                  $data =~ s/\s+/ /gi;                  $data =~ s/\s+/ /gi;
110                  warn ">> ", substr($data,0,70), $/;                  warn ">> ", substr($data,0,70), $/;
# Line 156  sub once { Line 164  sub once {
164          print $m if ($once->{$m} == 1);          print $m if ($once->{$m} == 1);
165  }  }
166    
167    my $status = '';
168    
169    sub status {
170            my $m = join('', @_);
171            if ($m ne $status) {
172                    print $m;
173                    $status = $m;
174            }
175    }
176    
177  local $SIG{ALRM} = sub {  local $SIG{ALRM} = sub {
178          mdap_send("ANT-SEARCH MDAP/1.1\r\n");          mdap_send("ANT-SEARCH MDAP/1.1\r\n");
179          alarm( $resend_search_delay );          alarm( $resend_search_delay );
# Line 180  while (1) { Line 198  while (1) {
198    
199                  print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet;                  print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet;
200    
201                  warn dump($h),$/ if ($debug);                  warn dump( $data, $h ),$/ if ($debug);
202    
203                  # we are getting our own messages (since our source port                  # we are getting our own messages (since our source port
204                  # is same as destination)                  # is same as destination)
# Line 207  while (1) { Line 225  while (1) {
225                                  next;                                  next;
226                          } else {                          } else {
227                                  $ant_ok_password->{$ant}++;                                  $ant_ok_password->{$ant}++;
228                                    print "$ant credentials $user_id $user_pwd\n" if ( $credentials && $ant_ok_password->{$ant} == 1 ) || $debug;
229                          }                          }
230    
231                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";
# Line 216  while (1) { Line 235  while (1) {
235                                  if ( $build ne $new_build ) {                                  if ( $build ne $new_build ) {
236                                          print "+ $ant version $build -> $new_build\n";                                          print "+ $ant version $build -> $new_build\n";
237                                          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");
238                                            $ant_flashing->{$ant}++;
239                                  } else {                                  } else {
240                                          once "$ant OK version $build",                                          once "$ant OK version $build",
241                                                  $ant_unknown_password->{$ant} ? ' with unknown password' :                                                  $ant_unknown_password->{$ant} ? ' with unknown password' :
242                                                  $ant_ok_password->{$ant} ? ' password protected' :                                                  $ant_passwd->{$ant} ? ' password protected' :
243                                                  '',                                                  '',
244                                                  "\n";                                                  "\n";
245    
246                                          $ant_flashing->{$ant} = 0;                                          $ant_flashing->{$ant} = 0;
247                                            # green|red|orange|flash|off
248                                            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");
249                                          my $waiting = 0;                                          my $waiting = 0;
250                                            my $count = 0;
251                                          map {                                          map {
252                                                  $waiting++ if ($ant_flashing->{$_});                                                  $waiting++ if ($ant_flashing->{$_});
253                                                    $count++;
254                                          } keys %$ant_flashing;                                          } keys %$ant_flashing;
255                                          print "**** ALL ANTS FLASHED ****\n" if ($ant_flashing && $waiting == 0);                                          if ($waiting == 0) {
256                                                    status "ALL $count ANTS FLASHED to $build\n";
257                                                    $ant_flashing = undef;
258                                            } else {
259                                                    status "$waiting of $count ants still flasing upto $build\n";
260                                            }
261                                  }                                  }
262                          } else {                          } else {
263                                  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";
264                          }                          }
265                  } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) {                  } elsif ( $type eq 'REPLY-EXEC-CLI' ) {
266                                  print "+ $ant bootp mode re-flash started\n";                          print "+ $type\n$data\n" if ($verbose);
267                            if ( $seq_nr == 1 ) {
268                                  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");
269                                  forget_ant( $ant );                                  forget_ant( $ant ) if ( $ant_flashing->{$ant} );
270                                  $ant_flashing->{$ant}++;                          }
271    
272                  } else {                  } else {
273                          print "!! reply ignored ", dump( $h ), $/;                          print "!! reply $type ignored ", dump( $h ), $/;
274                  }                  }
275    
276          } else {          } else {

Legend:
Removed from v.28  
changed lines
  Added in v.41

  ViewVC Help
Powered by ViewVC 1.1.26