]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
fireinfo: support upstream proxy with authentication
authorPeter Müller <peter.mueller@link38.eu>
Tue, 4 Dec 2018 17:13:15 +0000 (18:13 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Dec 2018 19:32:39 +0000 (19:32 +0000)
Fireinfo could not send its profile to https://fireinfo.ipfire.org/
if the machine is behind an upstream proxy which requires username
and password. This is fixed by tweaking urllib2's opening handler.

To apply this on existing installations, the fireinfo package
needs to be shipped during an update.

The third version of this patch fixes bogus indention, assembles
proxy authentication string more readable and preserves HTTP
proxy handler.

Fixes #11905

Signed-off-by: Peter Müller <peter.mueller@link38.eu>
Cc: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/sendprofile [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index b836567..3ce68b9
@@ -73,10 +73,20 @@ def send_profile(profile):
        request.add_header("User-Agent", "fireinfo/%s" % fireinfo.__version__)
 
        # Set upstream proxy if we have one.
-       # XXX this cannot handle authentication
        proxy = get_upstream_proxy()
+
        if proxy["host"]:
-               request.set_proxy(proxy["host"], "http")
+               # handling upstream proxies with authentication is more tricky...
+               if proxy["user"] and proxy["pass"]:
+                       prx_auth_string = "http://%s:%s@%s/" % (proxy["user"], proxy["pass"], proxy["host"])
+
+                       proxy_handler = urllib2.ProxyHandler({'http': prx_auth_string, 'https': prx_auth_string})
+                       auth = urllib2.HTTPBasicAuthHandler()
+                       opener = urllib2.build_opener(proxy_handler, auth, urllib2.HTTPHandler)
+                       urllib2.install_opener(opener)
+               else:
+                       request.set_proxy(proxy["host"], "http")
+                       request.set_proxy(proxy["host"], "https")
 
        try:
                urllib2.urlopen(request, timeout=60)