diff --git a/machines/forms.py b/machines/forms.py index afe781f1..a611fa98 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -230,9 +230,10 @@ class DelVlanForm(Form): vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple) class EditPortListForm(ModelForm): - tcp_ports = forms.CharField(required=False, label="Ports TCP") - udp_ports = forms.CharField(required=False, label="Ports UDP") - # interfaces = forms.ModelMultipleChoiceField(queryset=Interface.objects.filter(Q(has_public_ip=True)), label="Interface", widget=forms.CheckboxSelectMultiple) + tcp_ports_in = forms.CharField(required=False, label="Ports TCP (entrée)") + udp_ports_in = forms.CharField(required=False, label="Ports UDP (entrée)") + tcp_ports_out = forms.CharField(required=False, label="Ports TCP (sortie)") + udp_ports_out = forms.CharField(required=False, label="Ports UDP (sortie)") class Meta: model = PortList fields = ['name'] diff --git a/machines/migrations/0060_port_io.py b/machines/migrations/0060_port_io.py new file mode 100644 index 00000000..0d890b56 --- /dev/null +++ b/machines/migrations/0060_port_io.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-10-01 09:30 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0059_port_protocole'), + ] + + operations = [ + migrations.AddField( + model_name='port', + name='io', + field=models.CharField(choices=[('I', 'IN'), ('O', 'OUT')], default='O', max_length=1), + ), + ] diff --git a/machines/models.py b/machines/models.py index 91e16ab9..949d9608 100644 --- a/machines/models.py +++ b/machines/models.py @@ -417,11 +417,18 @@ class PortList(models.Model): def __str__(self): return ', '.join(map(str, self.port_set.all())) - def tcp_ports(self): - return self.port_set.filter(protocole=Port.TCP) + def tcp_ports_in(self): + return self.port_set.filter(protocole=Port.TCP, io=Port.IN) - def udp_ports(self): - return self.port_set.filter(protocole=Port.UDP) + def udp_ports_in(self): + return self.port_set.filter(protocole=Port.UDP, io=Port.IN) + + def tcp_ports_out(self): + return self.port_set.filter(protocole=Port.TCP, io=Port.OUT) + + def udp_ports_out(self): + return self.port_set.filter(protocole=Port.UDP, io=Port.OUT) + class Port(models.Model): """ @@ -432,6 +439,8 @@ class Port(models.Model): """ TCP = 'T' UDP = 'U' + IN = 'I' + OUT = 'O' begin = models.IntegerField() end = models.IntegerField() port_list = models.ForeignKey('PortList', on_delete=models.CASCADE) @@ -443,6 +452,14 @@ class Port(models.Model): ), default=TCP, ) + io = models.CharField( + max_length=1, + choices=( + (IN, 'IN'), + (OUT, 'OUT'), + ), + default=OUT, + ) def __str__(self): if self.begin == self.end : diff --git a/machines/templates/machines/index_portlist.html b/machines/templates/machines/index_portlist.html index ce48e249..81847af1 100644 --- a/machines/templates/machines/index_portlist.html +++ b/machines/templates/machines/index_portlist.html @@ -11,16 +11,20 @@ Nom - TCP - UDP + TCP (entrée) + TCP (sortie) + UDP (entrée) + UDP (sortie) {% for pl in port_list %} {{pl.name}} - {% for p in pl.tcp_ports%}{{p.show_port}}, {%endfor%} - {% for p in pl.udp_ports%}{{p.show_port}}, {%endfor%} + {% for p in pl.tcp_ports_in %}{{p.show_port}}, {%endfor%} + {% for p in pl.tcp_ports_out %}{{p.show_port}}, {%endfor%} + {% for p in pl.udp_ports_in %}{{p.show_port}}, {%endfor%} + {% for p in pl.udp_ports_out %}{{p.show_port}}, {%endfor%} {%comment%} {% include 'buttons/suppr.html' href='machines:del-portlist' id=pl.id %}