uhttpd: support multiple Lua prefixes

Update to latest git HEAD in order to support configuring multiple
concurrent Lua prefixes in a single uhttpd instance:

  b741dec lua: support multiple Lua prefixes

Additionally rework the init script and update the default configuration
example to treat the lua_prefix option as key=value uci list, similar to
the interpreter extension mapping. Support for the old "option lua_prefix"
plus "option lua_handler" notation is still present.

Finally drop the sed postinstall hack in uhttpd-mod-lua to avoid mangling
files belonging to other packages. Since Lua prefixes have precedence
over CGI prefixes, simply register `/cgi-bin/luci` as Lua handler which
will only become active if both luci-base and uhttpd-mod-lua is installed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2018-08-23 09:07:23 +02:00
parent 7e73e9128f
commit 214146c6f2
3 changed files with 32 additions and 21 deletions

View file

@ -12,9 +12,9 @@ PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/uhttpd.git
PKG_SOURCE_DATE:=2018-08-21
PKG_SOURCE_VERSION:=952bf9d754d021ee9c08f9add5c9af53aaaf39ae
PKG_MIRROR_HASH:=34cd66b4c8b4a384e31f3821a4536854491ed2cd62f49c7ae0b0cd4381f061dd
PKG_SOURCE_DATE:=2018-08-23
PKG_SOURCE_VERSION:=b741dec35698a80266fb8206970638e666774a33
PKG_MIRROR_HASH:=2f7c88ba1b36dd6776a7d954b4c5e96aff288992acf19152a38641c665e261e4
PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
PKG_LICENSE:=ISC
@ -107,16 +107,6 @@ define Package/uhttpd-mod-ubus/install
$(INSTALL_DATA) ./files/ubus.default $(1)/etc/uci-defaults/00_uhttpd_ubus
endef
define Package/uhttpd-mod-lua/postinst
$(if $(CONFIG_uhttpd_lua),
#!/bin/sh
if [ -f $${IPKG_INSTROOT}/www/index.html ]
then
sed -e 's:/cgi-bin::g' -i $${IPKG_INSTROOT}/www/index.html
fi
,)
endef
$(eval $(call BuildPackage,uhttpd))
$(eval $(call BuildPackage,uhttpd-mod-lua))

View file

@ -49,10 +49,13 @@ config uhttpd main
# list interpreter ".php=/usr/bin/php-cgi"
# list interpreter ".cgi=/usr/bin/perl"
# Lua url prefix and handler script.
# Lua support is disabled if no prefix given.
option lua_prefix /luci
option lua_handler /usr/lib/lua/luci/sgi/uhttpd.lua
# List of prefix->Lua handler mappings.
# Any request to an URL beneath the prefix
# will be dispatched to the associated Lua
# handler script. Lua support is disabled when
# no handler mappings are specified. Lua prefix
# matches have precedence over the CGI prefix.
list lua_prefix "/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua"
# Specify the ubus-rpc prefix and socket path.
# option ubus_prefix /ubus

View file

@ -74,6 +74,18 @@ create_httpauth() {
haveauth=1
}
append_lua_prefix() {
local v="$1"
local prefix="${v%%=*}"
local handler="${v#*=}"
if [ "$prefix" != "$handler" ] && [ -n "$prefix" ] && [ -f "$handler" ]; then
procd_append_param command -l "$prefix" -L "$handler"
else
echo "Skipping invalid Lua prefix \"$v\"" >&2
fi
}
start_instance()
{
UHTTPD_CERT=""
@ -105,10 +117,16 @@ start_instance()
append_arg "$cfg" config "-c"
append_arg "$cfg" cgi_prefix "-x"
[ -f /usr/lib/uhttpd_lua.so ] && {
config_get handler "$cfg" lua_handler
[ -f "$handler" ] && append_arg "$cfg" lua_prefix "-l" && {
procd_append_param command "-L" "$handler"
}
local len
config_get len "$cfg" lua_prefix_LENGTH
if [ -n "$len" ]; then
config_list_foreach "$cfg" lua_prefix append_lua_prefix
else
config_get prefix "$cfg" lua_prefix
config_get handler "$cfg" lua_handler
append_lua_prefix "$prefix=$handler"
fi
}
[ -f /usr/lib/uhttpd_ubus.so ] && {
append_arg "$cfg" ubus_prefix "-u"