Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Wed Apr 10 10:06:14 2019 +0000
Revision:
88:2857259fc2b4
Parent:
86:f3c9beec4ee7
Child:
89:615fb951df69
Made ARP and DNS entries in IPv6 and IPv4 pages update by ajax

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 86:f3c9beec4ee7 1 "'use strict';\n"
andrewboyson 86:f3c9beec4ee7 2 "\n"
andrewboyson 88:2857259fc2b4 3 "var response = '';\n"
andrewboyson 88:2857259fc2b4 4 "var headers = '';\n"
andrewboyson 88:2857259fc2b4 5 "var arp = '';\n"
andrewboyson 88:2857259fc2b4 6 "var dns = '';\n"
andrewboyson 86:f3c9beec4ee7 7 "\n"
andrewboyson 88:2857259fc2b4 8 "function makeIpWord(text)\n"
andrewboyson 88:2857259fc2b4 9 "{\n"
andrewboyson 88:2857259fc2b4 10 " var word = parseInt(text, 16);\n"
andrewboyson 88:2857259fc2b4 11 " if (word === 0) return '';\n"
andrewboyson 88:2857259fc2b4 12 " return word.toString(16);\n"
andrewboyson 88:2857259fc2b4 13 "}\n"
andrewboyson 88:2857259fc2b4 14 "function makeIp(text)\n"
andrewboyson 88:2857259fc2b4 15 "{\n"
andrewboyson 88:2857259fc2b4 16 " text = text.toLowerCase();\n"
andrewboyson 88:2857259fc2b4 17 " var result = '';\n"
andrewboyson 88:2857259fc2b4 18 " result += makeIpWord(text.substr( 0, 4));\n"
andrewboyson 88:2857259fc2b4 19 " result += ':';\n"
andrewboyson 88:2857259fc2b4 20 " result += makeIpWord(text.substr( 4, 4));\n"
andrewboyson 88:2857259fc2b4 21 " result += ':';\n"
andrewboyson 88:2857259fc2b4 22 " result += makeIpWord(text.substr( 8, 4));\n"
andrewboyson 88:2857259fc2b4 23 " result += ':';\n"
andrewboyson 88:2857259fc2b4 24 " result += makeIpWord(text.substr(12, 4));\n"
andrewboyson 88:2857259fc2b4 25 " result += ':';\n"
andrewboyson 88:2857259fc2b4 26 " result += makeIpWord(text.substr(16, 4));\n"
andrewboyson 88:2857259fc2b4 27 " result += ':';\n"
andrewboyson 88:2857259fc2b4 28 " result += makeIpWord(text.substr(20, 4));\n"
andrewboyson 88:2857259fc2b4 29 " result += ':';\n"
andrewboyson 88:2857259fc2b4 30 " result += makeIpWord(text.substr(24, 4));\n"
andrewboyson 88:2857259fc2b4 31 " result += ':';\n"
andrewboyson 88:2857259fc2b4 32 " result += makeIpWord(text.substr(28, 4));\n"
andrewboyson 88:2857259fc2b4 33 " return result;\n"
andrewboyson 88:2857259fc2b4 34 "}\n"
andrewboyson 88:2857259fc2b4 35 "function makeMac(text)\n"
andrewboyson 88:2857259fc2b4 36 "{\n"
andrewboyson 88:2857259fc2b4 37 " text = text.toLowerCase();\n"
andrewboyson 88:2857259fc2b4 38 " var result = '';\n"
andrewboyson 88:2857259fc2b4 39 " result += text.substr( 0, 2);\n"
andrewboyson 88:2857259fc2b4 40 " result += ':';\n"
andrewboyson 88:2857259fc2b4 41 " result += text.substr( 2, 2);\n"
andrewboyson 88:2857259fc2b4 42 " result += ':';\n"
andrewboyson 88:2857259fc2b4 43 " result += text.substr( 4, 2);\n"
andrewboyson 88:2857259fc2b4 44 " result += ':';\n"
andrewboyson 88:2857259fc2b4 45 " result += text.substr( 6, 2);\n"
andrewboyson 88:2857259fc2b4 46 " result += ':';\n"
andrewboyson 88:2857259fc2b4 47 " result += text.substr( 8, 2);\n"
andrewboyson 88:2857259fc2b4 48 " result += ':';\n"
andrewboyson 88:2857259fc2b4 49 " result += text.substr(10, 2);\n"
andrewboyson 88:2857259fc2b4 50 " return result;\n"
andrewboyson 88:2857259fc2b4 51 "}\n"
andrewboyson 88:2857259fc2b4 52 "function parseArpLine(line)\n"
andrewboyson 88:2857259fc2b4 53 "{\n"
andrewboyson 88:2857259fc2b4 54 " if (line.length == 0) return;\n"
andrewboyson 88:2857259fc2b4 55 " var minutes = parseInt(line.substr(0, 8), 16) / 1000 / 60;\n"
andrewboyson 88:2857259fc2b4 56 " arp += Math.floor(minutes).toString().padStart(4, ' ');\n"
andrewboyson 88:2857259fc2b4 57 " arp += ' ';\n"
andrewboyson 88:2857259fc2b4 58 " arp += makeIp(line.substr(8, 32)).padEnd(40, ' ');\n"
andrewboyson 88:2857259fc2b4 59 " arp += ' ';\n"
andrewboyson 88:2857259fc2b4 60 " arp += makeMac(line.substr(40, 12));\n"
andrewboyson 88:2857259fc2b4 61 " arp += '\\r\\n';\n"
andrewboyson 88:2857259fc2b4 62 "}\n"
andrewboyson 88:2857259fc2b4 63 "function parseDnsLine(line)\n"
andrewboyson 88:2857259fc2b4 64 "{\n"
andrewboyson 88:2857259fc2b4 65 " if (line.length == 0) return;\n"
andrewboyson 88:2857259fc2b4 66 " var minutes = parseInt(line.substr(0, 8), 16) / 1000 / 60;\n"
andrewboyson 88:2857259fc2b4 67 " dns += Math.floor(minutes).toString().padStart(4, ' ');\n"
andrewboyson 88:2857259fc2b4 68 " dns += ' ';\n"
andrewboyson 88:2857259fc2b4 69 " dns += makeIp(line.substr(8, 32)).padEnd(40, ' ');\n"
andrewboyson 88:2857259fc2b4 70 " dns += ' ';\n"
andrewboyson 88:2857259fc2b4 71 " dns += line.substr(40, 1);\n"
andrewboyson 88:2857259fc2b4 72 " dns += ' ';\n"
andrewboyson 88:2857259fc2b4 73 " dns += line.substr(41);\n"
andrewboyson 88:2857259fc2b4 74 " dns += '\\r\\n';\n"
andrewboyson 88:2857259fc2b4 75 "}\n"
andrewboyson 88:2857259fc2b4 76 "function parseArpLines(text)\n"
andrewboyson 88:2857259fc2b4 77 "{\n"
andrewboyson 88:2857259fc2b4 78 " arp = '';\n"
andrewboyson 88:2857259fc2b4 79 " text.split('\\n').forEach(parseArpLine);\n"
andrewboyson 88:2857259fc2b4 80 "}\n"
andrewboyson 88:2857259fc2b4 81 "function parseDnsLines(text)\n"
andrewboyson 88:2857259fc2b4 82 "{\n"
andrewboyson 88:2857259fc2b4 83 " dns = '';\n"
andrewboyson 88:2857259fc2b4 84 " text.split('\\n').forEach(parseDnsLine);\n"
andrewboyson 88:2857259fc2b4 85 "}\n"
andrewboyson 86:f3c9beec4ee7 86 "function parseAjax()\n"
andrewboyson 86:f3c9beec4ee7 87 "{\n"
andrewboyson 86:f3c9beec4ee7 88 " var topics = response.split('\\f');\n"
andrewboyson 88:2857259fc2b4 89 " parseArpLines(topics[0]);\n"
andrewboyson 88:2857259fc2b4 90 " parseDnsLines(topics[1]);\n"
andrewboyson 86:f3c9beec4ee7 91 "}\n"
andrewboyson 86:f3c9beec4ee7 92 "function displayGeneral()\n"
andrewboyson 86:f3c9beec4ee7 93 "{\n"
andrewboyson 86:f3c9beec4ee7 94 " var elem;\n"
andrewboyson 86:f3c9beec4ee7 95 "\n"
andrewboyson 86:f3c9beec4ee7 96 " elem = document.getElementById('ajax-response' ); if (elem) elem.textContent = response;\n"
andrewboyson 86:f3c9beec4ee7 97 " elem = document.getElementById('ajax-headers' ); if (elem) elem.textContent = headers;\n"
andrewboyson 86:f3c9beec4ee7 98 " elem = document.getElementById('ajax-arp' ); if (elem) elem.textContent = arp;\n"
andrewboyson 86:f3c9beec4ee7 99 " elem = document.getElementById('ajax-dns' ); if (elem) elem.textContent = dns;\n"
andrewboyson 86:f3c9beec4ee7 100 "}\n"
andrewboyson 86:f3c9beec4ee7 101 "\n"
andrewboyson 86:f3c9beec4ee7 102 "var ajax;\n"
andrewboyson 86:f3c9beec4ee7 103 "function AjaxRequest(request) //Used by this script and from HTML page\n"
andrewboyson 86:f3c9beec4ee7 104 "{\n"
andrewboyson 86:f3c9beec4ee7 105 " ajax=new XMLHttpRequest();\n"
andrewboyson 86:f3c9beec4ee7 106 " ajax.onreadystatechange=handleAjaxResponse;\n"
andrewboyson 86:f3c9beec4ee7 107 " if (request) ajax.open('GET', '/net6-ajax' + '?' + request, true);\n"
andrewboyson 86:f3c9beec4ee7 108 " else ajax.open('GET', '/net6-ajax' , true);\n"
andrewboyson 86:f3c9beec4ee7 109 " ajax.send();\n"
andrewboyson 86:f3c9beec4ee7 110 "}\n"
andrewboyson 86:f3c9beec4ee7 111 "function requestAjax() //Used in this script\n"
andrewboyson 86:f3c9beec4ee7 112 "{\n"
andrewboyson 86:f3c9beec4ee7 113 " AjaxRequest('');\n"
andrewboyson 86:f3c9beec4ee7 114 "}\n"
andrewboyson 86:f3c9beec4ee7 115 "\n"
andrewboyson 86:f3c9beec4ee7 116 "function handleAjaxResponse()\n"
andrewboyson 86:f3c9beec4ee7 117 "{\n"
andrewboyson 86:f3c9beec4ee7 118 " if (ajax.readyState==4 && ajax.status==200)\n"
andrewboyson 86:f3c9beec4ee7 119 " {\n"
andrewboyson 86:f3c9beec4ee7 120 " response = ajax.responseText;\n"
andrewboyson 86:f3c9beec4ee7 121 " headers = ajax.getAllResponseHeaders();\n"
andrewboyson 86:f3c9beec4ee7 122 " parseAjax();\n"
andrewboyson 86:f3c9beec4ee7 123 " displayGeneral();\n"
andrewboyson 86:f3c9beec4ee7 124 " }\n"
andrewboyson 86:f3c9beec4ee7 125 "}\n"
andrewboyson 86:f3c9beec4ee7 126 "\n"
andrewboyson 86:f3c9beec4ee7 127 "function init()\n"
andrewboyson 86:f3c9beec4ee7 128 "{\n"
andrewboyson 86:f3c9beec4ee7 129 " setInterval(requestAjax, 10000);\n"
andrewboyson 86:f3c9beec4ee7 130 " requestAjax();\n"
andrewboyson 86:f3c9beec4ee7 131 "}\n"
andrewboyson 86:f3c9beec4ee7 132 "if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init ); // Loading hasn't finished yet\n"
andrewboyson 86:f3c9beec4ee7 133 "else init(); //`DOMContentLoaded` has already fired\n"
andrewboyson 86:f3c9beec4ee7 134 ""