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 "