Merge pull request #1287 from emqtt/develop

Version2.3-rc.1
This commit is contained in:
huangdan 2017-10-10 19:25:34 -05:00 committed by GitHub
commit d3aacc1e8a
6 changed files with 57 additions and 18 deletions

View File

@ -137,12 +137,24 @@ log.syslog.level = error
## Console log file ## Console log file
## log.console.file = {{ platform_log_dir }}/console.log ## log.console.file = {{ platform_log_dir }}/console.log
## Console log file size
## log.console.size = 10485760
## Console log count size
## log.console.count = 5
## Info log file ## Info log file
## log.info.file = {{ platform_log_dir }}/info.log ## log.info.file = {{ platform_log_dir }}/info.log
## Error log file ## Error log file
log.error.file = {{ platform_log_dir }}/error.log log.error.file = {{ platform_log_dir }}/error.log
## Error log file size
## log.error.size = 10485760
## Error log file count
## log.error.count = 5
## Enable the crash log. Enum: on, off ## Enable the crash log. Enum: on, off
log.crash = on log.crash = on

View File

@ -326,11 +326,31 @@ end}.
{datatype, file} {datatype, file}
]}. ]}.
{mapping, "log.console.size", "lager.handlers", [
{default, 10485760},
{datatype, integer}
]}.
{mapping, "log.console.count", "lager.handlers", [
{default, 5},
{datatype, integer}
]}.
{mapping, "log.error.file", "lager.handlers", [ {mapping, "log.error.file", "lager.handlers", [
{default, "log/error.log"}, {default, "log/error.log"},
{datatype, file} {datatype, file}
]}. ]}.
{mapping, "log.error.size", "lager.handlers", [
{default, 10485760},
{datatype, integer}
]}.
{mapping, "log.error.count", "lager.handlers", [
{default, 5},
{datatype, integer}
]}.
{mapping, "log.syslog", "lager.handlers", [ {mapping, "log.syslog", "lager.handlers", [
{default, off}, {default, off},
{datatype, flag} {datatype, flag}
@ -370,9 +390,9 @@ end}.
undefined -> []; undefined -> [];
ErrorFilename -> [{lager_file_backend, [{file, ErrorFilename}, ErrorFilename -> [{lager_file_backend, [{file, ErrorFilename},
{level, error}, {level, error},
{size, 10485760}, {size, cuttlefish:conf_get("log.error.size", Conf)},
{date, "$D0"}, {date, "$D0"},
{count, 5}]}] {count, cuttlefish:conf_get("log.error.count", Conf)}]}]
end, end,
ConsoleLogLevel = cuttlefish:conf_get("log.console.level", Conf), ConsoleLogLevel = cuttlefish:conf_get("log.console.level", Conf),
@ -381,9 +401,9 @@ end}.
ConsoleHandler = {lager_console_backend, ConsoleLogLevel}, ConsoleHandler = {lager_console_backend, ConsoleLogLevel},
ConsoleFileHandler = {lager_file_backend, [{file, ConsoleLogFile}, ConsoleFileHandler = {lager_file_backend, [{file, ConsoleLogFile},
{level, ConsoleLogLevel}, {level, ConsoleLogLevel},
{size, 10485760}, {size, cuttlefish:conf_get("log.console.size", Conf)},
{date, "$D0"}, {date, "$D0"},
{count, 5}]}, {count, cuttlefish:conf_get("log.console.count", Conf)}]},
ConsoleHandlers = case cuttlefish:conf_get("log.console", Conf) of ConsoleHandlers = case cuttlefish:conf_get("log.console", Conf) of
off -> []; off -> [];

View File

@ -63,12 +63,12 @@ passwd_hash(sha256, Password) ->
passwd_hash(pbkdf2, {Salt, Password, Macfun, Iterations, Dklen}) -> passwd_hash(pbkdf2, {Salt, Password, Macfun, Iterations, Dklen}) ->
case pbkdf2:pbkdf2(Macfun, Password, Salt, Iterations, Dklen) of case pbkdf2:pbkdf2(Macfun, Password, Salt, Iterations, Dklen) of
{ok, Hexstring} -> pbkdf2:to_hex(Hexstring); {ok, Hexstring} -> pbkdf2:to_hex(Hexstring);
{error, Error} -> lager:error("PasswdHash with pbkdf2 error:~p", [Error]), error {error, Error} -> lager:error("PasswdHash with pbkdf2 error:~p", [Error]), <<>>
end; end;
passwd_hash(bcrypt, {Salt, Password}) -> passwd_hash(bcrypt, {Salt, Password}) ->
case bcrypt:hashpw(Password, Salt) of case bcrypt:hashpw(Password, Salt) of
{ok, HashPassword} -> list_to_binary(HashPassword); {ok, HashPassword} -> list_to_binary(HashPassword);
{error, Error}-> lager:error("PasswdHash with bcrypt error:~p", [Error]), error {error, Error}-> lager:error("PasswdHash with bcrypt error:~p", [Error]), <<>>
end. end.
hexstring(<<X:128/big-unsigned-integer>>) -> hexstring(<<X:128/big-unsigned-integer>>) ->

View File

@ -26,7 +26,7 @@
-import(proplists, [get_value/2, get_value/3]). -import(proplists, [get_value/2, get_value/3]).
-export([http_handler/0, handle_request/2, http_api/0]). -export([http_handler/0, handle_request/2, http_api/0, inner_handle_request/2]).
-include("emqttd_internal.hrl"). -include("emqttd_internal.hrl").
@ -54,12 +54,14 @@ handle_request(Req, State) ->
"/api/v2/auth" -> "/api/v2/auth" ->
handle_request(Path, Req, State); handle_request(Path, Req, State);
_ -> _ ->
Host = Req:get_header_value("Host"), if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
[_, Port] = string:tokens(Host, ":"), end.
case Port of
"18083" -> handle_request(Path, Req, State); inner_handle_request(Req, State) ->
Path = Req:get(path),
case Path of
"/api/v2/auth" -> handle_request(Path, Req, State);
_ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end) _ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
end
end. end.
handle_request("/api/v2/" ++ Url, Req, #state{dispatch = Dispatch}) -> handle_request("/api/v2/" ++ Url, Req, #state{dispatch = Dispatch}) ->

View File

@ -387,7 +387,11 @@ shutdown(conflict, #proto_state{client_id = _ClientId}) ->
shutdown(Error, State = #proto_state{will_msg = WillMsg}) -> shutdown(Error, State = #proto_state{will_msg = WillMsg}) ->
?LOG(debug, "Shutdown for ~p", [Error], State), ?LOG(debug, "Shutdown for ~p", [Error], State),
Client = client(State), Client = client(State),
send_willmsg(Client, WillMsg), %% Auth failure not publish the will message
case Error =:= auth_failure of
true -> ok;
false -> send_willmsg(Client, WillMsg)
end,
emqttd_hooks:run('client.disconnected', [Error], Client), emqttd_hooks:run('client.disconnected', [Error], Client),
%% let it down %% let it down
%% emqttd_cm:unreg(ClientId). %% emqttd_cm:unreg(ClientId).

View File

@ -25,7 +25,7 @@
-http_api({"^nodes/(.+?)/clients/(.+?)/?$", 'GET',client_list, []}). -http_api({"^nodes/(.+?)/clients/(.+?)/?$", 'GET',client_list, []}).
-http_api({"^clients/(.+?)/?$", 'GET', client, []}). -http_api({"^clients/(.+?)/?$", 'GET', client, []}).
-http_api({"^clients/(.+?)/?$", 'DELETE', kick_client, []}). -http_api({"^clients/(.+?)/?$", 'DELETE', kick_client, []}).
-http_api({"^clients/(.+?)/clean_acl_cache?$", 'DELETE', clean_acl_cache, [{<<"topic">>, binary}]}). -http_api({"^clients/(.+?)/clean_acl_cache?$", 'PUT', clean_acl_cache, [{<<"topic">>, binary}]}).
-http_api({"^routes?$", 'GET', route_list, []}). -http_api({"^routes?$", 'GET', route_list, []}).
-http_api({"^routes/(.+?)/?$", 'GET', route, []}). -http_api({"^routes/(.+?)/?$", 'GET', route, []}).
@ -212,9 +212,10 @@ session_list('GET', Params, Node, ClientId) ->
{ok, [{objects, [session_row(Row) || Row <- Data]}]}. {ok, [{objects, [session_row(Row) || Row <- Data]}]}.
session_row({ClientId, _Pid, _Persistent, Session}) -> session_row({ClientId, _Pid, _Persistent, Session}) ->
InfoKeys = [clean_sess, max_inflight, inflight_queue, message_queue, Data = lists:append(Session, emqttd_stats:get_session_stats(ClientId)),
message_dropped, awaiting_rel, awaiting_ack, awaiting_comp, created_at], InfoKeys = [clean_sess, subscriptions, max_inflight, inflight_len, mqueue_len,
[{client_id, ClientId} | [{Key, format(Key, get_value(Key, Session))} || Key <- InfoKeys]]. mqueue_dropped, awaiting_rel_len, deliver_msg,enqueue_msg, created_at],
[{client_id, ClientId} | [{Key, format(Key, get_value(Key, Data))} || Key <- InfoKeys]].
%%-------------------------------------------------------------------------- %%--------------------------------------------------------------------------
%% subscription %% subscription