mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
sulu: use mosquitto uci for services
This commit is contained in:
parent
34c0b3bb9e
commit
5419eb07d2
19 changed files with 198 additions and 152 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=sulu-builder
|
PKG_NAME:=sulu-builder
|
||||||
PKG_VERSION:=1.3.24
|
PKG_VERSION:=1.3.25
|
||||||
|
|
||||||
PKG_SOURCE_PROTO:=git
|
PKG_SOURCE_PROTO:=git
|
||||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/sulu-builder.git
|
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/sulu-builder.git
|
||||||
|
|
@ -162,11 +162,6 @@ endif
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/sulu
|
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/sulu
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/etc/mosquitto/conf.d/
|
|
||||||
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/obuspa.conf $(1)/etc/mosquitto/conf.d/
|
|
||||||
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/sulu.conf $(1)/etc/mosquitto/conf.d/
|
|
||||||
$(INSTALL_DATA) ./files/etc/mosquitto/sulu.password $(1)/etc/mosquitto/sulu.password
|
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/etc/sulu
|
$(INSTALL_DIR) $(1)/etc/sulu
|
||||||
$(INSTALL_DATA) ./files/etc/sulu/roles.json $(1)/etc/sulu/
|
$(INSTALL_DATA) ./files/etc/sulu/roles.json $(1)/etc/sulu/
|
||||||
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
|
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
|
||||||
|
|
@ -176,6 +171,7 @@ endif
|
||||||
$(INSTALL_BIN) ./files/etc/uci-defaults/99-fix-sulu-config $(1)/etc/uci-defaults/
|
$(INSTALL_BIN) ./files/etc/uci-defaults/99-fix-sulu-config $(1)/etc/uci-defaults/
|
||||||
$(INSTALL_BIN) ./files/etc/uci-defaults/40-add-sulu-nginx-config $(1)/etc/uci-defaults/
|
$(INSTALL_BIN) ./files/etc/uci-defaults/40-add-sulu-nginx-config $(1)/etc/uci-defaults/
|
||||||
$(INSTALL_BIN) ./files/etc/uci-defaults/01-update-nginx-uci-template $(1)/etc/uci-defaults/
|
$(INSTALL_BIN) ./files/etc/uci-defaults/01-update-nginx-uci-template $(1)/etc/uci-defaults/
|
||||||
|
$(INSTALL_BIN) ./files/etc/uci-defaults/10-add-mqtt-config $(1)/etc/uci-defaults/
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,${PKG_NAME}))
|
$(eval $(call BuildPackage,${PKG_NAME}))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
config global 'global'
|
config global 'global'
|
||||||
option enable_system_credentials '1'
|
|
||||||
option role_based_access '1'
|
option role_based_access '1'
|
||||||
list user 'admin'
|
list user 'admin'
|
||||||
list user 'user'
|
list user 'user'
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,9 @@ start_service() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
update_nginx_template
|
||||||
configure_sulu "${enable_system_credentials}" "${role_based_access}" 1
|
configure_sulu "${enable_system_credentials}" "${role_based_access}" 1
|
||||||
update_sulu_connection_port
|
generate_sulu_conn_config "${role_based_access}"
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
listener 1883 127.0.0.1
|
|
||||||
allow_anonymous true
|
|
||||||
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
listener 9001
|
|
||||||
protocol websockets
|
|
||||||
require_certificate false
|
|
||||||
allow_anonymous false
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
admin:$6$OmM9kU/lYct3KJ9j$iP0WK4ezEtRm8+EAggNp7WbJFoWO0p7IUdI0v/hr1WcVHyfFAC30Pb8Csn7GqwwqI2dcmnDOAITnimo2VNe6ug==
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
. /lib/functions.sh
|
. /lib/functions.sh
|
||||||
|
|
||||||
ACL_FILE="/tmp/sulu/mqtt.acl"
|
|
||||||
_RESTART_SERVICES="0"
|
_RESTART_SERVICES="0"
|
||||||
|
|
||||||
mkdir -p /tmp/sulu/
|
mkdir -p /tmp/sulu/
|
||||||
|
|
@ -54,6 +53,22 @@ function _get_sulu_root()
|
||||||
echo "${root:-/sulu}"
|
echo "${root:-/sulu}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _get_usp_upstream_port()
|
||||||
|
{
|
||||||
|
local port
|
||||||
|
|
||||||
|
port="$(uci -q get mosquitto.sulu.port)"
|
||||||
|
echo "${port:-9009}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _get_sulu_acl_file()
|
||||||
|
{
|
||||||
|
local file
|
||||||
|
|
||||||
|
file="$(uci -q get mosquitto.sulu.acl_file)"
|
||||||
|
echo "${file}"
|
||||||
|
}
|
||||||
|
|
||||||
function _get_sulu_tls_port()
|
function _get_sulu_tls_port()
|
||||||
{
|
{
|
||||||
local port listen
|
local port listen
|
||||||
|
|
@ -64,6 +79,19 @@ function _get_sulu_tls_port()
|
||||||
echo "${port:-8443}"
|
echo "${port:-8443}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_nginx_template()
|
||||||
|
{
|
||||||
|
local port
|
||||||
|
|
||||||
|
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
|
||||||
|
port="$(_get_usp_upstream_port)"
|
||||||
|
if ! grep -q "upstream websocket { server 127.0.0.1:${port}; }" ${UCI_TEMPLATE}; then
|
||||||
|
sed -i "s/upstream websocket { server 127.0.0.1:[0-9]\+; }/upstream websocket { server 127.0.0.1:${var}; }/" ${UCI_TEMPLATE}
|
||||||
|
log "Restarting nginx"
|
||||||
|
ubus call uci commit '{"config":"nginx"}'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function generate_sulu_conn_config()
|
function generate_sulu_conn_config()
|
||||||
{
|
{
|
||||||
local rbac users SCONFIG
|
local rbac users SCONFIG
|
||||||
|
|
@ -275,72 +303,40 @@ function _remove_obuspa_config_rbac()
|
||||||
}
|
}
|
||||||
|
|
||||||
function _create_acl() {
|
function _create_acl() {
|
||||||
local agentid rbac users
|
local agentid rbac users restart
|
||||||
|
local ACL_FILE
|
||||||
|
|
||||||
rbac="${1:-0}"
|
rbac="${1:-0}"
|
||||||
|
restart="0"
|
||||||
|
|
||||||
[ -f "${ACL_FILE}" ] && rm -f "${ACL_FILE}"
|
ACL_FILE="$(_get_sulu_acl_file)"
|
||||||
|
if [ -z "${ACL_FILE}" -o "${rbac}" -eq "0" ]; then
|
||||||
if [ "${rbac}" -eq "0" ]; then
|
return 0
|
||||||
return 0;
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
agentid="$(_get_agent_id)"
|
if [ -f "${ACL_FILE}" ]; then
|
||||||
users="$(_get_sulu_users)"
|
rm -f "${ACL_FILE}"
|
||||||
for f in ${users}; do
|
|
||||||
echo "user ${f}" >> ${ACL_FILE}
|
|
||||||
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
|
|
||||||
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
|
|
||||||
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
|
|
||||||
echo "" >> ${ACL_FILE}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_mosquitto_broker_config()
|
|
||||||
{
|
|
||||||
local system_cred rbac restart
|
|
||||||
|
|
||||||
MB_SULU_CONF="/etc/mosquitto/conf.d/sulu.conf"
|
|
||||||
system_cred="${1}"
|
|
||||||
rbac="${2}"
|
|
||||||
restart=0
|
|
||||||
|
|
||||||
if [ "${system_cred}" -eq "1" ]; then
|
|
||||||
if grep -q "password_file " ${MB_SULU_CONF}; then
|
|
||||||
sed -i '/password_file /d' ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
if ! grep -q "plugin .*mosquitto_auth_shadow.so" ${MB_SULU_CONF}; then
|
|
||||||
echo "plugin /usr/lib/mosquitto_auth_shadow.so" >> ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if grep -q 'plugin .*mosquitto_auth_shadow.so' ${MB_SULU_CONF}; then
|
|
||||||
sed -i '/plugin .*mosquitto_auth_shadow.so/d' ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
if ! grep -q "password_file /etc/mosquitto/sulu.password" ${MB_SULU_CONF}; then
|
|
||||||
echo "password_file /etc/mosquitto/sulu.password" >> ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
touch "${ACL_FILE}"
|
||||||
|
|
||||||
if [ "${rbac}" -eq "1" ]; then
|
if [ "${rbac}" -eq "1" ]; then
|
||||||
_create_acl "${rbac}"
|
users="$(_get_sulu_users)"
|
||||||
if ! grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
|
agentid="$(_get_agent_id)"
|
||||||
echo "acl_file ${ACL_FILE}" >> ${MB_SULU_CONF}
|
for f in ${users}; do
|
||||||
restart=1
|
if ! grep -q "user $f" ${ACL_FILE}; then
|
||||||
fi
|
echo "user ${f}" >> ${ACL_FILE}
|
||||||
else
|
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
|
||||||
if grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
|
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
|
||||||
sed -i '/acl_file /d' ${MB_SULU_CONF}
|
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
|
||||||
restart=1
|
echo "" >> ${ACL_FILE}
|
||||||
fi
|
restart="1"
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${_RESTART_SERVICES}" -eq "1" -a "${restart}" -eq "1" ]; then
|
if [ "${restart}" -gt "0" ]; then
|
||||||
slog "Restarting mqtt broker..."
|
slog "Restarting mosquitto..."
|
||||||
/etc/init.d/mosquitto restart &
|
ubus call uci commit '{"config":"mosquitto"}'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -386,7 +382,7 @@ function configure_sulu()
|
||||||
|
|
||||||
_RESTART_SERVICES="${restart}"
|
_RESTART_SERVICES="${restart}"
|
||||||
|
|
||||||
update_mosquitto_broker_config "${sys_cred}" "${rbac}"
|
|
||||||
set_sulu_connection_mode "${rbac}"
|
set_sulu_connection_mode "${rbac}"
|
||||||
update_obuspa_config "${rbac}"
|
update_obuspa_config "${rbac}"
|
||||||
|
_create_acl "${rbac}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
|
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
|
||||||
update_nginx_uci_template()
|
update_nginx_uci_template()
|
||||||
{
|
{
|
||||||
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
|
if ! grep -q "upstream websocket" ${UCI_TEMPLATE}; then
|
||||||
sed -i '/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:9001; }' ${UCI_TEMPLATE}
|
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
|
||||||
|
sed -i '/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:9009; }' ${UCI_TEMPLATE}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_nginx_uci_template
|
update_nginx_uci_template
|
||||||
|
|
|
||||||
37
sulu-builder/files/etc/uci-defaults/10-add-mqtt-config
Executable file
37
sulu-builder/files/etc/uci-defaults/10-add-mqtt-config
Executable file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
|
||||||
|
if [ ! -f "/etc/config/mosquitto" ]; then
|
||||||
|
echo "Local mosquitto broker not available"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
add_obuspa_config()
|
||||||
|
{
|
||||||
|
if ! uci_get mosquitto obuspa >/dev/null 2>&1; then
|
||||||
|
uci_add mosquitto listener obuspa
|
||||||
|
uci_set mosquitto obuspa enabled 1
|
||||||
|
uci_set mosquitto obuspa port '1883'
|
||||||
|
uci_set mosquitto obuspa no_remote_access '1'
|
||||||
|
uci_set mosquitto obuspa allow_anonymous '1'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add_sulu_config()
|
||||||
|
{
|
||||||
|
if ! uci_get mosquitto sulu >/dev/null 2>&1; then
|
||||||
|
uci_add mosquitto listener sulu
|
||||||
|
uci_set mosquitto sulu enabled 1
|
||||||
|
uci_set mosquitto sulu port '9009'
|
||||||
|
uci_set mosquitto sulu no_remote_access '1'
|
||||||
|
uci_set mosquitto sulu protocol 'websockets'
|
||||||
|
uci_set mosquitto sulu require_certificates '0'
|
||||||
|
uci_set mosquitto sulu auth_plugin '/usr/lib/mosquitto_auth_shadow.so'
|
||||||
|
uci_set mosquitto sulu acl_file '/tmp/sulu/mqtt.acl'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
uci_load mosquitto
|
||||||
|
add_obuspa_config
|
||||||
|
add_sulu_config
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=sulu
|
PKG_NAME:=sulu
|
||||||
PKG_VERSION:=1.3.24
|
PKG_VERSION:=1.3.25
|
||||||
|
|
||||||
PKG_SOURCE_PROTO:=git
|
PKG_SOURCE_PROTO:=git
|
||||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/sulu.git
|
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/sulu.git
|
||||||
|
|
@ -49,11 +49,6 @@ endif
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/sulu
|
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/sulu
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/etc/mosquitto/conf.d/
|
|
||||||
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/obuspa.conf $(1)/etc/mosquitto/conf.d/
|
|
||||||
$(INSTALL_DATA) ./files/etc/mosquitto/conf.d/sulu.conf $(1)/etc/mosquitto/conf.d/
|
|
||||||
$(INSTALL_DATA) ./files/etc/mosquitto/sulu.password $(1)/etc/mosquitto/sulu.password
|
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/etc/sulu
|
$(INSTALL_DIR) $(1)/etc/sulu
|
||||||
$(INSTALL_DATA) ./files/etc/sulu/roles.json $(1)/etc/sulu/
|
$(INSTALL_DATA) ./files/etc/sulu/roles.json $(1)/etc/sulu/
|
||||||
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
|
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
|
||||||
|
|
@ -63,6 +58,7 @@ endif
|
||||||
$(INSTALL_BIN) ./files/etc/uci-defaults/99-fix-sulu-config $(1)/etc/uci-defaults/
|
$(INSTALL_BIN) ./files/etc/uci-defaults/99-fix-sulu-config $(1)/etc/uci-defaults/
|
||||||
$(INSTALL_BIN) ./files/etc/uci-defaults/40-add-sulu-nginx-config $(1)/etc/uci-defaults/
|
$(INSTALL_BIN) ./files/etc/uci-defaults/40-add-sulu-nginx-config $(1)/etc/uci-defaults/
|
||||||
$(INSTALL_BIN) ./files/etc/uci-defaults/01-update-nginx-uci-template $(1)/etc/uci-defaults/
|
$(INSTALL_BIN) ./files/etc/uci-defaults/01-update-nginx-uci-template $(1)/etc/uci-defaults/
|
||||||
|
$(INSTALL_BIN) ./files/etc/uci-defaults/10-add-mqtt-config $(1)/etc/uci-defaults/
|
||||||
endef
|
endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,sulu))
|
$(eval $(call BuildPackage,sulu))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
config global 'global'
|
config global 'global'
|
||||||
option enable_system_credentials '1'
|
|
||||||
option role_based_access '1'
|
option role_based_access '1'
|
||||||
list user 'admin'
|
list user 'admin'
|
||||||
list user 'user'
|
list user 'user'
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,9 @@ start_service() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
update_nginx_template
|
||||||
configure_sulu "${enable_system_credentials}" "${role_based_access}" 1
|
configure_sulu "${enable_system_credentials}" "${role_based_access}" 1
|
||||||
update_sulu_connection_port
|
generate_sulu_conn_config "${role_based_access}"
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
listener 1883 127.0.0.1
|
|
||||||
allow_anonymous true
|
|
||||||
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
listener 9001
|
|
||||||
protocol websockets
|
|
||||||
require_certificate false
|
|
||||||
allow_anonymous false
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
admin:$6$OmM9kU/lYct3KJ9j$iP0WK4ezEtRm8+EAggNp7WbJFoWO0p7IUdI0v/hr1WcVHyfFAC30Pb8Csn7GqwwqI2dcmnDOAITnimo2VNe6ug==
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
. /lib/functions.sh
|
. /lib/functions.sh
|
||||||
|
|
||||||
ACL_FILE="/tmp/sulu/mqtt.acl"
|
|
||||||
_RESTART_SERVICES="0"
|
_RESTART_SERVICES="0"
|
||||||
|
|
||||||
mkdir -p /tmp/sulu/
|
mkdir -p /tmp/sulu/
|
||||||
|
|
@ -54,6 +53,22 @@ function _get_sulu_root()
|
||||||
echo "${root:-/sulu}"
|
echo "${root:-/sulu}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _get_usp_upstream_port()
|
||||||
|
{
|
||||||
|
local port
|
||||||
|
|
||||||
|
port="$(uci -q get mosquitto.sulu.port)"
|
||||||
|
echo "${port:-9009}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _get_sulu_acl_file()
|
||||||
|
{
|
||||||
|
local file
|
||||||
|
|
||||||
|
file="$(uci -q get mosquitto.sulu.acl_file)"
|
||||||
|
echo "${file}"
|
||||||
|
}
|
||||||
|
|
||||||
function _get_sulu_tls_port()
|
function _get_sulu_tls_port()
|
||||||
{
|
{
|
||||||
local port listen
|
local port listen
|
||||||
|
|
@ -64,6 +79,19 @@ function _get_sulu_tls_port()
|
||||||
echo "${port:-8443}"
|
echo "${port:-8443}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_nginx_template()
|
||||||
|
{
|
||||||
|
local port
|
||||||
|
|
||||||
|
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
|
||||||
|
port="$(_get_usp_upstream_port)"
|
||||||
|
if ! grep -q "upstream websocket { server 127.0.0.1:${port}; }" ${UCI_TEMPLATE}; then
|
||||||
|
sed -i "s/upstream websocket { server 127.0.0.1:[0-9]\+; }/upstream websocket { server 127.0.0.1:${var}; }/" ${UCI_TEMPLATE}
|
||||||
|
log "Restarting nginx"
|
||||||
|
ubus call uci commit '{"config":"nginx"}'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function generate_sulu_conn_config()
|
function generate_sulu_conn_config()
|
||||||
{
|
{
|
||||||
local rbac users SCONFIG
|
local rbac users SCONFIG
|
||||||
|
|
@ -275,72 +303,40 @@ function _remove_obuspa_config_rbac()
|
||||||
}
|
}
|
||||||
|
|
||||||
function _create_acl() {
|
function _create_acl() {
|
||||||
local agentid rbac users
|
local agentid rbac users restart
|
||||||
|
local ACL_FILE
|
||||||
|
|
||||||
rbac="${1:-0}"
|
rbac="${1:-0}"
|
||||||
|
restart="0"
|
||||||
|
|
||||||
[ -f "${ACL_FILE}" ] && rm -f "${ACL_FILE}"
|
ACL_FILE="$(_get_sulu_acl_file)"
|
||||||
|
if [ -z "${ACL_FILE}" -o "${rbac}" -eq "0" ]; then
|
||||||
if [ "${rbac}" -eq "0" ]; then
|
return 0
|
||||||
return 0;
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
agentid="$(_get_agent_id)"
|
if [ -f "${ACL_FILE}" ]; then
|
||||||
users="$(_get_sulu_users)"
|
rm -f "${ACL_FILE}"
|
||||||
for f in ${users}; do
|
|
||||||
echo "user ${f}" >> ${ACL_FILE}
|
|
||||||
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
|
|
||||||
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
|
|
||||||
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
|
|
||||||
echo "" >> ${ACL_FILE}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_mosquitto_broker_config()
|
|
||||||
{
|
|
||||||
local system_cred rbac restart
|
|
||||||
|
|
||||||
MB_SULU_CONF="/etc/mosquitto/conf.d/sulu.conf"
|
|
||||||
system_cred="${1}"
|
|
||||||
rbac="${2}"
|
|
||||||
restart=0
|
|
||||||
|
|
||||||
if [ "${system_cred}" -eq "1" ]; then
|
|
||||||
if grep -q "password_file " ${MB_SULU_CONF}; then
|
|
||||||
sed -i '/password_file /d' ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
if ! grep -q "plugin .*mosquitto_auth_shadow.so" ${MB_SULU_CONF}; then
|
|
||||||
echo "plugin /usr/lib/mosquitto_auth_shadow.so" >> ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if grep -q 'plugin .*mosquitto_auth_shadow.so' ${MB_SULU_CONF}; then
|
|
||||||
sed -i '/plugin .*mosquitto_auth_shadow.so/d' ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
if ! grep -q "password_file /etc/mosquitto/sulu.password" ${MB_SULU_CONF}; then
|
|
||||||
echo "password_file /etc/mosquitto/sulu.password" >> ${MB_SULU_CONF}
|
|
||||||
restart=1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
touch "${ACL_FILE}"
|
||||||
|
|
||||||
if [ "${rbac}" -eq "1" ]; then
|
if [ "${rbac}" -eq "1" ]; then
|
||||||
_create_acl "${rbac}"
|
users="$(_get_sulu_users)"
|
||||||
if ! grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
|
agentid="$(_get_agent_id)"
|
||||||
echo "acl_file ${ACL_FILE}" >> ${MB_SULU_CONF}
|
for f in ${users}; do
|
||||||
restart=1
|
if ! grep -q "user $f" ${ACL_FILE}; then
|
||||||
fi
|
echo "user ${f}" >> ${ACL_FILE}
|
||||||
else
|
echo "topic read /usp/${agentid}/${f}/controller/reply-to/#" >> ${ACL_FILE}
|
||||||
if grep -q "acl_file ${ACL_FILE}" ${MB_SULU_CONF}; then
|
echo "topic write /usp/${agentid}/${f}/endpoint/#" >> ${ACL_FILE}
|
||||||
sed -i '/acl_file /d' ${MB_SULU_CONF}
|
echo "topic read /usp/${agentid}/${f}/controller/#" >> ${ACL_FILE}
|
||||||
restart=1
|
echo "" >> ${ACL_FILE}
|
||||||
fi
|
restart="1"
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${_RESTART_SERVICES}" -eq "1" -a "${restart}" -eq "1" ]; then
|
if [ "${restart}" -gt "0" ]; then
|
||||||
slog "Restarting mqtt broker..."
|
slog "Restarting mosquitto..."
|
||||||
/etc/init.d/mosquitto restart &
|
ubus call uci commit '{"config":"mosquitto"}'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -386,7 +382,7 @@ function configure_sulu()
|
||||||
|
|
||||||
_RESTART_SERVICES="${restart}"
|
_RESTART_SERVICES="${restart}"
|
||||||
|
|
||||||
update_mosquitto_broker_config "${sys_cred}" "${rbac}"
|
|
||||||
set_sulu_connection_mode "${rbac}"
|
set_sulu_connection_mode "${rbac}"
|
||||||
update_obuspa_config "${rbac}"
|
update_obuspa_config "${rbac}"
|
||||||
|
_create_acl "${rbac}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
sulu/files/etc/uci-defaults/01-update-nginx-uci-template
Normal file → Executable file
6
sulu/files/etc/uci-defaults/01-update-nginx-uci-template
Normal file → Executable file
|
|
@ -3,8 +3,10 @@
|
||||||
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
|
UCI_TEMPLATE="/etc/nginx/uci.conf.template"
|
||||||
update_nginx_uci_template()
|
update_nginx_uci_template()
|
||||||
{
|
{
|
||||||
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
|
if ! grep -q "upstream websocket" ${UCI_TEMPLATE}; then
|
||||||
sed -i '/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:9001; }' ${UCI_TEMPLATE}
|
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
|
||||||
|
sed -i '/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:9009; }' ${UCI_TEMPLATE}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_nginx_uci_template
|
update_nginx_uci_template
|
||||||
|
|
|
||||||
37
sulu/files/etc/uci-defaults/10-add-mqtt-config
Executable file
37
sulu/files/etc/uci-defaults/10-add-mqtt-config
Executable file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
|
||||||
|
if [ ! -f "/etc/config/mosquitto" ]; then
|
||||||
|
echo "Local mosquitto broker not available"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
add_obuspa_config()
|
||||||
|
{
|
||||||
|
if ! uci_get mosquitto obuspa >/dev/null 2>&1; then
|
||||||
|
uci_add mosquitto listener obuspa
|
||||||
|
uci_set mosquitto obuspa enabled 1
|
||||||
|
uci_set mosquitto obuspa port '1883'
|
||||||
|
uci_set mosquitto obuspa no_remote_access '1'
|
||||||
|
uci_set mosquitto obuspa allow_anonymous '1'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add_sulu_config()
|
||||||
|
{
|
||||||
|
if ! uci_get mosquitto sulu >/dev/null 2>&1; then
|
||||||
|
uci_add mosquitto listener sulu
|
||||||
|
uci_set mosquitto sulu enabled 1
|
||||||
|
uci_set mosquitto sulu port '9009'
|
||||||
|
uci_set mosquitto sulu no_remote_access '1'
|
||||||
|
uci_set mosquitto sulu protocol 'websockets'
|
||||||
|
uci_set mosquitto sulu require_certificates '0'
|
||||||
|
uci_set mosquitto sulu auth_plugin '/usr/lib/mosquitto_auth_shadow.so'
|
||||||
|
uci_set mosquitto sulu acl_file '/tmp/sulu/mqtt.acl'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
uci_load mosquitto
|
||||||
|
add_obuspa_config
|
||||||
|
add_sulu_config
|
||||||
0
sulu/files/etc/uci-defaults/99-fix-sulu-config
Normal file → Executable file
0
sulu/files/etc/uci-defaults/99-fix-sulu-config
Normal file → Executable file
Loading…
Add table
Reference in a new issue