Merge default into bug23374.

This commit is contained in:
Simon MacMullen 2010-11-02 17:29:38 +00:00
commit 7253d17ab6
7 changed files with 42 additions and 19 deletions

View File

@ -88,6 +88,14 @@ function fmt_table_short(table) {
return res;
}
function fmt_table_long(table) {
var res = '<table class="facts">';
for (k in table) {
res += '<tr><th>' + k + '</th><td>' + table[k] + '</td>';
}
return res + '</table>';
}
function alt_rows(i) {
return (i % 2 == 0) ? ' class="alt"' : '';
}

View File

@ -97,3 +97,10 @@
</form>
</div>
</div>
<div class="section-hidden">
<h2>Backing Queue Status</h2>
<div class="hider updatable">
<%= fmt_table_long(queue.backing_queue_status) %>
</div>
</div>

View File

@ -23,6 +23,8 @@
-behaviour(application).
-export([start/2, stop/1]).
-include_lib("amqp_client/include/amqp_client.hrl").
-define(PREFIX, "api").
-define(UI_PREFIX, "mgmt").
-define(CLI_PREFIX, "cli").
@ -56,8 +58,14 @@ register_contexts() ->
[{[?PREFIX | Path], F, A} ||
{Path, F, A} <- rabbit_mgmt_dispatcher:dispatcher()]),
application:set_env(webmachine, error_handler, webmachine_error_handler),
rabbit_mochiweb:register_static_context(?UI_PREFIX, ?MODULE, "priv/www",
"Management Console"),
rabbit_mochiweb:register_authenticated_static_context(
?UI_PREFIX, ?MODULE, "priv/www", "RabbitMQ Management Console",
fun (U, P) ->
case rabbit_access_control:lookup_user(U) of
{ok, User = #user{password = P1}} when P == P1 -> true;
_ -> false
end
end),
rabbit_mochiweb:register_context_handler(?PREFIX,
fun webmachine_mochiweb:loop/1,
"HTTP API"),

View File

@ -297,7 +297,7 @@ code_change(_OldVsn, State, _Extra) ->
handle_event(#event{type = queue_stats, props = Stats, timestamp = Timestamp},
State) ->
handle_stats(queue_stats, Stats, Timestamp,
[{fun rabbit_mgmt_format:table/1,[backing_queue_status]}],
[{fun rabbit_mgmt_format:properties/1,[backing_queue_status]}],
[], State);
handle_event(Event = #event{type = queue_deleted}, State) ->
@ -313,7 +313,7 @@ handle_event(#event{type = connection_created, props = Stats}, State) ->
[{fun rabbit_mgmt_format:ip/1, [address, peer_address]},
{fun rabbit_mgmt_format:node_and_pid/1, [pid]},
{fun rabbit_mgmt_format:protocol/1, [protocol]},
{fun rabbit_mgmt_format:table/1, [client_properties]}], State);
{fun rabbit_mgmt_format:amqp_table/1, [client_properties]}], State);
handle_event(#event{type = connection_stats, props = Stats,
timestamp = Timestamp},

View File

@ -21,11 +21,11 @@
%%
-module(rabbit_mgmt_format).
-export([format/2, print/2, pid/1, ip/1, table/1, tuple/1, timestamp/1]).
-export([format/2, print/2, pid/1, ip/1, amqp_table/1, tuple/1, timestamp/1]).
-export([node_and_pid/1, protocol/1, resource/1, permissions/1, queue/1]).
-export([exchange/1, user/1, binding/1, url/2, application/1]).
-export([pack_binding_props/2, unpack_binding_props/1, tokenise/1]).
-export([args_type/1, listener/1]).
-export([args_type/1, listener/1, properties/1]).
-include_lib("rabbit_common/include/rabbit.hrl").
@ -68,8 +68,12 @@ node_and_pid(none) -> [].
ip(unknown) -> unknown;
ip(IP) -> list_to_binary(inet_parse:ntoa(IP)).
table(unknown) -> unknown;
table(Table) -> {struct, [{Name, tuple(Value)} ||
properties(unknown) -> unknown;
properties(Table) -> {struct, [{Name, tuple(Value)} ||
{Name, Value} <- Table]}.
amqp_table(unknown) -> unknown;
amqp_table(Table) -> {struct, [{Name, tuple(Value)} ||
{Name, _Type, Value} <- Table]}.
tuple(unknown) -> unknown;
@ -187,8 +191,8 @@ application({Application, Description, Version}) ->
{version, list_to_binary(Version)}].
exchange(X) ->
format(X, [{fun resource/1, [name]},
{fun table/1, [arguments]}]).
format(X, [{fun resource/1, [name]},
{fun amqp_table/1, [arguments]}]).
%% We get queues using rabbit_amqqueue:list/1 rather than :info_all/1 since
%% the latter wakes up each queue. Therefore we have a record rather than a
@ -209,7 +213,7 @@ queue(#amqqueue{name = Name,
[{fun pid/1, [owner_pid]},
{fun node_and_pid/1, [pid]},
{fun resource/1, [name]},
{fun table/1, [arguments]}]).
{fun amqp_table/1, [arguments]}]).
%% We get bindings using rabbit_binding:list_*/1 rather than :info_all/1 since
%% there are no per-exchange / queue / etc variants for the latter. Therefore
@ -226,4 +230,4 @@ binding(#binding{source = S,
{arguments, Args},
{properties_key, pack_binding_props(Key, Args)}],
[{fun (Res) -> resource(source, Res) end, [source]},
{fun table/1, [arguments]}]).
{fun amqp_table/1, [arguments]}]).

View File

@ -62,11 +62,9 @@ is_authorized_user(ReqData, Context, Item) ->
is_authorized(ReqData, Context, Fun) ->
Unauthorized = {"Basic realm=\"RabbitMQ Management Console\"",
ReqData, Context},
case wrq:get_req_header("authorization", ReqData) of
"Basic " ++ Base64 ->
Str = base64:mime_decode_to_string(Base64),
[Username, Pass] =
[list_to_binary(S) || S <- string:tokens(Str, ":")],
case rabbit_mochiweb_util:parse_auth_header(
wrq:get_req_header("authorization", ReqData)) of
[Username, Pass] ->
case rabbit_access_control:lookup_user(Username) of
{ok, User = #user{password = Pass1,
is_admin = IsAdmin}} when Pass == Pass1 ->

View File

@ -37,8 +37,6 @@ overview_test() ->
true = 0 < length(pget(listeners, http_get("/overview"))),
%% TODO uncomment when priv works in test
%%http_get(""),
%% Just for coverage
http_get("/applications"),
ok.
nodes_test() ->