Merge pull request #188 from virmaior/master

Rudimentary webserver over httpd
This commit is contained in:
gtxaspec 2022-07-17 02:42:40 -07:00 committed by GitHub
commit 63f2442d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 230 additions and 0 deletions

View File

@ -593,6 +593,10 @@ if [[ "$NIGHT_DROP_DISABLE" == "true" ]]; then
touch /opt/wz_mini/tmp/.nd
fi
if [[ "$WEB_SERVER_ENABLED" == "true" ]]; then
httpd -p 80 -h /opt/wz_mini/www
fi
hostname_set
touch /opt/wz_mini/tmp/.wz_user_firstrun
pkill -f dumpload #Kill dumpload so it won't waste cpu or ram gathering cores and uploading them when something crashes

View File

@ -93,11 +93,15 @@ DISABLE_MOTOR="false"
ENABLE_FSCK_ON_BOOT="false"
ENABLE_CAR_DRIVER="false"
#####WEB#####
WEB_SERVER_ENABLED="false"
#####DEBUG#####
#drops you to a shell via serial, doesn't load app_init.sh
DEBUG_ENABLED="false"
DEBUG_INITRAMFS_ENABLED="false"
DEBUG_PASSWORD="false"
#####SCRIPTING#####
CUSTOM_SCRIPT_PATH=""

View File

@ -0,0 +1,4 @@
If a remote or app update is initiated, the camera will reboot due to the failure of the update. The firmware update should not proceed again for some time, or at all.
When a firmware update is initiated, due to a bootloader issue (bug?), we intercept the update process and flash it manually. This should now result in a successful update, if it doesn't, please restore the unit's firmware manually using demo_wcv3.bin on the micro sd card.

View File

@ -0,0 +1,13 @@
USB Ethernet Adapter support:
ENABLE_USB_ETH="true"
ENABLE_USB_ETH_MODULE_AUTODETECT="true"
ENABLE_USB_ETH_MODULE_MANUAL=""
To have the Ethernet NIC be auto-detected and loaded automatically, set the ENABLE_USB_ETH_MODULE_AUTODETECT value to true.
To load a specific USB Ethernet NIC driver, set ENABLE_USB_ETH_MODULE_MANUAL to one of the following: asix, ax88179_178a, cdc_ether, r8152
NOTE: There is a possibility of a conflict between Ethernet NIC adapters that report themselves as PCI ID '0bda:8152'. (Realtek 8152 and CDC Ethernet) Since the 8152 is Realtek's product, that driver will be the one used for products that report that PCI ID. If you happen to have a CDC Ethernet product that uses that specific PCI ID, please set the ENABLE_USB_ETH_MODULE_AUTODETECT option to false, and set ENABLE_USB_ETH_MODULE_MANUAL to "cdc_ether"
The next time you boot your camera, make sure your USB Ethernet Adapter is connected to the camera and ethernet. The camera has to be setup initially with Wi-Fi for this to work. After setup, Wi-Fi is no longer needed, as long as you are using the USB Ethernet Adapter. Note that using USB Ethernet disables the onboard Wi-Fi.

View File

@ -0,0 +1,19 @@
Wireguard support is available as a kernel module:
ENABLE_WIREGUARD="true"
Use the command wg to setup. See https://www.wireguard.com/quickstart/ for more info.
Some users have asked about tailscale support, I have tested and it works. See the issue #30 for further information.
Example setup:
ENABLE_WIREGUARD="true"
WIREGUARD_IPV4="192.168.2.101/32"
WIREGUARD_PEER_ENDPOINT="x.x.x.x:51820"
WIREGUARD_PEER_PUBLIC_KEY="INSERT_PEER_PUBLIC_KEY_HERE"
WIREGUARD_PEER_ALLOWED_IPS="192.168.2.0/24"
WIREGUARD_PEER_KEEP_ALIVE="25"
To retrieve the public key that you'll need to add the peer to your wireguard endpoint:
Use SSH to log in
wg

View File

@ -0,0 +1,157 @@
#we!/bin/sh
# This serves a rudimentary webpage based on wz_mini.conf
base_dir=/opt/wz_mini/
hack_ini=/opt/wz_mini/wz_mini.conf
www_dir=/opt/wz_mini/www/cgi-bin/
camver=V3
camfirmware=$(tail -n1 /configs/app.ver | cut -f2 -d= )
hackver=$(cat /opt/wz_mini/usr/bin/app.ver)
hostname=$(uname -n)
title="Wyze $camver on $camfirmware running wz_mini $hackver as $hostname"
echo "HTTP/1.1 200"
echo -e "Content-type: text/html\n\n"
echo ""
shft() {
cd $base_dir
# https://stackoverflow.com/questions/3690936/change-file-name-suffixes-using-sed/3691279#3691279
# Change this '8' to one less than your desired maximum rollover file.
# Must be in reverse order for renames to work (n..1, not 1..n).
for suff in {8..1} ; do
if [[ -f "$1.${suff}" ]] ; then
((nxt = suff + 1))
mv -f "$1.${suff}" "$1.${nxt}"
fi
done
mv -f "$1" "$1.1"
}
#test for post
if [[ $REQUEST_METHOD = 'POST' ]]; then
if [ "$CONTENT_LENGTH" -gt 0 ]; then
read -n $CONTENT_LENGTH POST_DATA <&0
while read line
do eval "echo ${line}"
done
fi
#since ash does not handle arrays we create variables using eval
IFS='&'
for PAIR in $POST_DATA
do
K=$(echo $PAIR | cut -f1 -d=)
VA=$(echo $PAIR | cut -f2 -d=)
VB=\"${VA//%3A/:}\"
#echo "<div>$K=$VB</div>"
eval POST_$K=\"$VB\"
done
#switch back to going through the config file
IFS=$'\n'
output="$hack_ini.new"
#name our output file
for ARGUMENT in $(cat $hack_ini)
do
#cycle through each line of the current config
#copy through all comments
if [[ ${ARGUMENT:0:1} == "#" ]] ; then
#echo $ARGUMENT $'\n'
echo -ne $ARGUMENT"\n" >> $output
else
#for non-comments check to see if we have an entry in the POST data by deciphering the key from the ini file and using eval for our fake array
KEY=$(echo $ARGUMENT | cut -f1 -d=)
test=$(eval echo \$POST_$KEY)
#echo "key was $KEY test was ... $test <br /> "
if [[ "$test" ]]; then
#if in the fake array then we use the new value
#echo "<div style=\"color:#c00\">matched </div>"
echo -ne $KEY=\"$test\""\n" >> $output
else
#if not in the fake array we use the current value
#echo "<div>key not found</div>"
echo -ne $ARGUMENT"\n" >> $output
fi
fi
done
shft $hack_ini
mv $output $hack_ini
echo "rebooting! wait a bit -- and go the same url"
reboot
exit
fi
function documentation_to_html
{
if [[ -f "$www_dir$1.md" ]]; then
printf '<div class="ii_explain"><pre>'
cat $web_dir$1.md
printf '</pre></div>'
fi
}
function ini_to_html_free
{
printf '<div class="ii"><div class="ii_key_DIV">%s</div><div class="ii_value_DIV"><input class="ii_value" type="text" name="%s" value="%s" /></div>' $1 $1 $2
documentation_to_html $1
printf '</div>'
}
function ini_to_html_tf
{
printf '<div class="ii"><div class="ii_key_DIV">%s</div>' $1
printf '<div class="ii_value_DIV">'
if [[ "$2" == "true" ]]; then
printf '<input class="ii_radio" type="radio" name="%s" value="true" checked="checked" /> True &nbsp;' $1
printf '<input class="ii_radio" type="radio" name="%s" value="false" /> False &nbsp;' $1
else
printf '<input class="ii_radio" type="radio" name="%s" value="true" /> True &nbsp;' $1
printf '<input class="ii_radio" type="radio" name="%s" value="false" checked="checked" /> False &nbsp;' $1
fi
printf '</div>'
documentation_to_html $1
printf '</div>'
}
echo -ne "<html><head><title>$title</title>"
echo -ne "<style type=\"text/css\">"
cat wz_mini_web.css
echo -ne '</style>';
echo -ne "</head>"
echo -ne '<body>'
echo -ne "<h1>$title</h1>";
echo -ne '<form name="wz_mini_hack_FORM" method="POST" enctype="application/x-www-form-urlencoded" >'
IFS=$'\n'
for ARGUMENT in $(cat $hack_ini)
do
if [[ ${ARGUMENT:0:1} == "#" ]] ; then
echo -ne '<div class="ii_info">'$ARGUMENT'</div>'
else
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VAL=$(echo $ARGUMENT | cut -f2 -d=)
VALUE=${VAL//\"/}
case "$VALUE" in
"true") ini_to_html_tf $KEY $VALUE ;;
"false") ini_to_html_tf $KEY $VALUE ;;
*) ini_to_html_free $KEY $VALUE
esac
fi
done
echo -ne '<input type="submit" name="update" value="Update" />'
echo -ne '</form>'
echo -ne '</body></html>'

View File

@ -0,0 +1,26 @@
.ii_info {
font-weight:bold;
background-color:#ccc;
}
.ii {
width:100%;
position:relative;
display:flex;
}
.ii_key_DIV {
flex:0 0 30vw;
font-weight:bold;
}
.ii_value_DIV {
flex: 0 0 40vw;
text-align:right;
}
.ii_value {
width:75%;
}
.ii_explain {
width:29vw;
overflow:scroll;
max-height:140px;
}

View File

@ -99,5 +99,8 @@ DEBUG_ENABLED="false"
DEBUG_INITRAMFS_ENABLED="false"
DEBUG_PASSWORD="false"
####WEB####
WEB_SERVER_ENABLED="true"
#####SCRIPTING#####
CUSTOM_SCRIPT_PATH=""