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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 10 deletions

View File

@ -525,9 +525,14 @@ Enables `dnsmasq`, a lightweight, local, caching DNS server on the camera. Fixe
### Web Server: ### Web Server:
``` ```
WEB_SERVER_ENABLED="true" WEB_SERVER_ENABLED="true"
WEB_SERVER_AUTH="true"
WEB_SERVER_LOGIN="admin"
WEB_SERVER_PASSWORD=""
``` ```
Enables the local webserver, for configuration, car control, or to retreive an image snapshot via a web browser. Available at : `http://<Camera IP>/` Thank you @virmaior! Enables the local webserver, for configuration, car control, or to retreive an image snapshot via a web browser. Available at : `http://<Camera IP>/` Thank you @virmaior!
Similar to the RTSP default password, if you don't set the password, the password will be set to the unique MAC address of the camera, in all uppercase, including the colons.
If you do not want to have an authentication prompt for the local webserver, set WEB_SERVER_AUTH to false.
``` ```
WEB_SERVER_OPTIONS="cam config car jpeg"` WEB_SERVER_OPTIONS="cam config car jpeg"`

View File

@ -7,26 +7,69 @@
. /opt/wz_mini/wz_mini.conf . /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 case "$1" in
start) start)
echo "#####$(basename "$0")#####" echo "#####$(basename "$0")#####"
do_start
if [[ "$WEB_SERVER_ENABLED" == "true" ]]; then
httpd -p 80 -h /opt/wz_mini/www
echo "httpd enabled"
fi
;; ;;
stop) stop)
pkill dnsmasq do_stop
;; ;;
restart) restart)
$0 stop do_stop
$0 start do_start
;; ;;
*) *)
echo "Usage: $0 {start|stop}" echo "Usage: $0 {start|stop|restart}"
exit 1 exit 1
;; ;;
esac esac
fi

View File

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