diff options
Diffstat (limited to '7/firewall.pl')
-rw-r--r-- | 7/firewall.pl | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/7/firewall.pl b/7/firewall.pl index 9e00afe..7e7b7e7 100644 --- a/7/firewall.pl +++ b/7/firewall.pl @@ -8,9 +8,10 @@ retract_all_from/1]). :- use_module(library(assoc)). +:- use_module(library(csv)). +:- use_module(library(dcgs)). :- use_module(library(files)). :- use_module(library(format)). -:- use_module(library(dcgs)). :- use_module(library(lists)). :- use_module(library(serialization/json)). @@ -26,7 +27,7 @@ warning(Msg) :- rules_from(From, Rules) :- findall( - fw_rule(H, Attr), + fw_rule(H, Attr), ( fw_rule(H, Attr), get_assoc("from", Attr, From) @@ -48,13 +49,23 @@ ansible_host(Basedir, [Host|Hosts]) :- atom_chars(Host, HostS), append(Basedir, [HostS], DirPs), path_segments(Dir, DirPs), - append(Basedir, [HostS, "firewall.yaml"], FilePs), + append(Basedir, [HostS, "firewall.csv"], FilePs), path_segments(File, FilePs), format("mkdir ~s~n", [Dir]), make_directory_path(Dir), - format("firewall: ~s~n", [File]), ansible_firewall(File, Host), ansible_host(Basedir, Hosts). +get_opt(Key, Assoc, Value) :- (get_assoc(Key, Assoc, Value) -> true; Value=''). + +to_csv(Host, Attrs, Row) :- + get_opt(family, Attrs, Family), + get_opt(src, Attrs, Src), + get_opt(dst, Attrs, Dst), + Row = [Host, Family, Src, Dst]. + ansible_firewall(File, Host) :- - true. + format("ansible_firewall: ~s~n", [File]), + findall(Attrs, fw_rule(Host, Attrs), Rules), + maplist(to_csv(Host), Rules, Rows), + write_csv(File, frame(['host','family','src','dst'], Rows)). |