1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/ufw.md

246 lines
4.6 KiB
Markdown
Raw Normal View History

2021-04-21 07:51:32 -07:00
[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.ufw"></a>
2021-04-21 07:51:32 -07:00
# jc.parsers.ufw
2022-01-25 17:07:47 -08:00
2021-04-21 07:51:32 -07:00
jc - JSON CLI output utility `ufw status` command output parser
Usage (cli):
2022-01-25 17:07:47 -08:00
$ ufw status | jc --ufw
2021-04-21 07:51:32 -07:00
2022-01-25 17:07:47 -08:00
or
2021-04-21 07:51:32 -07:00
2022-01-25 17:07:47 -08:00
$ jc ufw status
2021-04-21 07:51:32 -07:00
Usage (module):
2022-01-25 17:07:47 -08:00
import jc
result = jc.parse('ufw', ufw_command_output)
2022-01-18 15:38:03 -08:00
2022-01-25 17:07:47 -08:00
or
2022-01-18 15:38:03 -08:00
2022-01-25 17:07:47 -08:00
import jc.parsers.ufw
result = jc.parsers.ufw.parse(ufw_command_output)
2021-04-21 07:51:32 -07:00
Schema:
2022-01-25 17:07:47 -08:00
{
"status": string,
"logging": string,
"logging_level": string,
"default": string,
"new_profiles": string,
"rules": [
{
"action": string,
"action_direction": string, # null if blank
"index": integer, # null if blank
"network_protocol": string,
"to_ip": string,
"to_ip_prefix": integer,
"to_interface": string,
"to_transport": string,
"to_ports": [
integer
],
"to_port_ranges": [
{
"start": integer,
"end": integer
}
],
"to_service": string, # [0]
"from_ip": string,
"from_ip_prefix": integer,
"from_interface": string,
"from_transport": string,
"from_ports": [
integer
],
"from_port_ranges": [
{
"start": integer,
"end": integer
}
],
"from_service": string, # [1]
"comment": string # null if no comment
}
]
}
[0] null if any 'to' ports or port_ranges are set
[1] null if any 'from' ports or port_ranges are set
**Examples**:
$ ufw status verbose | jc --ufw -p
{
- `"status"` - "active",
- `"logging"` - "on",
- `"logging_level"` - "low",
- `"default"` - "deny (incoming), allow (outgoing), disabled (routed)",
- `"new_profiles"` - "skip",
- `"rules"` - [
{
- `"action"` - "ALLOW",
- `"action_direction"` - "IN",
- `"index"` - null,
- `"network_protocol"` - "ipv4",
- `"to_interface"` - "any",
- `"to_transport"` - "any",
- `"to_service"` - null,
- `"to_ports"` - [
22
],
- `"to_ip"` - "0.0.0.0",
- `"to_ip_prefix"` - 0,
- `"comment"` - null,
- `"from_ip"` - "0.0.0.0",
- `"from_ip_prefix"` - 0,
- `"from_interface"` - "any",
- `"from_transport"` - "any",
- `"from_port_ranges"` - [
{
- `"start"` - 0,
- `"end"` - 65535
}
],
- `"from_service"` - null
},
{
- `"action"` - "ALLOW",
- `"action_direction"` - "IN",
- `"index"` - null,
- `"network_protocol"` - "ipv4",
- `"to_interface"` - "any",
- `"to_transport"` - "tcp",
- `"to_service"` - null,
- `"to_ports"` - [
80,
443
],
- `"to_ip"` - "0.0.0.0",
- `"to_ip_prefix"` - 0,
- `"comment"` - null,
- `"from_ip"` - "0.0.0.0",
- `"from_ip_prefix"` - 0,
- `"from_interface"` - "any",
- `"from_transport"` - "any",
- `"from_port_ranges"` - [
{
- `"start"` - 0,
- `"end"` - 65535
}
],
- `"from_service"` - null
},
...
]
}
$ ufw status verbose | jc --ufw -p -r
{
- `"status"` - "active",
- `"logging"` - "on",
- `"logging_level"` - "low",
- `"default"` - "deny (incoming), allow (outgoing), disabled (routed)",
- `"new_profiles"` - "skip",
- `"rules"` - [
{
- `"action"` - "ALLOW",
- `"action_direction"` - "IN",
- `"index"` - null,
- `"network_protocol"` - "ipv4",
- `"to_interface"` - "any",
- `"to_transport"` - "any",
- `"to_service"` - null,
- `"to_ports"` - [
"22"
],
- `"to_ip"` - "0.0.0.0",
- `"to_ip_prefix"` - "0",
- `"comment"` - null,
- `"from_ip"` - "0.0.0.0",
- `"from_ip_prefix"` - "0",
- `"from_interface"` - "any",
- `"from_transport"` - "any",
- `"from_port_ranges"` - [
{
- `"start"` - "0",
- `"end"` - "65535"
}
],
- `"from_service"` - null
},
{
- `"action"` - "ALLOW",
- `"action_direction"` - "IN",
- `"index"` - null,
- `"network_protocol"` - "ipv4",
- `"to_interface"` - "any",
- `"to_transport"` - "tcp",
- `"to_service"` - null,
- `"to_ports"` - [
"80",
"443"
],
- `"to_ip"` - "0.0.0.0",
- `"to_ip_prefix"` - "0",
- `"comment"` - null,
- `"from_ip"` - "0.0.0.0",
- `"from_ip_prefix"` - "0",
- `"from_interface"` - "any",
- `"from_transport"` - "any",
- `"from_port_ranges"` - [
{
- `"start"` - "0",
- `"end"` - "65535"
}
],
- `"from_service"` - null
},
...
]
}
<a id="jc.parsers.ufw.info"></a>
## info Objects
2021-04-21 07:51:32 -07:00
```python
2022-01-25 17:07:47 -08:00
class info()
2021-04-21 07:51:32 -07:00
```
2022-01-25 17:07:47 -08:00
2021-04-21 07:51:32 -07:00
Provides parser metadata (version, author, etc.)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.ufw.parse"></a>
#### parse
2021-04-21 07:51:32 -07:00
```python
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False)
2021-04-21 07:51:32 -07:00
```
Main text parsing function
2022-01-25 17:07:47 -08:00
**Arguments**:
2021-04-21 07:51:32 -07:00
2022-01-25 17:07:47 -08:00
- `data` - (string) text data to parse
- `raw` - (boolean) unprocessed output if True
- `quiet` - (boolean) suppress warning messages if True
2021-04-21 07:51:32 -07:00
2022-01-25 17:07:47 -08:00
**Returns**:
2021-04-21 07:51:32 -07:00
2022-01-25 17:07:47 -08:00
Dictionary. Raw or processed structured data.
2021-04-21 07:51:32 -07:00
## Parser Information
Compatibility: linux
2021-12-01 16:12:51 -08:00
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)