summaryrefslogtreecommitdiffstats
path: root/scripts
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-05-29 13:42:18 +0100
commitd8b564530eedc5367e661fd0d1b4aacd6a77dbaf (patch)
treed64a2807ab06c3a55608e426fe2c5fcf75a768a9 /scripts
parentaf91e98e32a76da587f3d7bcd4f767767ffe5fdc (diff)
downloadpoky-d8b564530eedc5367e661fd0d1b4aacd6a77dbaf.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) (From OE-Core rev: 3550355391a8920911e0dc68f01690afff7003b2) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-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.")