diff options
author | Daniel Dickinson <lede@cshore.thecshore.com> | 2016-08-13 19:24:59 -0400 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2016-10-31 13:22:51 +0100 |
commit | 98c86e29705cb1e73e4f2e16044f1e73cff32e31 (patch) | |
tree | 84e93cd71f196365f89027decc4bcee6eb295ca5 /package/network/services/uhttpd/files/uhttpd.init | |
parent | 671cb35880308404a17c430c4b3b13dd506a5671 (diff) | |
download | mtk-20170518-98c86e29705cb1e73e4f2e16044f1e73cff32e31.zip mtk-20170518-98c86e29705cb1e73e4f2e16044f1e73cff32e31.tar.gz mtk-20170518-98c86e29705cb1e73e4f2e16044f1e73cff32e31.tar.bz2 |
uhttpd: Add Basic Auth config
We add an 'httpauth' section type that contains the options:
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
httpauth section names are given included as list
items to the instances to which they are to be applied.
Further any existing httpd.conf file (really whatever
is configured in the instance, but default of
/etc/httpd.conf) is appended to the per-instance httpd.conf
Signed-off-by: Daniel Dickinson <lede@cshore.thecshore.com>
Diffstat (limited to 'package/network/services/uhttpd/files/uhttpd.init')
-rwxr-xr-x | package/network/services/uhttpd/files/uhttpd.init | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/package/network/services/uhttpd/files/uhttpd.init b/package/network/services/uhttpd/files/uhttpd.init index a2dbcd2..53bf04c 100755 --- a/package/network/services/uhttpd/files/uhttpd.init +++ b/package/network/services/uhttpd/files/uhttpd.init @@ -59,6 +59,21 @@ generate_keys() { } } +create_httpauth() { + local cfg="$1" + local prefix username password + + 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="" @@ -66,13 +81,25 @@ 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_list_foreach "$cfg" httpauth create_httpauth + if [ "$haveauth" = "1" ]; then + procd_append_param command -c ${httpdconf} + [ -r /etc/httpd.conf ] && cat /etc/httpd.conf >>/var/etc/uhttpd/httpd.${cfg}.conf + fi + fi + append_arg "$cfg" home "-h" append_arg "$cfg" realm "-r" "${realm:-OpenWrt}" append_arg "$cfg" config "-c" |