@@ -192,7 +192,7 @@ def output_firewall_vertical(rules, headers, adjust=True):
192192 print (tabulate .tabulate (transformed_rule , tablefmt = "presto" ))
193193 print ()
194194
195- def output_firewall_name (family , hook , priority , firewall_conf , single_rule_id = None ):
195+ def output_firewall_name (family , hook , priority , firewall_conf , single_rule_id = None , detail = False ):
196196 print (f'\n ---------------------------------\n { family } Firewall "{ hook } { priority } "\n ' )
197197
198198 details = get_nftables_details (family , hook , priority )
@@ -226,10 +226,10 @@ def output_firewall_name(family, hook, priority, firewall_conf, single_rule_id=N
226226 rows .append (row )
227227
228228 if rows :
229- if args . rule :
229+ if single_rule_id :
230230 rows .pop ()
231231
232- if args . detail :
232+ if detail :
233233 header = ['Rule' , 'Description' , 'Action' , 'Protocol' , 'Packets' , 'Bytes' , 'Conditions' ]
234234 output_firewall_vertical (rows , header )
235235 else :
@@ -238,7 +238,7 @@ def output_firewall_name(family, hook, priority, firewall_conf, single_rule_id=N
238238 rows [rows .index (i )].pop (1 )
239239 print (tabulate .tabulate (rows , header ) + '\n ' )
240240
241- def output_firewall_state_policy (family ):
241+ def output_firewall_state_policy (family , detail = None ):
242242 if family == 'bridge' :
243243 return {}
244244 print (f'\n ---------------------------------\n { family } State Policy\n ' )
@@ -254,10 +254,7 @@ def output_firewall_state_policy(family):
254254 rows .append (row )
255255
256256 if rows :
257- if args .rule :
258- rows .pop ()
259-
260- if args .detail :
257+ if detail :
261258 header = ['State' , 'Conditions' , 'Packets' , 'Bytes' ]
262259 output_firewall_vertical (rows , header )
263260 else :
@@ -266,7 +263,7 @@ def output_firewall_state_policy(family):
266263 rows [rows .index (i )].pop (1 )
267264 print (tabulate .tabulate (rows , header ) + '\n ' )
268265
269- def output_firewall_name_statistics (family , hook , prior , prior_conf , single_rule_id = None ):
266+ def output_firewall_name_statistics (family , hook , prior , prior_conf , single_rule_id = None , detail = None ):
270267 print (f'\n ---------------------------------\n { family } Firewall "{ hook } { prior } "\n ' )
271268
272269 details = get_nftables_details (family , hook , prior )
@@ -384,7 +381,7 @@ def output_firewall_name_statistics(family, hook, prior, prior_conf, single_rule
384381 rows .append (row )
385382
386383 if rows :
387- if args . detail :
384+ if detail :
388385 header = ['Rule' , 'Description' , 'Packets' , 'Bytes' , 'Action' , 'Source' , 'Destination' , 'Inbound-Interface' , 'Outbound-interface' ]
389386 output_firewall_vertical (rows , header )
390387 else :
@@ -393,7 +390,7 @@ def output_firewall_name_statistics(family, hook, prior, prior_conf, single_rule
393390 rows [rows .index (i )].pop (1 )
394391 print (tabulate .tabulate (rows , header ) + '\n ' )
395392
396- def show_firewall ():
393+ def show_firewall (detail = None ):
397394 print ('Rulesets Information' )
398395
399396 conf = Config ()
@@ -405,14 +402,14 @@ def show_firewall():
405402 for family in ['ipv4' , 'ipv6' , 'bridge' ]:
406403 if 'global_options' in firewall :
407404 if 'state_policy' in firewall ['global_options' ]:
408- output_firewall_state_policy (family )
405+ output_firewall_state_policy (family , detail = detail )
409406
410407 if family in firewall :
411408 for hook , hook_conf in firewall [family ].items ():
412409 for prior , prior_conf in firewall [family ][hook ].items ():
413- output_firewall_name (family , hook , prior , prior_conf )
410+ output_firewall_name (family , hook , prior , prior_conf , detail = detail )
414411
415- def show_firewall_family (family ):
412+ def show_firewall_family (family , detail = None ):
416413 print (f'Rulesets { family } Information' )
417414
418415 conf = Config ()
@@ -423,30 +420,30 @@ def show_firewall_family(family):
423420
424421 if 'global_options' in firewall :
425422 if 'state_policy' in firewall ['global_options' ]:
426- output_firewall_state_policy (family )
423+ output_firewall_state_policy (family , detail = detail )
427424
428425 if family in firewall :
429426 for hook , hook_conf in firewall [family ].items ():
430427 for prior , prior_conf in firewall [family ][hook ].items ():
431- output_firewall_name (family , hook , prior , prior_conf )
428+ output_firewall_name (family , hook , prior , prior_conf , detail = detail )
432429
433- def show_firewall_name (family , hook , priority ):
430+ def show_firewall_name (family , hook , priority , detail = None ):
434431 print ('Ruleset Information' )
435432
436433 conf = Config ()
437434 firewall = get_config_node (conf , 'firewall' , family , hook , priority )
438435 if firewall :
439- output_firewall_name (family , hook , priority , firewall )
436+ output_firewall_name (family , hook , priority , firewall , detail = detail )
440437
441- def show_firewall_rule (family , hook , priority , rule_id ):
438+ def show_firewall_rule (family , hook , priority , rule_id , detail = None ):
442439 print ('Rule Information' )
443440
444441 conf = Config ()
445442 firewall = get_config_node (conf , 'firewall' , family , hook , priority )
446443 if firewall :
447- output_firewall_name (family , hook , priority , firewall , rule_id )
444+ output_firewall_name (family , hook , priority , firewall , rule_id , detail = detail )
448445
449- def show_firewall_group (name = None ):
446+ def show_firewall_group (name = None , detail = None ):
450447 conf = Config ()
451448 firewall = get_config_node (conf , node = 'firewall' )
452449
@@ -594,7 +591,7 @@ def find_references(group_type, group_name):
594591 for group_type , group_type_conf in firewall ['group' ].items ():
595592 # interate over dynamic-groups
596593 if group_type == 'dynamic_group' :
597- if not args . detail :
594+ if not detail :
598595 header_tail = ['Timeout' , 'Expires' ]
599596
600597 for dynamic_type in ['address_group' , 'ipv6_address_group' ]:
@@ -611,7 +608,7 @@ def find_references(group_type, group_name):
611608 members = get_nftables_group_members (family , 'vyos_filter' , f'{ prefix } { dynamic_name } ' )
612609
613610 if not members :
614- if args . detail :
611+ if detail :
615612 row .append ('N/D' )
616613 else :
617614 row += ["N/D" ] * 3
@@ -629,7 +626,7 @@ def find_references(group_type, group_name):
629626 timeout = str (member .get ('timeout' , 'N/D' ))
630627 expires = str (member .get ('expires' , 'N/D' ))
631628
632- if args . detail :
629+ if detail :
633630 row .append (f'{ val } (timeout: { timeout } , expires: { expires } )' )
634631 continue
635632
@@ -639,7 +636,7 @@ def find_references(group_type, group_name):
639636 row += [val , timeout , expires ]
640637 rows .append (row )
641638
642- if args . detail :
639+ if detail :
643640 header_tail += ["" ] * (len (members ) - 1 )
644641 rows .append (row )
645642
@@ -657,7 +654,7 @@ def find_references(group_type, group_name):
657654 if 'url' in remote_conf :
658655 # display only the url if no members are found for both views
659656 if not members and not members6 :
660- if args . detail :
657+ if detail :
661658 header_tail = ['IPv6 Members' , 'Remote URL' ]
662659 row .append ('N/D' )
663660 row .append ('N/D' )
@@ -667,7 +664,7 @@ def find_references(group_type, group_name):
667664 rows .append (row )
668665 else :
669666 # display all table elements in detail view
670- if args . detail :
667+ if detail :
671668 header_tail = ['IPv6 Members' , 'Remote URL' ]
672669 if members :
673670 row .append (' ' .join (members ))
@@ -707,7 +704,7 @@ def find_references(group_type, group_name):
707704
708705 if rows :
709706 print ('Firewall Groups\n ' )
710- if args . detail :
707+ if detail :
711708 header = ['Name' , 'Description' , 'Type' , 'References' , 'Members' ] + header_tail
712709 output_firewall_vertical (rows , header , adjust = False )
713710 else :
@@ -716,7 +713,7 @@ def find_references(group_type, group_name):
716713 rows [rows .index (i )].pop (1 )
717714 print (tabulate .tabulate (rows , header ))
718715
719- def show_summary ():
716+ def show_summary (detail = None ):
720717 print ('Ruleset Summary' )
721718
722719 conf = Config ()
@@ -760,9 +757,9 @@ def show_summary():
760757 print ('\n Bridge Ruleset:\n ' )
761758 print (tabulate .tabulate (br_out , header ) + '\n ' )
762759
763- show_firewall_group ()
760+ show_firewall_group (detail = detail )
764761
765- def show_statistics ():
762+ def show_statistics (detail = None ):
766763 print ('Rulesets Statistics' )
767764
768765 conf = Config ()
@@ -779,7 +776,7 @@ def show_statistics():
779776 if family in firewall :
780777 for hook , hook_conf in firewall [family ].items ():
781778 for prior , prior_conf in firewall [family ][hook ].items ():
782- output_firewall_name_statistics (family , hook ,prior , prior_conf )
779+ output_firewall_name_statistics (family , hook ,prior , prior_conf , detail = detail )
783780
784781if __name__ == '__main__' :
785782 parser = argparse .ArgumentParser ()
@@ -796,16 +793,16 @@ def show_statistics():
796793
797794 if args .action == 'show' :
798795 if not args .rule :
799- show_firewall_name (args .family , args .hook , args .priority )
796+ show_firewall_name (args .family , args .hook , args .priority , args . detail )
800797 else :
801- show_firewall_rule (args .family , args .hook , args .priority , args .rule )
798+ show_firewall_rule (args .family , args .hook , args .priority , args .rule , args . detail )
802799 elif args .action == 'show_all' :
803- show_firewall ()
800+ show_firewall (args . detail )
804801 elif args .action == 'show_family' :
805- show_firewall_family (args .family )
802+ show_firewall_family (args .family , args . detail )
806803 elif args .action == 'show_group' :
807- show_firewall_group (args .name )
804+ show_firewall_group (args .name , args . detail )
808805 elif args .action == 'show_statistics' :
809- show_statistics ()
806+ show_statistics (args . detail )
810807 elif args .action == 'show_summary' :
811- show_summary ()
808+ show_summary (args . detail )
0 commit comments