summaryrefslogtreecommitdiffstats
path: root/scripts/send-error-report
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2014-04-11 20:49:14 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-04-23 11:43:27 +0100
commite2661d73672947f0981ffacfeed28209c8a6a128 (patch)
tree1290e53220d82042523752b252cac3b33ac99b99 /scripts/send-error-report
parent1cb95f7bdf04f189261db4ea0fbf1c7a6293cd04 (diff)
downloadpoky-e2661d73672947f0981ffacfeed28209c8a6a128.tar.gz
scripts/send-error-report: simple hack to use proxy from the enviroment
People behind a proxy couldn't send an error report to an upstream server, this should fix the issue if they use a proxy that doesn't require authentication, or one that uses basic http authentication and it's correctly exported in the enviroment. (From OE-Core rev: a8511ee80246b4e2caa353b87f4b586f1539e6d4) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/send-error-report')
-rwxr-xr-xscripts/send-error-report43
1 files changed, 36 insertions, 7 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report
index d23ae27dda..3d1f7a4017 100755
--- a/scripts/send-error-report
+++ b/scripts/send-error-report
@@ -7,7 +7,39 @@
7 7
8 8
9 9
10import httplib, urllib, os, sys, json 10import httplib, urllib, os, sys, json, base64
11from urllib2 import _parse_proxy as parseproxy
12
13
14def handle_connection(server, data):
15 params = urllib.urlencode({'data': data})
16 headers = {"Content-type": "application/json"}
17 proxyrequired = False
18 if os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"):
19 proxyrequired = True
20 # we need to check that the server isn't a local one, as in no_proxy
21 try:
22 temp = httplib.HTTPConnection(server, strict=True, timeout=5)
23 temp.request("GET", "/")
24 tempres = temp.getresponse()
25 if tempres.status == 200:
26 proxyrequired = False
27 temp.close()
28 except:
29 pass
30
31 if proxyrequired:
32 proxy = parseproxy(os.environ.get("http_proxy") or os.environ.get("HTTP_PROXY"))
33 if proxy[1] and proxy[2]:
34 auth = base64.encodestring("%s:%s" % (proxy[1], proxy[2]))
35 headers["Authorization"] = "Basic %s" % auth
36 conn = httplib.HTTPConnection(proxy[3])
37 conn.request("POST", "http://%s/ClientPost/" % server, params, headers)
38 else:
39 conn = httplib.HTTPConnection(server)
40 conn.request("POST", "/ClientPost/", params, headers)
41
42 return conn
11 43
12 44
13def sendData(json_file, server): 45def sendData(json_file, server):
@@ -45,10 +77,7 @@ def sendData(json_file, server):
45 return 77 return
46 78
47 try: 79 try:
48 params = urllib.urlencode({'data': data}) 80 conn = handle_connection(server, data)
49 headers = {"Content-type": "application/json"}
50 conn = httplib.HTTPConnection(server)
51 conn.request("POST", "/ClientPost/", params, headers)
52 response = conn.getresponse() 81 response = conn.getresponse()
53 print response.status, response.reason 82 print response.status, response.reason
54 res = response.read() 83 res = response.read()
@@ -59,8 +88,8 @@ def sendData(json_file, server):
59 with open("%s.response.html" % json_file, "w") as f: 88 with open("%s.response.html" % json_file, "w") as f:
60 f.write(res) 89 f.write(res)
61 conn.close() 90 conn.close()
62 except: 91 except Exception as e:
63 print("Server connection failed") 92 print("Server connection failed: %s" % e)
64 93
65 else: 94 else:
66 print("No data file found.") 95 print("No data file found.")