Changeset - ad556f8e81bd
[Not reviewed]
default
0 7 1
Branko Majic (branko) - 11 years ago 2013-03-14 19:41:58
branko@majic.rs
Added some comments. Implemented the entity detail view. The iptables rules can now actually be used by iptables-restore. Project details now show entities in a table (aligned iptables links). Added project/location/entity views. The entity_iptables view now lets user download the file straight away.
8 files changed with 82 insertions and 12 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/admin/conntrackt/communication/change_list.html
Show inline comments
 
@@ -5,6 +5,8 @@
 

	
 
{% block object-tools-items %}
 
            <li>
 
              {# Add the GET parameters from the admin's filter to 'Add entity' button #}
 
              {# so we can perform some filtering on source/destination interfaces. #}
 
              <a href="{% url cl.opts|admin_urlname:'add' %}?{% if is_popup %}_popup=1{% endif %}{% if 'source__entity__location__id__exact' in cl.params %}&source__entity__location__id__exact={{ cl.params.source__entity__location__id__exact }}{% endif %}{% if 'source__entity__project__id__exact' in cl.params %}&source__entity__project__id__exact={{ cl.params.source__entity__project__id__exact }}{% endif %}" class="addlink">
 
                {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
 
              </a>
conntrackt/templates/conntrackt/entity_detail.html
Show inline comments
 
new file 100644
 
{% extends "conntrackt/template.html" %}
 

	
 
{% load conntrackt %}
 

	
 
{% block content %}
 
{% with project=entity.project location=entity.location %}
 
{% if entity %}
 
<h1>{{entity.name}}</h1>
 
<dl>
 
<dt>Project</dt><dd>{% html_link 'project' project.name project.id %}</dd>
 
<dt>Location</dt><dd>{% html_link 'location' location.name location.id %}</dd>
 
<dt>Incoming communications</dt><dd><ul>{% for interface in entity.interface_set.all %}
 
{% for communication in interface.destination_set.all %}
 
<li>{{communication.destination}} - {{communication.protocol}}: {{communication.port}}</li>
 
{% endfor %}{% endfor %}</ul></dd>
 
<dt>Outgoing communications</dt><dd><ul>{% for interface in entity.interface_set.all %}
 
{% for communication in interface.source_set.all %}
 
<li>{{communication.destination}} - {{communication.protocol}}: {{communication.port}}</li>
 
{% endfor %}{% endfor %}</ul></dd>
 
<dt>iptables rules</dt><dd><pre>{% include "conntrackt/entity_iptables.html" with entity=entity %}</pre>{% html_link 'entity_iptables' 'Download' entity.id "btn btn-primary" %}</dd>
 
</dl>
 
{% endif %}
 
{% endwith %}
 
{% endblock %}
 
\ No newline at end of file
conntrackt/templates/conntrackt/entity_iptables.html
Show inline comments
 
# iptables rules generated by conntrackt for {{entity}}
 
*filter
 
:INPUT ACCEPT [0:0]
 
{% for interface in entity.interface_set.all %}{% for communication in interface.destination_set.all %}
 
{% ifchanged communication.description %}
 

	
 
@@ -8,3 +11,13 @@
 
iptables -A INPUT -s {{communication.source.address}}/{{communication.source.netmask}} -p {{communication.protocol|lower}} -m {{communication.protocol|lower}} --dport {{communication.port}} -j ACCEPT
 
{% endfor %}
 
{% endfor %}
 
:FORWARD ACCEPT [0:0]
 
:OUTPUT ACCEPT [0:0]
 
COMMIT
 
*nat
 
:PREROUTING ACCEPT [0:0]
 
:INPUT ACCEPT [0:0]
 
:OUTPUT ACCEPT [0:0]
 
:POSTROUTING ACCEPT [0:0]
 
COMMIT
 

	
conntrackt/templates/conntrackt/index.html
Show inline comments
 
@@ -4,7 +4,7 @@
 

	
 
{% block content %}
 
<h1>Welcome to Conntrackt</h1>
 
Select your project:
 
<div>Below you may find the list of projects that are available to you. Clicking on the project will take you to the summary page for that particular project.</div>
 
{% if projects %}
 
  {% for project in projects %}
 
<ul class="unstyled">
conntrackt/templates/conntrackt/link.html
Show inline comments
 
{% load url from future %}
 

	
 
{% if identifier %}
 
<a href="{% url view identifier %}" {% if html_class %}class="{{html_class}}"{% endif %}>{{title}}</a>
 
{% else %}
conntrackt/templates/conntrackt/project_detail.html
Show inline comments
 
@@ -5,10 +5,25 @@
 
{% block content %}
 
<h1>{{project.name}}</h1>
 

	
 
{% if project.description %}
 
<h2>Description</h2>
 
{{project.description}}
 
{% endif %}
 

	
 
{% if project.entity_set %}
 
<h2>Project Entities</h2>
 

	
 
<table>
 
{% for entity in project.entity_set.all %}
 
  <tr><td>{% html_link 'entity' entity.name entity.id "btn btn-link" %}</td><td>{% html_link 'entity_iptables' '<i class="icon-list"></i>' entity.id "btn btn-link" %}</td></tr>
 
{% endfor %}
 
</table>
 

	
 
<h2>Project Locations</h2>
 

	
 
<ul class="unstyled">
 
{% for entity in project.entity_set.all %}
 
  <li>{% html_link 'entity_iptables' entity.name entity.id "btn btn-link" %}</li>
 
{% for location in locations %}
 
  <li><a href="/location/{{location.id}}?project={{project.id}}">{{location}}</a></li>
 
{% endfor %}
 
</ul>
 
{% endif %}
conntrackt/urls.py
Show inline comments
 
# Import basic functions for URL pattern processing.
 
from django.conf.urls import patterns, url
 

	
 
# Import generic class views.
 
# For plain generic views
 
from conntrackt.models import Entity, Location
 
from django.views.generic import DetailView
 
# Models for generic class views.
 
from conntrackt.models import Project
 

	
 
# Import some app-specific views.
 
from conntrackt.views import IndexView, IptablesView
 
from conntrackt.views import IndexView, IptablesView, ProjectView
 

	
 
urlpatterns = patterns(
 
    'conntrackt.views',
 
    # Homepage/index view.
 
    url(r'^$', IndexView.as_view(), name="index"),
 
    # View for showing information about a project.
 
    url(r'^project/(?P<pk>\d+)/$', DetailView.as_view(model = Project),
 
    url(r'^project/(?P<pk>\d+)/$', ProjectView.as_view(),
 
        name = 'project'),
 
    # View for showing information about an entity.
 
    url(r'^entity/(?P<pk>\d+)/$', DetailView.as_view(model = Entity),
 
        name = 'entity'),
 
    # View for showing information about a location.
 
    url(r'^location/(?P<pk>\d+)/$', DetailView.as_view(model = Location),
 
        name = 'location'),
 
    # View for rendering iptables rules for a specific entity.
 
    url(r'^entity/(?P<pk>\d+)/iptables/$', IptablesView.as_view(), name="entity_iptables"),
 
)
conntrackt/views.py
Show inline comments
 
from django.views.generic import TemplateView, DetailView
 

	
 
from conntrackt.models import Project, Entity
 
from conntrackt.models import Project, Entity, Location
 

	
 
class IndexView(TemplateView):
 
    """
 
@@ -16,9 +16,21 @@ class IndexView(TemplateView):
 

	
 
        return context
 

	
 
class ProjectView(DetailView):
 
    model = Project
 

	
 
    def get_context_data(self, **kwargs):
 
        context = super(ProjectView, self).get_context_data(**kwargs)
 

	
 
        context['locations'] = Location.objects.filter(entity__project = context['project']).distinct()
 
        
 
        return context
 

	
 
class IptablesView(DetailView):
 
    model = Entity
 
    template_name = 'conntrackt/entity_iptables.html'
 
    def render_to_response(self, context, **kwargs):
 
        return super(IptablesView, self).render_to_response(context,
 
                                                            content_type='text/plain', **kwargs)
 
        response = super(IptablesView, self).render_to_response(context,
 
                                                                content_type='text/plain', **kwargs)
 
        response['Content-Disposition']="attachment; filename=iptables.conf"
 
        return response
0 comments (0 inline, 0 general)