##// END OF EJS Templates
Added ban reasons. Added write-only bans.
neko259 -
r340:1472a0a6 default
parent child Browse files
Show More
@@ -11,7 +11,9 b' class BanMiddleware:'
11
11
12 if view_func != views.you_are_banned:
12 if view_func != views.you_are_banned:
13 ip = utils.get_client_ip(request)
13 ip = utils.get_client_ip(request)
14 is_banned = Ban.objects.filter(ip=ip).exists()
14 bans = Ban.objects.filter(ip=ip)
15
15
16 if is_banned:
16 if bans.exists():
17 return redirect(views.you_are_banned) No newline at end of file
17 ban = bans[0]
18 if not ban.can_read:
19 return redirect(views.you_are_banned) No newline at end of file
@@ -16,6 +16,10 b' import thumbs'
16
16
17 import re
17 import re
18
18
19 BAN_REASON_MAX_LENGTH = 200
20
21 BAN_REASON_AUTO = 'Auto'
22
19 IMAGE_THUMB_SIZE = (200, 150)
23 IMAGE_THUMB_SIZE = (200, 150)
20
24
21 TITLE_MAX_LENGTH = 50
25 TITLE_MAX_LENGTH = 50
@@ -416,6 +420,9 b' class Setting(models.Model):'
416 class Ban(models.Model):
420 class Ban(models.Model):
417
421
418 ip = models.GenericIPAddressField()
422 ip = models.GenericIPAddressField()
423 reason = models.CharField(default=BAN_REASON_AUTO,
424 max_length=BAN_REASON_MAX_LENGTH)
425 can_read = models.BooleanField(default=True)
419
426
420 def __unicode__(self):
427 def __unicode__(self):
421 return self.ip
428 return self.ip
@@ -34,7 +34,7 b''
34 <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a>
34 <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a>
35 {% for tag in tags %}
35 {% for tag in tags %}
36 <a class="tag" href="{% url 'tag' tag_name=tag.name %}"
36 <a class="tag" href="{% url 'tag' tag_name=tag.name %}"
37 >#{{ tag.name }}</a>
37 >#{{ tag.name }}</a>,
38 {% endfor %}
38 {% endfor %}
39 <a class="tag" href="{% url 'tags' %}" title="{% trans 'Tag management' %}"
39 <a class="tag" href="{% url 'tags' %}" title="{% trans 'Tag management' %}"
40 >[...]</a>
40 >[...]</a>
@@ -91,7 +91,8 b''
91 {% for tag in thread.thread.get_tags %}
91 {% for tag in thread.thread.get_tags %}
92 <a class="tag" href="
92 <a class="tag" href="
93 {% url 'tag' tag_name=tag.name %}">
93 {% url 'tag' tag_name=tag.name %}">
94 #{{ tag.name }}</a>
94 #{{ tag.name }}</a
95 >{% if not forloop.last %},{% endif %}
95 {% endfor %}
96 {% endfor %}
96 </span>
97 </span>
97 {% endif %}
98 {% endif %}
@@ -9,4 +9,5 b''
9 {% block staticcontent %}
9 {% block staticcontent %}
10 <p><img src="{{ STATIC_URL }}images/banned.png" width="200" /></p>
10 <p><img src="{{ STATIC_URL }}images/banned.png" width="200" /></p>
11 <p>{% trans 'Your IP address has been banned. Contact the administrator' %}</p>
11 <p>{% trans 'Your IP address has been banned. Contact the administrator' %}</p>
12 <p>{{ ban_reason }}</p>
12 {% endblock %} No newline at end of file
13 {% endblock %}
@@ -76,12 +76,13 b''
76 </div>
76 </div>
77 {% endif %}
77 {% endif %}
78 </div>
78 </div>
79 {% if post.id == posts.0.id %}
79 {% if forloop.first %}
80 <div class="metadata">
80 <div class="metadata">
81 <span class="tags">
81 <span class="tags">
82 {% for tag in post.get_tags %}
82 {% for tag in post.get_tags %}
83 <a class="tag" href="{% url 'tag' tag.name %}">
83 <a class="tag" href="{% url 'tag' tag.name %}">
84 #{{ tag.name }}</a>
84 #{{ tag.name }}</a
85 >{% if not forloop.last %},{% endif %}
85 {% endfor %}
86 {% endfor %}
86 </span>
87 </span>
87 </div>
88 </div>
@@ -22,6 +22,8 b' from boards.utils import get_client_ip'
22 import neboard
22 import neboard
23 import re
23 import re
24
24
25 BAN_REASON_SPAM = 'Autoban: spam bot'
26
25
27
26 def index(request, page=0):
28 def index(request, page=0):
27 context = _init_default_context(request)
29 context = _init_default_context(request)
@@ -317,7 +319,10 b' def ban(request, post_id):'
317
319
318 if user.is_moderator():
320 if user.is_moderator():
319 # TODO Show confirmation page before ban
321 # TODO Show confirmation page before ban
320 Ban.objects.get_or_create(ip=post.poster_ip)
322 ban, created = Ban.objects.get_or_create(ip=post.poster_ip)
323 if created:
324 ban.reason = 'Banned for post ' + str(post_id)
325 ban.save()
321
326
322 return _redirect_to_next(request)
327 return _redirect_to_next(request)
323
328
@@ -326,6 +331,9 b' def you_are_banned(request):'
326 """Show the page that notifies that user is banned"""
331 """Show the page that notifies that user is banned"""
327
332
328 context = _init_default_context(request)
333 context = _init_default_context(request)
334
335 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
336 context['ban_reason'] = ban.reason
329 return render(request, 'boards/staticpages/banned.html', context)
337 return render(request, 'boards/staticpages/banned.html', context)
330
338
331
339
@@ -470,11 +478,16 b' def _redirect_to_next(request):'
470 return redirect(index)
478 return redirect(index)
471
479
472
480
481 @transaction.commit_on_success
473 def _ban_current_user(request):
482 def _ban_current_user(request):
474 """Add current user to the IP ban list"""
483 """Add current user to the IP ban list"""
475
484
476 ip = utils.get_client_ip(request)
485 ip = utils.get_client_ip(request)
477 Ban.objects.get_or_create(ip=ip)
486 ban, created = Ban.objects.get_or_create(ip=ip)
487 if created:
488 ban.can_read = False
489 ban.reason = BAN_REASON_SPAM
490 ban.save()
478
491
479
492
480 def _remove_invalid_links(text):
493 def _remove_invalid_links(text):
@@ -4,6 +4,8 b''
4 [DONE] Better django admin pages to simplify admin operations
4 [DONE] Better django admin pages to simplify admin operations
5 [DONE] Regen script to update all posts
5 [DONE] Regen script to update all posts
6 [DONE] Remove jump links from refmaps
6 [DONE] Remove jump links from refmaps
7 [DONE] Ban reasons. Split bans into 2 types "read-only" and "read
8 denied". Use second only for autoban for spam
7
9
8 [NOT STARTED] Tree view (JS)
10 [NOT STARTED] Tree view (JS)
9 [NOT STARTED] Adding tags to images filename
11 [NOT STARTED] Adding tags to images filename
@@ -20,8 +22,6 b''
20 [NOT STARTED] Clean up tests and make them run ALWAYS
22 [NOT STARTED] Clean up tests and make them run ALWAYS
21 [NOT STARTED] Save image thumbnails size to the separate field
23 [NOT STARTED] Save image thumbnails size to the separate field
22 [NOT STARTED] Whitelist functionality. Permin autoban of an address
24 [NOT STARTED] Whitelist functionality. Permin autoban of an address
23 [NOT STARTED] Ban reasons. Split bans into 2 types "read-only" and "read
24 denied". Use second only for autoban for spam
25
25
26 = Bugs =
26 = Bugs =
27 [DONE] Fix bug with creating threads from tag view
27 [DONE] Fix bug with creating threads from tag view
General Comments 0
You need to be logged in to leave comments. Login now