html_confWeb.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* clang-format off */
  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(el !== null) {
  8. // if(da == '1') {
  9. // el.checked = true;
  10. // el.style.visibility = 'visible';
  11. // }
  12. // else {
  13. // el.checked = false;
  14. // el.style.visibility = 'visible';
  15. // }
  16. // }
  17. // }
  18. // function updCbxVal(el) {
  19. // if(el !== null) {
  20. // if (el.checked) el.value = '1';
  21. // else {
  22. // el.checked = true;
  23. // el.value = '0';
  24. // el.style.visibility = 'hidden';
  25. // }
  26. // }
  27. // }
  28. static const char html_confweb_script[] PROGMEM = R"=====(
  29. function transmit(f) {
  30. if (!xhttp) {
  31. reqTime = 0;
  32. reqFin = false;
  33. updCbxVal(g('httpAuth'));
  34. updCbxVal(g('wConsole'));
  35. updCbxVal(g('wsConsole'));
  36. updCbxVal(g('enableOTA'));
  37. updCbxVal(g('FSbrowser'));
  38. xhttp = new XMLHttpRequest();
  39. xhttp.timeout = 1000;
  40. xhttp.overrideMimeType('application/json');
  41. xhttp.open('POST', 'confDataWeb');
  42. xhttp.send(f ? (new FormData(f)) : '');
  43. xhttp.onreadystatechange = function () {
  44. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  45. var data = JSON.parse(xhttp.responseText);
  46. g('apiToken').value = data.apiToken;
  47. g('httpUA').value = data.httpUA;
  48. g('httpPA').value = data.httpPA;
  49. setCbx(g('httpAuth'), data.httpAuth);
  50. g('httpU1').value = data.httpU1;
  51. g('httpP1').value = data.httpP1;
  52. g('httpU2').value = data.httpU2;
  53. g('httpP2').value = data.httpP2;
  54. setCbx(g('wConsole'), data.wConsole);
  55. setCbx(g('wsConsole'), data.wsConsole);
  56. setCbx(g('enableOTA'), data.enableOTA);
  57. setCbx(g('FSbrowser'), data.FSbrowser);
  58. xhttp = null;
  59. reqFin = true;
  60. }
  61. else {
  62. if(!reqFin && reqTime > 10) {
  63. xhttp = null;
  64. reqFin = true;
  65. }
  66. }
  67. }
  68. }
  69. return false;
  70. }
  71. //transmit();
  72. function saveConf() {
  73. updCbxVal(g('httpAuth'));
  74. updCbxVal(g('wConsole'));
  75. updCbxVal(g('wsConsole'));
  76. updCbxVal(g('enableOTA'));
  77. updCbxVal(g('FSbrowser'));
  78. if(g('httpPASet').checked && g('httpPA').value != g('httpPAC').value) {
  79. alert("Admin password verification failed!");
  80. }
  81. else g('frmConf').submit();
  82. }
  83. function init() {
  84. transmit();
  85. setCbx(g('httpPASet'), 0);
  86. setCbx(g('httpP1Set'), 0);
  87. setCbx(g('httpP2Set'), 0);
  88. setCbx(g('apiTokenSet'), 0);
  89. }
  90. )====="; // html_confweb_script
  91. // setInterval(function () { ++reqTime; }, 1000);
  92. //</script>
  93. static const char html_confweb_body[] PROGMEM = R"=====(
  94. <p><b>Configuration - Web</b></p>
  95. <div class='config'>
  96. <form id='frmConf' action='setConfWeb' method='POST'>
  97. <fieldset>
  98. <legend>HTTP-API</legend>
  99. <p><b>API Token</b><br><input type='text' name='apiToken' id='apiToken'></p>
  100. </fieldset>
  101. <br>
  102. <fieldset>
  103. <legend>Admin</legend>
  104. <p><b>Set</b>&nbsp;<input type='checkbox' id='httpPASet' name='httpPASet'></p>
  105. <p><b>Username *</b><br><input type='text' name='httpUA' id='httpUA'></p>
  106. <p><b>Password *</b>&nbsp;<input type='checkbox' onclick='sp("httpPA")'>&nbsp;show<br><input type='password' name='httpPA' id='httpPA'></p>
  107. <p><b>Confirm Password *</b><br><input type='password' name='httpPAC' id='httpPAC'></p>
  108. <p class='n'>Admin Password can only be set but is not displayed for security reasons.</p>
  109. </fieldset>
  110. <br>
  111. <fieldset>
  112. <legend>Users</legend>
  113. <p><b>Enable User-Authentication *</b>&nbsp;<input type='checkbox' name='httpAuth' id='httpAuth'></p>
  114. <p class='n'>If User-Auth is off and Admin-PW is set, <br>
  115. Web-Interface can only be accessed by Admin.<br>
  116. Enable User-Auth and set User 1 with emtpy username and password to <br>
  117. make usaccessible without Auth.</p>
  118. <div></div>
  119. <p><b>Set</b>&nbsp;<input type='checkbox' id='httpP1Set' name='httpP1Set'></p>
  120. <p><b>User 1 *</b><br><input type='text' name='httpU1' id='httpU1'></p>
  121. <p><b>User 1 Password *</b>&nbsp;<input type='checkbox' onclick='sp("httpP1")'>&nbsp;show<br><input type='password' name='httpP1' id='httpP1'></p>
  122. <div></div>
  123. <p><b>Set</b>&nbsp;<input type='checkbox' id='httpP2Set' name='httpP2Set'></p>
  124. <p><b>User 2 *</b><br><input type='text' name='httpU2' id='httpU2'></p>
  125. <p><b>User 2 Password *</b>&nbsp;<input type='checkbox' onclick='sp("httpP2")'>&nbsp;show<br><input type='password' name='httpP2' id='httpP2'></p>
  126. </fieldset>
  127. <br>
  128. <fieldset>
  129. <legend>Console</legend>
  130. <p><b>Enable Web Console</b>&nbsp;<input type='checkbox' name='wConsole' id='wConsole'></p>
  131. )====="; // html_confweb_body
  132. #ifdef ENABLE_FEATURE_WSCONSOLE
  133. static const char html_confweb_body_wsconsole[] PROGMEM = R"=====(
  134. <p><b>Enable WebSockets Console</b>&nbsp;<input type='checkbox' name='wsConsole' id='wsConsole'></p>
  135. )====="; // html_confweb_body_wsconsole
  136. #endif
  137. static const char html_confweb_body2[] PROGMEM = R"=====(
  138. </fieldset>
  139. <br>
  140. <fieldset>
  141. <legend>More Features</legend>
  142. <p><b>OTA Update (ESP8266)</b>&nbsp;<input type='checkbox' name='enableOTA' id='enableOTA'></p>
  143. <p class='n'>Enable ESP8266 OTA-Update in Web-Interface</p>
  144. )====="; // html_confweb_body2
  145. #ifdef ENABLE_FEATURE_FILESYSTEM_BROWSER
  146. static const char html_confweb_body_fsbrowser[] PROGMEM = R"=====(
  147. <br>
  148. <p><b>Filesystem Browser</b>&nbsp;<input type='checkbox' name='FSbrowser' id='FSbrowser'/></p>
  149. <p class='n'>Simple Browser for SPIFFS/LittleFS.</p>
  150. </fieldset>
  151. )====="; // html_confweb_body_fsbrowser
  152. #endif
  153. static const char html_confweb_body3[] PROGMEM = R"=====(
  154. </form>
  155. <div></div>
  156. <table style='width:100%'>
  157. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  158. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  159. </tr></table>
  160. <div></div>
  161. </div>
  162. )====="; // html_confweb_body3