Merge pull request #1289 from emqtt/emq24

Version 2.3-rc.1
This commit is contained in:
huangdan 2017-10-11 07:10:00 -05:00 committed by GitHub
commit b1842b535f
6 changed files with 95 additions and 27 deletions

View File

@ -128,26 +128,44 @@ log.console = console
## Console log level. Enum: debug, info, notice, warning, error, critical, alert, emergency
log.console.level = error
## Syslog. Enum: on, off
log.syslog = on
## syslog level. Enum: debug, info, notice, warning, error, critical, alert, emergency
log.syslog.level = error
## Console log file
## 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
## log.info.file = {{ platform_log_dir }}/info.log
## Info log file size
## log.info.size = 10485760
## Info log file count
## log.info.count = 5
## Error log file
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
log.crash = on
log.crash.file = {{ platform_log_dir }}/crash.log
## Syslog. Enum: on, off
log.syslog = on
## syslog level. Enum: debug, info, notice, warning, error, critical, alert, emergency
log.syslog.level = error
##--------------------------------------------------------------------
## Allow Anonymous and Default ACL
##--------------------------------------------------------------------

View File

@ -326,11 +326,45 @@ end}.
{datatype, file}
]}.
{mapping, "log.console.size", "lager.handlers", [
{default, 10485760},
{datatype, integer}
]}.
{mapping, "log.console.count", "lager.handlers", [
{default, 5},
{datatype, integer}
]}.
{mapping, "log.info.file", "lager.handlers", [
{datatype, file}
]}.
{mapping, "log.info.size", "lager.handlers", [
{default, 10485760},
{datatype, integer}
]}.
{mapping, "log.info.count", "lager.handlers", [
{default, 5},
{datatype, integer}
]}.
{mapping, "log.error.file", "lager.handlers", [
{default, "log/error.log"},
{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", [
{default, off},
{datatype, flag}
@ -370,9 +404,18 @@ end}.
undefined -> [];
ErrorFilename -> [{lager_file_backend, [{file, ErrorFilename},
{level, error},
{size, 10485760},
{size, cuttlefish:conf_get("log.error.size", Conf)},
{date, "$D0"},
{count, 5}]}]
{count, cuttlefish:conf_get("log.error.count", Conf)}]}]
end,
InfoHandler = case cuttlefish:conf_get("log.info.file", Conf, undefined) of
undefined -> [];
InfoFilename -> [{lager_file_backend, [{file, InfoFilename},
{level, info},
{size, cuttlefish:conf_get("log.info.size", Conf)},
{date, "$D0"},
{count, cuttlefish:conf_get("log.info.count", Conf)}]}]
end,
ConsoleLogLevel = cuttlefish:conf_get("log.console.level", Conf),
@ -381,9 +424,9 @@ end}.
ConsoleHandler = {lager_console_backend, ConsoleLogLevel},
ConsoleFileHandler = {lager_file_backend, [{file, ConsoleLogFile},
{level, ConsoleLogLevel},
{size, 10485760},
{size, cuttlefish:conf_get("log.console.size", Conf)},
{date, "$D0"},
{count, 5}]},
{count, cuttlefish:conf_get("log.console.count", Conf)}]},
ConsoleHandlers = case cuttlefish:conf_get("log.console", Conf) of
off -> [];
@ -400,7 +443,7 @@ end}.
cuttlefish:conf_get("log.syslog.level", Conf)]}]
end,
ConsoleHandlers ++ ErrorHandler ++ SyslogHandler
ConsoleHandlers ++ ErrorHandler ++ InfoHandler ++ SyslogHandler
end
}.

View File

@ -63,12 +63,12 @@ passwd_hash(sha256, Password) ->
passwd_hash(pbkdf2, {Salt, Password, Macfun, Iterations, Dklen}) ->
case pbkdf2:pbkdf2(Macfun, Password, Salt, Iterations, Dklen) of
{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;
passwd_hash(bcrypt, {Salt, Password}) ->
case bcrypt:hashpw(Password, Salt) of
{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.
hexstring(<<X:128/big-unsigned-integer>>) ->

View File

@ -26,7 +26,7 @@
-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").
@ -54,12 +54,14 @@ handle_request(Req, State) ->
"/api/v2/auth" ->
handle_request(Path, Req, State);
_ ->
Host = Req:get_header_value("Host"),
[_, Port] = string:tokens(Host, ":"),
case Port of
"18083" -> handle_request(Path, Req, State);
_ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
end
if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
end.
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)
end.
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}) ->
?LOG(debug, "Shutdown for ~p", [Error], 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),
%% let it down
%% emqttd_cm:unreg(ClientId).

View File

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