ui,fw: allow to use CIDR notation to add IPs

When adding firewall rules with IPs ranges, allow to use CIDR notation
(1.2.3.4/56).
Previously only 2.2.2.3-2.2.2.100 was supported.
This commit is contained in:
Gustavo Iñiguez Goia 2023-04-15 00:41:22 +02:00
parent fe88841640
commit fb27e4cbb1
Failed to generate hash of commit

View file

@ -1,6 +1,7 @@
import sys
import os
import os.path
import ipaddress
from PyQt5 import QtCore, QtGui, uic, QtWidgets
from PyQt5.QtCore import QCoreApplication as QC
@ -1136,10 +1137,20 @@ class FwRuleDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
sk['key'] = statem_value
statem_value = ""
elif st_idx == self.STATM_DEST_IP or \
st_idx == self.STATM_SOURCE_IP or \
st_idx == self.STATM_DPORT or \
st_idx == self.STATM_SPORT:
elif st_idx == self.STATM_DEST_IP or st_idx == self.STATM_SOURCE_IP:
statement = statem_opts
# convert network u.x.y.z/nn to 1.2.3.4-1.255.255.255
# format.
# FIXME: This should be supported by the daemon,
# instead of converting it here.
if "/" in statem_value:
try:
net = ipaddress.ip_network(statem_value)
hosts = list(net)
statem_value = "{0}-{1}".format(str(hosts[0]), str(hosts[-1]))
except Exception as e:
return None, None, None, QC.translate("firewall", "IP network format error, {0}".format(e))
elif st_idx == self.STATM_DPORT or st_idx == self.STATM_SPORT:
statement = statem_opts
try:
if "," in statem_value or "-" in statem_value or val_idx < 1: