html_confWeb.h 4.7 KB

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