Giter VIP home page Giter VIP logo

django-blacklist's People

Contributors

richardarpanet avatar vsemionov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-blacklist's Issues

AttributeError 'str' object has no attribute 'tzinfo'

Hello
I have error after adding one rule
id 1
created 2021-03-31 21:56:33.792587
updated 2021-03-31 22:31:44.223164
address 196.245.0.0
prefix 16
duration 7900000000
user_id NULL

python3.8/site-packages/blacklist/middleware.py in _load_blacklist
for rule in rules:

Variable | Value
addr_blacklist | {}
current_time | datetime.datetime(2021, 3, 31, 22, 32, 57, 493809, tzinfo=)
rules | Error in formatting: AttributeError: 'str' object has no attribute 'tzinfo'
until | Max(F(created) + F(duration))
user_blacklist | {}

Can you help me?

AttributeError Format for duration arithmetic

Error:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/

Django Version: 3.0.4
Python Version: 3.7.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_countries',
 'languages',
 'blacklist',
 'taggit',
 'user',
 'model',
 'administrator']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'blacklist.middleware.blacklist_middleware']



Traceback (most recent call last):
  File "D:\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\anaconda3\lib\site-packages\blacklist\middleware.py", line 40, in middleware
    _load_blacklist()
  File "D:\anaconda3\lib\site-packages\blacklist\middleware.py", line 98, in _load_blacklist
    for rule in rules:
  File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 276, in __iter__
    self._fetch_all()
  File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "D:\anaconda3\lib\site-packages\django\db\models\query.py", line 115, in __iter__
    for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1103, in results_iter
    results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1138, in execute_sql
    sql, params = self.as_sql()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 490, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 257, in get_select
    sql, params = self.compile(col)
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
    sql, params = node.as_sql(self, self.connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\aggregates.py", line 88, in as_sql
    return super().as_sql(compiler, connection, **extra_context)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 633, in as_sql
    arg_sql, arg_params = compiler.compile(arg)
  File "D:\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 422, in compile
    sql, params = node.as_sql(self, self.connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 448, in as_sql
    return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 494, in as_sql
    sql, params = self.compile(self.rhs, compiler, connection)
  File "D:\anaconda3\lib\site-packages\django\db\models\expressions.py", line 484, in compile
    return connection.ops.format_for_duration_arithmetic(sql), params

Exception Type: AttributeError at /admin/
Exception Value: 'DatabaseOperations' object has no attribute 'format_for_duration_arithmetic'

Perhaps of note: I am using djongo

Support for Custom User

When I try to run the migration I get:

blacklist.Rule.user: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
        HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.

My settings.AUTH_USER_MODEL:
`AUTH_USER_MODEL = 'users.CustomUser' # Custom User Model

line 15 in blacklist/models.py needs updated to:
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)

And from django.conf import settings needs added to imports.

I can do a PR if you prefer.

Access is denied to all users.

In the production environment, the guest user's IP address is detected as 127.0.0.1.
Therefore, access to the site is closed to all users. How can I block the guest user's IP address?

image

Disabling Logging

Hello, thanks for your work on the plugin! Would it be possible to add in a setting variable to disable logging? When blacklisted IPs hit our endpoints repeatedly it leads to some spam in our logs. It would be great if we could just reject ip's silently. Thanks very much,
Steve

Adding setting that allows to override the header name that contains the real IP address

Hi there,

thanks a lot for this plugin! It has helped me a lot recently to reduce spam on my blog.

I'm hosting my app on Pythonanywhere. The issue is that they're changing the header of the requests slightly, so the real IP address of the client ends up under a different key, i.e. request.META.get('HTTP_X_REAL_IP'), see their docs.

I was thinking about adding a setting, e.g. BLACKLIST_REMOTE_ADDR, that would allow you to override the default header name (defaults to "REMOTE_ADDR"). Would you be happy to review a PR? Many thanks!

Adding proxy

Hi,

Can you describe with more detail, how to I pass the proxy server and add clients ip, not proxy ip?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.