Manage spamassassin preferences in shared space
authorClinton Ebadi <clinton@unknownlamer.org>
Tue, 6 May 2014 23:54:09 +0000 (19:54 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Tue, 6 May 2014 23:54:09 +0000 (19:54 -0400)
configDefault/spamassassin.cfg
configDefault/spamassassin.csg
scripts/domtool-publish
src/mail/setsa.sig
src/mail/setsa.sml
src/main.sml
src/msg.sml
src/msgTypes.sml

index 9be1007..7f347a1 100644 (file)
@@ -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
index 5bbab44..a4930b1 100644 (file)
@@ -1,5 +1,8 @@
 signature SPAM_ASSASSIN_CONFIG = sig
 
     val addrsDir : string
+    val addrsDb : string
+
+    val postReload : string
 
 end
index 9eea020..0771867 100755 (executable)
@@ -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
        ;;
index bc81859..5ec1020 100644 (file)
@@ -1,5 +1,6 @@
 (* HCoop Domtool (http://hcoop.sourceforge.net/)
  * Copyright (c) 2006, Adam Chlipala
+ * Copyright (c) 2014 Clinton Ebadi <clinton@unknownlamer.org>
  *
  * 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
index ef60dca..32fa0ab 100644 (file)
@@ -1,5 +1,6 @@
 (* HCoop Domtool (http://hcoop.sourceforge.net/)
  * Copyright (c) 2006, Adam Chlipala
+ * Copyright (c) 2014 Clinton Ebadi <clinton@unknownlamer.org>
  *
  * 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
index cc35c62..50f5e97 100644 (file)
@@ -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
index a1a52de..cbb9059 100644 (file)
@@ -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
index 08972bb..c6dcb50 100644 (file)
@@ -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