Commit d02be623 by Bach Dániel

firewall: Blacklist.host, ban notification added

parent 54cd2c2f
...@@ -336,8 +336,9 @@ class Record(models.Model): ...@@ -336,8 +336,9 @@ class Record(models.Model):
'address': address} 'address': address}
class Blacklist(models.Model): class Blacklist(models.Model):
CHOICES_type = (('permban', 'permanent ban'), ('tempban', 'temporary ban'), ('whitelist', 'whitelist')) CHOICES_type = (('permban', 'permanent ban'), ('tempban', 'temporary ban'), ('whitelist', 'whitelist'), ('tempwhite', 'tempwhite'))
ipv4 = models.GenericIPAddressField(protocol='ipv4', unique=True) ipv4 = models.GenericIPAddressField(protocol='ipv4', unique=True)
host = models.ForeignKey('Host', blank=True, null=True)
reason = models.TextField(blank=True) reason = models.TextField(blank=True)
snort_message = models.TextField(blank=True) snort_message = models.TextField(blank=True)
type = models.CharField(max_length=10, choices=CHOICES_type, default='tempban') type = models.CharField(max_length=10, choices=CHOICES_type, default='tempban')
......
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render_to_response
from firewall.models import * from firewall.models import *
from firewall.fw import * from firewall.fw import *
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
...@@ -9,12 +8,15 @@ from django.db import IntegrityError ...@@ -9,12 +8,15 @@ from django.db import IntegrityError
from tasks import * from tasks import *
from celery.task.control import inspect from celery.task.control import inspect
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.template.loader import render_to_string
import re import re
import base64 import base64
import json import json
import sys import sys
import datetime
from django.utils.timezone import utc
def reload_firewall(request): def reload_firewall(request):
if request.user.is_authenticated(): if request.user.is_authenticated():
...@@ -41,11 +43,27 @@ def firewall_api(request): ...@@ -41,11 +43,27 @@ def firewall_api(request):
if command == "blacklist": if command == "blacklist":
obj, created = Blacklist.objects.get_or_create(ipv4=data["ip"]) obj, created = Blacklist.objects.get_or_create(ipv4=data["ip"])
if created:
obj.reason=data["reason"] obj.reason=data["reason"]
obj.snort_message=data["snort_message"] obj.snort_message=data["snort_message"]
if created:
try:
obj.host = models.Host.objects.get(ipv4=data["ip"])
user = obj.host.owner
lang = user.person_set.all()[0].language
s = render_to_string('mails/notification-ban-now.txt', { 'user': user, 'bl': obj } )
print s
# send_mail(settings.EMAIL_SUBJECT_PREFIX + (_('New project: %s') % p.identifier), s, settings.SERVER_EMAIL, [])
except Host.DoesNotExist, ValidationError, IntegrityError, AttributeError as e:
pass
except:
raise
print "ok"
print obj.modified_at + datetime.timedelta(minutes=5)
print datetime.datetime.utcnow().replace(tzinfo=utc)
if obj.type == 'tempwhite' and obj.modified_at + datetime.timedelta(minutes=1) < datetime.datetime.utcnow().replace(tzinfo=utc):
obj.type = 'tempban'
obj.save() obj.save()
return HttpResponse(unicode(_("OK"))); return HttpResponse(unicode(_("OK")))
if not (data["vlan"] == "vm-net" or data["vlan"] == "war"): if not (data["vlan"] == "vm-net" or data["vlan"] == "war"):
raise Exception(_("Only vm-net and war can be used.")) raise Exception(_("Only vm-net and war can be used."))
......
{% load i18n %} {% load i18n %}
{% blocktrans with name=user.name %} {% blocktrans with name=user.get_full_name %}
Dear {{name}}, Dear {{name}},
{% endblocktrans %} {% endblocktrans %}
......
{% extends "mails/base.txt" %}
{% load i18n %}
{% block body %}
{% blocktrans with reason=bl.reason snort_message=bl.snort_message %}
{{reason}} {{snort_message}}
{% endblocktrans %}
{% endblock %}
{% base base.txt %} {% extends "mails/base.txt" %}
{% load i18n %} {% load i18n %}
{% block body %} {% block body %}
{% blocktrans with vm=instance.name state=instance.state date=exp %} {% blocktrans with vm=instance.name state=instance.state date=instance.time_of_delete %}
Your {{state}} virtual machine "{{vm}}" has been DELETED Your {{state}} virtual machine "{{vm}}" has been DELETED
at {{date}}. at {{date}}.
{% endblocktrans %} {% endblocktrans %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment