Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Mon Apr 08 10:13:01 2019 +0000
Revision:
86:f3c9beec4ee7
Parent:
84:4ed751de613e
Child:
90:9cc77a16b6c5
Split the NET page into general net, net ipv4 and net ipv6. Also made the arp and dns update through ajax.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 0:f8998d10763e 1 #include <stdio.h>
andrewboyson 30:6a08abbe6301 2 #include "http.h"
andrewboyson 30:6a08abbe6301 3 #include "page.h"
andrewboyson 30:6a08abbe6301 4 #include "page-derived.h"
andrewboyson 30:6a08abbe6301 5 #include "mac.h"
andrewboyson 0:f8998d10763e 6 #include "ip4addr.h"
andrewboyson 0:f8998d10763e 7 #include "ip6addr.h"
andrewboyson 0:f8998d10763e 8
andrewboyson 2:14de8c14afd9 9 void PageAddHeader(const char* site, const char* title, const char* style, const char* script)
andrewboyson 0:f8998d10763e 10 {
andrewboyson 0:f8998d10763e 11 HttpAddText("<!DOCTYPE html>\r\n"
andrewboyson 0:f8998d10763e 12 "<html>\r\n"
andrewboyson 0:f8998d10763e 13 "<head>\r\n");
andrewboyson 2:14de8c14afd9 14 if (site)
andrewboyson 0:f8998d10763e 15 {
andrewboyson 0:f8998d10763e 16 HttpAddText(" <title>");
andrewboyson 2:14de8c14afd9 17 HttpAddText(site);
andrewboyson 2:14de8c14afd9 18 if (title)
andrewboyson 2:14de8c14afd9 19 {
andrewboyson 2:14de8c14afd9 20 HttpAddText(" - ");
andrewboyson 2:14de8c14afd9 21 HttpAddText(title);
andrewboyson 2:14de8c14afd9 22 }
andrewboyson 0:f8998d10763e 23 HttpAddText("</title>\r\n");
andrewboyson 0:f8998d10763e 24 }
andrewboyson 0:f8998d10763e 25 HttpAddText(" <link rel='stylesheet' href='/base.css' type='text/css'/>\r\n");
andrewboyson 0:f8998d10763e 26 if (style)
andrewboyson 0:f8998d10763e 27 {
andrewboyson 0:f8998d10763e 28 HttpAddText(" <link rel='stylesheet' href='/");
andrewboyson 0:f8998d10763e 29 HttpAddText(style);
andrewboyson 0:f8998d10763e 30 HttpAddText("' type='text/css'/>\r\n");
andrewboyson 0:f8998d10763e 31 }
andrewboyson 0:f8998d10763e 32 if (script)
andrewboyson 0:f8998d10763e 33 {
andrewboyson 0:f8998d10763e 34 HttpAddText(" <script src='/");
andrewboyson 0:f8998d10763e 35 HttpAddText(script);
andrewboyson 0:f8998d10763e 36 HttpAddText("' type='text/javascript'></script>\r\n");
andrewboyson 0:f8998d10763e 37 }
andrewboyson 0:f8998d10763e 38 HttpAddText(" <meta name='viewport' content='width=device-width, initial-scale=1'>\r\n"
andrewboyson 0:f8998d10763e 39 " <link rel='icon' href='/favicon.ico' type='image/x-icon'/>\r\n"
andrewboyson 0:f8998d10763e 40 "</head>\r\n"
andrewboyson 0:f8998d10763e 41 "<body>\r\n");
andrewboyson 0:f8998d10763e 42
andrewboyson 0:f8998d10763e 43 }
andrewboyson 12:237a0f75b4d0 44 void PageAddH1(const char* site, const char* pageName)
andrewboyson 12:237a0f75b4d0 45 {
andrewboyson 12:237a0f75b4d0 46 HttpAddText("<h1>");
andrewboyson 12:237a0f75b4d0 47 HttpAddText(site);
andrewboyson 12:237a0f75b4d0 48 HttpAddText(" - ");
andrewboyson 12:237a0f75b4d0 49 HttpAddText(pageName);
andrewboyson 12:237a0f75b4d0 50 HttpAddText("</h1>\r\n");
andrewboyson 12:237a0f75b4d0 51 }
andrewboyson 12:237a0f75b4d0 52 void PageAddH2(const char* text)
andrewboyson 12:237a0f75b4d0 53 {
andrewboyson 12:237a0f75b4d0 54 HttpAddText("<h2>");
andrewboyson 12:237a0f75b4d0 55 HttpAddText(text);
andrewboyson 12:237a0f75b4d0 56 HttpAddText("</h2>\r\n");
andrewboyson 12:237a0f75b4d0 57 }
andrewboyson 12:237a0f75b4d0 58 void PageAddEnd()
andrewboyson 12:237a0f75b4d0 59 {
andrewboyson 12:237a0f75b4d0 60 HttpAddText("</body>\r\n"
andrewboyson 12:237a0f75b4d0 61 "</html>\r\n");
andrewboyson 12:237a0f75b4d0 62 }
andrewboyson 0:f8998d10763e 63
andrewboyson 0:f8998d10763e 64 void PageAddNavItem(int highlight, char* href, char* title)
andrewboyson 0:f8998d10763e 65 {
andrewboyson 0:f8998d10763e 66 char *p;
andrewboyson 0:f8998d10763e 67 HttpAddText("<li ");
andrewboyson 0:f8998d10763e 68 if (highlight) p = "class='this'";
andrewboyson 0:f8998d10763e 69 else p = " ";
andrewboyson 0:f8998d10763e 70 HttpAddText(p);
andrewboyson 0:f8998d10763e 71 HttpAddText("><a href='");
andrewboyson 0:f8998d10763e 72 HttpAddText(href);
andrewboyson 0:f8998d10763e 73 HttpAddText("'>");
andrewboyson 0:f8998d10763e 74 HttpAddText(title);
andrewboyson 0:f8998d10763e 75 HttpAddText("</a></li>\r\n");
andrewboyson 0:f8998d10763e 76
andrewboyson 0:f8998d10763e 77 }
andrewboyson 30:6a08abbe6301 78 void PageAddNav(int page)
andrewboyson 30:6a08abbe6301 79 {
andrewboyson 30:6a08abbe6301 80 HttpAddText("<nav><ul>\r\n");
andrewboyson 30:6a08abbe6301 81 PageAddNavDerived(page);
andrewboyson 86:f3c9beec4ee7 82 PageAddNavItem(page == CLOCK_PAGE, "/clock", "Clock" );
andrewboyson 86:f3c9beec4ee7 83 PageAddNavItem(page == FAULT_PAGE, "/fault", "Fault" );
andrewboyson 86:f3c9beec4ee7 84 PageAddNavItem(page == NET_PAGE, "/net", "Net" );
andrewboyson 86:f3c9beec4ee7 85 PageAddNavItem(page == NET4_PAGE, "/net4", "Net IPv4" );
andrewboyson 86:f3c9beec4ee7 86 PageAddNavItem(page == NET6_PAGE, "/net6", "Net IPv6" );
andrewboyson 86:f3c9beec4ee7 87 PageAddNavItem(page == TRACE_PAGE, "/trace", "Net Trace");
andrewboyson 86:f3c9beec4ee7 88 PageAddNavItem(page == LOG_PAGE, "/log", "Log" );
andrewboyson 86:f3c9beec4ee7 89 PageAddNavItem(page == FIRMWARE_PAGE, "/firmware", "Firmware" );
andrewboyson 30:6a08abbe6301 90 HttpAddText("</ul></nav>\r\n");
andrewboyson 30:6a08abbe6301 91 }
andrewboyson 0:f8998d10763e 92
andrewboyson 77:4689596a2f3f 93 void PageAddLabelledPrefixSuffix(char* label, char* prefix, char* text, char* suffix)
andrewboyson 0:f8998d10763e 94 {
andrewboyson 77:4689596a2f3f 95 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 96 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 97 HttpAddF (" <div>%s%s%s</div>\r\n", prefix, text, suffix);
andrewboyson 77:4689596a2f3f 98 HttpAddText("</div>\r\n");
andrewboyson 77:4689596a2f3f 99 }
andrewboyson 77:4689596a2f3f 100 void PageAddLabelledText(char* label, char* text)
andrewboyson 77:4689596a2f3f 101 {
andrewboyson 77:4689596a2f3f 102 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 103 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 104 HttpAddF (" <div>%s</div>\r\n", text);
andrewboyson 0:f8998d10763e 105 HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 106 }
andrewboyson 0:f8998d10763e 107
andrewboyson 77:4689596a2f3f 108 void PageAddLabelledMac(char* label, char* mac)
andrewboyson 0:f8998d10763e 109 {
andrewboyson 77:4689596a2f3f 110 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 111 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 112 HttpAddText(" <div>"); MacHttp(mac); HttpAddText("</div>\r\n");
andrewboyson 77:4689596a2f3f 113 HttpAddText("</div>\r\n");
andrewboyson 77:4689596a2f3f 114 }
andrewboyson 77:4689596a2f3f 115
andrewboyson 77:4689596a2f3f 116 void PageAddLabelledIp4(char* label, uint32_t ip)
andrewboyson 77:4689596a2f3f 117 {
andrewboyson 77:4689596a2f3f 118 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 119 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 120 HttpAddText(" <div>"); Ip4AddressHttp(ip); HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 121 HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 122 }
andrewboyson 0:f8998d10763e 123
andrewboyson 77:4689596a2f3f 124 void PageAddLabelledIp6(char* label, char* ip)
andrewboyson 0:f8998d10763e 125 {
andrewboyson 77:4689596a2f3f 126 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 127 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 128 HttpAddText(" <div>"); Ip6AddressHttp(ip); HttpAddText("</div>\r\n");
andrewboyson 77:4689596a2f3f 129 HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 130 }
andrewboyson 77:4689596a2f3f 131 void PageAddLabelledOnOff(char* label, bool value)
andrewboyson 0:f8998d10763e 132 {
andrewboyson 77:4689596a2f3f 133 if (value) PageAddLabelledText(label, "On");
andrewboyson 77:4689596a2f3f 134 else PageAddLabelledText(label, "Off");
andrewboyson 0:f8998d10763e 135 }
andrewboyson 77:4689596a2f3f 136 void PageAddLabelledInt(char* label, int value)
andrewboyson 0:f8998d10763e 137 {
andrewboyson 0:f8998d10763e 138 char text[30];
andrewboyson 11:84121d7b47e9 139 snprintf(text, sizeof(text), "%8d", value); //Right align with enough spaces so that the length is always constant.
andrewboyson 77:4689596a2f3f 140 PageAddLabelledText(label, text);
andrewboyson 0:f8998d10763e 141 }
andrewboyson 77:4689596a2f3f 142 void PageAddInputText(char* label, float inputwidth, char* value, char* action, char* name)
andrewboyson 0:f8998d10763e 143 {
andrewboyson 58:e5ab14ef6ea6 144 HttpAddF ("<form action='%s' method='get'>\r\n", action);
andrewboyson 77:4689596a2f3f 145 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 146 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 58:e5ab14ef6ea6 147 HttpAddF (" <input type='text' name='%s' style='width:%.1fem;' value='%s'>\r\n", name, inputwidth, value);
andrewboyson 77:4689596a2f3f 148 HttpAddText("</div>\r\n");
andrewboyson 77:4689596a2f3f 149 HttpAddText("<input type='submit' value='Set' style='display:none;'>\r\n");
andrewboyson 58:e5ab14ef6ea6 150 HttpAddF ("</form>\r\n");
andrewboyson 0:f8998d10763e 151
andrewboyson 0:f8998d10763e 152 }
andrewboyson 77:4689596a2f3f 153 void PageAddInputInt(char* label, float inputwidth, int value, char* action, char* name)
andrewboyson 0:f8998d10763e 154 {
andrewboyson 0:f8998d10763e 155 char text[30];
andrewboyson 0:f8998d10763e 156 snprintf(text, sizeof(text), "%d", value);
andrewboyson 77:4689596a2f3f 157 PageAddInputText(label, inputwidth, text, action, name);
andrewboyson 0:f8998d10763e 158 }
andrewboyson 77:4689596a2f3f 159 void PageAddInputButton(char* label, char* value, char* action, char* name)
andrewboyson 0:f8998d10763e 160 {
andrewboyson 77:4689596a2f3f 161 HttpAddF ("<form action='%s' method='get'>\r\n", action);
andrewboyson 77:4689596a2f3f 162 HttpAddF ("<input type='hidden' name='%s'>\r\n", name);
andrewboyson 77:4689596a2f3f 163 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 164 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 165 HttpAddF (" <input type='submit' value='%s'>\r\n", value);
andrewboyson 77:4689596a2f3f 166 HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 167 HttpAddText("</form>\r\n");
andrewboyson 0:f8998d10763e 168 }
andrewboyson 77:4689596a2f3f 169 void PageAddAjaxInputToggle(char* label, char* id, char* name)
andrewboyson 0:f8998d10763e 170 {
andrewboyson 77:4689596a2f3f 171 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 172 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 58:e5ab14ef6ea6 173 HttpAddF (" <div class='toggle' id='%s' dir='ltr' onclick='AjaxRequest(\"%s=1\")'>\r\n", id, name);
andrewboyson 58:e5ab14ef6ea6 174 HttpAddText(" <div class='slot'></div><div class='knob'></div>\r\n");
andrewboyson 58:e5ab14ef6ea6 175 HttpAddText(" </div>\r\n");
andrewboyson 0:f8998d10763e 176 HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 177 }
andrewboyson 77:4689596a2f3f 178 void PageAddAjaxLed(char* label, char* id)
andrewboyson 58:e5ab14ef6ea6 179 {
andrewboyson 77:4689596a2f3f 180 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 181 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 58:e5ab14ef6ea6 182 HttpAddF (" <div class='led' id='%s' dir='ltr'></div>\r\n", id);
andrewboyson 0:f8998d10763e 183 HttpAddText("</div>\r\n");
andrewboyson 58:e5ab14ef6ea6 184 }
andrewboyson 77:4689596a2f3f 185 void PageAddAjaxInput(char* label, float inputwidth, char* id, char* name)
andrewboyson 58:e5ab14ef6ea6 186 {
andrewboyson 77:4689596a2f3f 187 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 188 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 189 HttpAddF (" <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>\r\n", inputwidth, id, name);
andrewboyson 0:f8998d10763e 190 HttpAddText("</div>\r\n");
andrewboyson 0:f8998d10763e 191 }
andrewboyson 84:4ed751de613e 192 void PageAddAjaxInputSuffix(char* label, float inputwidth, char* id, char* name, char* suffix)
andrewboyson 84:4ed751de613e 193 {
andrewboyson 84:4ed751de613e 194 HttpAddText("<div class='line'>\r\n");
andrewboyson 84:4ed751de613e 195 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 84:4ed751de613e 196 HttpAddF (" <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>%s\r\n", inputwidth, id, name, suffix);
andrewboyson 84:4ed751de613e 197 HttpAddText("</div>\r\n");
andrewboyson 84:4ed751de613e 198 }
andrewboyson 77:4689596a2f3f 199 void PageAddAjaxLabelled(char* label, char* id)
andrewboyson 57:8fa31ff4e773 200 {
andrewboyson 77:4689596a2f3f 201 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 202 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 203 HttpAddF (" <div id='%s'></div>\r\n", id);
andrewboyson 77:4689596a2f3f 204 HttpAddText("</div>\r\n");
andrewboyson 77:4689596a2f3f 205 }
andrewboyson 77:4689596a2f3f 206 void PageAddAjaxLabelledSuffix(char* label, char* id, char* suffix)
andrewboyson 77:4689596a2f3f 207 {
andrewboyson 77:4689596a2f3f 208 HttpAddText("<div class='line'>\r\n");
andrewboyson 77:4689596a2f3f 209 HttpAddF (" <div>%s</div>\r\n", label);
andrewboyson 77:4689596a2f3f 210 HttpAddF (" <div><span id='%s'></span>%s</div>\r\n", id, suffix);
andrewboyson 57:8fa31ff4e773 211 HttpAddText("</div>\r\n");
andrewboyson 57:8fa31ff4e773 212 }
andrewboyson 0:f8998d10763e 213
andrewboyson 0:f8998d10763e 214