[OpenWrt-Devel] [PATCH] network/services/uhttpd: Add Basic Auth config
openwrt at daniel.thecshore.com
openwrt at daniel.thecshore.com
Tue Dec 22 22:26:27 EST 2015
From: Daniel Dickinson <openwrt at daniel.thecshore.com>
We add an 'httpauth' section type that contains the options:
instance: Which uhttpd config section the auth is associated with
prefix: What virtual or real URL is being protected
username: The username for the Basic Auth dialogue
password: Hashed (crypt()) or plaintext password for the Basic Auth dialogue
If instance is not specified auth section applies to
all instances of uhttpd; if instance is specified
the auth section only applies to the uhttpd config
section with the same name as specified with the
instance option.
Signed-off-by: Daniel Dickinson <openwrt at daniel.thecshore.com>
---
package/network/services/uhttpd/files/uhttpd.init | 36 ++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/package/network/services/uhttpd/files/uhttpd.init b/package/network/services/uhttpd/files/uhttpd.init
index add0924..df17c31 100755
--- a/package/network/services/uhttpd/files/uhttpd.init
+++ b/package/network/services/uhttpd/files/uhttpd.init
@@ -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. at 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" && {
--
2.4.3
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list