diff --git a/etc/emq.conf b/etc/emq.conf index 1c0859921..e5fc93f75 100644 --- a/etc/emq.conf +++ b/etc/emq.conf @@ -137,12 +137,24 @@ 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 ## 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 diff --git a/priv/emq.schema b/priv/emq.schema index ce4baf36b..b1fdf138f 100644 --- a/priv/emq.schema +++ b/priv/emq.schema @@ -326,11 +326,31 @@ 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.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 +390,9 @@ 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, ConsoleLogLevel = cuttlefish:conf_get("log.console.level", Conf), @@ -381,9 +401,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 -> []; diff --git a/src/emqttd_auth_mod.erl b/src/emqttd_auth_mod.erl index c94578c46..d413446ff 100644 --- a/src/emqttd_auth_mod.erl +++ b/src/emqttd_auth_mod.erl @@ -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(<>) -> diff --git a/src/emqttd_http.erl b/src/emqttd_http.erl index bc5ba764d..a41025294 100644 --- a/src/emqttd_http.erl +++ b/src/emqttd_http.erl @@ -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}) -> diff --git a/src/emqttd_protocol.erl b/src/emqttd_protocol.erl index 0129faedd..31354dd84 100644 --- a/src/emqttd_protocol.erl +++ b/src/emqttd_protocol.erl @@ -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). diff --git a/src/emqttd_rest_api.erl b/src/emqttd_rest_api.erl index d0ab6a855..0c4bae3bf 100644 --- a/src/emqttd_rest_api.erl +++ b/src/emqttd_rest_api.erl @@ -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, []}). @@ -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