From b239a07aa42d0fcba8cb84c554674c744d872041 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 25 Nov 2023 20:17:48 +0100 Subject: wip --- 7/firewall.pl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to '7/firewall.pl') 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)). -- cgit v1.2.3