示例#1
0
def test_override_remote_addr():
    original = core.get_remote_addr()

    with core.override_remote_addr('some other value'):
        assert core.get_remote_addr() == 'some other value'

    assert core.get_remote_addr() == original
示例#2
0
    def from_post(
        cls,
        chunks,
        *,
        filename,
        size,
        user,
        source,
        channel,
        addon=None,
        version=None,
    ):
        max_ip_length = cls._meta.get_field('ip_address').max_length
        ip_address = (core.get_remote_addr() or '')[:max_ip_length]
        upload = FileUpload(
            addon=addon,
            user=user,
            source=source,
            automated_signing=channel == amo.RELEASE_CHANNEL_UNLISTED,
            ip_address=ip_address,
            version=version,
        )
        upload.add_file(chunks, filename, size)

        # The following log statement is used by foxsec-pipeline.
        log.info('FileUpload created: %s' % upload.uuid.hex)

        return upload
示例#3
0
    def log_login_attempt(self, successful):
        """Log a user's login attempt"""
        self.last_login_attempt = datetime.now()
        self.last_login_attempt_ip = core.get_remote_addr()

        if successful:
            log.debug(u"User (%s) logged in successfully" % self)
            self.failed_login_attempts = 0
            self.last_login_ip = core.get_remote_addr()
        else:
            log.debug(u"User (%s) failed to log in" % self)
            if self.failed_login_attempts < 16777216:
                self.failed_login_attempts += 1

        self.save(update_fields=['last_login_ip', 'last_login_attempt',
                                 'last_login_attempt_ip',
                                 'failed_login_attempts'])
示例#4
0
 def process(self, msg, kwargs):
     kwargs.setdefault('extra', {}).update({
         'REMOTE_ADDR':
         core.get_remote_addr() or '',
         'USERNAME':
         getattr(core.get_user(), 'username', None) or '<anon>',
     })
     return msg, kwargs
示例#5
0
文件: models.py 项目: Osmose/olympia
    def log_login_attempt(self, successful):
        """Log a user's login attempt"""
        self.last_login_attempt = datetime.now()
        self.last_login_attempt_ip = core.get_remote_addr()

        if successful:
            log.debug(u"User (%s) logged in successfully" % self)
            self.failed_login_attempts = 0
            self.last_login_ip = core.get_remote_addr()
        else:
            log.debug(u"User (%s) failed to log in" % self)
            if self.failed_login_attempts < 16777216:
                self.failed_login_attempts += 1

        self.save(update_fields=['last_login_ip', 'last_login_attempt',
                                 'last_login_attempt_ip',
                                 'failed_login_attempts'])
示例#6
0
    def from_post(cls, chunks, filename, size, **params):
        max_ip_length = cls._meta.get_field('ip_address').max_length
        params['ip_address'] = (core.get_remote_addr() or '')[:max_ip_length]
        if 'channel' in params:
            params['automated_signing'] = (
                params.pop('channel') == amo.RELEASE_CHANNEL_UNLISTED)
        upload = FileUpload(**params)
        upload.add_file(chunks, filename, size)

        # The following log statement is used by foxsec-pipeline.
        log.info('FileUpload created: %s' % upload.uuid.hex)

        return upload
示例#7
0
 def user_logged_in(sender, request, user, **kwargs):
     """Log when a user logs in and records its IP address."""
     log.debug(u'User (%s) logged in successfully' % user,
               extra={'email': user.email})
     user.update(last_login_ip=core.get_remote_addr() or '')
示例#8
0
    def create(cls, action, *args, **kw):
        """
        e.g. ActivityLog.create(amo.LOG.CREATE_ADDON, addon),
             ActivityLog.create(amo.LOG.ADD_FILE_TO_VERSION, file, version)
        In case of circular import you can use `olympia.activity.log_create()`
        """
        from olympia import core

        user = kw.get('user', core.get_user())

        if not user:
            log.warning('Activity log called with no user: %s' % action.id)
            return

        # We make sure that we take the timestamp if provided, instead of
        # creating a new one, especially useful for log entries created
        # in a loop.
        al = ActivityLog(user=user,
                         action=action.id,
                         created=kw.get('created', timezone.now()))
        al.set_arguments(args)
        if 'details' in kw:
            al.details = kw['details']
        al.save()

        if 'details' in kw and 'comments' in al.details:
            CommentLog.objects.create(
                comments=al.details['comments'],
                activity_log=al,
                created=kw.get('created', timezone.now()),
            )

        for arg in args:
            if isinstance(arg, tuple):
                class_ = arg[0]
                id_ = arg[1]
            else:
                class_ = arg.__class__
                id_ = arg.id if isinstance(arg, ModelBase) else None

            if class_ == Addon:
                AddonLog.objects.create(
                    addon_id=id_,
                    activity_log=al,
                    created=kw.get('created', timezone.now()),
                )
            elif class_ == Version:
                VersionLog.objects.create(
                    version_id=id_,
                    activity_log=al,
                    created=kw.get('created', timezone.now()),
                )
            elif class_ == UserProfile:
                UserLog.objects.create(
                    user_id=id_,
                    activity_log=al,
                    created=kw.get('created', timezone.now()),
                )
            elif class_ == Group:
                GroupLog.objects.create(
                    group_id=id_,
                    activity_log=al,
                    created=kw.get('created', timezone.now()),
                )
            elif class_ == Block:
                BlockLog.objects.create(
                    block_id=id_,
                    activity_log=al,
                    guid=arg.guid,
                    created=kw.get('created', timezone.now()),
                )

        if getattr(action, 'store_ip', False):
            # Index specific actions by their IP address. Note that the caller
            # must take care of overriding remote addr if the action is created
            # from a task.
            IPLog.objects.create(
                ip_address=core.get_remote_addr(),
                activity_log=al,
                created=kw.get('created', timezone.now()),
            )

        # Index by every user
        UserLog.objects.create(activity_log=al,
                               user=user,
                               created=kw.get('created', timezone.now()))
        return al
示例#9
0
文件: models.py 项目: diox/olympia
 def user_logged_in(sender, request, user, **kwargs):
     """Log when a user logs in and records its IP address."""
     log.debug(u'User (%s) logged in successfully' % user)
     user.update(last_login_ip=core.get_remote_addr() or '')
示例#10
0
 def user_logged_in(sender, request, user, **kwargs):
     """Log when a user logs in and records its IP address."""
     # The following log statement is used by foxsec-pipeline.
     log.info('User (%s) logged in successfully' % user,
              extra={'email': user.email})
     user.update(last_login_ip=core.get_remote_addr() or '')
示例#11
0
 def process(self, msg, kwargs):
     kwargs['extra'] = {
         'REMOTE_ADDR': core.get_remote_addr() or '',
         'USERNAME': getattr(core.get_user(), 'username', None) or '<anon>'
     }
     return msg, kwargs
示例#12
0
文件: logger.py 项目: Osmose/olympia
 def process(self, msg, kwargs):
     kwargs['extra'] = {
         'REMOTE_ADDR': core.get_remote_addr() or '',
         'USERNAME': getattr(core.get_user(), 'username', None) or '<anon>'
     }
     return msg, kwargs