From 4c38cb37f5bdedae9941b6f12898801c91497ac1 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 1 Jun 2015 12:36:30 +0800 Subject: [PATCH 1/5] use re:replace/4 to fill username --- plugins/emqttd_auth_ldap/src/emqttd_auth_ldap.erl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/emqttd_auth_ldap/src/emqttd_auth_ldap.erl b/plugins/emqttd_auth_ldap/src/emqttd_auth_ldap.erl index ba1bdca4d..965aaeefe 100644 --- a/plugins/emqttd_auth_ldap/src/emqttd_auth_ldap.erl +++ b/plugins/emqttd_auth_ldap/src/emqttd_auth_ldap.erl @@ -82,10 +82,7 @@ ldap_bind(LDAP, UserDn, Password) -> end. fill(Username, UserDn) -> - lists:append(lists:map( - fun("$u") -> Username; - (S) -> S - end, string:tokens(UserDn, ",="))). + re:replace(UserDn, "\\$u", Username, [global, {return, list}]). description() -> "LDAP Authentication Module". From 8aa2b8fbedbf3e306eec065b69dd6b60d3a304a8 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 1 Jun 2015 16:41:59 +0800 Subject: [PATCH 2/5] fix the issue that websocket client cannot subscribe '/queue/#' --- apps/emqttd/src/emqttd_ws_client.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/emqttd/src/emqttd_ws_client.erl b/apps/emqttd/src/emqttd_ws_client.erl index 23ac6aff0..52a7ba7d9 100644 --- a/apps/emqttd/src/emqttd_ws_client.erl +++ b/apps/emqttd/src/emqttd_ws_client.erl @@ -145,6 +145,10 @@ handle_info({redeliver, {?PUBREL, PacketId}}, #state{proto_state = ProtoState} = {ok, ProtoState1} = emqttd_protocol:redeliver({?PUBREL, PacketId}, ProtoState), {noreply, State#state{proto_state = ProtoState1}}; +handle_info({subscribe, Topic, Qos}, #state{proto_state = ProtoState} = State) -> + {ok, ProtoState1} = emqttd_protocol:handle({subscribe, Topic, Qos}, ProtoState), + {noreply, State#state{proto_state = ProtoState1}}; + handle_info({stop, duplicate_id, _NewPid}, State=#state{proto_state = ProtoState}) -> lager:error("Shutdown for duplicate clientid: ~s", [emqttd_protocol:clientid(ProtoState)]), stop({shutdown, duplicate_id}, State); @@ -169,7 +173,8 @@ handle_info({keepalive, timeout}, State = #state{request = Req, keepalive = Keep handle_info({'EXIT', WsPid, Reason}, State = #state{ws_pid = WsPid}) -> stop(Reason, State); -handle_info(_Info, State) -> +handle_info(Info, State = #state{request = Req}) -> + lager:critical("Client(WebSocket) ~s: Unexpected Info - ~p", [Req:get(peer), Info]), {noreply, State}. terminate(Reason, #state{proto_state = ProtoState, keepalive = KeepAlive}) -> From bc4c8a94010d217727394ce2ba3655df93243cb7 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 1 Jun 2015 17:05:13 +0800 Subject: [PATCH 3/5] 0.8.2 --- CHANGELOG.md | 8 ++++++++ README.md | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c32652458..40566d051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ emqttd ChangeLog ================== +0.8.2-alpha (2015-06-01) +------------------------- + +Bugfix: issue #147 - WebSocket client cannot subscribe queue '$Q/queue/${clientId}' + +Bugfix: issue #146 - emqttd_auth_ldap: fill(Username, UserDn) is not right + + 0.8.1-alpha (2015-05-28) ------------------------- diff --git a/README.md b/README.md index bc86472e7..c09b3f05b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,16 @@ emqttd is aimed to provide a solid, enterprise grade, extensible open-source MQT * Passed eclipse paho interoperability tests +## Plugins + +* [emqttd_auth_clientid](https://github.com/emqtt/emqttd/wiki/Authentication) - Authentication with ClientIds +* emqttd_auth_mysql - Authentication with MySQL +* emqttd_auth_ldap - Authentication with LDAP +* emqttd_mod_autosub - Subscribe some topics automatically when client connected +* [emqttd_mod_presence](https://github.com/emqtt/emqttd/wiki/Presence) - Publish presence message to $SYS topics when client connected or disconnected +* [emqttd_mod_rewrite](https://github.com/emqtt/emqttd/wiki/Rewrite) - Topics rewrite like HTTP rewrite module + + ## Design ![emqttd architecture](http://emqtt.io/static/img/Architecture.png) From f3dbb7ba540863962f960202016f0b00c3a59b24 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 1 Jun 2015 17:45:45 +0800 Subject: [PATCH 4/5] 0.8.2 --- apps/emqtt/src/emqtt.app.src | 2 +- apps/emqttd/src/emqttd.app.src | 2 +- rel/reltool.config | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/emqtt/src/emqtt.app.src b/apps/emqtt/src/emqtt.app.src index 488ebbb8e..6f545b0bc 100644 --- a/apps/emqtt/src/emqtt.app.src +++ b/apps/emqtt/src/emqtt.app.src @@ -1,7 +1,7 @@ {application, emqtt, [ {description, "Erlang MQTT Common Library"}, - {vsn, "0.8.1"}, + {vsn, "0.8.2"}, {modules, []}, {registered, []}, {applications, [ diff --git a/apps/emqttd/src/emqttd.app.src b/apps/emqttd/src/emqttd.app.src index b7459e519..a6004f473 100644 --- a/apps/emqttd/src/emqttd.app.src +++ b/apps/emqttd/src/emqttd.app.src @@ -1,7 +1,7 @@ {application, emqttd, [ {description, "Erlang MQTT Broker"}, - {vsn, "0.8.1"}, + {vsn, "0.8.2"}, {modules, []}, {registered, []}, {applications, [kernel, diff --git a/rel/reltool.config b/rel/reltool.config index ace833401..1ea929f55 100644 --- a/rel/reltool.config +++ b/rel/reltool.config @@ -4,7 +4,7 @@ {lib_dirs, ["../apps", "../deps", "../plugins"]}, {erts, [{mod_cond, derived}, {app_file, strip}]}, {app_file, strip}, - {rel, "emqttd", "0.8.1", + {rel, "emqttd", "0.8.2", [ kernel, stdlib, From 5a75e59dd1842cbfe062de5e0e5b74938d918bd9 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Tue, 2 Jun 2015 12:52:40 +0800 Subject: [PATCH 5/5] fix mysql auth error --- apps/emqttd/src/emqttd_access_control.erl | 1 + plugins/emqttd_auth_mysql/etc/plugin.config | 3 ++- plugins/emqttd_auth_mysql/src/emqttd_auth_mysql.erl | 8 ++++++-- plugins/emqttd_auth_mysql/src/emqttd_auth_mysql_app.erl | 2 +- rel/files/plugins.config | 7 ++++++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/emqttd/src/emqttd_access_control.erl b/apps/emqttd/src/emqttd_access_control.erl index 3f1ca1b36..30efa0ad5 100644 --- a/apps/emqttd/src/emqttd_access_control.erl +++ b/apps/emqttd/src/emqttd_access_control.erl @@ -179,6 +179,7 @@ handle_call({register_mod, Type, Mod, Opts}, _From, State) -> ets:insert(?ACCESS_CONTROL_TAB, {tab_key(Type), [{Mod, ModState}|Mods]}), ok; {'EXIT', Error} -> + lager:error("Access Control: register ~s error - ~p", [Mod, Error]), {error, Error} end; _ -> diff --git a/plugins/emqttd_auth_mysql/etc/plugin.config b/plugins/emqttd_auth_mysql/etc/plugin.config index a5ef4bc41..367983f5f 100644 --- a/plugins/emqttd_auth_mysql/etc/plugin.config +++ b/plugins/emqttd_auth_mysql/etc/plugin.config @@ -9,8 +9,9 @@ ]}, {emqttd_auth_mysql, [ {users_table, mqtt_users}, + {password_hash, plain}, {field_mapper, [ {username, username}, - {password, password, plain} + {password, password} ]} ]} diff --git a/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql.erl b/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql.erl index cf2d32cbc..be8685103 100644 --- a/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql.erl +++ b/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql.erl @@ -38,15 +38,19 @@ init(Opts) -> Mapper = proplists:get_value(field_mapper, Opts), - {ok, #state{user_table = proplists:get_value(user_table, Opts, mqtt_users), + {ok, #state{user_table = proplists:get_value(user_table, Opts), name_field = proplists:get_value(username, Mapper), pass_field = proplists:get_value(password, Mapper), - pass_hash = proplists:get_value(Opts, password_hash)}}. + pass_hash = proplists:get_value(password_hash, Opts)}}. check(#mqtt_client{username = undefined}, _Password, _State) -> {error, "Username undefined"}; +check(#mqtt_client{username = <<>>}, _Password, _State) -> + {error, "Username undefined"}; check(_Client, undefined, _State) -> {error, "Password undefined"}; +check(_Client, <<>>, _State) -> + {error, "Password undefined"}; check(#mqtt_client{username = Username}, Password, #state{user_table = UserTab, pass_hash = Type, name_field = NameField, pass_field = PassField}) -> diff --git a/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql_app.erl b/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql_app.erl index 86881a4bb..11734fbad 100644 --- a/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql_app.erl +++ b/plugins/emqttd_auth_mysql/src/emqttd_auth_mysql_app.erl @@ -40,7 +40,7 @@ start(_StartType, _StartArgs) -> Env = application:get_all_env(), - emqttd_access_control:register_mod(auth, emqttd_auth_mysql, Env), + ok = emqttd_access_control:register_mod(auth, emqttd_auth_mysql, Env), supervisor:start_link({local, ?MODULE}, ?MODULE, []). prep_stop(State) -> diff --git a/rel/files/plugins.config b/rel/files/plugins.config index 57dcb8abf..c2fde4d51 100644 --- a/rel/files/plugins.config +++ b/rel/files/plugins.config @@ -9,7 +9,12 @@ % {encoding, utf8} % ]}, % {emqttd_auth_mysql, [ -% {user_table, mqtt_users} +% {users_table, mqtt_users}, +% {password_hash, plain}, +% {field_mapper, [ +% {username, username}, +% {password, password} +% ]} % ]} % % {emqttd_dashboard, [