From: Clinton Ebadi Date: Tue, 6 May 2014 23:54:09 +0000 (-0400) Subject: Manage spamassassin preferences in shared space X-Git-Tag: release_20140509~4 X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/commitdiff_plain/ebb51f80568cc35cf3cd2f99a31a28f72526798d Manage spamassassin preferences in shared space --- diff --git a/configDefault/spamassassin.cfg b/configDefault/spamassassin.cfg index 9be1007..7f347a1 100644 --- a/configDefault/spamassassin.cfg +++ b/configDefault/spamassassin.cfg @@ -1,5 +1,8 @@ structure SpamAssassin :> SPAM_ASSASSIN_CONFIG = struct +val addrsDb = ConfigCore.sharedRoot ^ "/email/spamassassin/addrs" val addrsDir = "/etc/spamassassin/addrs" +val postReload = ConfigCore.sudo ^ " " ^ ConfigCore.installPrefix ^ "/sbin/domtool-publish spamassassin" + end diff --git a/configDefault/spamassassin.csg b/configDefault/spamassassin.csg index 5bbab44..a4930b1 100644 --- a/configDefault/spamassassin.csg +++ b/configDefault/spamassassin.csg @@ -1,5 +1,8 @@ signature SPAM_ASSASSIN_CONFIG = sig val addrsDir : string + val addrsDb : string + + val postReload : string end diff --git a/scripts/domtool-publish b/scripts/domtool-publish index 9eea020..0771867 100755 --- a/scripts/domtool-publish +++ b/scripts/domtool-publish @@ -71,6 +71,10 @@ case $1 in /bin/chgrp mail /etc/courier/exim.dat /bin/chmod o-r /etc/courier/exim.dat ;; + spamassassin) + SHAREDROOT=`domtool-config -path shared-root` + /usr/bin/rsync -r --delete ${SHAREDROOT}/email/spamassassin/addrs/ /etc/spamassassin/addrs + ;; smtplog) /bin/grep $2 /var/log/exim4/mainlog ;; diff --git a/src/mail/setsa.sig b/src/mail/setsa.sig index bc81859..5ec1020 100644 --- a/src/mail/setsa.sig +++ b/src/mail/setsa.sig @@ -1,5 +1,6 @@ (* HCoop Domtool (http://hcoop.sourceforge.net/) * Copyright (c) 2006, Adam Chlipala + * Copyright (c) 2014 Clinton Ebadi * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,5 +27,6 @@ signature SET_SA = sig val query : address -> bool val set : address * bool -> unit + val rebuild : unit -> bool end diff --git a/src/mail/setsa.sml b/src/mail/setsa.sml index ef60dca..32fa0ab 100644 --- a/src/mail/setsa.sml +++ b/src/mail/setsa.sml @@ -1,5 +1,6 @@ (* HCoop Domtool (http://hcoop.sourceforge.net/) * Copyright (c) 2006, Adam Chlipala + * Copyright (c) 2014 Clinton Ebadi * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,6 +21,8 @@ structure SetSA :> SET_SA = struct +open MsgTypes + datatype address = User of string | Email of string @@ -27,7 +30,7 @@ datatype address = fun address (User s) = s ^ "@localhost" | address (Email s) = s -fun file addr = OS.Path.joinDirFile {dir = Config.SpamAssassin.addrsDir, +fun file addr = OS.Path.joinDirFile {dir = Config.SpamAssassin.addrsDb, file = address addr} fun query addr = Posix.FileSys.access (file addr, []) @@ -38,4 +41,13 @@ fun set (addr, setting) = else OS.FileSys.remove (file addr) +fun rebuild () = + let + fun doNode (site, ok) = + (print ("New spamassassin data for node " ^ site ^ "\n"); + Connect.commandWorker (Domain.get_context (), site, MsgSaChanged)) + in + foldl doNode true Config.mailNodes_all + end + end diff --git a/src/main.sml b/src/main.sml index cc35c62..50f5e97 100644 --- a/src/main.sml +++ b/src/main.sml @@ -1552,6 +1552,7 @@ fun service () = NONE => ("User tried to set SA filtering for " ^ addr, SOME "You aren't allowed to configure SA filtering for that recipient.") | SOME addr' => (SetSA.set (addr', b); + SetSA.rebuild (); Msg.send (bio, MsgOk); ("Set SA filtering status for " ^ addr ^ " to " ^ (if b then "ON" else "OFF"), @@ -1691,6 +1692,10 @@ fun slave () = Msg.send (bio, MsgOk) else Msg.send (bio, MsgError "userdb update failed")) + | MsgSaChanged => (if Slave.shell [Config.SpamAssassin.postReload] then + Msg.send (bio, MsgOk) + else + Msg.send (bio, MsgError "Error reloading SpamAssassin addresses")) | _ => (print "Dispatcher sent unexpected command\n"; Msg.send (bio, MsgError "Unexpected command")) in diff --git a/src/msg.sml b/src/msg.sml index a1a52de..cbb9059 100644 --- a/src/msg.sml +++ b/src/msg.sml @@ -249,6 +249,7 @@ fun send (bio, m) = | MsgAptQuery {section, description} => (OpenSSL.writeInt (bio, 44); OpenSSL.writeString (bio, section); OpenSSL.writeString (bio, description)) + | MsgSaChanged => OpenSSL.writeInt (bio, 45) fun checkIt v = case v of @@ -367,6 +368,7 @@ fun recv bio = | 44 => (case (OpenSSL.readString bio, OpenSSL.readString bio) of (SOME section, SOME description) => SOME (MsgAptQuery {section = section, description = description}) | _ => NONE) + | 45 => SOME MsgSaChanged | _ => NONE) end diff --git a/src/msgTypes.sml b/src/msgTypes.sml index 08972bb..c6dcb50 100644 --- a/src/msgTypes.sml +++ b/src/msgTypes.sml @@ -100,6 +100,8 @@ datatype msg = (* Response to MsgSaQuery *) | MsgSaSet of string * bool (* Set the filtering status of a user or e-mail address *) + | MsgSaChanged + (* Reload spamassassin addrs *) | MsgSmtpLogReq of string (* Request all current SMTP log lines about a domain *) | MsgSmtpLogRes of string