commit
b1842b535f
30
etc/emq.conf
30
etc/emq.conf
|
@ -128,26 +128,44 @@ log.console = console
|
||||||
## Console log level. Enum: debug, info, notice, warning, error, critical, alert, emergency
|
## Console log level. Enum: debug, info, notice, warning, error, critical, alert, emergency
|
||||||
log.console.level = error
|
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
|
## 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
|
||||||
|
|
||||||
|
## Info log file size
|
||||||
|
## log.info.size = 10485760
|
||||||
|
|
||||||
|
## Info log file count
|
||||||
|
## log.info.count = 5
|
||||||
|
|
||||||
## 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
|
||||||
|
|
||||||
log.crash.file = {{ platform_log_dir }}/crash.log
|
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
|
## Allow Anonymous and Default ACL
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
|
|
|
@ -326,11 +326,45 @@ 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.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", [
|
{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 +404,18 @@ 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,
|
||||||
|
|
||||||
|
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,
|
end,
|
||||||
|
|
||||||
ConsoleLogLevel = cuttlefish:conf_get("log.console.level", Conf),
|
ConsoleLogLevel = cuttlefish:conf_get("log.console.level", Conf),
|
||||||
|
@ -381,9 +424,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 -> [];
|
||||||
|
@ -400,7 +443,7 @@ end}.
|
||||||
cuttlefish:conf_get("log.syslog.level", Conf)]}]
|
cuttlefish:conf_get("log.syslog.level", Conf)]}]
|
||||||
end,
|
end,
|
||||||
|
|
||||||
ConsoleHandlers ++ ErrorHandler ++ SyslogHandler
|
ConsoleHandlers ++ ErrorHandler ++ InfoHandler ++ SyslogHandler
|
||||||
end
|
end
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
|
|
@ -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>>) ->
|
||||||
|
|
|
@ -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) ->
|
||||||
_ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
|
Path = Req:get(path),
|
||||||
end
|
case Path of
|
||||||
|
"/api/v2/auth" -> handle_request(Path, Req, State);
|
||||||
|
_ -> if_authorized(Req, fun() -> handle_request(Path, Req, State) end)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle_request("/api/v2/" ++ Url, Req, #state{dispatch = Dispatch}) ->
|
handle_request("/api/v2/" ++ Url, Req, #state{dispatch = Dispatch}) ->
|
||||||
|
|
|
@ -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).
|
||||||
|
|
|
@ -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, []}).
|
||||||
|
@ -66,9 +66,9 @@
|
||||||
-http_api({"^users/?$", 'GET', users, []}).
|
-http_api({"^users/?$", 'GET', users, []}).
|
||||||
-http_api({"^users/?$", 'POST', users, [{<<"username">>, binary},
|
-http_api({"^users/?$", 'POST', users, [{<<"username">>, binary},
|
||||||
{<<"password">>, binary},
|
{<<"password">>, binary},
|
||||||
{<<"tag">>, binary}]}).
|
{<<"tags">>, binary}]}).
|
||||||
-http_api({"^users/(.+?)/?$", 'GET', users, []}).
|
-http_api({"^users/(.+?)/?$", 'GET', users, []}).
|
||||||
-http_api({"^users/(.+?)/?$", 'PUT', users, []}).
|
-http_api({"^users/(.+?)/?$", 'PUT', users, [{<<"tags">>, binary}]}).
|
||||||
-http_api({"^users/(.+?)/?$", 'DELETE', users, []}).
|
-http_api({"^users/(.+?)/?$", 'DELETE', users, []}).
|
||||||
|
|
||||||
-http_api({"^auth/?$", 'POST', auth, [{<<"username">>, binary}, {<<"password">>, binary}]}).
|
-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]}]}.
|
{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
|
||||||
|
|
Loading…
Reference in New Issue