diff --git a/SD_ROOT/wz_mini/www/cam.js b/SD_ROOT/wz_mini/www/cam.js new file mode 100644 index 0000000..43f9f61 --- /dev/null +++ b/SD_ROOT/wz_mini/www/cam.js @@ -0,0 +1,59 @@ + +var feed_interval_frequency = 1000; + +// https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript#14794066 +function isInt(value) { + return !isNaN(value) && + parseInt(Number(value)) == value && + !isNaN(parseInt(value, 10)); +} + + +function enable_submit() +{ + alert("no guarantees at all on this one. Change values at your own risk"); + document.getElementById("update").disabled = false; + +} + +window.onload = function() +{ + var feed = document.getElementById("current_feed"); + function update_image() + { + feed.src = feed.src.split("&")[0] + "&load=" + new Date().getTime(); + } + feed_interval = setInterval(update_image, feed_interval_frequency); + + + var sels = document.querySelectorAll('.ii_select').forEach(function(item){ + var row = item.getAttribute("row"); + item.addEventListener('change',function(e){ + var row = this.getAttribute("row"); + document.querySelector(".ii_value[row='" + row + "']").value = this.value; + + }); + var b = document.querySelector(".ii_value[row='" + row + "']"); + item.value = b.value; + + b.classList.add('ii_shared'); + b.addEventListener('change',function(e){ + var row = this.getAttribute("row"); + document.querySelector(".ii_select[row='" + row + "']").value = this.value; + + }); + }); + + document.querySelector('[name="update_config"]').addEventListener('submit', + function(e){ + var changed = 0; + const values = document.getElementsByClassName('ii_value'); + Array.from(values).forEach(function(item){ + if (item.getAttribute('default_value') == item.value) { item.disabled = true; } else { changed++; } + }); + if (changed == 0) { + e.preventDefault(); + Array.from(values).forEach(function(item){ item.disabled = false; }); + } + }); +} diff --git a/SD_ROOT/wz_mini/www/cgi-bin/cam-values.txt b/SD_ROOT/wz_mini/www/cgi-bin/cam-values.txt new file mode 100644 index 0000000..1a34b94 --- /dev/null +++ b/SD_ROOT/wz_mini/www/cgi-bin/cam-values.txt @@ -0,0 +1,18 @@ +bitRate=120 # (60=360p or SD, 120=HD) +res=1 # (1=SD or HD, 2=360p) +drawBoxSwitch=2 # Motion Box (1=Enabled, 2=Disabled) +MASwitch=2 # Detects Motion (1=Enabled, 2=Disabled) +AASwitch=2 # Detects Sound (1=Enabled, 2=Disabled) +SASwitch=2 # Smoke Alarm Sound (1=Enabled, 2=Disabled) +CASwitch=2 # CO Alarm Sound (1=Enabled, 2=Disabled) +recordType=1 # Record to SD (1=Continous, 2=Events Only, 3=Disabled) +nightVision=3 # Night Vision Mode (1=On, 2=Off, 3=Auto) +night_cut_thr=1 # Nightvision Conditions (1=Dusk, 2=Dark) +night_led_ex=1 # Night Vision IR Lights Near (1=Near, 2=Off or Far) +NIGHT_LED_flag=2 # Night Vision IR Lights Far (1=Far, 2=Off or Near) +indicator=2 # Camera Status Light (1=Enabled, 2=Disabled) +verSwitch=1 # Flip Vertical (1=Disabled, 2=Enabled) +horSwitch=1 # Flip Horizontal (1=Disabled, 2=Enabled) +osdSwitch=2 # Show Timestamp (1=Enabled, 2=Disabled) +watermark_flag=2 # Show WYZE Logo (1=Enabled, 2=Disabled) +AST=2 # Record Sound (1=Enabled, 2=Disabled) diff --git a/SD_ROOT/wz_mini/www/cgi-bin/cam.cgi b/SD_ROOT/wz_mini/www/cgi-bin/cam.cgi index 2cf27ae..eaddf7d 100644 --- a/SD_ROOT/wz_mini/www/cgi-bin/cam.cgi +++ b/SD_ROOT/wz_mini/www/cgi-bin/cam.cgi @@ -1,4 +1,4 @@ -#!/bin/sh +#!/opt/wz_mini/bin/bash # This serves a rudimentary webpage based on wz_mini.conf . /opt/wz_mini/www/cgi-bin/shared.cgi @@ -22,7 +22,7 @@ then echo "$cam_config exists and not empty" else echo "$cam_config exists but empty" - echo "if you reboot then the camera will revert to defaults or possibly fail " + echo "if you reboot then the camera will revert to defaults " exit fi else @@ -34,32 +34,13 @@ fi } -reboot_camera() { - die_no_config - reboot_wait=90 - echo "rebooting camera (refreshing screen in $reboot_wait seconds)" - echo '' - handle_css config.css - version_info "display_BAR" - reboot - exit +function revert_config +{ + mv "$cam_config" "$cam_config.old" + mv "$cam_config.$1" "$cam_config" } - -shft() { - # SE loop did not work -- thanks ash! - suff=8 - while [ "$suff" -gt 0 ] ; - do - if [[ -f "$1.$suff" ]] ; then - nxt=$((suff + 1)) - mv -f "$1.$suff" "$1.$nxt" - fi - suff=$((suff-1)) - done - mv -f "$1" "$1.1" -} - - + + @@ -78,6 +59,15 @@ if [[ $REQUEST_METHOD = 'GET' ]]; then if [[ "$GET_action" = "reboot" ]]; then reboot_camera fi + + if [[ "$GET_action" = "revert" ]]; then + revert_config "$GET_version" + fi + if [[ "$GET_action" = "show_revert" ]]; then + cam_config="$cam_config.$GET_version" + fi + + fi @@ -90,47 +80,25 @@ if [[ $REQUEST_METHOD = 'POST' ]]; then done fi + output="$cam_config.new" + cp $cam_config $output + #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 "
$K=$VB
" - eval POST_$K=\"$VB\" - done + FK=$(echo $PAIR | cut -f1 -d= ) + VA=$(echo $PAIR | cut -f2 -d= ) + FK=$(urldecode "$FK") + VA=$(urldecode "$VA") - #switch back to going through the config file - output="$cam_config.new" - - #name our output file - while IFS= read -r \ARGUMENT; do - #cycle through each line of the current config - #copy through all comments - if [ -z "$ARGUMENT" ]; then - echo -ne "\n" >> $output - elif [[ ${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
" - if [[ "$test" ]]; then - #if in the fake array then we use the new value - #echo "
matched
" - echo -ne $KEY=\"$test\""\n" >> $output - else - #if not in the fake array we use the current value - #echo "
key not found
" - echo -ne $ARGUMENT"\n" >> $output + if [ "${FK:0:3}" == "row" ]; then + K=$(echo "$FK" | cut -f2 -d[ | cut -f1 -d]) +# echo "
match: $K=$VA
" + sed -i s/$K.*/$K=$VA/ $output fi - - fi - done < $cam_config + done shft $cam_config mv $output $cam_config @@ -140,7 +108,6 @@ fi - function documentation_to_html { fname="$www_dir"'cam-'"$1.md" @@ -150,44 +117,37 @@ function documentation_to_html printf '' fi } - + +function select_block +{ + fname="$www_dir"'cam-values.txt' + testval=$(grep "$1" "$fname" | cut -f2 -d# | cut -f2 -d"(" | cut -f1 -d")" | tr " " "Q") + + if [[ -n "$testval" ]]; then + echo '' + fi +} + function ini_to_html_free { classes="" - if [ "$1" = "USB_DIRECT_MAC_ADDR" ]; then - classes=" mac_addr" - fi - if grep -q -wi "$1" cam-numerics.txt; then - classes=" numeric" - fi - printf '
%s
' $1 $1 $2 + printf '
%s
' $1 + select_block $1 $3 + printf '
' "row_$3[$1]" $2 $2 $3 documentation_to_html $1 printf '
' } -function ini_to_html_tf -{ - printf '
%s
' $1 - printf '
' - if [[ "$2" == "true" ]]; then - printf ' True  ' $1 - printf ' False  ' $1 - else - printf ' True  ' $1 - printf ' False  ' $1 - - fi - printf '
' - documentation_to_html $1 - printf '
' -} - -#function to handle camera feed -function html_cam_feed -{ - printf '' -} @@ -195,7 +155,7 @@ function html_cam_feed echo -ne "$title" handle_css config.css -echo '' +echo '' echo -ne "" @@ -212,12 +172,19 @@ fi html_cam_feed +if [ $base_cam_config != $cam_config ]; then + + echo '
Revert to this version
' +fi + + echo -ne '
' CONFIG_BLOCK=0 - +row=0 while IFS= read -r ARGUMENT; do + row=$((row+1)) if [ -z "$ARGUMENT" ] ; then echo -ne "" elif [[ ${ARGUMENT:0:1} == "[" ]] ; then @@ -232,12 +199,7 @@ while IFS= read -r ARGUMENT; do 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 + ini_to_html_free $KEY $VAL $row fi done < $cam_config if [ "$CONFIG_BLOCK" -gt 0 ]; then @@ -250,6 +212,8 @@ echo -ne '' echo -ne ''; +revert_menu $base_hack_ini $cam_config + version_info "display_BAR" diff --git a/SD_ROOT/wz_mini/www/cgi-bin/config.cgi b/SD_ROOT/wz_mini/www/cgi-bin/config.cgi index 5c5da3c..edb97ba 100644 --- a/SD_ROOT/wz_mini/www/cgi-bin/config.cgi +++ b/SD_ROOT/wz_mini/www/cgi-bin/config.cgi @@ -34,32 +34,6 @@ fi } -reboot_camera() { - die_no_config - reboot_wait=90 - echo "rebooting camera (refreshing screen in $reboot_wait seconds)" - echo '' - handle_css config.css - version_info "display_BAR" - reboot - exit -} - -shft() { - # SE loop did not work -- thanks ash! - suff=8 - while [ "$suff" -gt 0 ] ; - do - if [[ -f "$1.$suff" ]] ; then - nxt=$((suff + 1)) - mv -f "$1.$suff" "$1.$nxt" - fi - suff=$((suff-1)) - done - mv -f "$1" "$1.1" -} - - function revert_config { mv "$hack_ini" "$hack_ini.old" @@ -67,29 +41,6 @@ function revert_config } -function revert_menu -{ - echo '

Revert Menu' - echo '
' - echo 'Prior Versions : ' - xuff=0 - while [ "$xuff" -lt 9 ] ; - do - xuff=$((xuff + 1)) - if [[ -f "$1.$xuff" ]] ; then - filedate=$(date -r "$1.$xuff" ) - class="" - if [ "$1.$xuff" = "$2" ]; - then - class="current_revert" - fi - echo '
$filedate
" - fi - done - echo '
' -} - - if [[ $REQUEST_METHOD = 'GET' ]]; then #since ash does not handle arrays we create variables using eval @@ -128,6 +79,7 @@ if [[ $REQUEST_METHOD = 'POST' ]]; then do K=$(echo $PAIR | cut -f1 -d=) VA=$(echo $PAIR | cut -f2 -d=) + VA=$(urldecode $VA) VB=\"${VA//%3A/:}\" #echo "
$K=$VB
" eval POST_$K=\"$VB\" @@ -214,13 +166,6 @@ function ini_to_html_tf printf '

' } -#function to handle camera feed -function html_cam_feed -{ - printf '' -} - - echo -ne "$title" diff --git a/SD_ROOT/wz_mini/www/cgi-bin/config.css b/SD_ROOT/wz_mini/www/cgi-bin/config.css index fe53991..4ca938c 100644 --- a/SD_ROOT/wz_mini/www/cgi-bin/config.css +++ b/SD_ROOT/wz_mini/www/cgi-bin/config.css @@ -48,6 +48,13 @@ H1 { .ii_value { width:75%; } +.ii_shared { + width:20% !important; +} +.ii_select { + width: 55%; +} + .feed { position:absolute; top:10px; @@ -154,3 +161,16 @@ H1 { color:red; font-family: monospace; } + +.github_link { + border:1px solid white; + border-radius:5px; + padding:2px; + padding-right:2px !important; + width:40px; + margin-right:15px; +} +.github_link A { + color:white; + font-size:12px; +} diff --git a/SD_ROOT/wz_mini/www/cgi-bin/shared.cgi b/SD_ROOT/wz_mini/www/cgi-bin/shared.cgi index 91fcac0..0d6e21d 100644 --- a/SD_ROOT/wz_mini/www/cgi-bin/shared.cgi +++ b/SD_ROOT/wz_mini/www/cgi-bin/shared.cgi @@ -8,12 +8,13 @@ www_dir=/opt/wz_mini/www/cgi-bin/ if [ -f /opt/wz_mini/tmp/.T31 ]; then camtype=T31 camfirmware=$(tail -n1 /configs/app.ver | cut -f2 -d= ) - cam_config="/configs/.user_config" + base_cam_config="/configs/.user_config" elif [ -f /opt/wz_mini/tmp/.T20 ]; then camtype=T20 camfirmware=$(tail -n1 /system/bin/app.ver | cut -f2 -d= ) - cam_config="/configs//parameters" + base_cam_config="/configs/.parameters" fi +cam_config=$base_cam_config cammodel=$(/opt/wz_mini/etc/init.d/s04model start | grep detected | cut -f1 -d ' ' ) @@ -40,8 +41,73 @@ function version_info echo "
$camfirmware
" echo "
$hackver
" echo "
$HOSTNAME
" - echo ''; + echo ''; echo "" } +#function to handle camera feed +function html_cam_feed +{ + printf '' +} + +#code for rebooting the camera +reboot_camera() { + die_no_config + reboot_wait=90 + echo "rebooting camera (refreshing screen in $reboot_wait seconds)" + echo '' + handle_css config.css + version_info "display_BAR" + reboot + exit +} + +#creates backup files +shft() { + # SE loop did not work -- thanks ash! + suff=8 + while [ "$suff" -gt 0 ] ; + do + if [[ -f "$1.$suff" ]] ; then + nxt=$((suff + 1)) + mv -f "$1.$suff" "$1.$nxt" + fi + suff=$((suff-1)) + done + mv -f "$1" "$1.1" +} + +#displays backup files using $1 to identify the file and $2 to identify if one is currently open +function revert_menu +{ + echo '

Revert Menu' + echo '
' + echo 'Prior Versions : ' + xuff=0 + while [ "$xuff" -lt 9 ] ; + do + xuff=$((xuff + 1)) + if [[ -f "$1.$xuff" ]] ; then + filedate=$(date -r "$1.$xuff" ) + class="" + if [ "$1.$xuff" = "$2" ]; + then + class="current_revert" + fi + echo '
'"$xuff
$filedate
" + fi + done + echo '
' +} + + +urldecode(){ + a=${1//+/ } + b=${a//%/\\x} + echo -e "$b" +} +