wmbiff: Fix security.debian.rb script.
Patch by Lothar Ketterer <lketterer@users.sourceforge.net> For more information, see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525749
This commit is contained in:
parent
b0006da45a
commit
0293ad1117
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
# Based on security-update-check.py by Rob Bradford
|
# Based on security-update-check.py by Rob Bradford
|
||||||
|
|
||||||
require 'net/http'
|
require 'net/ftp'
|
||||||
|
|
||||||
#require 'profile'
|
#require 'profile'
|
||||||
|
|
||||||
|
@ -67,16 +67,13 @@ end
|
||||||
# file, the url, the system's cache of the file, and a
|
# file, the url, the system's cache of the file, and a
|
||||||
# per-user cache of the file.
|
# per-user cache of the file.
|
||||||
packagelists = Dir.glob("/var/lib/apt/lists/#{Server}*Packages").map { |pkgfile|
|
packagelists = Dir.glob("/var/lib/apt/lists/#{Server}*Packages").map { |pkgfile|
|
||||||
[ pkgfile.gsub(/.*#{Server}/, '').tr('_','/'), # the url path
|
[ '/debian-security' + pkgfile.gsub(/.*#{Server}/, '').tr('_','/').gsub(/Packages/, ''), # the url path
|
||||||
pkgfile, # the system cache of the packages file. probably up-to-date.
|
pkgfile, # the system cache of the packages file. probably up-to-date.
|
||||||
# and finally, a user's cache of the page, if needed.
|
# and finally, a user's cache of the page, if needed.
|
||||||
"%s/%s" % [ Cachedir, pkgfile.gsub(/.*#{Server}_/,'') ]
|
"%s/%s" % [ Cachedir, pkgfile.gsub(/.*#{Server}_/,'') ]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
# we'll open a persistent session, but only if we need it.
|
|
||||||
session = nil
|
|
||||||
|
|
||||||
# update the user's cache if necessary.
|
# update the user's cache if necessary.
|
||||||
packagelists.each { |urlpath, sc, uc|
|
packagelists.each { |urlpath, sc, uc|
|
||||||
sctime = File.stat(sc).mtime
|
sctime = File.stat(sc).mtime
|
||||||
|
@ -91,31 +88,23 @@ packagelists.each { |urlpath, sc, uc|
|
||||||
uctime
|
uctime
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# the user cache doesn't exist, but we might have
|
sctime
|
||||||
# talked to the server recently.
|
|
||||||
if(test(?e, uc + '.stamp')) then
|
|
||||||
File.stat(uc + '.stamp').mtime
|
|
||||||
else
|
|
||||||
sctime
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if(Time.now > cached_time + Refetch_Interval_Sec) then
|
if(Time.now > cached_time + Refetch_Interval_Sec) then
|
||||||
debugmsg "fetching #{urlpath} %s > %s + %d" % [Time.now, cached_time, Refetch_Interval_Sec]
|
debugmsg "fetching #{urlpath} %s > %s + %d" % [Time.now, cached_time, Refetch_Interval_Sec]
|
||||||
begin
|
begin
|
||||||
if(session == nil) then
|
test(?e, Cachedir) or Dir.mkdir(Cachedir)
|
||||||
session = Net::HTTP.new(Server)
|
|
||||||
# session.set_pipe($stderr);
|
ftp = Net::FTP.new(Server)
|
||||||
end
|
ftp.login
|
||||||
begin
|
ftp.chdir(urlpath)
|
||||||
# the warning with ruby1.8 on the following line
|
ftp.getbinaryfile('Packages.gz', uc + '.gz', 1024)
|
||||||
# has to do with the resp, data bit, which should
|
ftp.close
|
||||||
# eventually be replaced with (copied from the
|
|
||||||
# docs with the 1.8 net/http.rb)
|
# need to unzip Packages.gz
|
||||||
# response = http.get('/index.html')
|
cmd_gunzip = "gzip -df %s" % [ uc + '.gz' ]
|
||||||
# puts response.body
|
Kernel.system(cmd_gunzip)
|
||||||
resp, data = session.get(urlpath,
|
|
||||||
{ 'If-Modified-Since' =>
|
|
||||||
cached_time.strftime( "%a, %d %b %Y %H:%M:%S GMT" ) })
|
|
||||||
rescue SocketError => e
|
rescue SocketError => e
|
||||||
# if the net is down, we'll get this error; avoid printing a stack trace.
|
# if the net is down, we'll get this error; avoid printing a stack trace.
|
||||||
puts "XX old"
|
puts "XX old"
|
||||||
|
@ -127,24 +116,7 @@ packagelists.each { |urlpath, sc, uc|
|
||||||
puts "XX old"
|
puts "XX old"
|
||||||
exit 1;
|
exit 1;
|
||||||
end
|
end
|
||||||
test(?e, Cachedir) or Dir.mkdir(Cachedir)
|
|
||||||
File.open(uc, 'w') { |o| o.puts data }
|
|
||||||
test(?e, uc + '.stamp') and File.unlink(uc + '.stamp') # we have a copy, don't need the stamp.
|
|
||||||
debugmsg "urlpath updated"
|
debugmsg "urlpath updated"
|
||||||
rescue Net::ProtoRetriableError => detail
|
|
||||||
head = detail.data
|
|
||||||
if head.code != "304"
|
|
||||||
raise "unexpected error occurred: " + detail
|
|
||||||
end
|
|
||||||
test(?e, Cachedir) or Dir.mkdir(Cachedir)
|
|
||||||
if(test(?e, uc)) then
|
|
||||||
touch(uc)
|
|
||||||
else
|
|
||||||
# we didn't get an update, but we don't have a cached
|
|
||||||
# copy in the user directory.
|
|
||||||
touch(uc + '.stamp')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
debugmsg "skipping #{urlpath}"
|
debugmsg "skipping #{urlpath}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue