[BACK]Return to update_trango.pl CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / scripts

Diff for /trango/Net-Telnet-Trango/scripts/update_trango.pl between version 1.11 and 1.23

version 1.11, 2005/12/21 02:03:30 version 1.23, 2007/02/01 18:44:30
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: update_trango.pl,v 1.10 2005/12/21 01:17:06 andrew Exp $  # $RedRiver: update_trango.pl,v 1.22 2007/02/01 17:58:33 andrew Exp $
 ########################################################################  ########################################################################
 # update_trango.pl *** Updates trango foxes with a new firmware  # update_trango.pl *** Updates trango foxes with a new firmware
 #  #
 # 2005.11.15 #*#*# andrew fresh <andrew@mad-techies.org>  # 2005.11.15 #*#*# andrew fresh <andrew@mad-techies.org>
 ########################################################################  ########################################################################
 use strict;  use strict;
 use warnings;  use warnings;
   
 use Net::TFTP;  use YAML qw/ LoadFile /;
   use Net::TFTP;
 my $config_file = shift || 'update_trango.conf';  use lib '.';
 my $max_tries = 3;  use Net::Telnet::Trango;
   
   my $config_file = shift || 'update_trango.yaml';
   my $max_tries = 3;
 my $l = Mylogger->new( { log_prefix => 'UT' } );  
   my $l = Mylogger->new( { log_prefix => 'UT' } );
   
 $l->sp("Reading config file '$config_file'");  $l->sp("Reading config file '$config_file'");
 my $conf = read_conf($config_file);  my $conf = LoadFile($config_file);
   
 $l->sp("  Hardware Type: $conf->{'type'}");  my @foxes = (
 $l->sp("  File Name:     $conf->{'file_name'}");  '10.100.1.2',
 $l->sp("  File Size:     $conf->{'file_size'}");  '10.100.2.2',
 $l->sp("  File Checksum: $conf->{'file_cksum'}");  '10.100.3.2',
 $l->sp("  FW Version:    $conf->{'ver'}");  '10.100.4.2',
 $l->sp("  FW Checksum:   $conf->{'cksum'}");  );
 $l->sp("");  
   foreach my $fox (@foxes) {
     $l->sp("Checking: $fox");
     my $needs_reboot = 0;
   
     ## Connect and login.
     my $t = new Net::Telnet::Trango (
 foreach my $fox (@{ $conf->{'ips'} }) {      Timeout => 5,
   $l->sp("Updating: $fox");      Errmode => 'return',
     ) or die "Couldn't make new connection: $!";
   ## Connect and login.    $l->p("Connecting to $fox");
   my $t = new Trango::Telnet ({    unless ( $t->open($fox) ) {
     Host    => $fox,      $l->sp("Error connecting: $!");
     Timeout => 5,      next;
   });    }
   
   $l->p("Connecting to $fox");    foreach my $firmware_type ('Firmware', 'FPGA') {
   my ($type, $version) = $t->connect();  
       if (! exists $conf->{$firmware_type}) {
   unless (defined $type && defined $version) {            $l->s("No configs for '$firmware_type'");
     $l->sp("Error connecting!");            $t->close();
     next;            next;
   }          }
   
   if ($type ne $conf->{'type'}) {      my $host_type = $t->host_type;
     $l->sp("Wrong type of unit ('$type' should be '$conf->{'type'}')");      if ($firmware_type eq 'FPGA') {
     $t->close;        $host_type =~ s/\s.*$//;
     next;      }
   }  
       if (! exists $conf->{$firmware_type}->{$host_type}) {
   if ($version eq $conf->{'ver'}) {            $l->sp("No '$firmware_type' config for type $host_type");
     $l->sp("Already up to date with firmware version '$version'");            $t->close();
     $t->close;            next;
     next;          }
   }  
       if (! $t->logged_in) {
   $l->p("Logging in");        $l->p("Logging in");
   $t->login($conf->{'password'}) || die "Couldn't login: $!";        $t->login($conf->{general}->{'password'});
         unless ($t->logged_in) {
   $l->p("Sending commands");          $l->p('Failed!');
   ## Send commands          $t->bye();
   if ( upload($t, $conf->{'file_name'}) ) {          next;
     $l->p("Rebooting");        }
     $t->reboot;      }
   } else {  
     $l->p("Exiting");          foreach my $k (keys %{ $conf->{general} }) {
     $t->exit;            $conf->{$firmware_type}->{$host_type}->{$k} ||= $conf->{general}->{$k};
   }      }
   $t->close;          $conf->{$firmware_type}->{$host_type}->{firmware_type} ||= $firmware_type;
   $l->sp("");          $conf->{$firmware_type}->{$host_type}->{type} ||= $host_type;
 }  
       $l->sp("$host_type $firmware_type");
 sub upload      $l->p("Sending commands");
 {      ## Send commands
   my $t    = shift;      my $rc = upload($t, $conf->{$firmware_type}->{$host_type});
   my $file = shift;          if ($rc) {
         $l->sp("Successfull!");
   my $ver = $t->ver;            $needs_reboot = 1;
   $l->p("Current version '$ver->{'Firmware Version'}'");      } elsif (defined $rc) {
             $l->sp("Already up to date");
   if (      } else {
     $ver->{'Firmware Version'}  eq $conf->{'ver'} &&            $l->sp("Failed");
     $ver->{'Firmware Checksum'} eq $conf->{'cksum'}            $t->bye;
   ) {            next;
     $l->sp("Already updated!");      }
     return 1;  
   }    }
   
   my $try = 0;    if ($needs_reboot) {
   while (1) {      $l->sp("Rebooting $fox");
     if ($try >= $max_tries) {      $t->reboot;
       $l->sp("Couldn't update in $max_tries tries!");    } else {
       return undef;      $l->sp("Bye $fox");
     }      $t->bye();
     $try++;    }
     $l->sp("");
     #sysinfo($self->{'_host'});  }
       
     $l->p("Enabling TFTPd");  sub upload
     $t->enable_tftpd || die "Couldn't enable tftpd";  {
     my $t    = shift;
     $l->p("Uploading file ($file)");    my $conf = shift;
     # use tftp to push the file up  
     my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');    my $file = $conf->{firmware_path} . '/' . $conf->{file_name};
   
     $tftp->put($file, $file)    my $fw_type = $conf->{firmware_type};
       or die "Error uploading: " . $tftp->error;  
     my $ver = $t->ver;
     # waitfor some sort of output  
     # make sure it says 'Success.' otherwise error    if (
     #print "LAST: " . $self->lastline;      $ver->{$fw_type . ' Version'}  eq $conf->{'ver'} &&
     #my @lines = $self->getlines;      $ver->{$fw_type . ' Checksum'} eq $conf->{'cksum'}
     #print Dump \@lines;    ) {
           return 0;
     $l->p("Checking upload ($conf->{'file_cksum'})");    }
     my $results = $t->tftpd;  
     # check the 'File Length' against ???    $l->sp("Config information:");
     if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {    $l->sp("  Hardware Type: $conf->{'type'}");
       $l->sp(    $l->sp("  File Name:     $conf->{'file_name'}");
         "File checksum '" . $results->{'File Checksum'} .    $l->sp("  File Size:     $conf->{'file_size'}");
         "does not match config file '" . $conf->{'file_cksum'} . "'!"    $l->sp("  File Checksum: $conf->{'file_cksum'}");
       );    $l->sp("  Conf Version:  $conf->{'ver'}");
       next;    $l->sp("  Cur  Version:  $ver->{$fw_type . ' Version'}");
     }    $l->sp("  Conf Checksum: $conf->{'cksum'}");
     $l->p("File checksum matches . . . ");    $l->sp("  Cur  Checksum: $ver->{$fw_type . ' Checksum'}");
   
     if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {    $l->sp("Updating");
       $l->sp(    my $try = 0;
         "File length '" . $results->{'File Length'} .    while (1) {
         "does not match config file '" . $conf->{'file_size'} . " bytes'!"      if ($try >= $max_tries) {
       );        $l->sp("Couldn't update in $max_tries tries!");
       next;        return;
     }      }
     $l->p("File length matches . . . ");      $try++;
   
     if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {      #sysinfo($self->{'_host'});
       $l->sp(  
         "File name '" . $results->{'File Name'} .      $l->p("Enabling TFTPd");
         "' does not match config file '" . $conf->{'file_name'} . "'!"      unless ($t->enable_tftpd) {
       );        $l->sp("Couldn't enable tftpd");
       next;        next;
     }      }
     $l->p("File name  matches . . . ");  
       $l->p("Uploading file ($file)");
     $l->p("Updating flash (new checksum '$conf->{'cksum'}')");      # use tftp to push the file up
     unless ($results = $t->updateflash(      my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');
       $ver->{'Firmware Checksum'}, $conf->{'cksum'}  
     ) ) {      unless ($tftp->put($file, $file)) {
       $l->sp("Couldn't update flash: $!");        $l->sp("Error uploading: " . $tftp->error);
       next;        next;
     }      }
   
     unless (      $l->p("Checking upload ($conf->{'file_cksum'})");
       defined $results->{'Checksum'} &&      my $results = $t->tftpd;
       $results->{'Checksum'} eq $conf->{'cksum'}      # check the 'File Length' against ???
     ) {      if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {
       $l->sp("Saved checksum does not match config file!");        $l->sp(
       next;          "File checksum '" . $results->{'File Checksum'} .
     }          " does not match config file '" . $conf->{'file_cksum'} . "'!"
     $l->p("Uploaded checksum ($results->{'Checksum'}) " .        );
           "matches ($conf->{'cksum'})");        next;
           }
     $l->sp("Successfully updated!");      $l->p("File checksum matches . . . ");
     return 1;  
   }      if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {
 }        $l->sp(
           "File length '" . $results->{'File Length'} .
 sub read_conf          "does not match config file '" . $conf->{'file_size'} . " bytes'!"
 {        );
   my $file = shift;        next;
   my %conf;      }
   my $in_ip_list = 0;      $l->p("File length matches . . . ");
   open my $fh, $file or die "Couldn't open file $file: $!";  
   while (<$fh>) {      if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {
     chomp;        $l->sp(
     next if /^#/;          "File name '" . $results->{'File Name'} .
     next if /^$/;          "' does not match config file '" . $conf->{'file_name'} . "'!"
     if ($in_ip_list) {        );
       s/\s+//g; # Whitespace is a no no        next;
       }
       if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {      $l->p("File name  matches . . . ");
         push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);  
       } else {      my $image_type = 'mainimage';
         push @{ $conf{'ips'} }, $_;      if ($fw_type eq 'FPGA') {
       }        $image_type = 'fpgaimage';
     } else {      }
       my ($key, $val) = split /\s+/, $_, 2;      $l->p("Updating $image_type (new checksum '$conf->{'cksum'}')");
       unless ($results = $t->updateflash(
       if (lc($key) eq 'ips') {        args => $image_type . ' ' . $ver->{$fw_type . ' Checksum'} .
         $in_ip_list = 1;                ' '          . $conf->{'cksum'},
         next;        Timeout => 90,
       }      ) ) {
         $l->sp("Couldn't update flash: $!");
       $key =~ s/^\s+//;        next;
       $key =~ s/\s+$//;      }
       $val =~ s/^\s+//;  
       $val =~ s/\s+$//;      unless (
         defined $results->{'Checksum'} &&
       $conf{ lc($key) } = $val;        $results->{'Checksum'} eq $conf->{'cksum'}
     }      ) {
   }        $l->sp("Saved checksum " . $results->{'Checksum'} . " does not match config file " .  $conf->{'cksum'} . "!");
   close $fh;        next;
       }
   #print Dump \%conf;      $l->p("Uploaded checksum ($results->{'Checksum'}) " .
   foreach (            "matches ($conf->{'cksum'})");
     'password',  
     'file_name', 'file_size', 'file_cksum',      $l->sp("Successfully updated!");
     'ver', 'cksum', 'ips',      return 1;
   ) {    }
     die "No $_ specified in config file!"  }
       if (not exists $conf{$_});  
   }  package Mylogger;
   
   #print Dump \%conf;  use Fcntl ':flock'; # import LOCK_* constants
   #exit;  #use YAML;
   return \%conf;  use constant LOG_PRINT => 128;
 }  use constant LOG_SAVE  =>  64;
   
 package Trango::Telnet;  DESTROY {
 use base 'Net::Telnet';    my $self = shift;
     if ($self->{'MYLOG'}) {
 my %PRIVATE = (      $self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})");
   connected => 0,      close $self->{'MYLOG'};
   logged_in => 0,    }
 );  }
   
 sub new {  sub new {
   my $class = shift;    my $package = shift;
   my $args = shift || {};    my $self = shift || {};
   
   $args->{'Timeout'} ||= 5;    $self->{'base_path'}  ||= '.';
   $args->{'Prompt'}  ||= '/#> *$/';    $self->{'log_path'}   ||= $self->{'base_path'};
     $self->{'log_prefix'} ||= 'LOG';
   foreach my $key (keys %{ $args }) {    $self->{'log_file'}   ||= GetLogName(
     $PRIVATE{$key} = $args->{$key};      $self->{'log_prefix'},
   }      $self->{'log_path'}
     );
   my $self = $class->SUPER::new(%{ $args });    bless $self, $package;
   bless $self;  }
   
   #bless $self, $package;  sub s
   return $self;  {
 }    my $self = shift;
     my $m = shift;
 sub connect    return $self->mylog($m, LOG_SAVE);
 {  }
   my $self = shift;  
   sub p
   unless ( $self->open(  {
       Host => $PRIVATE{'Host'},    my $self = shift;
       Errmode => 'return',    my $m = shift;
   ) ) {    return $self->mylog($m, LOG_PRINT);
     $! = "Couldn't connect to $self->{'Host'}.  Connection timed out.";  }
     return undef, undef;  
   }  sub sp
   #$self->dump_log('dump.log');  {
     my $self = shift;
   ## Login to remote host.    my $m = shift;
   unless ($self->waitfor(    return $self->mylog($m, LOG_SAVE | LOG_PRINT);
     -match => '/password: ?$/i',  }
     -errmode => "return",  
   ) ) {  sub mylog
     $! = "problem connecting to host ($self->{'Host'}): " . $self->lastline;  {
     return undef;    my $self = shift;
   }  
     my $thing = shift;
   $self->login_banner($self->lastline);    chomp $thing;
   
   $PRIVATE{'connected'} = 1;    my $which = shift;
   
   return ($self->host_type, $self->firmware_version);    my $MYLOG;
 }    if ($which & LOG_PRINT) {
       print $thing, "\n";
 sub login    }
 {  
   my $self = shift;    if ($which & LOG_SAVE) {
       if ($self->{'MYLOG'}) {
   my $password = shift;        $MYLOG = $self->{'MYLOG'};
       } else {
   $self->print($password);        unless ($MYLOG) {
   unless ($self->waitfor(                  open ($MYLOG, '>>', $self->{'log_path'} . '/' . $self->{'log_file'})
     -match => $self->prompt,            or die "Couldn't open logfile!\n";
     -errmode => "return",          my $ofh = select $MYLOG;
   ) ) {          $|=1;
     $! = "login ($self->{'Host'}) failed: " . $self->lastline;          select $ofh;
     return undef;          $self->{'MYLOG'} = $MYLOG;
   }  
           $self->p("Opened log ($self->{'log_path'}/$self->{'log_file'})");
   $PRIVATE{'logged_in'} = 1;        }
       }
   return 1;      flock($MYLOG, LOCK_EX);
 }      print $MYLOG (scalar gmtime), "\t", $thing, "\n"
         or die "Couldn't print to MYLOG: $!";
 sub login_banner      flock($MYLOG, LOCK_UN);
 {    }
   my $self = shift;  }
   
   my $banner = shift || $PRIVATE{'login_banner'};  sub GetLogName
   {
   my ($type, $ver) = $banner =~    my $prefix  = shift || die "Invalid prefix passed for log";
     /Welcome to Trango Broadband Wireless (\S+)[\s-]+(.+)$/i;  
     my $logdate = GetLogDate();
   $self->host_type($type);    my $logver  = 0;
   $self->firmware_version($ver);    my $logname;
   
   return $banner;    do {
 }      $logname = $prefix . $logdate . sprintf("%02d", $logver) . '.log';
       $logver++;
 sub host_type    } until (not -e $logname);
 {  
   my $self = shift;    return $logname;
   }
   my $type = shift || $PRIVATE{'host_type'};  
   $PRIVATE{'host_type'} = $type;  sub GetLogDate
   {
   return $type;    my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime();
 }  
     $mon++;
 sub firmware_version    $year += 1900;
 {  
   my $self = shift;    if ($min  < 10) { $min  = "0$min"  }
     if ($sec  < 10) { $sec  = "0$sec"  }
   my $ver = shift || $PRIVATE{'firmware_version'};    if ($hour < 10) { $hour = "0$hour" }
   $PRIVATE{'firmware_version'} = $ver;    if ($mday < 10) { $mday = "0$mday" }
       if ($mon  < 10) { $mon  = "0$mon"  }
   return $ver  
 }    my $time = $year . $mon . $mday;
   
 sub Host    return $time;
 {  }
   my $self = shift;  
     
   my $host = shift || $PRIVATE{'Host'};  
   $PRIVATE{'HOST'} = $host;  
   
   return $host;  
 }  
   
   
 sub reboot  
 {  
   my $self = shift;  
   
   $self->print("reboot\n");  
   $self->getline;  
   
   return 1;  
 }  
   
 sub exit  
 {  
   my $self = shift;  
   
   $self->print("exit\n");  
   $self->getline;  
   
   return 1;  
 }  
   
 sub ver  
 {  
   my $self = shift;  
   
   return $self->cmd('ver');  
 }  
   
 sub tftpd  
 {  
   my $self = shift;  
   
   return $self->cmd('tftpd', 'Success.');  
 }  
   
 sub sysinfo  
 {  
   my $self = shift;  
   
   return $self->cmd('sysinfo', 'Success.');  
 }  
   
 sub enable_tftpd  
 {  
   my $self = shift;  
   
   my $vals = $self->cmd('tftpd on', 'Success.');  
   
   if ($vals->{'Tftpd'} eq 'listen') {  
     return $vals;  
   } else {  
     return undef;  
   }  
 }  
   
 sub updateflash  
 {  
   my $self = shift;  
   
   my $old = shift;  
   my $new = shift;  
   
   return undef unless $new;  
   
   return $self->cmd("updateflash mainimage $old $new", 'Success.', 90);  
 }  
   
 sub cmd  
 {  
   my $self = shift;  
   
   my $string = shift;  
   my $expect_last = shift;  
   my $timeout = shift || $PRIVATE{'Timeout'};  
   
   unless (defined $string) {  
     $! = "No command passed";  
     return undef;  
   }  
   
   unless ($PRIVATE{'connected'}) {  
     $! = "Not connected";  
     return undef;  
   }  
   
   unless ($PRIVATE{'logged_in'}) {  
     $! = "Not logged in";  
     return undef;  
   }  
   
   my @lines = $self->SUPER::cmd(String => $string, Timeout => $timeout);  
   
   my $vals = _decode_lines(@lines);  
   
   unless ($expect_last) {  
     return $vals;  
   }  
   
   my $last = $self->lastline;  
   
   if ($last =~ /$expect_last$/) {  
     return $vals;  
   } else {  
     warn "Error with command ($string): $last";  
     return undef;  
   }  
 }  
   
 sub _decode_lines  
 {  
   my @lines = @_;  
   
   my %conf;  
   
   my $key = '';  
   my $val = '';  
   my $in_key = 0;  
   my $in_val = 0;  
   
   foreach my $line (@lines) {  
     my @chars = split //, $line;  
   
     my $last_key = '';  
     foreach my $c (@chars) {  
   
       if ($c eq '[' || $c eq "\r" || $c eq "\n") {  
         if ($c eq '[') {  
           $in_key = 1;  
           $in_val = 0;  
         } else {  
           $in_key = 0;  
           $in_val = 0;  
         }  
   
         if ($key) {  
           $key =~ s/^\s+//;  
           $key =~ s/\s+$//;  
   
           $val =~ s/^\s+//;  
           $val =~ s/\s+$//;  
   
           if ($key eq 'Checksum' && $last_key) {  
             # Special case for these bastids.  
             my $new = $last_key;  
             $new =~ s/\s+\S+$//;  
             $key = $new . " " . $key;  
           }  
   
           $last_key = $key;  
           $conf{$key} = $val;  
           $key = '';  
           $val = '';  
         }  
   
       } elsif ($c eq ']') {  
         $in_val = 1;  
         $in_key = 0;  
         $c = shift @chars;  
   
       } elsif ($in_key) {  
         $key .= $c;  
   
       } elsif ($in_val) {  
         $val .= $c;  
       }  
     }  
   }  
   #print Dump \%conf;  
   
   if (%conf) {  
     return \%conf;  
   } else {  
     return \@lines;  
   }  
 }  
   
   
   
 package Mylogger;  
   
 use Fcntl ':flock'; # import LOCK_* constants  
 #use YAML;  
 use constant LOG_PRINT => 128;  
 use constant LOG_SAVE  =>  64;  
   
 DESTROY {  
   my $self = shift;  
   if ($self->{'MYLOG'}) {  
     $self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})");  
     close $self->{'MYLOG'};  
   }  
 }  
   
 sub new {  
   my $package = shift;  
   my $self = shift || {};  
   
   $self->{'base_path'}  ||= '.';  
   $self->{'log_path'}   ||= $self->{'base_path'};  
   $self->{'log_prefix'} ||= 'LOG';  
   $self->{'log_file'}   ||= GetLogName(  
     $self->{'log_prefix'},  
     $self->{'log_path'}  
   );  
   bless $self, $package;  
 }  
   
 sub s  
 {  
   my $self = shift;  
   my $m = shift;  
   return $self->mylog($m, LOG_SAVE);  
 }  
   
 sub p  
 {  
   my $self = shift;  
   my $m = shift;  
   return $self->mylog($m, LOG_PRINT);  
 }  
   
 sub sp  
 {  
   my $self = shift;  
   my $m = shift;  
   return $self->mylog($m, LOG_SAVE | LOG_PRINT);  
 }  
   
 sub mylog  
 {  
   my $self = shift;  
   
   my $thing = shift;  
   chomp $thing;  
   
   my $which = shift;  
   
   my $MYLOG;  
   if ($which & LOG_PRINT) {  
     print $thing, "\n";  
   }  
   
   if ($which & LOG_SAVE) {  
     if ($self->{'MYLOG'}) {  
       $MYLOG = $self->{'MYLOG'};  
     } else {  
       unless ($MYLOG) {  
                 open ($MYLOG, '>>', $self->{'log_path'} . '/' . $self->{'log_file'})  
           or die "Couldn't open logfile!\n";  
         my $ofh = select $MYLOG;  
         $|=1;  
         select $ofh;  
         $self->{'MYLOG'} = $MYLOG;  
   
         $self->p("Opened log ($self->{'log_path'}/$self->{'log_file'})");  
       }  
     }  
     flock($MYLOG, LOCK_EX);  
     print $MYLOG (scalar gmtime), "\t", $thing, "\n"  
       or die "Couldn't print to MYLOG: $!";  
     flock($MYLOG, LOCK_UN);  
   }  
 }  
   
 sub GetLogName  
 {  
   my $prefix  = shift || die "Invalid prefix passed for log";  
   
   my $logdate = GetLogDate();  
   my $logver  = 0;  
   my $logname;  
   
   do {  
     $logname = $prefix . $logdate . sprintf("%02d", $logver) . '.log';  
     $logver++;  
   } until (not -e $logname);  
   
   return $logname;  
 }  
   
 sub GetLogDate  
 {  
   my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime();  
   
   $mon++;  
   $year += 1900;  
   
   if ($min  < 10) { $min  = "0$min"  }  
   if ($sec  < 10) { $sec  = "0$sec"  }  
   if ($hour < 10) { $hour = "0$hour" }  
   if ($mday < 10) { $mday = "0$mday" }  
   if ($mon  < 10) { $mon  = "0$mon"  }  
   
   my $time = $year . $mon . $mday;  
   
   return $time;  
 }  

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.23

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>