From 3147066a852e7868aea606441ff5653fc9f4b622 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 2 Oct 2017 04:54:40 +0200 Subject: [PATCH] =?UTF-8?q?L'affichage=20et=20l'acc=C3=A8s=20au=20menu=20p?= =?UTF-8?q?ort=20sont=20possible=20que=20si=20ip=20publique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/models.py | 6 +++--- machines/templates/machines/aff_machines.html | 2 ++ machines/views.py | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/machines/models.py b/machines/models.py index 0313470d..cb859141 100644 --- a/machines/models.py +++ b/machines/models.py @@ -280,13 +280,13 @@ class Interface(models.Model): return str(domain) def has_private_ip(self): - if hasattr(self, 'ipv4'): + if self.ipv4: return IPAddress(str(self.ipv4)).is_private() else: return False def may_have_port_open(self): - return hasattr(self, 'ipv4') and self.has_private_ip() + return self.ipv4 and not self.has_private_ip() class Domain(models.Model): PRETTY_NAME = "Domaine dns" @@ -497,7 +497,7 @@ def interface_post_save(sender, **kwargs): interface = kwargs['instance'] user = interface.machine.user user.ldap_sync(base=False, access_refresh=False, mac_refresh=True) - if interface.may_have_port_open() and interface.port_lists.all(): + if not interface.may_have_port_open() and interface.port_lists.all(): interface.port_lists.clear() # Regen services regen('dhcp') diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index c4a2dd56..6cf306f7 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -91,11 +91,13 @@ with this program; if not, write to the Free Software Foundation, Inc., Gerer les alias + {% if interface.may_have_port_open %}
  • Gerer la configuration des ports
  • + {% endif %}
  • Historique diff --git a/machines/views.py b/machines/views.py index 8a01d813..8200843c 100644 --- a/machines/views.py +++ b/machines/views.py @@ -1001,6 +1001,9 @@ def configure_ports(request, pk): except Interface.DoesNotExist: messages.error(request, u"Interface inexistante" ) return redirect("/machines") + if not interface_instance.may_have_port_open(): + messages.error(request, "L'ip de cette interface n'est pas publique ou non assignée") + return redirect("/machines") interface = EditOuverturePortConfigForm(request.POST or None, instance=interface_instance) if interface.is_valid(): interface.save()