Add all-balance summing and listing of retired balances
[hcoop/zz_old/portal.git] / apt.mlt
1 <% @header [("title", ["APT package installation requests"])];
2
3 val admin = Group.inGroupName "server";
4
5 if $"new" <> "" then
6 val node = Web.stoi ($"node");
7 val pkgs = String.tokens Char.isSpace ($"new");
8
9 ref ok = true;
10 ref infos = [];
11
12 foreach pkg in pkgs do
13 switch AptQuery.query {node = node, pkg = pkg} of
14 NONE =>
15 ok := false;
16 %><b>Error</b>: Unknown package "<% Web.html pkg %>."<br><%
17 | SOME info =>
18 if #installed info then
19 ok := false;
20 %><b>Error</b>: Package "<% pkg %>" is already installed!<br><%
21 else
22 infos := info :: infos
23 end
24 end
25 end;
26
27 if ok then
28 val debian = Init.nodeDebian node %>
29 Are you sure these are the packages you wanted?<br><br>
30 <table>
31 <% foreach info in infos do %>
32 <tr> <td align="right"><a href="http://packages.debian.org/<% debian %>/<% #section info %>/<% #name info %>"><% #name info %></a></td>
33 <td><% Web.html (#descr info) %></td> </tr>
34 <% end %>
35 </table><br>
36 <br>
37 <b>Reason:</b> <blockquote><% Web.htmlNl ($"msg") %></blockquote><br>
38 <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>
39
40 <% end
41
42 elseif $"req" <> "" then
43 val node = Web.stoi ($"node");
44 val pkgs = String.tokens Char.isSpace ($"req");
45
46 ref ok = true;
47
48 foreach pkg in pkgs do
49 switch AptQuery.query {node = node, pkg = pkg} of
50 NONE =>
51 ok := false;
52 %><b>Error</b>: Unknown package "<% Web.html pkg %>."<br><%
53 | SOME info =>
54 if #installed info then
55 ok := false;
56 %><b>Error</b>: Package "<% pkg %>" is already installed!<br><%
57 end
58 end
59 end;
60
61 if ok then
62 val id = Apt.add {usr = Init.getUserId(), node = node, data = $"req", msg = $"msg"};
63 if not (Apt.notifyNew id) then
64 %><h3>Error sending e-mail notification</h3><%
65 end
66 %><h3>Request added</h3><%
67 end
68
69 elseif $"cmd" = "open" then
70 %><h3>Open requests</h3>
71 <a href="apt?cmd=list">List all requests</a><%
72
73 foreach (name, req) in Apt.listOpen () do %>
74 <br><hr><br>
75 <table class="blanks">
76 <tr> <td>By:</td> <td colspan="2"><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
77 <tr> <td>Time:</td> <td colspan="2"><% #stamp req %></td> </tr>
78 <tr> <td>Node:</td> <td colspan="2"><% Web.html (Init.nodeName (#node req)) %></td> </tr>
79 <tr> <td>Packages:</td><%
80 ref first = true;
81
82 val pkgs = String.tokens Char.isSpace (#data req);
83 val debian = Init.nodeDebian (#node req);
84
85 foreach pkg in pkgs do
86 if first then
87 first := false
88 else
89 %></tr><tr> <td></td><%
90 end;
91 switch AptQuery.query {node = #node req, pkg = pkg} of
92 NONE =>
93 %><td></td> <td><b>Error</b>: Unknown package "<% Web.html pkg %>."</td><%
94 | SOME info =>
95 %><td align="right"><a href="http://packages.debian.org/<% debian %>/<% #section info %>/<% #name info %>"><% #name info %></a></td>
96 <td><% Web.html (#descr info) %></td><%
97 end
98 end %>
99 </tr>
100 <tr> <td>Reason:</td> <td colspan="2"><% Web.html (#msg req) %></td> </tr>
101 </table>
102
103 <% if admin then %>
104 <br>
105 <a href="apt?mod=<% #id req %>">[Modify]</a>
106 <a href="apt?del=<% #id req %>">[Delete]</a><br>
107 To install, run: <tt>apt-get install<% foreach pkg in pkgs do %>&nbsp;<% pkg %><% end %></tt>
108 <% end %>
109
110 <% end
111
112 elseif $"cmd" = "list" then
113 %><h3>All requests</h3><%
114
115 foreach (name, req) in Apt.list () do %>
116 <br><hr><br>
117 <table class="blanks">
118 <tr> <td>By:</td> <td colspan="2"><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
119 <tr> <td>Time:</td> <td colspan="2"><% #stamp req %></td> </tr>
120 <tr> <td>Node:</td> <td colspan="2"><% Web.html (Init.nodeName (#node req)) %></td> </tr>
121 <tr> <td>Packages:</td><%
122 ref first = true;
123
124 val pkgs = String.tokens Char.isSpace (#data req);
125 val debian = Init.nodeDebian (#node req);
126
127 foreach pkg in pkgs do
128 if first then
129 first := false
130 else
131 %></tr><tr> <td></td><%
132 end;
133 switch AptQuery.query {node = #node req, pkg = pkg} of
134 NONE =>
135 %><td></td> <td><b>Error</b>: Unknown package "<% Web.html pkg %>."</td><%
136 | SOME info =>
137 %><td align="right"><a href="http://packages.debian.org/<% debian %>/<% #section info %>/<% #name info %>"><% #name info %></a></td>
138 <td><% Web.html (#descr info) %></td><%
139 end
140 end %>
141 </tr>
142 <tr> <td>Reason:</td> <td colspan="2"><% Web.html (#msg req) %></td> </tr>
143 </table>
144
145 <% if admin then %>
146 <br>
147 <a href="apt?mod=<% #id req %>">[Modify]</a>
148 <a href="apt?del=<% #id req %>">[Delete]</a>
149 <% end %>
150
151 <% end
152
153 elseif $"mod" <> "" then
154 Group.requireGroupName "server";
155 val id = Web.stoi ($"mod");
156 val req = Apt.lookup id;
157 val user = Init.lookupUser (#usr req) %>
158 <h3>Handle request</h3>
159
160 <form action="apt" method="post">
161 <input type="hidden" name="save" value="<% id %>">
162 <table class="blanks">
163 <tr> <td>Requestor:</td> <td><a href="user?id=<% #usr req %>"><% #name user %></a></td> </tr>
164 <tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
165 <tr> <td>Node:</td> <td><select name="node">
166 <% foreach node in Init.listNodes () do %>
167 <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>
168 <% end %>
169 </select>
170 <tr> <td>Status:</td> <td><select name="status">
171 <option value="0"<% if #status req = Apt.NEW then %> selected<% end %>>New</option>
172 <option value="1"<% if #status req = Apt.INSTALLED then %> selected<% end %>>Installed</option>
173 <option value="2"<% if #status req = Apt.REJECTED then %> selected<% end %>>Rejected</option>
174 </select></td> </tr>
175 <tr> <td>Packages:</td> <td><textarea name="pkgs" rows="5" cols="40" wrap="soft"><% Web.html (#data req) %></textarea></td> </tr>
176 <tr> <td>Message:</td> <td><textarea name="msg" rows="10" cols="80" wrap="soft"><% Web.html (#msg req) %></textarea></td> </tr>
177 <tr> <td><input type="submit" value="Save"></td> </tr>
178 </table>
179 </form>
180
181 <% elseif $"save" <> "" then
182 Group.requireGroupName "server";
183 val id = Web.stoi ($"save");
184 val node = Web.stoi ($"node");
185 val req = Apt.lookup id;
186 val oldStatus = #status req;
187 val newStatus = Apt.statusFromInt (Web.stoi ($"status"));
188 Apt.modify {req with node = node, data = $"pkgs", msg = $"msg", status = newStatus};
189 if oldStatus <> newStatus then
190 if not (Apt.notifyMod {old = oldStatus, new = newStatus, changer = Init.getUserName(), req = id}) then
191 %><h3>Error sending e-mail notification</h3><%
192 end
193 end
194 %><h3>Request modified</h3>
195 Back to: <a href="apt?cmd=open">open requests</a>, <a href="apt?cmd=list">all requests</a>
196
197 <% elseif $"del" <> "" then
198 Group.requireGroupName "server";
199 val id = Web.stoi ($"del");
200 val req = Apt.lookup id;
201 val user = Init.lookupUser (#usr req)
202 %><h3>Are you sure you want to delete request by <% #name user %> for <tt><% #data req %></tt>?</h3>
203 <a href="apt?del2=<% id %>">Yes, I'm sure!</a>
204
205 <% elseif $"del2" <> "" then
206 Group.requireGroupName "server";
207 val id = Web.stoi ($"del2");
208 Apt.delete id
209 %><h3>Request deleted</b><h3>
210 Back to: <a href="apt?cmd=open">open requests</a>, <a href="apt?cmd=list">all requests</a>
211
212 <% else %>
213
214 <h3>Request new installations</h3>
215
216 List the package names you'd like, separated by any whitespace characters.
217
218 <form action="apt" method="post">
219 <table class="blanks">
220 <tr> <td>Machine:</td> <td><select name="node">
221 <% foreach node in Init.listNodes () do %>
222 <option value="<% #id node %>"><% Web.html (#name node) %> (<% Web.html (#descr node) %>; Debian <% Web.html (#debian node) %>)</option>
223 <% end %>
224 </select></td></tr>
225 <tr> <td>Packages:</td> <td><textarea name="new" rows="10" cols="40" wrap="soft"></textarea></td> </tr>
226 <tr> <td>Reason:</td> <td><textarea name="msg" rows="5" cols="80" wrap="soft"></textarea></td> </tr>
227 <tr> <td><input type="submit" value="Request"></td> </tr>
228 </table>
229 </form>
230
231 <% end %>
232
233 <% @footer[] %>