Changeset - 87d2821ecdfd
[Not reviewed]
default
0 3 0
Branko Majic (branko) - 11 years ago 2013-07-14 22:26:05
branko@majic.rs
CONNT-9: Reworked the entity details view to be more consistent with the other views. Move implicit queries from template to view.
3 files changed with 101 insertions and 18 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/conntrackt/entity_detail.html
Show inline comments
 
@@ -4,8 +4,6 @@
 
{% load conntrackt_tags %}
 

	
 
{% block content %}
 
{# Use a bit shorter variable names. #}
 
{% with project=entity.project location=entity.location %}
 

	
 
{% if entity %}
 
<div class="row">
 
@@ -20,27 +18,88 @@
 
</div>
 
<hr>
 
{% endif %}
 

	
 
<div class="row">
 
  <div class="span12">
 
    {% html_link "Edit" "entity_update" entity.id class="btn btn-primary" %}
 
    {% html_link "Remove" "entity_delete" entity.id class="btn btn-primary" %}
 
    {% html_link "Get Iptables" 'entity_iptables' entity.id class="btn btn-primary" %}
 
  </div>
 
</div>
 

	
 
<hr>
 

	
 
<div class="row">
 

	
 
  <div class="span6">
 
    <div class="well">
 
      <table class="table table-striped">
 
        <tr>
 
          <th colspan="2">General information</th>
 
        </tr>
 
        <tr>
 
          <th>Project</th><td style="width:99%">{% html_link project.name 'project'  project.id  %}</td>
 
        </tr>
 
        <tr>
 
          <th>Location</th><td>{{location}}</td>
 
        </tr>
 
      </table>
 
    </div>
 
  </div>
 

	
 
  <div class="span6">
 
    <div class="well">
 
      <table class="table table-striped">
 
        <tr>
 
          <th style="width:99%">Interfaces</th>
 
        </tr>
 
        <tr>
 
          {% for interface in interfaces %}
 
            <td>{{interface.name}} ({{interface.address}}/{{interface.netmask}})</td>
 
          {% endfor %}
 
        </tr>
 
      </table>
 
    </div>
 
  </div>
 
</div>
 
<hr>
 
<dl>
 
  <dt>Project</dt><dd>{% html_link project.name 'project'  project.id  %}</dd>
 
  <dt>Location</dt><dd>{{location.name}}</dd>
 
  <dt>Incoming communications</dt><dd><ul class="unstyled">{% for interface in entity.interface_set.all %}
 
    {% for communication in interface.destination_set.all %}
 
    <li>{{communication.source}} - {{communication.protocol}}: {{communication.port}}</li>
 
    {% endfor %}{% endfor %}</ul></dd>
 
    <dt>Outgoing communications</dt><dd><ul class="unstyled">{% 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>{{ entity_iptables }}</pre>{% html_link 'Download' 'entity_iptables' entity.id class="btn btn-primary input-small" %}</dd>
 
</dl>
 

	
 
<div class="row">
 
  <div class="span6">
 
    <div class="well">
 
      <table class="table table-striped">
 
        <tr>
 
          <th>Incoming communications</th>
 
        </tr>
 
        {% for comm in incoming_communications %}
 
          <tr><td>{{comm.source}} - {{comm.protocol}}: {{comm.port}}</td></tr>
 
        {% endfor %}
 
      </table>
 
    </div>
 
  </div>
 

	
 
  <div class="span6">
 
    <div class="well">
 
      <table class="table table-striped">
 
        <tr>
 
          <th>Outgoing communications</th>
 
        </tr>
 
        {% for comm in outgoing_communications %}
 
          <tr><td>{{comm.destination}} - {{comm.protocol}}: {{comm.port}}</td></tr>
 
        {% endfor %}
 
        <tr>
 
        </tr>
 
      </table>
 
    </div>
 
  </div>
 

	
 
  <div class="span12">
 
    <div>
 
      <p><strong>Iptables rules</strong></p>
 
      <pre>{{ entity_iptables }}</pre>
 
    </div>
 
  </div>
 
  
 
</div>
 
{% endif %}
 
{% endwith %}
 
{% endblock %}
 

	
conntrackt/tests/test_views.py
Show inline comments
 
@@ -157,7 +157,7 @@ class ProjectViewTest(ViewTest):
 
        self.assertContains(response, "Test Location 2")
 

	
 

	
 
class EntityView(ViewTest):
 
class EntityViewTest(ViewTest):
 

	
 
    def test_permission_denied(self):
 
        """
 
@@ -190,6 +190,19 @@ class EntityView(ViewTest):
 

	
 
        response = self.client.get(reverse("entity", args=(1,)))
 

	
 
        expected_incoming_communications = ["<Communication: Test Entity 2 -> Test Entity 1 (TCP:22)>",
 
                                            "<Communication: Test Entity 2 -> Test Entity 1 (ICMP:8)>",
 
                                            "<Communication: Test Entity 3 -> Test Entity 1 (TCP:3306)>",
 
                                            "<Communication: Test Subnet -> Test Entity 1 (TCP:22)>",]
 

	
 
        expected_outgoing_communications = ["<Communication: Test Entity 1 -> Test Entity 2 (UDP:123)>",
 
                                            "<Communication: Test Entity 1 -> Test Entity 3 (UDP:53)>"]
 

	
 
        expected_interfaces = ["<Interface: Test Entity 1 (192.168.1.1)>"]
 

	
 
        self.assertQuerysetEqual(response.context["interfaces"], expected_interfaces)
 
        self.assertQuerysetEqual(response.context["incoming_communications"], expected_incoming_communications)
 
        self.assertQuerysetEqual(response.context["outgoing_communications"], expected_outgoing_communications) 
 
        self.assertEqual(str(response.context["entity"]), "Test Entity 1 (Test Project 1 - Test Location 1)")
 
        self.assertContains(response, "Test Entity 1")
 
        self.assertContains(response, ":INPUT")
conntrackt/views.py
Show inline comments
 
@@ -131,6 +131,17 @@ class EntityView(MultiplePermissionsRequ
 
        # 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()
 
        context["outgoing_communications"] = self.object.outgoing_communications()
 

	
 
        # Add the interfaces to the context.
 
        context["interfaces"] = self.object.interface_set.all().order_by("name")
 

	
 
        # Add project/location to the context.
 
        context["project"] = self.object.project
 
        context["location"] = self.object.location
 

	
 
        return context
 

	
 

	
0 comments (0 inline, 0 general)