import dateutil.parser
import httplib
import ipaddr
+import logging
import time
import tornado.locale
import tornado.web
def get_user_locale(self):
# The planet is always in english.
- if self.request.host == "planet.ipfire.org":
+ if self.hostname == "planet.ipfire.org":
return tornado.locale.get("en_US")
# Otherwise take the browser locale.
return self.get_browser_locale()
+ @property
+ def hostname(self):
+ # Remove the development prefix
+ return self.request.host.replace(".dev.", ".")
+
+ @property
+ def ssl_params(self):
+ return {
+ "ssl_cipher" : self.request.headers.get("X-Https-Cipher", None),
+ "ssl_protocol" : self.request.headers.get("X-Https-Protocol", None),
+ }
+
@property
def render_args(self):
today = datetime.date.today()
- # Get the requested host and remove the development prefix
- hostname = self.request.host.replace(".dev.", ".")
-
- return {
+ ret = {
"format_size" : backend.util.format_size,
"format_time" : backend.util.format_time,
- "hostname" : hostname,
+ "hostname" : self.hostname,
"lang" : self.locale.code[:2],
"rss_url" : self.rss_url,
"year" : today.year,
}
+ ret.update(self.ssl_params)
+
+ return ret
def render(self, *args, **_kwargs):
kwargs = self.render_args
if self.settings.get("debug", False):
return ret
- elif self.request.host == "admin.ipfire.org":
- return ret
-
- elif static:
- return "http://static.ipfire.org%s" % ret
+ if static:
+ return "//static.ipfire.org%s" % ret
return ret
def get_remote_ip(self):
# Fix for clients behind a proxy that sends "X-Forwarded-For".
remote_ips = self.request.remote_ip.split(", ")
+
for remote_ip in remote_ips:
try:
addr = ipaddr.IPAddress(remote_ip)
return remote_ip
+ # Return the last IP if nothing else worked
+ return remote_ips.pop()
+
def get_remote_location(self):
if not hasattr(self, "__remote_location"):
remote_ip = self.get_remote_ip()