Автор:
Slapotam
Описание: Обновление NOD32 в папку
Язык: Perl
#!/usr/bin/perl
use LWP;
# path to store updates
$PATH="/home/samba/nod32";
# username/password for updates registered users
$LOGIN="";
$PASS="";
# URL for updates
#$URL_UPD="http://u2.eset.com/nod_eval";
#$URL_UPD="http://u2.eset.com/";
$URL_UPD="http://192.168.x.x/nod32/";
$URL_UPD =~ s/\/$//;
$URL_UPD =~ m/(.*:\/\/)(.*?)(\/.*)/;
$site = "$1$2";
if ($site =~ m//) {
print "Enter correct URL\n";
return;
}
unlink("$PATH/update.ver","$PATH/update.tmp");
download($PATH,"$URL_UPD/update.ver",$LOGIN,$PASS);
`/usr/local/bin/unrar e -y $PATH/update.ver $PATH 2> /dev/null`;
rename("$PATH/update.ver","$PATH/update.tmp");
$ver = "$PATH/update.tmp";
$vers = "$PATH/update.ver";
open(VER, "< $ver") or die "Couldn't open $ver for reading: $!\n";
open(VERS, "> $vers") or die "Couldn't open $vers for writing: $!\n";
%files = ();
%urls = ();
while (defined($line = <VER>) )
{
chomp $line;
$line =~ s/^\s+//;
$line =~ s/\s+$//;
($par,$val)=split /=/, $line;
if ($par =~ /file/ )
{
$name = $val;
$name =~ s/\/.*\///;
if ($name=~m/$val/) {$furl="$URL_UPD/$val";}
else {$furl="$site$val";}
$line="file=$name";
}
if ($par =~ /size/ )
{
$size = $val;
$files{$name} = $size;
$urls{$name} = "$furl";
}
print VERS "$line\r\n";
}
print "\n";
close(VER);
close(VERS);
foreach $f (keys %files) {
if ( (-s ("$PATH/$f")) != $files{$f}){
download($PATH,$urls{$f},$LOGIN,$PASS);
}
}
chmod(0644,"$PATH/*");
sub download()
{
my ($path, $url, $login, $pass) = @_;
# use external downloader
system("cd \"$PATH\"; /usr/bin/wget -c $url");
return;
# PERL downloader
$url =~ m/(.*:\/\/)(.*)\/(.*)/;
my $filename = $3;
my $ua=LWP::UserAgent->new();
$ua->agent("PerlUA/0.1");
my $ua=LWP::UserAgent->new();
$ua->agent("PerlUA/0.1");
my $req = HTTP::Request->new(HEAD => "$url");
$req->authorization_basic($login, $pass);
my $document=$ua->request($req);
if($document->is_success) {
if (!($document->content_length== -s("$path/$filename"))) {
my $req = HTTP::Request->new(GET => "$url");
$req->authorization_basic('login', 'password');
my $document=$ua->request($req);
if($document->is_success) {
open(OUT, "> $path/$filename");
print OUT $document->content;
close(OUT);
print "Downloading $url ";
print "- ok\n";
}
else {
print "$url ",$document->status_line,"\n";
}
}
else {
# print "$filename - exist\n";
}
}
else {
print "$url ",$document->status_line,"\n";
}
}
|
Последние размещения:
antonivanov (SQL)
antonivanov (PHP)
brinza (PHP)
ilyhamas (Delphi)
Riateche (PHP)
otherlight (Java)
otherlight (JavaScript)
otherlight (CSS)
otherlight (CSS)
biophreak (JavaScript)
n4n (Perl)
prostoHz (Java)
ndubinkin (XML)
Riateche (Plain Text)
Slapotam (Perl)
ksurent (Perl)
John_Wein (Java)
John_Wein (HTML)
Riateche (HTML)
|