From 0e07daa5f1f8606d28ba3157ee164062489530fb Mon Sep 17 00:00:00 2001 From: Tobias Herre Date: Fri, 3 Nov 2023 08:53:12 +0100 Subject: [PATCH] Install optional rspamd scripts --- dovecot.cf | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/dovecot.cf b/dovecot.cf index 1c4fb85..9af177f 100644 --- a/dovecot.cf +++ b/dovecot.cf @@ -5,7 +5,9 @@ bundle agent dovecot(cfg) { classes: - "use_ssl" expression => strcmp("$(cfg[ssl])","true"); + "use_ssl" expression => strcmp("$(cfg[ssl])","true"); + "rspamd_scripts" expression => strcmp("$(cfg[rspamd_scripts])","true"); + vars: freebsd:: "cfg_dir" string => "/usr/local/etc/dovecot"; @@ -75,6 +77,9 @@ methods: "any" usebundle => wmde_install_packages(@(pkgs),"dovecot"); "any" usebundle => wmde_service("$(service_name)","dovecot_kept","dovecot_repaired"), depends_on => @(service_deps); + rspamd_scripts:: + "any" usebundle => dovecot_install_rspamd_sieve_scripts("$(dovecot.cfg_dir)/rspamd"), + depends_on => {"dovecot_pkgs_installed"}; files: "$(cfg_dir)/." @@ -166,6 +171,7 @@ bundle agent install_global_sieve_script( filename , content) { vars: "rep_class" string =>"global_sieve_repaired_$(filename)"; + files: "$(filename)" create => "true", @@ -175,12 +181,103 @@ files: classes => if_repaired (sieve_repaired); commands: -# sieve_repaired:: -# "$(dovecot.sievec_exe)" -# args => "$(filename)", -# depends_on => { "global_sieve_$(filename)_created" }; + sieve_repaired:: + "$(dovecot.sievec_exe)" + args => "$(filename)", + depends_on => { "global_sieve_$(filename)_created" }; +reports: + +} + +bundle agent dovecot_install_sieve_script( filename , content, cls) +{ +vars: + "rep_class" string =>"global_sieve_$(filename)_repaired"; + +files: + "$(filename)" + create => "true", + content => "$(content)", + perms => m("644"), + handle => "sieve_$(filename)_created", + classes => if_repaired ("$(cls)_repaired"); + +commands: + "$(cls)_repaired":: + "$(dovecot.sievec_exe)" + args => "$(filename)", + depends_on => { "sieve_$(filename)_created" }; reports: } + + + +bundle agent dovecot_rspamd_sieve_vars(read) +{ +classes: + "$(read)"; +vars: +# do_read:: +# "ham_script" string => readfile("$(def.wmde_lib/scripts/rspamd-learn-ham.sieve.mustache)"); +# "spam_script" string => readfile("$(def.wmde_lib/scripts/rspamd-learn-ham.sieve.mustache)"); +# "ham_sh" string => readfile("$(def.wmde_lib/scripts/rspamd-learn-ham.sieve.mustache)"); +# "spam_sh" string => readfile("$(def.wmde_lib/scripts/rspamd-learn-ham.sieve.mustache)"); + +} + +bundle agent dovecot_install_rspamd_sieve_scripts(target_dir) +{ +methods: + "any" usebundle => dovecot_rspamd_sieve_vars("do_read"), + handle => "dovecot_rspamd_vars_ready"; +files: + "$(target_dir)/." + create => "true", + perms => m("755"), + handle => "dovecot_install_rspamd_sieve_scripts_dir_created"; + +methods: + "any" usebundle => dovecot_install_sieve_script( "$(target_dir)/rspamd-learn-ham.sieve", +# string_mustache( + readfile("$(def.wmde_lib)/scripts/dovecot/rspamd-learn-ham.sieve.mustache") +# ), + , "dovecot_sieve_ham" + ) ,depends_on => {"dovecot_install_rspamd_sieve_scripts_dir_created"}; + "any" usebundle => dovecot_install_sieve_script( "$(target_dir)/rspamd-learn-spam.sieve", +# string_mustache( + readfile("$(def.wmde_lib)/scripts/dovecot/rspamd-learn-spam.sieve.mustache") +# ) + , "dovecot_sieve_spam" + + ) ,depends_on => {"dovecot_install_rspamd_sieve_scripts_dir_created"}; + +files: + + "$(target_dir)/rspamd-learn-ham.sh" + create => "true", + content => string_mustache( + readfile("$(def.wmde_lib)/scripts/dovecot/rspamd-learn-ham.sh.mustache") + ), + perms => m("755"), + depends_on => {"dovecot_install_rspamd_sieve_scripts_dir_created"}; + + "$(target_dir)/rspamd-learn-spam.sh" + create => "true", + content => string_mustache( + readfile("$(def.wmde_lib)/scripts/dovecot/rspamd-learn-spam.sh.mustache") + ), + perms => m("755"), + depends_on => {"dovecot_install_rspamd_sieve_scripts_dir_created"}; + + + +reports: + "LOADER: $(def.wmde_lib)/scripts/dovecot/rspamd-learn-ham.sieve.mustache"; + + + +} +