euscan: verify urls when redirected

Reported-By: Daniel Pielmeier <billie@gentoo.org>
Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary 2011-04-18 21:20:45 +02:00
parent a7a15c0ac7
commit d74b2c5056

17
euscan
View File

@ -175,23 +175,31 @@ def gen_versions(components, level):
return versions return versions
def tryurl(fileurl, output): def tryurl(fileurl, output, regex):
result = False result = False
output.ebegin("Trying: " + fileurl) output.ebegin("Trying: " + fileurl)
try: try:
basename = os.path.basename(fileurl)
fp = urllib2.urlopen(fileurl, None, 5) fp = urllib2.urlopen(fileurl, None, 5)
headers = fp.info() headers = fp.info()
basename = os.path.basename(fileurl)
if 'Content-disposition' in headers and basename not in headers['Content-disposition']: if 'Content-disposition' in headers and basename not in headers['Content-disposition']:
result = False result = False
elif 'Content-Length' in headers and headers['Content-Length'] == '0': elif 'Content-Length' in headers and headers['Content-Length'] == '0':
result = False result = False
elif 'text/html' in headers['Content-Type']: elif 'text/html' in headers['Content-Type']:
result = False result = False
elif fp.geturl() != fileurl:
basename2 = os.path.basename(fp.geturl())
# Redirect to another (earlier?) version
if basename != basename2 and re.match(regex, fp.geturl()):
result = False
else:
result = True
else: else:
result = True result = True
except urllib2.URLError: except urllib2.URLError:
@ -388,8 +396,9 @@ def brute_force(cpv, fileurl, options, output, limit=None):
continue continue
url = url_from_template(template, vstring) url = url_from_template(template, vstring)
regex = regex_from_template(template)
if not tryurl(url, output): if not tryurl(url, output, regex):
continue continue
result.append([url, vstring]) result.append([url, vstring])