Commit 4f2fc667 authored by Johannes Schilling's avatar Johannes Schilling
Browse files

util/web: find whether remote addr is internal

parent 8d99888a
......@@ -9,6 +9,7 @@ from werkzeug.routing import Map, Rule
from werkzeug.exceptions import BadRequest
import os
import netaddr
import util.gitVersion
import util.univis
......@@ -66,6 +67,7 @@ def update_meta_from_request(metadata, form):
if metadata['name'] == u'':
metadata['name'] = None
metadata['comment'] = form.get('comment')
if metadata['comment'] == u'' or not 'keeptext' in form:
metadata['comment'] = None
......@@ -99,6 +101,21 @@ class ThemeSupportTemplateLoader(BaseLoader):
except TemplateNotFound:
return self.default_loader.get_source(environment, template)
def get_remote_addr(request):
try:
return request.environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip()
except KeyError:
return request.environ['REMOTE_ADDR']
def remote_is_internal_network(request):
remote_addr = netaddr.IPAddress(get_remote_addr(request))
for net in config.local_networks:
if remote_addr in netaddr.IPNetwork(net):
return True
return False
available_themes = [it[1] for it in config.themes_by_url]
jinja_env = Environment(loader=ThemeSupportTemplateLoader(available_themes), cache_size=0)
jinja_env.globals['url_for'] = url_for
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment