wz_mini_web.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # This serves a rudimentary webpage based on wz_mini.conf
  3. hack_ini=/opt/wz_mini/wz_mini.conf
  4. camver=V3
  5. camfirmware=$(tail -n1 /configs/app.ver | cut -f2 -d= )
  6. hackver="unknown"
  7. hostname=$(uname -n)
  8. title="Wyze $camver on $camfirmware running wz_mini $hackver as $hostname"
  9. echo "HTTP/1.1 200"
  10. echo ""
  11. #echo "Content Length: 100000"
  12. function ini_to_html_free
  13. {
  14. 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
  15. }
  16. function ini_to_html_tf
  17. {
  18. printf '<div class="ii"><div class="ii_key_DIV">%s</div>' $1
  19. printf '<div class="ii_value_DIV">'
  20. if [[ "$2" == "true" ]]; then
  21. printf '<input class="ii_radio" type="radio" name="%s" value="true" checked="checked" /> True &nbsp;' $1
  22. printf '<input class="ii_radio" type="radio" name="%s" value="false" /> False &nbsp;' $1
  23. else
  24. printf '<input class="ii_radio" type="radio" name="%s" value="true" /> True &nbsp;' $1
  25. printf '<input class="ii_radio" type="radio" name="%s" value="false" checked="checked" /> False &nbsp;' $1
  26. fi
  27. printf '</div></div>'
  28. }
  29. echo -ne "<html><head><title>$title</title>"
  30. echo -ne "<style type=\"text/css\">"
  31. cat wz_mini_web.css
  32. echo -ne '</style>';
  33. echo -ne "</head>"
  34. echo -ne '<body>'
  35. echo -ne "<h1>$title</h1>";
  36. echo -ne '<form name=\"wz_mini_hack_FORM\">'
  37. IFS=$'\n'
  38. for ARGUMENT in $(cat $hack_ini)
  39. do
  40. if [[ ${ARGUMENT:0:1} == "#" ]] ; then
  41. echo -ne '<div class="ii_info">'$ARGUMENT'</div>'
  42. else
  43. KEY=$(echo $ARGUMENT | cut -f1 -d=)
  44. VAL=$(echo $ARGUMENT | cut -f2 -d=)
  45. VALUE=${VAL//\"/}
  46. case "$VALUE" in
  47. "true") ini_to_html_tf $KEY $VALUE ;;
  48. "false") ini_to_html_tf $KEY $VALUE ;;
  49. *) ini_to_html_free $KEY $VALUE
  50. esac
  51. fi
  52. done
  53. echo -ne '<input type="submit" name="update" value="Update" />'
  54. echo -ne '</form>'
  55. echo -ne '</body></html>'