# HG changeset patch # User BenoƮt Allard # Date 1416238917 -3600 # Node ID 0a5b5b5549cbde67e7c29bb1cc3aba4679345b0f # Parent 3b93e8e7876b18a278be5600c64d757ed4e93614 Add Proxy Configuration diff -r 3b93e8e7876b -r 0a5b5b5549cb farol/main.py --- a/farol/main.py Fri Nov 14 17:08:37 2014 +0100 +++ b/farol/main.py Mon Nov 17 16:41:57 2014 +0100 @@ -32,7 +32,6 @@ import farolluz from farolluz.cvrf import CVRF, ValidationError from farolluz.parsers.cvrf import parse -from farolluz.py2 import urlopen from farolluz.renderer import render as render_cvrf from farolluz.utils import utcnow @@ -109,8 +108,13 @@ ('Edit a security advisory in CVRF format', 100)] ) -def set_url(url): - try: content = urlopen(url).read() +def download_url(url): + proxy_host = app.config.get('PROXY_HOST', '') + if proxy_host: + proxy = urllib2.ProxyHandler({'http': proxy_host, 'https': proxy_host}) + opener = urllib2.build_opener(proxy) + urllib2.install_opener(opener) + try: content = urllib2.urlopen(url).read() except urllib2.HTTPError as e: flash('Unable to retrieve %s: %s' % (url, e)) return @@ -129,14 +133,14 @@ flash('Wrong RHSA id: %s' % id_) return # Process it - set_url("https://www.redhat.com/security/data/cvrf/%(year)s/cvrf-rhsa-%(year)s-%(index)s.xml" % {'year': year, 'index': index}) + download_url("https://www.redhat.com/security/data/cvrf/%(year)s/cvrf-rhsa-%(year)s-%(index)s.xml" % {'year': year, 'index': index}) def set_oracle(id_): try: int(id_) except ValueError: flash('Wrong Oracle id: %s' % id_) return - set_url("http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/%s.xml" % id_) + download_url("http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/%s.xml" % id_) def set_cisco(id_): if id_.count('-') < 2: @@ -147,7 +151,7 @@ except KeyError: flash('Wrong cisco id: %s' % id_) return - set_url("http://tools.cisco.com/security/center/contentxml/CiscoSecurity%(kind)s/cisco-%(id)s/cvrf/cisco-%(id)s_cvrf.xml" % {'kind': kind, 'id': id_}) + download_url("http://tools.cisco.com/security/center/contentxml/CiscoSecurity%(kind)s/cisco-%(id)s/cvrf/cisco-%(id)s_cvrf.xml" % {'kind': kind, 'id': id_}) def set_text(text): try: doc = parse(text) @@ -171,7 +175,7 @@ flash("I'm not able to parse NASL scripts yet", 'danger') return redirect(url_for('new')) elif 'url' in request.form: - set_url(request.form['url']) + download_url(request.form['url']) elif 'local' in request.files: upload = request.files['local'] fpath = os.path.join(app.instance_path, 'tmp',