mirror of
https://github.com/gtxaspec/wz_mini_hacks.git
synced 2024-11-22 13:37:19 +00:00
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
This commit is contained in:
parent
c4c10e65cd
commit
a91b20a959
117
SD_ROOT/wz_mini/etc/network.d/s10httpd
Normal file
117
SD_ROOT/wz_mini/etc/network.d/s10httpd
Normal file
@ -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 '<a class="server_LINK" href="/cgi-bin/cam.cgi" >Wyze Camera Core Config</a>' >> $target ;;
|
||||
config) echo '<a class="server_LINK" href="/cgi-bin/config.cgi" >Wz Mini Configuration</a>' >> $target ;;
|
||||
car) echo '<a class="server_LINK" href="/car.html" >Car Tool</a>' >> $target ;;
|
||||
current) echo '<a class="server_LINK" href="/cgi-bin/jpeg.cgi" >Current Screen</a>' >> $target ;;
|
||||
multicam) echo '<a class="server_LINK" href="/multicam.html" >Multi-Cam Viewer</a>' >> $target ;;
|
||||
diag) echo '<a class="server_LINK" href="/cgi-bin/diagnostics.cgi" >Diagnostics</a>' >> $target ;;
|
||||
status) echo '<a class="server_LINK" href="/cgi-bin/status.cgi?test=recording">Check Recording</a>' >> $target ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo '<a class="server_LINK" href="/mulitcam.html" >Multi-Cam</a>' >> $target
|
||||
else
|
||||
echo 'wz_mini.conf is missing the line WEB_SERVER_OPTIONS <br >';
|
||||
echo 'to populate it with full capabilities:<pre>WEB_SERVER_OPTIONS="cam config car jpeg multicam diag status"</pre>';
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$GO2RTC_SERVER_ENABLED" == "true" ]]; then
|
||||
echo '<a class="server_LINK" href="#Go2RTC" onclick="javascript:event.target.port=1984">Go2RTC Server</a>' >> $target
|
||||
|
||||
fi
|
||||
|
||||
echo '<div id="display_BAR"><div class="github_link"><a target="_new" href="https://github.com/gtxaspec/wz_mini_hacks">GitHub: wz_mini_hack</a></div></div>' >> $target
|
||||
echo '</body></html>' >> $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 <<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")#####"
|
||||
compose_home
|
||||
do_start
|
||||
;;
|
||||
stop)
|
||||
do_stop
|
||||
;;
|
||||
restart)
|
||||
do_stop
|
||||
compose_home
|
||||
do_start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
111
SD_ROOT/wz_mini/www/cgi-bin/status.cgi
Normal file
111
SD_ROOT/wz_mini/www/cgi-bin/status.cgi
Normal file
@ -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="<br >"
|
||||
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user