diff --git a/boards/config/default_settings.ini b/boards/config/default_settings.ini --- a/boards/config/default_settings.ini +++ b/boards/config/default_settings.ini @@ -17,6 +17,7 @@ LimitPostingSpeed = false MaxPostsPerThread = 10 # Old posts will be archived or deleted if this value is reached MaxThreadCount = 5 +AnonymousMode = false [View] DefaultTheme = md diff --git a/boards/models/post/manager.py b/boards/models/post/manager.py --- a/boards/models/post/manager.py +++ b/boards/models/post/manager.py @@ -35,7 +35,8 @@ class PostManager(models.Manager): Creates new post """ - is_banned = Ban.objects.filter(ip=ip).exists() + if not utils.is_anonymous_mode(): + is_banned = Ban.objects.filter(ip=ip).exists() # TODO Raise specific exception and catch it in the views if is_banned: diff --git a/boards/utils.py b/boards/utils.py --- a/boards/utils.py +++ b/boards/utils.py @@ -11,7 +11,9 @@ from django import forms from django.utils import timezone from django.utils.translation import ugettext_lazy as _ + import boards +from boards.settings import get_bool from neboard import settings @@ -19,12 +21,28 @@ from neboard import settings CACHE_KEY_DELIMITER = '_' PERMISSION_MODERATE = 'moderation' +HTTP_FORWARDED = 'HTTP_X_FORWARDED_FOR' +META_REMOTE_ADDR = 'REMOTE_ADDR' + +SETTING_MESSAGES = 'Messages' +SETTING_ANON_MODE = 'AnonymousMode' + +ANON_IP = '127.0.0.1' + + +def is_anonymous_mode(): + return get_bool(SETTING_MESSAGES, SETTING_ANON_MODE) + + def get_client_ip(request): - x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') - if x_forwarded_for: - ip = x_forwarded_for.split(',')[-1].strip() + if is_anonymous_mode(): + ip = ANON_IP else: - ip = request.META.get('REMOTE_ADDR') + x_forwarded_for = request.META.get(HTTP_FORWARDED) + if x_forwarded_for: + ip = x_forwarded_for.split(',')[-1].strip() + else: + ip = request.META.get(META_REMOTE_ADDR) return ip