<% @header [("title", ["APT package installation requests"])]; val admin = Group.inGroupName "server"; val nodeNum = case $"node" of "" => 2 | node => Web.stoi node; if $"new" <> "" then val pkgs = String.tokens Char.isSpace ($"new"); ref ok = true; ref infos = []; foreach pkg in pkgs do switch AptQuery.query {node = nodeNum, pkg = pkg} of NONE => ok := false; %>Error: Unknown package "<% Web.html pkg %>."
<% | SOME info => if #installed info then ok := false; %>Error: Package "<% pkg %>" is already installed!
<% else infos := info :: infos end end end; if ok then val debian = Init.nodeDebian nodeNum %> Are you sure these are the packages you wanted?

<% foreach info in infos do %> <% end %>
<% #name info %> <% Web.html (#descr info) %>


Reason:
<% Web.htmlNl ($"msg") %>

">Yes, I want to request these packages. <% end elseif $"req" <> "" then val pkgs = String.tokens Char.isSpace ($"req"); ref ok = true; foreach pkg in pkgs do switch AptQuery.query {node = nodeNum, pkg = pkg} of NONE => ok := false; %>Error: Unknown package "<% Web.html pkg %>."
<% | SOME info => if #installed info then ok := false; %>Error: Package "<% pkg %>" is already installed!
<% end end end; if ok then val id = Apt.add {usr = Init.getUserId(), node = nodeNum, data = $"req", msg = $"msg"}; if not (Apt.notifyNew id) then %>

Error sending e-mail notification

<% end %>

Request added

<% end elseif $"cmd" = "open" then %>

Open requests

List all requests<% foreach (name, req) in Apt.listOpen () do %>


<% 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 first := false else %><% end; switch AptQuery.query {node = #node req, pkg = pkg} of NONE => %><% | SOME info => %><% end end %>
By: <% name %>
Time: <% #stamp req %> (<% Util.diffFromNow (#stamp req) %> ago)
Node: <% Web.html (Init.nodeName (#node req)) %>
Packages:
Error: Unknown package "<% Web.html pkg %>."<% #name info %> <% Web.html (#descr info) %>
Reason: <% Web.html (#msg req) %>
<% if admin then %>
[Modify] [Delete]
To install, run: apt-get install<% foreach pkg in pkgs do %> <% pkg %><% end %> <% end %> <% end elseif $"cmd" = "list" then %>

All requests

<% foreach (name, req) in Apt.list () do %>


<% 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 first := false else %><% end; switch AptQuery.query {node = #node req, pkg = pkg} of NONE => %><% | SOME info => %><% end end %>
By: <% name %>
Time: <% #stamp req %> (<% Util.diffFromNow (#stamp req) %> ago)
Node: <% Web.html (Init.nodeName (#node req)) %>
Packages:
Error: Unknown package "<% Web.html pkg %>."<% #name info %> <% Web.html (#descr info) %>
Reason: <% Web.html (#msg req) %>
<% if admin then %>
[Modify] [Delete] <% end %> <% end elseif $"mod" <> "" then Group.requireGroupName "server"; val id = Web.stoi ($"mod"); val req = Apt.lookup id; val user = Init.lookupUser (#usr req) %>

Handle request

Requestor: <% #name user %>
Time: <% #stamp req %> (<% Util.diffFromNow (#stamp req) %> ago)
Node:
Status:
Packages:
Message:
<% 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 node = node, data = $"pkgs", msg = $"msg", status = newStatus}; if not (Apt.notifyMod {old = oldStatus, new = newStatus, changer = Init.getUserName(), req = id}) then %>

Error sending e-mail notification

<% end %>

Request modified

Back to: open requests, all requests <% elseif $"del" <> "" then Group.requireGroupName "server"; val id = Web.stoi ($"del"); val req = Apt.lookup id; val user = Init.lookupUser (#usr req) %>

Are you sure you want to delete request by <% #name user %> for <% #data req %>?

Yes, I'm sure! <% elseif $"del2" <> "" then Group.requireGroupName "server"; val id = Web.stoi ($"del2"); Apt.delete id %>

Request deleted

Back to: open requests, all requests <% else %>

Request new installations

List the package names you'd like, separated by any whitespace characters.
Machine:
Packages:
Reason:
<% end %> <% @footer[] %>