Show More
@@ -0,0 +1,17 b'' | |||
|
1 | from django.shortcuts import redirect | |
|
2 | from boards import views, utils | |
|
3 | from boards.models import Ban | |
|
4 | ||
|
5 | ||
|
6 | class BanMiddleware: | |
|
7 | """This is run before showing the thread. Banned users don't need to see | |
|
8 | anything""" | |
|
9 | ||
|
10 | def process_view(self, request, view_func, view_args, view_kwargs): | |
|
11 | ||
|
12 | if view_func != views.you_are_banned: | |
|
13 | ip = utils.get_client_ip(request) | |
|
14 | is_banned = Ban.objects.filter(ip=ip).exists() | |
|
15 | ||
|
16 | if is_banned: | |
|
17 | return redirect(views.you_are_banned) No newline at end of file |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | <link rel="stylesheet" type="text/css" |
|
8 | 8 | href="{{ STATIC_URL }}css/jquery.fancybox.css" media="all"/> |
|
9 | 9 | <link rel="stylesheet" type="text/css" |
|
10 |
href="{{ STATIC_URL }}css/{{ theme }}/base_page.css? |
|
|
10 | href="{{ STATIC_URL }}css/{{ theme }}/base_page.css?4" media="all"/> | |
|
11 | 11 | <link rel="alternate" type="application/rss+xml" href="rss/" title=" |
|
12 | 12 | {% trans 'Feed' %}"/> |
|
13 | 13 |
@@ -27,9 +27,9 b'' | |||
|
27 | 27 | <form method="post">{% csrf_token %} |
|
28 | 28 | {{ form.as_p }} |
|
29 | 29 | <hr /> |
|
30 | <input type="submit" value="{% trans "Save" %}" /> | |
|
30 | 31 | </form> |
|
31 | 32 | </div> |
|
32 | <input type="submit" value="{% trans "Save" %}" /> | |
|
33 | 33 | </div> |
|
34 | 34 | |
|
35 | 35 | {% endblock %} |
@@ -62,3 +62,12 b' def update_captcha_access(request, passe' | |||
|
62 | 62 | |
|
63 | 63 | session[KEY_CAPTCHA_LAST_ACTIVITY] = int(time.time()) |
|
64 | 64 | session[KEY_CAPTCHA_DELAY_TIME] = delay_time |
|
65 | ||
|
66 | ||
|
67 | def get_client_ip(request): | |
|
68 | x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
|
69 | if x_forwarded_for: | |
|
70 | ip = x_forwarded_for.split(',')[-1].strip() | |
|
71 | else: | |
|
72 | ip = request.META.get('REMOTE_ADDR') | |
|
73 | return ip No newline at end of file |
@@ -14,6 +14,7 b' from boards.forms import ThreadForm, Pos' | |||
|
14 | 14 | |
|
15 | 15 | from boards.models import Post, Tag, Ban, User, RANK_USER, SETTING_MODERATE |
|
16 | 16 | from boards import authors |
|
17 | from boards.utils import get_client_ip | |
|
17 | 18 | import neboard |
|
18 | 19 | |
|
19 | 20 | |
@@ -53,8 +54,8 b' def index(request, page=0):' | |||
|
53 | 54 | def _new_post(request, form, thread_id=boards.models.NO_PARENT): |
|
54 | 55 | """Add a new post (in thread or as a reply).""" |
|
55 | 56 | |
|
56 |
ip = |
|
|
57 |
is_banned = Ban.objects.filter(ip=ip). |
|
|
57 | ip = get_client_ip(request) | |
|
58 | is_banned = Ban.objects.filter(ip=ip).exists() | |
|
58 | 59 | |
|
59 | 60 | if is_banned: |
|
60 | 61 | return redirect(you_are_banned) |
@@ -319,15 +320,6 b' def _get_theme(request, user=None):' | |||
|
319 | 320 | return theme |
|
320 | 321 | |
|
321 | 322 | |
|
322 | def _get_client_ip(request): | |
|
323 | x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
|
324 | if x_forwarded_for: | |
|
325 | ip = x_forwarded_for.split(',')[-1].strip() | |
|
326 | else: | |
|
327 | ip = request.META.get('REMOTE_ADDR') | |
|
328 | return ip | |
|
329 | ||
|
330 | ||
|
331 | 323 | def _init_default_context(request): |
|
332 | 324 | """Create context with default values that are used in most views""" |
|
333 | 325 |
@@ -117,7 +117,8 b' MIDDLEWARE_CLASSES = (' | |||
|
117 | 117 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
118 | 118 | 'django.contrib.messages.middleware.MessageMiddleware', |
|
119 | 119 | # Uncomment the next line for simple clickjacking protection: |
|
120 |
# 'django.middleware.clickjacking.XFrameOptionsMiddleware' |
|
|
120 | # 'django.middleware.clickjacking.XFrameOptionsMiddleware' | |
|
121 | 'boards.middlewares.BanMiddleware', | |
|
121 | 122 | ) |
|
122 | 123 | |
|
123 | 124 | ROOT_URLCONF = 'neboard.urls' |
General Comments 0
You need to be logged in to leave comments.
Login now