From a91b20a959f8dbf51f602b8711afdb1cdde421c2 Mon Sep 17 00:00:00 2001 From: virmaior <70625876+virmaior@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:36:42 +0900 Subject: [PATCH] make clearer why base page is not populating / add check recording (#624) * add ability to check if last minute recorded to SD * improve composition of web root * add multicam to list of options in s10httpd * make cgi-bin and sh functional / improve logic --- SD_ROOT/wz_mini/etc/network.d/s10httpd | 117 +++++++++++++++++++++++++ SD_ROOT/wz_mini/www/cgi-bin/status.cgi | 111 +++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 SD_ROOT/wz_mini/etc/network.d/s10httpd create mode 100644 SD_ROOT/wz_mini/www/cgi-bin/status.cgi diff --git a/SD_ROOT/wz_mini/etc/network.d/s10httpd b/SD_ROOT/wz_mini/etc/network.d/s10httpd new file mode 100644 index 0000000..d745a7b --- /dev/null +++ b/SD_ROOT/wz_mini/etc/network.d/s10httpd @@ -0,0 +1,117 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: +# Short-Description: Basic Web Server +# Description: If enabled, start the httpd web server +### END INIT INFO + +. /opt/wz_mini/wz_mini.conf + + +compose_home() +{ + target=/opt/wz_mini/www/index.html + rm $target + cp /opt/wz_mini/www/index.top.html $target + + + if [[ "$WEB_SERVER_OPTIONS" ]]; then + for part in $WEB_SERVER_OPTIONS + do + case "$part" in + cam) echo 'Wyze Camera Core Config' >> $target ;; + config) echo 'Wz Mini Configuration' >> $target ;; + car) echo 'Car Tool' >> $target ;; + current) echo 'Current Screen' >> $target ;; + multicam) echo 'Multi-Cam Viewer' >> $target ;; + diag) echo 'Diagnostics' >> $target ;; + status) echo 'Check Recording' >> $target ;; + esac + done + + echo 'Multi-Cam' >> $target + else + echo 'wz_mini.conf is missing the line WEB_SERVER_OPTIONS
'; + echo 'to populate it with full capabilities:
WEB_SERVER_OPTIONS="cam config car jpeg multicam diag status"
'; + + fi + + if [[ "$GO2RTC_SERVER_ENABLED" == "true" ]]; then + echo 'Go2RTC Server' >> $target + + fi + + echo '
' >> $target + echo '' >> $target +} + + +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 < $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")#####" + compose_home + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + compose_home + do_start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac + +fi diff --git a/SD_ROOT/wz_mini/www/cgi-bin/status.cgi b/SD_ROOT/wz_mini/www/cgi-bin/status.cgi new file mode 100644 index 0000000..c2e8220 --- /dev/null +++ b/SD_ROOT/wz_mini/www/cgi-bin/status.cgi @@ -0,0 +1,111 @@ +#!/bin/sh +# This serves a rudimentary webpage to test different items +. /opt/wz_mini/www/cgi-bin/shared.cgi + + +base='/opt/record/'; +TZ=$(cat /configs/TZ) + + + + + +test_recording() +{ + +msg="" +fpath=$(TZ="$TZ" date +"%Y%m%d") +nowmin=$(TZ="$TZ" date +"%M") +curmin=$((10#$nowmin - 1)) +curhour=$(TZ="$TZ" date +"%H") +cursec=$(TZ="$TZ" date +"%S") + + +if [[ "$cursec" -lt "03" ]]; then + wt=$((3 - $cursec)) + msg="delayed $wt seconds to allow copy to SD" + sleep $wt +fi + +if [[ "$curmin" -eq "0" ]]; then + if [[ "$curhour" -gt "0" ]]; then + curhour=$(($curhour - 1)) + curhour=$(printf %02d $curhour) + else + fpath=$(($fpath - 1)) + curhour=23 + fi + curmin=59 +fi + +curmin=$(printf %02d $curmin) + +if [ ! -d "$base$fpath" ]; then + echo -e "NG $lb" + echo "Date directory does not exist ($base$fname)" + exit +fi + + + + +if [ ! -d "$base$fpath/$curhour" ]; then + echo -e "NG $lb" + echo "Hour directory does not exist ($base$fname/$curhour)" + exit +fi + + + +if [ ! -f "$base$fpath/$curhour/$curmin.mp4" ]; then + echo -e "NG $lb" + echo "Last minute not recorded ($base$fname/$curhour/$curmin.mp4)" + exit +fi + + +echo "OK$lb" +echo found "$base$fpath/$curhour/$curmin.mp4" +echo $msg +} + + +if [ -z $REQUEST_METHOD ]; then + echo "run on command line -- not in web " + +for ARGUMENT in "$@" +do + + KEY=$(echo $ARGUMENT | cut -f1 -d=) + VALUE=$(echo $ARGUMENT | cut -f2 -d=) + + case "$KEY" in + test) GET_test=${VALUE} ;; + esac + lb="" +done + +elif [[ $REQUEST_METHOD = 'GET' ]]; then + + + echo "HTTP/1.1 200" + echo -e "Content-type: text/html\n\n" + echo "" + lb="
" + + #since ash does not handle arrays we create variables using eval + IFS='&' + for PAIR in $QUERY_STRING + do + K=$(echo $PAIR | cut -f1 -d=) + VA=$(echo $PAIR | cut -f2 -d=) + eval GET_$K=$VA + done + +fi + + + if [[ "$GET_test" = "recording" ]]; then + test_recording + fi +