iptables-converter - python classes

iptables_converter.py:

convert iptables commands within a script into a correspondig iptables-save script

default filename to read is rules, to read some other
file, append: -s filename

output is written to stdout for maximum flexibilty

Author: Johannes Hubertz <johannes@hubertz.de> Date: 2015-03-17 version: 0.9.8 License: GNU General Public License version 3 or later

Have Fun!

class iptables_converter.Chains(name, tables)

this is for one type of tables

put_into_fgr(content)

fill this line into this tabular

reset()

name is one of filter, nat, raw, mangle, tables is a list of tables in that table-class

class iptables_converter.ConverterError(message)

on accidential case of error show given reason

class iptables_converter.Tables(fname='reference-one')

some chaingroups in tables are predef: filter, nat, mangle, raw

put_into_tables(line)

put line into matching Chains-object

read_file(fname)

read file into Tables-object

reset(fname)

all predefined Chains aka lists are setup as new here

table_printout()

printout nonempty tabulars in fixed sequence

iptables_converter.main()

main parses options, filnames and the like one option (-s) may be given: input-filename if none given, it defaults to: rules

class iptables_converter.Chains(name, tables)

this is for one type of tables

put_into_fgr(content)

fill this line into this tabular

reset()

name is one of filter, nat, raw, mangle, tables is a list of tables in that table-class

class iptables_converter.Tables(fname='reference-one')

some chaingroups in tables are predef: filter, nat, mangle, raw

put_into_tables(line)

put line into matching Chains-object

read_file(fname)

read file into Tables-object

reset(fname)

all predefined Chains aka lists are setup as new here

table_printout()

printout nonempty tabulars in fixed sequence

class iptables_converter_tests.Chains_Test(methodName='runTest')

some tests for class Chain

test_01_create_a_chain_object()

Chain 01: create a Filter group, f.e. filter

test_02_prove_policies()

Chain 02: check 3 valid policies, 1 exception

test_03_tables_names()

Chain 03: 3 cases OK, 1 Exception

test_04_flush()

Chain 04: flush filter group, 2 rules and an invalid chain

test_05_new_chain()

Chain 05: create a new chain in filtergroup,

test_06_new_existing_chain_fails()

Chain 06: create an exsiting chain should fail

test_07_insert_rule_fail()

Chain 07: insert a rule into an empty chain fails

test_08_insert_rule_fail()

Chain 08: insert a rule into a non_existing chain fails

test_09_insert_rule_works()

Chain 09: insert a rule into a nonempty chain works at start

test_10_append_rule()

Chain 10: append a rule to a chain

test_11_remove_predef_chain()

Chain 11: try to remove a prefined chain

test_12_remove_chain()

Chain 12: try to remove an existing chain

test_13_illegal_command()

Chain 13: try an ilegal command

class iptables_converter_tests.Tables_Test(methodName='runTest')

Tables: some first tests for the class

test_01_create_a_tables_object()

Tables 01: create a Tables object, check chains

test_02_nat_prerouting()

Tables 02: nat PREROUTING entry

test_03_mangle_table()

Tables 03: mangle INPUT entry

test_04_raw_table()

Tables 04: raw OUTPUT entry

test_05_not_existing_chain()

Tables 05: INPUT to not existing chain

test_06_read_not_existing_file()

Tables 06: read non existing file

test_07_read_empty_file()

Tables 07: read empty file (in relation to iptables-commands)

test_08_reference_one()

Tables 08: read default file: reference-one, check chains

test_09_shell_variables()

Tables 09: read buggy file with shell variables

test_10_shell_functions()

Tables 10: read buggy file with shell functions