diff --git a/README.md b/README.md index d9c49018..584f2ed3 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ pip3 install jc | FreeBSD | `portsnap fetch update && cd /usr/ports/textproc/py-jc && make install clean` | | Ansible filter plugin | `ansible-galaxy collection install community.general` | -> For more packages and binaries, see https://kellyjonbrazil.github.io/jc-packaging/. +> For more packages and binaries, see the [jc packaging](https://kellyjonbrazil.github.io/jc-packaging/) site. ## Usage `jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`. @@ -182,6 +182,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio - `--timedatectl` enables the `timedatectl status` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/timedatectl)) - `--tracepath` enables the `tracepath` and `tracepath6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/tracepath)) - `--traceroute` enables the `traceroute` and `traceroute6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/traceroute)) +- `--ufw` enables the `ufw status` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ufw)) - `--uname` enables the `uname -a` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/uname)) - `--upower` enables the `upower` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/upower)) - `--uptime` enables the `uptime` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/uptime)) diff --git a/docs/parsers/ping.md b/docs/parsers/ping.md index 3e7db2b5..fe0c0bc6 100644 --- a/docs/parsers/ping.md +++ b/docs/parsers/ping.md @@ -97,7 +97,6 @@ Examples: ] } - $ ping -c 3 -p ff cnn.com | jc --ping -p -r { "destination_ip": "151.101.129.67", diff --git a/docs/parsers/ufw.md b/docs/parsers/ufw.md new file mode 100644 index 00000000..750c7026 --- /dev/null +++ b/docs/parsers/ufw.md @@ -0,0 +1,302 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + +# jc.parsers.ufw +jc - JSON CLI output utility `ufw status` command output parser + +Usage (cli): + + $ ufw status | jc --ufw + + or + + $ jc ufw status + +Usage (module): + + import jc.parsers.ufw + result = jc.parsers.ufw.parse(ufw_command_output) + +Schema: + + { + "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, # null if to_service is set + "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 any above are set + "from_ip": string, + "from_ip_prefix": integer, + "from_interface": string, + "from_transport": string, # null if from_service is set + "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 any above are set + } + ] + } + +Examples: + + $ ufw status verbose numbered | jc --ufw -p + { + "status": "active", + "logging": "on", + "logging_level": "low", + "default": "deny (incoming), allow (outgoing), deny (routed)", + "new_profiles": "skip", + "rules": [ + { + "action": "ALLOW", + "action_direction": "IN", + "index": 1, + "network_protocol": "ipv4", + "to_interface": "any", + "to_transport": "tcp", + "to_start_port": 22, + "to_end_port": 22, + "to_service": null, + "to_ip": "0.0.0.0", + "to_ip_prefix": "0", + "from_ip": "0.0.0.0", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": 0, + "from_end_port": 65535, + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": 2, + "network_protocol": "ipv6", + "to_interface": "any", + "to_transport": "tcp", + "to_start_port": 22, + "to_end_port": 22, + "to_service": null, + "to_ip": "::", + "to_ip_prefix": "0", + "from_ip": "::", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": 0, + "from_end_port": 65535, + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": 3, + "network_protocol": "ipv4", + "to_interface": "any", + "to_transport": null, + "to_service": "Apache Full", + "to_start_port": null, + "to_end_port": null, + "to_ip": "0.0.0.0", + "to_ip_prefix": "0", + "from_ip": "0.0.0.0", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": 0, + "from_end_port": 65535, + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": 4, + "network_protocol": "ipv6", + "to_interface": "any", + "to_ip": "2405:204:7449:49fc:f09a:6f4a:bc93:1955", + "to_ip_prefix": "128", + "to_transport": "any", + "to_start_port": 0, + "to_end_port": 65535, + "to_service": null, + "from_ip": "::", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": 0, + "from_end_port": 65535, + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": 5, + "network_protocol": "ipv4", + "to_interface": "en0", + "to_ip": "10.10.10.10", + "to_ip_prefix": "32", + "to_transport": "any", + "to_start_port": 0, + "to_end_port": 65535, + "to_service": null, + "from_ip": "0.0.0.0", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": 0, + "from_end_port": 65535, + "from_service": null + } + ] + } + + $ ufw status verbose numbered | jc --ufw -p -r + { + "status": "active", + "logging": "on", + "logging_level": "low", + "default": "deny (incoming), allow (outgoing), deny (routed)", + "new_profiles": "skip", + "rules": [ + { + "action": "ALLOW", + "action_direction": "IN", + "index": "1", + "network_protocol": "ipv4", + "to_interface": "any", + "to_transport": "tcp", + "to_start_port": "22", + "to_end_port": "22", + "to_service": null, + "to_ip": "0.0.0.0", + "to_ip_prefix": "0", + "from_ip": "0.0.0.0", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": "0", + "from_end_port": "65535", + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": "2", + "network_protocol": "ipv6", + "to_interface": "any", + "to_transport": "tcp", + "to_start_port": "22", + "to_end_port": "22", + "to_service": null, + "to_ip": "::", + "to_ip_prefix": "0", + "from_ip": "::", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": "0", + "from_end_port": "65535", + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": "3", + "network_protocol": "ipv4", + "to_interface": "any", + "to_transport": null, + "to_service": "Apache Full", + "to_start_port": null, + "to_end_port": null, + "to_ip": "0.0.0.0", + "to_ip_prefix": "0", + "from_ip": "0.0.0.0", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": "0", + "from_end_port": "65535", + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": "4", + "network_protocol": "ipv6", + "to_interface": "any", + "to_ip": "2405:204:7449:49fc:f09a:6f4a:bc93:1955", + "to_ip_prefix": "128", + "to_transport": "any", + "to_start_port": "0", + "to_end_port": "65535", + "to_service": null, + "from_ip": "::", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": "0", + "from_end_port": "65535", + "from_service": null + }, + { + "action": "ALLOW", + "action_direction": "IN", + "index": "5", + "network_protocol": "ipv4", + "to_interface": "en0", + "to_ip": "10.10.10.10", + "to_ip_prefix": "32", + "to_transport": "any", + "to_start_port": "0", + "to_end_port": "65535", + "to_service": null, + "from_ip": "0.0.0.0", + "from_ip_prefix": "0", + "from_interface": "any", + "from_transport": "any", + "from_start_port": "0", + "from_end_port": "65535", + "from_service": null + } + ] + } + + +## info +```python +info() +``` +Provides parser metadata (version, author, etc.) + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + +Returns: + + Dictionary. Raw or processed structured data. + +## Parser Information +Compatibility: linux + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/utils.md b/docs/utils.md index e245fd8c..1cac00ed 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -74,7 +74,7 @@ Returns: convert_to_int(value) ``` -Converts string input to integer by stripping all non-numeric characters +Converts string and float input to int. Strips all non-numeric characters from strings. Parameters: @@ -90,7 +90,7 @@ Returns: convert_to_float(value) ``` -Converts string input to float by stripping all non-numeric characters +Converts string and int input to float. Strips all non-numeric characters from strings. Parameters: diff --git a/jc/man/jc.1.gz b/jc/man/jc.1.gz index d860a611..3ceb719e 100644 Binary files a/jc/man/jc.1.gz and b/jc/man/jc.1.gz differ diff --git a/man/jc.1.gz b/man/jc.1.gz index d860a611..3ceb719e 100644 Binary files a/man/jc.1.gz and b/man/jc.1.gz differ