aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar bai 2020-07-22 03:33:44 -0400
committerLibravatar bai 2020-07-22 03:33:44 -0400
commitd4b0e27b70f5c7c324edbbaa930197970dfe55c8 (patch)
tree6c66e59d959f7beecf104bb4376d91d951e1bd39
parentcff1db8bcacb369938384c9b99116b7a3d9842b9 (diff)
downloadweabot-d4b0e27b70f5c7c324edbbaa930197970dfe55c8.tar.gz
weabot-d4b0e27b70f5c7c324edbbaa930197970dfe55c8.tar.xz
weabot-d4b0e27b70f5c7c324edbbaa930197970dfe55c8.zip
Ajustado manejo de globs y CIDR
-rw-r--r--cgi/manage.py35
-rw-r--r--cgi/templates/manage/bans.html13
2 files changed, 33 insertions, 15 deletions
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 @@
<hr />
<table class="managertable">
<tr>
- <th>Dirección IP</th>
+ <th>Dirección o Rango IP</th>
<th>Boards</th>
<th>Agregado</th>
<th>Expira</th>
@@ -47,7 +47,16 @@
<?py elif mode == 1: ?>
<form action="#{cgi_url}manage/ban" name="banform" method="post">
<table>
- <tr><td class="postblock">IP o Rango</td><td><input type="text" name="ip" value="${ip}" size="20" style="width:100%;" /></td></tr>
+ <tr><td class="postblock">IP o Rango</td><td><input type="text" name="ip" value="${ip}" size="20" style="width:100%;" />
+ <small>
+ <br>Formatos soportados:
+ <ul>
+ <li><b>IPv4 o IPv6.</b><br>Ejemplo: <em>160.25.60.122 o 2001:db8::7334</em></li>
+ <li><b>Rango glob.</b> Sólo IPv4.<br>Ejemplo: <em>192.16.*.* o 200.20.4.10-80</em></li>
+ <li><b>Rango CIDR.</b> IPv4 y IPv6.<br>Ejemplo: <em>190.6.0.0/16 o 2620:0:2d0:200::7/32</em></li>
+ </ul>
+ </small>
+ </td></tr>
<tr>
<td class="postblock">Board(s)</td>
<td>