]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Transition to new library for finding IPs from the Django request
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Thu, 11 May 2023 15:58:32 +0000 (08:58 -0700)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Thu, 11 May 2023 20:51:04 +0000 (13:51 -0700)
Pipfile
Pipfile.lock
src/paperless/signals.py

diff --git a/Pipfile b/Pipfile
index f9d40625a0a63174e8735d9c2b9285493f0213af..7707a8cdd3319bd50d39c826bf3ce4b558cac6d6 100644 (file)
--- a/Pipfile
+++ b/Pipfile
@@ -21,7 +21,6 @@ django-extensions = "*"
 django-filter = "~=22.1"
 djangorestframework = "~=3.14"
 djangorestframework-guardian = "*"
-django-ipware = "*"
 filelock = "*"
 gunicorn = "*"
 imap-tools = "*"
@@ -33,6 +32,7 @@ python-gnupg = "*"
 python-dotenv = "*"
 python-dateutil = "*"
 python-magic = "*"
+python-ipware = "*"
 psycopg2 = "*"
 rapidfuzz = "*"
 redis = {extras = ["hiredis"], version = "*"}
@@ -51,7 +51,6 @@ channels = "~=3.0"
 channels-redis = "*"
 uvicorn = {extras = ["standard"], version = "*"}
 concurrent-log-handler = "*"
-
 pyzbar = "*"
 mysqlclient = "*"
 celery = {extras = ["redis"], version = "*"}
index 02ca702835e42052ff860872cad0577adeac1ff4..47bd4364e368540b752e868a20aba0afa03ebf32 100644 (file)
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "8fecf74dce093fa66c1027ae9230da1afb1c61d80eab7264823884e005e7284b"
+            "sha256": "6aeae592dcf1d7737a6cb6886db1ff7387a9daf3796f782531d25f2e22d608d9"
         },
         "pipfile-spec": 6,
         "requires": {},
             "index": "pypi",
             "version": "==2.4.0"
         },
-        "django-ipware": {
-            "hashes": [
-                "sha256:4fa5607ee85e12ee5e158bc7569ff1e134fb1579681aa1ff3f0ed04be21be153",
-                "sha256:80b52a3f571a371519cc552798f1015b934dd5dd7738bfad87e101e861bd21b8"
-            ],
-            "index": "pypi",
-            "version": "==5.0.0"
-        },
         "djangorestframework": {
             "hashes": [
                 "sha256:579a333e6256b09489cbe0a067e66abe55c6595d8926be6b99423786334350c8",
             "index": "pypi",
             "version": "==0.5.0"
         },
+        "python-ipware": {
+            "hashes": [
+                "sha256:01b9fa589521c29d7573f69fc4855c6b95687f0029601b78fffef1eb17f1de27",
+                "sha256:ee84cd16c2cf862faae197ad5f8fae6c75e4b1f40bb13357944a5d63ddc2a373"
+            ],
+            "index": "pypi",
+            "version": "==0.9.0"
+        },
         "python-magic": {
             "hashes": [
                 "sha256:c1ba14b08e4a5f5c31a302b7721239695b2f0f058d125bd5ce1ee36b9d9d3c3b",
index 40e2682ddea6383b9481578a67682861affd6b3a..83ba741930c1199992f9a70dc9683e87c6a80bf1 100644 (file)
@@ -1,24 +1,25 @@
 import logging
 
 from django.conf import settings
-from ipware import get_client_ip
+from ipware import IpWare
 
 logger = logging.getLogger("paperless.auth")
 
 
 # https://docs.djangoproject.com/en/4.1/ref/contrib/auth/#django.contrib.auth.signals.user_login_failed
 def handle_failed_login(sender, credentials, request, **kwargs):
-    client_ip, is_routable = get_client_ip(
-        request,
-        proxy_trusted_ips=settings.TRUSTED_PROXIES,
+    ipware = IpWare(proxy_trusted_list=settings.TRUSTED_PROXIES)
+    client_ip, _ = ipware.get_client_ip(
+        meta=request.META,
     )
+
     if client_ip is None:
         logger.info(
             f"Login failed for user `{credentials['username']}`."
             " Unable to determine IP address.",
         )
     else:
-        if is_routable:
+        if client_ip.is_global:
             # We got the client's IP address
             logger.info(
                 f"Login failed for user `{credentials['username']}`"