2
# This file is part of Checkbox.
4
# Copyright 2008 Canonical Ltd.
6
# Checkbox is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# Checkbox is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21
from checkbox.lib.environ import add_variable, get_variable
23
from checkbox.properties import String
24
from checkbox.plugin import Plugin
27
class ProxyInfo(Plugin):
29
# HTTP proxy to use instead of the one specified in environment.
30
http_proxy = String(required=False)
32
# HTTPS proxy to use instead of the one specified in environment.
33
https_proxy = String(required=False)
35
def register(self, manager):
36
super(ProxyInfo, self).register(manager)
40
self._manager.reactor.call_on("report-gconf", self.report_gconf)
41
self._manager.reactor.call_on("gather", self.gather, 100)
43
def report_gconf(self, resources):
44
proxy_pattern = re.compile(r"/system/(http_)?proxy/(?P<name>[^/]+)$")
45
for resource in resources:
46
match = proxy_pattern.match(resource["name"])
48
self.proxy[match.group("name")] = resource["value"]
51
# Config has lowest precedence
52
http_proxy = self.http_proxy
53
https_proxy = self.https_proxy
55
# Gconf has higher precedence
57
if proxy.get("use_http_proxy", False):
58
if proxy.get("use_authentication", False):
59
http_proxy = "http://%s:%s@%s:%s" % (
60
proxy["authentication_user"],
61
proxy["authentication_password"],
65
http_proxy = "http://%s:%s" % (
69
if proxy.get("use_same_proxy", False):
70
https_proxy = http_proxy
71
elif "secure_host" in proxy:
72
https_proxy = "https://%s:%s" % (
76
# Environment has highest precedence
77
http_proxy = get_variable("http_proxy", http_proxy)
78
https_proxy = get_variable("https_proxy", https_proxy)
80
add_variable("http_proxy", http_proxy)
81
add_variable("https_proxy", https_proxy)