html_confweb.ino 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. static const char html_confweb_script[] PROGMEM = R"=====(
  2. <script>
  3. function g(i) { return document.getElementById(i) };
  4. function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
  5. var xhttp, reqTime, reqFin;
  6. function setCbx(el, da) {
  7. if(da == '1') {
  8. el.checked = true;
  9. el.style.visibility = 'visible';
  10. }
  11. else {
  12. el.checked = false;
  13. el.style.visibility = 'visible';
  14. }
  15. }
  16. function updCbxVal(el) {
  17. if (el.checked) el.value = '1';
  18. else {
  19. el.checked = true;
  20. el.value = '0';
  21. el.style.visibility = 'hidden';
  22. }
  23. }
  24. function transmit(f) {
  25. if (!xhttp) {
  26. reqTime = 0;
  27. reqFin = false;
  28. updCbxVal(g('httpAuth'));
  29. xhttp = new XMLHttpRequest();
  30. xhttp.timeout = 1000;
  31. xhttp.overrideMimeType('application/json');
  32. xhttp.open('POST', 'confdweb');
  33. xhttp.send(f ? (new FormData(f)) : '');
  34. xhttp.onreadystatechange = function () {
  35. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  36. var data = JSON.parse(xhttp.responseText);
  37. g('apiToken').value = data.apiToken;
  38. g('httpUA').value = data.httpUA;
  39. setCbx(g('httpAuth'), data.httpAuth);
  40. g('httpU1').value = data.httpU1;
  41. g('httpP1').value = data.httpP1;
  42. g('httpU2').value = data.httpU2;
  43. g('httpP2').value = data.httpP2;
  44. xhttp = null;
  45. reqFin = true;
  46. }
  47. else {
  48. if(!reqFin && reqTime > 10) {
  49. xhttp = null;
  50. reqFin = true;
  51. }
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57. //transmit();
  58. function saveConf() {
  59. updCbxVal(g('httpAuth'));
  60. if(g('httpPA').value != g('httpPAC').value) {
  61. alert("Admin password verification failed!");
  62. }
  63. else g('frmConf').submit();
  64. }
  65. function init() {
  66. transmit();
  67. setCbx(g('httpPASet'), 0);
  68. setCbx(g('httpP1Set'), 0);
  69. setCbx(g('httpP2Set'), 0);
  70. }
  71. setInterval(function () { ++reqTime; }, 1000);
  72. </script>
  73. )====="; // html_confweb_script
  74. static const char html_confweb_body[] PROGMEM = R"=====(
  75. <p><b>Configuration - Web</b></p>
  76. <div class='config'>
  77. <form id='frmConf' action='setConfWeb' method='POST'>
  78. <fieldset>
  79. <legend>HTTP-API</legend>
  80. <p><b>API Token</b><br><input type='text' name='apiToken' id='apiToken'></p>
  81. </fieldset>
  82. <br>
  83. <fieldset>
  84. <legend>Admin</legend>
  85. <p><b>Username *</b><br><input type='text' name='httpUA' id='httpUA'></p>
  86. <p><b>Password *</b><input type='checkbox' id='httpPASet' name='httpPASet' onclick='sp("httpPA")'><br><input type='password' name='httpPA' id='httpPA'></p>
  87. <p><b>Confirm Password *</b><br><input type='password' name='httpPAC' id='httpPAC'></p>
  88. <p style='font-weight:normal;font-size:0.8em;'>Admin Password can only be set but is not displayed for security reasons.</p>
  89. </fieldset>
  90. <br>
  91. <fieldset>
  92. <legend>Users</legend>
  93. <p><b>Enable User-Authentication *</b>&nbsp;<input type='checkbox' name='httpAuth' id='httpAuth'></p>
  94. <p style='font-weight:normal;font-size:0.8em;'>If User-Auth is off and Admin-PW is set, <br>
  95. Web-Interface can only be accessed by Admin.<br>
  96. Enable User-Auth and set User 1 with emtpy username and password to <br>
  97. make usaccessible without Auth.</p>
  98. <div></div>
  99. <p><b>User 1 *</b><br><input type='text' name='httpU1' id='httpU1'></p>
  100. <p><b>User 1 Password *</b><input type='checkbox' id='httpP1Set' name='httpP1Set' onclick='sp("httpP1")'><br><input type='password' name='httpP1' id='httpP1'></p>
  101. <div></div>
  102. <p><b>User 2 *</b><br><input type='text' name='httpU2' id='httpU2'></p>
  103. <p><b>User 2 Password *</b><input type='checkbox' id='httpP2Set' name='httpP2Set' onclick='sp("httpP2")'><br><input type='password' name='httpP2' id='httpP2'></p>
  104. </fieldset>
  105. </form>
  106. <div></div>
  107. <table style='width:100%'>
  108. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  109. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  110. </tr></table>
  111. <div></div>
  112. </div>
  113. )====="; // html_confweb_body