从 django 服务器获取用户的 UUID

发布于 2025-01-09 01:48:41 字数 1448 浏览 0 评论 0原文

我有一个带有管理面板的 Django 服务器。
不同的用户在那里进行更改,这些更改通过数据库中的审核日志保存并显示在“历史记录”中。
但在某些情况下,用户会进入另一个用户的帐户并代表他进行更改。
为了确定这个或那个更改是在哪个设备上进行的,最好还记录有关进行更改的用户的 IP 及其唯一设备编号的数据。
通过重载“AuditlogMiddleware”类中的几个方法,我通过“uuid.UUID(int=uuid.getnode())”获得了所需的结果。
(在本地测试,因为产品服务器负载很重,无法进行测试委员会)

from __future__ import unicode_literals

import threading
import time

from auditlog.middleware import AuditlogMiddleware


threadlocal = threading.local()


class ExtendedAuditlogMiddleware(AuditlogMiddleware):

    def process_request(self, request):
        threadlocal.auditlog = {
            'signal_duid': (self.__class__, time.time()),
            'remote_addr': request.META.get('REMOTE_ADDR'),
        }
        super(ExtendedAuditlogMiddleware, self).process_request(request)

        **#changes here
        import uuid
        threadlocal.auditlog['additional_data'] = str(uuid.UUID(int=uuid.getnode()))+" | "+request.META["USERNAME"]**

    # @staticmethod
    def set_actor(self, user, sender, instance, signal_duid, **kwargs):
        super(ExtendedAuditlogMiddleware, self).set_actor(user, sender, instance, signal_duid, **kwargs)
        
        **#changes here
        instance.additional_data = threadlocal.auditlog['additional_data']**

但问题是我认为我得到的UUID不是用户的,而是服务器的,因为无法访问用户,我猜。我找不到相关信息,也无法提出自己的解决方案。
问题 - 是否可以从服务器获取有关 django 管理员用户设备的信息?
如果没有,我可以使用什么来代替 UUID 来识别在 django 管理面板中进行更改时使用的设备?
提前谢谢大家!

I have a django server with an admin panel.
Different users make changes there and this is saved via auditlog in the database and displayed in the "history".
But there are situations when a user enters under the account of another user and makes changes on his behalf.
In order to identify from which device this or that change was made, it was a nice decision to also record data about the IP of the user from whom the change was made, and his unique device number.
By overloading several methods in the "AuditlogMiddleware" class, I got the desired result via "uuid.UUID(int=uuid.getnode())".
(Tested locally, because the prod server is heavily loaded and there is no way to do test committees)

from __future__ import unicode_literals

import threading
import time

from auditlog.middleware import AuditlogMiddleware


threadlocal = threading.local()


class ExtendedAuditlogMiddleware(AuditlogMiddleware):

    def process_request(self, request):
        threadlocal.auditlog = {
            'signal_duid': (self.__class__, time.time()),
            'remote_addr': request.META.get('REMOTE_ADDR'),
        }
        super(ExtendedAuditlogMiddleware, self).process_request(request)

        **#changes here
        import uuid
        threadlocal.auditlog['additional_data'] = str(uuid.UUID(int=uuid.getnode()))+" | "+request.META["USERNAME"]**

    # @staticmethod
    def set_actor(self, user, sender, instance, signal_duid, **kwargs):
        super(ExtendedAuditlogMiddleware, self).set_actor(user, sender, instance, signal_duid, **kwargs)
        
        **#changes here
        instance.additional_data = threadlocal.auditlog['additional_data']**

But the problem is that I think I get the UUID not of the user, but of the server, because there is no access to the user, i guess. I couldn't find the information, and I couldn't come up with my own solution either.
Question - is it even possible to get information from the server about django admin users' devices??
If not, what can i use instead of UUID to identify which device was used while making changes in django admin panel??
Thank you all in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

跨年 2025-01-16 01:48:41

尝试在模板中使用 javascript 来发送此信息

try to use javascript in side of your template to send this info thrugh

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文