--- /dev/null
+<% @header [("title", ["Disk quota change requests"])];
+
+val admin = Group.inGroupName "server";
+
+if $"new" <> "" then
+ ref url = "?cmd=request&msg=" ^ Web.urlEncode ($"msg");
+ ref changed = false;
+ val uname = Init.getUserName ();
+
+ %>Are you sure you want to request these quota changes?
+ <ul><%
+
+ foreach vol in Quotas.getQuotas uname do
+ val requested = Web.stoi ($(#vol vol));
+ url := url ^ "&" ^ #vol vol ^ "=" ^ Int.toString requested;
+ if requested <> #quota vol then
+ changed := true;
+ %><li> Change quota for <% #vol vol %> from <% #quota vol %> to <% requested %>.</li><%
+ end
+ end;
+
+ %></ul><%
+ if changed then %>
+ <a href="<% url %>">Yes, I'm sure!</a>
+ <% else %>
+ Hm, no changes!
+ <% end
+elseif $"cmd" = "request" then
+ ref cmds = "";
+ val uname = Init.getUserName ();
+
+ foreach vol in Quotas.getQuotas uname do
+ val requested = Web.stoi ($(#vol vol));
+ if requested <> #quota vol then
+ cmds := cmds ^ "fs sq " ^ Quotas.path (#vol vol) ^ " " ^ Int.toString requested
+ ^ "\n# Current quota: " ^ Int.toString (#quota vol) ^ "\n"
+ end
+ end;
+
+ val id = Quota.add (Init.getUserId (), cmds, $"msg");
+ if not (Quota.notifyNew id) then
+ %><h3>Error sending e-mail notification</h3><%
+ end
+ %><h3>Request added</h3><%
+
+elseif $"cmd" = "open" then
+ %><h3>Open requests</h3>
+ <a href="?cmd=list">List all requests</a><%
+
+ foreach (name, req) in Quota.listOpen () do %>
+<br><hr><br>
+<table class="blanks">
+<tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Request:</td> <td><% Web.htmlNl (#data req) %></td> </tr>
+<tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr>
+</table>
+
+<% if admin then %>
+ <br>
+ <a href="?mod=<% #id req %>">[Modify]</a>
+ <a href="?del=<% #id req %>">[Delete]</a><br>
+<% end %>
+
+<% end
+
+elseif $"cmd" = "list" then
+ %><h3>All requests</h3><%
+
+ foreach (name, req) in Quota.list () do %>
+<br><hr><br>
+<table class="blanks">
+<tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Request:</td> <td><% Web.htmlNl (#data req) %></td> </tr>
+<tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr>
+</table>
+
+<% if admin then %>
+ <br>
+ <a href="?mod=<% #id req %>">[Modify]</a>
+ <a href="?del=<% #id req %>">[Delete]</a>
+<% end %>
+
+<% end
+
+elseif $"mod" <> "" then
+ Group.requireGroupName "server";
+ val id = Web.stoi ($"mod");
+ val req = Quota.lookup id;
+ val user = Init.lookupUser (#usr req) %>
+<h3>Handle request</h3>
+
+<form method="post">
+<input type="hidden" name="save" value="<% id %>">
+<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>Status:</td> <td><select name="status">
+ <option value="0"<% if #status req = Quota.NEW then %> selected<% end %>>New</option>
+ <option value="1"<% if #status req = Quota.INSTALLED then %> selected<% end %>>Installed</option>
+ <option value="2"<% if #status req = Quota.REJECTED then %> selected<% end %>>Rejected</option>
+</select></td> </tr>
+<tr> <td>Request:</td> <td><input name="req" size="60" value="<% Web.html (#data req) %>"></td> </tr>
+<tr> <td>Message:</td> <td><textarea name="msg" rows="10" cols="80" wrap="soft"><% Web.html (#msg req) %></textarea></td> </tr>
+<tr> <td><input type="submit" value="Save"></td> </tr>
+</table>
+</form>
+
+<% elseif $"save" <> "" then
+ Group.requireGroupName "server";
+ val id = Web.stoi ($"save");
+ val req = Quota.lookup id;
+ val oldStatus = #status req;
+ val newStatus = Quota.statusFromInt (Web.stoi ($"status"));
+ Quota.modify {req with data = $"req", msg = $"msg", status = newStatus};
+ if oldStatus <> newStatus then
+ if not (Quota.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then
+ %><h3>Error sending e-mail notification</h3><%
+ end
+ end
+ %><h3>Request modified</h3>
+ Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a>
+
+<% elseif $"del" <> "" then
+ Group.requireGroupName "server";
+ val id = Web.stoi ($"del");
+ val req = Quota.lookup id;
+ val user = Init.lookupUser (#usr req)
+ %><h3>Are you sure you want to delete request by <% #name user %> for <tt><% #data req %></tt>?</h3>
+ <a href="?del2=<% id %>">Yes, I'm sure!</a>
+
+<% elseif $"del2" <> "" then
+ Group.requireGroupName "server";
+ val id = Web.stoi ($"del2");
+ Quota.delete id
+ %><h3>Request deleted</b><h3>
+ Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a>
+
+<% else %>
+
+<h3>Request a disk quota change</h3>
+
+<form method="post">
+
+<table>
+<tr> <th>Volume</th> <th>Used (kB)</th> <th>Quota now (kB)</th> <th>Requested quota (kB)</th> </tr>
+<% foreach vol in Quotas.getQuotas (Init.getUserName ()) do %>
+ <tr> <td><% #vol vol %></td> <td><% #used vol %></td> <td><% #quota vol %></td>
+ <td><input name="<% #vol vol %>" value="<% #quota vol %>"></td> </tr>
+<% end %>
+</table>
+
+<input type="hidden" name="new" value="1">
+<table class="blanks">
+<tr> <td>Additional comments:</td> <td><textarea name="msg" rows="5" cols="80" wrap="soft"></textarea></td> </tr>
+<tr> <td><input type="submit" value="Request"></td> </tr>
+</table>
+</form>
+
+<% end %>
+
+<% @footer[] %>
--- /dev/null
+structure Quotas :> QUOTAS =
+struct
+ fun getQuotas uname =
+ let
+ val proc = Unix.execute ("/bin/sh", ["-c", "/usr/bin/vos listvol -long deleuze"])
+ val inf = Unix.textInstreamOf proc
+
+ fun eatUntilBlankLine () =
+ case TextIO.inputLine inf of
+ NONE => ()
+ | SOME "\n" => ()
+ | SOME _ => eatUntilBlankLine ()
+
+ val suffix = "." ^ uname
+
+ fun loop acc =
+ case TextIO.inputLine inf of
+ NONE => acc
+ | SOME line =>
+ case String.tokens Char.isSpace line of
+ [vol, _, _, kbs, _, _] =>
+ if String.isSuffix suffix vol then
+ let
+ val _ = TextIO.inputLine inf
+ val _ = TextIO.inputLine inf
+ in
+ case TextIO.inputLine inf of
+ NONE => loop acc
+ | SOME line =>
+ let
+ val quota =
+ case String.tokens Char.isSpace line of
+ [_, quota, _] => quota
+ | _ => raise Fail "Bad quota string"
+ in
+ eatUntilBlankLine ();
+ loop ({vol = vol,
+ used = valOf (Int.fromString kbs),
+ quota = valOf (Int.fromString quota)}
+ :: acc)
+ end
+ end
+ else
+ (eatUntilBlankLine ();
+ loop acc)
+ | _ => acc
+
+ val _ = TextIO.inputLine inf
+ in
+ loop []
+ before ignore (Unix.reap proc)
+ end
+
+ fun goofy s =
+ if size s < 2 then
+ raise Fail "Username too short"
+ else
+ String.concat [String.substring (s, 0, 1), "/",
+ String.substring (s, 0, 2), "/",
+ s]
+
+ fun splitVol vol =
+ let
+ val (befor, after) = Substring.splitl (fn ch => ch <> #".") (Substring.full vol)
+ in
+ (Substring.string befor,
+ Substring.string (Substring.slice (after, 1, NONE)))
+ end
+
+ fun path vol =
+ let
+ val (kind, uname) = splitVol vol
+ in
+ case kind of
+ "user" => "/afs/hcoop.net/user/" ^ goofy uname
+ | "db" => "/afs/hcoop.net/.databases/" ^ goofy uname
+ | "mail" => "/afs/hcoop.net/user/" ^ goofy uname ^ "/Maildir"
+ | _ => raise Fail ("Don't know how to find mount point for volume " ^ vol)
+ end
+
+end