#!/usr/bin/perl # Autor: Sebastian Enger, 14.04.05 # Zweck: Ceckt nach Security Patches für Debian-Systeme und lädt diese bei bedarf automatisch herrunter # future: installiere heruntergeladene datein gleich use LWP::Simple; use HTML::LinkExtor; use LWP::UserAgent; use URI::URL; # hash with year/site information %debian_security_sites = ( "2007" => 'http://www.debian.org/security/2007/', "2006" => 'http://www.debian.org/security/2006/', "2005" => 'http://www.debian.org/security/2005/', "2004" => 'http://www.debian.org/security/2004/', "2003" => 'http://www.debian.org/security/2003/', "2002" => 'http://www.debian.org/security/2002/', "2001" => 'http://www.debian.org/security/2001/', "2000" => 'http://www.debian.org/security/2000/', ); $count = "1"; system("clear"); print "$0 - check for Security Patches for Debian Linux and download them\n"; print "Enter Year to check for updates [2000 2001 2002 2003 2004 2005 2006]\n"; # get input from keyboard chomp($year=); if ($year !~ /\d/) { print "Only Numbers please!\n"; print "Exiting now!\n"; exit; } else { # make folder structure to download files to # /tmp/security_patches/$year/$number -> download # created directory will be readable for everyone mkdir("/tmp/security_patches", 0755); mkdir("/tmp/security_patches/$year", 0755); # foreach year/site combination in hash %debian_security_sites do something while ( my ($key, $value) = each(%debian_security_sites) ) { if ($key == $year) { # get debian site with advisories in -> use function "get" from LWP::Simple $doc = get($value); @content = split(/\n/, $doc); foreach $line (@content){ if ($line =~ //) { # if an Security Advisories was found # algorithm for extracting important values goes here @important = split(/>/,$line); @important[1] =~ s/<\/tt//; @it = split(/"/,@important[3]); substr(@it[1], 0, 2) = ""; @important[4] =~ s/<\/a//; @important[6] =~ s/ - //; @important[6] =~ s/
); if ($files =~ /all/i){ print "DOWNLOADING ALL PATCHES FROM $year to /tmp/security_patches/$year/ !\n"; sleep 1; foreach $f_entry (@download){ # split into number and uri @uris = split(/ /,$f_entry); # get the files and download them to folder -> use an own function for it &gather_patchfiles(@uris[0],@uris[1]); } } else { print "DOWNLOADING CHOOSEN FILES TO /tmp/security_patches/$year/ "; @files = split(/ /,$files); foreach $entry (@files){ foreach $number (@download){ if ($entry == $number){ # split into number and uri @imp = split(/ /, $number); &gather_patchfiles(@imp[0],@imp[1]); } } } }# else } # function for downloading patches sub gather_patchfiles { $patch_number = @_[0]; $url = @_[1]; $ua = new LWP::UserAgent; $p = HTML::LinkExtor->new(\&collect); sub collect { my($tag, %attr) = @_; # request(HTTP::Request->new(GET => $url), sub { $p->parse($_[0]) } ); $base = $response->base; @A_HREF = map { $_ = url($_, $base)->abs; } @A_HREF; foreach $file (@A_HREF){ if (reverse($file) =~ /^bed./){ # only *.deb files contain patches @filename = split(/\//, $file); print "Downloading @filename[$#filename] to $year/$patch_number\n"; mkdir("/tmp/security_patches/$year/$patch_number", 0755); chdir("/tmp/security_patches/$year/$patch_number"); # download patch to folder -> use function "getstore" from LWP::Simple getstore("$file","@filename[$#filename]"); } } }# sub gather_patchfiles