hostname : string, (* Internet hostname *)
id : string} (* Name of stats directory *)
- val getWebbw : int -> int * (host * int) list * (string * host list * int) list
+ val getWebbw : int -> {total : int,
+ vhosts: {host : host, size : int} list,
+ users : {user : string, hosts : host list, size : int} list}
(* Get web bandwidth usage stats. The argument tells how many months ago
* to look for the data. The return gives the total b/w usage, a mapping from
* vhosts to kilobytes, and a mapping from usernames to their vhosts and bandwidth
hostname : string,
id : string}
- fun checkSsl host =
- case String.fields (fn ch => ch = #".") host of
- first::rest =>
- (case String.fields (fn ch => ch = #"_") first of
- [first, "ssl"] => {ssl = true, hostname = String.concatWith "." (first::rest),
- id = host}
- | _ => {ssl = false, hostname = host, id = host})
- | _ => {ssl = false, hostname = host, id = host}
+ fun checkSsl (node, host) =
+ let
+ val id = case String.tokens (fn ch => ch = #".") host of
+ [] => node ^ "/" ^ host
+ | first :: rest =>
+ case rev (String.tokens (fn ch => ch = #"_") first) of
+ "ssl" :: rest' => node ^ "/" ^ String.concatWith "_" (rev rest')
+ ^ "." ^ String.concatWith "." rest ^ ".ssl"
+ | _ => node ^ "/" ^ host
+ in
+ case String.fields (fn ch => ch = #".") host of
+ first::rest =>
+ (case String.fields (fn ch => ch = #"_") first of
+ [first, "ssl"] => {ssl = true, hostname = String.concatWith "." (first::rest),
+ id = id}
+ | _ => {ssl = false, hostname = host, id = id})
+ | _ => {ssl = false, hostname = host, id = id}
+ end
fun getWebbw last =
let
(NONE | SOME "\n") => List.rev L
| SOME l =>
case String.tokens (fn ch => Char.isSpace ch orelse ch = #":") l of
- [d, n] => readEm ((checkSsl d, valOf (Int.fromString n)) :: L)
- | _ => raise Fail "Bad row in webbw"
+ [d, n] =>
+ (case String.tokens (fn ch => ch = #"@") d of
+ [d, node] => readEm ({host = checkSsl (node, d), size = valOf (Int.fromString n)} :: L)
+ | _ => raise Fail ("Bad row in webbw [2]: " ^ l))
+ | _ => raise Fail ("Bad row in webbw [1]: " ^ l)
fun splitLast [] = raise Fail "Not enough items for splitLast"
| splitLast [x] = ([], x)
d :: rest =>
let
val (l, x) = splitLast rest
+
+ fun split s =
+ case String.tokens (fn ch => ch = #"@") s of
+ [host, node] => (node, host)
+ | _ => raise Fail ("Bad row in webbw [3]: " ^ s)
in
- readGroups ((d, map checkSsl l, valOf (Int.fromString x)) :: L)
+ readGroups ({user = d, hosts = map (checkSsl o split) l, size = valOf (Int.fromString x)} :: L)
end
- | _ => raise Fail "Bad row in webbw, part 2"
+ | _ => raise Fail ("Bad row in webbw [4]: " ^ l)
in
TextIO.inputLine inf;
- (sum, readEm [], readGroups [])
+ {total = sum, vhosts = readEm [], users = readGroups []}
before TextIO.closeIn inf
end
<% @header [("title", ["Web usage stats"])] %>
-<b><u>Web virtual host bandwidth</u></b> (bandwidth usage of Apache sites in this calendar month)<br>
+<b><u>Web virtual host bandwidth</u></b> (bandwidth usage of Apache sites <% case $"last" of "1" => "last month" | "2" => "two months ago" | _ => "this calendar month" %>)<br>
<% if $"last" = "1" then %>
<a href="webbw?last=2">[Previous]</a> | <a href="webbw?last=0">[Current]</a>
<% elseif $"last" = "2" then %>
<% end %>
<br><br>
-<% val (sum, doms, groups) = iff $"last" = "" then
+<% val stats = iff $"last" = "" then
Stats.getWebbw 0
else
Stats.getWebbw (Web.stoi ($"last")) %>
<table>
<tr><td></td><td><b>Bandwidth (kB)</b></td></tr>
-<tr><td align="right"><b>Total Apache bandwidth</b></td> <td><% sum %></td></tr>
+<tr><td align="right"><b>Total Apache bandwidth</b></td> <td><% #total stats %></td></tr>
<tr><td> </td></tr>
-<% foreach (d, n) in doms do %>
- <tr><td align="right"><a href="<% if #ssl d then %>https<% else %>http<% end %>://<% #hostname d %>/"><% #hostname d %></a> <a href="/webalizer/<% #id d %>/">[detail]</a></td><td><% n %></td></tr>
+<% foreach dom in #vhosts stats do %>
+ <tr><td align="right"><a href="<% if #ssl (#host dom) then %>https<% else %>http<% end %>://<% #hostname (#host dom) %>/"><% #hostname (#host dom) %><% if #ssl (#host dom) then %> (SSL)<% end %></a> <a href="/webalizer/<% #id (#host dom) %>/">[detail]</a></td><td><% #size dom %></td></tr>
<% end %>
</table>
<tr><td></td><td></td><td><b>Bandwidth (kB)</b></td></tr>
<tr><td> </td></tr>
-<% foreach (gr, ds, n) in groups do %>
- <tr><td align="right"><% gr %></td><td>
- <% foreach dom in ds do %>
- [<a href="/webalizer/<% #id dom %>/"><% #hostname dom %></a> <a href="<% if #ssl dom then %>https<% else %>http<% end %>://<% #hostname dom %>/">(S)</a>]
+<% foreach group in #users stats do %>
+ <tr><td align="right"><% #user group %></td><td>
+ <% foreach dom in #hosts group do %>
+ [<a href="/webalizer/<% #id dom %>/"><% #hostname dom %><% if #ssl dom then %> (SSL)<% end %></a> <a href="<% if #ssl dom then %>https<% else %>http<% end %>://<% #hostname dom %>/">(S)</a>]
<% end %>
- </td><td><% n %></td></tr>
+ </td><td><% #size group %></td></tr>
<% end %>
</table>