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:
parent
a7a15c0ac7
commit
d74b2c5056
17
euscan
17
euscan
@ -175,23 +175,31 @@ def gen_versions(components, level):
|
||||
|
||||
return versions
|
||||
|
||||
def tryurl(fileurl, output):
|
||||
def tryurl(fileurl, output, regex):
|
||||
result = False
|
||||
|
||||
output.ebegin("Trying: " + fileurl)
|
||||
|
||||
try:
|
||||
basename = os.path.basename(fileurl)
|
||||
|
||||
fp = urllib2.urlopen(fileurl, None, 5)
|
||||
headers = fp.info()
|
||||
|
||||
basename = os.path.basename(fileurl)
|
||||
|
||||
if 'Content-disposition' in headers and basename not in headers['Content-disposition']:
|
||||
result = False
|
||||
elif 'Content-Length' in headers and headers['Content-Length'] == '0':
|
||||
result = False
|
||||
elif 'text/html' in headers['Content-Type']:
|
||||
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:
|
||||
result = True
|
||||
except urllib2.URLError:
|
||||
@ -388,8 +396,9 @@ def brute_force(cpv, fileurl, options, output, limit=None):
|
||||
continue
|
||||
|
||||
url = url_from_template(template, vstring)
|
||||
regex = regex_from_template(template)
|
||||
|
||||
if not tryurl(url, output):
|
||||
if not tryurl(url, output, regex):
|
||||
continue
|
||||
|
||||
result.append([url, vstring])
|
||||
|
Loading…
Reference in New Issue
Block a user