diff --git a/machines/migrations/0058_auto_20170928_1711.py b/machines/migrations/0058_auto_20170928_1711.py new file mode 100644 index 00000000..41224de1 --- /dev/null +++ b/machines/migrations/0058_auto_20170928_1711.py @@ -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'), + ), + ] diff --git a/machines/migrations/0059_port_protocole.py b/machines/migrations/0059_port_protocole.py new file mode 100644 index 00000000..fc43bdb0 --- /dev/null +++ b/machines/migrations/0059_port_protocole.py @@ -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), + ), + ] diff --git a/machines/models.py b/machines/models.py index 8eff89fc..4dc0e3ad 100644 --- a/machines/models.py +++ b/machines/models.py @@ -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