|
@@ -11,14 +11,14 @@ from django.shortcuts import render_to_r
|
|
|
from django.views.generic import TemplateView, DetailView, CreateView, UpdateView, DeleteView
|
|
|
|
|
|
# Third-party application imports.
|
|
|
from braces.views import MultiplePermissionsRequiredMixin
|
|
|
|
|
|
# Application imports.
|
|
|
from .forms import EntityForm
|
|
|
from .models import Project, Entity, Location
|
|
|
from .forms import EntityForm, InterfaceForm
|
|
|
from .models import Project, Entity, Location, Interface
|
|
|
from .utils import generate_entity_iptables
|
|
|
|
|
|
|
|
|
class IndexView(MultiplePermissionsRequiredMixin, TemplateView):
|
|
|
"""
|
|
|
Custom view used for rendering the index page.
|
|
@@ -123,13 +123,13 @@ class EntityView(MultiplePermissionsRequ
|
|
|
|
|
|
Adds the 'entity_iptables' context object that contains full iptables
|
|
|
rules generated for the entity.
|
|
|
"""
|
|
|
|
|
|
# Call the parent class method.
|
|
|
context = super(DetailView, self).get_context_data(**kwargs)
|
|
|
context = super(EntityView, self).get_context_data(**kwargs)
|
|
|
|
|
|
# Add the rendered iptables rules to the context.
|
|
|
context['entity_iptables'] = generate_entity_iptables(self.object)
|
|
|
|
|
|
# Add the incoming and outgoing commmunication to the context.
|
|
|
context["incoming_communications"] = self.object.incoming_communications()
|
|
@@ -526,18 +526,75 @@ class EntityDeleteView(MultiplePermissio
|
|
|
"""
|
|
|
|
|
|
messages.success(self.request, "Entity %s has been removed." % self.get_object().name, extra_tags="alert alert-success")
|
|
|
|
|
|
return super(EntityDeleteView, self).post(*args, **kwargs)
|
|
|
|
|
|
|
|
|
def delete(self, *args, **kwargs):
|
|
|
"""
|
|
|
Deletes the object. This method is overridden in order to obtain the
|
|
|
project ID for success URL.
|
|
|
|
|
|
@TODO: Fix this once Django 1.6 comes out with fix from ticket 19044.
|
|
|
"""
|
|
|
|
|
|
self.success_url = reverse("project", args=(self.get_object().project.id,))
|
|
|
|
|
|
return super(EntityDeleteView, self).delete(*args, **kwargs)
|
|
|
|
|
|
|
|
|
class InterfaceCreateView(MultiplePermissionsRequiredMixin, CreateView):
|
|
|
"""
|
|
|
View for creating a new interface.
|
|
|
"""
|
|
|
|
|
|
model = Interface
|
|
|
form_class = InterfaceForm
|
|
|
template_name_suffix = "_create_form"
|
|
|
|
|
|
# Required permissions
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.add_interface",),
|
|
|
}
|
|
|
|
|
|
# Raise authorisation denied exception for unmet permissions.
|
|
|
raise_exception = True
|
|
|
|
|
|
def get_form(self, form_class):
|
|
|
"""
|
|
|
Returns an instance of form that can be used by the view.
|
|
|
|
|
|
The method will limit the entity select input if request contained this
|
|
|
information.
|
|
|
"""
|
|
|
|
|
|
form = super(InterfaceCreateView, self).get_form(form_class)
|
|
|
|
|
|
# Limit the entity selection if required.
|
|
|
entity_id = self.request.GET.get("entity", None)
|
|
|
if entity_id:
|
|
|
form.fields["entity"].queryset = Entity.objects.filter(pk=entity_id)
|
|
|
form.fields["entity"].widget.attrs["readonly"] = True
|
|
|
|
|
|
return form
|
|
|
|
|
|
def get_initial(self):
|
|
|
"""
|
|
|
Returns initial values that should be pre-selected (if they were
|
|
|
specified through a GET parameter).
|
|
|
"""
|
|
|
|
|
|
initial = super(InterfaceCreateView, self).get_initial()
|
|
|
|
|
|
initial["entity"] = self.request.GET.get("entity", None)
|
|
|
|
|
|
return initial
|
|
|
|
|
|
def get_success_url(self):
|
|
|
"""
|
|
|
Returns the URL to which the user should be redirected after an
|
|
|
interface has been created.
|
|
|
|
|
|
The URL in this case will be set to entity's details page.
|
|
|
"""
|
|
|
|
|
|
return reverse("entity", args=(self.object.entity.pk,))
|