rendered paste body#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use Time::Local;
open OUT, ">/home/download/data/htdocs/$ARGV[1]/list";
sub GetList($) {
my $URL = shift;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $URL);
my $contents;
my %mon = ( Jan=>0, Feb=>1, Mar=>2, Apr=>3, May=>4, Jun=>5, Jul=>6, Aug=>7, Sep=>8, Oct=>9, Nov=>10, Dec=>11 );
#/home/download/data/htdocs /Linux-cc6/x86_64/VDSmanager/DiskTemplate/openvz
$ua->request($req, sub { ($contents, undef) = @_; });
my @files = split /\n/, $contents;
foreach my $line (@files) {
my @fields = split / +/, $line;
if( my ($name) = ($fields[8] =~ /^(.*$ARGV[0].*)\.tar\.gz$/) ) {
my $time;
if( my @time = ($fields[7] =~ /^([0-9]+):([0-9]+)$/) ) {
if ($mon{$fields[5]} > (gmtime(time))[4]) {
$time = timegm(00, $time[1], $time[0], $fields[6], $mon{$fields[5]}, (gmtime(time))[5]-1);
} else {
$time = timegm(00, $time[1], $time[0], $fields[6], $mon{$fields[5]}, (gmtime(time))[5]);
}
} else {
$time = timegm(00, 00, 00, $fields[6], $mon{$fields[5]}, $fields[7]);
}
print OUT "$name $URL$name.tar.gz $fields[4] $time\n";
}
}
}
#GetList("ftp://download.openvz.org/template/precreated/");
#GetList("ftp://download.openvz.org/template/precreated/contrib/");
#Local
#/home/download/data/htdocs/Linux-cc6/x86_64/VDSmanager/DiskTemplate/openvz
my $path = "/home/download/data/htdocs/$ARGV[1]/openvz";
opendir DIR, $path;
readdir(DIR);
readdir(DIR);
while( my $name = readdir(DIR) ) {
#my $name = $_;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat "$path/$name";
my $short = substr($name, 0, length($name)-7);
print OUT "$short http://download.ispsystem.com/$ARGV[1]/openvz/$name $size $mtime\n";
}
closedir DIR;
if ("amd64" =~ $ARGV[0]) {
$path =~ s/x86_64/i686/go;
print $path;
opendir DIR, $path;
readdir(DIR);
readdir(DIR);
while( my $name = readdir(DIR) ) {
#my $name = $_;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat "$path/$name";
my $short = substr($name, 0, length($name)-7);
print OUT "$short http://download.ispsystem.com/$ARGV[1]/openvz/$name $size $mtime\n";
}
closedir DIR;
}
close OUT;