From 2faf26a372723ec40cc94277411e553c3a413e4f Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Wed, 22 Apr 2015 15:03:14 +0800 Subject: [PATCH] plugins.config, ERL_LIBS --- CHANGELOG.md | 10 +++++ plugins/TODO | 2 +- .../src/emqttd_plugin_demo.app.src | 4 +- .../src/emqttd_plugin_demo_acl.erl | 45 +++++++++++++++++++ .../src/emqttd_plugin_demo_app.erl | 5 ++- .../src/emqttd_plugin_demo_auth.erl | 42 +++++++++++++++++ rel/files/emqttd | 27 ++++++++++- 7 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_acl.erl create mode 100644 plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_auth.erl diff --git a/CHANGELOG.md b/CHANGELOG.md index fe7ceee41..bbefcff91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ emqttd ChangeLog ================== +0.7.0-alpha (2015-04-20) +------------------------- + +OK Trace API + +Plugin Load/Unload + +WebSocket + + 0.6.1-alpha (2015-04-20) ------------------------- diff --git a/plugins/TODO b/plugins/TODO index 73b14df1b..100b3a5c0 100644 --- a/plugins/TODO +++ b/plugins/TODO @@ -1,5 +1,5 @@ LDAP Auth MySQL Auth -Admin Console +Dashboard AMQP diff --git a/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo.app.src b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo.app.src index 1fd8ce62d..ecc0b1114 100644 --- a/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo.app.src +++ b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo.app.src @@ -1,7 +1,7 @@ {application, emqttd_plugin_demo, [ - {description, ""}, - {vsn, "1"}, + {description, "emqttd demo plugin"}, + {vsn, "0.1"}, {registered, []}, {applications, [ kernel, diff --git a/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_acl.erl b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_acl.erl new file mode 100644 index 000000000..424ee2c86 --- /dev/null +++ b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_acl.erl @@ -0,0 +1,45 @@ +%%%----------------------------------------------------------------------------- +%%% @Copyright (C) 2012-2015, Feng Lee +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a copy +%%% of this software and associated documentation files (the "Software"), to deal +%%% in the Software without restriction, including without limitation the rights +%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +%%% copies of the Software, and to permit persons to whom the Software is +%%% furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in all +%%% copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%%% SOFTWARE. +%%%----------------------------------------------------------------------------- +%%% @doc +%%% emqttd demo acl module. +%%% +%%% @end +%%%----------------------------------------------------------------------------- +-module(emqttd_plugin_demo_acl). + +-author("Feng Lee "). + +-include_lib("emqttd/include/emqttd.hrl"). + +-behaviour(emqttd_acl_mod). + +%% ACL callbacks +-export([init/1, check_acl/2, reload_acl/1, description/0]). + +init(Opts) -> {ok, Opts}. + +check_acl({_Client, _PubSub, _Topic}, _State) -> ignore. + +reload_acl(_State) -> ok. + +description() -> "Demo ACL Module". + diff --git a/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_app.erl b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_app.erl index 9042a449a..4976b2fc4 100644 --- a/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_app.erl +++ b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_app.erl @@ -10,7 +10,10 @@ %% =================================================================== start(_StartType, _StartArgs) -> - emqttd_plugin_demo_sup:start_link(). + {ok, Sup} = emqttd_plugin_demo_sup:start_link(), + emqttd_access_control:register_mod(auth, emqttd_plugin_demo_auth, []), + emqttd_access_control:register_mod(acl, emqttd_plugin_demo_acl, []), + {ok, Sup}. stop(_State) -> ok. diff --git a/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_auth.erl b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_auth.erl new file mode 100644 index 000000000..3e693335c --- /dev/null +++ b/plugins/emqttd_plugin_demo/src/emqttd_plugin_demo_auth.erl @@ -0,0 +1,42 @@ +%%%----------------------------------------------------------------------------- +%%% @Copyright (C) 2012-2015, Feng Lee +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a copy +%%% of this software and associated documentation files (the "Software"), to deal +%%% in the Software without restriction, including without limitation the rights +%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +%%% copies of the Software, and to permit persons to whom the Software is +%%% furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in all +%%% copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%%% SOFTWARE. +%%%----------------------------------------------------------------------------- +%%% @doc +%%% emqttd demo auth module. +%%% +%%% @end +%%%----------------------------------------------------------------------------- +-module(emqttd_plugin_demo_auth). + +-author("Feng Lee "). + +-include_lib("emqttd/include/emqttd.hrl"). + +-behaviour(emqttd_auth_mod). + +-export([init/1, check/3, description/0]). + +init(Opts) -> {ok, Opts}. + +check(_Client, _Password, _Opts) -> ignore. + +description() -> "Demo authentication module". + diff --git a/rel/files/emqttd b/rel/files/emqttd index 1fce9e89d..5157e28bc 100755 --- a/rel/files/emqttd +++ b/rel/files/emqttd @@ -20,6 +20,8 @@ RUNNER_BASE_DIR={{runner_base_dir}} RUNNER_ETC_DIR={{runner_etc_dir}} RUNNER_LIB_DIR={{platform_lib_dir}} RUNNER_LOG_DIR={{runner_log_dir}} +RUNNER_PLUGINS_DIR=$RUNNER_BASE_DIR/plugins + # Note the trailing slash on $PIPE_DIR/ PIPE_DIR={{pipe_dir}} RUNNER_USER={{runner_user}} @@ -139,6 +141,13 @@ case "$1" in echo $RES exit 1 fi + # Sanity check the plugins.config file + RES=`$NODETOOL_LITE chkconfig $RUNNER_ETC_DIR/plugins.config` + if [ $? != 0 ]; then + echo "Error reading $RUNNER_ETC_DIR/plugins.config" + echo $RES + exit 1 + fi HEART_COMMAND="$RUNNER_SCRIPT_DIR/$SCRIPT start" export HEART_COMMAND mkdir -p $PIPE_DIR @@ -256,17 +265,26 @@ case "$1" in echo $RES exit 1 fi + # Sanity check the plugins.config file + RES=`$NODETOOL_LITE chkconfig $RUNNER_ETC_DIR/plugins.config` + if [ $? != 0 ]; then + echo "Error reading $RUNNER_ETC_DIR/plugins.config" + echo $RES + exit 1 + fi # Setup beam-required vars ROOTDIR=$RUNNER_BASE_DIR + ERL_LIBS=$ROOTDIR/plugins BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin EMU=beam PROGNAME=`echo $0 | sed 's/.*\///'` CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$SCRIPT \ - -embedded -config $RUNNER_ETC_DIR/app.config \ + -embedded -config $RUNNER_ETC_DIR/app.config -config $RUNNER_ETC_DIR/plugins.config \ -pa $RUNNER_LIB_DIR/basho-patches \ -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}" export EMU export ROOTDIR + export ERL_LIBS export BINDIR export PROGNAME @@ -287,6 +305,13 @@ case "$1" in echo $RES exit 1 fi + # Sanity check the plugins.config file + RES=`$NODETOOL_LITE chkconfig $RUNNER_ETC_DIR/plugins.config` + if [ $? != 0 ]; then + echo "Error reading $RUNNER_ETC_DIR/plugins.config" + echo $RES + exit 1 + fi echo "config is OK" ;; escript)