|
| 1 | +const char index_html[] PROGMEM = R"rawliteral( |
| 2 | +<!DOCTYPE HTML> |
| 3 | +<html lang="en"> |
| 4 | +<head> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + <meta charset="UTF-8"> |
| 7 | +</head> |
| 8 | +<body> |
| 9 | + <p>Main page</p> |
| 10 | + <p>Firmware: %FIRMWARE%</p> |
| 11 | + <p>Free Storage: <span id="freespiffs">%FREESPIFFS%</span> | Used Storage: <span id="usedspiffs">%USEDSPIFFS%</span> | Total Storage: <span id="totalspiffs">%TOTALSPIFFS%</span></p> |
| 12 | + <p> |
| 13 | + <button onclick="logoutButton()">Logout</button> |
| 14 | + <button onclick="rebootButton()">Reboot</button> |
| 15 | + <button onclick="listFilesButton()">List Files</button> |
| 16 | + <button onclick="showUploadButtonFancy()">Upload File</button> |
| 17 | + </p> |
| 18 | + <p id="status"></p> |
| 19 | + <p id="detailsheader"></p> |
| 20 | + <p id="details"></p> |
| 21 | +<script> |
| 22 | +function logoutButton() { |
| 23 | + var xhr = new XMLHttpRequest(); |
| 24 | + xhr.open("GET", "/logout", true); |
| 25 | + xhr.send(); |
| 26 | + setTimeout(function(){ window.open("/logged-out","_self"); }, 1000); |
| 27 | +} |
| 28 | +function rebootButton() { |
| 29 | + document.getElementById("statusdetails").innerHTML = "Invoking Reboot ..."; |
| 30 | + var xhr = new XMLHttpRequest(); |
| 31 | + xhr.open("GET", "/reboot", true); |
| 32 | + xhr.send(); |
| 33 | + window.open("/reboot","_self"); |
| 34 | +} |
| 35 | +function listFilesButton() { |
| 36 | + xmlhttp=new XMLHttpRequest(); |
| 37 | + xmlhttp.open("GET", "/listfiles", false); |
| 38 | + xmlhttp.send(); |
| 39 | + document.getElementById("detailsheader").innerHTML = "<h3>Files<h3>"; |
| 40 | + document.getElementById("details").innerHTML = xmlhttp.responseText; |
| 41 | +} |
| 42 | +function downloadDeleteButton(filename, action) { |
| 43 | + var urltocall = "/file?name=" + filename + "&action=" + action; |
| 44 | + xmlhttp=new XMLHttpRequest(); |
| 45 | + if (action == "delete") { |
| 46 | + xmlhttp.open("GET", urltocall, false); |
| 47 | + xmlhttp.send(); |
| 48 | + document.getElementById("status").innerHTML = xmlhttp.responseText; |
| 49 | + xmlhttp.open("GET", "/listfiles", false); |
| 50 | + xmlhttp.send(); |
| 51 | + document.getElementById("details").innerHTML = xmlhttp.responseText; |
| 52 | + } |
| 53 | + if (action == "download") { |
| 54 | + document.getElementById("status").innerHTML = ""; |
| 55 | + window.open(urltocall,"_blank"); |
| 56 | + } |
| 57 | +} |
| 58 | +function showUploadButtonFancy() { |
| 59 | + document.getElementById("detailsheader").innerHTML = "<h3>Upload File<h3>" |
| 60 | + document.getElementById("status").innerHTML = ""; |
| 61 | + var uploadform = "<form method = \"POST\" action = \"/\" enctype=\"multipart/form-data\"><input type=\"file\" name=\"data\"/><input type=\"submit\" name=\"upload\" value=\"Upload\" title = \"Upload File\"></form>" |
| 62 | + document.getElementById("details").innerHTML = uploadform; |
| 63 | + var uploadform = |
| 64 | + "<form id=\"upload_form\" enctype=\"multipart/form-data\" method=\"post\">" + |
| 65 | + "<input type=\"file\" name=\"file1\" id=\"file1\" onchange=\"uploadFile()\"><br>" + |
| 66 | + "<progress id=\"progressBar\" value=\"0\" max=\"100\" style=\"width:300px;\"></progress>" + |
| 67 | + "<h3 id=\"status\"></h3>" + |
| 68 | + "<p id=\"loaded_n_total\"></p>" + |
| 69 | + "</form>"; |
| 70 | + document.getElementById("details").innerHTML = uploadform; |
| 71 | +} |
| 72 | +function _(el) { |
| 73 | + return document.getElementById(el); |
| 74 | +} |
| 75 | +function uploadFile() { |
| 76 | + var file = _("file1").files[0]; |
| 77 | + // alert(file.name+" | "+file.size+" | "+file.type); |
| 78 | + var formdata = new FormData(); |
| 79 | + formdata.append("file1", file); |
| 80 | + var ajax = new XMLHttpRequest(); |
| 81 | + ajax.upload.addEventListener("progress", progressHandler, false); |
| 82 | + ajax.addEventListener("load", completeHandler, false); // doesnt appear to ever get called even upon success |
| 83 | + ajax.addEventListener("error", errorHandler, false); |
| 84 | + ajax.addEventListener("abort", abortHandler, false); |
| 85 | + ajax.open("POST", "/"); |
| 86 | + ajax.send(formdata); |
| 87 | +} |
| 88 | +function progressHandler(event) { |
| 89 | + //_("loaded_n_total").innerHTML = "Uploaded " + event.loaded + " bytes of " + event.total; // event.total doesnt show accurate total file size |
| 90 | + _("loaded_n_total").innerHTML = "Uploaded " + event.loaded + " bytes"; |
| 91 | + var percent = (event.loaded / event.total) * 100; |
| 92 | + _("progressBar").value = Math.round(percent); |
| 93 | + _("status").innerHTML = Math.round(percent) + "% uploaded... please wait"; |
| 94 | + if (percent >= 100) { |
| 95 | + _("status").innerHTML = "Please wait, writing file to filesystem"; |
| 96 | + } |
| 97 | +} |
| 98 | +function completeHandler(event) { |
| 99 | + _("status").innerHTML = "Upload Complete"; |
| 100 | + _("progressBar").value = 0; |
| 101 | + xmlhttp=new XMLHttpRequest(); |
| 102 | + xmlhttp.open("GET", "/listfiles", false); |
| 103 | + xmlhttp.send(); |
| 104 | + document.getElementById("status").innerHTML = "File Uploaded"; |
| 105 | + document.getElementById("detailsheader").innerHTML = "<h3>Files<h3>"; |
| 106 | + document.getElementById("details").innerHTML = xmlhttp.responseText; |
| 107 | +} |
| 108 | +function errorHandler(event) { |
| 109 | + _("status").innerHTML = "Upload Failed"; |
| 110 | +} |
| 111 | +function abortHandler(event) { |
| 112 | + _("status").innerHTML = "inUpload Aborted"; |
| 113 | +} |
| 114 | +</script> |
| 115 | +</body> |
| 116 | +</html> |
| 117 | +)rawliteral"; |
| 118 | + |
| 119 | +const char logout_html[] PROGMEM = R"rawliteral( |
| 120 | +<!DOCTYPE HTML> |
| 121 | +<html lang="en"> |
| 122 | +<head> |
| 123 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 124 | + <meta charset="UTF-8"> |
| 125 | +</head> |
| 126 | +<body> |
| 127 | + <p><a href="/">Log Back In</a></p> |
| 128 | +</body> |
| 129 | +</html> |
| 130 | +)rawliteral"; |
| 131 | +
|
| 132 | +// reboot.html base upon https://gist.github.com/Joel-James/62d98e8cb3a1b6b05102 |
| 133 | +const char reboot_html[] PROGMEM = R"rawliteral( |
| 134 | +<!DOCTYPE HTML> |
| 135 | +<html lang="en"> |
| 136 | +<head> |
| 137 | + <meta charset="UTF-8"> |
| 138 | +</head> |
| 139 | +<body> |
| 140 | +<h3> |
| 141 | + Rebooting, returning to main page in <span id="countdown">30</span> seconds |
| 142 | +</h3> |
| 143 | +<script type="text/javascript"> |
| 144 | + var seconds = 20; |
| 145 | + function countdown() { |
| 146 | + seconds = seconds - 1; |
| 147 | + if (seconds < 0) { |
| 148 | + window.location = "/"; |
| 149 | + } else { |
| 150 | + document.getElementById("countdown").innerHTML = seconds; |
| 151 | + window.setTimeout("countdown()", 1000); |
| 152 | + } |
| 153 | + } |
| 154 | + countdown(); |
| 155 | +</script> |
| 156 | +</body> |
| 157 | +</html> |
| 158 | +)rawliteral"; |
0 commit comments