Commit 5d553027 authored by LEVY-FALK Hugo's avatar LEVY-FALK Hugo Committed by root

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

parent 98131ef3
# -*- 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'),
),
]
# -*- 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),
),
]
......@@ -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
......
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