diff --git a/apps/emqx_dashboard/i18n/emqx_dashboard_i18n.conf b/apps/emqx_dashboard/i18n/emqx_dashboard_i18n.conf index 07bd75f9b..9badd75e0 100644 --- a/apps/emqx_dashboard/i18n/emqx_dashboard_i18n.conf +++ b/apps/emqx_dashboard/i18n/emqx_dashboard_i18n.conf @@ -132,6 +132,16 @@ Note: `sample_interval` should be a divisor of 60.""" zh: "HTTPS" } } + listener_enable { + desc { + en: "Ignore or enable this listener" + zh: "忽略或启用该监听器配置" + } + label { + en: "Enable" + zh: "启用" + } + } bind { desc { en: "Port without IP(18083) or port with specified IP(127.0.0.1:18083)." diff --git a/apps/emqx_dashboard/src/emqx_dashboard.erl b/apps/emqx_dashboard/src/emqx_dashboard.erl index c13e20b00..af96bb15a 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard.erl @@ -153,10 +153,13 @@ apps() -> ]. listeners(Listeners) -> - lists:map( + lists:filtermap( fun({Protocol, Conf}) -> - {Conf1, Bind} = ip_port(Conf), - {listener_name(Protocol, Conf1), Protocol, Bind, ranch_opts(Conf1)} + maps:get(enable, Conf) andalso + begin + {Conf1, Bind} = ip_port(Conf), + {true, {listener_name(Protocol, Conf1), Protocol, Bind, ranch_opts(Conf1)}} + end end, maps:to_list(Listeners) ). diff --git a/apps/emqx_dashboard/src/emqx_dashboard_schema.erl b/apps/emqx_dashboard/src/emqx_dashboard_schema.erl index 27a7aa571..0f4221c84 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_schema.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_schema.erl @@ -76,6 +76,44 @@ fields("listeners") -> )} ]; fields("http") -> + [ + {"enable", + sc( + boolean(), + #{ + default => true, + desc => ?DESC(listener_enable) + } + )} + | common_listener_fields() + ]; +fields("https") -> + [ + {"enable", + sc( + boolean(), + #{ + default => false, + desc => ?DESC(listener_enable) + } + )} + | common_listener_fields() ++ + exclude_fields( + ["enable", "fail_if_no_peer_cert"], + emqx_schema:server_ssl_opts_schema(#{}, true) + ) + ]. + +exclude_fields([], Fields) -> + Fields; +exclude_fields([FieldName | Rest], Fields) -> + %% assert field exists + case lists:keytake(FieldName, 1, Fields) of + {value, _, New} -> exclude_fields(Rest, New); + false -> error({FieldName, Fields}) + end. + +common_listener_fields() -> [ {"bind", fun bind/1}, {"num_acceptors", @@ -126,19 +164,18 @@ fields("http") -> desc => ?DESC(ipv6_v6only) } )} - ]; -fields("https") -> - fields("http") ++ - proplists:delete( - "fail_if_no_peer_cert", - emqx_schema:server_ssl_opts_schema(#{}, true) - ). + ]. -desc("dashboard") -> ?DESC(desc_dashboard); -desc("listeners") -> ?DESC(desc_listeners); -desc("http") -> ?DESC(desc_http); -desc("https") -> ?DESC(desc_https); -desc(_) -> undefined. +desc("dashboard") -> + ?DESC(desc_dashboard); +desc("listeners") -> + ?DESC(desc_listeners); +desc("http") -> + ?DESC(desc_http); +desc("https") -> + ?DESC(desc_https); +desc(_) -> + undefined. bind(type) -> hoconsc:union([non_neg_integer(), emqx_schema:ip_port()]); bind(default) -> 18083;