mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-09 02:32:46 +01:00
Merge pull request #6220 from Security-Onion-Solutions/fix/revert-python-validation
Fix/revert python validation
This commit is contained in:
@@ -390,30 +390,20 @@ has_uppercase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
valid_cidr() {
|
valid_cidr() {
|
||||||
local cidr=$1
|
# Verify there is a backslash in the string
|
||||||
|
echo "$1" | grep -qP "^[^/]+/[^/]+$" || return 1
|
||||||
|
|
||||||
read -r -d '' cidr_python <<- EOM
|
local cidr
|
||||||
import ipaddress
|
local ip
|
||||||
import sys
|
|
||||||
|
|
||||||
def validate_cidr(cidr: str) -> bool:
|
cidr=$(echo "$1" | sed 's/.*\///')
|
||||||
# We want the string to be a cidr block and not a single ip
|
ip=$(echo "$1" | sed 's/\/.*//' )
|
||||||
if '/' not in cidr:
|
|
||||||
return False
|
|
||||||
try:
|
|
||||||
ipaddress.ip_network(cidr)
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
if validate_cidr('$cidr'):
|
if valid_ip4 "$ip"; then
|
||||||
sys.exit(0)
|
[[ $cidr =~ ([0-9]|[1-2][0-9]|3[0-2]) ]] && return 0 || return 1
|
||||||
else:
|
else
|
||||||
sys.exit(1)
|
return 1
|
||||||
EOM
|
fi
|
||||||
|
|
||||||
python3 -c "$cidr_python"
|
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
valid_cidr_list() {
|
valid_cidr_list() {
|
||||||
@@ -457,26 +447,7 @@ valid_hostname() {
|
|||||||
valid_ip4() {
|
valid_ip4() {
|
||||||
local ip=$1
|
local ip=$1
|
||||||
|
|
||||||
local ip_python
|
echo "$ip" | grep -qP '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' && return 0 || return 1
|
||||||
read -r -d '' ip_python <<- EOM
|
|
||||||
import ipaddress
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def validate_ip(ip: str) -> bool:
|
|
||||||
try:
|
|
||||||
ipaddress.ip_address(ip)
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
if validate_ip('$ip'):
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
|
||||||
sys.exit(1)
|
|
||||||
EOM
|
|
||||||
|
|
||||||
python3 -c "$ip_python"
|
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
valid_int() {
|
valid_int() {
|
||||||
|
|||||||
Reference in New Issue
Block a user