userinterface: Support AllowedRole

This commit is contained in:
Vivek Kumar Dutta 2024-05-23 12:53:55 +05:30
parent 83277d8a0c
commit cb37cc60b9
4 changed files with 21 additions and 16 deletions

View file

@ -17,7 +17,7 @@ endchoice
config USERINTERFACE_HTTPACCESS_MIGRATE_NGINX_CONFIG
bool "migrate nginx config"
depends on USERINTERFACE_HTTPACCESS_BACKEND_NGINX
default y
default n
help
Migrate nginx to userinterface on firmware upgrade
endif

View file

@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=userinterface
PKG_VERSION:=1.1.0
PKG_VERSION:=1.1.1
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/userinterface.git
PKG_SOURCE_VERSION:=8fd2afed32dea24ac5e0ce31f17b645ba852493f
PKG_SOURCE_VERSION:=e9bcaf53961d9e934abf081709c009ebbfcd73f9
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif

View file

@ -41,6 +41,7 @@ _set_server_params() {
config_get allow_host "${1}" allow_host
config_get protocol "${1}" protocol
config_get activationdate "${1}" activationdate
config_get redirect "${1}" redirect
if [ "$enable" -eq "0" ]; then
uci -q delete nginx."${1}"
@ -108,6 +109,18 @@ _set_server_params() {
uci_set nginx "${1}" "${opt//_nginx_}" "${val}"
fi
done
if [ -n "${redirect}" ]; then
config_get port "${redirect}" port
config_get protocol "${redirect}" protocol
if [ -n "${port}" ] && [ -n "${protocol}" ]; then
proto="$(echo ${protocol} | awk '{print tolower ($0)}')"
uci -q set nginx."${1}".return="302 ${proto}://\$host:${port}\$request_uri"
else
uci -q set nginx."${1}".return=""
fi
fi
}
# Public APIs

View file

@ -71,19 +71,12 @@ configure_ui_firewall_rule() {
local enabled access interface
local port=""
config_get_bool enabled "${sec}" uci_enable '1'
config_get access "${sec}" uci_access ""
config_get interface "${sec}" uci_interface ""
config_get_bool enabled "${sec}" enable '1'
config_get access "${sec}" access ""
config_get interface "${sec}" interface ""
config_get port "${sec}" port ""
if [ "${enabled}" -eq "1" ] && [ "${access}" == "remote" ] && [ -n "${interface}" ]; then
port_list=$(uci -q show nginx."${1}".listen|cut -d'=' -f 2|sed "s/'/ /g"|sed "s/\[\:\:\]\://g")
for item in ${port_list}; do
if [ -z "${item##[0-9]*}" ]; then
port="${item}"
break
fi
done
if [ -z "${port}" ]; then
return 0
fi
@ -119,7 +112,6 @@ config_load userinterface
config_get_bool serv_enable global enable 1
if [ "${serv_enable}" -eq "1" ]; then
config_load nginx
# Configure the User Interface rule
config_foreach configure_ui_firewall_rule server
config_foreach configure_ui_firewall_rule http_access
fi