Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Sun Jan 10 11:53:12 2021 +0000
Parent:
146:6bc151bd7063
Child:
148:3d685db9fdd3
Commit message:
Added ability for the user to resolve a name.

Changed in this revision

base/clock/web-clock-query.c Show annotated file Show diff for this revision Revisions of this file
base/clock/web-web-query.c Show diff for this revision Revisions of this file
base/net/web-net-ajax.c Show annotated file Show diff for this revision Revisions of this file
base/net/web-net-class.inc Show annotated file Show diff for this revision Revisions of this file
base/net/web-net-class.js Show annotated file Show diff for this revision Revisions of this file
base/net/web-net-html.c Show annotated file Show diff for this revision Revisions of this file
base/net/web-net-query.c Show annotated file Show diff for this revision Revisions of this file
base/net/web-net-script.inc Show annotated file Show diff for this revision Revisions of this file
base/net/web-net-script.js Show annotated file Show diff for this revision Revisions of this file
base/web-pages-base.h Show annotated file Show diff for this revision Revisions of this file
base/web-server-base.c Show annotated file Show diff for this revision Revisions of this file
web-add.c Show annotated file Show diff for this revision Revisions of this file
web-add.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/clock/web-clock-query.c	Sun Jan 10 11:53:12 2021 +0000
@@ -0,0 +1,62 @@
+#include "http.h"
+#include "clkgov.h"
+#include "clkutc.h"
+#include "led.h"
+#include "settings.h"
+
+void WebClockQuery(char* pQuery)
+{
+    while (pQuery)
+    {
+        char* pName;
+        char* pValue;
+        pQuery = HttpQuerySplit(pQuery, &pName, &pValue);
+        int value = HttpQueryValueAsInt(pValue);
+        
+        if (HttpSameStr(pName, "chg-clock-leap-enable" )) ClkUtcTglNextLeapEnable ();
+        if (HttpSameStr(pName, "chg-clock-leap-forward")) ClkUtcTglNextLeapForward();
+        
+        int months1970 = ClkUtcGetNextEpochMonth1970();
+        int months     = months1970 % 12;
+        int years      = months1970 / 12;
+        
+        if (HttpSameStr(pName, "set-clock-leap-year"    ))
+        {
+            years = value - 1970;
+            if (years < 0) years = 0;
+            ClkUtcSetNextEpochMonth1970(years * 12 + months);     
+        }
+        if (HttpSameStr(pName, "set-clock-leap-month"   ))
+        {
+            months = value - 1;
+            if (months < 0) months = 0;
+            ClkUtcSetNextEpochMonth1970(years * 12 + months);     
+        }
+        if (HttpSameStr(pName, "set-clock-leap-count"   ))
+        {
+            uint16_t leaps = value;
+            ClkUtcSetEpochOffsetWithoutUtcChange(leaps);     
+        }
+        
+        if (HttpSameStr(pName, "ppb"           )) ClkGovSetPpb               (value           );
+        if (HttpSameStr(pName, "slewdivisor"   )) SetClockSlewDivisor        (value           );
+        if (HttpSameStr(pName, "slewmax"       )) SetClockSlewMaxMs          (value           );
+        if (HttpSameStr(pName, "ppbdivisor"    )) SetClockPpbDivisor         (value           );
+        if (HttpSameStr(pName, "ppbmaxchange"  )) SetClockPpbChangeMax       (value           );
+        if (HttpSameStr(pName, "syncedlimitns" )) SetClockSyncedLimitNs      (value * 1000000 );
+        if (HttpSameStr(pName, "syncedhysns"   )) SetClockSyncedHysterisNs   (value * 1000000 );
+        if (HttpSameStr(pName, "syncedlimitppb")) SetClockSyncedLimitPpb     (value           );
+        if (HttpSameStr(pName, "syncedhysppb"  )) SetClockSyncedHysterisPpb  (value           );
+        if (HttpSameStr(pName, "maxoffsetsecs" )) SetClockMaxOffsetSecs      (value           );
+        if (HttpSameStr(pName, "clockgovtrace" )) ChgTraceSync();
+        
+        if (HttpSameStr(pName, "ntpserver"     )) SetNtpClientServerName     (pValue          );
+        if (HttpSameStr(pName, "clockinitial"  )) SetNtpClientInitialInterval(value           );
+        if (HttpSameStr(pName, "clocknormal"   )) SetNtpClientNormalInterval (value *      60 );
+        if (HttpSameStr(pName, "clockretry"    )) SetNtpClientRetryInterval  (value           );
+        if (HttpSameStr(pName, "clockoffset"   )) SetNtpClientOffsetMs       (value           );
+        if (HttpSameStr(pName, "clockmaxdelay" )) SetNtpClientMaxDelayMs     (value           );
+
+    }
+}
+
--- a/base/clock/web-web-query.c	Mon Jan 04 16:09:03 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-#include "http.h"
-#include "clkgov.h"
-#include "clkutc.h"
-#include "led.h"
-#include "settings.h"
-
-void WebClockQuery(char* pQuery)
-{
-    while (pQuery)
-    {
-        char* pName;
-        char* pValue;
-        pQuery = HttpQuerySplit(pQuery, &pName, &pValue);
-        int value = HttpQueryValueAsInt(pValue);
-        
-        if (HttpSameStr(pName, "chg-clock-leap-enable" )) ClkUtcTglNextLeapEnable ();
-        if (HttpSameStr(pName, "chg-clock-leap-forward")) ClkUtcTglNextLeapForward();
-        
-        int months1970 = ClkUtcGetNextEpochMonth1970();
-        int months     = months1970 % 12;
-        int years      = months1970 / 12;
-        
-        if (HttpSameStr(pName, "set-clock-leap-year"    ))
-        {
-            years = value - 1970;
-            if (years < 0) years = 0;
-            ClkUtcSetNextEpochMonth1970(years * 12 + months);     
-        }
-        if (HttpSameStr(pName, "set-clock-leap-month"   ))
-        {
-            months = value - 1;
-            if (months < 0) months = 0;
-            ClkUtcSetNextEpochMonth1970(years * 12 + months);     
-        }
-        if (HttpSameStr(pName, "set-clock-leap-count"   ))
-        {
-            uint16_t leaps = value;
-            ClkUtcSetEpochOffsetWithoutUtcChange(leaps);     
-        }
-        
-        if (HttpSameStr(pName, "ppb"           )) ClkGovSetPpb               (value           );
-        if (HttpSameStr(pName, "slewdivisor"   )) SetClockSlewDivisor        (value           );
-        if (HttpSameStr(pName, "slewmax"       )) SetClockSlewMaxMs          (value           );
-        if (HttpSameStr(pName, "ppbdivisor"    )) SetClockPpbDivisor         (value           );
-        if (HttpSameStr(pName, "ppbmaxchange"  )) SetClockPpbChangeMax       (value           );
-        if (HttpSameStr(pName, "syncedlimitns" )) SetClockSyncedLimitNs      (value * 1000000 );
-        if (HttpSameStr(pName, "syncedhysns"   )) SetClockSyncedHysterisNs   (value * 1000000 );
-        if (HttpSameStr(pName, "syncedlimitppb")) SetClockSyncedLimitPpb     (value           );
-        if (HttpSameStr(pName, "syncedhysppb"  )) SetClockSyncedHysterisPpb  (value           );
-        if (HttpSameStr(pName, "maxoffsetsecs" )) SetClockMaxOffsetSecs      (value           );
-        if (HttpSameStr(pName, "clockgovtrace" )) ChgTraceSync();
-        
-        if (HttpSameStr(pName, "ntpserver"     )) SetNtpClientServerName     (pValue          );
-        if (HttpSameStr(pName, "clockinitial"  )) SetNtpClientInitialInterval(value           );
-        if (HttpSameStr(pName, "clocknormal"   )) SetNtpClientNormalInterval (value *      60 );
-        if (HttpSameStr(pName, "clockretry"    )) SetNtpClientRetryInterval  (value           );
-        if (HttpSameStr(pName, "clockoffset"   )) SetNtpClientOffsetMs       (value           );
-        if (HttpSameStr(pName, "clockmaxdelay" )) SetNtpClientMaxDelayMs     (value           );
-
-    }
-}
-
--- a/base/net/web-net-ajax.c	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/net/web-net-ajax.c	Sun Jan 10 11:53:12 2021 +0000
@@ -12,6 +12,8 @@
     
     for (int b = 0; b < 6; b++) HttpAddByteAsHex(MacLocal[b]);
     HttpAddChar('\n');
+    HttpAddText(NrTest);
+    HttpAddChar('\n');
     HttpAddChar('\f');
     
     TcbSendAjax();
--- a/base/net/web-net-class.inc	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/net/web-net-class.inc	Sun Jan 10 11:53:12 2021 +0000
@@ -39,6 +39,13 @@
 "    }\n"
 "    static getVendorFromLocalStorage(mac)\n"
 "    {\n"
+"        if (mac[1] === '2' ||\n"
+"            mac[1] === '6' ||\n"
+"            mac[1] === 'a' ||\n"
+"            mac[1] === 'A' ||\n"
+"            mac[1] === 'e' ||\n"
+"            mac[1] === 'E'    ) return '(Locally administered)';\n"
+"            \n"
 "        return localStorage.getItem(mac);\n"
 "    }\n"
 "    static clearVendorsFromLocalStorage()\n"
--- a/base/net/web-net-class.js	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/net/web-net-class.js	Sun Jan 10 11:53:12 2021 +0000
@@ -39,6 +39,13 @@
     }
     static getVendorFromLocalStorage(mac)
     {
+        if (mac[1] === '2' ||
+            mac[1] === '6' ||
+            mac[1] === 'a' ||
+            mac[1] === 'A' ||
+            mac[1] === 'e' ||
+            mac[1] === 'E'    ) return '(Locally administered)';
+            
         return localStorage.getItem(mac);
     }
     static clearVendorsFromLocalStorage()
--- a/base/net/web-net-html.c	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/net/web-net-html.c	Sun Jan 10 11:53:12 2021 +0000
@@ -11,11 +11,21 @@
     WebAddH1("Net");
                      
     WebAddH2("MAC");
-    HttpAddText("<code id='ajax-mac'></code>\r\n");    
+    HttpAddText("<code id='ajax-mac'></code>\r\n");
+    
     WebAddH2("TCP connections");
     HttpAddText("<code id='ajax-tcp'></code>\r\n");
+    
     WebAddH2("Name resolution");
+    WebAddAjaxInput("Name", 40, "ajax-nr", "name-to-resolve");
+    WebAddAjaxButton("Request AAAA", "request-AAAA");
+    WebAddAjaxButton("Request A"   , "request-A"   );
+    
+    WebAddH2("Name cache");
     HttpAddText("<code id='ajax-dns'></code>\r\n");
+    HttpAddText("<div class='line'>\r\n");
+    HttpAddText("<button onclick = 'Net.clearVendorsFromLocalStorage()'>Clear vendors</button>\r\n");
+    HttpAddText("</div>\r\n");
     
     WebAddEnd();
                         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/net/web-net-query.c	Sun Jan 10 11:53:12 2021 +0000
@@ -0,0 +1,29 @@
+#include <string.h>
+
+#include "http.h"
+#include "nr.h"
+
+void WebNetQuery(char* pQuery)
+{
+    while (pQuery)
+    {
+        char* pName;
+        char* pValue;
+        pQuery = HttpQuerySplit(pQuery, &pName, &pValue);
+        int value = HttpQueryValueAsInt(pValue);
+        
+        if (HttpSameStr(pName, "name-to-resolve"))
+        {
+            strncpy(NrTest, pValue, NR_NAME_MAX_LENGTH);
+        }
+        if (HttpSameStr(pName, "request-AAAA"))
+        {
+            NrMakeRequestForAddress6FromName(NrTest);
+        }
+        if (HttpSameStr(pName, "request-A"))
+        {
+            NrMakeRequestForAddress4FromName(NrTest);
+        }
+    }
+}
+
--- a/base/net/web-net-script.inc	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/net/web-net-script.inc	Sun Jan 10 11:53:12 2021 +0000
@@ -2,6 +2,7 @@
 "'use strict';\n"
 "\n"
 "let mac = '';\n"
+"let nr  = '';\n"
 "let tcp = '';\n"
 "let dns = '';\n"
 "let a4s = null;\n"
@@ -52,31 +53,52 @@
 "    let minutes  = parseInt(fields[1], 16) / 1000 / 60;\n"
 "    dns += Math.floor(minutes).toString().padStart(4, ' ');\n"
 "    dns += ' ';\n"
+"    let addrType = fields[2];\n"
+"    switch (addrType)\n"
+"    {\n"
+"        case '4': dns += '   A'; break;\n"
+"        case '6': dns += 'AAAA'; break;\n"
+"        default:  dns += addrType; break;\n"
+"    }\n"
+"    dns += ' ';\n"
 "    let addr = '';\n"
 "    let mac = '';\n"
-"    if (fields[2].substr( 0, 2) === '00') //Is empty or IP4\n"
+"    switch (addrType)\n"
 "    {\n"
-"        if (fields[2].substr(24, 2) === '00') //Is empty\n"
+"        case '4':\n"
+"            addr = Net.makeIp4(fields[3]);\n"
+"            if (a4s.has(addr)) mac = a4s.get(addr);\n"
+"            break;\n"
+"        case '6':\n"
+"            addr = Net.makeIp6(fields[3]);\n"
+"            if (a6s.has(addr)) mac = a6s.get(addr);\n"
+"            break;\n"
+"    }\n"
+"    /*\n"
+"    if (fields[3].substr( 0, 2) === '00') //Is empty or IP4\n"
+"    {\n"
+"        if (fields[3].substr(24, 2) === '00') //Is empty\n"
 "        {\n"
 "            addr = '';\n"
 "        }\n"
 "        else //Is Ip4\n"
 "        {\n"
-"            addr = Net.makeIp4Rev(fields[2].substr(24, 8));\n"
+"            addr = Net.makeIp4Rev(fields[3].substr(24, 8));\n"
 "            if (a4s.has(addr)) mac = a4s.get(addr);\n"
 "        }\n"
 "    }\n"
 "    else //Is IP6\n"
 "    {\n"
-"        addr = Net.makeIp6(fields[2]);\n"
+"        addr = Net.makeIp6(fields[3]);\n"
 "        if (a6s.has(addr)) mac = a6s.get(addr)\n"
 "    }\n"
+"    */\n"
 "    dns += addr.padEnd(40, ' ');\n"
 "    \n"
 "    dns += ' ';\n"
-"    dns += fields[3]; //DNS protocol used\n"
+"    dns += fields[4]; //DNS protocol used\n"
 "    dns += ' ';\n"
-"    dns += fields[4].padEnd(20, ' '); //Resolved name\n"
+"    dns += fields[5].padEnd(32, ' '); //Resolved name\n"
 "    \n"
 "    if (mac != '')\n"
 "    {\n"
@@ -125,6 +147,7 @@
 "{\n"
 "    let lines = text.split('\\n');\n"
 "    mac = Net.makeMac(lines[ 0]);\n"
+"    nr  =             lines[ 1] ;\n"
 "}\n"
 "function parseTcpLines(text)\n"
 "{\n"
@@ -161,6 +184,7 @@
 "\n"
 "    elem = Ajax.getElementOrNull('ajax-tcp'         ); if (elem) elem.textContent = tcp;\n"
 "    elem = Ajax.getElementOrNull('ajax-mac'         ); if (elem) elem.textContent = mac;\n"
+"    elem = Ajax.getElementOrNull('ajax-nr'          ); if (elem) elem.value       = nr;\n"
 "    elem = Ajax.getElementOrNull('ajax-dns'         ); if (elem) elem.textContent = dns;\n"
 "}\n"
 "\n"
--- a/base/net/web-net-script.js	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/net/web-net-script.js	Sun Jan 10 11:53:12 2021 +0000
@@ -2,6 +2,7 @@
 'use strict';
 
 let mac = '';
+let nr  = '';
 let tcp = '';
 let dns = '';
 let a4s = null;
@@ -52,31 +53,52 @@
     let minutes  = parseInt(fields[1], 16) / 1000 / 60;
     dns += Math.floor(minutes).toString().padStart(4, ' ');
     dns += ' ';
+    let addrType = fields[2];
+    switch (addrType)
+    {
+        case '4': dns += '   A'; break;
+        case '6': dns += 'AAAA'; break;
+        default:  dns += addrType; break;
+    }
+    dns += ' ';
     let addr = '';
     let mac = '';
-    if (fields[2].substr( 0, 2) === '00') //Is empty or IP4
+    switch (addrType)
     {
-        if (fields[2].substr(24, 2) === '00') //Is empty
+        case '4':
+            addr = Net.makeIp4(fields[3]);
+            if (a4s.has(addr)) mac = a4s.get(addr);
+            break;
+        case '6':
+            addr = Net.makeIp6(fields[3]);
+            if (a6s.has(addr)) mac = a6s.get(addr);
+            break;
+    }
+    /*
+    if (fields[3].substr( 0, 2) === '00') //Is empty or IP4
+    {
+        if (fields[3].substr(24, 2) === '00') //Is empty
         {
             addr = '';
         }
         else //Is Ip4
         {
-            addr = Net.makeIp4Rev(fields[2].substr(24, 8));
+            addr = Net.makeIp4Rev(fields[3].substr(24, 8));
             if (a4s.has(addr)) mac = a4s.get(addr);
         }
     }
     else //Is IP6
     {
-        addr = Net.makeIp6(fields[2]);
+        addr = Net.makeIp6(fields[3]);
         if (a6s.has(addr)) mac = a6s.get(addr)
     }
+    */
     dns += addr.padEnd(40, ' ');
     
     dns += ' ';
-    dns += fields[3]; //DNS protocol used
+    dns += fields[4]; //DNS protocol used
     dns += ' ';
-    dns += fields[4].padEnd(20, ' '); //Resolved name
+    dns += fields[5].padEnd(32, ' '); //Resolved name
     
     if (mac != '')
     {
@@ -125,6 +147,7 @@
 {
     let lines = text.split('\n');
     mac = Net.makeMac(lines[ 0]);
+    nr  =             lines[ 1] ;
 }
 function parseTcpLines(text)
 {
@@ -161,6 +184,7 @@
 
     elem = Ajax.getElementOrNull('ajax-tcp'         ); if (elem) elem.textContent = tcp;
     elem = Ajax.getElementOrNull('ajax-mac'         ); if (elem) elem.textContent = mac;
+    elem = Ajax.getElementOrNull('ajax-nr'          ); if (elem) elem.value       = nr;
     elem = Ajax.getElementOrNull('ajax-dns'         ); if (elem) elem.textContent = dns;
 }
 
--- a/base/web-pages-base.h	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/web-pages-base.h	Sun Jan 10 11:53:12 2021 +0000
@@ -48,6 +48,7 @@
 extern const char* WebNetScriptDate;
 extern const char* WebNetScriptTime;
 extern void        WebNetAjax       (void);
+extern void        WebNetQuery      (char* pQuery);
 
 extern void        WebNet4Html      (void);
 extern void        WebNet4Script    (void);
--- a/base/web-server-base.c	Mon Jan 04 16:09:03 2021 +0000
+++ b/base/web-server-base.c	Sun Jan 10 11:53:12 2021 +0000
@@ -63,6 +63,7 @@
         case DO_TRACE_AJAX:    WebTraceQuery   (pQuery); return true;
         case DO_CLOCK_AJAX:    WebClockQuery   (pQuery); return true;
         case DO_CLOCK_HTML:    WebClockQuery   (pQuery); return true;
+        case DO_NET_AJAX:      WebNetQuery     (pQuery); return true;
         case DO_LOG_HTML:      WebLogQuery     (pQuery); return true;
         case DO_RESET_HTML:    WebResetQuery   (pQuery); return true;
         case DO_FIRMWARE_HTML: WebFirmwareQuery(pQuery); return true;
--- a/web-add.c	Mon Jan 04 16:09:03 2021 +0000
+++ b/web-add.c	Sun Jan 10 11:53:12 2021 +0000
@@ -183,6 +183,10 @@
     HttpAddF   ("  <div class='led' id='%s' dir='ltr'></div>\r\n", id);
     HttpAddText("</div>\r\n");
 }
+void WebAddAjaxButton(const char* caption, const char* name)
+{
+    HttpAddF   ("<button onclick='AjaxSendNameValue(\"%s\", \"1\")'>%s</button>\r\n", name, caption);
+}
 void WebAddAjaxInput(const char* label, float inputwidth, const char* id, const char* name)
 {
     HttpAddText("<div class='line'>\r\n");
--- a/web-add.h	Mon Jan 04 16:09:03 2021 +0000
+++ b/web-add.h	Sun Jan 10 11:53:12 2021 +0000
@@ -22,6 +22,7 @@
 extern void WebAddInputButton         (const char* label,                       const char* value, const char* action, const char* name);
 
 extern void WebAddAjaxLed             (const char* label,                       const char* id);
+extern void WebAddAjaxButton          (const char* label,                                       const char* name);
 extern void WebAddAjaxLabelled        (const char* label,                       const char* id);
 extern void WebAddAjaxLabelledSuffix  (const char* label,                       const char* id,                   const char* suffix);
 extern void WebAddAjaxInputToggle     (const char* label,                       const char* id, const char* name);