mirror of
https://github.com/gtxaspec/wz_mini_hacks.git
synced 2024-11-26 07:07:19 +00:00
Update wz_mini_web.sh
This commit is contained in:
parent
815afe9083
commit
9c065b078f
@ -7,29 +7,100 @@ hackver="unknown"
|
|||||||
hostname=$(uname -n)
|
hostname=$(uname -n)
|
||||||
title="Wyze $camver on $camfirmware running wz_mini $hackver as $hostname"
|
title="Wyze $camver on $camfirmware running wz_mini $hackver as $hostname"
|
||||||
|
|
||||||
|
|
||||||
echo "HTTP/1.1 200"
|
echo "HTTP/1.1 200"
|
||||||
|
echo -e "Content-type: text/html\n\n"
|
||||||
echo ""
|
echo ""
|
||||||
#echo "Content Length: 100000"
|
|
||||||
|
|
||||||
|
shft() {
|
||||||
|
# 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=wz_mini.conf.new
|
||||||
|
shft $output
|
||||||
|
|
||||||
|
#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 $ARGUMENT >> $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 $KEY="$test" >> $output
|
||||||
|
else
|
||||||
|
#if not in the fake array we use the current value
|
||||||
|
#echo "<div>key not found</div>"
|
||||||
|
echo $ARGUMENT >> $output
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
function ini_to_html_free
|
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></div>' $1 $1 $2
|
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></div>' $1 $1 $2
|
||||||
}
|
}
|
||||||
|
|
||||||
function ini_to_html_tf
|
function ini_to_html_tf
|
||||||
{
|
{
|
||||||
printf '<div class="ii"><div class="ii_key_DIV">%s</div>' $1
|
printf '<div class="ii"><div class="ii_key_DIV">%s</div>' $1
|
||||||
printf '<div class="ii_value_DIV">'
|
printf '<div class="ii_value_DIV">'
|
||||||
if [[ "$2" == "true" ]]; then
|
if [[ "$2" == "true" ]]; then
|
||||||
printf '<input class="ii_radio" type="radio" name="%s" value="true" checked="checked" /> True ' $1
|
printf '<input class="ii_radio" type="radio" name="%s" value="true" checked="checked" /> True ' $1
|
||||||
printf '<input class="ii_radio" type="radio" name="%s" value="false" /> False ' $1
|
printf '<input class="ii_radio" type="radio" name="%s" value="false" /> False ' $1
|
||||||
else
|
else
|
||||||
printf '<input class="ii_radio" type="radio" name="%s" value="true" /> True ' $1
|
printf '<input class="ii_radio" type="radio" name="%s" value="true" /> True ' $1
|
||||||
printf '<input class="ii_radio" type="radio" name="%s" value="false" checked="checked" /> False ' $1
|
printf '<input class="ii_radio" type="radio" name="%s" value="false" checked="checked" /> False ' $1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
printf '</div></div>'
|
printf '</div></div>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -38,27 +109,31 @@ echo -ne "<style type=\"text/css\">"
|
|||||||
cat wz_mini_web.css
|
cat wz_mini_web.css
|
||||||
echo -ne '</style>';
|
echo -ne '</style>';
|
||||||
echo -ne "</head>"
|
echo -ne "</head>"
|
||||||
|
|
||||||
|
|
||||||
echo -ne '<body>'
|
echo -ne '<body>'
|
||||||
echo -ne "<h1>$title</h1>";
|
echo -ne "<h1>$title</h1>";
|
||||||
echo -ne '<form name=\"wz_mini_hack_FORM\">'
|
echo -ne '<form name="wz_mini_hack_FORM" method="POST" enctype="application/x-www-form-urlencoded" >'
|
||||||
|
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for ARGUMENT in $(cat $hack_ini)
|
for ARGUMENT in $(cat $hack_ini)
|
||||||
do
|
do
|
||||||
if [[ ${ARGUMENT:0:1} == "#" ]] ; then
|
if [[ ${ARGUMENT:0:1} == "#" ]] ; then
|
||||||
echo -ne '<div class="ii_info">'$ARGUMENT'</div>'
|
echo -ne '<div class="ii_info">'$ARGUMENT'</div>'
|
||||||
else
|
else
|
||||||
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
||||||
VAL=$(echo $ARGUMENT | cut -f2 -d=)
|
VAL=$(echo $ARGUMENT | cut -f2 -d=)
|
||||||
VALUE=${VAL//\"/}
|
VALUE=${VAL//\"/}
|
||||||
case "$VALUE" in
|
case "$VALUE" in
|
||||||
"true") ini_to_html_tf $KEY $VALUE ;;
|
"true") ini_to_html_tf $KEY $VALUE ;;
|
||||||
"false") ini_to_html_tf $KEY $VALUE ;;
|
"false") ini_to_html_tf $KEY $VALUE ;;
|
||||||
*) ini_to_html_free $KEY $VALUE
|
*) ini_to_html_free $KEY $VALUE
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -ne '<input type="submit" name="update" value="Update" />'
|
echo -ne '<input type="submit" name="update" value="Update" />'
|
||||||
echo -ne '</form>'
|
echo -ne '</form>'
|
||||||
|
|
||||||
|
|
||||||
echo -ne '</body></html>'
|
echo -ne '</body></html>'
|
||||||
|
Loading…
Reference in New Issue
Block a user