8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 03:16:25 +00:00

Gestion de l'ouverture en entrée et en sortie.

This commit is contained in:
LEVY-FALK Hugo 2017-10-01 11:39:39 +02:00 committed by root
parent 4716d7f343
commit cf9db8f1d1
4 changed files with 53 additions and 11 deletions

View file

@ -230,9 +230,10 @@ class DelVlanForm(Form):
vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple) vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple)
class EditPortListForm(ModelForm): class EditPortListForm(ModelForm):
tcp_ports = forms.CharField(required=False, label="Ports TCP") tcp_ports_in = forms.CharField(required=False, label="Ports TCP (entrée)")
udp_ports = forms.CharField(required=False, label="Ports UDP") udp_ports_in = forms.CharField(required=False, label="Ports UDP (entrée)")
# interfaces = forms.ModelMultipleChoiceField(queryset=Interface.objects.filter(Q(has_public_ip=True)), label="Interface", widget=forms.CheckboxSelectMultiple) tcp_ports_out = forms.CharField(required=False, label="Ports TCP (sortie)")
udp_ports_out = forms.CharField(required=False, label="Ports UDP (sortie)")
class Meta: class Meta:
model = PortList model = PortList
fields = ['name'] fields = ['name']

View file

@ -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),
),
]

View file

@ -417,11 +417,18 @@ class PortList(models.Model):
def __str__(self): def __str__(self):
return ', '.join(map(str, self.port_set.all())) return ', '.join(map(str, self.port_set.all()))
def tcp_ports(self): def tcp_ports_in(self):
return self.port_set.filter(protocole=Port.TCP) return self.port_set.filter(protocole=Port.TCP, io=Port.IN)
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)
def udp_ports(self):
return self.port_set.filter(protocole=Port.UDP)
class Port(models.Model): class Port(models.Model):
""" """
@ -432,6 +439,8 @@ class Port(models.Model):
""" """
TCP = 'T' TCP = 'T'
UDP = 'U' UDP = 'U'
IN = 'I'
OUT = 'O'
begin = models.IntegerField() begin = models.IntegerField()
end = models.IntegerField() end = models.IntegerField()
port_list = models.ForeignKey('PortList', on_delete=models.CASCADE) port_list = models.ForeignKey('PortList', on_delete=models.CASCADE)
@ -443,6 +452,14 @@ class Port(models.Model):
), ),
default=TCP, default=TCP,
) )
io = models.CharField(
max_length=1,
choices=(
(IN, 'IN'),
(OUT, 'OUT'),
),
default=OUT,
)
def __str__(self): def __str__(self):
if self.begin == self.end : if self.begin == self.end :

View file

@ -11,16 +11,20 @@
<thead> <thead>
<tr> <tr>
<th>Nom</th> <th>Nom</th>
<th>TCP</th> <th>TCP (entrée)</th>
<th>UDP</th> <th>TCP (sortie)</th>
<th>UDP (entrée)</th>
<th>UDP (sortie)</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for pl in port_list %} {% for pl in port_list %}
<tr> <tr>
<td>{{pl.name}}</td> <td>{{pl.name}}</td>
<td>{% for p in pl.tcp_ports%}{{p.show_port}}, {%endfor%}</td> <td>{% for p in pl.tcp_ports_in %}{{p.show_port}}, {%endfor%}</td>
<td>{% for p in pl.udp_ports%}{{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 class="text-right"> <td class="text-right">
{%comment%} {%comment%}
{% include 'buttons/suppr.html' href='machines:del-portlist' id=pl.id %} {% include 'buttons/suppr.html' href='machines:del-portlist' id=pl.id %}