Testing queries on slave servers
[hcoop/domtool2.git] / src / main.sml
index 0ddc508..19fe40c 100644 (file)
@@ -606,9 +606,13 @@ fun requestSmtpLog domain =
 
 fun requestApt {node, pkg} =
     let
-       val (_, bio) = requestBio (fn () => ())
+       val (user, context) = requestContext (fn () => ())
+       val bio = OpenSSL.connect (context, if node = Config.masterNode then
+                                               dispatcher
+                                           else
+                                               Domain.nodeIp node ^ ":" ^ Int.toString Config.slavePort)
 
-       val _ = Msg.send (bio, MsgApt pkg)
+       val _ = Msg.send (bio, MsgQuery (QApt pkg))
 
        fun loop () =
            case Msg.recv bio of
@@ -712,6 +716,14 @@ fun rmuser user =
 
 fun now () = Date.toString (Date.fromTimeUniv (Time.now ()))
 
+fun answerQuery q =
+    case q of
+       QApt pkg => if Apt.installed pkg then MsgYes else MsgNo
+
+fun describeQuery q =
+    case q of
+       QApt pkg => "Requested installation status of package " ^ pkg
+
 fun service () =
     let
        val () = Acl.read Config.aclFile
@@ -1055,12 +1067,9 @@ fun service () =
                                               NONE)))
                                (fn () => ())
 
-                             | MsgApt pkg =>
-                               doIt (fn () => (Msg.send (bio, if Apt.installed pkg then
-                                                                  MsgYes
-                                                              else
-                                                                  MsgNo);
-                                               ("User requested installation status of package " ^ pkg,
+                             | MsgQuery q =>
+                               doIt (fn () => (Msg.send (bio, answerQuery q);
+                                               (describeQuery q,
                                                 NONE)))
                                (fn () => ())
 
@@ -1134,9 +1143,14 @@ fun slave () =
                          | _ => (OpenSSL.close bio;
                                  loop ())
                    else
-                       (print "Not authorized!\n";
-                        OpenSSL.close bio;
-                        loop ())
+                       case Msg.recv bio of
+                           SOME (MsgQuery q) => (print (describeQuery q ^ "\n");
+                                                 Msg.send (bio, answerQuery q);
+                                                 ignore (OpenSSL.readChar bio);
+                                                 OpenSSL.close bio;
+                                                 loop ())
+                         | _ => (OpenSSL.close bio;
+                                 loop ())
                end handle OpenSSL.OpenSSL s =>
                           (print ("OpenSSL error: "^ s ^ "\n");
                            OpenSSL.close bio