8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 00:13:45 +00:00

Les algo sont fixés par RFC; simplification

This commit is contained in:
Gabriel Detraz 2018-07-29 13:40:49 +02:00 committed by Maël Kervella
parent eac4933853
commit ce0b67209f
9 changed files with 16 additions and 271 deletions

View file

@ -45,7 +45,6 @@ from .models import (
Ipv6List, Ipv6List,
OuverturePortList, OuverturePortList,
SshFingerprint, SshFingerprint,
SshFprAlgo,
) )
@ -143,11 +142,6 @@ class ServiceAdmin(VersionAdmin):
list_display = ('service_type', 'min_time_regen', 'regular_time_regen') list_display = ('service_type', 'min_time_regen', 'regular_time_regen')
class SshFprAlgoAdmin(VersionAdmin):
""" Admin view of a SshFprAlgo object """
pass
class SshFingerprintAdmin(VersionAdmin): class SshFingerprintAdmin(VersionAdmin):
""" Admin view of a SshFprAlgo object """ """ Admin view of a SshFprAlgo object """
pass pass
@ -171,5 +165,4 @@ admin.site.register(Ipv6List, Ipv6ListAdmin)
admin.site.register(Nas, NasAdmin) admin.site.register(Nas, NasAdmin)
admin.site.register(OuverturePort, OuverturePortAdmin) admin.site.register(OuverturePort, OuverturePortAdmin)
admin.site.register(OuverturePortList, OuverturePortListAdmin) admin.site.register(OuverturePortList, OuverturePortListAdmin)
admin.site.register(SshFprAlgo, SshFprAlgoAdmin)
admin.site.register(SshFingerprint, SshFingerprintAdmin) admin.site.register(SshFingerprint, SshFingerprintAdmin)

View file

@ -61,7 +61,6 @@ from .models import (
OuverturePortList, OuverturePortList,
Ipv6List, Ipv6List,
SshFingerprint, SshFingerprint,
SshFprAlgo
) )
@ -612,18 +611,3 @@ class SshFingerprintForm(FormRevMixin, ModelForm):
prefix=prefix, prefix=prefix,
**kwargs **kwargs
) )
class SshFprAlgoForm(FormRevMixin, ModelForm):
"""Edits a SSH fingerprint algorithm."""
class Meta:
model = SshFprAlgo
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(SshFprAlgoForm, self).__init__(
*args,
prefix=prefix,
**kwargs
)

View file

@ -1,46 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-23 14:51
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('machines', '0083_remove_duplicate_rights'),
]
operations = [
migrations.CreateModel(
name='SshFprAlgo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256)),
],
options={
'permissions': (('view_sshfpralgo', 'Can see an SSH fingerprint algorithm'),),
'verbose_name': 'SSH fingerprint algorithm',
'verbose_name_plural': 'SSH fingerprint algorithms'
},
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
),
migrations.CreateModel(
name='SshFingerprint',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('pub_key_entry', models.TextField(help_text='SSH public key', max_length=2048)),
('comment', models.CharField(blank=True, help_text='Comment', max_length=255, null=True)),
('algo', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='machines.SshFprAlgo')),
('machine', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='machines.Machine')),
],
options={
'permissions': (('view_sshfingerprint', 'Can see an SSH fingerprint'),),
'verbose_name': 'SSH fingerprint',
'verbose_name_plural': 'SSH fingerprints'
},
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
),
]

View file

@ -200,16 +200,27 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
def __str__(self): def __str__(self):
return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name) return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name)
class SshFingerprint(RevMixin, AclMixin, models.Model): class SshFingerprint(RevMixin, AclMixin, models.Model):
"""A fingerpirnt of an SSH public key""" """A fingerpirnt of an SSH public key"""
ALGO = (
("ssh-rsa", "ssh-rsa"),
("ssh-ed25519", "ssh-ed25519"),
("ecdsa-sha2-nistp256", "ecdsa-sha2-nistp256"),
("ecdsa-sha2-nistp384", "ecdsa-sha2-nistp384"),
("ecdsa-sha2-nistp521", "ecdsa-sha2-nistp521"),
("ecdsa-sha2-nistp521", "ecdsa-sha2-nistp521"),
)
machine = models.ForeignKey('Machine', on_delete=models.CASCADE) machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
pub_key_entry = models.TextField( pub_key_entry = models.TextField(
help_text="SSH public key", help_text="SSH public key",
max_length=2048 max_length=2048
) )
algo = models.ForeignKey( algo = models.CharField(
'SshFprAlgo', choices=ALGO,
on_delete=models.PROTECT max_length=32
) )
comment = models.CharField( comment = models.CharField(
help_text="Comment", help_text="Comment",
@ -238,21 +249,6 @@ class SshFingerprint(RevMixin, AclMixin, models.Model):
return str(self.algo) + ' ' + str(self.hash_entry) + ' ' + str(self.comment) return str(self.algo) + ' ' + str(self.hash_entry) + ' ' + str(self.comment)
class SshFprAlgo(RevMixin, AclMixin, models.Model):
"""An algorithm to compute SSH fingerprints"""
name = models.CharField(max_length=256)
class Meta:
permissions = (
("view_sshfpralgo", "Can see an SSH fingerprint algorithm"),
)
verbose_name = "SSH fingerprint algorithm"
verbose_name_plural = "SSH fingerprint algorithms"
def __str__(self):
return str(self.name)
class MachineType(RevMixin, AclMixin, models.Model): class MachineType(RevMixin, AclMixin, models.Model):
""" Type de machine, relié à un type d'ip, affecté aux interfaces""" """ Type de machine, relié à un type d'ip, affecté aux interfaces"""
PRETTY_NAME = "Type de machine" PRETTY_NAME = "Type de machine"

View file

@ -1,47 +0,0 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2018 Gabriel Détraz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Algorithm name</th>
<th></th>
</tr>
</thead>
{% for sshfpralgo in sshfpralgo_list %}
<tr>
<td>{{ sshfpralgo.name }}</td>
<td class="text-right">
{% can_edit sshfpralgo %}
{% include 'buttons/edit.html' with href='machines:edit-sshfpralgo' id=sshfpralgo.id %}
{% acl_end %}
{% can_delete sshfpralgo %}
{% include 'buttons/suppr.html' with href='machines:del-sshfpralgo' id=sshfpralgo.id %}
{% acl_end %}
{% history_button sshfpralgo %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -1,38 +0,0 @@
{% extends "machines/sidebar.html" %}
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2018 Gabriel Détraz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load bootstrap3 %}
{% load acl %}
{% block title %}Machines{% endblock %}
{% block content %}
<h2>SSH fingerprint algorithms</h2>
{% can_create SshFprAlgo %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-sshfpralgo' %}">
<i class="fa fa-plus"></i> Add an SSH fingerprint algorithm
</a>
{% acl_end %}
{% include "machines/aff_sshfpralgo.html" with sshfpralgo_list=sshfpralgo_list %}
{% endblock %}

View file

@ -44,12 +44,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Extensions et zones Extensions et zones
</a> </a>
{% acl_end %} {% acl_end %}
{% can_view_all SshFprAlgo %}
<a class="list-group-item list-group-item-info" href="{% url "machines:index-sshfpralgo" %}">
<i class="fa fa-list-ul"></i>
SSH fingerprint algorithm
</a>
{% acl_end %}
{% can_view_all IpType %} {% can_view_all IpType %}
<a class="list-group-item list-group-item-info" href="{% url "machines:index-iptype" %}"> <a class="list-group-item list-group-item-info" href="{% url "machines:index-iptype" %}">
<i class="fa fa-list-ul"></i> <i class="fa fa-list-ul"></i>

View file

@ -119,18 +119,6 @@ urlpatterns = [
url(r'^index_sshfingerprint/(?P<machineid>[0-9]+)$', url(r'^index_sshfingerprint/(?P<machineid>[0-9]+)$',
views.index_sshfingerprint, views.index_sshfingerprint,
name='index-sshfingerprint'), name='index-sshfingerprint'),
url(r'^new_sshfpralgo/$',
views.new_sshfpralgo,
name='new-sshfpralgo'),
url(r'^edit_sshfpralgo/(?P<sshfpralgoid>[0-9]+)$',
views.edit_sshfpralgo,
name='edit-sshfpralgo'),
url(r'^del_sshfpralgo/(?P<sshfpralgoid>[0-9]+)$',
views.del_sshfpralgo,
name='del-sshfpralgo'),
url(r'^index_sshfpralgo/$',
views.index_sshfpralgo,
name='index-sshfpralgo'),
url(r'^add_service/$', views.add_service, name='add-service'), url(r'^add_service/$', views.add_service, name='add-service'),
url(r'^edit_service/(?P<serviceid>[0-9]+)$', url(r'^edit_service/(?P<serviceid>[0-9]+)$',
views.edit_service, views.edit_service,

View file

@ -54,6 +54,7 @@ from re2o.utils import (
from re2o.acl import ( from re2o.acl import (
can_create, can_create,
can_edit, can_edit,
can_view,
can_delete, can_delete,
can_view_all, can_view_all,
can_delete_set, can_delete_set,
@ -110,7 +111,6 @@ from .forms import (
EditOuverturePortListForm, EditOuverturePortListForm,
EditOuverturePortConfigForm, EditOuverturePortConfigForm,
SshFingerprintForm, SshFingerprintForm,
SshFprAlgoForm,
) )
from .models import ( from .models import (
IpType, IpType,
@ -133,7 +133,6 @@ from .models import (
OuverturePort, OuverturePort,
Ipv6List, Ipv6List,
SshFingerprint, SshFingerprint,
SshFprAlgo,
) )
@ -530,72 +529,6 @@ def del_sshfingerprint(request, sshfingerprint, **_kwargs):
) )
@login_required
@can_create(SshFprAlgo)
def new_sshfpralgo(request, **_kwargs):
"""Creates an SSH fingeprint algorithm"""
sshfpralgo = SshFprAlgoForm(
request.POST or None,
)
if sshfpralgo.is_valid():
sshfpralgo.save()
messages.success(request, "The SSH fingerprint algorithm was added")
return redirect(reverse(
'machines:index-sshfpralgo'
))
return form(
{'sshfpralgoform': sshfpralgo, 'action_name': 'Create'},
'machines/machine.html',
request
)
@login_required
@can_edit(SshFprAlgo)
def edit_sshfpralgo(request, sshfpralgo_instance, **_kwargs):
"""Edits an SSH fingerprint algorithm"""
sshfpralgo = SshFprAlgoForm(
request.POST or None,
instance=sshfpralgo_instance
)
if sshfpralgo.is_valid():
if sshfpralgo.changed_data:
sshfpralgo.save()
messages.success(request, "The SSH fingerprint algorithm was edited")
return redirect(reverse(
'machines:index-sshfpralgo'
))
return form(
{'sshfpralgoform': sshfpralgo, 'action_name': 'Edit'},
'machines/machine.html',
request
)
@login_required
@can_delete(SshFprAlgo)
def del_sshfpralgo(request, sshfpralgo, **_kwargs):
"""Deletes an SSH fingerprint algorithm"""
if request.method == "POST":
try:
sshfpralgo.delete()
messages.success(request, "The SSH fingerprint algorithm was deleted")
except ProtectedError:
messages.error(
request,
("This SSH fingerprint algorithm is used by at least one SSH"
"fingerprint and thus can not be deleted.")
)
return redirect(reverse(
'machines:index-sshfpralgo'
))
return form(
{'objet': sshfpralgo, 'objet_name': 'sshfpralgo'},
'machines/delete.html',
request
)
@login_required @login_required
@can_create(IpType) @can_create(IpType)
def add_iptype(request): def add_iptype(request):
@ -1524,7 +1457,7 @@ def index_alias(request, interface, interfaceid):
@login_required @login_required
@can_view_all(Machine) @can_view(Machine)
def index_sshfingerprint(request, machine, machineid): def index_sshfingerprint(request, machine, machineid):
"""View used to display the list of existing SSH fingerprint of a machine""" """View used to display the list of existing SSH fingerprint of a machine"""
sshfingerprint_list = SshFingerprint.objects.filter(machine=machine) sshfingerprint_list = SshFingerprint.objects.filter(machine=machine)
@ -1535,18 +1468,6 @@ def index_sshfingerprint(request, machine, machineid):
) )
@login_required
@can_view_all(SshFprAlgo)
def index_sshfpralgo(request):
"""View used to display the list of existing SSH fingerprint algorithm"""
sshfpralgo_list = SshFprAlgo.objects.all()
return render(
request,
'machines/index_sshfpralgo.html',
{'sshfpralgo_list': sshfpralgo_list}
)
@login_required @login_required
@can_view_all(Interface) @can_view_all(Interface)
def index_ipv6(request, interface, interfaceid): def index_ipv6(request, interface, interfaceid):