Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Sat Dec 26 19:38:40 2020 +0000
Revision:
143:cc2e148cb96a
Parent:
133:98c6bf14bc37
Child:
144:7106252b7abf
First part of moving DNs from ipv6 to net

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 132:5b2df69a4f17 1 "//Net script\n"
andrewboyson 132:5b2df69a4f17 2 "'use strict';\n"
andrewboyson 132:5b2df69a4f17 3 "\n"
andrewboyson 132:5b2df69a4f17 4 "let mac = '';\n"
andrewboyson 132:5b2df69a4f17 5 "let tcp = '';\n"
andrewboyson 143:cc2e148cb96a 6 "let dns = '';\n"
andrewboyson 132:5b2df69a4f17 7 "\n"
andrewboyson 132:5b2df69a4f17 8 "function parseTcpLine(line)\n"
andrewboyson 132:5b2df69a4f17 9 "{\n"
andrewboyson 132:5b2df69a4f17 10 " if (line.length == 0) return;\n"
andrewboyson 132:5b2df69a4f17 11 " let fields = line.split('\\t');\n"
andrewboyson 133:98c6bf14bc37 12 " let state = parseInt(fields[0], 16);\n"
andrewboyson 133:98c6bf14bc37 13 " let idleMs = parseInt(fields[1], 16);\n"
andrewboyson 133:98c6bf14bc37 14 " let ipType = parseInt(fields[2], 16);\n"
andrewboyson 133:98c6bf14bc37 15 " let arIndex = parseInt(fields[3], 16);\n"
andrewboyson 133:98c6bf14bc37 16 " let locPort = parseInt(fields[4], 16);\n"
andrewboyson 133:98c6bf14bc37 17 " let remPort = parseInt(fields[5], 16);\n"
andrewboyson 133:98c6bf14bc37 18 " let bytesRcvd = parseInt(fields[6], 16);\n"
andrewboyson 133:98c6bf14bc37 19 " let bytesSent = parseInt(fields[7], 16);\n"
andrewboyson 132:5b2df69a4f17 20 " \n"
andrewboyson 133:98c6bf14bc37 21 " switch (state)\n"
andrewboyson 133:98c6bf14bc37 22 " {\n"
andrewboyson 143:cc2e148cb96a 23 " case 1: tcp += \" Syn\"; break;\n"
andrewboyson 143:cc2e148cb96a 24 " case 2: tcp += \" Est\"; break;\n"
andrewboyson 143:cc2e148cb96a 25 " case 3: tcp += \" Wait\"; break;\n"
andrewboyson 133:98c6bf14bc37 26 " default: tcp += state.toString().padStart(5, ' '); break;\n"
andrewboyson 133:98c6bf14bc37 27 " }\n"
andrewboyson 132:5b2df69a4f17 28 " \n"
andrewboyson 133:98c6bf14bc37 29 " let idleMinutes = Math.floor(idleMs / 1000 / 60);\n"
andrewboyson 133:98c6bf14bc37 30 " tcp += idleMinutes.toString().padStart(4, ' ');\n"
andrewboyson 133:98c6bf14bc37 31 " tcp += \" \";\n"
andrewboyson 132:5b2df69a4f17 32 " \n"
andrewboyson 133:98c6bf14bc37 33 " if (ipType == 0x0800) tcp += \"IPv4\";\n"
andrewboyson 132:5b2df69a4f17 34 " else if (ipType == 0x86DD) tcp += \"IPv6\";\n"
andrewboyson 132:5b2df69a4f17 35 " else tcp += fields[1];\n"
andrewboyson 132:5b2df69a4f17 36 " \n"
andrewboyson 133:98c6bf14bc37 37 " tcp += arIndex.toString().padStart(4, ' ');\n"
andrewboyson 133:98c6bf14bc37 38 " tcp += locPort.toString().padStart(9, ' ');\n"
andrewboyson 133:98c6bf14bc37 39 " tcp += remPort.toString().padStart(9, ' ');\n"
andrewboyson 133:98c6bf14bc37 40 " tcp += bytesRcvd.toString().padStart(6, ' ');\n"
andrewboyson 133:98c6bf14bc37 41 " tcp += bytesSent.toString().padStart(6, ' ');\n"
andrewboyson 132:5b2df69a4f17 42 " tcp += '\\r\\n';\n"
andrewboyson 132:5b2df69a4f17 43 "}\n"
andrewboyson 132:5b2df69a4f17 44 "function parseTcpLines(text)\n"
andrewboyson 132:5b2df69a4f17 45 "{\n"
andrewboyson 133:98c6bf14bc37 46 " tcp = \"State Idle Protocol ARI Port-Loc Port-Rem Rcvd Sent\\n\";\n"
andrewboyson 132:5b2df69a4f17 47 " text.split('\\n').forEach(parseTcpLine);\n"
andrewboyson 132:5b2df69a4f17 48 "}\n"
andrewboyson 143:cc2e148cb96a 49 "function parseDnsLine(line)\n"
andrewboyson 143:cc2e148cb96a 50 "{\n"
andrewboyson 143:cc2e148cb96a 51 " if (line.length == 0) return;\n"
andrewboyson 143:cc2e148cb96a 52 " let fields = line.split('\\t');\n"
andrewboyson 143:cc2e148cb96a 53 " \n"
andrewboyson 143:cc2e148cb96a 54 " dns += parseInt(fields[0], 16).toString().padStart(2, ' ');\n"
andrewboyson 143:cc2e148cb96a 55 " let minutes = parseInt(fields[1], 16) / 1000 / 60;\n"
andrewboyson 143:cc2e148cb96a 56 " dns += Math.floor(minutes).toString().padStart(4, ' ');\n"
andrewboyson 143:cc2e148cb96a 57 " dns += ' ';\n"
andrewboyson 143:cc2e148cb96a 58 " dns += Net.makeIp6(fields[2]).padEnd(40, ' ');\n"
andrewboyson 143:cc2e148cb96a 59 " dns += ' ';\n"
andrewboyson 143:cc2e148cb96a 60 " dns += fields[3];\n"
andrewboyson 143:cc2e148cb96a 61 " dns += ' ';\n"
andrewboyson 143:cc2e148cb96a 62 " dns += fields[4];\n"
andrewboyson 143:cc2e148cb96a 63 " dns += '\\r\\n';\n"
andrewboyson 143:cc2e148cb96a 64 "}\n"
andrewboyson 132:5b2df69a4f17 65 "function parseGenLines(text)\n"
andrewboyson 132:5b2df69a4f17 66 "{\n"
andrewboyson 132:5b2df69a4f17 67 " let lines = text.split('\\n');\n"
andrewboyson 132:5b2df69a4f17 68 " mac = Net.makeMac(lines[ 0]);\n"
andrewboyson 132:5b2df69a4f17 69 "}\n"
andrewboyson 132:5b2df69a4f17 70 "function parse()\n"
andrewboyson 132:5b2df69a4f17 71 "{\n"
andrewboyson 132:5b2df69a4f17 72 " let topics = Ajax.response.split('\\f');\n"
andrewboyson 132:5b2df69a4f17 73 " parseGenLines(topics[0]);\n"
andrewboyson 132:5b2df69a4f17 74 " parseTcpLines(topics[1]);\n"
andrewboyson 143:cc2e148cb96a 75 " parseDnsLines(topics[2]);\n"
andrewboyson 132:5b2df69a4f17 76 "}\n"
andrewboyson 132:5b2df69a4f17 77 "function display()\n"
andrewboyson 132:5b2df69a4f17 78 "{\n"
andrewboyson 132:5b2df69a4f17 79 " let elem;\n"
andrewboyson 132:5b2df69a4f17 80 "\n"
andrewboyson 132:5b2df69a4f17 81 " elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp;\n"
andrewboyson 132:5b2df69a4f17 82 " elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac;\n"
andrewboyson 143:cc2e148cb96a 83 " elem = Ajax.getElementOrNull('ajax-dns' ); if (elem) elem.textContent = dns;\n"
andrewboyson 132:5b2df69a4f17 84 "}\n"
andrewboyson 132:5b2df69a4f17 85 "\n"
andrewboyson 132:5b2df69a4f17 86 "Ajax.server = '/net-ajax';\n"
andrewboyson 132:5b2df69a4f17 87 "Ajax.onResponse = function() { parse(); display(); };\n"
andrewboyson 132:5b2df69a4f17 88 "Ajax.init();\n"
andrewboyson 132:5b2df69a4f17 89 ""