[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.9 and 1.16

version 1.9, 2005/11/18 19:17:12 version 1.16, 2007/01/08 16:49:44
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: update_trango.pl,v 1.8 2005/11/17 20:20:59 andrew Exp $  # $RedRiver: update_trango.pl,v 1.15 2005/12/30 20:26:41 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 Net::TFTP;
   use YAML;
 my $config_file = shift || 'update_trango.conf';  use lib '.';
 my $max_tries = 3;  use Net::Telnet::Trango;
   
   my $config_file = shift || 'update_trango.conf';
   my $max_tries = 3;
 my $l = Mylogger->new( { log_prefix => 'UT' } );  
   
   
 $l->sp("Reading config file '$config_file'");  my $l = Mylogger->new( { log_prefix => 'UT' } );
 my $conf = read_conf($config_file);  
   
 $l->sp("  Hardware Type: $conf->{'type'}");  $l->sp("Reading config file '$config_file'");
 $l->sp("  File Name:     $conf->{'file_name'}");  my $conf = read_conf($config_file);
 $l->sp("  File Size:     $conf->{'file_size'}");  
 $l->sp("  File Checksum: $conf->{'file_cksum'}");  $l->sp("  Hardware Type: $conf->{'type'}");
 $l->sp("  FW Version:    $conf->{'ver'}");  $l->sp("  File Name:     $conf->{'file_name'}");
 $l->sp("  FW Checksum:   $conf->{'cksum'}");  $l->sp("  File Size:     $conf->{'file_size'}");
 $l->sp("");  $l->sp("  File Checksum: $conf->{'file_cksum'}");
   $l->sp("  FW Version:    $conf->{'ver'}");
   $l->sp("  FW Checksum:   $conf->{'cksum'}");
   $l->sp("");
   
   
   
 foreach my $fox (@{ $conf->{'ips'} }) {  
   $l->sp("Updating: $fox");  
   
   ## Connect and login.  foreach my $fox (@{ $conf->{'ips'} }) {
   my $t = new Trango::Telnet ({    $l->sp("Updating: $fox");
     Host    => $fox,  
     Timeout => 5,    ## Connect and login.
   });    my $t = new Net::Telnet::Trango (
       Timeout => 5,
   $l->p("Connecting to $fox");      Errmode => 'return',
   my ($type, $version) = $t->connect();    ) or die "Couldn't make new connection: $!";
   
   unless (defined $type && defined $version) {    $l->p("Connecting to $fox");
     $l->sp("Error connecting!");    unless ( $t->open($fox) ) {
     next;      $l->sp("Error connecting: $!");
   }      next;
     }
   if ($type ne $conf->{'type'}) {  
     $l->sp("Wrong type of unit ('$type' should be '$conf->{'type'}')");    if ($t->host_type ne $conf->{'type'}) {
     $t->close;      $l->sp("Wrong type of unit ('$t->host_type' should be '$conf->{'type'}')");
     next;      $t->close;
   }      next;
     }
   if ($version eq $conf->{'ver'}) {  
     $l->sp("Already up to date with firmware version '$version'");    if ($t->firmware_version eq $conf->{'ver'}) {
     $t->close;      $l->sp("Already up to date with firmware version '$t->firmware_version'");
     next;      $t->close;
   }      next;
     }
   $l->p("Logging in");  
   $t->login($conf->{'password'}) || die "Couldn't login: $!";    $l->p("Logging in");
     $t->login($conf->{'password'}) || die "Couldn't login: $!";
   $l->p("Sending commands");  
   ## Send commands    $l->p("Sending commands");
   if ( upload($t, $conf->{'file_name'}) ) {    ## Send commands
     $l->p("Rebooting");    #print Dump $t->login_banner;
     $t->reboot;    #print Dump $t->sysinfo;
   } else {    #print Dump $t->last_lines;
     $l->p("Exiting");    #print Dump $t->ver();
     $t->exit;    #print Dump $t->tftpd();
   }    #print Dump $t->enable_tftpd();
   $t->close;    #print Dump [ "Exit", $t->exit ];
   $l->sp("");    #print Dump $t->tftpd();
 }    #print Dump $t->disable_tftpd();
     #print Dump $t->tftpd();
 sub upload    print Dump $t->sulog(args => 5);
 {    #if ( upload($t, $conf->{'file_name'}) ) {
   my $t    = shift;    #   $l->p("Rebooting");
   my $file = shift;    #  $t->reboot;
     #} else {
   $l->p("Getting current version");      $l->p("Exiting");
   my $ver = $t->ver;      $t->exit;
     #}
   if (  
     $ver->{'Firmware Version'}  eq $conf->{'ver'} &&    $l->sp("");
     $ver->{'Firmware Checksum'} eq $conf->{'cksum'}  }
   ) {  
     $l->sp("Already updated!");  sub upload
     return 1;  {
   }    my $t    = shift;
     my $file = shift;
   my $try = 0;  
   while (1) {    my $ver = $t->ver;
     if ($try >= $max_tries) {    $l->p("Current version '$ver->{'Firmware Version'}'");
       $l->sp("Couldn't update in $max_tries tries!");  
       return undef;    if (
     }      $ver->{'Firmware Version'}  eq $conf->{'ver'} &&
     $try++;      $ver->{'Firmware Checksum'} eq $conf->{'cksum'}
     ) {
     #sysinfo($self->{'_host'});      $l->sp("Already updated!");
           return 1;
     $l->p("Enabling TFTPd");    }
     $t->enable_tftpd || die "Couldn't enable tftpd";  
     my $try = 0;
     $l->p("Uploading file ($file)");    while (1) {
     # use tftp to push the file up      if ($try >= $max_tries) {
     my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');        $l->sp("Couldn't update in $max_tries tries!");
         return undef;
     $tftp->put($file, $file)      }
       or die "Error uploading: " . $tftp->error;      $try++;
   
     # waitfor some sort of output      #sysinfo($self->{'_host'});
     # make sure it says 'Success.' otherwise error  
     #print "LAST: " . $self->lastline;      $l->p("Enabling TFTPd");
     #my @lines = $self->getlines;      $t->enable_tftpd || die "Couldn't enable tftpd";
     #print Dump \@lines;  
           $l->p("Uploading file ($file)");
     $l->p("Checking upload ($conf->{'file_cksum'})");      # use tftp to push the file up
     my $results = $t->tftpd;      my $tftp = Net::TFTP->new($t->Host, Mode => 'octet');
     # check the 'File Length' against ???  
     if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {      $tftp->put($file, $file)
       $l->sp("File checksum does not match config file!");        or die "Error uploading: " . $tftp->error;
       next;  
     }      # waitfor some sort of output
     $l->p("File checksum ($results->{'File Checksum'}) " .      # make sure it says 'Success.' otherwise error
           "matches ($conf->{'file_cksum'})");      #print "LAST: " . $self->lastline;
       #my @lines = $self->getlines;
     if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {      #print Dump \@lines;
       $l->sp("File length does not match config file!");  
       next;      $l->p("Checking upload ($conf->{'file_cksum'})");
     }      my $results = $t->tftpd;
     $l->p("File length ($results->{'File Length'}) " .      # check the 'File Length' against ???
           "matches ($conf->{'file_size'})");      if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) {
         $l->sp(
     if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {          "File checksum '" . $results->{'File Checksum'} .
       $l->sp("File name does not match config file!");          "does not match config file '" . $conf->{'file_cksum'} . "'!"
       next;        );
     }        next;
     $l->p("File name ($results->{'File Name'}) " .      }
           "matches ($conf->{'file_name'})");      $l->p("File checksum matches . . . ");
   
     $l->p("Updating flash (new checksum '$conf->{'cksum'}')");      if ($results->{'File Length'}   !~ /^$conf->{'file_size'} bytes/) {
     unless ($results = $t->updateflash(        $l->sp(
       $ver->{'Firmware Checksum'}, $conf->{'cksum'}          "File length '" . $results->{'File Length'} .
     ) ) {          "does not match config file '" . $conf->{'file_size'} . " bytes'!"
       $l->sp("Couldn't update flash: $!");        );
       next;        next;
     }      }
       $l->p("File length matches . . . ");
     unless (  
       defined $results->{'Checksum'} &&      if ( uc($results->{'File Name'}) ne uc($conf->{'file_name'}) ) {
       $results->{'Checksum'} eq $conf->{'cksum'}        $l->sp(
     ) {          "File name '" . $results->{'File Name'} .
       $l->sp("Saved checksum does not match config file!");          "' does not match config file '" . $conf->{'file_name'} . "'!"
       next;        );
     }        next;
     $l->p("Uploaded checksum ($results->{'Checksum'}) " .      }
           "matches ($conf->{'cksum'})");      $l->p("File name  matches . . . ");
       
     $l->sp("Successfully updated!");      $l->p("Updating flash (new checksum '$conf->{'cksum'}')");
     return 1;      unless ($results = $t->updateflash(
   }        args => 'mainimage ' . $ver->{'Firmware Checksum'} .
 }                ' '          . $conf->{'cksum'},
         Timeout => 90,
 sub read_conf      ) ) {
 {        $l->sp("Couldn't update flash: $!");
   my $file = shift;        next;
   my %conf;      }
   my $in_ip_list = 0;  
   open my $fh, $file or die "Couldn't open file $file: $!";      unless (
   while (<$fh>) {        defined $results->{'Checksum'} &&
     chomp;        $results->{'Checksum'} eq $conf->{'cksum'}
     next if /^#/;      ) {
     next if /^$/;        $l->sp("Saved checksum does not match config file!");
     if ($in_ip_list) {        next;
       if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {      }
         push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);      $l->p("Uploaded checksum ($results->{'Checksum'}) " .
       } else {            "matches ($conf->{'cksum'})");
         push @{ $conf{'ips'} }, $_;  
       }      $l->sp("Successfully updated!");
     } else {      return 1;
       my ($key, $val) = split /\s+/, $_, 2;    }
   }
       if (lc($key) eq 'ips') {  
         $in_ip_list = 1;  sub read_conf
         next;  {
       }    my $file = shift;
     my %conf;
       $conf{ lc($key) } = $val;    my $in_ip_list = 0;
     }    open my $fh, $file or die "Couldn't open file $file: $!";
   }    while (<$fh>) {
   close $fh;      chomp;
       next if /^#/;
   #print Dump \%conf;      next if /^$/;
   foreach (      if ($in_ip_list) {
     'password',        s/\s+//g; # Whitespace is a no no
     'file_name', 'file_size', 'file_cksum',  
     'ver', 'cksum', 'ips',        if (/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) {
   ) {          push @{ $conf{'ips'} }, $1 . $_ for ($2..$3);
     die "No $_ specified in config file!"        } else {
       if (not exists $conf{$_});          push @{ $conf{'ips'} }, $_;
   }        }
       } else {
   #print Dump \%conf;        my ($key, $val) = split /\s+/, $_, 2;
   #exit;  
   return \%conf;        if (lc($key) eq 'ips') {
 }          $in_ip_list = 1;
           next;
 package Trango::Telnet;        }
 use base 'Net::Telnet';  
         $key =~ s/^\s+//;
 my %PRIVATE = (        $key =~ s/\s+$//;
   connected => 0,        $val =~ s/^\s+//;
   logged_in => 0,        $val =~ s/\s+$//;
 );  
         $conf{ lc($key) } = $val;
 sub new {      }
   my $class = shift;    }
   my $args = shift || {};    close $fh;
   
   $args->{'Timeout'} ||= 5;    #print Dump \%conf;
   $args->{'Prompt'}  ||= '/#> *$/';    foreach (
       'password',
   foreach my $key (keys %{ $args }) {      'file_name', 'file_size', 'file_cksum',
     $PRIVATE{$key} = $args->{$key};      'ver', 'cksum', 'ips',
   }    ) {
       die "No $_ specified in config file!"
   my $self = $class->SUPER::new(%{ $args });        if (not exists $conf{$_});
   bless $self;    }
   
   #bless $self, $package;    #print Dump \%conf;
   return $self;    #exit;
 }    return \%conf;
   }
 sub connect  
 {  package Mylogger;
   my $self = shift;  
   use Fcntl ':flock'; # import LOCK_* constants
   unless ( $self->open(  #use YAML;
       Host => $PRIVATE{'Host'},  use constant LOG_PRINT => 128;
       Errmode => 'return',  use constant LOG_SAVE  =>  64;
   ) ) {  
     $! = "Couldn't connect to $self->{'Host'}.  Connection timed out.";  DESTROY {
     return undef, undef;    my $self = shift;
   }    if ($self->{'MYLOG'}) {
   #$self->dump_log('dump.log');      $self->p("Closing log ($self->{'log_path'}/$self->{'log_file'})");
       close $self->{'MYLOG'};
   ## Login to remote host.    }
   unless ($self->waitfor(  }
     -match => '/password: ?$/i',  
     -errmode => "return",  sub new {
   ) ) {    my $package = shift;
     $! = "problem connecting to host ($self->{'Host'}): " . $self->lastline;    my $self = shift || {};
     return undef;  
   }    $self->{'base_path'}  ||= '.';
     $self->{'log_path'}   ||= $self->{'base_path'};
   $self->login_banner($self->lastline);    $self->{'log_prefix'} ||= 'LOG';
     $self->{'log_file'}   ||= GetLogName(
   $PRIVATE{'connected'} = 1;      $self->{'log_prefix'},
       $self->{'log_path'}
   return ($self->host_type, $self->firmware_version);    );
 }    bless $self, $package;
   }
 sub login  
 {  sub s
   my $self = shift;  {
     my $self = shift;
   my $password = shift;    my $m = shift;
     return $self->mylog($m, LOG_SAVE);
   $self->print($password);  }
   unless ($self->waitfor(  
     -match => $self->prompt,  sub p
     -errmode => "return",  {
   ) ) {    my $self = shift;
     $! = "login ($self->{'Host'}) failed: " . $self->lastline;    my $m = shift;
     return undef;    return $self->mylog($m, LOG_PRINT);
   }  }
   
   $PRIVATE{'logged_in'} = 1;  sub sp
   {
   return 1;    my $self = shift;
 }    my $m = shift;
     return $self->mylog($m, LOG_SAVE | LOG_PRINT);
 sub login_banner  }
 {  
   my $self = shift;  sub mylog
   {
   my $banner = shift || $PRIVATE{'login_banner'};    my $self = shift;
   
   my ($type, $ver) = $banner =~    my $thing = shift;
     /Welcome to Trango Broadband Wireless (\w+)-(.+)$/i;    chomp $thing;
   
   $self->host_type($type);    my $which = shift;
   $self->firmware_version($ver);  
     my $MYLOG;
   return $banner;    if ($which & LOG_PRINT) {
 }      print $thing, "\n";
     }
 sub host_type  
 {    if ($which & LOG_SAVE) {
   my $self = shift;      if ($self->{'MYLOG'}) {
         $MYLOG = $self->{'MYLOG'};
   my $type = shift || $PRIVATE{'host_type'};      } else {
   $PRIVATE{'host_type'} = $type;        unless ($MYLOG) {
                   open ($MYLOG, '>>', $self->{'log_path'} . '/' . $self->{'log_file'})
   return $type;            or die "Couldn't open logfile!\n";
 }          my $ofh = select $MYLOG;
           $|=1;
 sub firmware_version          select $ofh;
 {          $self->{'MYLOG'} = $MYLOG;
   my $self = shift;  
           $self->p("Opened log ($self->{'log_path'}/$self->{'log_file'})");
   my $ver = shift || $PRIVATE{'firmware_version'};        }
   $PRIVATE{'firmware_version'} = $ver;      }
         flock($MYLOG, LOCK_EX);
   return $ver      print $MYLOG (scalar gmtime), "\t", $thing, "\n"
 }        or die "Couldn't print to MYLOG: $!";
       flock($MYLOG, LOCK_UN);
 sub Host    }
 {  }
   my $self = shift;  
     sub GetLogName
   my $host = shift || $PRIVATE{'Host'};  {
   $PRIVATE{'HOST'} = $host;    my $prefix  = shift || die "Invalid prefix passed for log";
   
   return $host;    my $logdate = GetLogDate();
 }    my $logver  = 0;
     my $logname;
   
 sub reboot    do {
 {      $logname = $prefix . $logdate . sprintf("%02d", $logver) . '.log';
   my $self = shift;      $logver++;
     } until (not -e $logname);
   $self->print("reboot\n");  
   $self->getline;    return $logname;
   }
   return 1;  
 }  sub GetLogDate
   {
 sub exit    my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime();
 {  
   my $self = shift;    $mon++;
     $year += 1900;
   $self->print("exit\n");  
   $self->getline;    if ($min  < 10) { $min  = "0$min"  }
     if ($sec  < 10) { $sec  = "0$sec"  }
   return 1;    if ($hour < 10) { $hour = "0$hour" }
 }    if ($mday < 10) { $mday = "0$mday" }
     if ($mon  < 10) { $mon  = "0$mon"  }
 sub ver  
 {    my $time = $year . $mon . $mday;
   my $self = shift;  
     return $time;
   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.9  
changed lines
  Added in v.1.16

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