Commit d60bb407 by Bach Dániel

firewall: rename Blacklist to BlacklistItem

parent 442f0538
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
from django.contrib import admin from django.contrib import admin
from firewall.models import (Rule, Host, Vlan, Group, VlanGroup, Firewall, from firewall.models import (Rule, Host, Vlan, Group, VlanGroup, Firewall,
Domain, Record, Blacklist, Domain, Record, BlacklistItem,
SwitchPort, EthernetDevice) SwitchPort, EthernetDevice)
from django import contrib from django import contrib
...@@ -114,8 +114,8 @@ class RecordAdmin(admin.ModelAdmin): ...@@ -114,8 +114,8 @@ class RecordAdmin(admin.ModelAdmin):
list_display = ('name', 'type', 'address', 'ttl', 'host', 'owner') list_display = ('name', 'type', 'address', 'ttl', 'host', 'owner')
class BlacklistAdmin(admin.ModelAdmin): class BlacklistItemAdmin(admin.ModelAdmin):
list_display = ('ipv4', 'reason', 'created_at', 'modified_at') list_display = ('ipv4', 'type', 'reason', 'created_at', 'modified_at')
class SwitchPortAdmin(admin.ModelAdmin): class SwitchPortAdmin(admin.ModelAdmin):
...@@ -133,6 +133,6 @@ admin.site.register(VlanGroup) ...@@ -133,6 +133,6 @@ admin.site.register(VlanGroup)
admin.site.register(Firewall, FirewallAdmin) admin.site.register(Firewall, FirewallAdmin)
admin.site.register(Domain, DomainAdmin) admin.site.register(Domain, DomainAdmin)
admin.site.register(Record, RecordAdmin) admin.site.register(Record, RecordAdmin)
admin.site.register(Blacklist, BlacklistAdmin) admin.site.register(BlacklistItem, BlacklistItemAdmin)
admin.site.register(SwitchPort) admin.site.register(SwitchPort)
admin.site.register(EthernetDevice, EthernetDeviceAdmin) admin.site.register(EthernetDevice, EthernetDeviceAdmin)
...@@ -5,7 +5,8 @@ from netaddr import IPAddress, AddrFormatError ...@@ -5,7 +5,8 @@ from netaddr import IPAddress, AddrFormatError
from datetime import datetime, timedelta from datetime import datetime, timedelta
from itertools import product from itertools import product
from .models import (Host, Rule, Vlan, Domain, Record, Blacklist, SwitchPort) from .models import (Host, Rule, Vlan, Domain, Record, BlacklistItem,
SwitchPort)
from .iptables import IptRule, IptChain from .iptables import IptRule, IptChain
import django.conf import django.conf
from django.db.models import Q from django.db.models import Q
...@@ -136,7 +137,7 @@ def ipset(): ...@@ -136,7 +137,7 @@ def ipset():
week = datetime.now() - timedelta(days=2) week = datetime.now() - timedelta(days=2)
filter_ban = (Q(type='tempban', modified_at__gte=week) | filter_ban = (Q(type='tempban', modified_at__gte=week) |
Q(type='permban')) Q(type='permban'))
return Blacklist.objects.filter(filter_ban).values('ipv4', 'reason') return BlacklistItem.objects.filter(filter_ban).values('ipv4', 'reason')
def ipv6_to_octal(ipv6): def ipv6_to_octal(ipv6):
......
...@@ -923,7 +923,7 @@ class EthernetDevice(models.Model): ...@@ -923,7 +923,7 @@ class EthernetDevice(models.Model):
return self.name return self.name
class Blacklist(models.Model): class BlacklistItem(models.Model):
CHOICES_type = (('permban', 'permanent ban'), ('tempban', 'temporary ban'), CHOICES_type = (('permban', 'permanent ban'), ('tempban', 'temporary ban'),
('whitelist', 'whitelist'), ('tempwhite', 'tempwhite')) ('whitelist', 'whitelist'), ('tempwhite', 'tempwhite'))
ipv4 = models.GenericIPAddressField(protocol='ipv4', unique=True) ipv4 = models.GenericIPAddressField(protocol='ipv4', unique=True)
...@@ -945,7 +945,7 @@ class Blacklist(models.Model): ...@@ -945,7 +945,7 @@ class Blacklist(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.full_clean() self.full_clean()
super(Blacklist, self).save(*args, **kwargs) super(BlacklistItem, self).save(*args, **kwargs)
def __unicode__(self): def __unicode__(self):
return self.ipv4 return self.ipv4
...@@ -959,7 +959,7 @@ def send_task(sender, instance, created=False, **kwargs): ...@@ -959,7 +959,7 @@ def send_task(sender, instance, created=False, **kwargs):
reloadtask.apply_async(queue='localhost.man', args=[sender.__name__]) reloadtask.apply_async(queue='localhost.man', args=[sender.__name__])
for sender in [Host, Rule, Domain, Record, Vlan, Firewall, Group, Blacklist, for sender in [Host, Rule, Domain, Record, Vlan, Firewall, Group,
SwitchPort, EthernetDevice]: BlacklistItem, SwitchPort, EthernetDevice]:
post_save.connect(send_task, sender=sender) post_save.connect(send_task, sender=sender)
post_delete.connect(send_task, sender=sender) post_delete.connect(send_task, sender=sender)
...@@ -11,7 +11,7 @@ from django.views.decorators.csrf import csrf_exempt ...@@ -11,7 +11,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from .tasks.local_tasks import reloadtask from .tasks.local_tasks import reloadtask
from .models import Blacklist, Host from .models import BlacklistItem, Host
def reload_firewall(request): def reload_firewall(request):
...@@ -38,7 +38,7 @@ def firewall_api(request): ...@@ -38,7 +38,7 @@ def firewall_api(request):
raise Exception(_("Wrong password.")) raise Exception(_("Wrong password."))
if command == "blacklist": if command == "blacklist":
obj, created = Blacklist.objects.get_or_create(ipv4=data["ip"]) obj, created = BlacklistItem.objects.get_or_create(ipv4=data["ip"])
obj.reason = data["reason"] obj.reason = data["reason"]
obj.snort_message = data["snort_message"] obj.snort_message = data["snort_message"]
if created: if created:
......
...@@ -5,7 +5,7 @@ from crispy_forms.helper import FormHelper ...@@ -5,7 +5,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Div, Submit, BaseInput from crispy_forms.layout import Layout, Fieldset, Div, Submit, BaseInput
from crispy_forms.bootstrap import FormActions from crispy_forms.bootstrap import FormActions
from firewall.models import (Host, Vlan, Domain, Group, Record, Blacklist, from firewall.models import (Host, Vlan, Domain, Group, Record, BlacklistItem,
Rule, VlanGroup, SwitchPort) Rule, VlanGroup, SwitchPort)
...@@ -26,7 +26,7 @@ class LinkButton(BaseInput): ...@@ -26,7 +26,7 @@ class LinkButton(BaseInput):
super(LinkButton, self).__init__(name, text, *args, **kwargs) super(LinkButton, self).__init__(name, text, *args, **kwargs)
class BlacklistForm(ModelForm): class BlacklistItemForm(ModelForm):
helper = FormHelper() helper = FormHelper()
helper.layout = Layout( helper.layout = Layout(
Div( Div(
...@@ -45,7 +45,7 @@ class BlacklistForm(ModelForm): ...@@ -45,7 +45,7 @@ class BlacklistForm(ModelForm):
) )
class Meta: class Meta:
model = Blacklist model = BlacklistItem
class DomainForm(ModelForm): class DomainForm(ModelForm):
......
...@@ -4,7 +4,7 @@ from django_tables2.columns import LinkColumn, TemplateColumn ...@@ -4,7 +4,7 @@ from django_tables2.columns import LinkColumn, TemplateColumn
from firewall.models import Host, Vlan, Domain, Group, Record, Rule, SwitchPort from firewall.models import Host, Vlan, Domain, Group, Record, Rule, SwitchPort
class BlacklistTable(Table): class BlacklistItemTable(Table):
ipv4 = LinkColumn('network.blacklist', args=[A('pk')]) ipv4 = LinkColumn('network.blacklist', args=[A('pk')])
class Meta: class Meta:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<h2>{% trans "Create a blacklist" %}</h2> <h2>{% trans "Create a blacklist item" %}</h2>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-4"> <div class="col-sm-4">
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url "network.blacklist_delete" pk=blacklist_pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> {% trans "Delete this blaclist" %}</a> <a href="{% url "network.blacklist_delete" pk=blacklist_pk %}" class="btn btn-danger pull-right"><i class="icon-remove-sign"></i> {% trans "Delete this blaclist item" %}</a>
<h2>{{ form.ipv4.value }} <small>{{ form.type.value }}</small></h2> <h2>{{ form.ipv4.value }} <small>{{ form.type.value }}</small></h2>
</div> </div>
<div class="row"> <div class="row">
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
{% block content %} {% block content %}
<div class="page-header"> <div class="page-header">
<a href="{% url "network.blacklist_create" %}" class="btn btn-success pull-right"><i class="icon-plus-sign"></i> {% trans "Create a new blacklist" %}</a> <a href="{% url "network.blacklist_create" %}" class="btn btn-success pull-right"><i class="icon-plus-sign"></i> {% trans "Create a new blacklist item" %}</a>
<h1>{% trans "Blacklists" %} <small></small></h1> <h1>{% trans "Blacklist" %} <small></small></h1>
</div> </div>
<div class="table-responsive"> <div class="table-responsive">
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
{% trans "Records" as t %} {% trans "Records" as t %}
{% include "network/menu-item.html" with href=u text=t %} {% include "network/menu-item.html" with href=u text=t %}
{% url "network.blacklist_list" as u %} {% url "network.blacklist_list" as u %}
{% trans "Blacklists" as t %} {% trans "Blacklist" as t %}
{% include "network/menu-item.html" with href=u text=t %} {% include "network/menu-item.html" with href=u text=t %}
{% url "network.rule_list" as u %} {% url "network.rule_list" as u %}
{% trans "Rules" as t %} {% trans "Rules" as t %}
...@@ -43,4 +43,4 @@ ...@@ -43,4 +43,4 @@
{# <li><a href="/firewalls/">{% trans "Firewalls" %}</a></li> #} {# <li><a href="/firewalls/">{% trans "Firewalls" %}</a></li> #}
{# <li><a href="/domains/">{% trans "Domains" %}</a></li> #} {# <li><a href="/domains/">{% trans "Domains" %}</a></li> #}
{# <li><a href="/records/">{% trans "DNS records" %}</a></li> #} {# <li><a href="/records/">{% trans "DNS records" %}</a></li> #}
{# <li><a href="/blacklists/">{% trans "Blacklists" %}</a></li> #} {# <li><a href="/blacklist/">{% trans "Blacklist" %}</a></li> #}
...@@ -22,13 +22,13 @@ js_info_dict = { ...@@ -22,13 +22,13 @@ js_info_dict = {
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url('^$', IndexView.as_view(), name='network.index'), url('^$', IndexView.as_view(), name='network.index'),
url('^blacklists/$', BlacklistList.as_view(), url('^blacklist/$', BlacklistList.as_view(),
name='network.blacklist_list'), name='network.blacklist_list'),
url('^blacklists/create$', BlacklistCreate.as_view(), url('^blacklist/create$', BlacklistCreate.as_view(),
name='network.blacklist_create'), name='network.blacklist_create'),
url('^blacklists/(?P<pk>\d+)/$', BlacklistDetail.as_view(), url('^blacklist/(?P<pk>\d+)/$', BlacklistDetail.as_view(),
name='network.blacklist'), name='network.blacklist'),
url('^blacklists/delete/(?P<pk>\d+)/$', BlacklistDelete.as_view(), url('^blacklist/delete/(?P<pk>\d+)/$', BlacklistDelete.as_view(),
name="network.blacklist_delete"), name="network.blacklist_delete"),
url('^domains/$', DomainList.as_view(), name='network.domain_list'), url('^domains/$', DomainList.as_view(), name='network.domain_list'),
url('^domains/create$', DomainCreate.as_view(), url('^domains/create$', DomainCreate.as_view(),
......
...@@ -6,15 +6,15 @@ from django.http import HttpResponse ...@@ -6,15 +6,15 @@ from django.http import HttpResponse
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from firewall.models import (Host, Vlan, Domain, Group, Record, Blacklist, from firewall.models import (Host, Vlan, Domain, Group, Record, BlacklistItem,
Rule, VlanGroup, SwitchPort, EthernetDevice) Rule, VlanGroup, SwitchPort, EthernetDevice)
from vm.models import Interface from vm.models import Interface
from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable, from .tables import (HostTable, VlanTable, SmallHostTable, DomainTable,
GroupTable, RecordTable, BlacklistTable, RuleTable, GroupTable, RecordTable, BlacklistItemTable, RuleTable,
VlanGroupTable, SmallRuleTable, SmallGroupRuleTable, VlanGroupTable, SmallRuleTable, SmallGroupRuleTable,
SmallRecordTable, SwitchPortTable) SmallRecordTable, SwitchPortTable)
from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm, from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
BlacklistForm, RuleForm, VlanGroupForm, SwitchPortForm) BlacklistItemForm, RuleForm, VlanGroupForm, SwitchPortForm)
from django.contrib import messages from django.contrib import messages
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
...@@ -51,7 +51,8 @@ class IndexView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView): ...@@ -51,7 +51,8 @@ class IndexView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
context = super(IndexView, self).get_context_data(**kwargs) context = super(IndexView, self).get_context_data(**kwargs)
size = 13 size = 13
blacklists = Blacklist.objects.all().order_by('-modified_at')[:size] blacklists = BlacklistItem.objects.all().order_by(
'-modified_at')[:size]
domains = Domain.objects.all().order_by('-modified_at')[:size] domains = Domain.objects.all().order_by('-modified_at')[:size]
groups = Group.objects.all().order_by('-modified_at')[:size] groups = Group.objects.all().order_by('-modified_at')[:size]
hosts = Host.objects.all().order_by('-modified_at')[:size] hosts = Host.objects.all().order_by('-modified_at')[:size]
...@@ -80,18 +81,18 @@ class IndexView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView): ...@@ -80,18 +81,18 @@ class IndexView(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
class BlacklistList(LoginRequiredMixin, SuperuserRequiredMixin, class BlacklistList(LoginRequiredMixin, SuperuserRequiredMixin,
SingleTableView): SingleTableView):
model = Blacklist model = BlacklistItem
table_class = BlacklistTable table_class = BlacklistItemTable
template_name = "network/blacklist-list.html" template_name = "network/blacklist-list.html"
table_pagination = False table_pagination = False
class BlacklistDetail(LoginRequiredMixin, SuperuserRequiredMixin, class BlacklistDetail(LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, UpdateView): SuccessMessageMixin, UpdateView):
model = Blacklist model = BlacklistItem
template_name = "network/blacklist-edit.html" template_name = "network/blacklist-edit.html"
form_class = BlacklistForm form_class = BlacklistItemForm
success_message = _(u'Successfully modified blacklist ' success_message = _(u'Successfully modified blacklist item'
'%(ipv4)s - %(type)s!') '%(ipv4)s - %(type)s!')
def get_success_url(self): def get_success_url(self):
...@@ -106,22 +107,22 @@ class BlacklistDetail(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -106,22 +107,22 @@ class BlacklistDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class BlacklistCreate(LoginRequiredMixin, SuperuserRequiredMixin, class BlacklistCreate(LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, CreateView): SuccessMessageMixin, CreateView):
model = Blacklist model = BlacklistItem
template_name = "network/blacklist-create.html" template_name = "network/blacklist-create.html"
form_class = BlacklistForm form_class = BlacklistItemForm
success_message = _(u'Successfully created blacklist ' success_message = _(u'Successfully created blacklist item '
'%(ipv4)s - %(type)s!') '%(ipv4)s - %(type)s!')
class BlacklistDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView): class BlacklistDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
model = Blacklist model = BlacklistItem
template_name = "network/confirm/base_delete.html" template_name = "network/confirm/base_delete.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
""" display more information about the object """ """ display more information about the object """
context = super(BlacklistDelete, self).get_context_data(**kwargs) context = super(BlacklistDelete, self).get_context_data(**kwargs)
if 'pk' in self.kwargs: if 'pk' in self.kwargs:
to_delete = Blacklist.objects.get(pk=self.kwargs['pk']) to_delete = BlacklistItem.objects.get(pk=self.kwargs['pk'])
context['object'] = "%s - %s - %s" % (to_delete.ipv4, context['object'] = "%s - %s - %s" % (to_delete.ipv4,
to_delete.reason, to_delete.reason,
to_delete.type) to_delete.type)
......
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