Update APT requests to take multiple servers into consideration
[hcoop/zz_old/portal.git] / apt.mlt
diff --git a/apt.mlt b/apt.mlt
index 0679155..d51c509 100644 (file)
--- a/apt.mlt
+++ b/apt.mlt
@@ -3,13 +3,14 @@
 val admin = Group.inGroupName "server";
 
 if $"new" <> "" then
+       val node = Web.stoi ($"node");
        val pkgs = String.tokens Char.isSpace ($"new");
 
        ref ok = true;
        ref infos = [];
 
        foreach pkg in pkgs do
-               switch AptQuery.query pkg of
+               switch AptQuery.query {node = node, pkg = pkg} of
                  NONE =>
                        ok := false;
                        %><b>Error</b>: Unknown package "<% Web.html pkg %>."<br><%
@@ -23,27 +24,29 @@ if $"new" <> "" then
                end
        end;
 
-       if ok then %>
+       if ok then
+               val debian = Init.nodeDebian node %>
 Are you sure these are the packages you wanted?<br><br>
 <table>
 <%             foreach info in infos do %>
-       <tr> <td align="right"><a href="http://packages.debian.org/testing/<% #section info %>/<% #name info %>"><% #name info %></a></td>
+       <tr> <td align="right"><a href="http://packages.debian.org/<% debian %>/<% #section info %>/<% #name info %>"><% #name info %></a></td>
                <td><% Web.html (#descr info) %></td> </tr>
 <% end %>
        </table><br>
        <br>
        <b>Reason:</b> <blockquote><% Web.htmlNl ($"msg") %></blockquote><br>
-       <a href="apt?req=<% foreach info in infos do %><% #name info %>+<% end %>&msg=<% Web.urlEncode ($"msg") %>">Yes, I want to request these packages.</a>
+       <a href="apt?node=<% node %>&req=<% foreach info in infos do %><% #name info %>+<% end %>&msg=<% Web.urlEncode ($"msg") %>">Yes, I want to request these packages.</a>
 
 <%     end
 
 elseif $"req" <> "" then
+       val node = Web.stoi ($"node");
        val pkgs = String.tokens Char.isSpace ($"req");
 
        ref ok = true;
 
        foreach pkg in pkgs do
-               switch AptQuery.query pkg of
+               switch AptQuery.query {node = node, pkg = pkg} of
                  NONE =>
                        ok := false;
                        %><b>Error</b>: Unknown package "<% Web.html pkg %>."<br><%
@@ -56,7 +59,7 @@ elseif $"req" <> "" then
        end;
 
        if ok then
-               val id = Apt.add (Init.getUserId(), $"req", $"msg");
+               val id = Apt.add {usr = Init.getUserId(), node = node, data = $"req", msg = $"msg"};
                if not (Apt.notifyNew id) then
                        %><h3>Error sending e-mail notification</h3><%
                end
@@ -72,10 +75,12 @@ elseif $"cmd" = "open" then
 <table class="blanks">
 <tr> <td>By:</td> <td colspan="2"><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
 <tr> <td>Time:</td> <td colspan="2"><% #stamp req %></td> </tr>
+<tr> <td>Node:</td> <td colspan="2"><% Web.html (Init.nodeName (#node req)) %></td> </tr>
 <tr> <td>Packages:</td><%
        ref first = true;
 
        val pkgs = String.tokens Char.isSpace (#data req);
+       val debian = Init.nodeDebian (#node req);
 
        foreach pkg in pkgs do
                if first then
@@ -83,11 +88,11 @@ elseif $"cmd" = "open" then
                else
                        %></tr><tr> <td></td><%
                end;
-               switch AptQuery.query pkg of
+               switch AptQuery.query {node = #node req, pkg = pkg} of
                  NONE =>
                        %><td></td> <td><b>Error</b>: Unknown package "<% Web.html pkg %>."</td><%
                | SOME info =>
-                       %><td align="right"><a href="http://packages.debian.org/testing/<% #section info %>/<% #name info %>"><% #name info %></a></td>
+                       %><td align="right"><a href="http://packages.debian.org/<% debian %>/<% #section info %>/<% #name info %>"><% #name info %></a></td>
                        <td><% Web.html (#descr info) %></td><%
                end
        end %>
@@ -112,10 +117,12 @@ elseif $"cmd" = "list" then
 <table class="blanks">
 <tr> <td>By:</td> <td colspan="2"><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
 <tr> <td>Time:</td> <td colspan="2"><% #stamp req %></td> </tr>
+<tr> <td>Node:</td> <td colspan="2"><% Web.html (Init.nodeName (#node req)) %></td> </tr>
 <tr> <td>Packages:</td><%
        ref first = true;
 
        val pkgs = String.tokens Char.isSpace (#data req);
+       val debian = Init.nodeDebian (#node req);
 
        foreach pkg in pkgs do
                if first then
@@ -123,11 +130,11 @@ elseif $"cmd" = "list" then
                else
                        %></tr><tr> <td></td><%
                end;
-               switch AptQuery.query pkg of
+               switch AptQuery.query {node = #node req, pkg = pkg} of
                  NONE =>
                        %><td></td> <td><b>Error</b>: Unknown package "<% Web.html pkg %>."</td><%
                | SOME info =>
-                       %><td align="right"><a href="http://packages.debian.org/testing/<% #section info %>/<% #name info %>"><% #name info %></a></td>
+                       %><td align="right"><a href="http://packages.debian.org/<% debian %>/<% #section info %>/<% #name info %>"><% #name info %></a></td>
                        <td><% Web.html (#descr info) %></td><%
                end
        end %>
@@ -155,6 +162,11 @@ elseif $"mod" <> "" then
 <table class="blanks">
 <tr> <td>Requestor:</td> <td><a href="user?id=<% #usr req %>"><% #name user %></a></td> </tr>
 <tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Node:</td> <td><select name="node">
+<% foreach node in Init.listNodes () do %>
+       <option value="<% #id node %>"<% if #id node = #node req then %> selected<% end %>><% Web.html (#name node) %> (<% Web.html (#descr node) %>; Debian <% Web.html (#debian node) %>)</option>
+<% end %>
+</select>
 <tr> <td>Status:</td> <td><select name="status">
        <option value="0"<% if #status req = Apt.NEW then %> selected<% end %>>New</option>
        <option value="1"<% if #status req = Apt.INSTALLED then %> selected<% end %>>Installed</option>
@@ -169,12 +181,13 @@ elseif $"mod" <> "" then
 <% elseif $"save" <> "" then
        Group.requireGroupName "server";
        val id = Web.stoi ($"save");
+       val node = Web.stoi ($"node");
        val req = Apt.lookup id;
        val oldStatus = #status req;
        val newStatus = Apt.statusFromInt (Web.stoi ($"status"));
-       Apt.modify {req with data = $"pkgs", msg = $"msg", status = newStatus};
+       Apt.modify {req with node = node, data = $"pkgs", msg = $"msg", status = newStatus};
        if oldStatus <> newStatus then
-               if not (Apt.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then
+               if not (Apt.notifyMod {old = oldStatus, new = newStatus, changer = Init.getUserName(), req = id}) then
                        %><h3>Error sending e-mail notification</h3><%
                end
        end
@@ -204,6 +217,11 @@ List the package names you'd like, separated by any whitespace characters.
 
 <form action="apt" method="post">
 <table class="blanks">
+<tr> <td>Machine:</td> <td><select name="node">
+<% foreach node in Init.listNodes () do %>
+       <option value="<% #id node %>"><% Web.html (#name node) %> (<% Web.html (#descr node) %>; Debian <% Web.html (#debian node) %>)</option>
+<% end %>
+</select></td></tr>
 <tr> <td>Packages:</td> <td><textarea name="new" rows="10" cols="40" wrap="soft"></textarea></td> </tr>
 <tr> <td>Reason:</td> <td><textarea name="msg" rows="5" cols="80" wrap="soft"></textarea></td> </tr>
 <tr> <td><input type="submit" value="Request"></td> </tr>