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
net/http-net6-script.inc@89:615fb951df69, 2019-04-11 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu Apr 11 09:45:36 2019 +0000
- Revision:
- 89:615fb951df69
- Parent:
- 88:2857259fc2b4
- Child:
- 96:eb2eb75bad0f
Made Ipv6 tab use ajax
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 86:f3c9beec4ee7 | 1 | "'use strict';\n" |
| andrewboyson | 86:f3c9beec4ee7 | 2 | "\n" |
| andrewboyson | 89:615fb951df69 | 3 | "var response = '';\n" |
| andrewboyson | 89:615fb951df69 | 4 | "var headers = '';\n" |
| andrewboyson | 89:615fb951df69 | 5 | "var arp = '';\n" |
| andrewboyson | 89:615fb951df69 | 6 | "var dns = '';\n" |
| andrewboyson | 89:615fb951df69 | 7 | "var hopLimit = '';\n" |
| andrewboyson | 89:615fb951df69 | 8 | "var managed = false;\n" |
| andrewboyson | 89:615fb951df69 | 9 | "var other = false;\n" |
| andrewboyson | 89:615fb951df69 | 10 | "var routerMac = '';\n" |
| andrewboyson | 89:615fb951df69 | 11 | "var prefixLength = '';\n" |
| andrewboyson | 89:615fb951df69 | 12 | "var prefixL = false;\n" |
| andrewboyson | 89:615fb951df69 | 13 | "var prefixA = false;\n" |
| andrewboyson | 89:615fb951df69 | 14 | "var prefixLimit = '';\n" |
| andrewboyson | 89:615fb951df69 | 15 | "var prefixPreferred = '';\n" |
| andrewboyson | 89:615fb951df69 | 16 | "var prefix = '';\n" |
| andrewboyson | 89:615fb951df69 | 17 | "var dnsLife = '';\n" |
| andrewboyson | 89:615fb951df69 | 18 | "var dnsIp = '';\n" |
| andrewboyson | 89:615fb951df69 | 19 | "var ndpLease = '';\n" |
| andrewboyson | 89:615fb951df69 | 20 | "var ndpElapsed = '';\n" |
| andrewboyson | 89:615fb951df69 | 21 | "var slaac = '';\n" |
| andrewboyson | 89:615fb951df69 | 22 | "var mtu = '';\n" |
| andrewboyson | 86:f3c9beec4ee7 | 23 | "\n" |
| andrewboyson | 89:615fb951df69 | 24 | "function hexToBit(text, iBit)\n" |
| andrewboyson | 89:615fb951df69 | 25 | "{\n" |
| andrewboyson | 89:615fb951df69 | 26 | " var value = parseInt(text, 16);\n" |
| andrewboyson | 89:615fb951df69 | 27 | " value >>= iBit;\n" |
| andrewboyson | 89:615fb951df69 | 28 | " return value & 1;\n" |
| andrewboyson | 89:615fb951df69 | 29 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 30 | "function makeIpWord(text)\n" |
| andrewboyson | 88:2857259fc2b4 | 31 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 32 | " var word = parseInt(text, 16);\n" |
| andrewboyson | 88:2857259fc2b4 | 33 | " if (word === 0) return '';\n" |
| andrewboyson | 88:2857259fc2b4 | 34 | " return word.toString(16);\n" |
| andrewboyson | 88:2857259fc2b4 | 35 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 36 | "function makeIp(text)\n" |
| andrewboyson | 88:2857259fc2b4 | 37 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 38 | " text = text.toLowerCase();\n" |
| andrewboyson | 88:2857259fc2b4 | 39 | " var result = '';\n" |
| andrewboyson | 88:2857259fc2b4 | 40 | " result += makeIpWord(text.substr( 0, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 41 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 42 | " result += makeIpWord(text.substr( 4, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 43 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 44 | " result += makeIpWord(text.substr( 8, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 45 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 46 | " result += makeIpWord(text.substr(12, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 47 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 48 | " result += makeIpWord(text.substr(16, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 49 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 50 | " result += makeIpWord(text.substr(20, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 51 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 52 | " result += makeIpWord(text.substr(24, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 53 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 54 | " result += makeIpWord(text.substr(28, 4));\n" |
| andrewboyson | 88:2857259fc2b4 | 55 | " return result;\n" |
| andrewboyson | 88:2857259fc2b4 | 56 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 57 | "function makeMac(text)\n" |
| andrewboyson | 88:2857259fc2b4 | 58 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 59 | " text = text.toLowerCase();\n" |
| andrewboyson | 88:2857259fc2b4 | 60 | " var result = '';\n" |
| andrewboyson | 88:2857259fc2b4 | 61 | " result += text.substr( 0, 2);\n" |
| andrewboyson | 88:2857259fc2b4 | 62 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 63 | " result += text.substr( 2, 2);\n" |
| andrewboyson | 88:2857259fc2b4 | 64 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 65 | " result += text.substr( 4, 2);\n" |
| andrewboyson | 88:2857259fc2b4 | 66 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 67 | " result += text.substr( 6, 2);\n" |
| andrewboyson | 88:2857259fc2b4 | 68 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 69 | " result += text.substr( 8, 2);\n" |
| andrewboyson | 88:2857259fc2b4 | 70 | " result += ':';\n" |
| andrewboyson | 88:2857259fc2b4 | 71 | " result += text.substr(10, 2);\n" |
| andrewboyson | 88:2857259fc2b4 | 72 | " return result;\n" |
| andrewboyson | 88:2857259fc2b4 | 73 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 74 | "function parseArpLine(line)\n" |
| andrewboyson | 88:2857259fc2b4 | 75 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 76 | " if (line.length == 0) return;\n" |
| andrewboyson | 88:2857259fc2b4 | 77 | " var minutes = parseInt(line.substr(0, 8), 16) / 1000 / 60;\n" |
| andrewboyson | 88:2857259fc2b4 | 78 | " arp += Math.floor(minutes).toString().padStart(4, ' ');\n" |
| andrewboyson | 88:2857259fc2b4 | 79 | " arp += ' ';\n" |
| andrewboyson | 88:2857259fc2b4 | 80 | " arp += makeIp(line.substr(8, 32)).padEnd(40, ' ');\n" |
| andrewboyson | 88:2857259fc2b4 | 81 | " arp += ' ';\n" |
| andrewboyson | 88:2857259fc2b4 | 82 | " arp += makeMac(line.substr(40, 12));\n" |
| andrewboyson | 88:2857259fc2b4 | 83 | " arp += '\\r\\n';\n" |
| andrewboyson | 88:2857259fc2b4 | 84 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 85 | "function parseDnsLine(line)\n" |
| andrewboyson | 88:2857259fc2b4 | 86 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 87 | " if (line.length == 0) return;\n" |
| andrewboyson | 88:2857259fc2b4 | 88 | " var minutes = parseInt(line.substr(0, 8), 16) / 1000 / 60;\n" |
| andrewboyson | 88:2857259fc2b4 | 89 | " dns += Math.floor(minutes).toString().padStart(4, ' ');\n" |
| andrewboyson | 88:2857259fc2b4 | 90 | " dns += ' ';\n" |
| andrewboyson | 88:2857259fc2b4 | 91 | " dns += makeIp(line.substr(8, 32)).padEnd(40, ' ');\n" |
| andrewboyson | 88:2857259fc2b4 | 92 | " dns += ' ';\n" |
| andrewboyson | 88:2857259fc2b4 | 93 | " dns += line.substr(40, 1);\n" |
| andrewboyson | 88:2857259fc2b4 | 94 | " dns += ' ';\n" |
| andrewboyson | 88:2857259fc2b4 | 95 | " dns += line.substr(41);\n" |
| andrewboyson | 88:2857259fc2b4 | 96 | " dns += '\\r\\n';\n" |
| andrewboyson | 88:2857259fc2b4 | 97 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 98 | "function parseArpLines(text)\n" |
| andrewboyson | 88:2857259fc2b4 | 99 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 100 | " arp = '';\n" |
| andrewboyson | 88:2857259fc2b4 | 101 | " text.split('\\n').forEach(parseArpLine);\n" |
| andrewboyson | 88:2857259fc2b4 | 102 | "}\n" |
| andrewboyson | 88:2857259fc2b4 | 103 | "function parseDnsLines(text)\n" |
| andrewboyson | 88:2857259fc2b4 | 104 | "{\n" |
| andrewboyson | 88:2857259fc2b4 | 105 | " dns = '';\n" |
| andrewboyson | 88:2857259fc2b4 | 106 | " text.split('\\n').forEach(parseDnsLine);\n" |
| andrewboyson | 88:2857259fc2b4 | 107 | "}\n" |
| andrewboyson | 89:615fb951df69 | 108 | "function parseGenLines(text)\n" |
| andrewboyson | 89:615fb951df69 | 109 | "{\n" |
| andrewboyson | 89:615fb951df69 | 110 | " var lines = text.split('\\n');\n" |
| andrewboyson | 89:615fb951df69 | 111 | " \n" |
| andrewboyson | 89:615fb951df69 | 112 | " hopLimit = parseInt(lines[ 1], 16);\n" |
| andrewboyson | 89:615fb951df69 | 113 | " managed = hexToBit(lines[ 0], 0);\n" |
| andrewboyson | 89:615fb951df69 | 114 | " other = hexToBit(lines[ 0], 1);\n" |
| andrewboyson | 89:615fb951df69 | 115 | " routerMac = makeMac (lines[ 2], 16);\n" |
| andrewboyson | 89:615fb951df69 | 116 | " prefixLength = parseInt(lines[ 3], 16);\n" |
| andrewboyson | 89:615fb951df69 | 117 | " prefixL = hexToBit(lines[ 0], 2);\n" |
| andrewboyson | 89:615fb951df69 | 118 | " prefixA = hexToBit(lines[ 0], 3);\n" |
| andrewboyson | 89:615fb951df69 | 119 | " prefixLimit = parseInt(lines[ 4], 16);\n" |
| andrewboyson | 89:615fb951df69 | 120 | " prefixPreferred = parseInt(lines[ 5], 16);\n" |
| andrewboyson | 89:615fb951df69 | 121 | " prefix = makeIp (lines[ 6] );\n" |
| andrewboyson | 89:615fb951df69 | 122 | " dnsLife = parseInt(lines[ 7], 16);\n" |
| andrewboyson | 89:615fb951df69 | 123 | " dnsIp = makeIp (lines[ 8] );\n" |
| andrewboyson | 89:615fb951df69 | 124 | " ndpLease = parseInt(lines[ 9], 16);\n" |
| andrewboyson | 89:615fb951df69 | 125 | " ndpElapsed = parseInt(lines[10], 16);\n" |
| andrewboyson | 89:615fb951df69 | 126 | " slaac = makeIp (lines[11] );\n" |
| andrewboyson | 89:615fb951df69 | 127 | " mtu = parseInt(lines[12], 16);\n" |
| andrewboyson | 89:615fb951df69 | 128 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 129 | "function parseAjax()\n" |
| andrewboyson | 86:f3c9beec4ee7 | 130 | "{\n" |
| andrewboyson | 86:f3c9beec4ee7 | 131 | " var topics = response.split('\\f');\n" |
| andrewboyson | 89:615fb951df69 | 132 | " parseGenLines(topics[0]);\n" |
| andrewboyson | 89:615fb951df69 | 133 | " parseArpLines(topics[1]);\n" |
| andrewboyson | 89:615fb951df69 | 134 | " parseDnsLines(topics[2]);\n" |
| andrewboyson | 86:f3c9beec4ee7 | 135 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 136 | "function displayGeneral()\n" |
| andrewboyson | 86:f3c9beec4ee7 | 137 | "{\n" |
| andrewboyson | 89:615fb951df69 | 138 | " var elem;\n" |
| andrewboyson | 89:615fb951df69 | 139 | " \n" |
| andrewboyson | 89:615fb951df69 | 140 | " elem = document.getElementById('ajax-response' ); if (elem) elem.textContent = response;\n" |
| andrewboyson | 89:615fb951df69 | 141 | " elem = document.getElementById('ajax-headers' ); if (elem) elem.textContent = headers;\n" |
| andrewboyson | 89:615fb951df69 | 142 | " elem = document.getElementById('ajax-arp' ); if (elem) elem.textContent = arp;\n" |
| andrewboyson | 89:615fb951df69 | 143 | " elem = document.getElementById('ajax-dns' ); if (elem) elem.textContent = dns;\n" |
| andrewboyson | 89:615fb951df69 | 144 | " elem = document.getElementById('ajax-hop-limit' ); if (elem) elem.textContent = hopLimit;\n" |
| andrewboyson | 89:615fb951df69 | 145 | " elem = document.getElementById('ajax-managed' ); if (elem) elem.setAttribute('dir', managed ? 'rtl' : 'ltr');\n" |
| andrewboyson | 89:615fb951df69 | 146 | " elem = document.getElementById('ajax-other' ); if (elem) elem.setAttribute('dir', other ? 'rtl' : 'ltr');\n" |
| andrewboyson | 89:615fb951df69 | 147 | " elem = document.getElementById('ajax-router-mac' ); if (elem) elem.textContent = routerMac;\n" |
| andrewboyson | 89:615fb951df69 | 148 | " elem = document.getElementById('ajax-prefix-length' ); if (elem) elem.textContent = prefixLength;\n" |
| andrewboyson | 89:615fb951df69 | 149 | " elem = document.getElementById('ajax-prefix-l' ); if (elem) elem.setAttribute('dir', prefixL ? 'rtl' : 'ltr');\n" |
| andrewboyson | 89:615fb951df69 | 150 | " elem = document.getElementById('ajax-prefix-a' ); if (elem) elem.setAttribute('dir', prefixA ? 'rtl' : 'ltr');\n" |
| andrewboyson | 89:615fb951df69 | 151 | " elem = document.getElementById('ajax-prefix-limit' ); if (elem) elem.textContent = prefixLimit;\n" |
| andrewboyson | 89:615fb951df69 | 152 | " elem = document.getElementById('ajax-prefix-preferred'); if (elem) elem.textContent = prefixPreferred;\n" |
| andrewboyson | 89:615fb951df69 | 153 | " elem = document.getElementById('ajax-prefix' ); if (elem) elem.textContent = prefix;\n" |
| andrewboyson | 89:615fb951df69 | 154 | " elem = document.getElementById('ajax-dns-life' ); if (elem) elem.textContent = dnsLife;\n" |
| andrewboyson | 89:615fb951df69 | 155 | " elem = document.getElementById('ajax-dns-ip' ); if (elem) elem.textContent = dnsIp;\n" |
| andrewboyson | 89:615fb951df69 | 156 | " elem = document.getElementById('ajax-ndp-lease' ); if (elem) elem.textContent = ndpLease;\n" |
| andrewboyson | 89:615fb951df69 | 157 | " elem = document.getElementById('ajax-ndp-elapsed' ); if (elem) elem.textContent = ndpElapsed;\n" |
| andrewboyson | 89:615fb951df69 | 158 | " elem = document.getElementById('ajax-slaac' ); if (elem) elem.textContent = slaac;\n" |
| andrewboyson | 89:615fb951df69 | 159 | " elem = document.getElementById('ajax-mtu' ); if (elem) elem.textContent = mtu;\n" |
| andrewboyson | 86:f3c9beec4ee7 | 160 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 161 | "\n" |
| andrewboyson | 86:f3c9beec4ee7 | 162 | "var ajax;\n" |
| andrewboyson | 86:f3c9beec4ee7 | 163 | "function AjaxRequest(request) //Used by this script and from HTML page\n" |
| andrewboyson | 86:f3c9beec4ee7 | 164 | "{\n" |
| andrewboyson | 86:f3c9beec4ee7 | 165 | " ajax=new XMLHttpRequest();\n" |
| andrewboyson | 86:f3c9beec4ee7 | 166 | " ajax.onreadystatechange=handleAjaxResponse;\n" |
| andrewboyson | 86:f3c9beec4ee7 | 167 | " if (request) ajax.open('GET', '/net6-ajax' + '?' + request, true);\n" |
| andrewboyson | 86:f3c9beec4ee7 | 168 | " else ajax.open('GET', '/net6-ajax' , true);\n" |
| andrewboyson | 86:f3c9beec4ee7 | 169 | " ajax.send();\n" |
| andrewboyson | 86:f3c9beec4ee7 | 170 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 171 | "function requestAjax() //Used in this script\n" |
| andrewboyson | 86:f3c9beec4ee7 | 172 | "{\n" |
| andrewboyson | 86:f3c9beec4ee7 | 173 | " AjaxRequest('');\n" |
| andrewboyson | 86:f3c9beec4ee7 | 174 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 175 | "\n" |
| andrewboyson | 86:f3c9beec4ee7 | 176 | "function handleAjaxResponse()\n" |
| andrewboyson | 86:f3c9beec4ee7 | 177 | "{\n" |
| andrewboyson | 86:f3c9beec4ee7 | 178 | " if (ajax.readyState==4 && ajax.status==200)\n" |
| andrewboyson | 86:f3c9beec4ee7 | 179 | " {\n" |
| andrewboyson | 86:f3c9beec4ee7 | 180 | " response = ajax.responseText;\n" |
| andrewboyson | 86:f3c9beec4ee7 | 181 | " headers = ajax.getAllResponseHeaders();\n" |
| andrewboyson | 86:f3c9beec4ee7 | 182 | " parseAjax();\n" |
| andrewboyson | 86:f3c9beec4ee7 | 183 | " displayGeneral();\n" |
| andrewboyson | 86:f3c9beec4ee7 | 184 | " }\n" |
| andrewboyson | 86:f3c9beec4ee7 | 185 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 186 | "\n" |
| andrewboyson | 86:f3c9beec4ee7 | 187 | "function init()\n" |
| andrewboyson | 86:f3c9beec4ee7 | 188 | "{\n" |
| andrewboyson | 86:f3c9beec4ee7 | 189 | " setInterval(requestAjax, 10000);\n" |
| andrewboyson | 86:f3c9beec4ee7 | 190 | " requestAjax();\n" |
| andrewboyson | 86:f3c9beec4ee7 | 191 | "}\n" |
| andrewboyson | 86:f3c9beec4ee7 | 192 | "if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init ); // Loading hasn't finished yet\n" |
| andrewboyson | 86:f3c9beec4ee7 | 193 | "else init(); //`DOMContentLoaded` has already fired\n" |
| andrewboyson | 86:f3c9beec4ee7 | 194 | "" |