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