Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
firmware/http-firmware-script.inc@50:edd44fe9320f, 2019-02-28 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu Feb 28 18:50:34 2019 +0000
- Revision:
- 50:edd44fe9320f
- Parent:
- 49:66f5471a19dc
- Child:
- 51:c605b2794b44
Changed from innerHtml to textContent for security best practise.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 50:edd44fe9320f | 1 | "'use strict';\n" |
| andrewboyson | 50:edd44fe9320f | 2 | "\n" |
| andrewboyson | 48:4e678727c4c9 | 3 | "var file;\n" |
| andrewboyson | 46:1822fdbe6c0c | 4 | "var xhr;\n" |
| andrewboyson | 48:4e678727c4c9 | 5 | "var fr;\n" |
| andrewboyson | 48:4e678727c4c9 | 6 | "var checksum;\n" |
| andrewboyson | 48:4e678727c4c9 | 7 | "\n" |
| andrewboyson | 50:edd44fe9320f | 8 | "function log(text)\n" |
| andrewboyson | 50:edd44fe9320f | 9 | "{\n" |
| andrewboyson | 50:edd44fe9320f | 10 | " document.getElementById('result').textContent = text;\n" |
| andrewboyson | 50:edd44fe9320f | 11 | "}\n" |
| andrewboyson | 50:edd44fe9320f | 12 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 13 | "function xhrOnLoad()\n" |
| andrewboyson | 46:1822fdbe6c0c | 14 | "{\n" |
| andrewboyson | 50:edd44fe9320f | 15 | " if (xhr.status == 200) log(xhr.responseText);\n" |
| andrewboyson | 50:edd44fe9320f | 16 | " else log('Upload failed');\n" |
| andrewboyson | 46:1822fdbe6c0c | 17 | "}\n" |
| andrewboyson | 46:1822fdbe6c0c | 18 | "function xhrOnError()\n" |
| andrewboyson | 46:1822fdbe6c0c | 19 | "{\n" |
| andrewboyson | 50:edd44fe9320f | 20 | " log('Upload error');\n" |
| andrewboyson | 46:1822fdbe6c0c | 21 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 22 | "function startXhr()\n" |
| andrewboyson | 48:4e678727c4c9 | 23 | "{\n" |
| andrewboyson | 50:edd44fe9320f | 24 | " log('Uploading...');\n" |
| andrewboyson | 48:4e678727c4c9 | 25 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 26 | " xhr = new XMLHttpRequest();\n" |
| andrewboyson | 48:4e678727c4c9 | 27 | "\n" |
| andrewboyson | 48:4e678727c4c9 | 28 | " xhr.onload = xhrOnLoad;\n" |
| andrewboyson | 48:4e678727c4c9 | 29 | " xhr.onerror = xhrOnError;\n" |
| andrewboyson | 48:4e678727c4c9 | 30 | "\n" |
| andrewboyson | 49:66f5471a19dc | 31 | " xhr.open('POST', '/firmware-ajax?checksum=' + checksum, true);\n" |
| andrewboyson | 48:4e678727c4c9 | 32 | " xhr.send(file);\n" |
| andrewboyson | 48:4e678727c4c9 | 33 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 34 | "\n" |
| andrewboyson | 48:4e678727c4c9 | 35 | "function frOnLoad()\n" |
| andrewboyson | 48:4e678727c4c9 | 36 | "{\n" |
| andrewboyson | 48:4e678727c4c9 | 37 | " var arrayBuffer = fr.result;\n" |
| andrewboyson | 48:4e678727c4c9 | 38 | " var bytes = new Uint8Array(arrayBuffer);\n" |
| andrewboyson | 50:edd44fe9320f | 39 | " for (var i = 0; i < bytes.length; ++i )\n" |
| andrewboyson | 48:4e678727c4c9 | 40 | " {\n" |
| andrewboyson | 48:4e678727c4c9 | 41 | " checksum = (checksum + bytes[i]) >>> 0;\n" |
| andrewboyson | 48:4e678727c4c9 | 42 | " }\n" |
| andrewboyson | 48:4e678727c4c9 | 43 | " startXhr();\n" |
| andrewboyson | 48:4e678727c4c9 | 44 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 45 | "function frOnError()\n" |
| andrewboyson | 48:4e678727c4c9 | 46 | "{\n" |
| andrewboyson | 50:edd44fe9320f | 47 | " log('Check sum calculation error');\n" |
| andrewboyson | 48:4e678727c4c9 | 48 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 49 | "function startChecksumCalculation()\n" |
| andrewboyson | 48:4e678727c4c9 | 50 | "{\n" |
| andrewboyson | 50:edd44fe9320f | 51 | " log('Calculating checksum...');\n" |
| andrewboyson | 48:4e678727c4c9 | 52 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 53 | " checksum = 0;\n" |
| andrewboyson | 48:4e678727c4c9 | 54 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 55 | " fr = new FileReader();\n" |
| andrewboyson | 48:4e678727c4c9 | 56 | " fr.onload = frOnLoad;\n" |
| andrewboyson | 48:4e678727c4c9 | 57 | " fr.onerror = frOnError;\n" |
| andrewboyson | 48:4e678727c4c9 | 58 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 59 | " fr.readAsArrayBuffer(file);\n" |
| andrewboyson | 48:4e678727c4c9 | 60 | "}\n" |
| andrewboyson | 46:1822fdbe6c0c | 61 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 62 | "function startUpload()\n" |
| andrewboyson | 46:1822fdbe6c0c | 63 | "{\n" |
| andrewboyson | 46:1822fdbe6c0c | 64 | " var fileInput = document.getElementById('fileInput');\n" |
| andrewboyson | 46:1822fdbe6c0c | 65 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 66 | " if (fileInput.files.length == 0)\n" |
| andrewboyson | 46:1822fdbe6c0c | 67 | " {\n" |
| andrewboyson | 50:edd44fe9320f | 68 | " log('Please choose a file');\n" |
| andrewboyson | 46:1822fdbe6c0c | 69 | " return;\n" |
| andrewboyson | 46:1822fdbe6c0c | 70 | " }\n" |
| andrewboyson | 46:1822fdbe6c0c | 71 | "\n" |
| andrewboyson | 46:1822fdbe6c0c | 72 | " if (fileInput.files.length > 1)\n" |
| andrewboyson | 46:1822fdbe6c0c | 73 | " {\n" |
| andrewboyson | 50:edd44fe9320f | 74 | " log('Please choose just one file');\n" |
| andrewboyson | 46:1822fdbe6c0c | 75 | " return;\n" |
| andrewboyson | 46:1822fdbe6c0c | 76 | " }\n" |
| andrewboyson | 48:4e678727c4c9 | 77 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 78 | " file = fileInput.files[0];\n" |
| andrewboyson | 48:4e678727c4c9 | 79 | " \n" |
| andrewboyson | 48:4e678727c4c9 | 80 | " startChecksumCalculation();\n" |
| andrewboyson | 48:4e678727c4c9 | 81 | "}\n" |
| andrewboyson | 48:4e678727c4c9 | 82 | "" |