Allow to disable ip check & define trusted subnets
Will need manually editing config.yaml for the time being. Someone who is not able to edit a yaml file should not be able to disable the warning.
This commit is contained in:
1 parent
286376321c
commit
a929100889
4 files changed
+25
-6
No files matched your search
@@ -216,7 +216,9 @@ def login():
|
||||
identity_changed.send(current_app._get_current_object(), identity=Identity(user.get_id()))
|
||||
|
||||
response = user.asDict()
|
||||
response["_is_external_client"] = not util_net.is_lan_address(get_remote_address(request))
|
||||
response["_is_external_client"] = s().getBoolean(["server", "ipCheck", "enabled"]) \
|
||||
and not util_net.is_lan_address(get_remote_address(request),
|
||||
additional_private=s().get(["server", "ipCheck", "trustedSubnets"]))
|
||||
return jsonify(response)
|
||||
|
||||
return make_response(("User unknown or password incorrect", 401, []))
|
||||
|
||||
@@ -516,6 +516,8 @@ def passive_login():
|
||||
user = flask_login.current_user
|
||||
|
||||
remoteAddr = get_remote_address(flask.request)
|
||||
ipCheckEnabled = settings().getBoolean(["server", "ipCheck", "enabled"])
|
||||
ipCheckTrusted = settings().get(["server", "ipCheck", "trustedSubnets"])
|
||||
|
||||
if user is not None and not user.is_anonymous() and user.is_active():
|
||||
flask_principal.identity_changed.send(flask.current_app._get_current_object(),
|
||||
@@ -525,7 +527,8 @@ def passive_login():
|
||||
flask.g.user = user
|
||||
|
||||
response = user.asDict()
|
||||
response["_is_external_client"] = not is_lan_address(remoteAddr)
|
||||
response["_is_external_client"] = ipCheckEnabled and not is_lan_address(remoteAddr,
|
||||
additional_private=ipCheckTrusted)
|
||||
return flask.jsonify(response)
|
||||
|
||||
elif settings().getBoolean(["accessControl", "autologinLocal"]) \
|
||||
@@ -549,7 +552,8 @@ def passive_login():
|
||||
identity=flask_principal.Identity(user.get_id()))
|
||||
|
||||
response = user.asDict()
|
||||
response["_is_external_client"] = not is_lan_address(remoteAddr)
|
||||
response["_is_external_client"] = ipCheckEnabled and not is_lan_address(remoteAddr,
|
||||
additional_private=ipCheckTrusted)
|
||||
return flask.jsonify(response)
|
||||
except:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -198,6 +198,10 @@ default_settings = {
|
||||
"preemptiveCache": {
|
||||
"exceptions": [],
|
||||
"until": 7
|
||||
},
|
||||
"ipCheck": {
|
||||
"enabled": True,
|
||||
"trustedSubnets": []
|
||||
}
|
||||
},
|
||||
"webcam": {
|
||||
|
||||
@@ -22,15 +22,24 @@ else:
|
||||
# Whatever we are running on here, it we don't want to use V6 on here due to lack of dual stack support
|
||||
HAS_V6 = False
|
||||
|
||||
def is_lan_address(address):
|
||||
def is_lan_address(address, additional_private=None):
|
||||
import netaddr
|
||||
import netifaces
|
||||
|
||||
ip = netaddr.IPAddress(address)
|
||||
if ip.is_private():
|
||||
if ip.is_private() or ip.is_loopback():
|
||||
return True
|
||||
|
||||
if additional_private is None or not isinstance(additional_private, (list, tuple)):
|
||||
additional_private = []
|
||||
|
||||
subnets = netaddr.IPSet()
|
||||
for additional in additional_private:
|
||||
try:
|
||||
subnets.add(netaddr.IPNetwork(additional))
|
||||
except:
|
||||
pass
|
||||
|
||||
for interface in netifaces.interfaces():
|
||||
addrs = netifaces.ifaddresses(interface)
|
||||
for v4 in addrs.get(socket.AF_INET, ()):
|
||||
@@ -42,7 +51,7 @@ def is_lan_address(address):
|
||||
if HAS_V6:
|
||||
for v6 in addrs.get(socket.AF_INET6, ()):
|
||||
try:
|
||||
subnets.add(netaddr.IPNetwork(v6["addr"], v6["addr"]))
|
||||
subnets.add(netaddr.IPNetwork(v6["addr"], v6["netmask"]))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user