import fireinfo
ENABLED_FILE = "/var/ipfire/main/send_profile"
+PROXY_SETTINGS = "/var/ipfire/proxy/advanced/settings"
log_level = logging.INFO
if "-d" in sys.argv:
PROFILE_URL = "http://stasy.ipfire.org/send/%(public_id)s"
+def get_upstream_proxy():
+ if not os.path.exists(PROXY_SETTINGS):
+ return
+
+ proxy_settings = {}
+ with open(PROXY_SETTINGS) as f:
+ for line in f.readlines():
+ k, v = line.split("=", 1)
+ proxy_settings[k] = v.strip()
+
+ return {
+ "host" : proxy_settings.get("UPSTREAM_PROXY", ""),
+ "user" : proxy_settings.get("UPSTREAM_USER", ""),
+ "pass" : proxy_settings.get("UPSTREAM_PASSWORD", ""),
+ }
+
def send_profile(profile):
logging.debug("Sending profile:")
for line in json.dumps(profile, sort_keys=True, indent=4).splitlines():
logging.debug(line)
+ request = urllib2.Request(PROFILE_URL % profile,
+ data = urllib.urlencode({"profile" : json.dumps(profile)}),
+ )
+
+ # 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")
+
try:
- request = urllib2.Request(PROFILE_URL % profile,
- data = urllib.urlencode({"profile" : json.dumps(profile)}),
- )
urllib2.urlopen(request, timeout=60)
except (urllib2.HTTPError, urllib2.URLError), e:
reason = "Unknown reason"