/[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 24 by dpavlin, Mon Apr 23 23:11:30 2007 UTC revision 32 by dpavlin, Tue Apr 24 17:02:41 2007 UTC
# Line 11  my $PORT  = '3235'; Line 11  my $PORT  = '3235';
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/';
# Line 23  GetOptions( Line 24  GetOptions(
24          "verbose!"      => \$verbose,          "verbose!"      => \$verbose,
25          "search=i"      => \$resend_search_delay,          "search=i"      => \$resend_search_delay,
26          "tftp=s"        => \$tftp_path,          "tftp=s"        => \$tftp_path,
27            "credentials"   => \$credentials,
28  );  );
29    
30  $quiet = 0 if $verbose;  $quiet = 0 if $verbose;
31    $credentials = 1 if $debug;
32    
33  # tab-delimited list of user id/passwd to try on ants  # tab-delimited list of user id/passwd to try on ants
34  my @try_accounts = ( "Administrator\t" );  my @try_accounts = ( "Administrator\t" );
# Line 38  if (-e $passwd_path) { Line 41  if (-e $passwd_path) {
41          while(<$fh>) {          while(<$fh>) {
42                  chomp;                  chomp;
43                  next if /^#/ || /^$/ || /^\s+$/;                  next if /^#/ || /^$/ || /^\s+$/;
44                  if (/^\S+\t\S+$/) {                  if (/^\S+\s\S+$/) {
45                          push @try_accounts, $_;                          push @try_accounts, $_;
46                  } else {                  } else {
47                          warn "invalid $passwd_path entry: $_\n";                          warn "invalid $passwd_path entry: $_\n";
# Line 96  sub mdap_send { Line 99  sub mdap_send {
99    
100          $sock->mcast_send( $data, "${GROUP}:${PORT}" );          $sock->mcast_send( $data, "${GROUP}:${PORT}" );
101          if ($debug) {          if ($debug) {
102                  warn ">> ", dump( $data ), $/;                  warn ">> ${GROUP}:${PORT} >> ", dump( $data ), $/;
103          } elsif( ! $quiet ) {          } elsif( ! $quiet ) {
104                  $data =~ s/\s+/ /gi;                  $data =~ s/\s+/ /gi;
105                  warn ">> ", substr($data,0,70), $/;                  warn ">> ", substr($data,0,70), $/;
# Line 104  sub mdap_send { Line 107  sub mdap_send {
107  }  }
108    
109  my $ant_passwd;  my $ant_passwd;
110    my $ant_unknown_password;
111    my $ant_ok_password;
112    my $ant_flashing;
113    
114  sub ant_credentials {  sub ant_credentials {
115          my $ant = shift || die "no ant?";          my $ant = shift || die "no ant?";
# Line 113  sub ant_credentials { Line 119  sub ant_credentials {
119          return ($user_id,$user_pwd);          return ($user_id,$user_pwd);
120  }  }
121    
122  my $ant_unknown_password;  sub ant_unknown_password {
123  my $ant_ok_password;          my $ant = shift || die "no ant?";
124            if ( $ant_unknown_password->{$ant} ) {
125                    $ant_unknown_password->{$ant}--;
126            }
127            return $ant_unknown_password->{$ant};
128    }
129    
130  sub ant_another_passwd {  sub ant_another_passwd {
131          my $ant = shift || die "no ant?";          my $ant = shift || die "no ant?";
132          return 0 if ( $ant_unknown_password->{$ant} );  
133            return 0 if ant_unknown_password( $ant );
134            return 0 if $ant_ok_password->{$ant};
135    
136          $ant_passwd->{$ant}++;          $ant_passwd->{$ant}++;
137    
138          if ( $ant_passwd->{$ant} > $#try_accounts ) {          if ( $ant_passwd->{$ant} > $#try_accounts ) {
139                  print "$ant ant with unknown password\n";                  print "$ant ant with unknown password\n";
140                  $ant_unknown_password->{$ant}++;                  $ant_unknown_password->{$ant} = 10;
141                  $ant_passwd->{$ant} = 0;                  $ant_passwd->{$ant} = 0;
142                  return 0;                  return 0;
143          }          }
144          return 1;          return 1;
145  }  }
146    
147    sub forget_ant {
148            my $ant = shift || die "no ant?";
149            delete $ant_unknown_password->{$ant};
150            delete $ant_passwd->{$ant};
151            delete $ant_ok_password->{$ant};
152    }
153    
154  my $once;  my $once;
155    
156  sub once {  sub once {
# Line 139  sub once { Line 159  sub once {
159          print $m if ($once->{$m} == 1);          print $m if ($once->{$m} == 1);
160  }  }
161    
162    my $status = '';
163    
164    sub status {
165            my $m = join('', @_);
166            if ($m ne $status) {
167                    print $m;
168                    $status = $m;
169            }
170    }
171    
172  local $SIG{ALRM} = sub {  local $SIG{ALRM} = sub {
173          mdap_send("ANT-SEARCH MDAP/1.1\r\n");          mdap_send("ANT-SEARCH MDAP/1.1\r\n");
174          alarm( $resend_search_delay );          alarm( $resend_search_delay );
# Line 163  while (1) { Line 193  while (1) {
193    
194                  print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet;                  print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet;
195    
196                  warn dump($h),$/ if ($debug);                  warn dump( $data, $h ),$/ if ($debug);
197    
198                  # we are getting our own messages (since our source port                  # we are getting our own messages (since our source port
199                  # is same as destination)                  # is same as destination)
# Line 176  while (1) { Line 206  while (1) {
206                  my ($user_id,$user_pwd) = ant_credentials( $ant );                  my ($user_id,$user_pwd) = ant_credentials( $ant );
207    
208                  if ($type eq 'REPLY-ANT-SEARCH') {                  if ($type eq 'REPLY-ANT-SEARCH') {
209                          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") unless ( $ant_unknown_password->{$ant} );                          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") unless ant_unknown_password( $ant );
210                  } elsif ($type eq 'REPLY-INFO') {                  } elsif ($type eq 'REPLY-INFO') {
211    
212                          if ( $seq_nr < 0 ) {                          if ( $seq_nr < 0 ) {
213                                  if ( $ant_ok_password ) {  #                               if ( $ant_ok_password ) {
214                                          $ant_ok_password->{$ant} = 0;  #                                       $ant_ok_password->{$ant} = 0;
215                                  } elsif ( ant_another_passwd( $ant ) ) {  #                               } elsif ( ant_another_passwd( $ant ) ) {
216                                    if ( ant_another_passwd( $ant ) ) {
217                                          ($user_id,$user_pwd) = ant_credentials( $ant );                                          ($user_id,$user_pwd) = ant_credentials( $ant );
218                                          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");
219                                  }                                  }
220                                  next;                                  next;
221                          } else {                          } else {
222                                  $ant_ok_password->{$ant}++;                                  $ant_ok_password->{$ant}++;
223                                    print "$ant credentials $user_id $user_pwd\n" if ( $credentials && $ant_ok_password->{$ant} == 1 ) || $debug;
224                          }                          }
225    
226                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";
# Line 204  while (1) { Line 236  while (1) {
236                                                  $ant_ok_password->{$ant} ? ' password protected' :                                                  $ant_ok_password->{$ant} ? ' password protected' :
237                                                  '',                                                  '',
238                                                  "\n";                                                  "\n";
239    
240                                            $ant_flashing->{$ant} = 0;
241                                            # green|red|orange|flash|off
242                                            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");
243                                            my $waiting = 0;
244                                            my $count = 0;
245                                            map {
246                                                    $waiting++ if ($ant_flashing->{$_});
247                                                    $count++;
248                                            } keys %$ant_flashing;
249                                            if ($waiting == 0) {
250                                                    status "ALL $count ANTS FLASHED to $build\n";
251                                                    $ant_flashing = undef;
252                                            } else {
253                                                    status "$waiting of $count ants still flasing upto $build\n";
254                                            }
255                                  }                                  }
256                          } else {                          } else {
257                                  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";
258                          }                          }
259                  } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) {                  } elsif ( $type eq 'REPLY-EXEC-CLI' ) {
260                                  print "+ $ant bootp mode re-flash started\n";                          if ( $seq_nr == 1 ) {
261                                    print "+ $ant bootp mode re-flash started\n" if ($verbose);
262                                  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");
263                                  $ant_unknown_password->{$ant} = 0;                                  forget_ant( $ant );
264                                  $ant_passwd->{$ant} = 0;                                  $ant_flashing->{$ant}++;
265                                  $ant_ok_password->{$ant} = 0;                          } elsif ( $seq_nr == 2 ) {
266                                    print "+ $ant led\n" if ($verbose);
267                            }
268                  } else {                  } else {
269                          print "!! reply ignored ", dump( $h ), $/;                          print "!! reply $type ignored ", dump( $h ), $/;
270                  }                  }
271    
272          } else {          } else {

Legend:
Removed from v.24  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26