diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-25 20:17:48 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2023-11-25 20:17:48 +0100 |
commit | b239a07aa42d0fcba8cb84c554674c744d872041 (patch) | |
tree | 6a30543307b394e339103600d8c43f518e06b009 /7/firewall.pl | |
parent | 8062753241f2c510c94b0fec6f2552950e0c8014 (diff) | |
download | prolog-firewall-b239a07aa42d0fcba8cb84c554674c744d872041.tar.gz prolog-firewall-b239a07aa42d0fcba8cb84c554674c744d872041.tar.bz2 prolog-firewall-b239a07aa42d0fcba8cb84c554674c744d872041.tar.xz prolog-firewall-b239a07aa42d0fcba8cb84c554674c744d872041.zip |
wip
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)). |