Verified Commit ec6b227b authored by erdnaxe's avatar erdnaxe 🎇

Move open ports profile to admin

parent 30eee276
Pipeline #1119 passed with stage
in 2 minutes and 55 seconds
......@@ -34,6 +34,7 @@ What have been done so far in Aube that is not in Re2o :
* Add automatic documentation with Django AdminDocs ;
* New login form ;
* Drop custom password reset mechanics in favor of Django Contrib Auth. Now users can also ask a mail to recall their username ;
* Filter interfaces with port opening profile rather than listing all machine per profile ;
* More coming soon…
## How to migrate from Re2o to Aube
......
......@@ -74,6 +74,7 @@ class Ipv6ListInline(admin.TabularInline):
class InterfaceAdmin(VersionAdmin):
"""Admin view of a Interface object"""
list_display = ('domain', 'machine', 'machine_type', 'mac_address', 'ipv4')
list_filter = ('port_lists',)
inlines = (DomainInline, Ipv6ListInline)
......@@ -133,22 +134,15 @@ class OuverturePortInline(admin.TabularInline):
@admin.register(OuverturePortList)
class OuverturePortListAdmin(VersionAdmin):
"""Admin view of a OuverturePortList object"""
list_display = ('name', 'tcp_in', 'tcp_out', 'udp_in', 'udp_out')
list_display = ('name', 'open_ports')
inlines = (OuverturePortInline,)
# TODO(erdnaxe): add machines list
@staticmethod
def open_ports(obj):
"""All ports refering to a profile"""
return ", ".join(port.show_port() for port in obj.ouvertureport_set.all())
def tcp_in(self, obj):
return None
def tcp_out(self, obj):
return None
def udp_in(self, obj):
return None
def udp_out(self, obj):
return None
open_ports.short_description = "open ports"
@admin.register(Role)
......
This diff is collapsed.
......@@ -1114,7 +1114,11 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
machine_type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
details = models.CharField(max_length=255, blank=True)
port_lists = models.ManyToManyField('OuverturePortList', blank=True)
port_lists = models.ManyToManyField(
'OuverturePortList',
blank=True,
verbose_name=_('open ports profile'),
)
class Meta:
permissions = (
......@@ -1901,14 +1905,13 @@ class OuverturePortList(RevMixin, AclMixin, models.Model):
"""Liste des ports ouverts sur une interface."""
name = models.CharField(
max_length=255,
verbose_name=_('name'),
help_text=_("Name of the ports configuration"),
max_length=255
)
class Meta:
verbose_name = _("ports opening profile")
verbose_name_plural = _("ports opening profiles")
verbose_name = _("open ports profile")
verbose_name_plural = _("open ports profiles")
def can_delete(self, user_request, *_args, **_kwargs):
"""Verifie que l'user a les bons droits bureau pour delete
......@@ -2010,8 +2013,10 @@ class OuverturePort(RevMixin, AclMixin, models.Model):
return ':'.join([str(self.begin), str(self.end)])
def show_port(self):
"""Formatage plus joli, alias pour str"""
return str(self)
"""Format all information"""
protocole = 'TCP' if self.protocole == 'T' else 'UDP'
in_out = 'IN' if self.io == 'I' else 'OUT'
return '{} ({} {})'.format(self, protocole, in_out)
@receiver(post_save, sender=Machine)
......
{% extends 'machines/sidebar.html' %}
{% load bootstrap3 %}
{% load acl %}
{% load i18n %}
{% block title %}{% trans "Machines" %}{% endblock %}
{% block content %}
<h2>{% trans "List of ports configurations" %}</h2>
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Name" %}</th>
<th>{% trans "TCP (input)" %}</th>
<th>{% trans "TCP (output)" %}</th>
<th>{% trans "UDP (input)" %}</th>
<th>{% trans "UDP (output)" %}</th>
<th>{% trans "Machines" %}</th>
</tr>
</thead>
{% for pl in port_list %}
<tr>
<td>{{ pl.name }}</td>
<td>{% for p in pl.tcp_ports_in %}{{ p.show_port }}, {% endfor %}</td>
<td>{% for p in pl.tcp_ports_out %}{{ p.show_port }}, {% endfor %}</td>
<td>{% for p in pl.udp_ports_in %}{{ p.show_port }}, {% endfor %}</td>
<td>{% for p in pl.udp_ports_out %}{{ p.show_port }}, {% endfor %}</td>
<td>
{% if pl.interface_set.all %}
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioninterface"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="editioninterface">
{% for interface in pl.interface_set.all %}
<li>
<a href="{% url 'users:profil' userid=interface.machine.user.id %}">
{{ interface }}
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</tr>
{% endfor %}
</table>
{% endblock %}
......@@ -45,11 +45,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% trans "Services (DHCP, DNS, ...)" %}
</a>
{% acl_end %}
{% can_view_all OuverturePortList %}
<a class="list-group-item list-group-item-info" href="{% url 'machines:index-portlist' %}">
<i class="fa fa-list-ul"></i>
{% trans "Ports openings" %}
</a>
{% acl_end %}
{% endblock %}
......@@ -94,7 +94,6 @@ urlpatterns = [
url(r'^rest/ouverture_ports/$',
views.ouverture_ports,
name='ouverture-ports'),
url(r'index_portlist/$', views.index_portlist, name='index-portlist'),
url(r'^port_config/(?P<interfaceid>[0-9]+)$',
views.configure_ports,
name='port-config'),
......
......@@ -732,22 +732,6 @@ def index_service(request):
)
@login_required
@can_view_all(OuverturePortList)
def index_portlist(request):
""" View used to display the list of existing port policies """
port_list = (OuverturePortList.objects
.prefetch_related('ouvertureport_set')
.prefetch_related('interface_set__domain__extension')
.prefetch_related('interface_set__machine__user')
.order_by('name'))
return render(
request,
"machines/index_portlist.html",
{'port_list': port_list}
)
@login_required
@can_create(OuverturePort)
@can_edit(Interface)
......
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 to comment