From d4b0e27b70f5c7c324edbbaa930197970dfe55c8 Mon Sep 17 00:00:00 2001 From: bai Date: Wed, 22 Jul 2020 03:33:44 -0400 Subject: Ajustado manejo de globs y CIDR --- cgi/manage.py | 35 ++++++++++++++++++++++------------- cgi/templates/manage/bans.html | 13 +++++++++++-- 2 files changed, 33 insertions(+), 15 deletions(-) (limited to 'cgi') diff --git a/cgi/manage.py b/cgi/manage.py index 4ece445..f21e7e8 100644 --- a/cgi/manage.py +++ b/cgi/manage.py @@ -675,20 +675,29 @@ def manage(self, path_split): # Parse CIDR or IP glob try: - ipnetwork = netaddr.IPNetwork(ip) - ipstart, ipend = str(ipnetwork[0]), str(ipnetwork[-1]) - ipstr = str(ipnetwork) - except netaddr.core.AddrFormatError: - # Invalid format so try with globs - iprange = netaddr.glob_to_iprange(ip) - ipstart, ipend = str(iprange[0]), str(iprange[-1]) - - cidrs = iprange.cidrs() - if len(cidrs) == 1: - ipstr = str(cidrs[0]) + if netaddr.valid_ipv4(ip) or netaddr.valid_ipv6(ip): + ipaddress = netaddr.IPAddress(ip) + ipstart = ipend = ipstr = str(ipaddress) + elif netaddr.valid_glob(ip): + iprange = netaddr.glob_to_iprange(ip) + ipstart, ipend = str(iprange[0]), str(iprange[-1]) + + cidrs = iprange.cidrs() + if len(cidrs) == 1: + ipstr = str(cidrs[0]) + else: + ipstr = str(iprange) + elif '/' in ip: + # Try with CIDR + ipnetwork = netaddr.IPNetwork(ip) + ipstart, ipend = str(ipnetwork[0]), str(ipnetwork[-1]) + ipstr = str(ipnetwork) else: - ipstr = str(iprange) - + self.error("IP o rango inválido.") + return + except netaddr.core.AddrFormatError, e: + self.error("Problema con el IP o rango ingresado: {}".format(e)) + return if self.formdata['seconds'] != '0': until = str( diff --git a/cgi/templates/manage/bans.html b/cgi/templates/manage/bans.html index 96e1ed1..eee4471 100644 --- a/cgi/templates/manage/bans.html +++ b/cgi/templates/manage/bans.html @@ -16,7 +16,7 @@
- + @@ -47,7 +47,16 @@
Dirección IPDirección o Rango IP Boards Agregado Expira
- +
IP o Rango
IP o Rango + +
Formatos soportados: +
    +
  • IPv4 o IPv6.
    Ejemplo: 160.25.60.122 o 2001:db8::7334
  • +
  • Rango glob. Sólo IPv4.
    Ejemplo: 192.16.*.* o 200.20.4.10-80
  • +
  • Rango CIDR. IPv4 y IPv6.
    Ejemplo: 190.6.0.0/16 o 2620:0:2d0:200::7/32
  • +
+
+
Board(s) -- cgit v1.2.1-18-gbd029