html_confWeb.h 4.5 KB

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