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