@@ -53,6 +53,28 @@ generate_keys() {
}
}
+create_httpauth() {
+ local cfg="$1"
+ local basecfg="$2"
+ local prefix username password
+
+ local instance
+ config_get instance "$cfg" instance
+ if [ -n "$instance" ] && [ "$instance" != "$basecfg" ]; then
+ return
+ fi
+
+ config_get prefix "$cfg" prefix
+ config_get username "$cfg" username
+ config_get password "$cfg" password
+
+ if [ -z "$prefix" ] || [ -z "$username" ] || [ -z "$password" ]; then
+ return
+ fi
+ echo "${prefix}:${username}:${password}" >>$httpdconf
+ haveauth=1
+}
+
start_instance()
{
UHTTPD_CERT=""
@@ -60,17 +82,29 @@ start_instance()
local cfg="$1"
local realm="$(uci_get system.@system[0].hostname)"
- local listen http https interpreter indexes path handler
+ local listen http https interpreter indexes path handler httpdconf haveauth
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param command "$UHTTPD_BIN" -f
+ config_get config "$cfg" config
+ if [ -z "$config" ]; then
+ mkdir -p /var/etc/uhttpd
+ httpdconf="/var/etc/uhttpd/httpd.${cfg}.conf"
+ rm -f ${httpdconf}
+ config_foreach create_httpauth httpauth "$cfg"
+ if [ "$haveauth" = "1" ]; then
+ procd_append_param command -c ${httpdconf}
+ fi
+ fi
+
append_arg "$cfg" home "-h"
append_arg "$cfg" realm "-r" "${realm:-OpenWrt}"
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" && {