Add Basic Auth to Web Server portal (#391)

Add Basic Auth to Web Server portal
This commit is contained in:
glessa1
2023-06-28 22:39:02 -04:00
committed by GitHub
parent 725e52609e
commit f004af3ef5
3 changed files with 61 additions and 10 deletions

View File

@@ -7,26 +7,69 @@
. /opt/wz_mini/wz_mini.conf
create_httpdconf()
{
conffile="/opt/wz_mini/etc/httpd.conf"
if [[ -f $conffile ]]; then
rm $conffile
fi
if [[ "$WEB_SERVER_PASSWORD" == "" ]]; then
WEB_SERVER_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
fi
webpassword=$(busybox httpd -m "$WEB_SERVER_PASSWORD")
authline="/:$WEB_SERVER_LOGIN:$webpassword"
cat <<EOF > $conffile
$authline
EOF
}
do_start()
{
create_httpdconf
if [[ "$WEB_SERVER_AUTH" == "false" ]]; then
httpd -p 80 -h /opt/wz_mini/www
echo "httpd enabled"
elif [[ "$WEB_SERVER_AUTH" == "true" ]]; then
httpd -p 80 -h /opt/wz_mini/www -r "Identify yourself:" -c /opt/wz_mini/etc/httpd.conf
echo "httpd enabled"
fi
}
do_stop()
{
#pkill httpd
pidnum=$(ps | egrep "[0-9]{2} httpd -p 80" | awk '{print $1}')
if [[ -z $pidnum ]]; then
echo "httpd was not running"
else
kill $pidnum
echo "httpd killed"
fi
}
if [[ "$WEB_SERVER_ENABLED" == "true" ]]; then
case "$1" in
start)
echo "#####$(basename "$0")#####"
if [[ "$WEB_SERVER_ENABLED" == "true" ]]; then
httpd -p 80 -h /opt/wz_mini/www
echo "httpd enabled"
fi
do_start
;;
stop)
pkill dnsmasq
do_stop
;;
restart)
$0 stop
$0 start
do_stop
do_start
;;
*)
echo "Usage: $0 {start|stop}"
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
fi

View File

@@ -109,6 +109,9 @@ ENABLE_SYSLOG_SAVE="false"
####WEB####
WEB_SERVER_ENABLED="false"
WEB_SERVER_AUTH="true"
WEB_SERVER_LOGIN="admin"
WEB_SERVER_PASSWORD=""
#####SCRIPTING#####
CUSTOM_SCRIPT_PATH=""