diff options
author | l0crian1 <143656816+l0crian1@users.noreply.github.com> | 2024-04-05 08:48:15 -0400 |
---|---|---|
committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2024-04-06 09:57:25 +0000 |
commit | f08ccb6635d63c920b36f1d57b1ef4f3e6603e27 (patch) | |
tree | 5277945f6a09c14965ad7da352e18475050e10cc /src/op_mode/firewall.py | |
parent | 9a682c0a4116785f9611f7804f35c28db8fea2b5 (diff) | |
download | vyos-1x-f08ccb6635d63c920b36f1d57b1ef4f3e6603e27.tar.gz vyos-1x-f08ccb6635d63c920b36f1d57b1ef4f3e6603e27.zip |
T6188: Add description to detail view only
For readability in console sessions, moved the description column to only be shown in the detail view.
Changed wrapping in the detail view for description to 65 characters to prevent full line wrapping in console sessions.
(cherry picked from commit 4dba82c7517f4a93b9727d22104e4a339bad127a)
Diffstat (limited to 'src/op_mode/firewall.py')
-rwxr-xr-x | src/op_mode/firewall.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/op_mode/firewall.py b/src/op_mode/firewall.py index 26f3a5156..25554b781 100755 --- a/src/op_mode/firewall.py +++ b/src/op_mode/firewall.py @@ -92,7 +92,7 @@ def get_nftables_details(family, hook, priority): def output_firewall_vertical(rules, headers): for rule in rules: adjusted_rule = rule + [""] * (len(headers) - len(rule)) # account for different header length, like default-action - transformed_rule = [[header, textwrap.fill(adjusted_rule[i].replace('\n', ' '), 100)] for i, header in enumerate(headers)] # create key-pair list from headers and rules lists; wrap at 100 char + transformed_rule = [[header, textwrap.fill(adjusted_rule[i].replace('\n', ' '), 65)] for i, header in enumerate(headers)] # create key-pair list from headers and rules lists; wrap at 100 char print(tabulate.tabulate(transformed_rule, tablefmt="presto")) print() @@ -134,10 +134,13 @@ def output_firewall_name(family, hook, priority, firewall_conf, single_rule_id=N if args.rule: rows.pop() - header = ['Rule', 'Description', 'Action', 'Protocol', 'Packets', 'Bytes', 'Conditions'] if args.detail: + header = ['Rule', 'Description', 'Action', 'Protocol', 'Packets', 'Bytes', 'Conditions'] output_firewall_vertical(rows, header) else: + header = ['Rule', 'Action', 'Protocol', 'Packets', 'Bytes', 'Conditions'] + for i in rows: + rows[rows.index(i)].pop(1) print(tabulate.tabulate(rows, header) + '\n') def output_firewall_name_statistics(family, hook, prior, prior_conf, single_rule_id=None): @@ -254,10 +257,13 @@ def output_firewall_name_statistics(family, hook, prior, prior_conf, single_rule rows.append(row) if rows: - header = ['Rule', 'Description', 'Packets', 'Bytes', 'Action', 'Source', 'Destination', 'Inbound-Interface', 'Outbound-interface'] if args.detail: + header = ['Rule', 'Description', 'Packets', 'Bytes', 'Action', 'Source', 'Destination', 'Inbound-Interface', 'Outbound-interface'] output_firewall_vertical(rows, header) else: + header = ['Rule', 'Packets', 'Bytes', 'Action', 'Source', 'Destination', 'Inbound-Interface', 'Outbound-interface'] + for i in rows: + rows[rows.index(i)].pop(1) print(tabulate.tabulate(rows, header) + '\n') def show_firewall(): @@ -446,7 +452,6 @@ def show_firewall_group(name=None): return out - header = ['Name', 'Description','Type', 'References', 'Members'] rows = [] for group_type, group_type_conf in firewall['group'].items(): @@ -485,8 +490,12 @@ def show_firewall_group(name=None): if rows: print('Firewall Groups\n') if args.detail: + header = ['Name', 'Description','Type', 'References', 'Members'] output_firewall_vertical(rows, header) else: + header = ['Name', 'Type', 'References', 'Members'] + for i in rows: + rows[rows.index(i)].pop(1) print(tabulate.tabulate(rows, header)) def show_summary(): |