mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-23 00:29:59 +02:00
clean up fields
This commit is contained in:
@ -17,13 +17,35 @@ Usage (module):
|
|||||||
|
|
||||||
Schema:
|
Schema:
|
||||||
|
|
||||||
[
|
{
|
||||||
{
|
"status": string,
|
||||||
"ufw": string,
|
"logging": string,
|
||||||
"bar": boolean,
|
"logging_level": string,
|
||||||
"baz": integer
|
"default": string,
|
||||||
}
|
"new_profiles": string,
|
||||||
]
|
"rules": [
|
||||||
|
{
|
||||||
|
"action": string,
|
||||||
|
"action_direction": string, # null if blank
|
||||||
|
"index": string, # null if blank
|
||||||
|
"network_protocol": string,
|
||||||
|
"to_ip": string,
|
||||||
|
"to_subnet": integer,
|
||||||
|
"to_interface": string,
|
||||||
|
"to_transport": string,
|
||||||
|
"to_start_port": integer, # null if to_service is set
|
||||||
|
"to_end_port": integer, # null if to_service is set
|
||||||
|
"to_service": string, # null if start/end ports above set
|
||||||
|
"from_ip": string,
|
||||||
|
"from_subnet": integer,
|
||||||
|
"from_interface": string,
|
||||||
|
"from_transport": string,
|
||||||
|
"from_start_port": integer, # null if from_service is set
|
||||||
|
"from_end_port": integer, # null if from_service is set
|
||||||
|
"from_service": string, # null if start/end ports above set
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
@ -145,18 +167,36 @@ def _parse_to_from(linedata, direction, rule_obj=None):
|
|||||||
|
|
||||||
# find the numeric port(s)
|
# find the numeric port(s)
|
||||||
linedata_list = linedata.split(':', maxsplit=1)
|
linedata_list = linedata.split(':', maxsplit=1)
|
||||||
if len(linedata_list) == 2 and linedata_list[1].isnumeric():
|
if len(linedata_list) == 2 and linedata_list[1].strip().isnumeric():
|
||||||
rule_obj[direction + '_start_port'] = linedata_list[0]
|
rule_obj[direction + '_start_port'] = linedata_list[0].strip()
|
||||||
rule_obj[direction + '_end_port'] = linedata_list[1]
|
rule_obj[direction + '_end_port'] = linedata_list[1].strip()
|
||||||
linedata = ''
|
linedata = ''
|
||||||
elif len(linedata_list) == 1 and linedata_list[0].isnumeric():
|
elif len(linedata_list) == 1 and linedata_list[0].strip().isnumeric():
|
||||||
rule_obj[direction + '_start_port'] = linedata_list[0]
|
rule_obj[direction + '_start_port'] = linedata_list[0].strip()
|
||||||
rule_obj[direction + '_end_port'] = linedata_list[0]
|
rule_obj[direction + '_end_port'] = linedata_list[0].strip()
|
||||||
linedata = ''
|
linedata = ''
|
||||||
|
|
||||||
# only thing left should be the service name.
|
# only thing left should be the service name.
|
||||||
if linedata.strip():
|
if linedata.strip():
|
||||||
rule_obj[direction + '_service'] = linedata.strip()
|
rule_obj[direction + '_service'] = linedata.strip()
|
||||||
|
rule_obj[direction + '_start_port'] = None
|
||||||
|
rule_obj[direction + '_end_port'] = None
|
||||||
|
|
||||||
|
# check if to/from IP addresses exist. If not, set to 0.0.0.0/0 or ::/0
|
||||||
|
if direction + '_ip' not in rule_obj:
|
||||||
|
if rule_obj.get('network_protocol') == 'ipv6':
|
||||||
|
rule_obj[direction + '_ip'] = '::'
|
||||||
|
rule_obj[direction + '_subnet'] = '0'
|
||||||
|
elif rule_obj.get('network_protocol') == 'ipv4':
|
||||||
|
rule_obj[direction + '_ip'] = '0.0.0.0'
|
||||||
|
rule_obj[direction + '_subnet'] = '0'
|
||||||
|
|
||||||
|
# finally ensure service or ports exist. If not, set default values
|
||||||
|
if not rule_obj.get(direction + '_service'):
|
||||||
|
if not rule_obj.get(direction + '_start_port'):
|
||||||
|
rule_obj[direction + '_start_port'] = '0'
|
||||||
|
rule_obj[direction + '_end_port'] = '65535'
|
||||||
|
rule_obj[direction + '_service'] = None
|
||||||
|
|
||||||
return rule_obj
|
return rule_obj
|
||||||
|
|
||||||
@ -192,7 +232,12 @@ def parse(data, raw=False, quiet=False):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if line.startswith('Logging: '):
|
if line.startswith('Logging: '):
|
||||||
raw_output['logging'] = line.split(': ', maxsplit=1)[1]
|
log_line = line.split(': ', maxsplit=1)
|
||||||
|
log_line = log_line[1]
|
||||||
|
log_line = log_line.split()
|
||||||
|
raw_output['logging'] = log_line[0]
|
||||||
|
if len(log_line) == 2:
|
||||||
|
raw_output['logging_level'] = log_line[1].replace('(', '').replace(')', '').strip()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.startswith('Default: '):
|
if line.startswith('Default: '):
|
||||||
|
Reference in New Issue
Block a user