8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Crée un modèle pour une liste de ports et un autre pour représenter un port ou une plage de ports.

This commit is contained in:
LEVY-FALK Hugo 2017-09-28 17:19:33 +02:00 committed by root
parent 98131ef31a
commit 5d55302715
3 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-28 15:11
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('machines', '0057_nas_autocapture_mac'),
]
operations = [
migrations.CreateModel(
name='Port',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('begin', models.IntegerField()),
('end', models.IntegerField()),
],
),
migrations.CreateModel(
name='PortList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='Nom de la configuration des ports.', max_length=255)),
('interfaces', models.ManyToManyField(to='machines.Interface')),
],
),
migrations.AddField(
model_name='port',
name='port_list',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.PortList'),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-28 16:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0058_auto_20170928_1711'),
]
operations = [
migrations.AddField(
model_name='port',
name='protocole',
field=models.CharField(choices=[('T', 'TCP'), ('U', 'UDP')], default='T', max_length=1),
),
]

View file

@ -406,6 +406,43 @@ class Service_link(models.Model):
def __str__(self):
return str(self.server) + " " + str(self.service)
class PortList(models.Model):
"""Liste des ports ouverts sur une interface."""
interfaces = models.ManyToManyField('Interface')
name = models.CharField(help_text="Nom de la configuration des ports.", max_length=255)
def __str__(self):
return ', '.join(map(str, self.port_set.all()))
class Port(models.Model):
"""
Représente un simple port ou une plage de ports.
Les ports de la plage sont compris entre begin et en inclus.
Si begin == end alors on ne représente qu'un seul port.
"""
TCP = 'T'
UDP = 'U'
begin = models.IntegerField()
end = models.IntegerField()
port_list = models.ForeignKey('PortList', on_delete=models.CASCADE)
protocole = models.CharField(
max_length=1,
choices=(
(TCP, 'TCP'),
(UDP, 'UDP'),
),
default=TCP,
)
def __str__(self):
beg = self.protocole + ' : '
if self.begin == self.end :
return beg + str(self.begin)
return beg + '-'.join([str(self.begin), str(self.end)])
@receiver(post_save, sender=Machine)
def machine_post_save(sender, **kwargs):
user = kwargs['instance'].user