| 1 | /* |
|---|
| 2 | * dd-wrt.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2005 - 2007 Sebastian Gottschall <sebastian.gottschall@blueline-ag.de> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of the GNU General Public License |
|---|
| 8 | * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | * of the License, or (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | * |
|---|
| 20 | * $Id: |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include <stdio.h> |
|---|
| 24 | #include <stdlib.h> |
|---|
| 25 | #include <string.h> |
|---|
| 26 | #include <unistd.h> |
|---|
| 27 | #include <ctype.h> |
|---|
| 28 | #include <signal.h> |
|---|
| 29 | |
|---|
| 30 | #include <sys/ioctl.h> |
|---|
| 31 | #include <sys/types.h> |
|---|
| 32 | #include <sys/stat.h> |
|---|
| 33 | #include <sys/socket.h> |
|---|
| 34 | #include <sys/statfs.h> |
|---|
| 35 | #include <netinet/in.h> |
|---|
| 36 | #include <arpa/inet.h> |
|---|
| 37 | #include <broadcom.h> |
|---|
| 38 | #include <cymac.h> |
|---|
| 39 | #include <wlutils.h> |
|---|
| 40 | #include <bcmparams.h> |
|---|
| 41 | #include <dirent.h> |
|---|
| 42 | #include <netdb.h> |
|---|
| 43 | #include <utils.h> |
|---|
| 44 | #include <bcmnvram.h> |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | static unsigned int oldclocks[9] = |
|---|
| 49 | { 192, 200, 216, 228, 240, 252, 264, 280, 300 }; |
|---|
| 50 | static unsigned int newclocks[9] = |
|---|
| 51 | { 183, 187, 198, 200, 216, 225, 233, 237, 250 }; |
|---|
| 52 | |
|---|
| 53 | void |
|---|
| 54 | show_ipnetmask (webs_t wp, char *var) |
|---|
| 55 | { |
|---|
| 56 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 57 | websWrite (wp, |
|---|
| 58 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n"); |
|---|
| 59 | |
|---|
| 60 | char ip[32]; |
|---|
| 61 | sprintf (ip, "%s_ipaddr", var); |
|---|
| 62 | char *ipv = nvram_safe_get (ip); |
|---|
| 63 | websWrite (wp, |
|---|
| 64 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,1,223,share.ip)\" name=\"%s_ipaddr_0\" value=\"%d\" />.", |
|---|
| 65 | var, get_single_ip (ipv, 0)); |
|---|
| 66 | websWrite (wp, |
|---|
| 67 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_1\" value=\"%d\" />.", |
|---|
| 68 | var, get_single_ip (ipv, 1)); |
|---|
| 69 | websWrite (wp, |
|---|
| 70 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_2\" value=\"%d\" />.", |
|---|
| 71 | var, get_single_ip (ipv, 2)); |
|---|
| 72 | websWrite (wp, |
|---|
| 73 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_3\" value=\"%d\" />\n", |
|---|
| 74 | var, get_single_ip (ipv, 3)); |
|---|
| 75 | websWrite (wp, "</div>\n"); |
|---|
| 76 | |
|---|
| 77 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 78 | websWrite (wp, |
|---|
| 79 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n"); |
|---|
| 80 | sprintf (ip, "%s_netmask", var); |
|---|
| 81 | ipv = nvram_safe_get (ip); |
|---|
| 82 | |
|---|
| 83 | websWrite (wp, |
|---|
| 84 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_0\" value=\"%d\" />.", |
|---|
| 85 | var, get_single_ip (ipv, 0)); |
|---|
| 86 | websWrite (wp, |
|---|
| 87 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_1\" value=\"%d\" />.", |
|---|
| 88 | var, get_single_ip (ipv, 1)); |
|---|
| 89 | websWrite (wp, |
|---|
| 90 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_2\" value=\"%d\" />.", |
|---|
| 91 | var, get_single_ip (ipv, 2)); |
|---|
| 92 | websWrite (wp, |
|---|
| 93 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_3\" value=\"%d\" />", |
|---|
| 94 | var, get_single_ip (ipv, 3)); |
|---|
| 95 | websWrite (wp, "</div>\n<br />\n"); |
|---|
| 96 | |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | void |
|---|
| 100 | ej_show_clocks (webs_t wp, int argc, char_t ** argv) |
|---|
| 101 | { |
|---|
| 102 | int tab = getcpurev (); |
|---|
| 103 | unsigned int *c; |
|---|
| 104 | |
|---|
| 105 | if (tab == 7) |
|---|
| 106 | c = oldclocks; |
|---|
| 107 | else if (tab == 8) |
|---|
| 108 | c = newclocks; |
|---|
| 109 | else |
|---|
| 110 | { |
|---|
| 111 | websWrite (wp, |
|---|
| 112 | "<script type=\"text/javascript\">Capture(management.clock_support)</script>\n</div>\n"); |
|---|
| 113 | return; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | websWrite (wp, |
|---|
| 117 | "<div class=\"label\"><script type=\"text/javascript\">Capture(management.clock_frq)</script></div>\n"); |
|---|
| 118 | websWrite (wp, "<select name=\"overclocking\">\n"); |
|---|
| 119 | int i; |
|---|
| 120 | for (i = 0; i < 9; i++) |
|---|
| 121 | { |
|---|
| 122 | char clock[16]; |
|---|
| 123 | sprintf (clock, "%d", c[i]); |
|---|
| 124 | websWrite (wp, "<option value=\"%d\" %s >%d MHz</option>\n", c[i], |
|---|
| 125 | nvram_match ("overclocking", |
|---|
| 126 | clock) ? "selected=\"selected\"" : "", c[i]); |
|---|
| 127 | |
|---|
| 128 | } |
|---|
| 129 | websWrite (wp, "</select>\n</div>\n"); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | void |
|---|
| 133 | ej_show_routing (webs_t wp, int argc, char_t ** argv) |
|---|
| 134 | { |
|---|
| 135 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 136 | websWrite (wp, |
|---|
| 137 | "document.write(\"<option value=\\\"gateway\\\" %s >\" + share.gateway + \"</option>\");\n", |
|---|
| 138 | nvram_selmatch (wp, "wk_mode", |
|---|
| 139 | "gateway") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 140 | #ifdef HAVE_BIRD |
|---|
| 141 | websWrite (wp, |
|---|
| 142 | "document.write(\"<option value=\\\"bgp\\\" %s >BGP</option>\");\n", |
|---|
| 143 | nvram_selmatch (wp, "wk_mode", |
|---|
| 144 | "bgp") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 145 | websWrite (wp, |
|---|
| 146 | "document.write(\"<option value=\\\"router\\\" %s >\" + route.rip2_mod + \"</option>\");\n", |
|---|
| 147 | nvram_selmatch (wp, "wk_mode", |
|---|
| 148 | "router") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 149 | #endif |
|---|
| 150 | #ifdef HAVE_QUAGGA |
|---|
| 151 | websWrite (wp, |
|---|
| 152 | "document.write(\"<option value=\\\"bgp\\\" %s >BGP</option>\");\n", |
|---|
| 153 | nvram_selmatch (wp, "wk_mode", |
|---|
| 154 | "bgp") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 155 | websWrite (wp, |
|---|
| 156 | "document.write(\"<option value=\\\"router\\\" %s >\" + route.rip2_mod + \"</option>\");\n", |
|---|
| 157 | nvram_selmatch (wp, "wk_mode", |
|---|
| 158 | "router") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 159 | websWrite (wp, |
|---|
| 160 | "document.write(\"<option value=\\\"ospf\\\" %s >\" + route.ospf_mod + \"</option>\");\n", |
|---|
| 161 | nvram_selmatch (wp, "wk_mode", |
|---|
| 162 | "ospf") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 163 | #endif |
|---|
| 164 | #ifdef HAVE_OLSRD |
|---|
| 165 | websWrite (wp, |
|---|
| 166 | "document.write(\"<option value=\\\"olsr\\\" %s >\" + route.olsrd_mod + \"</option>\");\n", |
|---|
| 167 | nvram_selmatch (wp, "wk_mode", |
|---|
| 168 | "olsr") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 169 | #endif |
|---|
| 170 | websWrite (wp, |
|---|
| 171 | "document.write(\"<option value=\\\"static\\\" %s >\" + share.router + \"</option>\");\n", |
|---|
| 172 | nvram_selmatch (wp, "wk_mode", |
|---|
| 173 | "static") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 174 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 175 | return; |
|---|
| 176 | |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | void |
|---|
| 180 | ej_show_connectiontype (webs_t wp, int argc, char_t ** argv) |
|---|
| 181 | { |
|---|
| 182 | |
|---|
| 183 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 184 | websWrite (wp, |
|---|
| 185 | "document.write(\"<option value=\\\"disabled\\\" %s >\" + share.disabled + \"</option>\");\n", |
|---|
| 186 | nvram_selmatch (wp, "wan_proto", |
|---|
| 187 | "disabled") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 188 | websWrite (wp, |
|---|
| 189 | "document.write(\"<option value=\\\"static\\\" %s >\" + idx.static_ip + \"</option>\");\n", |
|---|
| 190 | nvram_selmatch (wp, "wan_proto", |
|---|
| 191 | "static") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 192 | websWrite (wp, |
|---|
| 193 | "document.write(\"<option value=\\\"dhcp\\\" %s >\" + idx.dhcp + \"</option>\");\n", |
|---|
| 194 | nvram_selmatch (wp, "wan_proto", |
|---|
| 195 | "dhcp") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 196 | websWrite (wp, "\n//]]>\n</script>\n"); |
|---|
| 197 | |
|---|
| 198 | #ifdef HAVE_PPPOE |
|---|
| 199 | websWrite (wp, "<option value=\"pppoe\" %s >PPPoE</option>\n", |
|---|
| 200 | nvram_selmatch (wp, "wan_proto", |
|---|
| 201 | "pppoe") ? "selected=\"selected\"" : ""); |
|---|
| 202 | #endif |
|---|
| 203 | #ifdef HAVE_PPTP |
|---|
| 204 | websWrite (wp, "<option value=\"pptp\" %s >PPTP</option>\n", |
|---|
| 205 | nvram_selmatch (wp, "wan_proto", |
|---|
| 206 | "pptp") ? "selected=\"selected\"" : ""); |
|---|
| 207 | #endif |
|---|
| 208 | #ifdef HAVE_L2TP |
|---|
| 209 | websWrite (wp, "<option value=\"l2tp\" %s >L2TP</option>\n", |
|---|
| 210 | nvram_selmatch (wp, "wan_proto", |
|---|
| 211 | "l2tp") ? "selected=\"selected\"" : ""); |
|---|
| 212 | #endif |
|---|
| 213 | #ifdef HAVE_HEARTBEAT |
|---|
| 214 | websWrite (wp, |
|---|
| 215 | "<option value=\"heartbeat\" %s >HeartBeat Signal</option>\n", |
|---|
| 216 | nvram_selmatch (wp, "wan_proto", |
|---|
| 217 | "heartbeat") ? "selected=\"selected\"" : ""); |
|---|
| 218 | #endif |
|---|
| 219 | |
|---|
| 220 | return; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | void |
|---|
| 224 | ej_show_infopage (webs_t wp, int argc, char_t ** argv) |
|---|
| 225 | { |
|---|
| 226 | /* |
|---|
| 227 | #ifdef HAVE_NEWMEDIA |
|---|
| 228 | websWrite(wp,"<dl>\n"); |
|---|
| 229 | websWrite(wp,"<dd class=\"definition\">GGEW net GmbH</dd>\n"); |
|---|
| 230 | websWrite(wp,"<dd class=\"definition\">Dammstrasse 68</dd>\n"); |
|---|
| 231 | websWrite(wp,"<dd class=\"definition\">64625 Bensheim</dd>\n"); |
|---|
| 232 | websWrite(wp,"<dd class=\"definition\"><a href=\"http://ggew-net.de\"><img src=\"images/ggewlogo.gif\" border=\"0\"/></a></dd>\n"); |
|---|
| 233 | websWrite(wp,"<dd class=\"definition\"> </dd>\n"); |
|---|
| 234 | websWrite(wp,"<dd class=\"definition\"><a href=\"http://ggew-net.de\"/></dd>\n"); |
|---|
| 235 | websWrite(wp,"<dd class=\"definition\"> </dd>\n"); |
|---|
| 236 | websWrite(wp,"<dd class=\"definition\">In Kooperation mit NewMedia-NET GmbH</dd>\n"); |
|---|
| 237 | websWrite(wp,"<dd class=\"definition\"><a href=\"http://www.newmedia-net.de\"/></dd>\n"); |
|---|
| 238 | websWrite(wp,"</dl>\n"); |
|---|
| 239 | #endif*/ |
|---|
| 240 | return; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | void |
|---|
| 245 | ej_dumpmeminfo (webs_t wp, int argc, char_t ** argv) |
|---|
| 246 | { |
|---|
| 247 | FILE *fcpu = fopen ("/proc/meminfo", "r"); |
|---|
| 248 | if (fcpu == NULL) |
|---|
| 249 | { |
|---|
| 250 | return; |
|---|
| 251 | } |
|---|
| 252 | char buf[128]; |
|---|
| 253 | int n = 0; |
|---|
| 254 | rept:; |
|---|
| 255 | if (n == EOF) |
|---|
| 256 | { |
|---|
| 257 | fclose (fcpu); |
|---|
| 258 | return; |
|---|
| 259 | } |
|---|
| 260 | if (n) |
|---|
| 261 | websWrite (wp, "'%s'", buf); |
|---|
| 262 | n = fscanf (fcpu, "%s", buf); |
|---|
| 263 | if (n != EOF) |
|---|
| 264 | websWrite (wp, ","); |
|---|
| 265 | goto rept; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | #ifdef HAVE_RB500 |
|---|
| 269 | void |
|---|
| 270 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 271 | { |
|---|
| 272 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 273 | if (fp == NULL) |
|---|
| 274 | { |
|---|
| 275 | websWrite (wp, "unknown"); |
|---|
| 276 | return; |
|---|
| 277 | } |
|---|
| 278 | int cnt = 0; |
|---|
| 279 | int b = 0; |
|---|
| 280 | while (b != EOF) |
|---|
| 281 | { |
|---|
| 282 | b = getc (fp); |
|---|
| 283 | if (b == ':') |
|---|
| 284 | cnt++; |
|---|
| 285 | |
|---|
| 286 | if (cnt == 4) |
|---|
| 287 | { |
|---|
| 288 | getc (fp); |
|---|
| 289 | char cpuclk[4]; |
|---|
| 290 | cpuclk[0] = getc (fp); |
|---|
| 291 | cpuclk[1] = getc (fp); |
|---|
| 292 | cpuclk[2] = getc (fp); |
|---|
| 293 | cpuclk[3] = 0; |
|---|
| 294 | websWrite (wp, cpuclk); |
|---|
| 295 | fclose (fp); |
|---|
| 296 | return; |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | fclose (fp); |
|---|
| 301 | websWrite (wp, "unknown"); |
|---|
| 302 | return; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | #elif HAVE_XSCALE |
|---|
| 306 | void |
|---|
| 307 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 308 | { |
|---|
| 309 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 310 | if (fp == NULL) |
|---|
| 311 | { |
|---|
| 312 | websWrite (wp, "unknown"); |
|---|
| 313 | return; |
|---|
| 314 | } |
|---|
| 315 | int cnt = 0; |
|---|
| 316 | int b = 0; |
|---|
| 317 | while (b != EOF) |
|---|
| 318 | { |
|---|
| 319 | b = getc (fp); |
|---|
| 320 | if (b == ':') |
|---|
| 321 | cnt++; |
|---|
| 322 | if (cnt == 2) |
|---|
| 323 | { |
|---|
| 324 | getc (fp); |
|---|
| 325 | char cpuclk[4]; |
|---|
| 326 | cpuclk[0] = getc (fp); |
|---|
| 327 | cpuclk[1] = getc (fp); |
|---|
| 328 | cpuclk[2] = getc (fp); |
|---|
| 329 | cpuclk[3] = 0; |
|---|
| 330 | websWrite (wp, cpuclk); |
|---|
| 331 | fclose (fp); |
|---|
| 332 | return; |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | fclose (fp); |
|---|
| 337 | websWrite (wp, "unknown"); |
|---|
| 338 | return; |
|---|
| 339 | } |
|---|
| 340 | #elif HAVE_X86 |
|---|
| 341 | void |
|---|
| 342 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 343 | { |
|---|
| 344 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 345 | if (fp == NULL) |
|---|
| 346 | { |
|---|
| 347 | websWrite (wp, "unknown"); |
|---|
| 348 | return; |
|---|
| 349 | } |
|---|
| 350 | int cnt = 0; |
|---|
| 351 | int b = 0; |
|---|
| 352 | while (b != EOF) |
|---|
| 353 | { |
|---|
| 354 | b = getc (fp); |
|---|
| 355 | if (b == ':') |
|---|
| 356 | cnt++; |
|---|
| 357 | if (cnt == 7) |
|---|
| 358 | { |
|---|
| 359 | getc (fp); |
|---|
| 360 | char cpuclk[32]; |
|---|
| 361 | int i = 0; |
|---|
| 362 | b = getc (fp); |
|---|
| 363 | while (b != 0xa && b != 0xd && b != 0x20) |
|---|
| 364 | { |
|---|
| 365 | cpuclk[i++] = b; |
|---|
| 366 | b = getc (fp); |
|---|
| 367 | } |
|---|
| 368 | cpuclk[i++] = 0; |
|---|
| 369 | websWrite (wp, cpuclk); |
|---|
| 370 | fclose (fp); |
|---|
| 371 | return; |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | fclose (fp); |
|---|
| 376 | websWrite (wp, "unknown"); |
|---|
| 377 | return; |
|---|
| 378 | } |
|---|
| 379 | #elif HAVE_MAGICBOX |
|---|
| 380 | void |
|---|
| 381 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 382 | { |
|---|
| 383 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 384 | if (fp == NULL) |
|---|
| 385 | { |
|---|
| 386 | websWrite (wp, "unknown"); |
|---|
| 387 | return; |
|---|
| 388 | } |
|---|
| 389 | int cnt = 0; |
|---|
| 390 | int b = 0; |
|---|
| 391 | while (b != EOF) |
|---|
| 392 | { |
|---|
| 393 | b = getc (fp); |
|---|
| 394 | if (b == ':') |
|---|
| 395 | cnt++; |
|---|
| 396 | if (cnt == 3) |
|---|
| 397 | { |
|---|
| 398 | getc (fp); |
|---|
| 399 | char cpuclk[4]; |
|---|
| 400 | cpuclk[0] = getc (fp); |
|---|
| 401 | cpuclk[1] = getc (fp); |
|---|
| 402 | cpuclk[2] = getc (fp); |
|---|
| 403 | cpuclk[3] = 0; |
|---|
| 404 | websWrite (wp, cpuclk); |
|---|
| 405 | fclose (fp); |
|---|
| 406 | return; |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | fclose (fp); |
|---|
| 411 | websWrite (wp, "unknown"); |
|---|
| 412 | return; |
|---|
| 413 | } |
|---|
| 414 | #elif HAVE_FONERA |
|---|
| 415 | void |
|---|
| 416 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 417 | { |
|---|
| 418 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 419 | if (fp == NULL) |
|---|
| 420 | { |
|---|
| 421 | websWrite (wp, "unknown"); |
|---|
| 422 | return; |
|---|
| 423 | } |
|---|
| 424 | int cnt = 0; |
|---|
| 425 | int b = 0; |
|---|
| 426 | while (b != EOF) |
|---|
| 427 | { |
|---|
| 428 | b = getc (fp); |
|---|
| 429 | if (b == ':') |
|---|
| 430 | cnt++; |
|---|
| 431 | if (cnt == 4) |
|---|
| 432 | { |
|---|
| 433 | getc (fp); |
|---|
| 434 | char cpuclk[4]; |
|---|
| 435 | cpuclk[0] = getc (fp); |
|---|
| 436 | cpuclk[1] = getc (fp); |
|---|
| 437 | cpuclk[2] = getc (fp); |
|---|
| 438 | cpuclk[3] = 0; |
|---|
| 439 | websWrite (wp, cpuclk); |
|---|
| 440 | fclose (fp); |
|---|
| 441 | return; |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | fclose (fp); |
|---|
| 446 | websWrite (wp, "unknown"); |
|---|
| 447 | return; |
|---|
| 448 | } |
|---|
| 449 | #elif HAVE_MERAKI |
|---|
| 450 | void |
|---|
| 451 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 452 | { |
|---|
| 453 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 454 | if (fp == NULL) |
|---|
| 455 | { |
|---|
| 456 | websWrite (wp, "unknown"); |
|---|
| 457 | return; |
|---|
| 458 | } |
|---|
| 459 | int cnt = 0; |
|---|
| 460 | int b = 0; |
|---|
| 461 | while (b != EOF) |
|---|
| 462 | { |
|---|
| 463 | b = getc (fp); |
|---|
| 464 | if (b == ':') |
|---|
| 465 | cnt++; |
|---|
| 466 | if (cnt == 4) |
|---|
| 467 | { |
|---|
| 468 | getc (fp); |
|---|
| 469 | char cpuclk[4]; |
|---|
| 470 | cpuclk[0] = getc (fp); |
|---|
| 471 | cpuclk[1] = getc (fp); |
|---|
| 472 | cpuclk[2] = getc (fp); |
|---|
| 473 | cpuclk[3] = 0; |
|---|
| 474 | websWrite (wp, cpuclk); |
|---|
| 475 | fclose (fp); |
|---|
| 476 | return; |
|---|
| 477 | } |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | fclose (fp); |
|---|
| 481 | websWrite (wp, "unknown"); |
|---|
| 482 | return; |
|---|
| 483 | } |
|---|
| 484 | #elif HAVE_LS2 |
|---|
| 485 | void |
|---|
| 486 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 487 | { |
|---|
| 488 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 489 | if (fp == NULL) |
|---|
| 490 | { |
|---|
| 491 | websWrite (wp, "unknown"); |
|---|
| 492 | return; |
|---|
| 493 | } |
|---|
| 494 | int cnt = 0; |
|---|
| 495 | int b = 0; |
|---|
| 496 | while (b != EOF) |
|---|
| 497 | { |
|---|
| 498 | b = getc (fp); |
|---|
| 499 | if (b == ':') |
|---|
| 500 | cnt++; |
|---|
| 501 | if (cnt == 4) |
|---|
| 502 | { |
|---|
| 503 | getc (fp); |
|---|
| 504 | char cpuclk[4]; |
|---|
| 505 | cpuclk[0] = getc (fp); |
|---|
| 506 | cpuclk[1] = getc (fp); |
|---|
| 507 | cpuclk[2] = getc (fp); |
|---|
| 508 | cpuclk[3] = 0; |
|---|
| 509 | websWrite (wp, cpuclk); |
|---|
| 510 | fclose (fp); |
|---|
| 511 | return; |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | fclose (fp); |
|---|
| 516 | websWrite (wp, "unknown"); |
|---|
| 517 | return; |
|---|
| 518 | } |
|---|
| 519 | #elif HAVE_WHRAG108 |
|---|
| 520 | void |
|---|
| 521 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 522 | { |
|---|
| 523 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 524 | if (fp == NULL) |
|---|
| 525 | { |
|---|
| 526 | websWrite (wp, "unknown"); |
|---|
| 527 | return; |
|---|
| 528 | } |
|---|
| 529 | int cnt = 0; |
|---|
| 530 | int b = 0; |
|---|
| 531 | while (b != EOF) |
|---|
| 532 | { |
|---|
| 533 | b = getc (fp); |
|---|
| 534 | if (b == ':') |
|---|
| 535 | cnt++; |
|---|
| 536 | if (cnt == 4) |
|---|
| 537 | { |
|---|
| 538 | getc (fp); |
|---|
| 539 | char cpuclk[4]; |
|---|
| 540 | cpuclk[0] = getc (fp); |
|---|
| 541 | cpuclk[1] = getc (fp); |
|---|
| 542 | cpuclk[2] = getc (fp); |
|---|
| 543 | cpuclk[3] = 0; |
|---|
| 544 | websWrite (wp, cpuclk); |
|---|
| 545 | fclose (fp); |
|---|
| 546 | return; |
|---|
| 547 | } |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | fclose (fp); |
|---|
| 551 | websWrite (wp, "unknown"); |
|---|
| 552 | return; |
|---|
| 553 | } |
|---|
| 554 | #elif HAVE_CA8 |
|---|
| 555 | void |
|---|
| 556 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 557 | { |
|---|
| 558 | FILE *fp = fopen ("/proc/cpuinfo", "rb"); |
|---|
| 559 | if (fp == NULL) |
|---|
| 560 | { |
|---|
| 561 | websWrite (wp, "unknown"); |
|---|
| 562 | return; |
|---|
| 563 | } |
|---|
| 564 | int cnt = 0; |
|---|
| 565 | int b = 0; |
|---|
| 566 | while (b != EOF) |
|---|
| 567 | { |
|---|
| 568 | b = getc (fp); |
|---|
| 569 | if (b == ':') |
|---|
| 570 | cnt++; |
|---|
| 571 | if (cnt == 4) |
|---|
| 572 | { |
|---|
| 573 | getc (fp); |
|---|
| 574 | char cpuclk[4]; |
|---|
| 575 | cpuclk[0] = getc (fp); |
|---|
| 576 | cpuclk[1] = getc (fp); |
|---|
| 577 | cpuclk[2] = getc (fp); |
|---|
| 578 | cpuclk[3] = 0; |
|---|
| 579 | websWrite (wp, cpuclk); |
|---|
| 580 | fclose (fp); |
|---|
| 581 | return; |
|---|
| 582 | } |
|---|
| 583 | } |
|---|
| 584 | |
|---|
| 585 | fclose (fp); |
|---|
| 586 | websWrite (wp, "unknown"); |
|---|
| 587 | return; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | #else |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | void |
|---|
| 594 | ej_get_clkfreq (webs_t wp, int argc, char_t ** argv) |
|---|
| 595 | { |
|---|
| 596 | char *clk = nvram_get ("clkfreq"); |
|---|
| 597 | if (clk == NULL) |
|---|
| 598 | { |
|---|
| 599 | websWrite (wp, "125"); |
|---|
| 600 | return; |
|---|
| 601 | } |
|---|
| 602 | char buf[64]; |
|---|
| 603 | strcpy (buf, clk); |
|---|
| 604 | int i = 0; |
|---|
| 605 | while (buf[i++] != 0) |
|---|
| 606 | { |
|---|
| 607 | if (buf[i] == ',') |
|---|
| 608 | buf[i] = 0; |
|---|
| 609 | } |
|---|
| 610 | websWrite (wp, buf); |
|---|
| 611 | return; |
|---|
| 612 | } |
|---|
| 613 | #endif |
|---|
| 614 | |
|---|
| 615 | void |
|---|
| 616 | ej_show_cpuinfo (webs_t wp, int argc, char_t ** argv) |
|---|
| 617 | { |
|---|
| 618 | FILE *fcpu = fopen ("/proc/cpuinfo", "r"); |
|---|
| 619 | if (fcpu == NULL) |
|---|
| 620 | { |
|---|
| 621 | websWrite (wp, "Not Detected!\n"); |
|---|
| 622 | return; |
|---|
| 623 | } |
|---|
| 624 | char buf[256]; |
|---|
| 625 | int i; |
|---|
| 626 | #ifdef HAVE_MAGICBOX |
|---|
| 627 | int cnt = 0; |
|---|
| 628 | #endif |
|---|
| 629 | #ifdef HAVE_X86 |
|---|
| 630 | int cnt = 0; |
|---|
| 631 | #endif |
|---|
| 632 | for (i = 0; i < 256; i++) |
|---|
| 633 | { |
|---|
| 634 | int c = getc (fcpu); |
|---|
| 635 | if (c == EOF) |
|---|
| 636 | { |
|---|
| 637 | websWrite (wp, "Not Detected!\n"); |
|---|
| 638 | fclose (fcpu); |
|---|
| 639 | return; |
|---|
| 640 | } |
|---|
| 641 | if (c == ':') |
|---|
| 642 | #ifdef HAVE_MAGICBOX |
|---|
| 643 | cnt++; |
|---|
| 644 | if (cnt == 2) |
|---|
| 645 | break; |
|---|
| 646 | #elif HAVE_X86 |
|---|
| 647 | cnt++; |
|---|
| 648 | if (cnt == 5) |
|---|
| 649 | break; |
|---|
| 650 | #else |
|---|
| 651 | break; |
|---|
| 652 | #endif |
|---|
| 653 | } |
|---|
| 654 | getc (fcpu); |
|---|
| 655 | for (i = 0; i < 256; i++) |
|---|
| 656 | { |
|---|
| 657 | int c = getc (fcpu); |
|---|
| 658 | if (c == EOF) |
|---|
| 659 | { |
|---|
| 660 | websWrite (wp, "Not Detected!\n"); |
|---|
| 661 | fclose (fcpu); |
|---|
| 662 | return; |
|---|
| 663 | } |
|---|
| 664 | if (c == 0xa || c == 0xd) |
|---|
| 665 | break; |
|---|
| 666 | buf[i] = c; |
|---|
| 667 | } |
|---|
| 668 | buf[i] = 0; |
|---|
| 669 | websWrite (wp, buf); |
|---|
| 670 | fclose (fcpu); |
|---|
| 671 | return; |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | #define ASSOCLIST_TMP "/tmp/.wl_assoclist" |
|---|
| 675 | #define RSSI_TMP "/tmp/.rssi" |
|---|
| 676 | #define ASSOCLIST_CMD "wl assoclist" |
|---|
| 677 | #define RSSI_CMD "wl rssi" |
|---|
| 678 | #define NOISE_CMD "wl noise" |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | void |
|---|
| 682 | ej_show_wds_subnet (webs_t wp, int argc, char_t ** argv) |
|---|
| 683 | { |
|---|
| 684 | int index = -1; |
|---|
| 685 | #ifdef HAVE_MADWIFI |
|---|
| 686 | char *interface; |
|---|
| 687 | if (ejArgs (argc, argv, "%d %s", &index, &interface) < 2) |
|---|
| 688 | { |
|---|
| 689 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 690 | return; |
|---|
| 691 | } |
|---|
| 692 | #else |
|---|
| 693 | char *interface = "wl"; |
|---|
| 694 | if (ejArgs (argc, argv, "%d", &index) < 1) |
|---|
| 695 | { |
|---|
| 696 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 697 | return; |
|---|
| 698 | } |
|---|
| 699 | #endif |
|---|
| 700 | char br1[32]; |
|---|
| 701 | sprintf (br1, "%s_br1_enable", interface); |
|---|
| 702 | if (nvram_invmatch (br1, "1")) |
|---|
| 703 | return; |
|---|
| 704 | char buf[16]; |
|---|
| 705 | sprintf (buf, "%s_wds%d_enable", interface, index); |
|---|
| 706 | websWrite (wp, |
|---|
| 707 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"2\\\" %s >\" + wds.subnet + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 708 | nvram_selmatch (wp, buf, |
|---|
| 709 | "2") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 710 | return; |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | #ifdef HAVE_SKYTRON |
|---|
| 716 | void |
|---|
| 717 | ej_active_wireless2 (webs_t wp, int argc, char_t ** argv) |
|---|
| 718 | { |
|---|
| 719 | int rssi = 0, noise = 0; |
|---|
| 720 | FILE *fp, *fp2; |
|---|
| 721 | char *mode; |
|---|
| 722 | char mac[30]; |
|---|
| 723 | char list[2][30]; |
|---|
| 724 | char line[80]; |
|---|
| 725 | char cmd[80]; |
|---|
| 726 | |
|---|
| 727 | unlink (ASSOCLIST_TMP); |
|---|
| 728 | unlink (RSSI_TMP); |
|---|
| 729 | |
|---|
| 730 | mode = nvram_safe_get ("wl_mode"); |
|---|
| 731 | snprintf (cmd, sizeof (cmd), "%s > %s", ASSOCLIST_CMD, ASSOCLIST_TMP); |
|---|
| 732 | system2 (cmd); // get active wireless mac |
|---|
| 733 | |
|---|
| 734 | int connected = 0; |
|---|
| 735 | if ((fp = fopen (ASSOCLIST_TMP, "r"))) |
|---|
| 736 | { |
|---|
| 737 | while (fgets (line, sizeof (line), fp) != NULL) |
|---|
| 738 | { |
|---|
| 739 | if (sscanf (line, "%s %s", list[0], mac) != 2) // assoclist 00:11:22:33:44:55 |
|---|
| 740 | continue; |
|---|
| 741 | |
|---|
| 742 | if (strcmp (list[0], "assoclist")) |
|---|
| 743 | break; |
|---|
| 744 | |
|---|
| 745 | rssi = 0; |
|---|
| 746 | noise = 0; |
|---|
| 747 | // get rssi value |
|---|
| 748 | if (strcmp (mode, "ap")) |
|---|
| 749 | snprintf (cmd, sizeof (cmd), "%s > %s", RSSI_CMD, RSSI_TMP); |
|---|
| 750 | else |
|---|
| 751 | snprintf (cmd, sizeof (cmd), "%s \"%s\" > %s", RSSI_CMD, mac, |
|---|
| 752 | RSSI_TMP); |
|---|
| 753 | system2 (cmd); |
|---|
| 754 | |
|---|
| 755 | // get noise value if not ap mode |
|---|
| 756 | if (strcmp (mode, "ap")) |
|---|
| 757 | snprintf (cmd, sizeof (cmd), "%s >> %s", NOISE_CMD, RSSI_TMP); |
|---|
| 758 | |
|---|
| 759 | system2 (cmd); // get RSSI value for mac |
|---|
| 760 | |
|---|
| 761 | fp2 = fopen (RSSI_TMP, "r"); |
|---|
| 762 | if (fgets (line, sizeof (line), fp2) != NULL) |
|---|
| 763 | { |
|---|
| 764 | |
|---|
| 765 | // get rssi |
|---|
| 766 | if (sscanf (line, "%s %s %d", list[0], list[1], &rssi) != 3) |
|---|
| 767 | continue; |
|---|
| 768 | |
|---|
| 769 | // get noise for client/wet mode |
|---|
| 770 | if (strcmp (mode, "ap") && |
|---|
| 771 | fgets (line, sizeof (line), fp2) != NULL && |
|---|
| 772 | sscanf (line, "%s %s %d", list[0], list[1], &noise) != 3) |
|---|
| 773 | continue; |
|---|
| 774 | |
|---|
| 775 | fclose (fp2); |
|---|
| 776 | } |
|---|
| 777 | if (nvram_match ("maskmac", "1")) |
|---|
| 778 | { |
|---|
| 779 | mac[0] = 'x'; |
|---|
| 780 | mac[1] = 'x'; |
|---|
| 781 | mac[3] = 'x'; |
|---|
| 782 | mac[4] = 'x'; |
|---|
| 783 | mac[6] = 'x'; |
|---|
| 784 | mac[7] = 'x'; |
|---|
| 785 | mac[9] = 'x'; |
|---|
| 786 | mac[10] = 'x'; |
|---|
| 787 | } |
|---|
| 788 | if (strcmp (mode, "ap") != 0) |
|---|
| 789 | { |
|---|
| 790 | connected = 1; |
|---|
| 791 | websWrite (wp, "<tr>\n"); |
|---|
| 792 | websWrite (wp, |
|---|
| 793 | "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\"><b>Verbindungsstatus</b></font></td>\n"); |
|---|
| 794 | websWrite (wp, "<td bgcolor=\"#B2B2B2\"></td>\n"); |
|---|
| 795 | websWrite (wp, "<td bgcolor=\"#FFFFFF\"></td>\n"); |
|---|
| 796 | websWrite (wp, |
|---|
| 797 | "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Verbunden</font></td>\n"); |
|---|
| 798 | websWrite (wp, "</tr>\n"); |
|---|
| 799 | websWrite (wp, "<tr>\n"); |
|---|
| 800 | websWrite (wp, |
|---|
| 801 | "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Signal</font></td>\n"); |
|---|
| 802 | websWrite (wp, "<td bgcolor=\"#B2B2B2\"></td>\n"); |
|---|
| 803 | websWrite (wp, "<td bgcolor=\"#FFFFFF\"></td>\n"); |
|---|
| 804 | websWrite (wp, |
|---|
| 805 | "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">%d dBm</font></td>\n", |
|---|
| 806 | rssi); |
|---|
| 807 | websWrite (wp, "</tr>\n"); |
|---|
| 808 | websWrite (wp, "<tr>\n"); |
|---|
| 809 | websWrite (wp, |
|---|
| 810 | "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Rauschen</font></td>\n"); |
|---|
| 811 | websWrite (wp, "<td bgcolor=\"#B2B2B2\"></td>\n"); |
|---|
| 812 | websWrite (wp, "<td bgcolor=\"#FFFFFF\"></td>\n"); |
|---|
| 813 | websWrite (wp, |
|---|
| 814 | "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">%d dBm</font></td>\n", |
|---|
| 815 | noise); |
|---|
| 816 | websWrite (wp, "</tr>\n"); |
|---|
| 817 | } |
|---|
| 818 | } |
|---|
| 819 | } |
|---|
| 820 | |
|---|
| 821 | unlink (ASSOCLIST_TMP); |
|---|
| 822 | unlink (RSSI_TMP); |
|---|
| 823 | if (!connected) |
|---|
| 824 | { |
|---|
| 825 | connected = 1; |
|---|
| 826 | websWrite (wp, "<tr>\n"); |
|---|
| 827 | websWrite (wp, |
|---|
| 828 | "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\"><b>Verbindungsstatus</b></font></td>\n"); |
|---|
| 829 | websWrite (wp, "<td bgcolor=\"#B2B2B2\"></td>\n"); |
|---|
| 830 | websWrite (wp, "<td bgcolor=\"#FFFFFF\"></td>\n"); |
|---|
| 831 | websWrite (wp, |
|---|
| 832 | "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Nicht Verbunden</font></td>\n"); |
|---|
| 833 | websWrite (wp, "</tr>\n"); |
|---|
| 834 | |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | return 0; |
|---|
| 838 | } |
|---|
| 839 | #endif |
|---|
| 840 | |
|---|
| 841 | |
|---|
| 842 | void |
|---|
| 843 | macro_add (char *a) |
|---|
| 844 | { |
|---|
| 845 | cprintf ("adding %s\n", a); |
|---|
| 846 | |
|---|
| 847 | char *count; |
|---|
| 848 | int c; |
|---|
| 849 | char buf[20]; |
|---|
| 850 | count = nvram_safe_get (a); |
|---|
| 851 | cprintf ("count = %s\n", count); |
|---|
| 852 | if (count != NULL && strlen (count) > 0) |
|---|
| 853 | { |
|---|
| 854 | c = atoi (count); |
|---|
| 855 | if (c > -1) |
|---|
| 856 | { |
|---|
| 857 | c++; |
|---|
| 858 | sprintf (buf, "%d", c); |
|---|
| 859 | cprintf ("set %s to %s\n", a, buf); |
|---|
| 860 | nvram_set (a, buf); |
|---|
| 861 | } |
|---|
| 862 | } |
|---|
| 863 | return; |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | void |
|---|
| 867 | macro_rem (char *a, char *nv) |
|---|
| 868 | { |
|---|
| 869 | char *count; |
|---|
| 870 | int c, i, cnt; |
|---|
| 871 | char buf[20]; |
|---|
| 872 | char *buffer, *b; |
|---|
| 873 | cnt = 0; |
|---|
| 874 | count = nvram_safe_get (a); |
|---|
| 875 | if (count != NULL && strlen (count) > 0) |
|---|
| 876 | { |
|---|
| 877 | c = atoi (count); |
|---|
| 878 | if (c > 0) |
|---|
| 879 | { |
|---|
| 880 | c--; |
|---|
| 881 | sprintf (buf, "%d", c); |
|---|
| 882 | nvram_set (a, buf); |
|---|
| 883 | buffer = nvram_safe_get (nv); |
|---|
| 884 | if (buffer != NULL) |
|---|
| 885 | { |
|---|
| 886 | int slen = strlen (buffer); |
|---|
| 887 | b = malloc (slen + 1); |
|---|
| 888 | |
|---|
| 889 | for (i = 0; i < slen; i++) |
|---|
| 890 | { |
|---|
| 891 | if (buffer[i] == ' ') |
|---|
| 892 | cnt++; |
|---|
| 893 | if (cnt == c) |
|---|
| 894 | break; |
|---|
| 895 | b[i] = buffer[i]; |
|---|
| 896 | } |
|---|
| 897 | b[i] = 0; |
|---|
| 898 | nvram_set (nv, b); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | } |
|---|
| 902 | } |
|---|
| 903 | return; |
|---|
| 904 | } |
|---|
| 905 | |
|---|
| 906 | void |
|---|
| 907 | forward_remove (webs_t wp) |
|---|
| 908 | { |
|---|
| 909 | macro_rem ("forward_entries", "forward_port"); |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | void |
|---|
| 913 | forward_add (webs_t wp) |
|---|
| 914 | { |
|---|
| 915 | macro_add ("forward_entries"); |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | void |
|---|
| 919 | lease_remove (webs_t wp) |
|---|
| 920 | { |
|---|
| 921 | macro_rem ("static_leasenum", "static_leases"); |
|---|
| 922 | } |
|---|
| 923 | |
|---|
| 924 | void |
|---|
| 925 | lease_add (webs_t wp) |
|---|
| 926 | { |
|---|
| 927 | macro_add ("static_leasenum"); |
|---|
| 928 | } |
|---|
| 929 | |
|---|
| 930 | #ifdef HAVE_PPPOESERVER |
|---|
| 931 | void |
|---|
| 932 | chap_user_add (webs_t wp) |
|---|
| 933 | { |
|---|
| 934 | char *var = websGetVar (wp, "pppoeserver_enabled", NULL); |
|---|
| 935 | if (var != NULL) |
|---|
| 936 | nvram_set ("pppoeserver_enabled", var); |
|---|
| 937 | macro_add ("pppoeserver_chapsnum"); |
|---|
| 938 | } |
|---|
| 939 | |
|---|
| 940 | void |
|---|
| 941 | chap_user_remove (webs_t wp) |
|---|
| 942 | { |
|---|
| 943 | char *var = websGetVar (wp, "pppoeserver_enabled", NULL); |
|---|
| 944 | if (var != NULL) |
|---|
| 945 | nvram_set ("pppoeserver_enabled", var); |
|---|
| 946 | macro_rem ("pppoeserver_chapsnum", "pppoeserver_chaps"); |
|---|
| 947 | } |
|---|
| 948 | #endif |
|---|
| 949 | |
|---|
| 950 | void |
|---|
| 951 | forwardspec_remove (webs_t wp) |
|---|
| 952 | { |
|---|
| 953 | macro_rem ("forwardspec_entries", "forward_spec"); |
|---|
| 954 | } |
|---|
| 955 | |
|---|
| 956 | void |
|---|
| 957 | forwardspec_add (webs_t wp) |
|---|
| 958 | { |
|---|
| 959 | macro_add ("forwardspec_entries"); |
|---|
| 960 | } |
|---|
| 961 | |
|---|
| 962 | void |
|---|
| 963 | trigger_remove (webs_t wp) |
|---|
| 964 | { |
|---|
| 965 | macro_rem ("trigger_entries", "port_trigger"); |
|---|
| 966 | } |
|---|
| 967 | |
|---|
| 968 | void |
|---|
| 969 | trigger_add (webs_t wp) |
|---|
| 970 | { |
|---|
| 971 | macro_add ("trigger_entries"); |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | void |
|---|
| 975 | ej_show_paypal (webs_t wp, int argc, char_t ** argv) |
|---|
| 976 | { |
|---|
| 977 | #ifndef CONFIG_BRANDING |
|---|
| 978 | websWrite (wp, "<a href=\"http://www.dd-wrt.com/\">DD-WRT</a><br />"); |
|---|
| 979 | websWrite (wp, |
|---|
| 980 | "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" target=\"_blank\">"); |
|---|
| 981 | websWrite (wp, "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\" />"); |
|---|
| 982 | websWrite (wp, |
|---|
| 983 | "<input type=\"hidden\" name=\"business\" value=\"paypal@dd-wrt.com\" />"); |
|---|
| 984 | websWrite (wp, |
|---|
| 985 | "<input type=\"hidden\" name=\"item_name\" value=\"DD-WRT Development Support\" />"); |
|---|
| 986 | websWrite (wp, "<input type=\"hidden\" name=\"no_note\" value=\"1\" />"); |
|---|
| 987 | websWrite (wp, |
|---|
| 988 | "<input type=\"hidden\" name=\"currency_code\" value=\"EUR\" />"); |
|---|
| 989 | websWrite (wp, "<input type=\"hidden\" name=\"lc\" value=\"en\" />"); |
|---|
| 990 | websWrite (wp, "<input type=\"hidden\" name=\"tax\" value=\"0\" />"); |
|---|
| 991 | websWrite (wp, |
|---|
| 992 | "<input type=\"image\" src=\"images/paypal.gif\" name=\"submit\" />"); |
|---|
| 993 | websWrite (wp, "</form>"); |
|---|
| 994 | websWrite (wp, |
|---|
| 995 | "<br /><script type=\"text/javascript\">Capture(donate.mb)</script><br />\n"); |
|---|
| 996 | websWrite (wp, |
|---|
| 997 | "<a href=\"https://www.moneybookers.com/app/send.pl\" target=\"_blank\">\n"); |
|---|
| 998 | if (!strcmp (DIST, "micro")) |
|---|
| 999 | websWrite (wp, |
|---|
| 1000 | "<img style=\"border-width: 1px; border-color: #8B8583;\" src=\"http://www.moneybookers.com/images/banners/88_en_interpayments.gif\" alt=\"donate thru moneybookers\" />\n"); |
|---|
| 1001 | else |
|---|
| 1002 | websWrite (wp, |
|---|
| 1003 | "<img style=\"border-width: 1px; border-color: #8B8583;\" src=\"images/88_en_interpayments.gif\" alt=\"donate thru interpayments\" />\n"); |
|---|
| 1004 | websWrite (wp, "</a>\n"); |
|---|
| 1005 | #endif |
|---|
| 1006 | return; |
|---|
| 1007 | } |
|---|
| 1008 | |
|---|
| 1009 | void |
|---|
| 1010 | filterstring (char *str, char character) |
|---|
| 1011 | { |
|---|
| 1012 | if (str == NULL) |
|---|
| 1013 | return; |
|---|
| 1014 | int c; |
|---|
| 1015 | int i; |
|---|
| 1016 | int len = strlen (str); |
|---|
| 1017 | c = 0; |
|---|
| 1018 | for (i = 0; i < len; i++) |
|---|
| 1019 | { |
|---|
| 1020 | if (str[i] != character) |
|---|
| 1021 | str[c++] = str[i]; |
|---|
| 1022 | } |
|---|
| 1023 | str[c++] = 0; |
|---|
| 1024 | } |
|---|
| 1025 | |
|---|
| 1026 | char * |
|---|
| 1027 | buildmac (char *in) |
|---|
| 1028 | { |
|---|
| 1029 | char mac[20]; |
|---|
| 1030 | char *outmac; |
|---|
| 1031 | outmac = malloc (20); |
|---|
| 1032 | strncpy (mac, in, 20); |
|---|
| 1033 | filterstring (mac, ':'); |
|---|
| 1034 | filterstring (mac, '-'); |
|---|
| 1035 | filterstring (mac, ' '); |
|---|
| 1036 | if (strlen (mac) != 12) |
|---|
| 1037 | { |
|---|
| 1038 | free (outmac); |
|---|
| 1039 | return NULL; // error. invalid mac |
|---|
| 1040 | } |
|---|
| 1041 | int i; |
|---|
| 1042 | int c = 0; |
|---|
| 1043 | for (i = 0; i < 12; i += 2) |
|---|
| 1044 | { |
|---|
| 1045 | outmac[c++] = mac[i]; |
|---|
| 1046 | outmac[c++] = mac[i + 1]; |
|---|
| 1047 | if (i < 10) |
|---|
| 1048 | outmac[c++] = ':'; |
|---|
| 1049 | } |
|---|
| 1050 | outmac[c++] = 0; |
|---|
| 1051 | return outmac; |
|---|
| 1052 | } |
|---|
| 1053 | |
|---|
| 1054 | #ifdef HAVE_RADLOCAL |
|---|
| 1055 | |
|---|
| 1056 | void |
|---|
| 1057 | raduser_add (webs_t wp) |
|---|
| 1058 | { |
|---|
| 1059 | int radcount = 0; |
|---|
| 1060 | char *radc = nvram_get ("iradius_count"); |
|---|
| 1061 | if (radc != NULL) |
|---|
| 1062 | radcount = atoi (radc); |
|---|
| 1063 | radcount++; |
|---|
| 1064 | char count[16]; |
|---|
| 1065 | sprintf (count, "%d", radcount); |
|---|
| 1066 | nvram_set ("iradius_count", count); |
|---|
| 1067 | } |
|---|
| 1068 | |
|---|
| 1069 | void |
|---|
| 1070 | ej_show_iradius_check (webs_t wp, int argc, char_t ** argv) |
|---|
| 1071 | { |
|---|
| 1072 | char *sln = nvram_safe_get ("iradius_count"); |
|---|
| 1073 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1074 | return; |
|---|
| 1075 | int leasenum = atoi (sln); |
|---|
| 1076 | int i; |
|---|
| 1077 | for (i = 0; i < leasenum; i++) |
|---|
| 1078 | { |
|---|
| 1079 | websWrite (wp, "if(F._iradius%d_active)\n", i); |
|---|
| 1080 | websWrite (wp, "if(F._iradius%d_active.checked == true)\n", i); |
|---|
| 1081 | websWrite (wp, "F.iradius%d_active.value=1\n", i); |
|---|
| 1082 | websWrite (wp, "else\n"); |
|---|
| 1083 | websWrite (wp, "F.iradius%d_active.value=0\n", i); |
|---|
| 1084 | |
|---|
| 1085 | websWrite (wp, "if(F._iradius%d_delete)\n", i); |
|---|
| 1086 | websWrite (wp, "if(F._iradius%d_delete.checked == true)\n", i); |
|---|
| 1087 | websWrite (wp, "F.iradius%d_delete.value=1\n", i); |
|---|
| 1088 | websWrite (wp, "else\n"); |
|---|
| 1089 | websWrite (wp, "F.iradius%d_delete.value=0\n", i); |
|---|
| 1090 | } |
|---|
| 1091 | |
|---|
| 1092 | |
|---|
| 1093 | } |
|---|
| 1094 | void |
|---|
| 1095 | ej_show_iradius (webs_t wp, int argc, char_t ** argv) |
|---|
| 1096 | { |
|---|
| 1097 | char *sln = nvram_safe_get ("iradius_count"); |
|---|
| 1098 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1099 | return; |
|---|
| 1100 | int leasenum = atoi (sln); |
|---|
| 1101 | if (leasenum == 0) |
|---|
| 1102 | return; |
|---|
| 1103 | int i; |
|---|
| 1104 | char username[32]; |
|---|
| 1105 | char *o, *userlist; |
|---|
| 1106 | cprintf ("get collection\n"); |
|---|
| 1107 | char *u = nvram_get_collection ("iradius"); |
|---|
| 1108 | cprintf ("collection result %s", u); |
|---|
| 1109 | if (u != NULL) |
|---|
| 1110 | { |
|---|
| 1111 | userlist = (char *) malloc (strlen (u) + 1); |
|---|
| 1112 | strcpy (userlist, u); |
|---|
| 1113 | free (u); |
|---|
| 1114 | o = userlist; |
|---|
| 1115 | } |
|---|
| 1116 | else |
|---|
| 1117 | { |
|---|
| 1118 | userlist = NULL; |
|---|
| 1119 | o = NULL; |
|---|
| 1120 | } |
|---|
| 1121 | cprintf ("display = chain\n"); |
|---|
| 1122 | struct timeval now; |
|---|
| 1123 | gettimeofday (&now, NULL); |
|---|
| 1124 | for (i = 0; i < leasenum; i++) |
|---|
| 1125 | { |
|---|
| 1126 | snprintf (username, 31, "iradius%d_name", i); |
|---|
| 1127 | char *sep = NULL; |
|---|
| 1128 | if (userlist) |
|---|
| 1129 | sep = strsep (&userlist, " "); |
|---|
| 1130 | websWrite (wp, "<tr><td>\n"); |
|---|
| 1131 | websWrite (wp, "<input name=\"%s\" type=\"hidden\" />", username); |
|---|
| 1132 | websWrite (wp, |
|---|
| 1133 | "<input name=\"%s\" value=\"%s\" size=\"25\" maxlength=\"63\" />\n", |
|---|
| 1134 | username, sep != NULL ? sep : ""); |
|---|
| 1135 | websWrite (wp, "</td>\n"); |
|---|
| 1136 | if (userlist) |
|---|
| 1137 | sep = strsep (&userlist, " "); |
|---|
| 1138 | |
|---|
| 1139 | char active[32]; |
|---|
| 1140 | snprintf (active, 31, "iradius%d_active", i); |
|---|
| 1141 | |
|---|
| 1142 | websWrite (wp, "<td>\n"); |
|---|
| 1143 | websWrite (wp, "<input name=\"%s\" type=\"hidden\" />", active); |
|---|
| 1144 | websWrite (wp, |
|---|
| 1145 | "<input type=\"checkbox\" value=\"%s\" name=\"_%s\" %s />\n", |
|---|
| 1146 | sep, active, sep != NULL ? strcmp (sep, |
|---|
| 1147 | "1") == |
|---|
| 1148 | 0 ? "checked=\"checked\"" : "" : ""); |
|---|
| 1149 | websWrite (wp, "</td>\n"); |
|---|
| 1150 | websWrite (wp, "<td>\n"); |
|---|
| 1151 | if (userlist) |
|---|
| 1152 | sep = strsep (&userlist, " "); |
|---|
| 1153 | long t = atol (sep); |
|---|
| 1154 | if (t != -1) |
|---|
| 1155 | { |
|---|
| 1156 | t -= now.tv_sec; |
|---|
| 1157 | t /= 60; |
|---|
| 1158 | } |
|---|
| 1159 | |
|---|
| 1160 | snprintf (active, 31, "iradius%d_lease", i); |
|---|
| 1161 | char st[32]; |
|---|
| 1162 | if (t >= 0) |
|---|
| 1163 | sprintf (st, "%d", t); |
|---|
| 1164 | else |
|---|
| 1165 | sprintf (st, "over"); |
|---|
| 1166 | websWrite (wp, "<input type=\"num\" name=\"%s\" value='%s' />\n", |
|---|
| 1167 | active, st); |
|---|
| 1168 | websWrite (wp, "</td>\n"); |
|---|
| 1169 | |
|---|
| 1170 | websWrite (wp, "<td>\n"); |
|---|
| 1171 | snprintf (active, 31, "iradius%d_delete", i); |
|---|
| 1172 | websWrite (wp, "<input name=\"%s\" type=\"hidden\" />", active); |
|---|
| 1173 | websWrite (wp, "<input type=\"checkbox\" name=\"_%s\"/>\n", active); |
|---|
| 1174 | websWrite (wp, "</td></tr>\n"); |
|---|
| 1175 | } |
|---|
| 1176 | if (o != NULL) |
|---|
| 1177 | free (o); |
|---|
| 1178 | return; |
|---|
| 1179 | } |
|---|
| 1180 | |
|---|
| 1181 | |
|---|
| 1182 | void |
|---|
| 1183 | validate_iradius (webs_t wp, char *value, struct variable *v) |
|---|
| 1184 | { |
|---|
| 1185 | char username[32] = "iradiusxxx_name"; |
|---|
| 1186 | char active[32] = "iradiusxxx_active"; |
|---|
| 1187 | char del[32] = "iradiusxxx_delete"; |
|---|
| 1188 | |
|---|
| 1189 | char *sln = nvram_safe_get ("iradius_count"); |
|---|
| 1190 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1191 | return; |
|---|
| 1192 | int leasenum = atoi (sln); |
|---|
| 1193 | if (leasenum == 0) |
|---|
| 1194 | return; |
|---|
| 1195 | char *leases; |
|---|
| 1196 | int i; |
|---|
| 1197 | leases = (char *) malloc ((128 * leasenum) + 1); |
|---|
| 1198 | memset (leases, 0, (128 * leasenum) + 1); |
|---|
| 1199 | int leasen = 0; |
|---|
| 1200 | cprintf ("build mac list\n"); |
|---|
| 1201 | |
|---|
| 1202 | struct timeval now; |
|---|
| 1203 | gettimeofday (&now, NULL); |
|---|
| 1204 | |
|---|
| 1205 | for (i = 0; i < leasenum; i++) |
|---|
| 1206 | { |
|---|
| 1207 | snprintf (del, 31, "iradius%d_delete", i); |
|---|
| 1208 | char *d = websGetVar (wp, del, ""); |
|---|
| 1209 | cprintf ("radius delete = %s\n", d); |
|---|
| 1210 | if (strcmp (d, "1") == 0) |
|---|
| 1211 | continue; |
|---|
| 1212 | |
|---|
| 1213 | snprintf (username, 31, "iradius%d_name", i); |
|---|
| 1214 | strcat (leases, websGetVar (wp, username, "00:00:00:00:00:00")); |
|---|
| 1215 | strcat (leases, " "); |
|---|
| 1216 | |
|---|
| 1217 | snprintf (active, 31, "iradius%d_active", i); |
|---|
| 1218 | strcat (leases, websGetVar (wp, active, "0")); |
|---|
| 1219 | strcat (leases, " "); |
|---|
| 1220 | |
|---|
| 1221 | snprintf (active, 31, "iradius%d_lease", i); |
|---|
| 1222 | char *time = websGetVar (wp, active, "-1"); |
|---|
| 1223 | int t = -1; |
|---|
| 1224 | if (strcmp (time, "over")) |
|---|
| 1225 | t = atoi (time); |
|---|
| 1226 | if (t == -1) |
|---|
| 1227 | { |
|---|
| 1228 | strcat (leases, "-1"); |
|---|
| 1229 | } |
|---|
| 1230 | else |
|---|
| 1231 | { |
|---|
| 1232 | char st[32]; |
|---|
| 1233 | sprintf (st, "%d", (now.tv_sec + t * 60)); |
|---|
| 1234 | strcat (leases, st); |
|---|
| 1235 | } |
|---|
| 1236 | strcat (leases, " "); |
|---|
| 1237 | |
|---|
| 1238 | leasen++; |
|---|
| 1239 | } |
|---|
| 1240 | |
|---|
| 1241 | cprintf ("done %s\n", leases); |
|---|
| 1242 | nvram_store_collection ("iradius", leases); |
|---|
| 1243 | cprintf ("stored\n"); |
|---|
| 1244 | char nr[16]; |
|---|
| 1245 | sprintf (nr, "%d", leasen); |
|---|
| 1246 | nvram_set ("iradius_count", nr); |
|---|
| 1247 | nvram_commit (); |
|---|
| 1248 | free (leases); |
|---|
| 1249 | } |
|---|
| 1250 | |
|---|
| 1251 | |
|---|
| 1252 | |
|---|
| 1253 | |
|---|
| 1254 | #endif |
|---|
| 1255 | |
|---|
| 1256 | #ifdef HAVE_CHILLILOCAL |
|---|
| 1257 | |
|---|
| 1258 | void |
|---|
| 1259 | user_remove (webs_t wp) |
|---|
| 1260 | { |
|---|
| 1261 | macro_rem ("fon_usernames", "fon_userlist"); |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | void |
|---|
| 1265 | user_add (webs_t wp) |
|---|
| 1266 | { |
|---|
| 1267 | macro_add ("fon_usernames"); |
|---|
| 1268 | //validate_userlist(wp); |
|---|
| 1269 | } |
|---|
| 1270 | |
|---|
| 1271 | void |
|---|
| 1272 | ej_show_userlist (webs_t wp, int argc, char_t ** argv) |
|---|
| 1273 | { |
|---|
| 1274 | char *sln = nvram_safe_get ("fon_usernames"); |
|---|
| 1275 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1276 | return; |
|---|
| 1277 | int leasenum = atoi (sln); |
|---|
| 1278 | if (leasenum == 0) |
|---|
| 1279 | return; |
|---|
| 1280 | int i; |
|---|
| 1281 | char username[32]; |
|---|
| 1282 | char password[32]; |
|---|
| 1283 | char *u = nvram_safe_get ("fon_userlist"); |
|---|
| 1284 | char *userlist = (char *) malloc (strlen (u) + 1); |
|---|
| 1285 | strcpy (userlist, u); |
|---|
| 1286 | char *o = userlist; |
|---|
| 1287 | for (i = 0; i < leasenum; i++) |
|---|
| 1288 | { |
|---|
| 1289 | snprintf (username, 31, "fon_user%d_name", i); |
|---|
| 1290 | char *sep = strsep (&userlist, "="); |
|---|
| 1291 | websWrite (wp, "<tr><td>\n"); |
|---|
| 1292 | websWrite (wp, |
|---|
| 1293 | "<input name=\"%s\" value=\"%s\" size=\"25\" maxlength=\"63\" />\n", |
|---|
| 1294 | username, sep != NULL ? sep : ""); |
|---|
| 1295 | websWrite (wp, "</td>\n"); |
|---|
| 1296 | sep = strsep (&userlist, " "); |
|---|
| 1297 | snprintf (password, 31, "fon_user%d_password", i); |
|---|
| 1298 | websWrite (wp, "<td>\n"); |
|---|
| 1299 | websWrite (wp, |
|---|
| 1300 | "<input type=\"password\" name=\"%s\" value=\"blahblahblah\" size=\"25\" maxlength=\"63\" />\n", |
|---|
| 1301 | password); |
|---|
| 1302 | websWrite (wp, "</td></tr>\n"); |
|---|
| 1303 | } |
|---|
| 1304 | free (o); |
|---|
| 1305 | return; |
|---|
| 1306 | } |
|---|
| 1307 | |
|---|
| 1308 | |
|---|
| 1309 | void |
|---|
| 1310 | validate_userlist (webs_t wp, char *value, struct variable *v) |
|---|
| 1311 | { |
|---|
| 1312 | char username[32] = "fon_userxxx_name"; |
|---|
| 1313 | char password[32] = "fon_userxxx_password"; |
|---|
| 1314 | char *sln = nvram_safe_get ("fon_usernames"); |
|---|
| 1315 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1316 | return; |
|---|
| 1317 | int leasenum = atoi (sln); |
|---|
| 1318 | if (leasenum == 0) |
|---|
| 1319 | return; |
|---|
| 1320 | char *leases; |
|---|
| 1321 | int i; |
|---|
| 1322 | leases = (char *) malloc ((128 * leasenum) + 1); |
|---|
| 1323 | memset (leases, 0, (128 * leasenum) + 1); |
|---|
| 1324 | |
|---|
| 1325 | for (i = 0; i < leasenum; i++) |
|---|
| 1326 | { |
|---|
| 1327 | snprintf (username, 31, "fon_user%d_name", i); |
|---|
| 1328 | strcat (leases, websGetVar (wp, username, "")); |
|---|
| 1329 | strcat (leases, "="); |
|---|
| 1330 | snprintf (password, 31, "fon_user%d_password", i); |
|---|
| 1331 | strcat (leases, websGetVar (wp, password, "")); |
|---|
| 1332 | strcat (leases, " "); |
|---|
| 1333 | } |
|---|
| 1334 | nvram_set ("fon_userlist", leases); |
|---|
| 1335 | nvram_commit (); |
|---|
| 1336 | free (leases); |
|---|
| 1337 | } |
|---|
| 1338 | |
|---|
| 1339 | |
|---|
| 1340 | #endif |
|---|
| 1341 | |
|---|
| 1342 | |
|---|
| 1343 | |
|---|
| 1344 | void |
|---|
| 1345 | validate_staticleases (webs_t wp, char *value, struct variable *v) |
|---|
| 1346 | { |
|---|
| 1347 | char lease_hwaddr[32] = "leasexxx_hwaddr"; |
|---|
| 1348 | char lease_hostname[32] = "leasexxx_hostname"; |
|---|
| 1349 | char lease_ip[32] = "leasexxx_ip"; |
|---|
| 1350 | char *sln = nvram_safe_get ("static_leasenum"); |
|---|
| 1351 | char *hwaddr; |
|---|
| 1352 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1353 | return; |
|---|
| 1354 | int leasenum = atoi (sln); |
|---|
| 1355 | if (leasenum == 0) |
|---|
| 1356 | return; |
|---|
| 1357 | char *leases; |
|---|
| 1358 | int i; |
|---|
| 1359 | leases = (char *) malloc ((54 * leasenum) + 1); |
|---|
| 1360 | memset (leases, 0, (54 * leasenum) + 1); |
|---|
| 1361 | |
|---|
| 1362 | for (i = 0; i < leasenum; i++) |
|---|
| 1363 | { |
|---|
| 1364 | snprintf (lease_hwaddr, 31, "lease%d_hwaddr", i); |
|---|
| 1365 | hwaddr = websGetVar (wp, lease_hwaddr, NULL); |
|---|
| 1366 | if (hwaddr == NULL) |
|---|
| 1367 | break; |
|---|
| 1368 | char *mac = buildmac (hwaddr); |
|---|
| 1369 | if (mac == NULL) |
|---|
| 1370 | { |
|---|
| 1371 | free (leases); |
|---|
| 1372 | websError (wp, 400, "%s is not a valid mac adress\n", hwaddr); |
|---|
| 1373 | return; |
|---|
| 1374 | } |
|---|
| 1375 | strcat (leases, mac); |
|---|
| 1376 | free (mac); |
|---|
| 1377 | snprintf (lease_hostname, 31, "lease%d_hostname", i); |
|---|
| 1378 | char *hostname = websGetVar (wp, lease_hostname, NULL); |
|---|
| 1379 | snprintf (lease_ip, 31, "lease%d_ip", i); |
|---|
| 1380 | char *ip = websGetVar (wp, lease_ip, ""); |
|---|
| 1381 | if (hostname == NULL || strlen (hostname) == 0 || ip == NULL |
|---|
| 1382 | || strlen (ip) == 0) |
|---|
| 1383 | break; |
|---|
| 1384 | strcat (leases, "="); |
|---|
| 1385 | strcat (leases, hostname); |
|---|
| 1386 | strcat (leases, "="); |
|---|
| 1387 | strcat (leases, ip); |
|---|
| 1388 | strcat (leases, " "); |
|---|
| 1389 | } |
|---|
| 1390 | nvram_set ("static_leases", leases); |
|---|
| 1391 | nvram_commit (); |
|---|
| 1392 | free (leases); |
|---|
| 1393 | } |
|---|
| 1394 | |
|---|
| 1395 | void |
|---|
| 1396 | ej_show_staticleases (webs_t wp, int argc, char_t ** argv) |
|---|
| 1397 | { |
|---|
| 1398 | int i; |
|---|
| 1399 | //cprintf("get static leasenum"); |
|---|
| 1400 | |
|---|
| 1401 | char *sln = nvram_safe_get ("static_leasenum"); |
|---|
| 1402 | //cprintf("check null"); |
|---|
| 1403 | if (sln == NULL || strlen (sln) == 0) |
|---|
| 1404 | return; |
|---|
| 1405 | //cprintf("atoi"); |
|---|
| 1406 | |
|---|
| 1407 | int leasenum = atoi (sln); |
|---|
| 1408 | //cprintf("leasenum==0"); |
|---|
| 1409 | if (leasenum == 0) |
|---|
| 1410 | return; |
|---|
| 1411 | //cprintf("get leases"); |
|---|
| 1412 | char *nvleases = nvram_safe_get ("static_leases"); |
|---|
| 1413 | char *leases = (char *) malloc (strlen (nvleases) + 1); |
|---|
| 1414 | char *originalpointer = leases; //strsep destroys the pointer by moving it |
|---|
| 1415 | strcpy (leases, nvleases); |
|---|
| 1416 | for (i = 0; i < leasenum; i++) |
|---|
| 1417 | { |
|---|
| 1418 | char *sep = strsep (&leases, "="); |
|---|
| 1419 | websWrite (wp, |
|---|
| 1420 | "<tr><td><input name=\"lease%d_hwaddr\" value=\"%s\" size=\"18\" maxlength=\"18\" onblur=\"valid_name(this,share.mac,SPACE_NO)\" /></td>", |
|---|
| 1421 | i, sep != NULL ? sep : ""); |
|---|
| 1422 | sep = strsep (&leases, "="); |
|---|
| 1423 | websWrite (wp, |
|---|
| 1424 | "<td><input name=\"lease%d_hostname\" value=\"%s\" size=\"24\" maxlength=\"24\" onblur=\"valid_name(this,share.hostname,SPACE_NO)\" /></td>", |
|---|
| 1425 | i, sep != NULL ? sep : ""); |
|---|
| 1426 | sep = strsep (&leases, " "); |
|---|
| 1427 | websWrite (wp, |
|---|
| 1428 | "<td><input name=\"lease%d_ip\" value=\"%s\" size=\"15\" maxlength=\"15\" class=\"num\" onblur=\"valid_name(this,share.ip,SPACE_NO)\" /></td></tr>\n", |
|---|
| 1429 | i, sep != NULL ? sep : ""); |
|---|
| 1430 | } |
|---|
| 1431 | free (originalpointer); |
|---|
| 1432 | return; |
|---|
| 1433 | } |
|---|
| 1434 | |
|---|
| 1435 | |
|---|
| 1436 | void |
|---|
| 1437 | ej_show_control (webs_t wp, int argc, char_t ** argv) |
|---|
| 1438 | { |
|---|
| 1439 | #ifdef CONFIG_BRANDING |
|---|
| 1440 | websWrite (wp, "Control Panel"); |
|---|
| 1441 | #else |
|---|
| 1442 | websWrite (wp, "DD-WRT Control Panel"); |
|---|
| 1443 | #endif |
|---|
| 1444 | return; |
|---|
| 1445 | } |
|---|
| 1446 | |
|---|
| 1447 | |
|---|
| 1448 | #ifndef HAVE_AQOS |
|---|
| 1449 | void |
|---|
| 1450 | ej_show_default_level (webs_t wp, int argc, char_t ** argv) |
|---|
| 1451 | { |
|---|
| 1452 | return; |
|---|
| 1453 | } |
|---|
| 1454 | |
|---|
| 1455 | #else |
|---|
| 1456 | void |
|---|
| 1457 | ej_show_default_level (webs_t wp, int argc, char_t ** argv) |
|---|
| 1458 | { |
|---|
| 1459 | websWrite (wp, "<fieldset>\n"); |
|---|
| 1460 | websWrite (wp, |
|---|
| 1461 | "<legend><script type=\"text/javascript\">Capture(qos.legend6)</script></legend>\n"); |
|---|
| 1462 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1463 | websWrite (wp, |
|---|
| 1464 | "<div class=\"label\"><script type=\"text/javascript\">Capture(qos.bandwidth)</script> Up</div>\n"); |
|---|
| 1465 | websWrite (wp, |
|---|
| 1466 | "<input type=\"num\" name=\"default_uplevel\" size=\"6\" value=\"%s\" /> Down\n", |
|---|
| 1467 | nvram_safe_get ("default_uplevel")); |
|---|
| 1468 | websWrite (wp, |
|---|
| 1469 | "<input type=\"num\" name=\"default_downlevel\" size=\"6\" value=\"%s\" />\n", |
|---|
| 1470 | nvram_safe_get ("default_downlevel")); |
|---|
| 1471 | websWrite (wp, "</div>\n"); |
|---|
| 1472 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 1473 | return; |
|---|
| 1474 | } |
|---|
| 1475 | #endif |
|---|
| 1476 | |
|---|
| 1477 | void |
|---|
| 1478 | rep (char *in, char from, char to) |
|---|
| 1479 | { |
|---|
| 1480 | int i; |
|---|
| 1481 | int slen = strlen (in); |
|---|
| 1482 | for (i = 0; i < slen; i++) |
|---|
| 1483 | if (in[i] == from) |
|---|
| 1484 | in[i] = to; |
|---|
| 1485 | |
|---|
| 1486 | } |
|---|
| 1487 | |
|---|
| 1488 | |
|---|
| 1489 | #ifndef HAVE_MSSID |
|---|
| 1490 | |
|---|
| 1491 | void |
|---|
| 1492 | set_security (webs_t wp) |
|---|
| 1493 | { |
|---|
| 1494 | char *var = websGetVar (wp, "security_varname", "security_mode"); |
|---|
| 1495 | nvram_set (var, websGetVar (wp, var, "disabled")); |
|---|
| 1496 | } |
|---|
| 1497 | |
|---|
| 1498 | char * |
|---|
| 1499 | selmatch (char *var, char *is, char *ret) |
|---|
| 1500 | { |
|---|
| 1501 | if (nvram_match (var, is)) |
|---|
| 1502 | return ret; |
|---|
| 1503 | return ""; |
|---|
| 1504 | } |
|---|
| 1505 | |
|---|
| 1506 | void |
|---|
| 1507 | ej_show_security (webs_t wp, int argc, char_t ** argv) |
|---|
| 1508 | { |
|---|
| 1509 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1510 | websWrite (wp, |
|---|
| 1511 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.secmode)</script></div>\n"); |
|---|
| 1512 | websWrite (wp, |
|---|
| 1513 | "<select name=\"security_mode\" onchange=\"SelMode('security_mode',this.form.security_mode.selectedIndex,this.form)\">\n"); |
|---|
| 1514 | websWrite (wp, |
|---|
| 1515 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"disabled\\\" %s >\" + share.disabled + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 1516 | selmatch ("security_mode", "disabled", |
|---|
| 1517 | "selected=\\\"selected\\\"")); |
|---|
| 1518 | websWrite (wp, "<option value=\"psk\" %s>WPA Personal</option>\n", |
|---|
| 1519 | selmatch ("security_mode", "psk", "selected=\"selected\"")); |
|---|
| 1520 | websWrite (wp, "<option value=\"wpa\" %s>WPA Enterprise</option>\n", |
|---|
| 1521 | selmatch ("security_mode", "wpa", "selected=\"selected\"")); |
|---|
| 1522 | if (!nvram_match ("wl0_mode", "wet") && nvram_match ("wl_wds1_enable", "0") && nvram_match ("wl_wds2_enable", "0") && nvram_match ("wl_wds3_enable", "0") && nvram_match ("wl_wds4_enable", "0") && nvram_match ("wl_wds5_enable", "0") && nvram_match ("wl_wds6_enable", "0") && nvram_match ("wl_wds7_enable", "0") && nvram_match ("wl_wds8_enable", "0") && nvram_match ("wl_wds9_enable", "0") && nvram_match ("wl_wds10_enable", "0")) //botho 10/04/06 : if wireless client bridge mode selected or WDS activated => we don't display WPA2 security modes |
|---|
| 1523 | { |
|---|
| 1524 | websWrite (wp, |
|---|
| 1525 | "<option value=\"psk2\" %s>WPA2 Personal</option>\n", |
|---|
| 1526 | selmatch ("security_mode", "psk2", "selected")); |
|---|
| 1527 | websWrite (wp, "<option value=\"wpa2\" %s>WPA2 Enterprise</option>\n", |
|---|
| 1528 | selmatch ("security_mode", "wpa2", "selected=\"selected\"")); |
|---|
| 1529 | } |
|---|
| 1530 | websWrite (wp, |
|---|
| 1531 | "<option value=\"psk psk2\" %s>WPA2 Personal Mixed</option>\n", |
|---|
| 1532 | selmatch ("security_mode", "psk psk2", "selected")); |
|---|
| 1533 | websWrite (wp, |
|---|
| 1534 | "<option value=\"wpa wpa2\" %s>WPA2 Enterprise Mixed</option>\n", |
|---|
| 1535 | selmatch ("security_mode", "wpa wpa2", "selected=\"selected\"")); |
|---|
| 1536 | websWrite (wp, "<option value=\"radius\" %s>RADIUS</option>\n", |
|---|
| 1537 | selmatch ("security_mode", "radius", "selected=\"selected\"")); |
|---|
| 1538 | websWrite (wp, "<option value=\"wep\" %s>WEP</option></select>\n", |
|---|
| 1539 | selmatch ("security_mode", "wep", "selected=\"selected\"")); |
|---|
| 1540 | websWrite (wp, "</div>\n"); |
|---|
| 1541 | ej_show_wpa_setting (wp, argc, argv); |
|---|
| 1542 | return; |
|---|
| 1543 | } |
|---|
| 1544 | #else |
|---|
| 1545 | #ifdef HAVE_MADWIFI |
|---|
| 1546 | struct wifi_channels |
|---|
| 1547 | { |
|---|
| 1548 | int channel; |
|---|
| 1549 | int freq; |
|---|
| 1550 | int noise}; |
|---|
| 1551 | extern struct wifi_channels *list_channels (char *devnr); |
|---|
| 1552 | //extern int getchannelcount (void); |
|---|
| 1553 | extern int getdevicecount (void); |
|---|
| 1554 | #endif |
|---|
| 1555 | |
|---|
| 1556 | |
|---|
| 1557 | void |
|---|
| 1558 | set_security (webs_t wp) |
|---|
| 1559 | { |
|---|
| 1560 | char *var = websGetVar (wp, "security_varname", "security_mode"); |
|---|
| 1561 | cprintf ("set security to %s\n", var); |
|---|
| 1562 | cprintf ("security var = %s\n", websGetVar (wp, var, "disabled")); |
|---|
| 1563 | char *var2 = websGetVar (wp, var, "disabled"); |
|---|
| 1564 | //rep(var,'X','.'); |
|---|
| 1565 | nvram_set (var, var2); |
|---|
| 1566 | } |
|---|
| 1567 | |
|---|
| 1568 | char * |
|---|
| 1569 | selmatch (char *var, char *is, char *ret) |
|---|
| 1570 | { |
|---|
| 1571 | if (nvram_match (var, is)) |
|---|
| 1572 | return ret; |
|---|
| 1573 | return ""; |
|---|
| 1574 | } |
|---|
| 1575 | |
|---|
| 1576 | static void |
|---|
| 1577 | show_security_prefix (webs_t wp, int argc, char_t ** argv, char *prefix) |
|---|
| 1578 | { |
|---|
| 1579 | char var[80]; |
|---|
| 1580 | char sta[80]; |
|---|
| 1581 | //char p2[80]; |
|---|
| 1582 | cprintf ("show security prefix\n"); |
|---|
| 1583 | sprintf (var, "%s_security_mode", prefix); |
|---|
| 1584 | //strcpy(p2,prefix); |
|---|
| 1585 | //rep(p2,'X','.'); |
|---|
| 1586 | //websWrite (wp, "<input type=\"hidden\" name=\"%s_security_mode\"/>\n",p2); |
|---|
| 1587 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1588 | websWrite (wp, |
|---|
| 1589 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.secmode)</script></div>\n"); |
|---|
| 1590 | websWrite (wp, |
|---|
| 1591 | "<select name=\"%s_security_mode\" onchange=\"SelMode('%s_security_mode',this.form.%s_security_mode.selectedIndex,this.form)\">\n", |
|---|
| 1592 | prefix, prefix, prefix); |
|---|
| 1593 | websWrite (wp, |
|---|
| 1594 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"disabled\\\" %s >\" + share.disabled + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 1595 | selmatch (var, "disabled", "selected=\\\"selected\\\"")); |
|---|
| 1596 | websWrite (wp, "<option value=\"psk\" %s>WPA Personal</option>\n", |
|---|
| 1597 | selmatch (var, "psk", "selected=\"selected\"")); |
|---|
| 1598 | sprintf (sta, "%s_mode", prefix); |
|---|
| 1599 | if (nvram_match (sta, "ap")) |
|---|
| 1600 | { |
|---|
| 1601 | websWrite (wp, "<option value=\"wpa\" %s>WPA Enterprise</option>\n", |
|---|
| 1602 | selmatch (var, "wpa", "selected=\"selected\"")); |
|---|
| 1603 | } |
|---|
| 1604 | websWrite (wp, |
|---|
| 1605 | "<option value=\"psk2\" %s>WPA2 Personal</option>\n", |
|---|
| 1606 | selmatch (var, "psk2", "selected=\"selected\"")); |
|---|
| 1607 | if (nvram_match (sta, "ap")) |
|---|
| 1608 | { |
|---|
| 1609 | websWrite (wp, "<option value=\"wpa2\" %s>WPA2 Enterprise</option>\n", |
|---|
| 1610 | selmatch (var, "wpa2", "selected=\"selected\"")); |
|---|
| 1611 | websWrite (wp, |
|---|
| 1612 | "<option value=\"psk psk2\" %s>WPA2 Personal Mixed</option>\n", |
|---|
| 1613 | selmatch (var, "psk psk2", "selected=\"selected\"")); |
|---|
| 1614 | websWrite (wp, |
|---|
| 1615 | "<option value=\"wpa wpa2\" %s>WPA2 Enterprise Mixed</option>\n", |
|---|
| 1616 | selmatch (var, "wpa wpa2", "selected=\"selected\"")); |
|---|
| 1617 | } |
|---|
| 1618 | websWrite (wp, "<option value=\"radius\" %s>RADIUS</option>\n", |
|---|
| 1619 | selmatch (var, "radius", "selected=\"selected\"")); |
|---|
| 1620 | websWrite (wp, "<option value=\"wep\" %s>WEP</option>\n", |
|---|
| 1621 | selmatch (var, "wep", "selected=\"selected\"")); |
|---|
| 1622 | #ifdef HAVE_WPA_SUPPLICANT |
|---|
| 1623 | if (nvram_match (sta, "sta") || nvram_match (sta, "apsta") || nvram_match (sta, "wet")) |
|---|
| 1624 | { |
|---|
| 1625 | websWrite (wp, "<option value=\"8021X\" %s>802.1x</option>\n", |
|---|
| 1626 | selmatch (var, "8021X", "selected=\"selected\"")); |
|---|
| 1627 | } |
|---|
| 1628 | #endif |
|---|
| 1629 | |
|---|
| 1630 | websWrite (wp, "</select></div>\n"); |
|---|
| 1631 | rep (prefix, 'X', '.'); |
|---|
| 1632 | cprintf ("ej show wpa\n"); |
|---|
| 1633 | ej_show_wpa_setting (wp, argc, argv, prefix); |
|---|
| 1634 | |
|---|
| 1635 | } |
|---|
| 1636 | |
|---|
| 1637 | static void |
|---|
| 1638 | ej_show_security_single (webs_t wp, int argc, char_t ** argv, char *prefix) |
|---|
| 1639 | { |
|---|
| 1640 | char *next; |
|---|
| 1641 | char var[80]; |
|---|
| 1642 | char ssid[80]; |
|---|
| 1643 | char vif[16]; |
|---|
| 1644 | char mac[16]; |
|---|
| 1645 | sprintf (mac, "%s_hwaddr", prefix); |
|---|
| 1646 | sprintf (vif, "%s_vifs", prefix); |
|---|
| 1647 | char *vifs = nvram_safe_get (vif); |
|---|
| 1648 | if (vifs == NULL) |
|---|
| 1649 | return; |
|---|
| 1650 | sprintf (ssid, "%s_ssid", prefix); |
|---|
| 1651 | websWrite (wp, |
|---|
| 1652 | "<h2><script type=\"text/javascript\">Capture(wpa.h2)</script> %s</h2>\n", |
|---|
| 1653 | prefix); |
|---|
| 1654 | websWrite (wp, "<fieldset>\n"); |
|---|
| 1655 | //cprintf("getting %s %s\n",ssid,nvram_safe_get(ssid)); |
|---|
| 1656 | websWrite (wp, |
|---|
| 1657 | "<legend><script type=\"text/javascript\">Capture(share.pintrface)</script> %s SSID [%s] HWAddr [%s]</legend>\n", |
|---|
| 1658 | prefix, nvram_safe_get (ssid), nvram_safe_get (mac)); |
|---|
| 1659 | show_security_prefix (wp, argc, argv, prefix); |
|---|
| 1660 | websWrite (wp, "</fieldset>\n<br />\n"); |
|---|
| 1661 | foreach (var, vifs, next) |
|---|
| 1662 | { |
|---|
| 1663 | sprintf (ssid, "%s_ssid", var); |
|---|
| 1664 | websWrite (wp, "<fieldset>\n"); |
|---|
| 1665 | //cprintf("getting %s %s\n",ssid,nvram_safe_get(ssid)); |
|---|
| 1666 | websWrite (wp, |
|---|
| 1667 | "<legend><script type=\"text/javascript\">Capture(share.vintrface)</script> %s SSID [%s]</legend>\n", |
|---|
| 1668 | var, nvram_get (ssid)); |
|---|
| 1669 | rep (var, '.', 'X'); |
|---|
| 1670 | show_security_prefix (wp, argc, argv, var); |
|---|
| 1671 | websWrite (wp, "</fieldset>\n<br />\n"); |
|---|
| 1672 | } |
|---|
| 1673 | |
|---|
| 1674 | } |
|---|
| 1675 | |
|---|
| 1676 | void |
|---|
| 1677 | ej_show_security (webs_t wp, int argc, char_t ** argv) |
|---|
| 1678 | { |
|---|
| 1679 | #ifndef HAVE_MADWIFI |
|---|
| 1680 | return ej_show_security_single (wp, argc, argv, "wl0"); |
|---|
| 1681 | #else |
|---|
| 1682 | int c = getdevicecount (); |
|---|
| 1683 | int i; |
|---|
| 1684 | for (i = 0; i < c; i++) |
|---|
| 1685 | { |
|---|
| 1686 | char buf[16]; |
|---|
| 1687 | sprintf (buf, "ath%d", i); |
|---|
| 1688 | ej_show_security_single (wp, argc, argv, buf); |
|---|
| 1689 | } |
|---|
| 1690 | return; |
|---|
| 1691 | #endif |
|---|
| 1692 | } |
|---|
| 1693 | |
|---|
| 1694 | #endif |
|---|
| 1695 | |
|---|
| 1696 | |
|---|
| 1697 | |
|---|
| 1698 | void |
|---|
| 1699 | dhcpfwd (webs_t wp) |
|---|
| 1700 | { |
|---|
| 1701 | int ret = 0; |
|---|
| 1702 | char *enable; |
|---|
| 1703 | |
|---|
| 1704 | enable = websGetVar (wp, "dhcpfwd_enable", NULL); |
|---|
| 1705 | nvram_set ("dhcpfwd_enable", enable); |
|---|
| 1706 | |
|---|
| 1707 | } |
|---|
| 1708 | |
|---|
| 1709 | void |
|---|
| 1710 | wan_proto (webs_t wp) |
|---|
| 1711 | { |
|---|
| 1712 | int ret = 0; |
|---|
| 1713 | char *enable; |
|---|
| 1714 | |
|---|
| 1715 | enable = websGetVar (wp, "wan_proto", NULL); |
|---|
| 1716 | nvram_set ("wan_proto", enable); |
|---|
| 1717 | |
|---|
| 1718 | } |
|---|
| 1719 | |
|---|
| 1720 | |
|---|
| 1721 | void |
|---|
| 1722 | ej_show_dhcpd_settings (webs_t wp, int argc, char_t ** argv) |
|---|
| 1723 | { |
|---|
| 1724 | int i; |
|---|
| 1725 | if (nvram_match ("wl0_mode", "wet")) //dhcpd settings disabled in client bridge mode, so we wont display it |
|---|
| 1726 | return; |
|---|
| 1727 | if (nvram_match ("wl0_mode", "apstawet")) //dhcpd settings disabled in client bridge mode, so we wont display it |
|---|
| 1728 | return; |
|---|
| 1729 | websWrite (wp, |
|---|
| 1730 | "<fieldset><legend><script type=\"text/javascript\">Capture(idx.dhcp_legend)</script></legend>\n"); |
|---|
| 1731 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1732 | websWrite (wp, |
|---|
| 1733 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_type)</script></div>\n"); |
|---|
| 1734 | websWrite (wp, |
|---|
| 1735 | "<select class=\"num\" size=\"1\" name=\"dhcpfwd_enable\" onchange=SelDHCPFWD(this.form.dhcpfwd_enable.selectedIndex,this.form)>\n"); |
|---|
| 1736 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 1737 | websWrite (wp, |
|---|
| 1738 | "document.write(\"<option value=\\\"0\\\" %s >\" + idx.dhcp_srv + \"</option>\");\n", |
|---|
| 1739 | nvram_match ("dhcpfwd_enable", |
|---|
| 1740 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 1741 | websWrite (wp, |
|---|
| 1742 | "document.write(\"<option value=\\\"1\\\" %s >\" + idx.dhcp_fwd + \"</option>\");\n", |
|---|
| 1743 | nvram_match ("dhcpfwd_enable", |
|---|
| 1744 | "1") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 1745 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 1746 | websWrite (wp, "</select>\n"); |
|---|
| 1747 | websWrite (wp, "</div>\n"); |
|---|
| 1748 | if (nvram_match ("dhcpfwd_enable", "1")) |
|---|
| 1749 | { |
|---|
| 1750 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1751 | websWrite (wp, |
|---|
| 1752 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_srv)</script></div>\n"); |
|---|
| 1753 | char *ipfwd = nvram_safe_get ("dhcpfwd_ip"); |
|---|
| 1754 | websWrite (wp, |
|---|
| 1755 | "<input type=\"hidden\" name=\"dhcpfwd_ip\" value=\"4\" /><input class=\"num\" maxlength=\"3\" size=\"3\" name=\"dhcpfwd_ip_0\" onblur=\"valid_range(this,0,255,idx.dhcp_srv)\" value=\"%d\" />.<input class=\"num\" maxlength=\"3\" size=\"3\" name=\"dhcpfwd_ip_1\" onblur=\"valid_range(this,0,255,idx.dhcp_srv)\" value=\"%d\" />.<input class=\"num\" maxlength=\"3\" name=\"dhcpfwd_ip_2\" size=\"3\" onblur=\"valid_range(this,0,255,idx.dhcp_srv)\" value=\"%d\" />.<input class=\"num\" maxlength=\"3\" name=\"dhcpfwd_ip_3\" size=\"3\" onblur=\"valid_range(this,0,254,idx.dhcp_srv)\" value=\"%d\"\" /></div>\n", |
|---|
| 1756 | get_single_ip (ipfwd, 0), get_single_ip (ipfwd, 1), |
|---|
| 1757 | get_single_ip (ipfwd, 2), get_single_ip (ipfwd, 3)); |
|---|
| 1758 | } |
|---|
| 1759 | else |
|---|
| 1760 | { |
|---|
| 1761 | char buf[20]; |
|---|
| 1762 | prefix_ip_get ("lan_ipaddr", buf, 1); |
|---|
| 1763 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1764 | // char *nv = nvram_safe_get ("wan_wins"); |
|---|
| 1765 | websWrite (wp, |
|---|
| 1766 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_srv)</script></div><input class=\"spaceradio\" type=\"radio\" name=\"lan_proto\" value=\"dhcp\" onclick=SelDHCP('dhcp',this.form) %s /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 1767 | nvram_match ("lan_proto", |
|---|
| 1768 | "dhcp") ? "checked=\"checked\"" : ""); |
|---|
| 1769 | websWrite (wp, |
|---|
| 1770 | "<input class=\"spaceradio\" type=\"radio\" name=\"lan_proto\" value=\"static\" onclick=\"SelDHCP('static',this.form)\" %s /><script type=\"text/javascript\">Capture(share.disable)</script></div><input type=\"hidden\" name=\"dhcp_check\" /><div class=\"setting\">\n", |
|---|
| 1771 | nvram_match ("lan_proto", |
|---|
| 1772 | "static") ? "checked=\"checked\"" : ""); |
|---|
| 1773 | websWrite (wp, |
|---|
| 1774 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_start)</script></div>%s", |
|---|
| 1775 | buf); |
|---|
| 1776 | websWrite (wp, |
|---|
| 1777 | "<input class=\"num\" name=\"dhcp_start\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,1,254,idx.dhcp_start)\" value=\"%s\" />", |
|---|
| 1778 | nvram_safe_get ("dhcp_start")); |
|---|
| 1779 | websWrite (wp, "</div>\n"); |
|---|
| 1780 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1781 | websWrite (wp, |
|---|
| 1782 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_maxusers)</script></div><input class=\"num\" name=\"dhcp_num\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,1,253,idx.dhcp_maxusers)\" value=\"%s\" /></div>\n", |
|---|
| 1783 | nvram_safe_get ("dhcp_num")); |
|---|
| 1784 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1785 | websWrite (wp, |
|---|
| 1786 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_lease)</script></div><input class=\"num\" name=\"dhcp_lease\" size=\"4\" maxlength=\"4\" onblur=\"valid_range(this,0,9999,idx.dhcp_lease)\" value=\"%s\" > <script type=\"text/javascript\">Capture(share.minutes)</script></input></div>\n", |
|---|
| 1787 | nvram_safe_get ("dhcp_lease")); |
|---|
| 1788 | if (nvram_invmatch ("wan_proto", "static")) |
|---|
| 1789 | { |
|---|
| 1790 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1791 | websWrite (wp, |
|---|
| 1792 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx_static.dns)</script> 1</div>"); |
|---|
| 1793 | websWrite (wp, |
|---|
| 1794 | "<input type=\"hidden\" name=\"wan_dns\" value=\"4\" />"); |
|---|
| 1795 | for (i = 0; i < 4; i++) |
|---|
| 1796 | websWrite (wp, |
|---|
| 1797 | "<input class=\"num\" name=\"wan_dns0_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,idx_static.dns)\" value=\"%d\" />%s", |
|---|
| 1798 | i, i == 3 ? 254 : 255, get_dns_ip ("wan_dns", 0, i), |
|---|
| 1799 | i < 3 ? "." : ""); |
|---|
| 1800 | |
|---|
| 1801 | websWrite (wp, "\n</div>\n<div class=\"setting\">\n"); |
|---|
| 1802 | websWrite (wp, |
|---|
| 1803 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx_static.dns)</script> 2</div>"); |
|---|
| 1804 | for (i = 0; i < 4; i++) |
|---|
| 1805 | websWrite (wp, |
|---|
| 1806 | "<input class=\"num\" name=\"wan_dns1_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,idx_static.dns)\" value=\"%d\" />%s", |
|---|
| 1807 | i, i == 3 ? 254 : 255, get_dns_ip ("wan_dns", 1, i), |
|---|
| 1808 | i < 3 ? "." : ""); |
|---|
| 1809 | |
|---|
| 1810 | websWrite (wp, "\n</div>\n<div class=\"setting\">\n"); |
|---|
| 1811 | websWrite (wp, |
|---|
| 1812 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx_static.dns)</script> 3</div>"); |
|---|
| 1813 | for (i = 0; i < 4; i++) |
|---|
| 1814 | websWrite (wp, |
|---|
| 1815 | "<input class=\"num\" name=\"wan_dns2_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,idx_static.dns)\" value=\"%d\" />%s", |
|---|
| 1816 | i, i == 3 ? 254 : 255, get_dns_ip ("wan_dns", 2, i), |
|---|
| 1817 | i < 3 ? "." : ""); |
|---|
| 1818 | websWrite (wp, "\n</div>"); |
|---|
| 1819 | } |
|---|
| 1820 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1821 | websWrite (wp, "<div class=\"label\">WINS</div>\n"); |
|---|
| 1822 | websWrite (wp, |
|---|
| 1823 | "<input type=\"hidden\" name=\"wan_wins\" value=\"4\" />\n"); |
|---|
| 1824 | char *wins = nvram_safe_get ("wan_wins"); |
|---|
| 1825 | for (i = 0; i < 4; i++) |
|---|
| 1826 | { |
|---|
| 1827 | websWrite (wp, |
|---|
| 1828 | "<input class=\"num\" name=\"wan_wins_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,"WINS")\" value=\"%d\" />%s", |
|---|
| 1829 | i, i == 3 ? 254 : 255, get_single_ip (wins, i), |
|---|
| 1830 | i < 3 ? "." : ""); |
|---|
| 1831 | } |
|---|
| 1832 | |
|---|
| 1833 | websWrite (wp, "</div>\n<div class=\"setting\">\n"); |
|---|
| 1834 | websWrite (wp, |
|---|
| 1835 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_dnsmasq)</script></div>\n"); |
|---|
| 1836 | websWrite (wp, |
|---|
| 1837 | "<input type=\"checkbox\" name=\"_dhcp_dnsmasq\" value=\"1\" onclick=\"setDNSMasq(this.form)\" %s />\n", |
|---|
| 1838 | nvram_match ("dhcp_dnsmasq", |
|---|
| 1839 | "1") ? "checked=\"checked\"" : ""); |
|---|
| 1840 | websWrite (wp, "</div>\n<div class=\"setting\">\n"); |
|---|
| 1841 | websWrite (wp, |
|---|
| 1842 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dns_dnsmasq)</script></div>\n"); |
|---|
| 1843 | websWrite (wp, |
|---|
| 1844 | "<input type=\"checkbox\" name=\"_dns_dnsmasq\" value=\"1\" %s />\n", |
|---|
| 1845 | nvram_match ("dns_dnsmasq", |
|---|
| 1846 | "1") ? "checked=\"checked\"" : ""); |
|---|
| 1847 | websWrite (wp, "</div>\n<div class=\"setting\">\n"); |
|---|
| 1848 | websWrite (wp, |
|---|
| 1849 | "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.auth_dnsmasq)</script></div>\n"); |
|---|
| 1850 | websWrite (wp, |
|---|
| 1851 | "<input type=\"checkbox\" name=\"_auth_dnsmasq\" value=\"1\" %s />\n", |
|---|
| 1852 | nvram_match ("auth_dnsmasq", |
|---|
| 1853 | "1") ? "checked=\"checked\"" : ""); |
|---|
| 1854 | websWrite (wp, "</div>\n"); |
|---|
| 1855 | } |
|---|
| 1856 | |
|---|
| 1857 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 1858 | return; |
|---|
| 1859 | } |
|---|
| 1860 | |
|---|
| 1861 | |
|---|
| 1862 | |
|---|
| 1863 | #ifdef HAVE_MADWIFI |
|---|
| 1864 | void |
|---|
| 1865 | ej_show_wifiselect (webs_t wp, int argc, char_t ** argv) |
|---|
| 1866 | { |
|---|
| 1867 | char *next; |
|---|
| 1868 | char var[80]; |
|---|
| 1869 | int count = getifcount ("wifi"); |
|---|
| 1870 | if (count < 2) |
|---|
| 1871 | return; |
|---|
| 1872 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1873 | websWrite (wp, |
|---|
| 1874 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.intrface)</script></div>\n"); |
|---|
| 1875 | websWrite (wp, |
|---|
| 1876 | "<select name=\"wifi_display\" onchange=\"refresh(this.form)\">\n"); |
|---|
| 1877 | int i; |
|---|
| 1878 | for (i = 0; i < count; i++) |
|---|
| 1879 | { |
|---|
| 1880 | sprintf (var, "ath%d", i); |
|---|
| 1881 | websWrite (wp, "<option value=\"%s\" %s >%s</option>\n</script>\n", |
|---|
| 1882 | var, nvram_match ("wifi_display", |
|---|
| 1883 | var) ? "selected=\"selected\"" : "", var); |
|---|
| 1884 | sprintf (var, "ath%d_vifs", i); |
|---|
| 1885 | char *names = nvram_safe_get (var); |
|---|
| 1886 | foreach (var, names, next) |
|---|
| 1887 | { |
|---|
| 1888 | websWrite (wp, "<option value=\"%s\" %s >%s</option>\n</script>\n", |
|---|
| 1889 | var, nvram_match ("wifi_display", |
|---|
| 1890 | var) ? "selected=\"selected\"" : "", |
|---|
| 1891 | var); |
|---|
| 1892 | } |
|---|
| 1893 | } |
|---|
| 1894 | websWrite (wp, "</select>\n"); |
|---|
| 1895 | websWrite (wp, "</div>\n"); |
|---|
| 1896 | |
|---|
| 1897 | } |
|---|
| 1898 | #endif |
|---|
| 1899 | static void |
|---|
| 1900 | showOption (webs_t wp, char *propname, char *nvname) |
|---|
| 1901 | { |
|---|
| 1902 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1903 | websWrite (wp, |
|---|
| 1904 | "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>\n<select name=\"%s\">\n", |
|---|
| 1905 | propname, nvname); |
|---|
| 1906 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 1907 | websWrite (wp, |
|---|
| 1908 | "document.write(\"<option value=\\\"0\\\" %s >\" + share.disabled + \"</option>\");\n", |
|---|
| 1909 | nvram_default_match (nvname, "0", |
|---|
| 1910 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 1911 | websWrite (wp, |
|---|
| 1912 | "document.write(\"<option value=\\\"1\\\" %s >\" + share.enabled + \"</option>\");\n", |
|---|
| 1913 | nvram_default_match (nvname, "1", |
|---|
| 1914 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 1915 | websWrite (wp, "//]]>\n</script>\n</select>\n</div>\n"); |
|---|
| 1916 | |
|---|
| 1917 | } |
|---|
| 1918 | |
|---|
| 1919 | |
|---|
| 1920 | static void |
|---|
| 1921 | showOptions (webs_t wp, char *propname, char *names, char *select) |
|---|
| 1922 | { |
|---|
| 1923 | char *next; |
|---|
| 1924 | char var[80]; |
|---|
| 1925 | websWrite (wp, "<select name=\"%s\">\n", propname); |
|---|
| 1926 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 1927 | foreach (var, names, next) |
|---|
| 1928 | { |
|---|
| 1929 | websWrite (wp, |
|---|
| 1930 | "document.write(\"<option value=\\\"%s\\\" %s >%s</option>\");\n", |
|---|
| 1931 | var, !strcmp (var, select) ? "selected=\\\"selected\\\"" : "", |
|---|
| 1932 | var); |
|---|
| 1933 | } |
|---|
| 1934 | websWrite (wp, "//]]>\n</script>\n</select>\n"); |
|---|
| 1935 | } |
|---|
| 1936 | |
|---|
| 1937 | static void |
|---|
| 1938 | showOptionsLabel (webs_t wp, char *labelname, char *propname, char *names, |
|---|
| 1939 | char *select) |
|---|
| 1940 | { |
|---|
| 1941 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1942 | websWrite (wp, |
|---|
| 1943 | "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>", |
|---|
| 1944 | labelname); |
|---|
| 1945 | showOptions (wp, propname, names, select); |
|---|
| 1946 | websWrite (wp, "</div>\n"); |
|---|
| 1947 | |
|---|
| 1948 | } |
|---|
| 1949 | |
|---|
| 1950 | void |
|---|
| 1951 | show_inputlabel (webs_t wp, char *labelname, char *propertyname, |
|---|
| 1952 | int propertysize, char *inputclassname, int inputmaxlength) |
|---|
| 1953 | { |
|---|
| 1954 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1955 | websWrite (wp, |
|---|
| 1956 | "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>", |
|---|
| 1957 | labelname); |
|---|
| 1958 | websWrite (wp, |
|---|
| 1959 | "<input class=\"%s\" size=\"%d\" maxlength=\"%d\" name=\"%s\" value=\"%s\" />\n", |
|---|
| 1960 | inputclassname, propertysize, inputmaxlength, propertyname, |
|---|
| 1961 | nvram_safe_get (propertyname)); |
|---|
| 1962 | websWrite (wp, "</div>\n"); |
|---|
| 1963 | } |
|---|
| 1964 | |
|---|
| 1965 | void |
|---|
| 1966 | show_custominputlabel (webs_t wp, char *labelname, char *propertyname, |
|---|
| 1967 | char *property, int propertysize) |
|---|
| 1968 | { |
|---|
| 1969 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 1970 | websWrite (wp, "<div class=\"label\">%s</div>", labelname); |
|---|
| 1971 | websWrite (wp, "<input size=\"%d\" name=\"%s\" value=\"%s\" />\n", |
|---|
| 1972 | propertysize, propertyname, property); |
|---|
| 1973 | websWrite (wp, "</div>\n"); |
|---|
| 1974 | } |
|---|
| 1975 | |
|---|
| 1976 | void |
|---|
| 1977 | show_legend (webs_t wp, char *labelname, int *translate) |
|---|
| 1978 | { |
|---|
| 1979 | /* char buf[2]; |
|---|
| 1980 | sprintf(buf,"%d",translate); |
|---|
| 1981 | websWrite (wp, "<legend>%s%s%s</legend>\n", |
|---|
| 1982 | !strcmp (buf, "1") ? "<script type=\"text/javascript\">Capture(" : "", labelname, !strcmp (buf, "1") ? ")</script>" : ""); |
|---|
| 1983 | */ |
|---|
| 1984 | if (translate) |
|---|
| 1985 | websWrite (wp, |
|---|
| 1986 | "<legend><script type=\"text/javascript\">Capture(%s)</script></legend>\n", |
|---|
| 1987 | labelname); |
|---|
| 1988 | else |
|---|
| 1989 | websWrite (wp, "<legend>%s</legend>\n", labelname); |
|---|
| 1990 | |
|---|
| 1991 | } |
|---|
| 1992 | |
|---|
| 1993 | |
|---|
| 1994 | #ifdef HAVE_OLSRD |
|---|
| 1995 | void |
|---|
| 1996 | add_olsrd (webs_t wp) |
|---|
| 1997 | { |
|---|
| 1998 | char *ifname = websGetVar (wp, "olsrd_ifname", NULL); |
|---|
| 1999 | if (ifname == NULL) |
|---|
| 2000 | return; |
|---|
| 2001 | char *wordlist = nvram_safe_get ("olsrd_interfaces"); |
|---|
| 2002 | char *addition = ">5.0>90.0>2.0>270.0>15.0>90.0>15.0>90.0"; |
|---|
| 2003 | char *newadd = |
|---|
| 2004 | (char *) malloc (strlen (wordlist) + strlen (addition) + strlen (ifname) + |
|---|
| 2005 | 2); |
|---|
| 2006 | if (strlen (wordlist) > 0) |
|---|
| 2007 | { |
|---|
| 2008 | strcpy (newadd, wordlist); |
|---|
| 2009 | strcat (newadd, " "); |
|---|
| 2010 | strcat (newadd, ifname); |
|---|
| 2011 | } |
|---|
| 2012 | else |
|---|
| 2013 | { |
|---|
| 2014 | strcpy (newadd, ifname); |
|---|
| 2015 | } |
|---|
| 2016 | strcat (newadd, addition); |
|---|
| 2017 | nvram_set ("olsrd_interfaces", newadd); |
|---|
| 2018 | nvram_commit (); |
|---|
| 2019 | free (newadd); |
|---|
| 2020 | return; |
|---|
| 2021 | } |
|---|
| 2022 | |
|---|
| 2023 | void |
|---|
| 2024 | del_olsrd (webs_t wp) |
|---|
| 2025 | { |
|---|
| 2026 | char *del = websGetVar (wp, "olsrd_delcount", NULL); |
|---|
| 2027 | if (del == NULL) |
|---|
| 2028 | return; |
|---|
| 2029 | int d = atoi (del); |
|---|
| 2030 | char *wordlist = nvram_safe_get ("olsrd_interfaces"); |
|---|
| 2031 | char *newlist = (char *) malloc (strlen (wordlist) + 1); |
|---|
| 2032 | memset (newlist, 0, strlen (wordlist)); |
|---|
| 2033 | char *next; |
|---|
| 2034 | char word[128]; |
|---|
| 2035 | int count = 0; |
|---|
| 2036 | foreach (word, wordlist, next) |
|---|
| 2037 | { |
|---|
| 2038 | if (count != d) |
|---|
| 2039 | sprintf (newlist, "%s %s", newlist, word); |
|---|
| 2040 | count++; |
|---|
| 2041 | } |
|---|
| 2042 | nvram_set ("olsrd_interfaces", newlist); |
|---|
| 2043 | nvram_commit (); |
|---|
| 2044 | free (newlist); |
|---|
| 2045 | return; |
|---|
| 2046 | } |
|---|
| 2047 | |
|---|
| 2048 | void |
|---|
| 2049 | save_olsrd (webs_t wp) |
|---|
| 2050 | { |
|---|
| 2051 | char *wordlist = nvram_safe_get ("olsrd_interfaces"); |
|---|
| 2052 | char *newlist = (char *) malloc (strlen (wordlist) + 512); |
|---|
| 2053 | memset (newlist, 0, strlen (wordlist) + 512); |
|---|
| 2054 | char *next; |
|---|
| 2055 | char word[64]; |
|---|
| 2056 | foreach (word, wordlist, next) |
|---|
| 2057 | { |
|---|
| 2058 | char *interface = word; |
|---|
| 2059 | char *dummy = interface; |
|---|
| 2060 | strsep (&dummy, ">"); |
|---|
| 2061 | char valuename[32]; |
|---|
| 2062 | |
|---|
| 2063 | sprintf (valuename, "%s_hellointerval", interface); |
|---|
| 2064 | char *hellointerval = websGetVar (wp, valuename, "0"); |
|---|
| 2065 | sprintf (valuename, "%s_hellovaliditytime", interface); |
|---|
| 2066 | char *hellovaliditytime = websGetVar (wp, valuename, "0"); |
|---|
| 2067 | |
|---|
| 2068 | sprintf (valuename, "%s_tcinterval", interface); |
|---|
| 2069 | char *tcinterval = websGetVar (wp, valuename, "0"); |
|---|
| 2070 | sprintf (valuename, "%s_tcvaliditytime", interface); |
|---|
| 2071 | char *tcvaliditytime = websGetVar (wp, valuename, "0"); |
|---|
| 2072 | |
|---|
| 2073 | sprintf (valuename, "%s_midinterval", interface); |
|---|
| 2074 | char *midinterval = websGetVar (wp, valuename, "0"); |
|---|
| 2075 | sprintf (valuename, "%s_midvaliditytime", interface); |
|---|
| 2076 | char *midvaliditytime = websGetVar (wp, valuename, "0"); |
|---|
| 2077 | |
|---|
| 2078 | sprintf (valuename, "%s_hnainterval", interface); |
|---|
| 2079 | char *hnainterval = websGetVar (wp, valuename, "0"); |
|---|
| 2080 | sprintf (valuename, "%s_hnavaliditytime", interface); |
|---|
| 2081 | char *hnavaliditytime = websGetVar (wp, valuename, "0"); |
|---|
| 2082 | sprintf (newlist, "%s %s>%s>%s>%s>%s>%s>%s>%s>%s", newlist, interface, |
|---|
| 2083 | hellointerval, hellovaliditytime, tcinterval, tcvaliditytime, |
|---|
| 2084 | midinterval, midvaliditytime, hnainterval, hnavaliditytime); |
|---|
| 2085 | } |
|---|
| 2086 | nvram_set ("olsrd_interfaces", newlist); |
|---|
| 2087 | nvram_commit (); |
|---|
| 2088 | free (newlist); |
|---|
| 2089 | return; |
|---|
| 2090 | } |
|---|
| 2091 | |
|---|
| 2092 | void |
|---|
| 2093 | ej_show_olsrd (webs_t wp, int argc, char_t ** argv) |
|---|
| 2094 | { |
|---|
| 2095 | char *var = websGetVar (wp, "wk_mode", NULL); |
|---|
| 2096 | if (var == NULL) |
|---|
| 2097 | var = nvram_safe_get ("wk_mode"); |
|---|
| 2098 | if (!strcmp (var, "olsr")) |
|---|
| 2099 | { |
|---|
| 2100 | websWrite (wp, "<fieldset>\n"); |
|---|
| 2101 | show_legend (wp, "route.olsrd_legend", 1); |
|---|
| 2102 | show_inputlabel (wp, "route.olsrd_hna", "olsrd_hna", 32, "num", 32); |
|---|
| 2103 | show_inputlabel (wp, "route.olsrd_poll", "olsrd_pollsize", 5, "num", 5); |
|---|
| 2104 | showOptionsLabel (wp, "route.olsrd_tc", "olsrd_redundancy", |
|---|
| 2105 | "0 1 2", nvram_default_get ("olsrd_redundancy", "2")); |
|---|
| 2106 | show_inputlabel (wp, "route.olsrd_mpr", "olsrd_coverage", 5, "num", 5); |
|---|
| 2107 | showOption (wp, "route.olsrd_lqfe", "olsrd_lqfisheye"); |
|---|
| 2108 | show_inputlabel (wp, "route.olsrd_lqws", "olsrd_lqwinsize", 5, "num", |
|---|
| 2109 | 5); |
|---|
| 2110 | |
|---|
| 2111 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2112 | websWrite (wp, |
|---|
| 2113 | "<div class=\"label\"><script type=\"text/javascript\">Capture(route.olsrd_lqdmin)</script></div>"); |
|---|
| 2114 | websWrite (wp, |
|---|
| 2115 | "<input class=\"num\" size=\"5\" maxlength=\"5\" name=\"olsrd_lqdijkstramin\" onblur=\"olsrd_checkDijkstra(this.form)\" value=\"%s\" />\n", |
|---|
| 2116 | nvram_safe_get ("olsrd_lqdijkstramin")); |
|---|
| 2117 | websWrite (wp, "</div>\n"); |
|---|
| 2118 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2119 | websWrite (wp, |
|---|
| 2120 | "<div class=\"label\"><script type=\"text/javascript\">Capture(route.olsrd_lqdmax)</script></div>"); |
|---|
| 2121 | websWrite (wp, |
|---|
| 2122 | "<input class=\"num\" size=\"5\" maxlength=\"5\" name=\"olsrd_lqdijkstramax\" onblur=\"olsrd_checkDijkstra(this.form)\" value=\"%s\" />\n", |
|---|
| 2123 | nvram_safe_get ("olsrd_lqdijkstramax")); |
|---|
| 2124 | websWrite (wp, "</div>\n"); |
|---|
| 2125 | |
|---|
| 2126 | showOptionsLabel (wp, "route.olsrd_lqlvl", "olsrd_lqlevel", |
|---|
| 2127 | "0 1 2", nvram_default_get ("olsrd_lqlevel", "2")); |
|---|
| 2128 | showOption (wp, "route.olsrd_hysteresis", "olsrd_hysteresis"); |
|---|
| 2129 | char *wordlist = nvram_safe_get ("olsrd_interfaces"); |
|---|
| 2130 | char *next; |
|---|
| 2131 | char word[128]; |
|---|
| 2132 | int count = 0; |
|---|
| 2133 | foreach (word, wordlist, next) |
|---|
| 2134 | { |
|---|
| 2135 | char *interface = word; |
|---|
| 2136 | char *hellointerval = interface; |
|---|
| 2137 | strsep (&hellointerval, ">"); |
|---|
| 2138 | char *hellovaliditytime = hellointerval; |
|---|
| 2139 | strsep (&hellovaliditytime, ">"); |
|---|
| 2140 | char *tcinterval = hellovaliditytime; |
|---|
| 2141 | strsep (&tcinterval, ">"); |
|---|
| 2142 | char *tcvaliditytime = tcinterval; |
|---|
| 2143 | strsep (&tcvaliditytime, ">"); |
|---|
| 2144 | char *midinterval = tcvaliditytime; |
|---|
| 2145 | strsep (&midinterval, ">"); |
|---|
| 2146 | char *midvaliditytime = midinterval; |
|---|
| 2147 | strsep (&midvaliditytime, ">"); |
|---|
| 2148 | char *hnainterval = midvaliditytime; |
|---|
| 2149 | strsep (&hnainterval, ">"); |
|---|
| 2150 | char *hnavaliditytime = hnainterval; |
|---|
| 2151 | strsep (&hnavaliditytime, ">"); |
|---|
| 2152 | websWrite (wp, "<fieldset>\n"); |
|---|
| 2153 | show_legend (wp, interface, 0); |
|---|
| 2154 | char valuename[32]; |
|---|
| 2155 | sprintf (valuename, "%s_hellointerval", interface); |
|---|
| 2156 | show_custominputlabel (wp, "Hello Interval", valuename, hellointerval, |
|---|
| 2157 | 5); |
|---|
| 2158 | sprintf (valuename, "%s_hellovaliditytime", interface); |
|---|
| 2159 | show_custominputlabel (wp, "Hello Validity Time", valuename, |
|---|
| 2160 | hellovaliditytime, 5); |
|---|
| 2161 | |
|---|
| 2162 | sprintf (valuename, "%s_tcinterval", interface); |
|---|
| 2163 | show_custominputlabel (wp, "TC Interval", valuename, tcinterval, 5); |
|---|
| 2164 | sprintf (valuename, "%s_tcvaliditytime", interface); |
|---|
| 2165 | show_custominputlabel (wp, "TC Validity Time", valuename, |
|---|
| 2166 | tcvaliditytime, 5); |
|---|
| 2167 | |
|---|
| 2168 | sprintf (valuename, "%s_midinterval", interface); |
|---|
| 2169 | show_custominputlabel (wp, "MID Interval", valuename, midinterval, 5); |
|---|
| 2170 | sprintf (valuename, "%s_midvaliditytime", interface); |
|---|
| 2171 | show_custominputlabel (wp, "MID Validity Time", valuename, |
|---|
| 2172 | midvaliditytime, 5); |
|---|
| 2173 | |
|---|
| 2174 | sprintf (valuename, "%s_hnainterval", interface); |
|---|
| 2175 | show_custominputlabel (wp, "HNA Interval", valuename, hnainterval, 5); |
|---|
| 2176 | sprintf (valuename, "%s_hnavaliditytime", interface); |
|---|
| 2177 | show_custominputlabel (wp, "HNA Validity Time", valuename, |
|---|
| 2178 | hnavaliditytime, 5); |
|---|
| 2179 | websWrite (wp, |
|---|
| 2180 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"olsrd_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2181 | count); |
|---|
| 2182 | |
|---|
| 2183 | websWrite (wp, "</fieldset>\n"); |
|---|
| 2184 | count++; |
|---|
| 2185 | } |
|---|
| 2186 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2187 | websWrite (wp, |
|---|
| 2188 | "<div class=\"label\"><script type=\"text/javascript\">Capture(route.olsrd_newiface)</script></div>\n"); |
|---|
| 2189 | char buffer[256]; |
|---|
| 2190 | memset (buffer, 0, 256); |
|---|
| 2191 | getIfList (buffer, NULL); |
|---|
| 2192 | showOptions (wp, "olsrd_ifname", buffer, ""); |
|---|
| 2193 | websWrite (wp, " "); |
|---|
| 2194 | websWrite (wp, |
|---|
| 2195 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"olsrd_add_submit(this.form)\\\" />\");\n//]]>\n</script>\n"); |
|---|
| 2196 | websWrite (wp, "</div>\n"); |
|---|
| 2197 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 2198 | } |
|---|
| 2199 | } |
|---|
| 2200 | |
|---|
| 2201 | #endif |
|---|
| 2202 | #ifdef HAVE_VLANTAGGING |
|---|
| 2203 | |
|---|
| 2204 | |
|---|
| 2205 | void |
|---|
| 2206 | save_networking (webs_t wp) |
|---|
| 2207 | { |
|---|
| 2208 | char *value = websGetVar (wp, "action", ""); |
|---|
| 2209 | int vlancount = atoi (nvram_safe_get ("vlan_tagcount")); |
|---|
| 2210 | int bridgescount = atoi (nvram_safe_get ("bridges_count")); |
|---|
| 2211 | int bridgesifcount = atoi (nvram_safe_get ("bridgesif_count")); |
|---|
| 2212 | #ifdef HAVE_BONDING |
|---|
| 2213 | int bondcount = atoi (nvram_safe_get ("bonding_count")); |
|---|
| 2214 | #endif |
|---|
| 2215 | int i; |
|---|
| 2216 | //save vlan stuff |
|---|
| 2217 | char buffer[1024]; |
|---|
| 2218 | memset (buffer, 0, 1024); |
|---|
| 2219 | for (i = 0; i < vlancount; i++) |
|---|
| 2220 | { |
|---|
| 2221 | char *ifname, *tag; |
|---|
| 2222 | char var[32]; |
|---|
| 2223 | sprintf (var, "vlanifname%d", i); |
|---|
| 2224 | ifname = websGetVar (wp, var, NULL); |
|---|
| 2225 | if (!ifname) |
|---|
| 2226 | return; |
|---|
| 2227 | sprintf (var, "vlantag%d", i); |
|---|
| 2228 | tag = websGetVar (wp, var, NULL); |
|---|
| 2229 | if (!tag) |
|---|
| 2230 | return; |
|---|
| 2231 | strcat (buffer, ifname); |
|---|
| 2232 | strcat (buffer, ">"); |
|---|
| 2233 | strcat (buffer, tag); |
|---|
| 2234 | if (i < vlancount - 1) |
|---|
| 2235 | strcat (buffer, " "); |
|---|
| 2236 | } |
|---|
| 2237 | nvram_set ("vlan_tags", buffer); |
|---|
| 2238 | // save bonds |
|---|
| 2239 | memset (buffer, 0, 1024); |
|---|
| 2240 | #ifdef HAVE_BONDING |
|---|
| 2241 | char *bondingnumber = websGetVar (wp, "bonding_number", NULL); |
|---|
| 2242 | if (bondingnumber) |
|---|
| 2243 | nvram_set ("bonding_number", bondingnumber); |
|---|
| 2244 | char *bondingtype = websGetVar (wp, "bonding_type", NULL); |
|---|
| 2245 | if (bondingtype) |
|---|
| 2246 | nvram_set ("bonding_type", bondingtype); |
|---|
| 2247 | for (i = 0; i < bondcount; i++) |
|---|
| 2248 | { |
|---|
| 2249 | char *ifname, *tag; |
|---|
| 2250 | char var[32]; |
|---|
| 2251 | sprintf (var, "bondingifname%d", i); |
|---|
| 2252 | ifname = websGetVar (wp, var, NULL); |
|---|
| 2253 | if (!ifname) |
|---|
| 2254 | return; |
|---|
| 2255 | sprintf (var, "bondingattach%d", i); |
|---|
| 2256 | tag = websGetVar (wp, var, NULL); |
|---|
| 2257 | if (!tag) |
|---|
| 2258 | return; |
|---|
| 2259 | strcat (buffer, ifname); |
|---|
| 2260 | strcat (buffer, ">"); |
|---|
| 2261 | strcat (buffer, tag); |
|---|
| 2262 | if (i < bondcount - 1) |
|---|
| 2263 | strcat (buffer, " "); |
|---|
| 2264 | } |
|---|
| 2265 | nvram_set ("bondings", buffer); |
|---|
| 2266 | memset (buffer, 0, 1024); |
|---|
| 2267 | #endif |
|---|
| 2268 | |
|---|
| 2269 | // save bridges |
|---|
| 2270 | |
|---|
| 2271 | for (i = 0; i < bridgescount; i++) |
|---|
| 2272 | { |
|---|
| 2273 | char *ifname, *tag, *prio; |
|---|
| 2274 | char var[32]; |
|---|
| 2275 | char ipaddr[32]; |
|---|
| 2276 | char netmask[32]; |
|---|
| 2277 | char n[32]; |
|---|
| 2278 | memset (ipaddr, 0, 32); |
|---|
| 2279 | memset (netmask, 0, 32); |
|---|
| 2280 | sprintf (var, "bridgename%d", i); |
|---|
| 2281 | ifname = websGetVar (wp, var, NULL); |
|---|
| 2282 | if (!ifname) |
|---|
| 2283 | return; |
|---|
| 2284 | sprintf (var, "bridgestp%d", i); |
|---|
| 2285 | tag = websGetVar (wp, var, NULL); |
|---|
| 2286 | if (!tag) |
|---|
| 2287 | return; |
|---|
| 2288 | sprintf (var, "bridgeprio%d", i); |
|---|
| 2289 | prio = websGetVar (wp, var, NULL); |
|---|
| 2290 | if (!prio) |
|---|
| 2291 | prio = "32768"; |
|---|
| 2292 | if (strlen (prio) == 0) |
|---|
| 2293 | prio = "32768"; |
|---|
| 2294 | |
|---|
| 2295 | sprintf (n, "%s_ipaddr", ifname); |
|---|
| 2296 | if (get_merge_ipaddr (wp, n, ipaddr)) |
|---|
| 2297 | nvram_set (n, ipaddr); |
|---|
| 2298 | sprintf (n, "%s_netmask", ifname); |
|---|
| 2299 | if (get_merge_ipaddr (wp, n, netmask)) |
|---|
| 2300 | nvram_set (n, netmask); |
|---|
| 2301 | |
|---|
| 2302 | strcat (buffer, ifname); |
|---|
| 2303 | strcat (buffer, ">"); |
|---|
| 2304 | if (!strcmp (tag, "On")) |
|---|
| 2305 | strcat (buffer, "On"); |
|---|
| 2306 | else |
|---|
| 2307 | strcat (buffer, "Off"); |
|---|
| 2308 | strcat (buffer, ">"); |
|---|
| 2309 | strcat (buffer, prio); |
|---|
| 2310 | if (i < bridgescount - 1) |
|---|
| 2311 | strcat (buffer, " "); |
|---|
| 2312 | } |
|---|
| 2313 | nvram_set ("bridges", buffer); |
|---|
| 2314 | // save bridge assignment |
|---|
| 2315 | memset (buffer, 0, 1024); |
|---|
| 2316 | for (i = 0; i < bridgesifcount; i++) |
|---|
| 2317 | { |
|---|
| 2318 | char *ifname, *tag, *prio; |
|---|
| 2319 | char var[32]; |
|---|
| 2320 | sprintf (var, "bridge%d", i); |
|---|
| 2321 | ifname = websGetVar (wp, var, NULL); |
|---|
| 2322 | if (!ifname) |
|---|
| 2323 | return; |
|---|
| 2324 | sprintf (var, "bridgeif%d", i); |
|---|
| 2325 | tag = websGetVar (wp, var, NULL); |
|---|
| 2326 | if (!tag) |
|---|
| 2327 | return; |
|---|
| 2328 | sprintf (var, "bridgeifprio%d", i); |
|---|
| 2329 | prio = websGetVar (wp, var, NULL); |
|---|
| 2330 | if (!prio) |
|---|
| 2331 | prio = "128"; |
|---|
| 2332 | if (strlen (prio) == 0) |
|---|
| 2333 | prio = "128"; |
|---|
| 2334 | strcat (buffer, ifname); |
|---|
| 2335 | strcat (buffer, ">"); |
|---|
| 2336 | strcat (buffer, tag); |
|---|
| 2337 | strcat (buffer, ">"); |
|---|
| 2338 | strcat (buffer, prio); |
|---|
| 2339 | if (i < bridgesifcount - 1) |
|---|
| 2340 | strcat (buffer, " "); |
|---|
| 2341 | } |
|---|
| 2342 | nvram_set ("bridgesif", buffer); |
|---|
| 2343 | #ifdef HAVE_PORTSETUP |
|---|
| 2344 | validate_portsetup (wp, NULL, NULL); |
|---|
| 2345 | #endif |
|---|
| 2346 | |
|---|
| 2347 | addAction ("index"); |
|---|
| 2348 | if (!strcmp (value, "ApplyTake")) |
|---|
| 2349 | { |
|---|
| 2350 | nvram_commit (); |
|---|
| 2351 | service_restart (); |
|---|
| 2352 | } |
|---|
| 2353 | } |
|---|
| 2354 | |
|---|
| 2355 | void |
|---|
| 2356 | add_vlan (webs_t wp) |
|---|
| 2357 | { |
|---|
| 2358 | static char word[256]; |
|---|
| 2359 | char *next, *wordlist; |
|---|
| 2360 | int count = 0; |
|---|
| 2361 | int realcount = atoi (nvram_safe_get ("vlan_tagcount")); |
|---|
| 2362 | if (realcount == 0) |
|---|
| 2363 | { |
|---|
| 2364 | wordlist = nvram_safe_get ("vlan_tags"); |
|---|
| 2365 | foreach (word, wordlist, next) |
|---|
| 2366 | { |
|---|
| 2367 | count++; |
|---|
| 2368 | } |
|---|
| 2369 | realcount = count; |
|---|
| 2370 | } |
|---|
| 2371 | realcount++; |
|---|
| 2372 | char var[32]; |
|---|
| 2373 | sprintf (var, "%d", realcount); |
|---|
| 2374 | nvram_set ("vlan_tagcount", var); |
|---|
| 2375 | nvram_commit (); |
|---|
| 2376 | return; |
|---|
| 2377 | } |
|---|
| 2378 | |
|---|
| 2379 | void |
|---|
| 2380 | del_vlan (webs_t wp) |
|---|
| 2381 | { |
|---|
| 2382 | static char word[256]; |
|---|
| 2383 | int realcount = 0; |
|---|
| 2384 | char *next, *wordlist, *newwordlist; |
|---|
| 2385 | char *val = websGetVar (wp, "del_value", NULL); |
|---|
| 2386 | if (val == NULL) |
|---|
| 2387 | return; |
|---|
| 2388 | int todel = atoi (val); |
|---|
| 2389 | wordlist = nvram_safe_get ("vlan_tags"); |
|---|
| 2390 | newwordlist = (char *) malloc (strlen (wordlist)); |
|---|
| 2391 | memset (newwordlist, 0, strlen (wordlist)); |
|---|
| 2392 | int count = 0; |
|---|
| 2393 | foreach (word, wordlist, next) |
|---|
| 2394 | { |
|---|
| 2395 | if (count != todel) |
|---|
| 2396 | { |
|---|
| 2397 | strcat (newwordlist, word); |
|---|
| 2398 | strcat (newwordlist, " "); |
|---|
| 2399 | } |
|---|
| 2400 | count++; |
|---|
| 2401 | } |
|---|
| 2402 | |
|---|
| 2403 | char var[32]; |
|---|
| 2404 | realcount = atoi (nvram_safe_get ("vlan_tagcount")) - 1; |
|---|
| 2405 | sprintf (var, "%d", realcount); |
|---|
| 2406 | nvram_set ("vlan_tagcount", var); |
|---|
| 2407 | nvram_set ("vlan_tags", newwordlist); |
|---|
| 2408 | nvram_commit (); |
|---|
| 2409 | free (newwordlist); |
|---|
| 2410 | |
|---|
| 2411 | return; |
|---|
| 2412 | } |
|---|
| 2413 | |
|---|
| 2414 | #ifdef HAVE_BONDING |
|---|
| 2415 | void |
|---|
| 2416 | add_bond (webs_t wp) |
|---|
| 2417 | { |
|---|
| 2418 | static char word[256]; |
|---|
| 2419 | char *next, *wordlist; |
|---|
| 2420 | int count = 0; |
|---|
| 2421 | int realcount = atoi (nvram_safe_get ("bonding_count")); |
|---|
| 2422 | if (realcount == 0) |
|---|
| 2423 | { |
|---|
| 2424 | wordlist = nvram_safe_get ("bondings"); |
|---|
| 2425 | foreach (word, wordlist, next) |
|---|
| 2426 | { |
|---|
| 2427 | count++; |
|---|
| 2428 | } |
|---|
| 2429 | realcount = count; |
|---|
| 2430 | } |
|---|
| 2431 | realcount++; |
|---|
| 2432 | char var[32]; |
|---|
| 2433 | sprintf (var, "%d", realcount); |
|---|
| 2434 | nvram_set ("bonding_count", var); |
|---|
| 2435 | nvram_commit (); |
|---|
| 2436 | return; |
|---|
| 2437 | } |
|---|
| 2438 | |
|---|
| 2439 | |
|---|
| 2440 | void |
|---|
| 2441 | del_bond (webs_t wp) |
|---|
| 2442 | { |
|---|
| 2443 | static char word[256]; |
|---|
| 2444 | int realcount = 0; |
|---|
| 2445 | char *next, *wordlist, *newwordlist; |
|---|
| 2446 | char *val = websGetVar (wp, "del_value", NULL); |
|---|
| 2447 | if (val == NULL) |
|---|
| 2448 | return; |
|---|
| 2449 | int todel = atoi (val); |
|---|
| 2450 | wordlist = nvram_safe_get ("bondings"); |
|---|
| 2451 | newwordlist = (char *) malloc (strlen (wordlist)); |
|---|
| 2452 | memset (newwordlist, 0, strlen (wordlist)); |
|---|
| 2453 | int count = 0; |
|---|
| 2454 | foreach (word, wordlist, next) |
|---|
| 2455 | { |
|---|
| 2456 | if (count != todel) |
|---|
| 2457 | { |
|---|
| 2458 | strcat (newwordlist, word); |
|---|
| 2459 | strcat (newwordlist, " "); |
|---|
| 2460 | } |
|---|
| 2461 | count++; |
|---|
| 2462 | } |
|---|
| 2463 | |
|---|
| 2464 | char var[32]; |
|---|
| 2465 | realcount = atoi (nvram_safe_get ("bonding_count")) - 1; |
|---|
| 2466 | sprintf (var, "%d", realcount); |
|---|
| 2467 | nvram_set ("bonding_count", var); |
|---|
| 2468 | nvram_set ("bondings", newwordlist); |
|---|
| 2469 | nvram_commit (); |
|---|
| 2470 | free (newwordlist); |
|---|
| 2471 | |
|---|
| 2472 | return; |
|---|
| 2473 | } |
|---|
| 2474 | |
|---|
| 2475 | |
|---|
| 2476 | |
|---|
| 2477 | |
|---|
| 2478 | void |
|---|
| 2479 | ej_show_bondings (webs_t wp, int argc, char_t ** argv) |
|---|
| 2480 | { |
|---|
| 2481 | char buffer[256]; |
|---|
| 2482 | char bufferif[512]; |
|---|
| 2483 | char bondnames[256]; |
|---|
| 2484 | int count = 0; |
|---|
| 2485 | static char word[256]; |
|---|
| 2486 | char *next, *wordlist; |
|---|
| 2487 | memset (buffer, 0, 256); |
|---|
| 2488 | memset (bondnames, 0, 256); |
|---|
| 2489 | memset (bufferif, 0, 512); |
|---|
| 2490 | websWrite (wp, "<h2>Bonding</h2>\n"); |
|---|
| 2491 | websWrite (wp, "<fieldset>\n"); |
|---|
| 2492 | websWrite (wp, "<legend>Bonding</legend>\n"); |
|---|
| 2493 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2494 | websWrite (wp, "<div class=\"label\">Bonding Type</div>\n", count); |
|---|
| 2495 | showOptions (wp, "bonding_type", |
|---|
| 2496 | "balance-rr active-backup balance-xor broadcast 802.3ad balance-tlb balance-alb", |
|---|
| 2497 | nvram_default_get ("bonding_type", "balance-rr")); |
|---|
| 2498 | websWrite (wp, " Bonding Interfaces "); |
|---|
| 2499 | websWrite (wp, |
|---|
| 2500 | "<input class=\"num\" name=\"bonding_number\"size=\"5\" value=\"%s\" />\n", |
|---|
| 2501 | nvram_default_get ("bonding_number", "1")); |
|---|
| 2502 | websWrite (wp, "</div>\n"); |
|---|
| 2503 | |
|---|
| 2504 | getIfList (bufferif, "eth"); |
|---|
| 2505 | int i; |
|---|
| 2506 | #ifdef HAVE_XSCALE |
|---|
| 2507 | memset (buffer, 0, 256); |
|---|
| 2508 | getIfList (buffer, "ixp"); |
|---|
| 2509 | sprintf (bufferif, "%s %s", bufferif, buffer); |
|---|
| 2510 | #endif |
|---|
| 2511 | memset (buffer, 0, 256); |
|---|
| 2512 | getIfList (buffer, "br"); |
|---|
| 2513 | sprintf (bufferif, "%s %s", bufferif, buffer); |
|---|
| 2514 | #ifdef HAVE_MADWIFI |
|---|
| 2515 | int c = getifcount ("wifi"); |
|---|
| 2516 | for (i = 0; i < c; i++) |
|---|
| 2517 | { |
|---|
| 2518 | char ath[32]; |
|---|
| 2519 | sprintf (ath, "ath%d_bridged", i); |
|---|
| 2520 | if (nvram_default_match (ath, "0", "1")) |
|---|
| 2521 | { |
|---|
| 2522 | sprintf (bufferif, "%s ath%d", bufferif, i); |
|---|
| 2523 | char vifs[32]; |
|---|
| 2524 | sprintf (vifs, "ath%d_vifs", i); |
|---|
| 2525 | sprintf (bufferif, "%s %s", bufferif, nvram_safe_get (vifs)); |
|---|
| 2526 | } |
|---|
| 2527 | } |
|---|
| 2528 | #endif |
|---|
| 2529 | |
|---|
| 2530 | for (i = 0; i < atoi (nvram_safe_get ("bonding_number")); i++) |
|---|
| 2531 | { |
|---|
| 2532 | sprintf (bondnames, "%s bond%d", bondnames, i); |
|---|
| 2533 | } |
|---|
| 2534 | int totalcount = 0; |
|---|
| 2535 | int realcount = atoi (nvram_default_get ("bonding_count", "0")); |
|---|
| 2536 | wordlist = nvram_safe_get ("bondings"); |
|---|
| 2537 | foreach (word, wordlist, next) |
|---|
| 2538 | { |
|---|
| 2539 | char *port = word; |
|---|
| 2540 | char *tag = strsep (&port, ">"); |
|---|
| 2541 | if (!tag || !port) |
|---|
| 2542 | break; |
|---|
| 2543 | char vlan_name[32]; |
|---|
| 2544 | // sprintf (vlan_name, "%s.%s", tag, port); |
|---|
| 2545 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2546 | websWrite (wp, "<div class=\"label\">Bonding %d Assignment</div>\n", |
|---|
| 2547 | count); |
|---|
| 2548 | websWrite (wp, " Bond "); |
|---|
| 2549 | sprintf (vlan_name, "bondingifname%d", count); |
|---|
| 2550 | showOptions (wp, vlan_name, bondnames, tag); |
|---|
| 2551 | sprintf (vlan_name, "bondingattach%d", count); |
|---|
| 2552 | websWrite (wp, " Slave "); |
|---|
| 2553 | showOptions (wp, vlan_name, bufferif, port); |
|---|
| 2554 | websWrite (wp, |
|---|
| 2555 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"bond_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2556 | count); |
|---|
| 2557 | websWrite (wp, "</div>\n"); |
|---|
| 2558 | count++; |
|---|
| 2559 | } |
|---|
| 2560 | totalcount = count; |
|---|
| 2561 | for (i = count; i < realcount; i++) |
|---|
| 2562 | { |
|---|
| 2563 | char vlan_name[32]; |
|---|
| 2564 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2565 | websWrite (wp, "<div class=\"label\">Bonding %d Interface</div>\n", i); |
|---|
| 2566 | websWrite (wp, " Bond "); |
|---|
| 2567 | sprintf (vlan_name, "bondingifname%d", i); |
|---|
| 2568 | showOptions (wp, vlan_name, bondnames, ""); |
|---|
| 2569 | sprintf (vlan_name, "bondingattach%d", i); |
|---|
| 2570 | websWrite (wp, " Slave "); |
|---|
| 2571 | showOptions (wp, vlan_name, bufferif, ""); |
|---|
| 2572 | websWrite (wp, |
|---|
| 2573 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"bond_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2574 | i); |
|---|
| 2575 | websWrite (wp, "</div>\n"); |
|---|
| 2576 | totalcount++; |
|---|
| 2577 | } |
|---|
| 2578 | char var[32]; |
|---|
| 2579 | sprintf (var, "%d", totalcount); |
|---|
| 2580 | nvram_set ("bonding_count", var); |
|---|
| 2581 | websWrite (wp, |
|---|
| 2582 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"bond_add_submit(this.form)\\\" />\");\n//]]>\n</script>\n"); |
|---|
| 2583 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 2584 | } |
|---|
| 2585 | #endif |
|---|
| 2586 | void |
|---|
| 2587 | ej_show_vlantagging (webs_t wp, int argc, char_t ** argv) |
|---|
| 2588 | { |
|---|
| 2589 | char buffer[256]; |
|---|
| 2590 | int count = 0; |
|---|
| 2591 | static char word[256]; |
|---|
| 2592 | char *next, *wordlist; |
|---|
| 2593 | memset (buffer, 0, 256); |
|---|
| 2594 | getIfList (buffer, NULL); |
|---|
| 2595 | int totalcount = 0; |
|---|
| 2596 | int realcount = atoi (nvram_default_get ("vlan_tagcount", "0")); |
|---|
| 2597 | wordlist = nvram_safe_get ("vlan_tags"); |
|---|
| 2598 | foreach (word, wordlist, next) |
|---|
| 2599 | { |
|---|
| 2600 | char *port = word; |
|---|
| 2601 | char *tag = strsep (&port, ">"); |
|---|
| 2602 | if (!tag || !port) |
|---|
| 2603 | break; |
|---|
| 2604 | char vlan_name[32]; |
|---|
| 2605 | // sprintf (vlan_name, "%s.%s", tag, port); |
|---|
| 2606 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2607 | websWrite (wp, "<div class=\"label\">VLAN%d Interface</div>\n", count); |
|---|
| 2608 | sprintf (vlan_name, "vlanifname%d", count); |
|---|
| 2609 | showOptions (wp, vlan_name, buffer, tag); |
|---|
| 2610 | sprintf (vlan_name, "vlantag%d", count); |
|---|
| 2611 | websWrite (wp, " Tag Number "); |
|---|
| 2612 | websWrite (wp, |
|---|
| 2613 | "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n", |
|---|
| 2614 | vlan_name, port); |
|---|
| 2615 | websWrite (wp, |
|---|
| 2616 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"vlan_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2617 | count); |
|---|
| 2618 | websWrite (wp, "</div>\n"); |
|---|
| 2619 | count++; |
|---|
| 2620 | } |
|---|
| 2621 | totalcount = count; |
|---|
| 2622 | int i; |
|---|
| 2623 | for (i = count; i < realcount; i++) |
|---|
| 2624 | { |
|---|
| 2625 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2626 | websWrite (wp, "<div class=\"label\">VLAN%d Interface</div>\n", i); |
|---|
| 2627 | char vlan_name[32]; |
|---|
| 2628 | sprintf (vlan_name, "vlanifname%d", i); |
|---|
| 2629 | showOptions (wp, vlan_name, buffer, ""); |
|---|
| 2630 | sprintf (vlan_name, "vlantag%d", i); |
|---|
| 2631 | websWrite (wp, " Tag Number "); |
|---|
| 2632 | websWrite (wp, |
|---|
| 2633 | "<input class=\"num\" name=\"%s\" size=\"5\" value=\"0\" />\n", |
|---|
| 2634 | vlan_name); |
|---|
| 2635 | websWrite (wp, |
|---|
| 2636 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"vlan_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2637 | i); |
|---|
| 2638 | websWrite (wp, "</div>\n"); |
|---|
| 2639 | totalcount++; |
|---|
| 2640 | } |
|---|
| 2641 | char var[32]; |
|---|
| 2642 | sprintf (var, "%d", totalcount); |
|---|
| 2643 | nvram_set ("vlan_tagcount", var); |
|---|
| 2644 | websWrite (wp, |
|---|
| 2645 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"vlan_add_submit(this.form)\\\" />\");\n//]]>\n</script>\n"); |
|---|
| 2646 | } |
|---|
| 2647 | |
|---|
| 2648 | void |
|---|
| 2649 | del_bridge (webs_t wp) |
|---|
| 2650 | { |
|---|
| 2651 | static char word[256]; |
|---|
| 2652 | int realcount = 0; |
|---|
| 2653 | char *next, *wordlist, *newwordlist; |
|---|
| 2654 | char *val = websGetVar (wp, "del_value", NULL); |
|---|
| 2655 | if (val == NULL) |
|---|
| 2656 | return; |
|---|
| 2657 | int todel = atoi (val); |
|---|
| 2658 | wordlist = nvram_safe_get ("bridges"); |
|---|
| 2659 | newwordlist = (char *) malloc (strlen (wordlist)); |
|---|
| 2660 | memset (newwordlist, 0, strlen (wordlist)); |
|---|
| 2661 | int count = 0; |
|---|
| 2662 | foreach (word, wordlist, next) |
|---|
| 2663 | { |
|---|
| 2664 | if (count != todel) |
|---|
| 2665 | { |
|---|
| 2666 | strcat (newwordlist, word); |
|---|
| 2667 | strcat (newwordlist, " "); |
|---|
| 2668 | } |
|---|
| 2669 | count++; |
|---|
| 2670 | } |
|---|
| 2671 | |
|---|
| 2672 | realcount = atoi (nvram_safe_get ("bridges_count")) - 1; |
|---|
| 2673 | char var[32]; |
|---|
| 2674 | sprintf (var, "%d", realcount); |
|---|
| 2675 | nvram_set ("bridges_count", var); |
|---|
| 2676 | nvram_set ("bridges", newwordlist); |
|---|
| 2677 | nvram_commit (); |
|---|
| 2678 | free (newwordlist); |
|---|
| 2679 | |
|---|
| 2680 | return; |
|---|
| 2681 | } |
|---|
| 2682 | |
|---|
| 2683 | void |
|---|
| 2684 | add_bridge (webs_t wp) |
|---|
| 2685 | { |
|---|
| 2686 | static char word[256]; |
|---|
| 2687 | char *next, *wordlist; |
|---|
| 2688 | int count = 0; |
|---|
| 2689 | int realcount = atoi (nvram_safe_get ("bridges_count")); |
|---|
| 2690 | if (realcount == 0) |
|---|
| 2691 | { |
|---|
| 2692 | wordlist = nvram_safe_get ("bridges"); |
|---|
| 2693 | foreach (word, wordlist, next) |
|---|
| 2694 | { |
|---|
| 2695 | count++; |
|---|
| 2696 | } |
|---|
| 2697 | realcount = count; |
|---|
| 2698 | } |
|---|
| 2699 | realcount++; |
|---|
| 2700 | char var[32]; |
|---|
| 2701 | sprintf (var, "%d", realcount); |
|---|
| 2702 | nvram_set ("bridges_count", var); |
|---|
| 2703 | nvram_commit (); |
|---|
| 2704 | return; |
|---|
| 2705 | } |
|---|
| 2706 | |
|---|
| 2707 | void |
|---|
| 2708 | ej_show_bridgenames (webs_t wp, int argc, char_t ** argv) |
|---|
| 2709 | { |
|---|
| 2710 | char buffer[256]; |
|---|
| 2711 | int count = 0; |
|---|
| 2712 | static char word[256]; |
|---|
| 2713 | char *next, *wordlist; |
|---|
| 2714 | memset (buffer, 0, 256); |
|---|
| 2715 | getIfList (buffer, NULL); |
|---|
| 2716 | int realcount = atoi (nvram_default_get ("bridges_count", "0")); |
|---|
| 2717 | wordlist = nvram_safe_get ("bridges"); |
|---|
| 2718 | foreach (word, wordlist, next) |
|---|
| 2719 | { |
|---|
| 2720 | char *port = word; |
|---|
| 2721 | char *tag = strsep (&port, ">"); |
|---|
| 2722 | char *prio = port; |
|---|
| 2723 | strsep (&prio, ">"); |
|---|
| 2724 | if (!tag || !port) |
|---|
| 2725 | break; |
|---|
| 2726 | char vlan_name[32]; |
|---|
| 2727 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2728 | websWrite (wp, "<div class=\"label\">Bridge %d</div>\n", count); |
|---|
| 2729 | sprintf (vlan_name, "bridgename%d", count); |
|---|
| 2730 | websWrite (wp, |
|---|
| 2731 | "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n", |
|---|
| 2732 | vlan_name, tag); |
|---|
| 2733 | websWrite (wp, " STP "); |
|---|
| 2734 | sprintf (vlan_name, "bridgestp%d", count); |
|---|
| 2735 | showOptions (wp, vlan_name, "On Off", port); |
|---|
| 2736 | websWrite (wp, " Prio "); |
|---|
| 2737 | sprintf (vlan_name, "bridgeprio%d", count); |
|---|
| 2738 | websWrite (wp, |
|---|
| 2739 | "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n", |
|---|
| 2740 | vlan_name, prio != NULL ? prio : "32768"); |
|---|
| 2741 | websWrite (wp, |
|---|
| 2742 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"bridge_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2743 | count); |
|---|
| 2744 | websWrite (wp, "</div>\n"); |
|---|
| 2745 | show_ipnetmask (wp, tag); |
|---|
| 2746 | count++; |
|---|
| 2747 | } |
|---|
| 2748 | int i; |
|---|
| 2749 | int totalcount = count; |
|---|
| 2750 | for (i = count; i < realcount; i++) |
|---|
| 2751 | { |
|---|
| 2752 | char vlan_name[32]; |
|---|
| 2753 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2754 | websWrite (wp, "<div class=\"label\">Bridge %d</div>\n", i); |
|---|
| 2755 | sprintf (vlan_name, "bridgename%d", i); |
|---|
| 2756 | websWrite (wp, "<input class=\"num\" name=\"%s\"size=\"5\" />\n", |
|---|
| 2757 | vlan_name); |
|---|
| 2758 | websWrite (wp, " STP "); |
|---|
| 2759 | sprintf (vlan_name, "bridgestp%d", i); |
|---|
| 2760 | showOptions (wp, vlan_name, "On Off", "On"); |
|---|
| 2761 | websWrite (wp, " Prio "); |
|---|
| 2762 | sprintf (vlan_name, "bridgeprio%d", i); |
|---|
| 2763 | websWrite (wp, |
|---|
| 2764 | "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n", |
|---|
| 2765 | vlan_name, "32768"); |
|---|
| 2766 | websWrite (wp, |
|---|
| 2767 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"bridge_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2768 | i); |
|---|
| 2769 | websWrite (wp, "</div>\n"); |
|---|
| 2770 | totalcount++; |
|---|
| 2771 | } |
|---|
| 2772 | websWrite (wp, |
|---|
| 2773 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"bridge_add_submit(this.form)\\\" />\");\n//]]>\n</script>\n"); |
|---|
| 2774 | char var[32]; |
|---|
| 2775 | sprintf (var, "%d", totalcount); |
|---|
| 2776 | nvram_set ("bridges_count", var); |
|---|
| 2777 | } |
|---|
| 2778 | |
|---|
| 2779 | void |
|---|
| 2780 | ej_show_bridgetable (webs_t wp, int argc, char_t ** argv) |
|---|
| 2781 | { |
|---|
| 2782 | |
|---|
| 2783 | FILE *f; |
|---|
| 2784 | char buf[128]; |
|---|
| 2785 | char brname[32]; |
|---|
| 2786 | char brstp[8]; |
|---|
| 2787 | char brif[16]; |
|---|
| 2788 | int count = 0; |
|---|
| 2789 | |
|---|
| 2790 | system ("brctl show > /tmp/.brtable"); |
|---|
| 2791 | |
|---|
| 2792 | if ((f = fopen ("/tmp/.brtable", "r")) != NULL) |
|---|
| 2793 | { |
|---|
| 2794 | |
|---|
| 2795 | while (fgets (buf, sizeof (buf), f)) |
|---|
| 2796 | { |
|---|
| 2797 | |
|---|
| 2798 | if (count) //skip line 0 |
|---|
| 2799 | { |
|---|
| 2800 | strcpy (brname, ""); |
|---|
| 2801 | strcpy (brstp, ""); |
|---|
| 2802 | strcpy (brif, ""); |
|---|
| 2803 | |
|---|
| 2804 | if (strncmp (buf, "\t\t\t", 3) != 0) |
|---|
| 2805 | { |
|---|
| 2806 | if (count != 1) |
|---|
| 2807 | websWrite (wp, "\',"); //close |
|---|
| 2808 | sscanf (buf, "%s %*s %s %s", brname, brstp, brif); |
|---|
| 2809 | websWrite (wp, "\'%s\',\'%s\',\'%s ", brname, brstp, brif); |
|---|
| 2810 | } |
|---|
| 2811 | else |
|---|
| 2812 | { |
|---|
| 2813 | sscanf (buf, "%s", brif); |
|---|
| 2814 | websWrite (wp, "%s ", brif); |
|---|
| 2815 | } |
|---|
| 2816 | } |
|---|
| 2817 | count++; |
|---|
| 2818 | } |
|---|
| 2819 | |
|---|
| 2820 | websWrite (wp, "\'"); //close |
|---|
| 2821 | fclose (f); |
|---|
| 2822 | unlink ("/tmp/.brtable"); |
|---|
| 2823 | } |
|---|
| 2824 | return; |
|---|
| 2825 | } |
|---|
| 2826 | |
|---|
| 2827 | void |
|---|
| 2828 | del_bridgeif (webs_t wp) |
|---|
| 2829 | { |
|---|
| 2830 | static char word[256]; |
|---|
| 2831 | int realcount = 0; |
|---|
| 2832 | char *next, *wordlist, *newwordlist; |
|---|
| 2833 | char *val = websGetVar (wp, "del_value", NULL); |
|---|
| 2834 | if (val == NULL) |
|---|
| 2835 | return; |
|---|
| 2836 | int todel = atoi (val); |
|---|
| 2837 | wordlist = nvram_safe_get ("bridgesif"); |
|---|
| 2838 | newwordlist = (char *) malloc (strlen (wordlist)); |
|---|
| 2839 | memset (newwordlist, 0, strlen (wordlist)); |
|---|
| 2840 | int count = 0; |
|---|
| 2841 | foreach (word, wordlist, next) |
|---|
| 2842 | { |
|---|
| 2843 | if (count != todel) |
|---|
| 2844 | { |
|---|
| 2845 | strcat (newwordlist, word); |
|---|
| 2846 | strcat (newwordlist, " "); |
|---|
| 2847 | } |
|---|
| 2848 | count++; |
|---|
| 2849 | } |
|---|
| 2850 | |
|---|
| 2851 | char var[32]; |
|---|
| 2852 | realcount = atoi (nvram_safe_get ("bridgesif_count")) - 1; |
|---|
| 2853 | sprintf (var, "%d", realcount); |
|---|
| 2854 | nvram_set ("bridgesif_count", var); |
|---|
| 2855 | nvram_set ("bridgesif", newwordlist); |
|---|
| 2856 | nvram_commit (); |
|---|
| 2857 | free (newwordlist); |
|---|
| 2858 | |
|---|
| 2859 | return; |
|---|
| 2860 | } |
|---|
| 2861 | |
|---|
| 2862 | void |
|---|
| 2863 | add_bridgeif (webs_t wp) |
|---|
| 2864 | { |
|---|
| 2865 | |
|---|
| 2866 | static char word[256]; |
|---|
| 2867 | char *next, *wordlist; |
|---|
| 2868 | int count = 0; |
|---|
| 2869 | int realcount = atoi (nvram_safe_get ("bridgesif_count")); |
|---|
| 2870 | if (realcount == 0) |
|---|
| 2871 | { |
|---|
| 2872 | wordlist = nvram_safe_get ("bridgesif"); |
|---|
| 2873 | foreach (word, wordlist, next) |
|---|
| 2874 | { |
|---|
| 2875 | count++; |
|---|
| 2876 | } |
|---|
| 2877 | realcount = count; |
|---|
| 2878 | } |
|---|
| 2879 | realcount++; |
|---|
| 2880 | char var[32]; |
|---|
| 2881 | sprintf (var, "%d", realcount); |
|---|
| 2882 | nvram_set ("bridgesif_count", var); |
|---|
| 2883 | nvram_commit (); |
|---|
| 2884 | return; |
|---|
| 2885 | } |
|---|
| 2886 | |
|---|
| 2887 | void |
|---|
| 2888 | ej_show_bridgeifnames (webs_t wp, int argc, char_t ** argv) |
|---|
| 2889 | { |
|---|
| 2890 | char bufferif[512]; |
|---|
| 2891 | char bufferif2[256]; |
|---|
| 2892 | char finalbuffer[512]; |
|---|
| 2893 | int count = 0; |
|---|
| 2894 | static char word[256]; |
|---|
| 2895 | char *next, *wordlist; |
|---|
| 2896 | memset (bufferif, 0, 512); |
|---|
| 2897 | memset (bufferif2, 0, 256); |
|---|
| 2898 | getIfList (bufferif, "eth"); |
|---|
| 2899 | #ifdef HAVE_GATEWORX |
|---|
| 2900 | getIfList (bufferif2, "ixp"); |
|---|
| 2901 | sprintf (bufferif, "%s %s", bufferif, bufferif2); |
|---|
| 2902 | #endif |
|---|
| 2903 | memset (bufferif2, 0, 256); |
|---|
| 2904 | getIfList (bufferif2, "vlan"); |
|---|
| 2905 | sprintf (bufferif, "%s %s", bufferif, bufferif2); |
|---|
| 2906 | |
|---|
| 2907 | memset (bufferif2, 0, 256); |
|---|
| 2908 | getIfList (bufferif2, "br"); |
|---|
| 2909 | foreach (word, bufferif2, next) |
|---|
| 2910 | { |
|---|
| 2911 | if (contains (word, '.')) |
|---|
| 2912 | sprintf (bufferif, "%s %s", bufferif, word); |
|---|
| 2913 | } |
|---|
| 2914 | int i; |
|---|
| 2915 | #ifdef HAVE_MADWIFI |
|---|
| 2916 | int c = getifcount ("wifi"); |
|---|
| 2917 | for (i = 0; i < c; i++) |
|---|
| 2918 | { |
|---|
| 2919 | char ath[32]; |
|---|
| 2920 | sprintf (ath, "ath%d_bridged", i); |
|---|
| 2921 | if (nvram_default_match (ath, "1", "1")) |
|---|
| 2922 | { |
|---|
| 2923 | sprintf (bufferif, "%s ath%d", bufferif, i); |
|---|
| 2924 | char vifs[32]; |
|---|
| 2925 | sprintf (vifs, "ath%d_vifs", i); |
|---|
| 2926 | sprintf (bufferif, "%s %s", bufferif, nvram_safe_get (vifs)); |
|---|
| 2927 | } |
|---|
| 2928 | } |
|---|
| 2929 | #endif |
|---|
| 2930 | #ifdef HAVE_BONDING |
|---|
| 2931 | c = atoi (nvram_default_get ("bonding_number", "1")); |
|---|
| 2932 | for (i = 0; i < c; i++) |
|---|
| 2933 | { |
|---|
| 2934 | sprintf (bufferif, "%s bond%d", bufferif, i); |
|---|
| 2935 | } |
|---|
| 2936 | #endif |
|---|
| 2937 | #ifdef HAVE_EOP_TUNNEL |
|---|
| 2938 | for (i = 1; i < 11; i++) |
|---|
| 2939 | { |
|---|
| 2940 | char oet[32]; |
|---|
| 2941 | char oeten[32]; |
|---|
| 2942 | char EOP[32]; |
|---|
| 2943 | sprintf (oet, "oet%d_bridged", i); |
|---|
| 2944 | sprintf (oeten, "oet%d_en", i); |
|---|
| 2945 | if (nvram_match (oet, "1") && nvram_match (oeten, "1")) |
|---|
| 2946 | { |
|---|
| 2947 | sprintf (EOP, "EOP%d", i); |
|---|
| 2948 | sprintf (bufferif, "%s %s", bufferif, EOP); |
|---|
| 2949 | } |
|---|
| 2950 | } |
|---|
| 2951 | #endif |
|---|
| 2952 | char buffer[256]; |
|---|
| 2953 | memset (buffer, 0, 256); |
|---|
| 2954 | getIfList (buffer, "br"); |
|---|
| 2955 | |
|---|
| 2956 | memset (finalbuffer, 0, 256); |
|---|
| 2957 | foreach (word, buffer, next) |
|---|
| 2958 | { |
|---|
| 2959 | if (!contains (word, '.')) |
|---|
| 2960 | sprintf (finalbuffer, "%s %s", finalbuffer, word); |
|---|
| 2961 | } |
|---|
| 2962 | |
|---|
| 2963 | |
|---|
| 2964 | int realcount = atoi (nvram_default_get ("bridgesif_count", "0")); |
|---|
| 2965 | wordlist = nvram_safe_get ("bridgesif"); |
|---|
| 2966 | foreach (word, wordlist, next) |
|---|
| 2967 | { |
|---|
| 2968 | char *port = word; |
|---|
| 2969 | char *tag = strsep (&port, ">"); |
|---|
| 2970 | char *prio = port; |
|---|
| 2971 | strsep (&prio, ">"); |
|---|
| 2972 | if (!tag || !port) |
|---|
| 2973 | break; |
|---|
| 2974 | char vlan_name[32]; |
|---|
| 2975 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2976 | websWrite (wp, "<div class=\"label\">Assignment %d</div>\n", count); |
|---|
| 2977 | sprintf (vlan_name, "bridge%d", count); |
|---|
| 2978 | showOptions (wp, vlan_name, finalbuffer, tag); |
|---|
| 2979 | websWrite (wp, " Interface "); |
|---|
| 2980 | sprintf (vlan_name, "bridgeif%d", count); |
|---|
| 2981 | showOptions (wp, vlan_name, bufferif, port); |
|---|
| 2982 | websWrite (wp, " Prio "); |
|---|
| 2983 | sprintf (vlan_name, "bridgeifprio%d", count); |
|---|
| 2984 | websWrite (wp, |
|---|
| 2985 | "<input class=\"num\" name=\"%s\"size=\"3\" value=\"%s\" />\n", |
|---|
| 2986 | vlan_name, prio != NULL ? prio : "128"); |
|---|
| 2987 | websWrite (wp, |
|---|
| 2988 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"bridgeif_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 2989 | count); |
|---|
| 2990 | websWrite (wp, "</div>\n"); |
|---|
| 2991 | count++; |
|---|
| 2992 | } |
|---|
| 2993 | int totalcount = count; |
|---|
| 2994 | for (i = count; i < realcount; i++) |
|---|
| 2995 | { |
|---|
| 2996 | char vlan_name[32]; |
|---|
| 2997 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 2998 | websWrite (wp, "<div class=\"label\">Assignment %d</div>\n", i); |
|---|
| 2999 | sprintf (vlan_name, "bridge%d", i); |
|---|
| 3000 | showOptions (wp, vlan_name, finalbuffer, ""); |
|---|
| 3001 | websWrite (wp, " Interface "); |
|---|
| 3002 | sprintf (vlan_name, "bridgeif%d", i); |
|---|
| 3003 | showOptions (wp, vlan_name, bufferif, ""); |
|---|
| 3004 | websWrite (wp, " Prio "); |
|---|
| 3005 | sprintf (vlan_name, "bridgeifprio%d", i); |
|---|
| 3006 | websWrite (wp, |
|---|
| 3007 | "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n", |
|---|
| 3008 | vlan_name, "128"); |
|---|
| 3009 | websWrite (wp, |
|---|
| 3010 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"bridgeif_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n", |
|---|
| 3011 | i); |
|---|
| 3012 | websWrite (wp, "</div>\n"); |
|---|
| 3013 | totalcount++; |
|---|
| 3014 | } |
|---|
| 3015 | websWrite (wp, |
|---|
| 3016 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"bridgeif_add_submit(this.form)\\\" />\");\n//]]>\n</script>\n"); |
|---|
| 3017 | char var[32]; |
|---|
| 3018 | sprintf (var, "%d", totalcount); |
|---|
| 3019 | nvram_set ("bridgesif_count", var); |
|---|
| 3020 | } |
|---|
| 3021 | |
|---|
| 3022 | |
|---|
| 3023 | #endif |
|---|
| 3024 | static void |
|---|
| 3025 | showDynOption (webs_t wp, char *propname, char *nvname, char *options[], |
|---|
| 3026 | char *names[]) |
|---|
| 3027 | { |
|---|
| 3028 | int i; |
|---|
| 3029 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3030 | websWrite (wp, |
|---|
| 3031 | "<div class=\"label\">%s</div><select name=\"%s\">\n", |
|---|
| 3032 | propname, nvname); |
|---|
| 3033 | for (i = 0; options[i] != NULL; i++) |
|---|
| 3034 | { |
|---|
| 3035 | websWrite (wp, |
|---|
| 3036 | "<option value=\"%s\" %s>Off</option>\n", |
|---|
| 3037 | names[i], nvram_match (nvname, |
|---|
| 3038 | options[i]) ? "selected=\"selected\"" |
|---|
| 3039 | : ""); |
|---|
| 3040 | } |
|---|
| 3041 | websWrite (wp, "</div>\n"); |
|---|
| 3042 | |
|---|
| 3043 | } |
|---|
| 3044 | |
|---|
| 3045 | #ifdef HAVE_MSSID |
|---|
| 3046 | |
|---|
| 3047 | |
|---|
| 3048 | |
|---|
| 3049 | |
|---|
| 3050 | void |
|---|
| 3051 | show_channel (webs_t wp, char *dev, char *prefix, int type) |
|---|
| 3052 | { |
|---|
| 3053 | char wl_mode[16]; |
|---|
| 3054 | sprintf (wl_mode, "%s_mode", prefix); |
|---|
| 3055 | char wl_net_mode[16]; |
|---|
| 3056 | sprintf (wl_net_mode, "%s_net_mode", prefix); |
|---|
| 3057 | if (nvram_match (wl_mode, "ap") || nvram_match (wl_mode, "apsta") |
|---|
| 3058 | || nvram_match (wl_mode, "apstawet") || nvram_match (wl_mode, "wdsap") |
|---|
| 3059 | || nvram_match (wl_mode, "infra")) |
|---|
| 3060 | { |
|---|
| 3061 | char wl_channel[16]; |
|---|
| 3062 | sprintf (wl_channel, "%s_channel", prefix); |
|---|
| 3063 | char wl_wchannel[16]; |
|---|
| 3064 | sprintf (wl_wchannel, "%s_wchannel", prefix); |
|---|
| 3065 | char wl_nbw[16]; |
|---|
| 3066 | sprintf (wl_nbw, "%s_nbw", prefix); |
|---|
| 3067 | |
|---|
| 3068 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3069 | websWrite (wp, |
|---|
| 3070 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label4)</script></div>\n<select name=\"%s\" onfocus=\"check_action(this,0)\"><script type=\"text/javascript\">\n//<![CDATA[\n", |
|---|
| 3071 | wl_channel); |
|---|
| 3072 | #ifdef HAVE_MADWIFI |
|---|
| 3073 | struct wifi_channels *chan; |
|---|
| 3074 | char cn[32]; |
|---|
| 3075 | char fr[32]; |
|---|
| 3076 | chan = list_channels (prefix); |
|---|
| 3077 | if (chan == NULL) |
|---|
| 3078 | chan = list_channels (dev); |
|---|
| 3079 | if (chan != NULL) |
|---|
| 3080 | { |
|---|
| 3081 | //int cnt = getchannelcount (); |
|---|
| 3082 | websWrite (wp, |
|---|
| 3083 | "document.write(\"<option value=\\\"0\\\" %s>\" + share.auto + \"</option>\");\n", |
|---|
| 3084 | nvram_match (wl_channel, |
|---|
| 3085 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3086 | int i = 0; |
|---|
| 3087 | while (chan[i].freq != -1) |
|---|
| 3088 | { |
|---|
| 3089 | cprintf ("%d\n", chan[i].channel); |
|---|
| 3090 | cprintf ("%d\n", chan[i].freq); |
|---|
| 3091 | |
|---|
| 3092 | sprintf (cn, "%d", chan[i].channel); |
|---|
| 3093 | sprintf (fr, "%d", chan[i].freq); |
|---|
| 3094 | websWrite (wp, |
|---|
| 3095 | "document.write(\"<option value=\\\"%s\\\" %s>%s - %d MHz</option>\");\n", |
|---|
| 3096 | fr, nvram_match (wl_channel, |
|---|
| 3097 | fr) ? "selected=\\\"selected\\\"" : |
|---|
| 3098 | "", cn, chan[i].freq); |
|---|
| 3099 | //free (chan[i].freq); |
|---|
| 3100 | i++; |
|---|
| 3101 | } |
|---|
| 3102 | free (chan); |
|---|
| 3103 | } |
|---|
| 3104 | #else |
|---|
| 3105 | if (type == 1 && !nvram_match (wl_net_mode, "g-only") |
|---|
| 3106 | && !nvram_match (wl_net_mode, "a-only") |
|---|
| 3107 | && !nvram_match (wl_net_mode, "bg-mixed") |
|---|
| 3108 | && nvram_match (wl_nbw, "40")) |
|---|
| 3109 | { |
|---|
| 3110 | int ch = atoi (nvram_safe_get ("wl0_wchannel")); |
|---|
| 3111 | websWrite (wp, "var max_channel = 2;\n"); |
|---|
| 3112 | websWrite (wp, "var wl0_channel = '%s';\n", |
|---|
| 3113 | nvram_safe_get (wl_wchannel)); |
|---|
| 3114 | websWrite (wp, |
|---|
| 3115 | "var freq = new Array(\"Auto\",\"2.412\",\"2.417\",\"2.422\",\"2.427\",\"2.432\",\"2.437\",\"2.442\",\"2.447\",\"2.452\",\"2.457\",\"2.462\",\"2.467\",\"2.472\",\"2.484\");\n"); |
|---|
| 3116 | char *sel = ""; |
|---|
| 3117 | if (nvram_match ("wl0_nctrlsb", "lower")) |
|---|
| 3118 | sel = "selected"; |
|---|
| 3119 | |
|---|
| 3120 | websWrite (wp, |
|---|
| 3121 | " document.write(\"<option value=%d %s>%d - \"+freq[%d]+\" GHz</option>\");\n", |
|---|
| 3122 | ch - 2, sel, ch - 2, ch - 2); |
|---|
| 3123 | if (nvram_match ("wl0_nctrlsb", "upper")) |
|---|
| 3124 | sel = "selected"; |
|---|
| 3125 | websWrite (wp, |
|---|
| 3126 | " document.write(\"<option value=%d %s>%d - \"+freq[%d]+\" GHz</option>\");\n", |
|---|
| 3127 | ch + 2, sel, ch + 2, ch + 2); |
|---|
| 3128 | |
|---|
| 3129 | } |
|---|
| 3130 | else |
|---|
| 3131 | { |
|---|
| 3132 | |
|---|
| 3133 | unsigned int chanlist[128]; |
|---|
| 3134 | int chancount = getchannels (chanlist); |
|---|
| 3135 | |
|---|
| 3136 | websWrite (wp, "var max_channel = %d;\n", chancount); |
|---|
| 3137 | websWrite (wp, "var wl0_channel = '%s';\n", |
|---|
| 3138 | nvram_safe_get (wl_channel)); |
|---|
| 3139 | websWrite (wp, "var offset = %d;\n", chanlist[0]); |
|---|
| 3140 | websWrite (wp, "var buf = \"\";\n"); |
|---|
| 3141 | websWrite (wp, "var freq = new Array(\"Auto\""); |
|---|
| 3142 | int i; |
|---|
| 3143 | for (i = 0; i < chancount; i++) |
|---|
| 3144 | { |
|---|
| 3145 | float ofs; |
|---|
| 3146 | if (chanlist[i] < 25) |
|---|
| 3147 | ofs = 2.407f; |
|---|
| 3148 | else |
|---|
| 3149 | ofs = 5.000f; |
|---|
| 3150 | ofs += (float) (chanlist[i] * 0.005f); |
|---|
| 3151 | websWrite (wp, ", \"%0.3f\"", ofs); |
|---|
| 3152 | } |
|---|
| 3153 | websWrite (wp, ");\n"); |
|---|
| 3154 | websWrite (wp, "for(i=0; i<=max_channel ; i++) {\n"); |
|---|
| 3155 | websWrite (wp, " if(i == wl0_channel) buf = \"selected\";\n"); |
|---|
| 3156 | websWrite (wp, " else buf = \"\";\n"); |
|---|
| 3157 | websWrite (wp, " if (i==0)\n"); |
|---|
| 3158 | websWrite (wp, |
|---|
| 3159 | " document.write(\"<option value=\"+i+\" \"+buf+\">\" + share.auto + \"</option>\");\n"); |
|---|
| 3160 | websWrite (wp, " else\n"); |
|---|
| 3161 | websWrite (wp, |
|---|
| 3162 | " document.write(\"<option value=\"+i+\" \"+buf+\">\"+(i+offset-1)+\" - \"+freq[i]+\" GHz</option>\");\n"); |
|---|
| 3163 | websWrite (wp, "}\n"); |
|---|
| 3164 | } |
|---|
| 3165 | #endif |
|---|
| 3166 | websWrite (wp, "//]]>\n</script></select></div>\n"); |
|---|
| 3167 | } |
|---|
| 3168 | } |
|---|
| 3169 | |
|---|
| 3170 | #ifdef HAVE_MADWIFI |
|---|
| 3171 | static char *ag_rates[] = { "6", "9", "12", "18", "24", "36", "48", "54" }; |
|---|
| 3172 | static char *turbo_rates[] = { "12", "24", "36", "48", "72", "96", "108" }; |
|---|
| 3173 | static char *b_rates[] = { "1", "2", "5.5", "11" }; |
|---|
| 3174 | static char *bg_rates[] = |
|---|
| 3175 | { "1", "2", "5.5", "6", "9", "11", "12", "18", "24", "36", "48", "54" }; |
|---|
| 3176 | static char *xr_rates[] = |
|---|
| 3177 | { "0.25", "0.5", "1", "2", "3", "6", "9", "12", "18", "24", "36", "48", |
|---|
| 3178 | "54" |
|---|
| 3179 | }; |
|---|
| 3180 | static char *half_rates[] = { "3", "4.5", "6", "9", "12", "18", "24", "27" }; |
|---|
| 3181 | static char *quarter_rates[] = |
|---|
| 3182 | { "1.5", "2", "3", "4.5", "6", "9", "12", "13.5" }; |
|---|
| 3183 | |
|---|
| 3184 | |
|---|
| 3185 | |
|---|
| 3186 | void |
|---|
| 3187 | show_rates (webs_t wp, char *prefix, int maxrate) |
|---|
| 3188 | { |
|---|
| 3189 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3190 | if (maxrate) |
|---|
| 3191 | { |
|---|
| 3192 | websWrite (wp, |
|---|
| 3193 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label21)</script></div>\n"); |
|---|
| 3194 | websWrite (wp, "<select name=\"%s_maxrate\">\n", prefix); |
|---|
| 3195 | } |
|---|
| 3196 | else |
|---|
| 3197 | { |
|---|
| 3198 | websWrite (wp, |
|---|
| 3199 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label3)</script></div>\n"); |
|---|
| 3200 | websWrite (wp, "<select name=\"%s_rate\">\n", prefix); |
|---|
| 3201 | } |
|---|
| 3202 | websWrite (wp, "<script type=\"text/javascript\">\n"); |
|---|
| 3203 | websWrite (wp, "//<![CDATA[\n"); |
|---|
| 3204 | char srate[32]; |
|---|
| 3205 | sprintf (srate, "%s_rate", prefix); |
|---|
| 3206 | char mxrate[32]; |
|---|
| 3207 | sprintf (mxrate, "%s_maxrate", prefix); |
|---|
| 3208 | websWrite (wp, |
|---|
| 3209 | "document.write(\"<option value=\\\"0\\\" %s >\" + share.auto + \"</option>\");\n", |
|---|
| 3210 | nvram_match (srate, "0") ? "selected" : ""); |
|---|
| 3211 | websWrite (wp, "//]]>\n"); |
|---|
| 3212 | websWrite (wp, "</script>\n"); |
|---|
| 3213 | char **rate; |
|---|
| 3214 | char **showrates = NULL; |
|---|
| 3215 | int len; |
|---|
| 3216 | char turbo[32]; |
|---|
| 3217 | sprintf (turbo, "%s_turbo", prefix); |
|---|
| 3218 | char mode[32]; |
|---|
| 3219 | char bw[16]; |
|---|
| 3220 | sprintf (bw, "%s_channelbw", prefix); |
|---|
| 3221 | |
|---|
| 3222 | sprintf (mode, "%s_net_mode", prefix); |
|---|
| 3223 | if (nvram_match (mode, "b-only")) |
|---|
| 3224 | { |
|---|
| 3225 | rate = b_rates; |
|---|
| 3226 | len = sizeof (b_rates) / sizeof (char *); |
|---|
| 3227 | } |
|---|
| 3228 | if (nvram_match (mode, "g-only")) |
|---|
| 3229 | { |
|---|
| 3230 | rate = ag_rates; |
|---|
| 3231 | len = sizeof (ag_rates) / sizeof (char *); |
|---|
| 3232 | if (nvram_match (turbo, "1")) |
|---|
| 3233 | showrates = turbo_rates; |
|---|
| 3234 | if (nvram_match (bw, "10")) |
|---|
| 3235 | { |
|---|
| 3236 | rate = half_rates; |
|---|
| 3237 | len = sizeof (half_rates) / sizeof (char *); |
|---|
| 3238 | } |
|---|
| 3239 | if (nvram_match (bw, "5")) |
|---|
| 3240 | { |
|---|
| 3241 | rate = quarter_rates; |
|---|
| 3242 | len = sizeof (quarter_rates) / sizeof (char *); |
|---|
| 3243 | } |
|---|
| 3244 | } |
|---|
| 3245 | if (nvram_match (mode, "a-only")) |
|---|
| 3246 | { |
|---|
| 3247 | rate = ag_rates; |
|---|
| 3248 | len = sizeof (ag_rates) / sizeof (char *); |
|---|
| 3249 | if (nvram_match (turbo, "1")) |
|---|
| 3250 | showrates = turbo_rates; |
|---|
| 3251 | if (nvram_match (bw, "10")) |
|---|
| 3252 | { |
|---|
| 3253 | rate = half_rates; |
|---|
| 3254 | len = sizeof (half_rates) / sizeof (char *); |
|---|
| 3255 | } |
|---|
| 3256 | if (nvram_match (bw, "5")) |
|---|
| 3257 | { |
|---|
| 3258 | rate = quarter_rates; |
|---|
| 3259 | len = sizeof (quarter_rates) / sizeof (char *); |
|---|
| 3260 | } |
|---|
| 3261 | } |
|---|
| 3262 | if (nvram_match (mode, "bg-mixed")) |
|---|
| 3263 | { |
|---|
| 3264 | rate = bg_rates; |
|---|
| 3265 | len = sizeof (bg_rates) / sizeof (char *); |
|---|
| 3266 | if (nvram_match (bw, "10")) |
|---|
| 3267 | { |
|---|
| 3268 | rate = half_rates; |
|---|
| 3269 | len = sizeof (half_rates) / sizeof (char *); |
|---|
| 3270 | } |
|---|
| 3271 | if (nvram_match (bw, "5")) |
|---|
| 3272 | { |
|---|
| 3273 | rate = quarter_rates; |
|---|
| 3274 | len = sizeof (quarter_rates) / sizeof (char *); |
|---|
| 3275 | } |
|---|
| 3276 | } |
|---|
| 3277 | if (nvram_match (mode, "mixed")) |
|---|
| 3278 | { |
|---|
| 3279 | rate = bg_rates; |
|---|
| 3280 | len = sizeof (bg_rates) / sizeof (char *); |
|---|
| 3281 | if (nvram_match (turbo, "1")) |
|---|
| 3282 | { |
|---|
| 3283 | rate = ag_rates; |
|---|
| 3284 | len = sizeof (ag_rates) / sizeof (char *); |
|---|
| 3285 | showrates = turbo_rates; |
|---|
| 3286 | } |
|---|
| 3287 | if (nvram_match (bw, "10")) |
|---|
| 3288 | { |
|---|
| 3289 | rate = half_rates; |
|---|
| 3290 | len = sizeof (half_rates) / sizeof (char *); |
|---|
| 3291 | } |
|---|
| 3292 | if (nvram_match (bw, "5")) |
|---|
| 3293 | { |
|---|
| 3294 | rate = quarter_rates; |
|---|
| 3295 | len = sizeof (quarter_rates) / sizeof (char *); |
|---|
| 3296 | } |
|---|
| 3297 | } |
|---|
| 3298 | int i; |
|---|
| 3299 | for (i = 0; i < len; i++) |
|---|
| 3300 | { |
|---|
| 3301 | if (maxrate) |
|---|
| 3302 | { |
|---|
| 3303 | int offset = 0; |
|---|
| 3304 | // if (nvram_match(mode,"a-only") && nvram_match (bw, "20"))offset=0; |
|---|
| 3305 | if (nvram_match (mode, "g-only") && nvram_match (bw, "20")) |
|---|
| 3306 | offset = 4; |
|---|
| 3307 | char comp[32]; |
|---|
| 3308 | sprintf (comp, "%d", i + 1 + offset); |
|---|
| 3309 | if (showrates) |
|---|
| 3310 | websWrite (wp, "<option value=\"%d\" %s >%s Mbps</option>\n", |
|---|
| 3311 | i + 1 + offset, nvram_match (mxrate, |
|---|
| 3312 | comp) ? "selected" : "", |
|---|
| 3313 | showrates[i]); |
|---|
| 3314 | else |
|---|
| 3315 | websWrite (wp, "<option value=\"%d\" %s >%s Mbps</option>\n", |
|---|
| 3316 | i + 1 + offset, nvram_match (mxrate, |
|---|
| 3317 | comp) ? "selected" : "", |
|---|
| 3318 | rate[i]); |
|---|
| 3319 | } |
|---|
| 3320 | else |
|---|
| 3321 | { |
|---|
| 3322 | if (showrates) |
|---|
| 3323 | websWrite (wp, "<option value=\"%s\" %s >%s Mbps</option>\n", |
|---|
| 3324 | rate[i], nvram_match (srate, |
|---|
| 3325 | rate[i]) ? "selected" : "", |
|---|
| 3326 | showrates[i]); |
|---|
| 3327 | else |
|---|
| 3328 | websWrite (wp, "<option value=\"%s\" %s >%s Mbps</option>\n", |
|---|
| 3329 | rate[i], nvram_match (srate, |
|---|
| 3330 | rate[i]) ? "selected" : "", |
|---|
| 3331 | rate[i]); |
|---|
| 3332 | |
|---|
| 3333 | } |
|---|
| 3334 | } |
|---|
| 3335 | websWrite (wp, "</select>\n"); |
|---|
| 3336 | websWrite (wp, "<span class=\"default\">\n"); |
|---|
| 3337 | websWrite (wp, "<script type=\"text/javascript\">\n"); |
|---|
| 3338 | websWrite (wp, "//<![CDATA[\n"); |
|---|
| 3339 | websWrite (wp, |
|---|
| 3340 | "document.write(\"(\" + share.deflt + \": \" + share.auto + \")\");\n"); |
|---|
| 3341 | websWrite (wp, "//]]\n"); |
|---|
| 3342 | websWrite (wp, "</script></span></div>\n"); |
|---|
| 3343 | |
|---|
| 3344 | |
|---|
| 3345 | } |
|---|
| 3346 | #endif |
|---|
| 3347 | void |
|---|
| 3348 | show_netmode (webs_t wp, char *prefix) |
|---|
| 3349 | { |
|---|
| 3350 | char wl_net_mode[16]; |
|---|
| 3351 | sprintf (wl_net_mode, "%s_net_mode", prefix); |
|---|
| 3352 | |
|---|
| 3353 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3354 | websWrite (wp, |
|---|
| 3355 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label2)</script></div><select name=\"%s\" onchange=\"SelWL(this.form.%s.selectedIndex,this.form)\">\n", |
|---|
| 3356 | wl_net_mode, wl_net_mode); |
|---|
| 3357 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 3358 | websWrite (wp, |
|---|
| 3359 | "document.write(\"<option value=\\\"disabled\\\" %s>\" + share.disabled + \"</option>\");\n", |
|---|
| 3360 | nvram_match (wl_net_mode, |
|---|
| 3361 | "disabled") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3362 | websWrite (wp, |
|---|
| 3363 | "document.write(\"<option value=\\\"mixed\\\" %s>\" + wl_basic.mixed + \"</option>\");\n", |
|---|
| 3364 | nvram_match (wl_net_mode, |
|---|
| 3365 | "mixed") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3366 | if (has_mimo ()) |
|---|
| 3367 | { |
|---|
| 3368 | websWrite (wp, |
|---|
| 3369 | "document.write(\"<option value=\\\"bg-mixed\\\" %s>\" + wl_basic.bg + \"</option>\");\n", |
|---|
| 3370 | nvram_match (wl_net_mode, |
|---|
| 3371 | "bg-mixed") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3372 | } |
|---|
| 3373 | #ifdef HAVE_WHRAG108 |
|---|
| 3374 | if (!strcmp (prefix, "ath1")) |
|---|
| 3375 | #endif |
|---|
| 3376 | websWrite (wp, |
|---|
| 3377 | "document.write(\"<option value=\\\"b-only\\\" %s>\" + wl_basic.b + \"</option>\");\n", |
|---|
| 3378 | nvram_match (wl_net_mode, |
|---|
| 3379 | "b-only") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3380 | #ifdef HAVE_MADWIFI |
|---|
| 3381 | #ifdef HAVE_WHRAG108 |
|---|
| 3382 | if (!strcmp (prefix, "ath1")) |
|---|
| 3383 | #endif |
|---|
| 3384 | websWrite (wp, |
|---|
| 3385 | "document.write(\"<option value=\\\"g-only\\\" %s>\" + wl_basic.g + \"</option>\");\n", |
|---|
| 3386 | nvram_match (wl_net_mode, |
|---|
| 3387 | "g-only") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3388 | #ifdef HAVE_WHRAG108 |
|---|
| 3389 | if (!strcmp (prefix, "ath1")) |
|---|
| 3390 | #endif |
|---|
| 3391 | websWrite (wp, |
|---|
| 3392 | "document.write(\"<option value=\\\"bg-mixed\\\" %s>\" + wl_basic.bg + \"</option>\");\n", |
|---|
| 3393 | nvram_match (wl_net_mode, |
|---|
| 3394 | "bg-mixed") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3395 | #else |
|---|
| 3396 | #ifdef HAVE_WHRAG108 |
|---|
| 3397 | if (!strcmp (prefix, "ath1")) |
|---|
| 3398 | #endif |
|---|
| 3399 | websWrite (wp, |
|---|
| 3400 | "document.write(\"<option value=\\\"g-only\\\" %s>\" + wl_basic.g + \"</option>\");\n", |
|---|
| 3401 | nvram_match (wl_net_mode, |
|---|
| 3402 | "g-only") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3403 | #endif |
|---|
| 3404 | if (has_mimo ()) |
|---|
| 3405 | { |
|---|
| 3406 | websWrite (wp, |
|---|
| 3407 | "document.write(\"<option value=\\\"n-only\\\" %s>\" + wl_basic.n + \"</option>\");\n", |
|---|
| 3408 | nvram_match (wl_net_mode, |
|---|
| 3409 | "n-only") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3410 | } |
|---|
| 3411 | #if !defined(HAVE_FONERA) && !defined(HAVE_LS2) && !defined(HAVE_MERAKI) |
|---|
| 3412 | #ifndef HAVE_MADWIFI |
|---|
| 3413 | if (nvram_match ("wl0_phytypes", "ga") || nvram_match ("wl0_phytypes", "a")) |
|---|
| 3414 | websWrite (wp, |
|---|
| 3415 | "document.write(\"<option value=\\\"a-only\\\" %s>\" + wl_basic.a + \"</option>\");\n", |
|---|
| 3416 | nvram_match (wl_net_mode, |
|---|
| 3417 | "a-only") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3418 | #else |
|---|
| 3419 | #ifdef HAVE_WHRAG108 |
|---|
| 3420 | if (!strcmp (prefix, "ath0")) |
|---|
| 3421 | #endif |
|---|
| 3422 | websWrite (wp, |
|---|
| 3423 | "document.write(\"<option value=\\\"a-only\\\" %s>\" + wl_basic.a + \"</option>\");\n", |
|---|
| 3424 | nvram_match (wl_net_mode, |
|---|
| 3425 | "a-only") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3426 | #endif |
|---|
| 3427 | |
|---|
| 3428 | #endif |
|---|
| 3429 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 3430 | websWrite (wp, "</select>\n"); |
|---|
| 3431 | websWrite (wp, "</div>\n"); |
|---|
| 3432 | } |
|---|
| 3433 | |
|---|
| 3434 | void |
|---|
| 3435 | showbridgesettings (webs_t wp, char *var) |
|---|
| 3436 | { |
|---|
| 3437 | websWrite (wp, |
|---|
| 3438 | "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.network)</script></div>\n"); |
|---|
| 3439 | char ssid[32]; |
|---|
| 3440 | sprintf (ssid, "%s_bridged", var); |
|---|
| 3441 | char vvar[32]; |
|---|
| 3442 | strcpy (vvar, var); |
|---|
| 3443 | rep (vvar, '.', 'X'); |
|---|
| 3444 | websWrite (wp, |
|---|
| 3445 | "<input class=\"spaceradio\" type=\"radio\" value=\"0\" onclick=\"show_layer_ext(this, '%s_idnetvifs', true);\" name=\"%s_bridged\" %s><script type=\"text/javascript\">Capture(wl_basic.unbridged)</script></input> \n", |
|---|
| 3446 | vvar, var, nvram_default_match (ssid, "0", |
|---|
| 3447 | "1") ? "checked=\"checked\"" : |
|---|
| 3448 | ""); |
|---|
| 3449 | websWrite (wp, |
|---|
| 3450 | "<input class=\"spaceradio\" type=\"radio\" value=\"1\" onclick=\"show_layer_ext(this, '%s_idnetvifs', false);\" name=\"%s_bridged\" %s><script type=\"text/javascript\">Capture(wl_basic.bridged)</script></input>\n", |
|---|
| 3451 | vvar, var, nvram_default_match (ssid, "1", |
|---|
| 3452 | "1") ? "checked=\"checked\"" : |
|---|
| 3453 | ""); |
|---|
| 3454 | websWrite (wp, "</div>\n"); |
|---|
| 3455 | |
|---|
| 3456 | websWrite (wp, "<div id=\"%s_idnetvifs\">\n", vvar); |
|---|
| 3457 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3458 | websWrite (wp, |
|---|
| 3459 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n"); |
|---|
| 3460 | char ip[32]; |
|---|
| 3461 | sprintf (ip, "%s_ipaddr", var); |
|---|
| 3462 | char *ipv = nvram_safe_get (ip); |
|---|
| 3463 | websWrite (wp, |
|---|
| 3464 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,1,223,share.ip)\" name=\"%s_ipaddr_0\" value=\"%d\" />.", |
|---|
| 3465 | var, get_single_ip (ipv, 0)); |
|---|
| 3466 | websWrite (wp, |
|---|
| 3467 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_1\" value=\"%d\" />.", |
|---|
| 3468 | var, get_single_ip (ipv, 1)); |
|---|
| 3469 | websWrite (wp, |
|---|
| 3470 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_2\" value=\"%d\" />.", |
|---|
| 3471 | var, get_single_ip (ipv, 2)); |
|---|
| 3472 | websWrite (wp, |
|---|
| 3473 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_3\" value=\"%d\" />\n", |
|---|
| 3474 | var, get_single_ip (ipv, 3)); |
|---|
| 3475 | websWrite (wp, "</div>\n"); |
|---|
| 3476 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3477 | websWrite (wp, |
|---|
| 3478 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n"); |
|---|
| 3479 | sprintf (ip, "%s_netmask", var); |
|---|
| 3480 | ipv = nvram_safe_get (ip); |
|---|
| 3481 | |
|---|
| 3482 | websWrite (wp, |
|---|
| 3483 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_0\" value=\"%d\" />.", |
|---|
| 3484 | var, get_single_ip (ipv, 0)); |
|---|
| 3485 | websWrite (wp, |
|---|
| 3486 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_1\" value=\"%d\" />.", |
|---|
| 3487 | var, get_single_ip (ipv, 1)); |
|---|
| 3488 | websWrite (wp, |
|---|
| 3489 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_2\" value=\"%d\" />.", |
|---|
| 3490 | var, get_single_ip (ipv, 2)); |
|---|
| 3491 | websWrite (wp, |
|---|
| 3492 | "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_3\" value=\"%d\" />.", |
|---|
| 3493 | var, get_single_ip (ipv, 3)); |
|---|
| 3494 | websWrite (wp, "</div>\n"); |
|---|
| 3495 | websWrite (wp, "</div>\n"); |
|---|
| 3496 | |
|---|
| 3497 | websWrite (wp, "<script>\n//<![CDATA[\n "); |
|---|
| 3498 | websWrite (wp, |
|---|
| 3499 | "show_layer_ext(document.getElementsByName(\"%s_bridged\"), \"%s_idnetvifs\", %s);\n", |
|---|
| 3500 | var, vvar, nvram_match (ssid, "0") ? "true" : "false"); |
|---|
| 3501 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 3502 | |
|---|
| 3503 | } |
|---|
| 3504 | |
|---|
| 3505 | int |
|---|
| 3506 | show_virtualssid (webs_t wp, char *prefix) |
|---|
| 3507 | { |
|---|
| 3508 | char *next; |
|---|
| 3509 | char var[80]; |
|---|
| 3510 | char ssid[80]; |
|---|
| 3511 | char wmm[32]; |
|---|
| 3512 | char vif[16]; |
|---|
| 3513 | |
|---|
| 3514 | sprintf (vif, "%s_vifs", prefix); |
|---|
| 3515 | char *vifs = nvram_safe_get (vif); |
|---|
| 3516 | if (vifs == NULL) |
|---|
| 3517 | return 0; |
|---|
| 3518 | #ifndef HAVE_MADWIFI |
|---|
| 3519 | if (!nvram_match ("wl0_mode", "ap") && !nvram_match ("wl0_mode", "apsta") |
|---|
| 3520 | && !nvram_match ("wl0_mode", "apstawet")) |
|---|
| 3521 | return 0; |
|---|
| 3522 | #endif |
|---|
| 3523 | int count = 1; |
|---|
| 3524 | websWrite (wp, |
|---|
| 3525 | "<h2><script type=\"text/javascript\">Capture(wl_basic.h2_vi)</script></h2>\n"); |
|---|
| 3526 | foreach (var, vifs, next) |
|---|
| 3527 | { |
|---|
| 3528 | sprintf (ssid, "%s_ssid", var); |
|---|
| 3529 | websWrite (wp, |
|---|
| 3530 | "<fieldset><legend><script type=\"text/javascript\">Capture(share.vintrface)</script> %s SSID [%s]</legend>\n", |
|---|
| 3531 | var, nvram_safe_get (ssid)); |
|---|
| 3532 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3533 | websWrite (wp, |
|---|
| 3534 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label3)</script></div>\n"); |
|---|
| 3535 | |
|---|
| 3536 | websWrite (wp, |
|---|
| 3537 | "<input name=\"%s_ssid\" size=\"20\" maxlength=\"32\" onblur=\"valid_name(this,wl_basic.label3)\" value=\"%s\" /></div>\n", |
|---|
| 3538 | var, nvram_safe_get (ssid)); |
|---|
| 3539 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 3540 | websWrite (wp, |
|---|
| 3541 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label5)</script></div>"); |
|---|
| 3542 | sprintf (ssid, "%s_closed", var); |
|---|
| 3543 | websWrite (wp, |
|---|
| 3544 | "<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s_closed\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input> \n", |
|---|
| 3545 | var, nvram_match (ssid, "0") ? "checked=\"checked\"" : ""); |
|---|
| 3546 | websWrite (wp, |
|---|
| 3547 | "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s_closed\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>\n", |
|---|
| 3548 | var, nvram_match (ssid, "1") ? "checked=\"checked\"" : ""); |
|---|
| 3549 | websWrite (wp, "</div>\n"); |
|---|
| 3550 | char wl_mode[16]; |
|---|
| 3551 | #ifdef HAVE_MADWIFI |
|---|
| 3552 | sprintf (wl_mode, "%s_mode", var); |
|---|
| 3553 | websWrite (wp, |
|---|
| 3554 | "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label)</script></div><select name=\"%s\" >\n", |
|---|
| 3555 | wl_mode); |
|---|
| 3556 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 3557 | websWrite (wp, |
|---|
| 3558 | "document.write(\"<option value=\\\"ap\\\" %s >\" + wl_basic.ap + \"</option>\");\n", |
|---|
| 3559 | nvram_match (wl_mode, |
|---|
| 3560 | "ap") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3561 | websWrite (wp, |
|---|
| 3562 | "document.write(\"<option value=\\\"wdssta\\\" %s >\" + wl_basic.wdssta + \"</option>\");\n", |
|---|
| 3563 | nvram_match (wl_mode, |
|---|
| 3564 | "wdssta") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3565 | websWrite (wp, |
|---|
| 3566 | "document.write(\"<option value=\\\"wdsap\\\" %s >\" + wl_basic.wdsap + \"</option>\");\n", |
|---|
| 3567 | nvram_match (wl_mode, |
|---|
| 3568 | "wdsap") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 3569 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 3570 | websWrite (wp, "</select>\n"); |
|---|
| 3571 | websWrite (wp, "</div>\n"); |
|---|
| 3572 | sprintf (wmm, "%s_wmm", var); |
|---|
| 3573 | showOption (wp, "wl_adv.label18", wmm); |
|---|
| 3574 | #endif |
|---|
| 3575 | sprintf (ssid, "%s_ap_isolate", var); |
|---|
| 3576 | showOption (wp, "wl_adv.label11", ssid); |
|---|
| 3577 | sprintf (wl_mode, "%s_mode", var); |
|---|
| 3578 | showbridgesettings (wp, var); |
|---|
| 3579 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 3580 | count++; |
|---|
| 3581 | } |
|---|
| 3582 | |
|---|
| 3583 | websWrite (wp, "<div class=\"center\">\n"); |
|---|
| 3584 | #ifdef HAVE_MADWIFI |
|---|
| 3585 | if (count < 16) |
|---|
| 3586 | #else |
|---|
| 3587 | if (count < WL_MAXBSSCFG) |
|---|
| 3588 | #endif |
|---|
| 3589 | websWrite (wp, |
|---|
| 3590 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"vifs_add_submit(this.form,'%s')\\\" />\");\n//]]>\n</script>\n", |
|---|
| 3591 | prefix); |
|---|
| 3592 | |
|---|
| 3593 | if (count > 1) |
|---|
| 3594 | websWrite (wp, |
|---|
| 3595 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.remove + \"\\\" onclick=\\\"vifs_remove_submit(this.form,'%s')\\\" />\");\n//]]>\n</script>\n", |
|---|
| 3596 | prefix); |
|---|
| 3597 | |
|---|
| 3598 | websWrite (wp, "</div><br />\n"); |
|---|
| 3599 | |
|---|
| 3600 | return 0; |
|---|
| 3601 | } |
|---|
| 3602 | |
|---|
| 3603 | int |
|---|
| 3604 | get_vifcount (char *prefix) |
|---|
| 3605 | { |
|---|
| 3606 | char *next; |
|---|
| 3607 | char var[80]; |
|---|
| 3608 | char wif[16]; |
|---|
| 3609 | sprintf (wif, "%s_vifs", prefix); |
|---|
| 3610 | char *vifs = nvram_safe_get (wif); |
|---|
| 3611 | if (vifs == NULL) |
|---|
| 3612 | return 0; |
|---|
| 3613 | int count = 0; |
|---|
| 3614 | foreach (var, vifs, next) |
|---|
| 3615 | { |
|---|
| 3616 | count++; |
|---|
| 3617 | } |
|---|
| 3618 | return count; |
|---|
| 3619 | } |
|---|
| 3620 | |
|---|
| 3621 | |
|---|
| 3622 | void |
|---|
| 3623 | add_vifs_single (char *prefix, int device) |
|---|
| 3624 | { |
|---|
| 3625 | int count = get_vifcount (prefix); |
|---|
| 3626 | if (count == 16) |
|---|
| 3627 | return; |
|---|
| 3628 | char vif[16]; |
|---|
| 3629 | sprintf (vif, "%s_vifs", prefix); |
|---|
| 3630 | char *vifs = nvram_safe_get (vif); |
|---|
| 3631 | if (vifs == NULL) |
|---|
| 3632 | return; |
|---|
| 3633 | char *n = (char *) malloc (strlen (vifs) + 8); |
|---|
| 3634 | char v[80]; |
|---|
| 3635 | char v2[80]; |
|---|
| 3636 | #ifdef HAVE_MADWIFI |
|---|
| 3637 | // char *cou[] = { "a", "b", "c", "d", "e", "f" }; |
|---|
| 3638 | sprintf (v, "ath%d.%d", device, count + 1); |
|---|
| 3639 | #else |
|---|
| 3640 | sprintf (v, "wl%d.%d", device, count + 1); |
|---|
| 3641 | #endif |
|---|
| 3642 | if (strlen (vifs) == 0) |
|---|
| 3643 | sprintf (n, "%s", v); |
|---|
| 3644 | else |
|---|
| 3645 | sprintf (n, "%s %s", vifs, v); |
|---|
| 3646 | sprintf (v2, "%s_closed", v); |
|---|
| 3647 | nvram_set (v2, "0"); |
|---|
| 3648 | sprintf (v2, "%s_mode", v); |
|---|
| 3649 | nvram_set (v2, "ap"); |
|---|
| 3650 | |
|---|
| 3651 | sprintf (v2, "%s_ap_isolate", v); |
|---|
| 3652 | nvram_set (v2, "0"); |
|---|
| 3653 | sprintf (v2, "%s_ssid", v); |
|---|
| 3654 | #ifdef HAVE_MAKSAT |
|---|
| 3655 | nvram_set (v2, "maksat_vap"); |
|---|
| 3656 | #else |
|---|
| 3657 | nvram_set (v2, "dd-wrt_vap"); |
|---|
| 3658 | #endif |
|---|
| 3659 | sprintf (v2, "%s_vifs", prefix); |
|---|
| 3660 | nvram_set (v2, n); |
|---|
| 3661 | sprintf (v2, "%s_bridged", v); |
|---|
| 3662 | nvram_set (v2, "1"); |
|---|
| 3663 | sprintf (v2, "%s_ipaddr", v); |
|---|
| 3664 | nvram_set (v2, "0.0.0.0"); |
|---|
| 3665 | sprintf (v2, "%s_netmask", v); |
|---|
| 3666 | nvram_set (v2, "0.0.0.0"); |
|---|
| 3667 | |
|---|
| 3668 | sprintf (v2, "%s_gtk_rekey", v); |
|---|
| 3669 | nvram_set (v2, "3600"); |
|---|
| 3670 | |
|---|
| 3671 | sprintf (v2, "%s_radius_port", v); |
|---|
| 3672 | nvram_set (v2, "1812"); |
|---|
| 3673 | |
|---|
| 3674 | sprintf (v2, "%s_radius_ipaddr", v); |
|---|
| 3675 | nvram_set (v2, "0.0.0.0"); |
|---|
| 3676 | |
|---|
| 3677 | //nvram_commit (); |
|---|
| 3678 | free (n); |
|---|
| 3679 | } |
|---|
| 3680 | |
|---|
| 3681 | void |
|---|
| 3682 | add_vifs (webs_t wp) |
|---|
| 3683 | { |
|---|
| 3684 | char *prefix = websGetVar (wp, "iface", NULL); |
|---|
| 3685 | if (prefix == NULL) |
|---|
| 3686 | return; |
|---|
| 3687 | int devcount = prefix[strlen (prefix) - 1] - '0'; |
|---|
| 3688 | add_vifs_single (prefix, devcount); |
|---|
| 3689 | } |
|---|
| 3690 | |
|---|
| 3691 | void |
|---|
| 3692 | remove_vifs_single (char *prefix) |
|---|
| 3693 | { |
|---|
| 3694 | char wif[16]; |
|---|
| 3695 | sprintf (wif, "%s_vifs", prefix); |
|---|
| 3696 | int o = -1; |
|---|
| 3697 | char *vifs = nvram_safe_get (wif); |
|---|
| 3698 | char copy[128]; |
|---|
| 3699 | strcpy (copy, vifs); |
|---|
| 3700 | int i; |
|---|
| 3701 | int slen = strlen (copy); |
|---|
| 3702 | for (i = 0; i < slen; i++) |
|---|
| 3703 | { |
|---|
| 3704 | if (copy[i] == 0x20) |
|---|
| 3705 | o = i; |
|---|
| 3706 | } |
|---|
| 3707 | if (o == -1) |
|---|
| 3708 | { |
|---|
| 3709 | nvram_set (wif, ""); |
|---|
| 3710 | } |
|---|
| 3711 | else |
|---|
| 3712 | { |
|---|
| 3713 | copy[o] = 0; |
|---|
| 3714 | nvram_set (wif, copy); |
|---|
| 3715 | } |
|---|
| 3716 | //nvram_commit (); |
|---|
| 3717 | } |
|---|
| 3718 | |
|---|
| 3719 | void |
|---|
| 3720 | remove_vifs (webs_t wp) |
|---|
| 3721 | { |
|---|
| 3722 | char *prefix = websGetVar (wp, "iface", NULL); |
|---|
| 3723 | remove_vifs_single (prefix); |
|---|
| 3724 | } |
|---|
| 3725 | #endif |
|---|
| 3726 | |
|---|
| 3727 | void |
|---|
| 3728 | copytonv (webs_t wp, char *n) |
|---|
| 3729 | { |
|---|
| 3730 | char *wl = websGetVar (wp, n, NULL); |
|---|
| 3731 | cprintf ("copy value %s which is [%s] to nvram\n", n, wl); |
|---|
| 3732 | if (wl) |
|---|
| 3733 | nvram_set (n, wl); |
|---|
| 3734 | } |
|---|
| 3735 | |
|---|
| 3736 | static void |
|---|
| 3737 | save_prefix (webs_t wp, char *prefix) |
|---|
| 3738 | { |
|---|
| 3739 | char n[80]; |
|---|
| 3740 | char sifs[80]; |
|---|
| 3741 | char turbo[80]; |
|---|
| 3742 | char chanbw[80]; |
|---|
| 3743 | char preamble[80]; |
|---|
| 3744 | int turbochanged = 0; |
|---|
| 3745 | int cbwchanged = 0; |
|---|
| 3746 | sprintf (n, "%s_ssid", prefix); |
|---|
| 3747 | copytonv (wp, n); |
|---|
| 3748 | if (!strcmp (prefix, "wl0")) |
|---|
| 3749 | { |
|---|
| 3750 | char *wl = websGetVar (wp, n, NULL); |
|---|
| 3751 | cprintf ("copy value %s which is [%s] to nvram\n", n, wl); |
|---|
| 3752 | if (wl) |
|---|
| 3753 | nvram_set ("wl_ssid", wl); |
|---|
| 3754 | } |
|---|
| 3755 | sprintf (n, "%s_distance", prefix); |
|---|
| 3756 | copytonv (wp, n); |
|---|
| 3757 | #ifdef HAVE_MADWIFI |
|---|
| 3758 | sprintf (n, "%s_txpwrdbm", prefix); |
|---|
| 3759 | copytonv (wp, n); |
|---|
| 3760 | sprintf (n, "%s_antgain", prefix); |
|---|
| 3761 | copytonv (wp, n); |
|---|
| 3762 | sprintf (n, "ath_regulatory"); |
|---|
| 3763 | copytonv (wp, n); |
|---|
| 3764 | sprintf (n, "%s_scanlist", prefix); |
|---|
| 3765 | { |
|---|
| 3766 | char *sl = websGetVar (wp, n, NULL); |
|---|
| 3767 | if (sl) |
|---|
| 3768 | { |
|---|
| 3769 | char *slc = (char *) malloc (strlen (sl) + 1); |
|---|
| 3770 | strcpy (slc, sl); |
|---|
| 3771 | int i, sllen = strlen (slc); |
|---|
| 3772 | for (i = 0; i < sllen; i++) |
|---|
| 3773 | { |
|---|
| 3774 | if (slc[i] == ';') |
|---|
| 3775 | slc[i] = ' '; |
|---|
| 3776 | if (slc[i] == ',') |
|---|
| 3777 | slc[i] = ' '; |
|---|
| 3778 | } |
|---|
| 3779 | nvram_set (n, slc); |
|---|
| 3780 | } |
|---|
| 3781 | } |
|---|
| 3782 | #ifdef HAVE_MAKSAT |
|---|
| 3783 | sprintf (n, "ath_specialmode"); |
|---|
| 3784 | copytonv (wp, n); |
|---|
| 3785 | |
|---|
| 3786 | #endif |
|---|
| 3787 | sprintf (n, "%s_regdomain", prefix); |
|---|
| 3788 | copytonv (wp, n); |
|---|
| 3789 | |
|---|
| 3790 | sprintf (turbo, "%s_turbo", prefix); |
|---|
| 3791 | char *tw = websGetVar (wp, turbo, NULL); |
|---|
| 3792 | |
|---|
| 3793 | if (tw && !nvram_match (turbo, tw)) |
|---|
| 3794 | { |
|---|
| 3795 | turbochanged = 1; |
|---|
| 3796 | } |
|---|
| 3797 | if (tw) |
|---|
| 3798 | nvram_set (turbo, tw); |
|---|
| 3799 | |
|---|
| 3800 | sprintf (n, "%s_rate", prefix); |
|---|
| 3801 | copytonv (wp, n); |
|---|
| 3802 | sprintf (n, "%s_maxrate", prefix); |
|---|
| 3803 | copytonv (wp, n); |
|---|
| 3804 | sprintf (n, "%s_xr", prefix); |
|---|
| 3805 | copytonv (wp, n); |
|---|
| 3806 | // sprintf (n, "%s_xchanmode", prefix); |
|---|
| 3807 | // copytonv (wp, n); |
|---|
| 3808 | sprintf (n, "%s_outdoor", prefix); |
|---|
| 3809 | copytonv (wp, n); |
|---|
| 3810 | sprintf (n, "%s_compression", prefix); // Atheros SuperG header compression |
|---|
| 3811 | copytonv (wp, n); |
|---|
| 3812 | sprintf (n, "%s_ff", prefix); // ff = 0, Atheros SuperG fast framing disabled, 1 fast framing enabled |
|---|
| 3813 | copytonv (wp, n); |
|---|
| 3814 | sprintf (n, "%s_diversity", prefix); |
|---|
| 3815 | copytonv (wp, n); |
|---|
| 3816 | sprintf (n, "%s_preamble", prefix); |
|---|
| 3817 | copytonv (wp, n); |
|---|
| 3818 | sprintf (n, "%s_wmm", prefix); |
|---|
| 3819 | copytonv (wp, n); |
|---|
| 3820 | sprintf (n, "%s_txantenna", prefix); |
|---|
| 3821 | copytonv (wp, n); |
|---|
| 3822 | // sprintf (n, "wifi_bonding"); |
|---|
| 3823 | // copytonv (wp, n); |
|---|
| 3824 | sprintf (n, "%s_rxantenna", prefix); |
|---|
| 3825 | copytonv (wp, n); |
|---|
| 3826 | |
|---|
| 3827 | sprintf (chanbw, "%s_channelbw", prefix); |
|---|
| 3828 | char *cbw = websGetVar (wp, chanbw, NULL); |
|---|
| 3829 | |
|---|
| 3830 | if (cbw && !nvram_match (chanbw, cbw)) |
|---|
| 3831 | { |
|---|
| 3832 | cbwchanged = 1; |
|---|
| 3833 | } |
|---|
| 3834 | if (cbw) |
|---|
| 3835 | nvram_set (chanbw, cbw); |
|---|
| 3836 | |
|---|
| 3837 | sprintf (n, "%s_xr", prefix); |
|---|
| 3838 | copytonv (wp, n); |
|---|
| 3839 | sprintf (sifs, "%s_sifstime", prefix); |
|---|
| 3840 | copytonv (wp, sifs); |
|---|
| 3841 | sprintf (preamble, "%s_preambletime", prefix); |
|---|
| 3842 | copytonv (wp, preamble); |
|---|
| 3843 | |
|---|
| 3844 | |
|---|
| 3845 | #endif |
|---|
| 3846 | sprintf (n, "%s_closed", prefix); |
|---|
| 3847 | copytonv (wp, n); |
|---|
| 3848 | sprintf (n, "%s_bridged", prefix); |
|---|
| 3849 | copytonv (wp, n); |
|---|
| 3850 | |
|---|
| 3851 | char addr[32]; |
|---|
| 3852 | sprintf (n, "%s_ipaddr", prefix); |
|---|
| 3853 | if (get_merge_ipaddr (wp, n, addr)) |
|---|
| 3854 | nvram_set (n, addr); |
|---|
| 3855 | |
|---|
| 3856 | sprintf (n, "%s_netmask", prefix); |
|---|
| 3857 | if (get_merge_ipaddr (wp, n, addr)) |
|---|
| 3858 | nvram_set (n, addr); |
|---|
| 3859 | |
|---|
| 3860 | copytonv (wp, n); |
|---|
| 3861 | sprintf (n, "%s_ap_isolate", prefix); |
|---|
| 3862 | copytonv (wp, n); |
|---|
| 3863 | sprintf (n, "%s_mode", prefix); |
|---|
| 3864 | copytonv (wp, n); |
|---|
| 3865 | if (!strcmp (prefix, "wl0")) |
|---|
| 3866 | { |
|---|
| 3867 | char *wl = websGetVar (wp, n, NULL); |
|---|
| 3868 | cprintf ("copy value %s which is [%s] to nvram\n", n, wl); |
|---|
| 3869 | if (wl) |
|---|
| 3870 | nvram_set ("wl_mode", wl); |
|---|
| 3871 | #ifndef HAVE_MADWIFI |
|---|
| 3872 | if (strcmp (wl, "ap") && strcmp (wl, "apsta") |
|---|
| 3873 | && strcmp (wl, "apstawet")) |
|---|
| 3874 | { |
|---|
| 3875 | nvram_set ("wl0_vifs", ""); |
|---|
| 3876 | } |
|---|
| 3877 | #endif |
|---|
| 3878 | } |
|---|
| 3879 | int chanchanged = 0; |
|---|
| 3880 | #ifndef HAVE_MADWIFI |
|---|
| 3881 | if (!strcmp (prefix, "wl0")) |
|---|
| 3882 | #endif |
|---|
| 3883 | { |
|---|
| 3884 | |
|---|
| 3885 | sprintf (n, "%s_net_mode", prefix); |
|---|
| 3886 | if (!nvram_match (n, websGetVar (wp, n, ""))) |
|---|
| 3887 | { |
|---|
| 3888 | chanchanged = 1; |
|---|
| 3889 | copytonv (wp, n); |
|---|
| 3890 | //#ifndef HAVE_MADWIFI |
|---|
| 3891 | convert_wl_gmode (nvram_safe_get (n)); |
|---|
| 3892 | //#endif |
|---|
| 3893 | } |
|---|
| 3894 | } |
|---|
| 3895 | #ifdef HAVE_MADWIFI |
|---|
| 3896 | if (cbwchanged || chanchanged || turbochanged) |
|---|
| 3897 | { |
|---|
| 3898 | if (nvram_match (turbo, "1")) |
|---|
| 3899 | { |
|---|
| 3900 | nvram_set (sifs, "8"); |
|---|
| 3901 | nvram_set (preamble, "14"); |
|---|
| 3902 | } |
|---|
| 3903 | else if (nvram_match (chanbw, "5")) |
|---|
| 3904 | { |
|---|
| 3905 | nvram_set (sifs, "64"); |
|---|
| 3906 | nvram_set (preamble, "80"); |
|---|
| 3907 | } |
|---|
| 3908 | else if (nvram_match (chanbw, "10")) |
|---|
| 3909 | { |
|---|
| 3910 | nvram_set (sifs, "32"); |
|---|
| 3911 | nvram_set (preamble, "40"); |
|---|
| 3912 | } |
|---|
| 3913 | else |
|---|
| 3914 | { |
|---|
| 3915 | nvram_set (sifs, "16"); |
|---|
| 3916 | nvram_set (preamble, "20"); |
|---|
| 3917 | } |
|---|
| 3918 | |
|---|
| 3919 | } |
|---|
| 3920 | #endif |
|---|
| 3921 | sprintf (n, "%s_nbw", prefix); |
|---|
| 3922 | copytonv (wp, n); |
|---|
| 3923 | sprintf (n, "%s_nctrlsb", prefix); |
|---|
| 3924 | copytonv (wp, n); |
|---|
| 3925 | |
|---|
| 3926 | |
|---|
| 3927 | |
|---|
| 3928 | sprintf (n, "%s_channel", prefix); |
|---|
| 3929 | if (!strcmp (prefix, "wl0")) |
|---|
| 3930 | { |
|---|
| 3931 | char *wl = websGetVar (wp, n, NULL); |
|---|
| 3932 | cprintf ("copy value %s which is [%s] to nvram\n", n, wl); |
|---|
| 3933 | if (wl) |
|---|
| 3934 | nvram_set ("wl_channel", wl); |
|---|
| 3935 | } |
|---|
| 3936 | copytonv (wp, n); |
|---|
| 3937 | |
|---|
| 3938 | sprintf (n, "%s_wchannel", prefix); |
|---|
| 3939 | if (!strcmp (prefix, "wl0")) |
|---|
| 3940 | { |
|---|
| 3941 | char *wl = websGetVar (wp, n, NULL); |
|---|
| 3942 | cprintf ("copy value %s which is [%s] to nvram\n", n, wl); |
|---|
| 3943 | if (wl) |
|---|
| 3944 | nvram_set ("wl_wchannel", wl); |
|---|
| 3945 | } |
|---|
| 3946 | |
|---|
| 3947 | copytonv (wp, n); |
|---|
| 3948 | |
|---|
| 3949 | } |
|---|
| 3950 | |
|---|
| 3951 | void |
|---|
| 3952 | wireless_save (webs_t wp) |
|---|
| 3953 | { |
|---|
| 3954 | char *value = websGetVar (wp, "action", ""); |
|---|
| 3955 | addAction ("wireless"); |
|---|
| 3956 | #ifdef HAVE_MSSID |
|---|
| 3957 | char *next; |
|---|
| 3958 | char var[80]; |
|---|
| 3959 | char vif[16]; |
|---|
| 3960 | #ifndef HAVE_MADWIFI |
|---|
| 3961 | save_prefix (wp, "wl0"); |
|---|
| 3962 | char *vifs = nvram_safe_get ("wl0_vifs"); |
|---|
| 3963 | #else |
|---|
| 3964 | int c = getdevicecount (); |
|---|
| 3965 | int i; |
|---|
| 3966 | for (i = 0; i < c; i++) |
|---|
| 3967 | { |
|---|
| 3968 | sprintf (vif, "ath%d_vifs", i); |
|---|
| 3969 | char buf[16]; |
|---|
| 3970 | sprintf (buf, "ath%d", i); |
|---|
| 3971 | save_prefix (wp, buf); |
|---|
| 3972 | char *vifs = nvram_safe_get (vif); |
|---|
| 3973 | |
|---|
| 3974 | #endif |
|---|
| 3975 | if (vifs == NULL) |
|---|
| 3976 | return; |
|---|
| 3977 | foreach (var, vifs, next) |
|---|
| 3978 | { |
|---|
| 3979 | save_prefix (wp, var); |
|---|
| 3980 | } |
|---|
| 3981 | #ifdef HAVE_MADWIFI |
|---|
| 3982 | } |
|---|
| 3983 | #endif |
|---|
| 3984 | //nvram_commit (); |
|---|
| 3985 | #endif |
|---|
| 3986 | if (!strcmp (value, "ApplyTake")) |
|---|
| 3987 | { |
|---|
| 3988 | nvram_commit (); |
|---|
| 3989 | service_restart (); |
|---|
| 3990 | } |
|---|
| 3991 | } |
|---|
| 3992 | |
|---|
| 3993 | void |
|---|
| 3994 | ej_showad (webs_t wp, int argc, char_t ** argv) |
|---|
| 3995 | { |
|---|
| 3996 | #ifndef HAVE_FON |
|---|
| 3997 | #ifndef CONFIG_BRANDING |
|---|
| 3998 | #ifdef HAVE_CHILLI |
|---|
| 3999 | // if (nvram_invmatch ("fon_enable", "1")) |
|---|
| 4000 | // websWrite (wp, |
|---|
| 4001 | // "<a href=\"fon.cgi\"><img src=\"images/turn.gif\" border=0 /></a>"); |
|---|
| 4002 | #endif |
|---|
| 4003 | #endif |
|---|
| 4004 | #endif |
|---|
| 4005 | |
|---|
| 4006 | |
|---|
| 4007 | #ifndef HAVE_NOAD |
|---|
| 4008 | /* |
|---|
| 4009 | if (nvram_match("wanup","1")) |
|---|
| 4010 | { |
|---|
| 4011 | websWrite(wp,"<script type=\"text/javascript\"><!--\n//<![CDATA[\n "); |
|---|
| 4012 | websWrite(wp,"google_ad_client = \"pub-8308593183433068\";\n"); |
|---|
| 4013 | websWrite(wp,"google_ad_width = 728;\n"); |
|---|
| 4014 | websWrite(wp,"google_ad_height = 90;\n"); |
|---|
| 4015 | websWrite(wp,"google_ad_format = \"728x90_as\";\n"); |
|---|
| 4016 | websWrite(wp,"google_ad_type = \"text_image\";\n"); |
|---|
| 4017 | websWrite(wp,"google_ad_channel =\"8866414571\";\n"); |
|---|
| 4018 | websWrite(wp,"google_color_border = \"333333\";\n"); |
|---|
| 4019 | websWrite(wp,"google_color_bg = \"000000\";\n"); |
|---|
| 4020 | websWrite(wp,"google_color_link = \"FFFFFF\";\n"); |
|---|
| 4021 | websWrite(wp,"google_color_url = \"999999\";\n"); |
|---|
| 4022 | websWrite(wp,"google_color_text = \"CCCCCC\";\n"); |
|---|
| 4023 | websWrite(wp,"//-->//]]>\n</script>\n"); |
|---|
| 4024 | websWrite(wp,"<script type=\"text/javascript\"\n"); |
|---|
| 4025 | websWrite(wp," src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n"); |
|---|
| 4026 | websWrite(wp,"</script>\n"); |
|---|
| 4027 | }*/ |
|---|
| 4028 | #endif |
|---|
| 4029 | return; |
|---|
| 4030 | } |
|---|
| 4031 | |
|---|
| 4032 | |
|---|
| 4033 | #ifdef HAVE_MSSID |
|---|
| 4034 | #ifdef HAVE_MADWIFI |
|---|
| 4035 | |
|---|
| 4036 | static int |
|---|
| 4037 | getMaxPower (char *ifname) |
|---|
| 4038 | { |
|---|
| 4039 | char buf[128]; |
|---|
| 4040 | sprintf (buf, "iwlist %s txpower|grep \"Maximum Power:\" > /tmp/.power", |
|---|
| 4041 | ifname); |
|---|
| 4042 | system2 (buf); |
|---|
| 4043 | FILE *in = fopen ("/tmp/.power", "rb"); |
|---|
| 4044 | if (in == NULL) |
|---|
| 4045 | return 1000; |
|---|
| 4046 | char buf2[16]; |
|---|
| 4047 | int max; |
|---|
| 4048 | fscanf (in, "%s %s %d", buf, buf2, &max); |
|---|
| 4049 | fclose (in); |
|---|
| 4050 | return max; |
|---|
| 4051 | } |
|---|
| 4052 | |
|---|
| 4053 | |
|---|
| 4054 | #endif |
|---|
| 4055 | |
|---|
| 4056 | |
|---|
| 4057 | void |
|---|
| 4058 | ej_show_wireless_single (webs_t wp, char *prefix) |
|---|
| 4059 | { |
|---|
| 4060 | char wl_mode[16]; |
|---|
| 4061 | char wl_macaddr[16]; |
|---|
| 4062 | char wl_ssid[16]; |
|---|
| 4063 | sprintf (wl_mode, "%s_mode", prefix); |
|---|
| 4064 | sprintf (wl_macaddr, "%s_hwaddr", prefix); |
|---|
| 4065 | sprintf (wl_ssid, "%s_ssid", prefix); |
|---|
| 4066 | |
|---|
| 4067 | |
|---|
| 4068 | //wireless mode |
|---|
| 4069 | websWrite (wp, |
|---|
| 4070 | "<h2><script type=\"text/javascript\">Capture(wl_basic.h2_v24)</script> %s</h2>\n", |
|---|
| 4071 | prefix); |
|---|
| 4072 | websWrite (wp, "<fieldset>\n"); |
|---|
| 4073 | websWrite (wp, |
|---|
| 4074 | "<legend><script type=\"text/javascript\">Capture(share.pintrface)</script> %s - SSID [%s] HWAddr [%s]</legend>\n", |
|---|
| 4075 | prefix, nvram_safe_get (wl_ssid), nvram_safe_get (wl_macaddr)); |
|---|
| 4076 | char power[16]; |
|---|
| 4077 | // char maxpower[16]; |
|---|
| 4078 | #ifdef HAVE_MADWIFI |
|---|
| 4079 | char wl_regdomain[16]; |
|---|
| 4080 | sprintf (wl_regdomain, "%s_regdomain", prefix); |
|---|
| 4081 | if (nvram_match ("ath_regulatory", "1")) |
|---|
| 4082 | { |
|---|
| 4083 | websWrite (wp, |
|---|
| 4084 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.regdom)</script></div>\n"); |
|---|
| 4085 | char *list = getCountryList (); |
|---|
| 4086 | showOptions (wp, wl_regdomain, list, nvram_safe_get (wl_regdomain)); |
|---|
| 4087 | websWrite (wp, "</div>\n"); |
|---|
| 4088 | } |
|---|
| 4089 | /* while (regdomains[domcount].name != NULL) |
|---|
| 4090 | { |
|---|
| 4091 | char domcode[16]; |
|---|
| 4092 | sprintf (domcode, "%d", regdomains[domcount].code); |
|---|
| 4093 | websWrite (wp, "<option value=\"%d\" %s>%s</option>\n", |
|---|
| 4094 | regdomains[domcount].code, nvram_match (wl_regdomain, |
|---|
| 4095 | domcode) ? |
|---|
| 4096 | " selected=\"selected\"" : "", regdomains[domcount].name); |
|---|
| 4097 | domcount++; |
|---|
| 4098 | } |
|---|
| 4099 | websWrite (wp, "</select>\n"); |
|---|
| 4100 | websWrite (wp, "</div>\n");*/ |
|---|
| 4101 | //power adjustment |
|---|
| 4102 | sprintf (power, "%s_txpwrdbm", prefix); |
|---|
| 4103 | // sprintf (maxpower, "%s_maxpower", prefix); |
|---|
| 4104 | if (!strcmp (prefix, "ath0")) //show client only on first interface |
|---|
| 4105 | { |
|---|
| 4106 | #if !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_MERAKI) |
|---|
| 4107 | |
|---|
| 4108 | websWrite (wp, " <div class=\"setting\">\n"); |
|---|
| 4109 | websWrite (wp, |
|---|
| 4110 | " <div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.regulatory)</script></div>\n"); |
|---|
| 4111 | websWrite (wp, |
|---|
| 4112 | " <input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"ath_regulatory\" %s /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 4113 | nvram_match ("ath_regulatory", "1") ? "checked" : ""); |
|---|
| 4114 | websWrite (wp, |
|---|
| 4115 | " <input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"ath_regulatory\" %s /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 4116 | nvram_match ("ath_regulatory", "0") ? "checked" : ""); |
|---|
| 4117 | websWrite (wp, " </div>\n"); |
|---|
| 4118 | #else |
|---|
| 4119 | #ifdef WILLIAM |
|---|
| 4120 | websWrite (wp, " <div class=\"setting\">\n"); |
|---|
| 4121 | websWrite (wp, |
|---|
| 4122 | " <div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.regulatory)</script></div>\n"); |
|---|
| 4123 | websWrite (wp, |
|---|
| 4124 | " <input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"ath_regulatory\" %s /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 4125 | nvram_match ("ath_regulatory", "1") ? "checked" : ""); |
|---|
| 4126 | websWrite (wp, |
|---|
| 4127 | " <input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"ath_regulatory\" %s /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 4128 | nvram_match ("ath_regulatory", "0") ? "checked" : ""); |
|---|
| 4129 | websWrite (wp, " </div>\n"); |
|---|
| 4130 | #endif |
|---|
| 4131 | |
|---|
| 4132 | |
|---|
| 4133 | |
|---|
| 4134 | #endif |
|---|
| 4135 | |
|---|
| 4136 | } |
|---|
| 4137 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4138 | websWrite (wp, |
|---|
| 4139 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.TXpower)</script></div><input class=\"num\" name=\"%s\" size=\"6\" maxlength=\"3\" value=\"%s\" /> dBm\n", |
|---|
| 4140 | power, nvram_safe_get (power)); |
|---|
| 4141 | websWrite (wp, "</div>\n"); |
|---|
| 4142 | sprintf (power, "%s_antgain", prefix); |
|---|
| 4143 | #ifndef HAVE_MAKSAT |
|---|
| 4144 | if (nvram_match ("ath_regulatory", "1")) |
|---|
| 4145 | #endif |
|---|
| 4146 | { |
|---|
| 4147 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4148 | websWrite (wp, |
|---|
| 4149 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.AntGain)</script></div><input class=\"num\" name=\"%s\" size=\"6\" maxlength=\"3\" value=\"%s\" /> dBi\n", |
|---|
| 4150 | power, nvram_safe_get (power)); |
|---|
| 4151 | websWrite (wp, "</div>\n"); |
|---|
| 4152 | } |
|---|
| 4153 | #endif |
|---|
| 4154 | #ifdef HAVE_MADWIFI |
|---|
| 4155 | // if (!strcmp (prefix, "ath0")) |
|---|
| 4156 | #endif |
|---|
| 4157 | { |
|---|
| 4158 | //#ifdef HAVE_MADWIFI |
|---|
| 4159 | // if (!strcmp (prefix, "ath0")) //show client only on first interface |
|---|
| 4160 | //#endif |
|---|
| 4161 | { |
|---|
| 4162 | #ifdef HAVE_MADWIFI |
|---|
| 4163 | // if (!strcmp (prefix, "ath0")) //show client only on first interface |
|---|
| 4164 | // if (nvram_match ("ath0_mode", "wdsap") |
|---|
| 4165 | // || nvram_match ("ath0_mode", "wdssta")) |
|---|
| 4166 | // showOption (wp, "wl_basic.wifi_bonding", "wifi_bonding"); |
|---|
| 4167 | #endif |
|---|
| 4168 | websWrite (wp, |
|---|
| 4169 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label)</script></div><select name=\"%s\" >\n", |
|---|
| 4170 | wl_mode); |
|---|
| 4171 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 4172 | websWrite (wp, |
|---|
| 4173 | "document.write(\"<option value=\\\"ap\\\" %s >\" + wl_basic.ap + \"</option>\");\n", |
|---|
| 4174 | nvram_match (wl_mode, |
|---|
| 4175 | "ap") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4176 | websWrite (wp, |
|---|
| 4177 | "document.write(\"<option value=\\\"sta\\\" %s >\" + wl_basic.client + \"</option>\");\n", |
|---|
| 4178 | nvram_match (wl_mode, |
|---|
| 4179 | "sta") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4180 | websWrite (wp, |
|---|
| 4181 | "document.write(\"<option value=\\\"wet\\\" %s >\" + wl_basic.clientBridge + \"</option>\");\n", |
|---|
| 4182 | nvram_match (wl_mode, |
|---|
| 4183 | "wet") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4184 | websWrite (wp, |
|---|
| 4185 | "document.write(\"<option value=\\\"infra\\\" %s >\" + wl_basic.adhoc + \"</option>\");\n", |
|---|
| 4186 | nvram_match (wl_mode, |
|---|
| 4187 | "infra") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4188 | #ifndef HAVE_MADWIFI |
|---|
| 4189 | websWrite (wp, |
|---|
| 4190 | "document.write(\"<option value=\\\"apsta\\\" %s >\" + wl_basic.repeater + \"</option>\");\n", |
|---|
| 4191 | nvram_match (wl_mode, |
|---|
| 4192 | "apsta") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4193 | websWrite (wp, |
|---|
| 4194 | "document.write(\"<option value=\\\"apstawet\\\" %s >\" + wl_basic.repeaterbridge + \"</option>\");\n", |
|---|
| 4195 | nvram_match (wl_mode, |
|---|
| 4196 | "apstawet") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4197 | #else |
|---|
| 4198 | websWrite (wp, |
|---|
| 4199 | "document.write(\"<option value=\\\"wdssta\\\" %s >\" + wl_basic.wdssta + \"</option>\");\n", |
|---|
| 4200 | nvram_match (wl_mode, |
|---|
| 4201 | "wdssta") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4202 | websWrite (wp, |
|---|
| 4203 | "document.write(\"<option value=\\\"wdsap\\\" %s >\" + wl_basic.wdsap + \"</option>\");\n", |
|---|
| 4204 | nvram_match (wl_mode, |
|---|
| 4205 | "wdsap") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4206 | #endif |
|---|
| 4207 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4208 | websWrite (wp, "</select>\n"); |
|---|
| 4209 | websWrite (wp, "</div>\n"); |
|---|
| 4210 | } |
|---|
| 4211 | /*#ifdef HAVE_MADWIFI |
|---|
| 4212 | else |
|---|
| 4213 | { |
|---|
| 4214 | |
|---|
| 4215 | |
|---|
| 4216 | websWrite (wp, |
|---|
| 4217 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label)</script></div><select name=\"%s\">\n", |
|---|
| 4218 | wl_mode); |
|---|
| 4219 | websWrite (wp, |
|---|
| 4220 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"ap\\\" %s >\" + wl_basic.ap + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 4221 | nvram_match (wl_mode, |
|---|
| 4222 | "ap") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4223 | websWrite (wp, |
|---|
| 4224 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"infra\\\" %s >\" + wl_basic.adhoc + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 4225 | nvram_match (wl_mode, |
|---|
| 4226 | "infra") ? "selected=\\\"selected\\\"" : |
|---|
| 4227 | ""); |
|---|
| 4228 | websWrite (wp, |
|---|
| 4229 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"wdssta\\\" %s >\" + wl_basic.wdssta + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 4230 | nvram_match (wl_mode, |
|---|
| 4231 | "wdssta") ? "selected=\\\"selected\\\"" : |
|---|
| 4232 | ""); |
|---|
| 4233 | websWrite (wp, |
|---|
| 4234 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"wdsap\\\" %s >\" + wl_basic.wdsap + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 4235 | nvram_match (wl_mode, |
|---|
| 4236 | "wdsap") ? "selected=\\\"selected\\\"" : |
|---|
| 4237 | ""); |
|---|
| 4238 | websWrite (wp, "</select>\n"); |
|---|
| 4239 | websWrite (wp, "</div>\n"); |
|---|
| 4240 | } |
|---|
| 4241 | #endif*/ |
|---|
| 4242 | } |
|---|
| 4243 | //writeless net mode |
|---|
| 4244 | show_netmode (wp, prefix); |
|---|
| 4245 | //turbo options |
|---|
| 4246 | #ifdef HAVE_MADWIFI |
|---|
| 4247 | char wl_turbo[16]; |
|---|
| 4248 | // char wl_xchanmode[16]; |
|---|
| 4249 | char wl_outdoor[16]; |
|---|
| 4250 | char wl_diversity[16]; |
|---|
| 4251 | char wl_rxantenna[16]; |
|---|
| 4252 | char wl_txantenna[16]; |
|---|
| 4253 | char wl_width[16]; |
|---|
| 4254 | char wl_preamble[16]; |
|---|
| 4255 | char wl_xr[16]; |
|---|
| 4256 | char wl_comp[32]; |
|---|
| 4257 | char wl_ff[16]; |
|---|
| 4258 | char wmm[32]; |
|---|
| 4259 | char wl_isolate[32]; |
|---|
| 4260 | char wl_sifstime[32]; |
|---|
| 4261 | char wl_preambletime[32]; |
|---|
| 4262 | sprintf (wl_turbo, "%s_turbo", prefix); |
|---|
| 4263 | // sprintf (wl_xchanmode, "%s_xchanmode", prefix); |
|---|
| 4264 | sprintf (wl_outdoor, "%s_outdoor", prefix); |
|---|
| 4265 | sprintf (wl_diversity, "%s_diversity", prefix); |
|---|
| 4266 | sprintf (wl_rxantenna, "%s_rxantenna", prefix); |
|---|
| 4267 | sprintf (wl_txantenna, "%s_txantenna", prefix); |
|---|
| 4268 | sprintf (wl_width, "%s_channelbw", prefix); |
|---|
| 4269 | sprintf (wl_comp, "%s_compression", prefix); |
|---|
| 4270 | sprintf (wl_ff, "%s_ff", prefix); |
|---|
| 4271 | sprintf (wl_preamble, "%s_preamble", prefix); |
|---|
| 4272 | sprintf (wl_preambletime, "%s_preambletime", prefix); |
|---|
| 4273 | sprintf (wl_sifstime, "%s_sifstime", prefix); |
|---|
| 4274 | sprintf (wl_xr, "%s_xr", prefix); |
|---|
| 4275 | show_rates (wp, prefix, 0); |
|---|
| 4276 | show_rates (wp, prefix, 1); |
|---|
| 4277 | #if !defined(HAVE_FONERA) && !defined(HAVE_LS2) && !defined(HAVE_MERAKI) |
|---|
| 4278 | showOption (wp, "wl_basic.turbo", wl_turbo); |
|---|
| 4279 | #endif |
|---|
| 4280 | showOption (wp, "wl_basic.preamble", wl_preamble); |
|---|
| 4281 | showOption (wp, "wl_basic.extrange", wl_xr); |
|---|
| 4282 | showOption (wp, "wl_basic.supergcomp", wl_comp); |
|---|
| 4283 | showOption (wp, "wl_basic.supergff", wl_ff); |
|---|
| 4284 | |
|---|
| 4285 | |
|---|
| 4286 | // showOption (wp, "wl_basic.extchannel", wl_xchanmode); |
|---|
| 4287 | #if !defined(HAVE_FONERA) && !defined(HAVE_LS2) && !defined(HAVE_MERAKI) |
|---|
| 4288 | if (nvram_match ("ath_regulatory", "1")) |
|---|
| 4289 | { |
|---|
| 4290 | showOption (wp, "wl_basic.outband", wl_outdoor); |
|---|
| 4291 | } |
|---|
| 4292 | #endif |
|---|
| 4293 | showOption (wp, "wl_basic.diversity", wl_diversity); |
|---|
| 4294 | #if !defined(HAVE_FONERA) |
|---|
| 4295 | websWrite (wp, |
|---|
| 4296 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.channel_width)</script></div><select name=\"%s\" >\n", |
|---|
| 4297 | wl_width); |
|---|
| 4298 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 4299 | websWrite (wp, |
|---|
| 4300 | "document.write(\"<option value=\\\"20\\\" %s >\" + share.full + \"</option>\");\n", |
|---|
| 4301 | nvram_match (wl_width, "20") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4302 | websWrite (wp, |
|---|
| 4303 | "document.write(\"<option value=\\\"10\\\" %s >\" + share.half + \"</option>\");\n", |
|---|
| 4304 | nvram_match (wl_width, "10") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4305 | websWrite (wp, |
|---|
| 4306 | "document.write(\"<option value=\\\"5\\\" %s >\" + share.quarter + \"</option>\");\n", |
|---|
| 4307 | nvram_match (wl_width, "5") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4308 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4309 | websWrite (wp, "</select>\n"); |
|---|
| 4310 | websWrite (wp, "</div>\n"); |
|---|
| 4311 | #endif |
|---|
| 4312 | |
|---|
| 4313 | websWrite (wp, |
|---|
| 4314 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label12)</script></div><select name=\"%s\" >\n", |
|---|
| 4315 | wl_txantenna); |
|---|
| 4316 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 4317 | websWrite (wp, |
|---|
| 4318 | "document.write(\"<option value=\\\"0\\\" %s >\" + wl_basic.diversity + \"</option>\");\n", |
|---|
| 4319 | nvram_match (wl_txantenna, |
|---|
| 4320 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4321 | websWrite (wp, |
|---|
| 4322 | "document.write(\"<option value=\\\"1\\\" %s >\" + wl_basic.primary + \"</option>\");\n", |
|---|
| 4323 | nvram_match (wl_txantenna, |
|---|
| 4324 | "1") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4325 | websWrite (wp, |
|---|
| 4326 | "document.write(\"<option value=\\\"2\\\" %s >\" + wl_basic.secondary + \"</option>\");\n", |
|---|
| 4327 | nvram_match (wl_txantenna, |
|---|
| 4328 | "2") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4329 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4330 | websWrite (wp, "</select>\n"); |
|---|
| 4331 | websWrite (wp, "</div>\n"); |
|---|
| 4332 | |
|---|
| 4333 | websWrite (wp, |
|---|
| 4334 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label13)</script></div><select name=\"%s\" >\n", |
|---|
| 4335 | wl_rxantenna); |
|---|
| 4336 | websWrite (wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 4337 | websWrite (wp, |
|---|
| 4338 | "document.write(\"<option value=\\\"0\\\" %s >\" + wl_basic.diversity + \"</option>\");\n", |
|---|
| 4339 | nvram_match (wl_rxantenna, |
|---|
| 4340 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4341 | websWrite (wp, |
|---|
| 4342 | "document.write(\"<option value=\\\"1\\\" %s >\" + wl_basic.primary + \"</option>\");\n", |
|---|
| 4343 | nvram_match (wl_rxantenna, |
|---|
| 4344 | "1") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4345 | websWrite (wp, |
|---|
| 4346 | "document.write(\"<option value=\\\"2\\\" %s >\" + wl_basic.secondary + \"</option>\");\n", |
|---|
| 4347 | nvram_match (wl_rxantenna, |
|---|
| 4348 | "2") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4349 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4350 | websWrite (wp, "</select>\n"); |
|---|
| 4351 | websWrite (wp, "</div>\n"); |
|---|
| 4352 | |
|---|
| 4353 | #endif |
|---|
| 4354 | #ifdef HAVE_MADWIFI |
|---|
| 4355 | sprintf (wl_isolate, "%s_ap_isolate", prefix); |
|---|
| 4356 | showOption (wp, "wl_adv.label11", wl_isolate); |
|---|
| 4357 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4358 | websWrite (wp, |
|---|
| 4359 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.sifstime)</script></div>\n"); |
|---|
| 4360 | websWrite (wp, |
|---|
| 4361 | "<input class=\"num\" name=\"%s\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,99999999,wl_basic.sifstime)\" value=\"%s\" />\n", |
|---|
| 4362 | wl_sifstime, nvram_default_get (wl_sifstime, "16")); |
|---|
| 4363 | websWrite (wp, "</div>\n"); |
|---|
| 4364 | |
|---|
| 4365 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4366 | websWrite (wp, |
|---|
| 4367 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.preambletime)</script></div>\n"); |
|---|
| 4368 | websWrite (wp, |
|---|
| 4369 | "<input class=\"num\" name=\"%s\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,99999999,wl_basic.preambletime)\" value=\"%s\" />\n", |
|---|
| 4370 | wl_preambletime, nvram_default_get (wl_preambletime, "20")); |
|---|
| 4371 | websWrite (wp, "</div>\n"); |
|---|
| 4372 | sprintf (wmm, "%s_wmm", prefix); |
|---|
| 4373 | showOption (wp, "wl_adv.label18", wmm); |
|---|
| 4374 | #endif |
|---|
| 4375 | |
|---|
| 4376 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4377 | websWrite (wp, |
|---|
| 4378 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label3)</script></div><input name=\"%s\" size=\"20\" maxlength=\"32\" onblur=\"valid_name(this,wl_basic.label3)\" value=\"%s\" /></div>\n", |
|---|
| 4379 | wl_ssid, nvram_safe_get (wl_ssid)); |
|---|
| 4380 | |
|---|
| 4381 | if (nvram_match (wl_mode, "ap") || nvram_match (wl_mode, "apsta") |
|---|
| 4382 | || nvram_match (wl_mode, "apstawet") || nvram_match (wl_mode, "wdsap") |
|---|
| 4383 | || nvram_match (wl_mode, "infra")) |
|---|
| 4384 | { |
|---|
| 4385 | |
|---|
| 4386 | if (has_mimo () |
|---|
| 4387 | && (nvram_match ("wl0_net_mode", "n-only") |
|---|
| 4388 | || nvram_match ("wl0_net_mode", "mixed"))) |
|---|
| 4389 | { |
|---|
| 4390 | |
|---|
| 4391 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4392 | websWrite (wp, |
|---|
| 4393 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.channel_width)</script></div>\n"); |
|---|
| 4394 | websWrite (wp, "<select name=\"wl0_nbw\">\n"); |
|---|
| 4395 | websWrite (wp, |
|---|
| 4396 | "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"0\\\" %s >\" + share.auto + \"</option>\");\n//]]>\n</script>\n", |
|---|
| 4397 | nvram_match ("wl0_nbw", |
|---|
| 4398 | "0") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4399 | websWrite (wp, "<option value=\"10\" %s>10 MHz</option>", |
|---|
| 4400 | nvram_match ("wl0_nbw", |
|---|
| 4401 | "10") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4402 | websWrite (wp, "<option value=\"20\" %s>20 MHz</option>", |
|---|
| 4403 | nvram_match ("wl0_nbw", |
|---|
| 4404 | "20") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4405 | websWrite (wp, "<option value=\"40\" %s>40 MHz</option>", |
|---|
| 4406 | nvram_match ("wl0_nbw", |
|---|
| 4407 | "40") ? "selected=\\\"selected\\\"" : ""); |
|---|
| 4408 | websWrite (wp, "</select>\n"); |
|---|
| 4409 | websWrite (wp, "</div>\n"); |
|---|
| 4410 | |
|---|
| 4411 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4412 | websWrite (wp, |
|---|
| 4413 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.channel_wide)</script></div>\n"); |
|---|
| 4414 | websWrite (wp, "<select name=\"wl0_wchannel\" ></select>\n"); |
|---|
| 4415 | websWrite (wp, "</div>\n"); |
|---|
| 4416 | |
|---|
| 4417 | show_channel (wp, prefix, prefix, 1); |
|---|
| 4418 | } |
|---|
| 4419 | else |
|---|
| 4420 | |
|---|
| 4421 | show_channel (wp, prefix, prefix, 0); |
|---|
| 4422 | |
|---|
| 4423 | char wl_closed[16]; |
|---|
| 4424 | sprintf (wl_closed, "%s_closed", prefix); |
|---|
| 4425 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4426 | websWrite (wp, |
|---|
| 4427 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label5)</script></div>\n"); |
|---|
| 4428 | websWrite (wp, |
|---|
| 4429 | "<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input> \n", |
|---|
| 4430 | wl_closed, nvram_match (wl_closed, |
|---|
| 4431 | "0") ? "checked=\"checked\"" : ""); |
|---|
| 4432 | websWrite (wp, |
|---|
| 4433 | "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>\n", |
|---|
| 4434 | wl_closed, nvram_match (wl_closed, |
|---|
| 4435 | "1") ? "checked=\"checked\"" : ""); |
|---|
| 4436 | websWrite (wp, "</div>\n"); |
|---|
| 4437 | } |
|---|
| 4438 | #ifdef HAVE_MADWIFI |
|---|
| 4439 | if (nvram_match (wl_mode, "sta") || nvram_match (wl_mode, "wdssta") |
|---|
| 4440 | || nvram_match (wl_mode, "wet")) |
|---|
| 4441 | { |
|---|
| 4442 | char wl_scanlist[32]; |
|---|
| 4443 | sprintf (wl_scanlist, "%s_scanlist", prefix); |
|---|
| 4444 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4445 | websWrite (wp, |
|---|
| 4446 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.scanlist)</script></div>\n"); |
|---|
| 4447 | websWrite (wp, |
|---|
| 4448 | "<input name=\"%s\" size=\"32\" maxlength=\"512\" value=\"%s\" />\n", |
|---|
| 4449 | wl_scanlist, nvram_default_get (wl_scanlist, "default")); |
|---|
| 4450 | websWrite (wp, "</div>\n"); |
|---|
| 4451 | } |
|---|
| 4452 | #endif |
|---|
| 4453 | |
|---|
| 4454 | // ACK timing |
|---|
| 4455 | #if defined(HAVE_ACK) || defined(HAVE_MADWIFI) //temp fix for v24 broadcom ACKnot working |
|---|
| 4456 | |
|---|
| 4457 | sprintf (power, "%s_distance", prefix); |
|---|
| 4458 | websWrite (wp, "<br />\n"); |
|---|
| 4459 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4460 | websWrite (wp, |
|---|
| 4461 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label6)</script></div>\n"); |
|---|
| 4462 | websWrite (wp, |
|---|
| 4463 | "<input class=\"num\" name=\"%s\" size=\"8\" maxlength=\"8\" onblur=\"valid_range(this,0,99999999,wl_basic.label6)\" value=\"%s\" />\n", |
|---|
| 4464 | power, nvram_safe_get (power)); |
|---|
| 4465 | websWrite (wp, |
|---|
| 4466 | "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 2000 \" + share.meters + \")\");\n//]]>\n</script></span>\n"); |
|---|
| 4467 | websWrite (wp, "</div>\n"); |
|---|
| 4468 | // end ACK timing |
|---|
| 4469 | #endif |
|---|
| 4470 | |
|---|
| 4471 | showbridgesettings (wp, prefix); |
|---|
| 4472 | websWrite (wp, "</fieldset>\n"); |
|---|
| 4473 | websWrite (wp, "<br />\n"); |
|---|
| 4474 | show_virtualssid (wp, prefix); |
|---|
| 4475 | } |
|---|
| 4476 | |
|---|
| 4477 | void |
|---|
| 4478 | ej_show_wireless (webs_t wp, int argc, char_t ** argv) |
|---|
| 4479 | { |
|---|
| 4480 | #ifdef HAVE_MADWIFI |
|---|
| 4481 | int c = getdevicecount (); |
|---|
| 4482 | int i; |
|---|
| 4483 | for (i = 0; i < c; i++) |
|---|
| 4484 | { |
|---|
| 4485 | char buf[16]; |
|---|
| 4486 | sprintf (buf, "ath%d", i); |
|---|
| 4487 | ej_show_wireless_single (wp, buf); |
|---|
| 4488 | } |
|---|
| 4489 | #else |
|---|
| 4490 | ej_show_wireless_single (wp, "wl0"); |
|---|
| 4491 | #endif |
|---|
| 4492 | return; |
|---|
| 4493 | } |
|---|
| 4494 | |
|---|
| 4495 | void |
|---|
| 4496 | changeKeySize (webs_t wp) |
|---|
| 4497 | { |
|---|
| 4498 | security_save (wp); |
|---|
| 4499 | } |
|---|
| 4500 | |
|---|
| 4501 | void |
|---|
| 4502 | show_preshared (webs_t wp, char *prefix) |
|---|
| 4503 | { |
|---|
| 4504 | char var[80]; |
|---|
| 4505 | cprintf ("show preshared"); |
|---|
| 4506 | sprintf (var, "%s_crypto", prefix); |
|---|
| 4507 | websWrite (wp, "<div><div class=\"setting\">\n"); |
|---|
| 4508 | websWrite (wp, |
|---|
| 4509 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.algorithms)</script></div>\n"); |
|---|
| 4510 | websWrite (wp, "<select name=\"%s_crypto\">\n", prefix); |
|---|
| 4511 | websWrite (wp, "<option value=\"tkip\" %s>TKIP</option>\n", |
|---|
| 4512 | selmatch (var, "tkip", "selected=\"selected\"")); |
|---|
| 4513 | websWrite (wp, "<option value=\"aes\" %s>AES</option>\n", |
|---|
| 4514 | selmatch (var, "aes", "selected=\"selected\"")); |
|---|
| 4515 | websWrite (wp, "<option value=\"tkip+aes\" %s>TKIP+AES</option>\n", |
|---|
| 4516 | selmatch (var, "tkip+aes", "selected=\"selected\"")); |
|---|
| 4517 | websWrite (wp, "</select>\n"); |
|---|
| 4518 | websWrite (wp, "</div>\n"); |
|---|
| 4519 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4520 | websWrite (wp, |
|---|
| 4521 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.shared_key)</script></div>\n"); |
|---|
| 4522 | sprintf (var, "%s_wpa_psk", prefix); |
|---|
| 4523 | websWrite (wp, |
|---|
| 4524 | "<input type=\"password\" id=\"%s_wpa_psk\" name=\"%s_wpa_psk\" onblur=\"valid_psk_length(this)\" maxlength=\"64\" size=\"32\" value=\"", |
|---|
| 4525 | prefix, prefix); |
|---|
| 4526 | tf_webWriteESCNV (wp, var); |
|---|
| 4527 | websWrite (wp, "\" /> \n"); |
|---|
| 4528 | websWrite (wp, |
|---|
| 4529 | "<input type=\"checkbox\" name=\"%s_wl_unmask\" value=\"0\" onclick=\"setElementMask('%s_wpa_psk', this.checked)\" > <script type=\"text/javascript\">Capture(share.unmask)</script></input>\n", |
|---|
| 4530 | prefix, prefix); |
|---|
| 4531 | websWrite (wp, "</div>\n"); |
|---|
| 4532 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4533 | websWrite (wp, |
|---|
| 4534 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.rekey)</script></div>\n"); |
|---|
| 4535 | sprintf (var, "%s_wpa_gtk_rekey", prefix); |
|---|
| 4536 | websWrite (wp, |
|---|
| 4537 | "<input class=\"num\" name=\"%s_wpa_gtk_rekey\" maxlength=\"5\" size=\"5\" onblur=\"valid_range(this,0,99999,wpa.rekey)\" value=\"%s\" />\n", |
|---|
| 4538 | prefix, nvram_safe_get (var)); |
|---|
| 4539 | websWrite (wp, |
|---|
| 4540 | "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 3600, \" + share.range + \": 1 - 99999)\");\n//]]>\n</script></span>\n"); |
|---|
| 4541 | websWrite (wp, "</div>\n"); |
|---|
| 4542 | websWrite (wp, "</div>\n"); |
|---|
| 4543 | } |
|---|
| 4544 | |
|---|
| 4545 | void |
|---|
| 4546 | show_radius (webs_t wp, char *prefix, int showmacformat) |
|---|
| 4547 | { |
|---|
| 4548 | char var[80]; |
|---|
| 4549 | cprintf ("show radius\n"); |
|---|
| 4550 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4551 | websWrite (wp, |
|---|
| 4552 | "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label3)</script></div>\n"); |
|---|
| 4553 | websWrite (wp, |
|---|
| 4554 | "<input type=\"hidden\" name=\"%s_radius_ipaddr\" value=\"4\" />\n", |
|---|
| 4555 | prefix); |
|---|
| 4556 | sprintf (var, "%s_radius_ipaddr", prefix); |
|---|
| 4557 | char *rad = nvram_safe_get (var); |
|---|
| 4558 | websWrite (wp, |
|---|
| 4559 | "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_0\" onblur=\"valid_range(this,0,255,radius.label3)\" class=\"num\" value=\"%d\" />.", |
|---|
| 4560 | prefix, get_single_ip (rad, 0)); |
|---|
| 4561 | websWrite (wp, |
|---|
| 4562 | "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_1\" onblur=\"valid_range(this,0,255,radius.label3)\" class=\"num\" value=\"%d\" />.", |
|---|
| 4563 | prefix, get_single_ip (rad, 1)); |
|---|
| 4564 | websWrite (wp, |
|---|
| 4565 | "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_2\" onblur=\"valid_range(this,0,255,radius.label3)\" class=\"num\" value=\"%d\" />.", |
|---|
| 4566 | prefix, get_single_ip (rad, 2)); |
|---|
| 4567 | websWrite (wp, |
|---|
| 4568 | "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_3\" onblur=\"valid_range(this,1,254,radius.label3)\" class=\"num\" value=\"%d\" />\n", |
|---|
| 4569 | prefix, get_single_ip (rad, 3)); |
|---|
| 4570 | websWrite (wp, "</div>\n"); |
|---|
| 4571 | if (showmacformat) |
|---|
| 4572 | { |
|---|
| 4573 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4574 | websWrite (wp, |
|---|
| 4575 | "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label2)</script></div>\n"); |
|---|
| 4576 | websWrite (wp, "<select name=\"%s_radmactype\">\n", prefix); |
|---|
| 4577 | websWrite (wp, "<option value=\"0\" %s >aabbcc-ddeeff</option>\n", |
|---|
| 4578 | nvram_prefix_match ("radmactype", prefix, |
|---|
| 4579 | "0") ? "selected" : ""); |
|---|
| 4580 | websWrite (wp, "<option value=\"1\" %s >aabbccddeeff</option>\n", |
|---|
| 4581 | nvram_prefix_match ("radmactype", prefix, |
|---|
| 4582 | "1") ? "selected" : ""); |
|---|
| 4583 | websWrite (wp, "<option value=\"2\" %s >aa:bb:cc:dd:ee:ff</option>\n", |
|---|
| 4584 | nvram_prefix_match ("radmactype", prefix, |
|---|
| 4585 | "2") ? "selected" : ""); |
|---|
| 4586 | websWrite (wp, "<option value=\"3\" %s >aa-bb-cc-dd-ee-ff</option>\n", |
|---|
| 4587 | nvram_prefix_match ("radmactype", prefix, |
|---|
| 4588 | "3") ? "selected" : ""); |
|---|
| 4589 | websWrite (wp, "</select>\n"); |
|---|
| 4590 | websWrite (wp, "</div>\n"); |
|---|
| 4591 | } |
|---|
| 4592 | |
|---|
| 4593 | |
|---|
| 4594 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4595 | websWrite (wp, |
|---|
| 4596 | "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label4)</script></div>\n"); |
|---|
| 4597 | sprintf (var, "%s_radius_port", prefix); |
|---|
| 4598 | websWrite (wp, |
|---|
| 4599 | "<input name=\"%s_radius_port\" size=\"3\" maxlength=\"5\" onblur=\"valid_range(this,1,65535,radius.label4)\" value=\"%s\" /></div>\n", |
|---|
| 4600 | prefix, nvram_safe_get (var)); |
|---|
| 4601 | websWrite (wp, |
|---|
| 4602 | "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 1812)\");\n//]]>\n</script></span>\n"); |
|---|
| 4603 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4604 | websWrite (wp, |
|---|
| 4605 | "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label7)</script></div>\n"); |
|---|
| 4606 | sprintf (var, "%s_radius_key", prefix); |
|---|
| 4607 | websWrite (wp, |
|---|
| 4608 | "<input name=\"%s_radius_key\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4609 | prefix, nvram_safe_get (var)); |
|---|
| 4610 | } |
|---|
| 4611 | |
|---|
| 4612 | |
|---|
| 4613 | #ifdef HAVE_WPA_SUPPLICANT |
|---|
| 4614 | void |
|---|
| 4615 | show_80211X (webs_t wp, char *prefix) |
|---|
| 4616 | { |
|---|
| 4617 | /* |
|---|
| 4618 | * fields |
|---|
| 4619 | * _8021xtype |
|---|
| 4620 | * _8021xuser |
|---|
| 4621 | * _8021xpasswd |
|---|
| 4622 | * _8021xca |
|---|
| 4623 | * _8021xpem |
|---|
| 4624 | * _8021xprv |
|---|
| 4625 | */ |
|---|
| 4626 | /* |
|---|
| 4627 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4628 | websWrite (wp,"<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.xsuptype)</script></div>\n"); |
|---|
| 4629 | websWrite (wp, "<select name=\"%s_8021xtype\" onchange=\"change_80211x(this.form.security_mode.selectedIndex,this.form)\">\n", prefix); |
|---|
| 4630 | websWrite (wp, "<option value=\"peap\" onclick=\"enable_idpeap()\" %s >Peap</option>\n",nvram_prefix_match ("8021xtype", prefix,"peap") ? "selected" : ""); |
|---|
| 4631 | websWrite (wp, "<option value=\"leap\" onclick=\"enable_idleap()\" %s >Leap</option>\n",nvram_prefix_match ("8021xtype", prefix,"leap") ? "selected" : ""); |
|---|
| 4632 | websWrite (wp, "<option value=\"tls\" onclick=\"enable_idtls()\" %s >TLS</option>\n",nvram_prefix_match ("8021xtype", prefix,"tls") ? "selected" : ""); |
|---|
| 4633 | websWrite (wp, "</select>\n"); |
|---|
| 4634 | websWrite (wp, "</div>\n"); |
|---|
| 4635 | */ |
|---|
| 4636 | |
|---|
| 4637 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4638 | websWrite (wp, |
|---|
| 4639 | "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.xsuptype)</script></div>\n"); |
|---|
| 4640 | websWrite (wp, |
|---|
| 4641 | "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"peap\" onclick=\"enable_idpeap('%s')\" %s />Peap \n", |
|---|
| 4642 | prefix, prefix, nvram_prefix_match ("8021xtype", prefix, |
|---|
| 4643 | "peap") ? |
|---|
| 4644 | "checked=\"checked\"" : ""); |
|---|
| 4645 | websWrite (wp, |
|---|
| 4646 | "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"leap\" onclick=\"enable_idleap('%s')\" %s />Leap \n", |
|---|
| 4647 | prefix, prefix, nvram_prefix_match ("8021xtype", prefix, |
|---|
| 4648 | "leap") ? |
|---|
| 4649 | "checked=\"checked\"" : ""); |
|---|
| 4650 | websWrite (wp, |
|---|
| 4651 | "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"tls\" onclick=\"enable_idtls('%s')\" %s />TLS \n", |
|---|
| 4652 | prefix, prefix, nvram_prefix_match ("8021xtype", prefix, |
|---|
| 4653 | "tls") ? |
|---|
| 4654 | "checked=\"checked\"" : ""); |
|---|
| 4655 | websWrite (wp, "</div>\n"); |
|---|
| 4656 | |
|---|
| 4657 | |
|---|
| 4658 | |
|---|
| 4659 | |
|---|
| 4660 | //peap authentication |
|---|
| 4661 | websWrite (wp, "<div id=\"idpeap%s\">\n", prefix); |
|---|
| 4662 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4663 | websWrite (wp, |
|---|
| 4664 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n"); |
|---|
| 4665 | websWrite (wp, |
|---|
| 4666 | "<input name=\"%s_peap8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4667 | prefix, nvram_prefix_get ("peap8021xuser", prefix)); |
|---|
| 4668 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4669 | websWrite (wp, |
|---|
| 4670 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n"); |
|---|
| 4671 | websWrite (wp, |
|---|
| 4672 | "<input name=\"%s_peap8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4673 | prefix, nvram_prefix_get ("peap8021xpasswd", prefix)); |
|---|
| 4674 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4675 | websWrite (wp, |
|---|
| 4676 | "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.servercertif)</script></div>\n"); |
|---|
| 4677 | websWrite (wp, |
|---|
| 4678 | "<textarea cols=\"60\" rows=\"6\" id=\"%s_peap8021xca\" name=\"%s_peap8021xca\"></textarea><script language=\"text/javascript\">\n//<![CDATA[\n ", |
|---|
| 4679 | prefix, prefix); |
|---|
| 4680 | websWrite (wp, "var %s_peap8021xca = fix_cr( '%s' );\n", prefix, |
|---|
| 4681 | nvram_prefix_get ("peap8021xca", prefix)); |
|---|
| 4682 | websWrite (wp, |
|---|
| 4683 | "document.getElementById(\"%s_peap8021xca\").value = %s_peap8021xca;\n", |
|---|
| 4684 | prefix, prefix); |
|---|
| 4685 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4686 | websWrite (wp, "</div>\n"); |
|---|
| 4687 | websWrite (wp, "</div>\n"); |
|---|
| 4688 | //leap authentication |
|---|
| 4689 | websWrite (wp, "<div id=\"idleap%s\">\n", prefix); |
|---|
| 4690 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4691 | websWrite (wp, |
|---|
| 4692 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n"); |
|---|
| 4693 | websWrite (wp, |
|---|
| 4694 | "<input name=\"%s_peap8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4695 | prefix, nvram_prefix_get ("peap8021xuser", prefix)); |
|---|
| 4696 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4697 | websWrite (wp, |
|---|
| 4698 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n"); |
|---|
| 4699 | websWrite (wp, |
|---|
| 4700 | "<input name=\"%s_peap8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4701 | prefix, nvram_prefix_get ("peap8021xpasswd", prefix)); |
|---|
| 4702 | websWrite (wp, "</div>\n"); |
|---|
| 4703 | |
|---|
| 4704 | |
|---|
| 4705 | //tls authentication |
|---|
| 4706 | websWrite (wp, "<div id=\"idtls%s\">\n", prefix); |
|---|
| 4707 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4708 | websWrite (wp, |
|---|
| 4709 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n"); |
|---|
| 4710 | websWrite (wp, |
|---|
| 4711 | "<input name=\"%s_tls8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4712 | prefix, nvram_prefix_get ("tls8021xuser", prefix)); |
|---|
| 4713 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4714 | websWrite (wp, |
|---|
| 4715 | "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n"); |
|---|
| 4716 | websWrite (wp, |
|---|
| 4717 | "<input name=\"%s_tls8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n", |
|---|
| 4718 | prefix, nvram_prefix_get ("tls8021xpasswd", prefix)); |
|---|
| 4719 | |
|---|
| 4720 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4721 | websWrite (wp, |
|---|
| 4722 | "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.servercertif)</script></div>\n"); |
|---|
| 4723 | websWrite (wp, |
|---|
| 4724 | "<textarea cols=\"60\" rows=\"6\" id=\"%s_tls8021xca\" name=\"%s_tls8021xca\"></textarea><script language=\"text/javascript\">\n//<![CDATA[\n ", |
|---|
| 4725 | prefix, prefix); |
|---|
| 4726 | websWrite (wp, "var %s_tls8021xca = fix_cr( '%s' );\n", prefix, |
|---|
| 4727 | nvram_prefix_get ("tls8021xca", prefix)); |
|---|
| 4728 | websWrite (wp, |
|---|
| 4729 | "document.getElementById(\"%s_tls8021xca\").value = %s_tls8021xca;\n", |
|---|
| 4730 | prefix, prefix); |
|---|
| 4731 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4732 | websWrite (wp, "</div>\n"); |
|---|
| 4733 | |
|---|
| 4734 | |
|---|
| 4735 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4736 | websWrite (wp, |
|---|
| 4737 | "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.clientcertif)</script></div>\n"); |
|---|
| 4738 | websWrite (wp, |
|---|
| 4739 | "<textarea cols=\"60\" rows=\"6\" id=\"%s_tls8021xpem\" name=\"%s_tls8021xpem\"></textarea><script language=\"text/javascript\">\n//<![CDATA[\n ", |
|---|
| 4740 | prefix, prefix); |
|---|
| 4741 | websWrite (wp, "var %s_tls8021xpem = fix_cr( '%s' );\n", prefix, |
|---|
| 4742 | nvram_prefix_get ("tls8021xpem", prefix)); |
|---|
| 4743 | websWrite (wp, |
|---|
| 4744 | "document.getElementById(\"%s_tls8021xpem\").value = %s_tls8021xpem;\n", |
|---|
| 4745 | prefix, prefix); |
|---|
| 4746 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4747 | websWrite (wp, "</div>\n"); |
|---|
| 4748 | |
|---|
| 4749 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4750 | websWrite (wp, |
|---|
| 4751 | "<div class=\"label\">P<script type=\"text/javascript\">Capture(share.privatekey)</script></div>\n"); |
|---|
| 4752 | websWrite (wp, |
|---|
| 4753 | "<textarea cols=\"60\" rows=\"6\" id=\"%s_tls8021xprv\" name=\"%s_tls8021xprv\"></textarea><script language=\"text/javascript\">\n//<![CDATA[\n ", |
|---|
| 4754 | prefix, prefix); |
|---|
| 4755 | websWrite (wp, "var %s_tls8021xprv = fix_cr( '%s' );\n", prefix, |
|---|
| 4756 | nvram_prefix_get ("tls8021xprv", prefix)); |
|---|
| 4757 | websWrite (wp, |
|---|
| 4758 | "document.getElementById(\"%s_tls8021xprv\").value = %s_tls8021xprv;\n", |
|---|
| 4759 | prefix, prefix); |
|---|
| 4760 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4761 | websWrite (wp, "</div>\n"); |
|---|
| 4762 | |
|---|
| 4763 | websWrite (wp, "</div>\n"); |
|---|
| 4764 | websWrite (wp, "<script>\n//<![CDATA[\n "); |
|---|
| 4765 | // websWrite (wp,"show_layer_ext(document.getElementsByName(\"%s_bridged\"), \"%s_idnetvifs\", %s);\n",var, vvar, nvram_match (ssid, "0") ? "true" : "false"); |
|---|
| 4766 | char peap[32]; |
|---|
| 4767 | sprintf (peap, "%s_8021xtype", prefix); |
|---|
| 4768 | websWrite (wp, |
|---|
| 4769 | "show_layer_ext(document.wpa.%s_8021xtype, 'idpeap%s', %s);\n", |
|---|
| 4770 | prefix, prefix, nvram_match (peap, "peap") ? "true" : "false"); |
|---|
| 4771 | websWrite (wp, |
|---|
| 4772 | "show_layer_ext(document.wpa.%s_8021xtype, 'idtls%s', %s);\n", |
|---|
| 4773 | prefix, prefix, nvram_match (peap, "tls") ? "true" : "false"); |
|---|
| 4774 | websWrite (wp, |
|---|
| 4775 | "show_layer_ext(document.wpa.%s_8021xtype, 'idleap%s', %s);\n", |
|---|
| 4776 | prefix, prefix, nvram_match (peap, "leap") ? "true" : "false"); |
|---|
| 4777 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 4778 | |
|---|
| 4779 | } |
|---|
| 4780 | #endif |
|---|
| 4781 | |
|---|
| 4782 | void |
|---|
| 4783 | show_wparadius (webs_t wp, char *prefix) |
|---|
| 4784 | { |
|---|
| 4785 | char var[80]; |
|---|
| 4786 | websWrite (wp, "<div>\n"); |
|---|
| 4787 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4788 | websWrite (wp, |
|---|
| 4789 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.algorithms)</script></div>\n"); |
|---|
| 4790 | websWrite (wp, "<select name=\"%s_crypto\">\n", prefix); |
|---|
| 4791 | sprintf (var, "%s_crypto", prefix); |
|---|
| 4792 | websWrite (wp, "<option value=\"tkip\" %s>TKIP</option>\n", |
|---|
| 4793 | selmatch (var, "tkip", "selected=\"selected\"")); |
|---|
| 4794 | websWrite (wp, "<option value=\"aes\" %s>AES</option>\n", |
|---|
| 4795 | selmatch (var, "aes", "selected=\"selected\"")); |
|---|
| 4796 | websWrite (wp, "<option value=\"tkip+aes\" %s>TKIP+AES</option>\n", |
|---|
| 4797 | selmatch (var, "tkip+aes", "selected=\"selected\"")); |
|---|
| 4798 | websWrite (wp, "</select></div>\n"); |
|---|
| 4799 | show_radius (wp, prefix, 0); |
|---|
| 4800 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 4801 | websWrite (wp, |
|---|
| 4802 | "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.rekey)</script></div>\n"); |
|---|
| 4803 | sprintf (var, "%s_wpa_gtk_rekey", prefix); |
|---|
| 4804 | websWrite (wp, |
|---|
| 4805 | "<input name=\"%s_wpa_gtk_rekey\" maxlength=\"5\" size=\"10\" onblur=\"valid_range(this,0,99999,wpa.rekey)\" value=\"%s\" />", |
|---|
| 4806 | prefix, nvram_safe_get (var)); |
|---|
| 4807 | websWrite (wp, "</div>\n"); |
|---|
| 4808 | websWrite (wp, "</div>\n"); |
|---|
| 4809 | } |
|---|
| 4810 | |
|---|
| 4811 | void |
|---|
| 4812 | show_wep (webs_t wp, char *prefix) |
|---|
| 4813 | { |
|---|
| 4814 | char var[80]; |
|---|
| 4815 | char *bit; |
|---|
| 4816 | cprintf ("show wep\n"); |
|---|
| 4817 | websWrite (wp, |
|---|
| 4818 | "<div><div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wep.defkey)</script></div>"); |
|---|
| 4819 | websWrite (wp, "<input type=\"hidden\" name=\"%s_WEP_key\" />", prefix); |
|---|
| 4820 | websWrite (wp, |
|---|
| 4821 | "<input type=\"hidden\" name=\"%s_wep\" value=\"restricted\" />", |
|---|
| 4822 | prefix); |
|---|
| 4823 | sprintf (var, "%s_key", prefix); |
|---|
| 4824 | websWrite (wp, |
|---|
| 4825 | "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s_key\" %s />1 \n", |
|---|
| 4826 | prefix, selmatch (var, "1", "checked=\"checked\"")); |
|---|
| 4827 | websWrite (wp, |
|---|
| 4828 | "<input class=\"spaceradio\" type=\"radio\" value=\"2\" name=\"%s_key\" %s />2 \n", |
|---|
| 4829 | prefix, selmatch (var, "2", "checked=\"checked\"")); |
|---|
| 4830 | websWrite (wp, |
|---|
| 4831 | "<input class=\"spaceradio\" type=\"radio\" value=\"3\" name=\"%s_key\" %s />3 \n", |
|---|
| 4832 | prefix, selmatch (var, "3", "checked=\"checked\"")); |
|---|
| 4833 | websWrite (wp, |
|---|
| 4834 | "<input class=\"spaceradio\" type=\"radio\" value=\"4\" name=\"%s_key\" %s />4 \n", |
|---|
| 4835 | prefix, selmatch (var, "4", "checked=\"checked\"")); |
|---|
| 4836 | websWrite (wp, "</div>"); |
|---|
| 4837 | websWrite (wp, |
|---|
| 4838 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.encrypt)</script></div>"); |
|---|
| 4839 | |
|---|
| 4840 | sprintf (var, "%s_wep_bit", prefix); |
|---|
| 4841 | bit = nvram_safe_get (var); |
|---|
| 4842 | |
|---|
| 4843 | cprintf ("bit %s\n", bit); |
|---|
| 4844 | |
|---|
| 4845 | websWrite (wp, |
|---|
| 4846 | "<select name=\"%s_wep_bit\" size=\"1\" onchange=keyMode(this.form)>", |
|---|
| 4847 | prefix); |
|---|
| 4848 | websWrite (wp, "<option value=\"64\" %s >64 bits 10 hex digits</option>", |
|---|
| 4849 | selmatch (var, "64", "selected=\"selected\"")); |
|---|
| 4850 | websWrite (wp, "<option value=\"128\" %s >128 bits 26 hex digits</option>", |
|---|
| 4851 | selmatch (var, "128", "selected=\"selected\"")); |
|---|
| 4852 | websWrite (wp, |
|---|
| 4853 | "</select>\n</div>\n<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wep.passphrase)</script></div>\n"); |
|---|
| 4854 | websWrite (wp, |
|---|
| 4855 | "<input name=%s_passphrase maxlength=\"16\" size=\"20\" value=\"%s\" />", |
|---|
| 4856 | prefix, get_wep_value ("passphrase", bit, prefix)); |
|---|
| 4857 | websWrite (wp, |
|---|
| 4858 | "<input type=\"hidden\" value=\"Null\" name=\"generateButton\" />\n"); |
|---|
| 4859 | |
|---|
| 4860 | if (strcmp (bit, "64")) |
|---|
| 4861 | websWrite (wp, |
|---|
| 4862 | "<input class=\"button\" type=\"button\" value=\"Generate\" onclick=generateKey64(this.form,\"%s\") name=wepGenerate />\n</div>", |
|---|
| 4863 | prefix); |
|---|
| 4864 | else |
|---|
| 4865 | websWrite (wp, |
|---|
| 4866 | "<input class=\"button\" type=\"button\" value=\"Generate\" onclick=generateKey128(this.form,\"%s\") name=wepGenerate />\n</div>", |
|---|
| 4867 | prefix); |
|---|
| 4868 | |
|---|
| 4869 | websWrite (wp, |
|---|
| 4870 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 1</div>\n"); |
|---|
| 4871 | websWrite (wp, "<input name=%s_key1 size=\"36\" value=\"%s\" /></div>\n", |
|---|
| 4872 | prefix, get_wep_value ("key1", bit, prefix)); |
|---|
| 4873 | websWrite (wp, |
|---|
| 4874 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 2</div>\n"); |
|---|
| 4875 | websWrite (wp, "<input name=%s_key2 size=\"36\" value=\"%s\" /></div>\n", |
|---|
| 4876 | prefix, get_wep_value ("key2", bit, prefix)); |
|---|
| 4877 | websWrite (wp, |
|---|
| 4878 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 3</div>\n"); |
|---|
| 4879 | websWrite (wp, "<input name=%s_key3 size=\"36\" value=\"%s\" /></div>\n", |
|---|
| 4880 | prefix, get_wep_value ("key3", bit, prefix)); |
|---|
| 4881 | websWrite (wp, |
|---|
| 4882 | "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 4</div>\n"); |
|---|
| 4883 | websWrite (wp, "<input name=%s_key4 size=\"36\" value=\"%s\" /></div>\n", |
|---|
| 4884 | prefix, get_wep_value ("key4", bit, prefix)); |
|---|
| 4885 | websWrite (wp, "</div>\n"); |
|---|
| 4886 | } |
|---|
| 4887 | |
|---|
| 4888 | #endif |
|---|
| 4889 | |
|---|
| 4890 | void |
|---|
| 4891 | validate_wds (webs_t wp, char *value, struct variable *v) |
|---|
| 4892 | { |
|---|
| 4893 | #ifdef HAVE_MSSID |
|---|
| 4894 | int h, i, devcount = 1; //changed from 2 to 3 |
|---|
| 4895 | #else |
|---|
| 4896 | int h, i, devcount = 3; //changed from 2 to 3 |
|---|
| 4897 | #endif |
|---|
| 4898 | struct variable wds_variables[] = { |
|---|
| 4899 | {argv:NULL}, |
|---|
| 4900 | {argv:NULL}, |
|---|
| 4901 | {argv:NULL}, |
|---|
| 4902 | {argv:NULL}, |
|---|
| 4903 | {argv:NULL}, |
|---|
| 4904 | }; |
|---|
| 4905 | |
|---|
| 4906 | char *val = NULL; |
|---|
| 4907 | char wds[32] = ""; |
|---|
| 4908 | char wdsif_var[32] = ""; |
|---|
| 4909 | char enabled_var[32]; |
|---|
| 4910 | char hwaddr_var[32] = ""; |
|---|
| 4911 | char ipaddr_var[32] = ""; |
|---|
| 4912 | char netmask_var[32] = ""; |
|---|
| 4913 | char desc_var[32] = ""; |
|---|
| 4914 | char hwaddr[18] = ""; |
|---|
| 4915 | char ipaddr[16] = ""; |
|---|
| 4916 | char netmask[16] = ""; |
|---|
| 4917 | char desc[48] = ""; |
|---|
| 4918 | char wds_if[32] = { 0 }; |
|---|
| 4919 | char wds_list[199] = ""; |
|---|
| 4920 | #ifdef HAVE_MADWIFI |
|---|
| 4921 | char *interface = websGetVar (wp, "interface", NULL); |
|---|
| 4922 | if (interface == NULL) |
|---|
| 4923 | return; |
|---|
| 4924 | #else |
|---|
| 4925 | char *interface = "wl"; |
|---|
| 4926 | #endif |
|---|
| 4927 | |
|---|
| 4928 | char wl0wds[32]; |
|---|
| 4929 | sprintf (wl0wds, "%s_wds", interface); |
|---|
| 4930 | nvram_set (wl0wds, ""); |
|---|
| 4931 | snprintf (wds, 31, "%s_br1", interface); |
|---|
| 4932 | snprintf (enabled_var, 31, "%s_enable", wds); |
|---|
| 4933 | cprintf ("wds_validate\n"); |
|---|
| 4934 | /* validate separate br1 bridge params */ |
|---|
| 4935 | if (nvram_match (enabled_var, "1")) |
|---|
| 4936 | { |
|---|
| 4937 | |
|---|
| 4938 | memset (ipaddr, 0, sizeof (ipaddr)); |
|---|
| 4939 | memset (netmask, 0, sizeof (netmask)); |
|---|
| 4940 | |
|---|
| 4941 | // disable until validated |
|---|
| 4942 | nvram_set (enabled_var, "0"); |
|---|
| 4943 | |
|---|
| 4944 | // subnet params validation |
|---|
| 4945 | for (i = 0; i < 4; i++) |
|---|
| 4946 | { |
|---|
| 4947 | |
|---|
| 4948 | snprintf (ipaddr_var, 31, "%s_%s%d", wds, "ipaddr", i); |
|---|
| 4949 | val = websGetVar (wp, ipaddr_var, NULL); |
|---|
| 4950 | if (val) |
|---|
| 4951 | { |
|---|
| 4952 | strcat (ipaddr, val); |
|---|
| 4953 | if (i < 3) |
|---|
| 4954 | strcat (ipaddr, "."); |
|---|
| 4955 | } |
|---|
| 4956 | else |
|---|
| 4957 | break; |
|---|
| 4958 | |
|---|
| 4959 | snprintf (netmask_var, 31, "%s_%s%d", wds, "netmask", i); |
|---|
| 4960 | val = websGetVar (wp, netmask_var, NULL); |
|---|
| 4961 | if (val) |
|---|
| 4962 | { |
|---|
| 4963 | strcat (netmask, val); |
|---|
| 4964 | |
|---|
| 4965 | if (i < 3) |
|---|
| 4966 | strcat (netmask, "."); |
|---|
| 4967 | } |
|---|
| 4968 | else |
|---|
| 4969 | break; |
|---|
| 4970 | } |
|---|
| 4971 | |
|---|
| 4972 | if (!valid_ipaddr (wp, ipaddr, &wds_variables[1]) || |
|---|
| 4973 | !valid_netmask (wp, netmask, &wds_variables[2])) |
|---|
| 4974 | return; |
|---|
| 4975 | |
|---|
| 4976 | snprintf (ipaddr_var, 31, "%s_%s", wds, "ipaddr"); |
|---|
| 4977 | snprintf (netmask_var, 31, "%s_%s", wds, "netmask"); |
|---|
| 4978 | |
|---|
| 4979 | nvram_set (enabled_var, "1"); |
|---|
| 4980 | snprintf (ipaddr_var, 31, "%s_%s%d", wds, "ipaddr", i); |
|---|
| 4981 | nvram_set (ipaddr_var, ipaddr); |
|---|
| 4982 | snprintf (netmask_var, 31, "%s_%s%d", wds, "netmask", i); |
|---|
| 4983 | nvram_set (netmask_var, netmask); |
|---|
| 4984 | } |
|---|
| 4985 | else |
|---|
| 4986 | nvram_set (enabled_var, "0"); |
|---|
| 4987 | |
|---|
| 4988 | |
|---|
| 4989 | for (h = 1; h <= MAX_WDS_DEVS; h++) |
|---|
| 4990 | { |
|---|
| 4991 | memset (hwaddr, 0, sizeof (hwaddr)); |
|---|
| 4992 | memset (desc, 0, sizeof (desc)); |
|---|
| 4993 | snprintf (wds, 31, "%s_wds%d", interface, h); |
|---|
| 4994 | snprintf (enabled_var, 31, "%s_enable", wds); |
|---|
| 4995 | |
|---|
| 4996 | for (i = 0; i < 6; i++) |
|---|
| 4997 | { |
|---|
| 4998 | |
|---|
| 4999 | snprintf (hwaddr_var, 31, "%s_%s%d", wds, "hwaddr", i); |
|---|
| 5000 | val = websGetVar (wp, hwaddr_var, NULL); |
|---|
| 5001 | |
|---|
| 5002 | if (val) |
|---|
| 5003 | { |
|---|
| 5004 | strcat (hwaddr, val); |
|---|
| 5005 | if (i < 5) |
|---|
| 5006 | strcat (hwaddr, ":"); |
|---|
| 5007 | } |
|---|
| 5008 | } |
|---|
| 5009 | |
|---|
| 5010 | if (!valid_hwaddr (wp, hwaddr, &wds_variables[0])) |
|---|
| 5011 | { |
|---|
| 5012 | return; |
|---|
| 5013 | } |
|---|
| 5014 | |
|---|
| 5015 | snprintf (hwaddr_var, 31, "%s_%s", wds, "hwaddr"); |
|---|
| 5016 | nvram_set (hwaddr_var, hwaddr); |
|---|
| 5017 | |
|---|
| 5018 | snprintf (desc_var, 31, "%s_%s", wds, "desc"); |
|---|
| 5019 | val = websGetVar (wp, desc_var, NULL); |
|---|
| 5020 | if (val) |
|---|
| 5021 | { |
|---|
| 5022 | strcat (desc, val); |
|---|
| 5023 | snprintf (desc_var, 31, "%s_%s", wds, "desc"); |
|---|
| 5024 | nvram_set (desc_var, desc); |
|---|
| 5025 | } |
|---|
| 5026 | |
|---|
| 5027 | /* <lonewolf> */ |
|---|
| 5028 | snprintf (desc_var, 31, "%s_%s", wds, "ospf"); |
|---|
| 5029 | val = websGetVar (wp, desc_var, ""); |
|---|
| 5030 | if (val) |
|---|
| 5031 | { |
|---|
| 5032 | snprintf (desc_var, 31, "%s_%s", wds, "ospf"); |
|---|
| 5033 | nvram_set (desc_var, val); |
|---|
| 5034 | } |
|---|
| 5035 | /* </lonewolf> */ |
|---|
| 5036 | |
|---|
| 5037 | if (strcmp (hwaddr, "00:00:00:00:00:00") |
|---|
| 5038 | && nvram_invmatch (enabled_var, "0")) |
|---|
| 5039 | { |
|---|
| 5040 | snprintf (wds_list, 199, "%s %s", wds_list, hwaddr); |
|---|
| 5041 | } |
|---|
| 5042 | |
|---|
| 5043 | if (nvram_match (enabled_var, "1")) |
|---|
| 5044 | { |
|---|
| 5045 | |
|---|
| 5046 | memset (ipaddr, 0, sizeof (ipaddr)); |
|---|
| 5047 | memset (netmask, 0, sizeof (netmask)); |
|---|
| 5048 | |
|---|
| 5049 | // disable until validated |
|---|
| 5050 | nvram_set (enabled_var, "0"); |
|---|
| 5051 | |
|---|
| 5052 | // subnet params validation |
|---|
| 5053 | for (i = 0; i < 4; i++) |
|---|
| 5054 | { |
|---|
| 5055 | |
|---|
| 5056 | snprintf (ipaddr_var, 31, "%s_%s%d", wds, "ipaddr", i); |
|---|
| 5057 | val = websGetVar (wp, ipaddr_var, NULL); |
|---|
| 5058 | if (val) |
|---|
| 5059 | { |
|---|
| 5060 | strcat (ipaddr, val); |
|---|
| 5061 | if (i < 3) |
|---|
| 5062 | strcat (ipaddr, "."); |
|---|
| 5063 | } |
|---|
| 5064 | else |
|---|
| 5065 | break; |
|---|
| 5066 | |
|---|
| 5067 | snprintf (netmask_var, 31, "%s_%s%d", wds, "netmask", i); |
|---|
| 5068 | val = websGetVar (wp, netmask_var, NULL); |
|---|
| 5069 | if (val) |
|---|
| 5070 | { |
|---|
| 5071 | strcat (netmask, val); |
|---|
| 5072 | |
|---|
| 5073 | if (i < 3) |
|---|
| 5074 | strcat (netmask, "."); |
|---|
| 5075 | } |
|---|
| 5076 | else |
|---|
| 5077 | break; |
|---|
| 5078 | } |
|---|
| 5079 | |
|---|
| 5080 | if (!valid_ipaddr (wp, ipaddr, &wds_variables[1]) || |
|---|
| 5081 | !valid_netmask (wp, netmask, &wds_variables[2])) |
|---|
| 5082 | { |
|---|
| 5083 | continue; |
|---|
| 5084 | } |
|---|
| 5085 | |
|---|
| 5086 | snprintf (ipaddr_var, 31, "%s_%s", wds, "ipaddr"); |
|---|
| 5087 | snprintf (netmask_var, 31, "%s_%s", wds, "netmask"); |
|---|
| 5088 | |
|---|
| 5089 | nvram_set (enabled_var, "1"); |
|---|
| 5090 | nvram_set (ipaddr_var, ipaddr); |
|---|
| 5091 | nvram_set (netmask_var, netmask); |
|---|
| 5092 | } |
|---|
| 5093 | |
|---|
| 5094 | /* keep the wds devices in sync w enabled entries */ |
|---|
| 5095 | snprintf (wdsif_var, 31, "%s_if", wds); |
|---|
| 5096 | if (!nvram_match (enabled_var, "0")) |
|---|
| 5097 | { |
|---|
| 5098 | #ifdef HAVE_MADWIFI |
|---|
| 5099 | snprintf (wds_if, 31, "wds%s.%d", interface, (devcount++)); |
|---|
| 5100 | #elif HAVE_MSSID |
|---|
| 5101 | snprintf (wds_if, 31, "wds0.%d", (devcount++)); |
|---|
| 5102 | #else |
|---|
| 5103 | snprintf (wds_if, 31, "wds0.491%d", 50 + (devcount++)); |
|---|
| 5104 | #endif |
|---|
| 5105 | nvram_set (wdsif_var, wds_if); |
|---|
| 5106 | } |
|---|
| 5107 | else |
|---|
| 5108 | nvram_unset (wdsif_var); |
|---|
| 5109 | |
|---|
| 5110 | } |
|---|
| 5111 | |
|---|
| 5112 | nvram_set (wl0wds, wds_list); |
|---|
| 5113 | } |
|---|
| 5114 | |
|---|
| 5115 | void |
|---|
| 5116 | ej_get_wds_mac (webs_t wp, int argc, char_t ** argv) |
|---|
| 5117 | { |
|---|
| 5118 | int mac = -1, wds_idx = -1, mac_idx = -1; |
|---|
| 5119 | char *c, wds_var[32] = ""; |
|---|
| 5120 | |
|---|
| 5121 | #ifdef HAVE_MADWIFI |
|---|
| 5122 | char *interface; |
|---|
| 5123 | if (ejArgs (argc, argv, "%d %d %s", &wds_idx, &mac_idx, &interface) < 3) |
|---|
| 5124 | { |
|---|
| 5125 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5126 | return; |
|---|
| 5127 | } |
|---|
| 5128 | #else |
|---|
| 5129 | char *interface = "wl"; |
|---|
| 5130 | if (ejArgs (argc, argv, "%d %d", &wds_idx, &mac_idx) < 2) |
|---|
| 5131 | { |
|---|
| 5132 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5133 | return; |
|---|
| 5134 | } |
|---|
| 5135 | #endif |
|---|
| 5136 | else if (wds_idx < 1 || wds_idx > MAX_WDS_DEVS) |
|---|
| 5137 | return; |
|---|
| 5138 | else if (mac_idx < 0 || mac_idx > 5) |
|---|
| 5139 | return; |
|---|
| 5140 | |
|---|
| 5141 | snprintf (wds_var, 31, "%s_wds%d_hwaddr", interface, wds_idx); |
|---|
| 5142 | |
|---|
| 5143 | c = nvram_safe_get (wds_var); |
|---|
| 5144 | |
|---|
| 5145 | if (c) |
|---|
| 5146 | { |
|---|
| 5147 | mac = get_single_mac (c, mac_idx); |
|---|
| 5148 | websWrite (wp, "%02X", mac); |
|---|
| 5149 | } |
|---|
| 5150 | else |
|---|
| 5151 | websWrite (wp, "00"); |
|---|
| 5152 | |
|---|
| 5153 | return; |
|---|
| 5154 | |
|---|
| 5155 | } |
|---|
| 5156 | |
|---|
| 5157 | void |
|---|
| 5158 | ej_get_wds_ip (webs_t wp, int argc, char_t ** argv) |
|---|
| 5159 | { |
|---|
| 5160 | int ip = -1, wds_idx = -1, ip_idx = -1; |
|---|
| 5161 | char *c, wds_var[32] = ""; |
|---|
| 5162 | |
|---|
| 5163 | |
|---|
| 5164 | #ifdef HAVE_MADWIFI |
|---|
| 5165 | char *interface; |
|---|
| 5166 | if (ejArgs (argc, argv, "%d %d %s", &wds_idx, &ip_idx, &interface) < 3) |
|---|
| 5167 | { |
|---|
| 5168 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5169 | return; |
|---|
| 5170 | } |
|---|
| 5171 | #else |
|---|
| 5172 | char *interface = "wl"; |
|---|
| 5173 | if (ejArgs (argc, argv, "%d %d", &wds_idx, &ip_idx) < 2) |
|---|
| 5174 | { |
|---|
| 5175 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5176 | return; |
|---|
| 5177 | } |
|---|
| 5178 | #endif |
|---|
| 5179 | else if (wds_idx < 1 || wds_idx > MAX_WDS_DEVS) |
|---|
| 5180 | return; |
|---|
| 5181 | else if (ip_idx < 0 || ip_idx > 3) |
|---|
| 5182 | return; |
|---|
| 5183 | |
|---|
| 5184 | snprintf (wds_var, 31, "%s_wds%d_ipaddr", interface, wds_idx); |
|---|
| 5185 | |
|---|
| 5186 | c = nvram_safe_get (wds_var); |
|---|
| 5187 | |
|---|
| 5188 | if (c) |
|---|
| 5189 | { |
|---|
| 5190 | ip = get_single_ip (c, ip_idx); |
|---|
| 5191 | websWrite (wp, "%d", ip); |
|---|
| 5192 | } |
|---|
| 5193 | else |
|---|
| 5194 | websWrite (wp, "0"); |
|---|
| 5195 | |
|---|
| 5196 | return; |
|---|
| 5197 | |
|---|
| 5198 | } |
|---|
| 5199 | |
|---|
| 5200 | void |
|---|
| 5201 | ej_get_wds_netmask (webs_t wp, int argc, char_t ** argv) |
|---|
| 5202 | { |
|---|
| 5203 | int nm = -1, wds_idx = -1, nm_idx = -1; |
|---|
| 5204 | char *c, wds_var[32] = ""; |
|---|
| 5205 | |
|---|
| 5206 | |
|---|
| 5207 | #ifdef HAVE_MADWIFI |
|---|
| 5208 | char *interface; |
|---|
| 5209 | if (ejArgs (argc, argv, "%d %d %s", &wds_idx, &nm_idx, &interface) < 3) |
|---|
| 5210 | { |
|---|
| 5211 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5212 | return; |
|---|
| 5213 | } |
|---|
| 5214 | #else |
|---|
| 5215 | char *interface = "wl"; |
|---|
| 5216 | if (ejArgs (argc, argv, "%d %d", &wds_idx, &nm_idx) < 2) |
|---|
| 5217 | { |
|---|
| 5218 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5219 | return; |
|---|
| 5220 | } |
|---|
| 5221 | #endif |
|---|
| 5222 | |
|---|
| 5223 | else if (wds_idx < 1 || wds_idx > 6) |
|---|
| 5224 | return; |
|---|
| 5225 | else if (nm_idx < 0 || nm_idx > 3) |
|---|
| 5226 | return; |
|---|
| 5227 | |
|---|
| 5228 | snprintf (wds_var, 31, "%s_wds%d_netmask", interface, wds_idx); |
|---|
| 5229 | |
|---|
| 5230 | c = nvram_safe_get (wds_var); |
|---|
| 5231 | |
|---|
| 5232 | if (c) |
|---|
| 5233 | { |
|---|
| 5234 | nm = get_single_ip (c, nm_idx); |
|---|
| 5235 | websWrite (wp, "%d", nm); |
|---|
| 5236 | } |
|---|
| 5237 | else |
|---|
| 5238 | websWrite (wp, "255"); |
|---|
| 5239 | |
|---|
| 5240 | return; |
|---|
| 5241 | |
|---|
| 5242 | } |
|---|
| 5243 | |
|---|
| 5244 | |
|---|
| 5245 | void |
|---|
| 5246 | ej_get_wds_gw (webs_t wp, int argc, char_t ** argv) |
|---|
| 5247 | { |
|---|
| 5248 | int gw = -1, wds_idx = -1, gw_idx = -1; |
|---|
| 5249 | char *c, wds_var[32] = ""; |
|---|
| 5250 | |
|---|
| 5251 | |
|---|
| 5252 | |
|---|
| 5253 | #ifdef HAVE_MADWIFI |
|---|
| 5254 | char *interface; |
|---|
| 5255 | if (ejArgs (argc, argv, "%d %d %s", &wds_idx, &gw_idx, &interface) < 3) |
|---|
| 5256 | { |
|---|
| 5257 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5258 | return; |
|---|
| 5259 | } |
|---|
| 5260 | #else |
|---|
| 5261 | char *interface = "wl"; |
|---|
| 5262 | if (ejArgs (argc, argv, "%d %d", &wds_idx, &gw_idx) < 2) |
|---|
| 5263 | { |
|---|
| 5264 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5265 | return; |
|---|
| 5266 | } |
|---|
| 5267 | #endif |
|---|
| 5268 | |
|---|
| 5269 | else if (wds_idx < 1 || wds_idx > MAX_WDS_DEVS) |
|---|
| 5270 | return; |
|---|
| 5271 | else if (gw_idx < 0 || gw_idx > 3) |
|---|
| 5272 | return; |
|---|
| 5273 | |
|---|
| 5274 | snprintf (wds_var, 31, "%s_wds%d_gw", interface, wds_idx); |
|---|
| 5275 | |
|---|
| 5276 | c = nvram_safe_get (wds_var); |
|---|
| 5277 | |
|---|
| 5278 | if (c) |
|---|
| 5279 | { |
|---|
| 5280 | gw = get_single_ip (c, gw_idx); |
|---|
| 5281 | websWrite (wp, "%d", gw); |
|---|
| 5282 | } |
|---|
| 5283 | else |
|---|
| 5284 | websWrite (wp, "0"); |
|---|
| 5285 | |
|---|
| 5286 | return; |
|---|
| 5287 | |
|---|
| 5288 | } |
|---|
| 5289 | |
|---|
| 5290 | void |
|---|
| 5291 | ej_get_br1_ip (webs_t wp, int argc, char_t ** argv) |
|---|
| 5292 | { |
|---|
| 5293 | int ip = -1, ip_idx = -1; |
|---|
| 5294 | char *c; |
|---|
| 5295 | |
|---|
| 5296 | #ifdef HAVE_MADWIFI |
|---|
| 5297 | char *interface; |
|---|
| 5298 | if (ejArgs (argc, argv, "%d %s", &ip_idx, &interface) < 2) |
|---|
| 5299 | { |
|---|
| 5300 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5301 | return; |
|---|
| 5302 | } |
|---|
| 5303 | #else |
|---|
| 5304 | char *interface = "wl"; |
|---|
| 5305 | if (ejArgs (argc, argv, "%d", &ip_idx) < 1) |
|---|
| 5306 | { |
|---|
| 5307 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5308 | return; |
|---|
| 5309 | } |
|---|
| 5310 | #endif |
|---|
| 5311 | else if (ip_idx < 0 || ip_idx > 3) |
|---|
| 5312 | return; |
|---|
| 5313 | char br1[32]; |
|---|
| 5314 | sprintf (br1, "%s_br1_ipaddr", interface); |
|---|
| 5315 | c = nvram_safe_get (br1); |
|---|
| 5316 | |
|---|
| 5317 | if (c) |
|---|
| 5318 | { |
|---|
| 5319 | ip = get_single_ip (c, ip_idx); |
|---|
| 5320 | websWrite (wp, "%d", ip); |
|---|
| 5321 | } |
|---|
| 5322 | else |
|---|
| 5323 | websWrite (wp, "0"); |
|---|
| 5324 | |
|---|
| 5325 | return; |
|---|
| 5326 | |
|---|
| 5327 | } |
|---|
| 5328 | |
|---|
| 5329 | void |
|---|
| 5330 | ej_get_br1_netmask (webs_t wp, int argc, char_t ** argv) |
|---|
| 5331 | { |
|---|
| 5332 | int nm = -1, nm_idx = -1; |
|---|
| 5333 | char *c; |
|---|
| 5334 | |
|---|
| 5335 | |
|---|
| 5336 | #ifdef HAVE_MADWIFI |
|---|
| 5337 | char *interface; |
|---|
| 5338 | if (ejArgs (argc, argv, "%d %s", &nm_idx, &interface) < 2) |
|---|
| 5339 | { |
|---|
| 5340 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5341 | return; |
|---|
| 5342 | } |
|---|
| 5343 | #else |
|---|
| 5344 | char *interface = "wl"; |
|---|
| 5345 | if (ejArgs (argc, argv, "%d", &nm_idx) < 1) |
|---|
| 5346 | { |
|---|
| 5347 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5348 | return; |
|---|
| 5349 | } |
|---|
| 5350 | #endif |
|---|
| 5351 | else if (nm_idx < 0 || nm_idx > 3) |
|---|
| 5352 | return; |
|---|
| 5353 | char nms[32]; |
|---|
| 5354 | sprintf (nms, "%s_br1_netmask", interface); |
|---|
| 5355 | c = nvram_safe_get (nms); |
|---|
| 5356 | |
|---|
| 5357 | if (c) |
|---|
| 5358 | { |
|---|
| 5359 | nm = get_single_ip (c, nm_idx); |
|---|
| 5360 | websWrite (wp, "%d", nm); |
|---|
| 5361 | } |
|---|
| 5362 | else |
|---|
| 5363 | websWrite (wp, "255"); |
|---|
| 5364 | |
|---|
| 5365 | return; |
|---|
| 5366 | |
|---|
| 5367 | } |
|---|
| 5368 | |
|---|
| 5369 | #ifndef HAVE_MADWIFI |
|---|
| 5370 | |
|---|
| 5371 | |
|---|
| 5372 | void |
|---|
| 5373 | ej_get_currate (webs_t wp, int argc, char_t ** argv) |
|---|
| 5374 | { |
|---|
| 5375 | int rate = 0; |
|---|
| 5376 | |
|---|
| 5377 | wl_ioctl (get_wdev (), WLC_GET_RATE, &rate, sizeof (rate)); |
|---|
| 5378 | |
|---|
| 5379 | if (rate > 0) |
|---|
| 5380 | websWrite (wp, "%d%s Mbps", (rate / 2), (rate & 1) ? ".5" : ""); |
|---|
| 5381 | else |
|---|
| 5382 | websWrite (wp, "%s", live_translate ("share.unknown")); |
|---|
| 5383 | |
|---|
| 5384 | return; |
|---|
| 5385 | |
|---|
| 5386 | } |
|---|
| 5387 | #else |
|---|
| 5388 | extern float wifi_getrate (char *ifname); |
|---|
| 5389 | #define KILO 1e3 |
|---|
| 5390 | #define MEGA 1e6 |
|---|
| 5391 | #define GIGA 1e9 |
|---|
| 5392 | |
|---|
| 5393 | void |
|---|
| 5394 | ej_get_currate (webs_t wp, int argc, char_t ** argv) |
|---|
| 5395 | { |
|---|
| 5396 | float rate = wifi_getrate (nvram_safe_get ("wifi_display")); |
|---|
| 5397 | char scale; |
|---|
| 5398 | int divisor; |
|---|
| 5399 | |
|---|
| 5400 | if (rate >= GIGA) |
|---|
| 5401 | { |
|---|
| 5402 | scale = 'G'; |
|---|
| 5403 | divisor = GIGA; |
|---|
| 5404 | } |
|---|
| 5405 | else |
|---|
| 5406 | { |
|---|
| 5407 | if (rate >= MEGA) |
|---|
| 5408 | { |
|---|
| 5409 | scale = 'M'; |
|---|
| 5410 | divisor = MEGA; |
|---|
| 5411 | } |
|---|
| 5412 | else |
|---|
| 5413 | { |
|---|
| 5414 | scale = 'k'; |
|---|
| 5415 | divisor = KILO; |
|---|
| 5416 | } |
|---|
| 5417 | } |
|---|
| 5418 | char mode[32]; |
|---|
| 5419 | sprintf (mode, "%s_turbo", nvram_safe_get ("wifi_display")); |
|---|
| 5420 | if (nvram_match (mode, "1")) |
|---|
| 5421 | rate *= 2; |
|---|
| 5422 | if (rate > 0.0) |
|---|
| 5423 | { |
|---|
| 5424 | websWrite (wp, "%g %cb/s", rate / divisor, scale); |
|---|
| 5425 | } |
|---|
| 5426 | else |
|---|
| 5427 | websWrite (wp, "%s", live_translate ("share.auto")); |
|---|
| 5428 | |
|---|
| 5429 | } |
|---|
| 5430 | #endif |
|---|
| 5431 | |
|---|
| 5432 | #define UPTIME_TMP "/tmp/.uptime" |
|---|
| 5433 | void |
|---|
| 5434 | ej_get_uptime (webs_t wp, int argc, char_t ** argv) |
|---|
| 5435 | { |
|---|
| 5436 | char uptime[200] = { 0 }, cmd[200] = |
|---|
| 5437 | { |
|---|
| 5438 | 0}; |
|---|
| 5439 | FILE *fp; |
|---|
| 5440 | unlink (UPTIME_TMP); |
|---|
| 5441 | |
|---|
| 5442 | snprintf (cmd, 254, "uptime 2>&1 > %s", UPTIME_TMP); |
|---|
| 5443 | system2 (cmd); |
|---|
| 5444 | |
|---|
| 5445 | if ((fp = fopen (UPTIME_TMP, "r")) != NULL) |
|---|
| 5446 | fgets (uptime, sizeof (uptime), fp); |
|---|
| 5447 | else |
|---|
| 5448 | return; |
|---|
| 5449 | int i = 0; |
|---|
| 5450 | while (uptime[i++] != 0 && i < 199) |
|---|
| 5451 | { |
|---|
| 5452 | if (uptime[i] == 0xa || uptime[i] == 0xd) |
|---|
| 5453 | uptime[i] = 0; |
|---|
| 5454 | } |
|---|
| 5455 | websWrite (wp, "%s", uptime); |
|---|
| 5456 | |
|---|
| 5457 | fclose (fp); |
|---|
| 5458 | |
|---|
| 5459 | unlink (UPTIME_TMP); |
|---|
| 5460 | |
|---|
| 5461 | return; |
|---|
| 5462 | |
|---|
| 5463 | } |
|---|
| 5464 | |
|---|
| 5465 | void |
|---|
| 5466 | ej_get_wan_uptime (webs_t wp, int argc, char_t ** argv) |
|---|
| 5467 | { |
|---|
| 5468 | float sys_uptime; |
|---|
| 5469 | float uptime; |
|---|
| 5470 | int days, minutes; |
|---|
| 5471 | FILE *fp, *fp2; |
|---|
| 5472 | |
|---|
| 5473 | if (nvram_match ("wan_proto", "disabled")) |
|---|
| 5474 | return; |
|---|
| 5475 | if (!(fp = fopen ("/tmp/.wanuptime", "r"))) |
|---|
| 5476 | { |
|---|
| 5477 | websWrite (wp, "%s", live_translate ("status_router.notavail")); |
|---|
| 5478 | return; |
|---|
| 5479 | } |
|---|
| 5480 | if (fscanf (fp, "%f", &uptime) == 1) |
|---|
| 5481 | { |
|---|
| 5482 | fp2 = fopen ("/proc/uptime", "r"); |
|---|
| 5483 | fscanf (fp2, "%f", &sys_uptime); |
|---|
| 5484 | fclose (fp2); |
|---|
| 5485 | uptime = sys_uptime - uptime; |
|---|
| 5486 | days = (int) uptime / (60 * 60 * 24); |
|---|
| 5487 | if (days) |
|---|
| 5488 | websWrite (wp, "%d day%s, ", days, (days == 1 ? "" : "s")); |
|---|
| 5489 | minutes = (int) uptime / 60; |
|---|
| 5490 | websWrite (wp, "%d:%02d:%02d", (minutes / 60) % 24, minutes % 60, |
|---|
| 5491 | (int) uptime % 60); |
|---|
| 5492 | } |
|---|
| 5493 | fclose (fp); |
|---|
| 5494 | |
|---|
| 5495 | return; |
|---|
| 5496 | |
|---|
| 5497 | } |
|---|
| 5498 | |
|---|
| 5499 | #ifndef HAVE_MADWIFI |
|---|
| 5500 | |
|---|
| 5501 | void |
|---|
| 5502 | ej_get_curchannel (webs_t wp, int argc, char_t ** argv) |
|---|
| 5503 | { |
|---|
| 5504 | channel_info_t ci; |
|---|
| 5505 | |
|---|
| 5506 | ci.target_channel = 0; |
|---|
| 5507 | wl_ioctl (get_wdev (), WLC_GET_CHANNEL, &ci, sizeof (ci)); |
|---|
| 5508 | if (ci.target_channel > 0) |
|---|
| 5509 | { |
|---|
| 5510 | websWrite (wp, "%d", ci.target_channel); |
|---|
| 5511 | } |
|---|
| 5512 | else |
|---|
| 5513 | //websWrite (wp, "unknown"); |
|---|
| 5514 | websWrite (wp, "%s", live_translate ("share.unknown")); |
|---|
| 5515 | return; |
|---|
| 5516 | |
|---|
| 5517 | } |
|---|
| 5518 | |
|---|
| 5519 | #else |
|---|
| 5520 | |
|---|
| 5521 | void |
|---|
| 5522 | ej_get_curchannel (webs_t wp, int argc, char_t ** argv) |
|---|
| 5523 | { |
|---|
| 5524 | char *dev = NULL; |
|---|
| 5525 | |
|---|
| 5526 | int channel = wifi_getchannel (nvram_safe_get ("wifi_display")); |
|---|
| 5527 | if (channel > 0 && channel < 1000) |
|---|
| 5528 | { |
|---|
| 5529 | websWrite (wp, "%d", channel); |
|---|
| 5530 | } |
|---|
| 5531 | else |
|---|
| 5532 | //websWrite (wp, "unknown"); |
|---|
| 5533 | websWrite (wp, "%s", live_translate ("share.unknown")); |
|---|
| 5534 | return; |
|---|
| 5535 | |
|---|
| 5536 | } |
|---|
| 5537 | #endif |
|---|
| 5538 | #ifdef HAVE_MADWIFI |
|---|
| 5539 | #include <sys/types.h> |
|---|
| 5540 | #include <sys/file.h> |
|---|
| 5541 | #include <sys/ioctl.h> |
|---|
| 5542 | #include <sys/socket.h> |
|---|
| 5543 | #include <stdio.h> |
|---|
| 5544 | #include <stdlib.h> |
|---|
| 5545 | #include <string.h> |
|---|
| 5546 | #include <stdint.h> |
|---|
| 5547 | #include <ctype.h> |
|---|
| 5548 | #include <getopt.h> |
|---|
| 5549 | #include <err.h> |
|---|
| 5550 | |
|---|
| 5551 | |
|---|
| 5552 | #include "wireless_copy.h" |
|---|
| 5553 | #include "net80211/ieee80211.h" |
|---|
| 5554 | #include "net80211/ieee80211_crypto.h" |
|---|
| 5555 | #include "net80211/ieee80211_ioctl.h" |
|---|
| 5556 | static const char * |
|---|
| 5557 | ieee80211_ntoa (const uint8_t mac[IEEE80211_ADDR_LEN]) |
|---|
| 5558 | { |
|---|
| 5559 | static char a[18]; |
|---|
| 5560 | int i; |
|---|
| 5561 | |
|---|
| 5562 | i = snprintf (a, sizeof (a), "%02x:%02x:%02x:%02x:%02x:%02x", |
|---|
| 5563 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
|---|
| 5564 | return (i < 17 ? NULL : a); |
|---|
| 5565 | } |
|---|
| 5566 | |
|---|
| 5567 | static u_int |
|---|
| 5568 | rssi2dbm (u_int rssi) |
|---|
| 5569 | { |
|---|
| 5570 | return rssi - 95; |
|---|
| 5571 | } |
|---|
| 5572 | |
|---|
| 5573 | int |
|---|
| 5574 | ej_active_wireless_if (webs_t wp, int argc, char_t ** argv, |
|---|
| 5575 | char *ifname, int cnt, int turbo) |
|---|
| 5576 | { |
|---|
| 5577 | // unsigned char buf[24 * 1024]; |
|---|
| 5578 | |
|---|
| 5579 | unsigned char *cp; |
|---|
| 5580 | int s, len; |
|---|
| 5581 | struct iwreq iwr; |
|---|
| 5582 | if (!ifexists (ifname)) |
|---|
| 5583 | return cnt; |
|---|
| 5584 | s = socket (AF_INET, SOCK_DGRAM, 0); |
|---|
| 5585 | if (s < 0) |
|---|
| 5586 | { |
|---|
| 5587 | fprintf (stderr, "socket(SOCK_DRAGM)\n"); |
|---|
| 5588 | return cnt; |
|---|
| 5589 | } |
|---|
| 5590 | (void) memset (&iwr, 0, sizeof (struct iwreq)); |
|---|
| 5591 | (void) strncpy (iwr.ifr_name, ifname, sizeof (iwr.ifr_name)); |
|---|
| 5592 | unsigned char *buf = (unsigned char *) malloc (24 * 1024); |
|---|
| 5593 | iwr.u.data.pointer = (void *) buf; |
|---|
| 5594 | iwr.u.data.length = 24 * 1024; |
|---|
| 5595 | if (ioctl (s, IEEE80211_IOCTL_STA_INFO, &iwr) < 0) |
|---|
| 5596 | { |
|---|
| 5597 | close (s); |
|---|
| 5598 | free (buf); |
|---|
| 5599 | return cnt; |
|---|
| 5600 | } |
|---|
| 5601 | len = iwr.u.data.length; |
|---|
| 5602 | if (len < sizeof (struct ieee80211req_sta_info)) |
|---|
| 5603 | { |
|---|
| 5604 | close (s); |
|---|
| 5605 | free (buf); |
|---|
| 5606 | return cnt; |
|---|
| 5607 | } |
|---|
| 5608 | cp = buf; |
|---|
| 5609 | do |
|---|
| 5610 | { |
|---|
| 5611 | struct ieee80211req_sta_info *si; |
|---|
| 5612 | uint8_t *vp; |
|---|
| 5613 | |
|---|
| 5614 | si = (struct ieee80211req_sta_info *) cp; |
|---|
| 5615 | vp = (u_int8_t *) (si + 1); |
|---|
| 5616 | |
|---|
| 5617 | if (cnt) |
|---|
| 5618 | websWrite (wp, ","); |
|---|
| 5619 | cnt++; |
|---|
| 5620 | char mac[32]; |
|---|
| 5621 | strcpy (mac, ieee80211_ntoa (si->isi_macaddr)); |
|---|
| 5622 | if (nvram_match ("maskmac", "1")) |
|---|
| 5623 | { |
|---|
| 5624 | mac[0] = 'x'; |
|---|
| 5625 | mac[1] = 'x'; |
|---|
| 5626 | mac[3] = 'x'; |
|---|
| 5627 | mac[4] = 'x'; |
|---|
| 5628 | mac[6] = 'x'; |
|---|
| 5629 | mac[7] = 'x'; |
|---|
| 5630 | mac[9] = 'x'; |
|---|
| 5631 | mac[10] = 'x'; |
|---|
| 5632 | } |
|---|
| 5633 | if (si->isi_rates) |
|---|
| 5634 | { |
|---|
| 5635 | websWrite (wp, "'%s','%s','%3dM','%d','%d','%d'", |
|---|
| 5636 | mac, ifname, |
|---|
| 5637 | ((si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL) / |
|---|
| 5638 | //2) * turbo, -95 + si->isi_rssi,-95, |
|---|
| 5639 | 2) * turbo, si->isi_noise + si->isi_rssi, si->isi_noise, |
|---|
| 5640 | si->isi_rssi); |
|---|
| 5641 | } |
|---|
| 5642 | else |
|---|
| 5643 | { |
|---|
| 5644 | websWrite (wp, "'%s','%s','N/A','%d','%d','%d'", mac, ifname, |
|---|
| 5645 | //-95 + si->isi_rssi, -95, |
|---|
| 5646 | si->isi_noise + si->isi_rssi, si->isi_noise, |
|---|
| 5647 | si->isi_rssi); |
|---|
| 5648 | } |
|---|
| 5649 | cp += si->isi_len; |
|---|
| 5650 | len -= si->isi_len; |
|---|
| 5651 | } |
|---|
| 5652 | while (len >= sizeof (struct ieee80211req_sta_info)); |
|---|
| 5653 | free (buf); |
|---|
| 5654 | close (s); |
|---|
| 5655 | |
|---|
| 5656 | return cnt; |
|---|
| 5657 | } |
|---|
| 5658 | extern char *getiflist (void); |
|---|
| 5659 | |
|---|
| 5660 | |
|---|
| 5661 | void |
|---|
| 5662 | ej_active_wireless (webs_t wp, int argc, char_t ** argv) |
|---|
| 5663 | { |
|---|
| 5664 | int c = getdevicecount (); |
|---|
| 5665 | char devs[32]; |
|---|
| 5666 | int i; |
|---|
| 5667 | int cnt = 0; |
|---|
| 5668 | char turbo[32]; |
|---|
| 5669 | int t; |
|---|
| 5670 | for (i = 0; i < c; i++) |
|---|
| 5671 | { |
|---|
| 5672 | //fprintf(stderr,"try to assign new ifname for %d\n",i); |
|---|
| 5673 | sprintf (devs, "ath%d", i); |
|---|
| 5674 | //fprintf(stderr,"show ifname %s\n",devs); |
|---|
| 5675 | sprintf (turbo, "%s_turbo", devs); |
|---|
| 5676 | if (nvram_match (turbo, "1")) |
|---|
| 5677 | t = 2; |
|---|
| 5678 | else |
|---|
| 5679 | t = 1; |
|---|
| 5680 | cnt = ej_active_wireless_if (wp, argc, argv, devs, cnt, t); |
|---|
| 5681 | // fprintf(stderr,"returned with %d\n",cnt); |
|---|
| 5682 | char vif[32]; |
|---|
| 5683 | sprintf (vif, "%s_vifs", devs); |
|---|
| 5684 | char var[80], *next; |
|---|
| 5685 | char *vifs = nvram_get (vif); |
|---|
| 5686 | // fprintf(stderr,"wifs are %s\n",vifs); |
|---|
| 5687 | if (vifs != NULL) |
|---|
| 5688 | foreach (var, vifs, next) |
|---|
| 5689 | { |
|---|
| 5690 | // fprintf(stderr,"show ifname %s\n",var); |
|---|
| 5691 | cnt = ej_active_wireless_if (wp, argc, argv, var, cnt, t); |
|---|
| 5692 | // fprintf(stderr,"returned with %d, c=%d, i=%d\n",cnt,i,c); |
|---|
| 5693 | } |
|---|
| 5694 | } |
|---|
| 5695 | |
|---|
| 5696 | //fprintf(stderr,"show wds links\n"); |
|---|
| 5697 | //show wds links |
|---|
| 5698 | for (i = 0; i < c; i++) |
|---|
| 5699 | { |
|---|
| 5700 | |
|---|
| 5701 | int s; |
|---|
| 5702 | for (s = 1; s <= 10; s++) |
|---|
| 5703 | { |
|---|
| 5704 | char wdsvarname[32] = { 0 }; |
|---|
| 5705 | char wdsdevname[32] = { 0 }; |
|---|
| 5706 | char wdsmacname[32] = { 0 }; |
|---|
| 5707 | char *dev; |
|---|
| 5708 | char *hwaddr; |
|---|
| 5709 | char var[80]; |
|---|
| 5710 | //fprintf(stderr,"assign var\n"); |
|---|
| 5711 | sprintf (wdsvarname, "ath%d_wds%d_enable", i, s); |
|---|
| 5712 | //fprintf(stderr,"assign dev\n"); |
|---|
| 5713 | sprintf (wdsdevname, "ath%d_wds%d_if", i, s); |
|---|
| 5714 | //fprintf(stderr,"assign mac\n"); |
|---|
| 5715 | sprintf (wdsmacname, "ath%d_wds%d_hwaddr", i, s); |
|---|
| 5716 | //fprintf(stderr,"get nv\n"); |
|---|
| 5717 | sprintf (turbo, "ath%d_turbo", i); |
|---|
| 5718 | if (nvram_match (turbo, "1")) |
|---|
| 5719 | t = 2; |
|---|
| 5720 | else |
|---|
| 5721 | t = 1; |
|---|
| 5722 | |
|---|
| 5723 | dev = nvram_safe_get (wdsdevname); |
|---|
| 5724 | //fprintf(stderr,"devname %s\n",dev); |
|---|
| 5725 | if (dev == NULL || strlen (dev) == 0) |
|---|
| 5726 | continue; |
|---|
| 5727 | if (nvram_match (wdsvarname, "0")) |
|---|
| 5728 | continue; |
|---|
| 5729 | sprintf (var, "wdsath%d.%d", i, s); |
|---|
| 5730 | //fprintf(stderr,"var %s\n",var); |
|---|
| 5731 | cnt = ej_active_wireless_if (wp, argc, argv, var, cnt, t); |
|---|
| 5732 | } |
|---|
| 5733 | } |
|---|
| 5734 | } |
|---|
| 5735 | |
|---|
| 5736 | #else |
|---|
| 5737 | #define RSSI_TMP "/tmp/.rssi" |
|---|
| 5738 | #define ASSOCLIST_CMD "wl assoclist" |
|---|
| 5739 | #define RSSI_CMD "wl rssi" |
|---|
| 5740 | #define NOISE_CMD "wl noise" |
|---|
| 5741 | |
|---|
| 5742 | |
|---|
| 5743 | #ifndef HAVE_MSSID |
|---|
| 5744 | void |
|---|
| 5745 | ej_active_wireless (webs_t wp, int argc, char_t ** argv) |
|---|
| 5746 | { |
|---|
| 5747 | int rssi = 0, noise = 0; |
|---|
| 5748 | FILE *fp2; |
|---|
| 5749 | char *mode; |
|---|
| 5750 | char mac[30]; |
|---|
| 5751 | char list[2][30]; |
|---|
| 5752 | char line[80]; |
|---|
| 5753 | char cmd[80]; |
|---|
| 5754 | int macmask; |
|---|
| 5755 | if (ejArgs (argc, argv, "%d", &macmask) < 1) |
|---|
| 5756 | { |
|---|
| 5757 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5758 | return; |
|---|
| 5759 | } |
|---|
| 5760 | |
|---|
| 5761 | unlink (RSSI_TMP); |
|---|
| 5762 | int cnt = 0; |
|---|
| 5763 | mode = nvram_safe_get ("wl_mode"); |
|---|
| 5764 | unsigned char buf[WLC_IOCTL_MAXLEN]; |
|---|
| 5765 | memset (buf, 0, WLC_IOCTL_MAXLEN); |
|---|
| 5766 | char *iface = get_wdev (); |
|---|
| 5767 | int r = getassoclist (iface, buf); |
|---|
| 5768 | if (r < 0) |
|---|
| 5769 | return; |
|---|
| 5770 | struct maclist *maclist = (struct maclist *) buf; |
|---|
| 5771 | int i; |
|---|
| 5772 | for (i = 0; i < maclist->count; i++) |
|---|
| 5773 | { |
|---|
| 5774 | ether_etoa ((uint8 *) & maclist->ea[i], mac); |
|---|
| 5775 | |
|---|
| 5776 | rssi = 0; |
|---|
| 5777 | noise = 0; |
|---|
| 5778 | // get rssi value |
|---|
| 5779 | if (strcmp (mode, "ap") && strcmp (mode, "apsta") |
|---|
| 5780 | && strcmp (mode, "apstawet")) |
|---|
| 5781 | snprintf (cmd, sizeof (cmd), "%s > %s", RSSI_CMD, RSSI_TMP); |
|---|
| 5782 | else |
|---|
| 5783 | snprintf (cmd, sizeof (cmd), "%s \"%s\" > %s", RSSI_CMD, mac, |
|---|
| 5784 | RSSI_TMP); |
|---|
| 5785 | system2 (cmd); |
|---|
| 5786 | |
|---|
| 5787 | // get noise value if not ap mode |
|---|
| 5788 | if (strcmp (mode, "ap")) |
|---|
| 5789 | snprintf (cmd, sizeof (cmd), "%s >> %s", NOISE_CMD, RSSI_TMP); |
|---|
| 5790 | system2 (cmd); // get RSSI value for mac |
|---|
| 5791 | |
|---|
| 5792 | fp2 = fopen (RSSI_TMP, "r"); |
|---|
| 5793 | if (fgets (line, sizeof (line), fp2) != NULL) |
|---|
| 5794 | { |
|---|
| 5795 | |
|---|
| 5796 | // get rssi |
|---|
| 5797 | //#ifdef HAVE_MSSID |
|---|
| 5798 | if (sscanf (line, "%d", &rssi) != 1) |
|---|
| 5799 | continue; |
|---|
| 5800 | |
|---|
| 5801 | // noise=getNoise(iface); |
|---|
| 5802 | |
|---|
| 5803 | if (strcmp (mode, "ap") && |
|---|
| 5804 | fgets (line, sizeof (line), fp2) != NULL && |
|---|
| 5805 | sscanf (line, "%d", &noise) != 1) |
|---|
| 5806 | continue; |
|---|
| 5807 | /*#else |
|---|
| 5808 | if (sscanf (line, "%s %s %d", list[0], list[1], &rssi) != 3) |
|---|
| 5809 | continue; |
|---|
| 5810 | // noise=getNoise(iface); |
|---|
| 5811 | if (strcmp (mode, "ap") && |
|---|
| 5812 | fgets (line, sizeof (line), fp2) != NULL && |
|---|
| 5813 | sscanf (line, "%s %s %d", list[0], list[1], &noise) != 3) |
|---|
| 5814 | continue; |
|---|
| 5815 | #endif*/ |
|---|
| 5816 | // get noise for client/wet mode |
|---|
| 5817 | |
|---|
| 5818 | fclose (fp2); |
|---|
| 5819 | } |
|---|
| 5820 | if (nvram_match ("maskmac", "1") && macmask) |
|---|
| 5821 | { |
|---|
| 5822 | mac[0] = 'x'; |
|---|
| 5823 | mac[1] = 'x'; |
|---|
| 5824 | mac[3] = 'x'; |
|---|
| 5825 | mac[4] = 'x'; |
|---|
| 5826 | mac[6] = 'x'; |
|---|
| 5827 | mac[7] = 'x'; |
|---|
| 5828 | mac[9] = 'x'; |
|---|
| 5829 | mac[10] = 'x'; |
|---|
| 5830 | } |
|---|
| 5831 | if (cnt) |
|---|
| 5832 | websWrite (wp, ","); |
|---|
| 5833 | cnt++; |
|---|
| 5834 | if (!strcmp (mode, "ap")) |
|---|
| 5835 | { |
|---|
| 5836 | // char *ref = nvram_get ("noise_reference"); |
|---|
| 5837 | noise = -98; |
|---|
| 5838 | //if (ref) |
|---|
| 5839 | //noise = atoi (ref); |
|---|
| 5840 | } |
|---|
| 5841 | websWrite (wp, "'%s','%d','%d','%d'", mac, rssi, noise, rssi - noise); |
|---|
| 5842 | } |
|---|
| 5843 | unlink (RSSI_TMP); |
|---|
| 5844 | |
|---|
| 5845 | return; |
|---|
| 5846 | } |
|---|
| 5847 | #else |
|---|
| 5848 | int |
|---|
| 5849 | ej_active_wireless_if (webs_t wp, int argc, char_t ** argv, |
|---|
| 5850 | char *iface, char *visible, int cnt) |
|---|
| 5851 | { |
|---|
| 5852 | int rssi = 0, noise = 0; |
|---|
| 5853 | FILE *fp2; |
|---|
| 5854 | char *mode; |
|---|
| 5855 | char mac[30]; |
|---|
| 5856 | char list[2][30]; |
|---|
| 5857 | char line[80]; |
|---|
| 5858 | char cmd[80]; |
|---|
| 5859 | int macmask; |
|---|
| 5860 | if (ejArgs (argc, argv, "%d", &macmask) < 1) |
|---|
| 5861 | { |
|---|
| 5862 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5863 | return 0; |
|---|
| 5864 | } |
|---|
| 5865 | |
|---|
| 5866 | unlink (RSSI_TMP); |
|---|
| 5867 | char wlmode[32]; |
|---|
| 5868 | sprintf (wlmode, "%s_mode", visible); |
|---|
| 5869 | mode = nvram_safe_get (wlmode); |
|---|
| 5870 | unsigned char buf[WLC_IOCTL_MAXLEN]; |
|---|
| 5871 | memset (buf, 0, WLC_IOCTL_MAXLEN); //get_wdev |
|---|
| 5872 | int r = getassoclist (iface, buf); |
|---|
| 5873 | if (r < 0) |
|---|
| 5874 | return cnt; |
|---|
| 5875 | struct maclist *maclist = (struct maclist *) buf; |
|---|
| 5876 | int i; |
|---|
| 5877 | for (i = 0; i < maclist->count; i++) |
|---|
| 5878 | { |
|---|
| 5879 | ether_etoa ((uint8 *) & maclist->ea[i], mac); |
|---|
| 5880 | |
|---|
| 5881 | rssi = 0; |
|---|
| 5882 | noise = 0; |
|---|
| 5883 | // get rssi value |
|---|
| 5884 | if (strcmp (mode, "ap") && strcmp (mode, "apsta") |
|---|
| 5885 | && strcmp (mode, "apstawet")) |
|---|
| 5886 | snprintf (cmd, sizeof (cmd), "wl -i %s rssi > %s", iface, RSSI_TMP); |
|---|
| 5887 | else |
|---|
| 5888 | snprintf (cmd, sizeof (cmd), "wl -i %s rssi \"%s\" > %s", iface, mac, |
|---|
| 5889 | RSSI_TMP); |
|---|
| 5890 | system2 (cmd); |
|---|
| 5891 | |
|---|
| 5892 | // get noise value if not ap mode |
|---|
| 5893 | // if (strcmp (mode, "ap")) |
|---|
| 5894 | // snprintf (cmd, sizeof (cmd), "wl -i %s noise >> %s", iface, RSSI_TMP); |
|---|
| 5895 | // system2 (cmd); // get RSSI value for mac |
|---|
| 5896 | |
|---|
| 5897 | fp2 = fopen (RSSI_TMP, "r"); |
|---|
| 5898 | if (fgets (line, sizeof (line), fp2) != NULL) |
|---|
| 5899 | { |
|---|
| 5900 | |
|---|
| 5901 | // get rssi |
|---|
| 5902 | if (sscanf (line, "%d", &rssi) != 1) |
|---|
| 5903 | continue; |
|---|
| 5904 | noise = getNoise (iface, NULL); |
|---|
| 5905 | /* if (strcmp (mode, "ap") && |
|---|
| 5906 | fgets (line, sizeof (line), fp2) != NULL && |
|---|
| 5907 | sscanf (line, "%d", &noise) != 1) |
|---|
| 5908 | continue;*/ |
|---|
| 5909 | // get noise for client/wet mode |
|---|
| 5910 | |
|---|
| 5911 | fclose (fp2); |
|---|
| 5912 | } |
|---|
| 5913 | if (nvram_match ("maskmac", "1") && macmask) |
|---|
| 5914 | { |
|---|
| 5915 | mac[0] = 'x'; |
|---|
| 5916 | mac[1] = 'x'; |
|---|
| 5917 | mac[3] = 'x'; |
|---|
| 5918 | mac[4] = 'x'; |
|---|
| 5919 | mac[6] = 'x'; |
|---|
| 5920 | mac[7] = 'x'; |
|---|
| 5921 | mac[9] = 'x'; |
|---|
| 5922 | mac[10] = 'x'; |
|---|
| 5923 | } |
|---|
| 5924 | if (cnt) |
|---|
| 5925 | websWrite (wp, ","); |
|---|
| 5926 | cnt++; |
|---|
| 5927 | /* if (!strcmp (mode, "ap")) |
|---|
| 5928 | { |
|---|
| 5929 | noise = getNoise(iface,NULL); // null only for broadcom |
|---|
| 5930 | }*/ |
|---|
| 5931 | websWrite (wp, "'%s','%s','N/A','%d','%d','%d'", mac, iface, rssi, |
|---|
| 5932 | noise, rssi - noise); |
|---|
| 5933 | } |
|---|
| 5934 | unlink (RSSI_TMP); |
|---|
| 5935 | |
|---|
| 5936 | return cnt; |
|---|
| 5937 | } |
|---|
| 5938 | |
|---|
| 5939 | void |
|---|
| 5940 | ej_active_wireless (webs_t wp, int argc, char_t ** argv) |
|---|
| 5941 | { |
|---|
| 5942 | int cnt = 0; |
|---|
| 5943 | cnt = ej_active_wireless_if (wp, argc, argv, get_wdev (), "wl0", cnt); |
|---|
| 5944 | char *next; |
|---|
| 5945 | char var[80]; |
|---|
| 5946 | char *vifs = nvram_safe_get ("wl0_vifs"); |
|---|
| 5947 | if (vifs == NULL) |
|---|
| 5948 | return; |
|---|
| 5949 | |
|---|
| 5950 | foreach (var, vifs, next) |
|---|
| 5951 | { |
|---|
| 5952 | cnt = ej_active_wireless_if (wp, argc, argv, var, var, cnt); |
|---|
| 5953 | } |
|---|
| 5954 | } |
|---|
| 5955 | |
|---|
| 5956 | |
|---|
| 5957 | #endif |
|---|
| 5958 | |
|---|
| 5959 | |
|---|
| 5960 | #endif |
|---|
| 5961 | |
|---|
| 5962 | #define WDS_RSSI_TMP "/tmp/.rssi" |
|---|
| 5963 | #define WDS_CMD "wl wds" |
|---|
| 5964 | |
|---|
| 5965 | void |
|---|
| 5966 | ej_active_wds (webs_t wp, int argc, char_t ** argv) |
|---|
| 5967 | { |
|---|
| 5968 | #ifndef HAVE_MADWIFI |
|---|
| 5969 | int rssi = 0, i; |
|---|
| 5970 | FILE *fp2; |
|---|
| 5971 | char *mode; |
|---|
| 5972 | char mac[30]; |
|---|
| 5973 | char list[2][30]; |
|---|
| 5974 | char line[80]; |
|---|
| 5975 | char cmd[80]; |
|---|
| 5976 | // char title[30]; |
|---|
| 5977 | char wdsvar[30]; |
|---|
| 5978 | char desc[30]; |
|---|
| 5979 | int cnt = 0; |
|---|
| 5980 | int macmask; |
|---|
| 5981 | if (ejArgs (argc, argv, "%d", &macmask) < 1) |
|---|
| 5982 | { |
|---|
| 5983 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 5984 | return; |
|---|
| 5985 | } |
|---|
| 5986 | |
|---|
| 5987 | unlink (WDS_RSSI_TMP); |
|---|
| 5988 | |
|---|
| 5989 | mode = nvram_safe_get ("wl_mode"); |
|---|
| 5990 | |
|---|
| 5991 | if (strcmp (mode, "ap") && strcmp (mode, "apsta") |
|---|
| 5992 | && strcmp (mode, "apstawet")) |
|---|
| 5993 | return; |
|---|
| 5994 | unsigned char buf[WLC_IOCTL_MAXLEN]; |
|---|
| 5995 | char *iface = get_wdev (); |
|---|
| 5996 | int r = getwdslist (iface, buf); |
|---|
| 5997 | if (r < 0) |
|---|
| 5998 | return; |
|---|
| 5999 | struct maclist *maclist = (struct maclist *) buf; |
|---|
| 6000 | int e; |
|---|
| 6001 | for (e = 0; e < maclist->count; e++) |
|---|
| 6002 | { |
|---|
| 6003 | |
|---|
| 6004 | ether_etoa ((uint8 *) & maclist->ea[e], mac); |
|---|
| 6005 | |
|---|
| 6006 | |
|---|
| 6007 | rssi = 0; |
|---|
| 6008 | memset (desc, 0, 30); |
|---|
| 6009 | for (i = 1; i <= 10; i++) |
|---|
| 6010 | { |
|---|
| 6011 | snprintf (wdsvar, 30, "wl_wds%d_hwaddr", i); |
|---|
| 6012 | if (nvram_match (wdsvar, mac)) |
|---|
| 6013 | { |
|---|
| 6014 | snprintf (wdsvar, 30, "wl_wds%d_desc", i); |
|---|
| 6015 | snprintf (desc, sizeof (desc), "%s", nvram_get (wdsvar)); |
|---|
| 6016 | if (!strcmp (nvram_get (wdsvar), "")) |
|---|
| 6017 | strcpy (desc, " "); |
|---|
| 6018 | } |
|---|
| 6019 | } |
|---|
| 6020 | |
|---|
| 6021 | snprintf (cmd, sizeof (cmd), "%s \"%s\" > %s", RSSI_CMD, mac, RSSI_TMP); |
|---|
| 6022 | system2 (cmd); |
|---|
| 6023 | |
|---|
| 6024 | fp2 = fopen (RSSI_TMP, "r"); |
|---|
| 6025 | if (fgets (line, sizeof (line), fp2) != NULL) |
|---|
| 6026 | { |
|---|
| 6027 | |
|---|
| 6028 | // get rssi |
|---|
| 6029 | if (sscanf (line, "%d", &rssi) != 1) |
|---|
| 6030 | continue; |
|---|
| 6031 | fclose (fp2); |
|---|
| 6032 | } |
|---|
| 6033 | if (nvram_match ("maskmac", "1") && macmask) |
|---|
| 6034 | { |
|---|
| 6035 | mac[0] = 'x'; |
|---|
| 6036 | mac[1] = 'x'; |
|---|
| 6037 | mac[3] = 'x'; |
|---|
| 6038 | mac[4] = 'x'; |
|---|
| 6039 | mac[6] = 'x'; |
|---|
| 6040 | mac[7] = 'x'; |
|---|
| 6041 | mac[9] = 'x'; |
|---|
| 6042 | mac[10] = 'x'; |
|---|
| 6043 | } |
|---|
| 6044 | if (cnt) |
|---|
| 6045 | websWrite (wp, ","); |
|---|
| 6046 | cnt++; |
|---|
| 6047 | int noise = getNoise (iface, NULL); |
|---|
| 6048 | websWrite (wp, |
|---|
| 6049 | "\"%s\",\"%s\",\"%d\",\"%d\",\"%d\"", |
|---|
| 6050 | mac, desc, rssi, noise, rssi - noise); |
|---|
| 6051 | } |
|---|
| 6052 | |
|---|
| 6053 | unlink (WDS_RSSI_TMP); |
|---|
| 6054 | #endif |
|---|
| 6055 | return; |
|---|
| 6056 | } |
|---|
| 6057 | |
|---|
| 6058 | |
|---|
| 6059 | void |
|---|
| 6060 | ej_get_wdsp2p (webs_t wp, int argc, char_t ** argv) |
|---|
| 6061 | { |
|---|
| 6062 | int index = -1, ip[4] = { 0, 0, 0, 0 }, netmask[4] = |
|---|
| 6063 | { |
|---|
| 6064 | 0, 0, 0, 0}; |
|---|
| 6065 | char nvramvar[32] = { 0 }; |
|---|
| 6066 | #ifdef HAVE_MADWIFI |
|---|
| 6067 | char *interface; |
|---|
| 6068 | if (ejArgs (argc, argv, "%d %s", &index, &interface) < 2) |
|---|
| 6069 | { |
|---|
| 6070 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 6071 | return; |
|---|
| 6072 | } |
|---|
| 6073 | #else |
|---|
| 6074 | char *interface = "wl"; |
|---|
| 6075 | if (ejArgs (argc, argv, "%d", &index) < 1) |
|---|
| 6076 | { |
|---|
| 6077 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 6078 | return; |
|---|
| 6079 | } |
|---|
| 6080 | #endif |
|---|
| 6081 | char wlwds[32]; |
|---|
| 6082 | sprintf (wlwds, "%s_wds1_enable", interface); |
|---|
| 6083 | if (nvram_selmatch (wp, "wk_mode", "ospf") && |
|---|
| 6084 | nvram_selmatch (wp, "expert_mode", "1") && |
|---|
| 6085 | nvram_selmatch (wp, wlwds, "1")) |
|---|
| 6086 | { |
|---|
| 6087 | char buf[16]; |
|---|
| 6088 | sprintf (buf, "%s_wds%d_ospf", interface, index); |
|---|
| 6089 | websWrite (wp, |
|---|
| 6090 | "<input name=\"%s\" size=\"2\" maxlength=\"5\" value=\"%s\" />\n", |
|---|
| 6091 | buf, nvram_safe_get (buf)); |
|---|
| 6092 | } |
|---|
| 6093 | |
|---|
| 6094 | snprintf (nvramvar, 31, "%s_wds%d_ipaddr", interface, index); |
|---|
| 6095 | sscanf (nvram_safe_get (nvramvar), "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], |
|---|
| 6096 | &ip[3]); |
|---|
| 6097 | snprintf (nvramvar, 31, "%s_wds%d_netmask", interface, index); |
|---|
| 6098 | sscanf (nvram_safe_get (nvramvar), "%d.%d.%d.%d", &netmask[0], &netmask[1], |
|---|
| 6099 | &netmask[2], &netmask[3]); |
|---|
| 6100 | snprintf (nvramvar, 31, "%s_wds%d_enable", interface, index); |
|---|
| 6101 | |
|---|
| 6102 | // set netmask to a suggested default if blank |
|---|
| 6103 | if (netmask[0] == 0 && |
|---|
| 6104 | netmask[1] == 0 && netmask[2] == 0 && netmask[3] == 0) |
|---|
| 6105 | { |
|---|
| 6106 | netmask[0] = 255; |
|---|
| 6107 | netmask[1] = 255; |
|---|
| 6108 | netmask[2] = 255; |
|---|
| 6109 | netmask[3] = 252; |
|---|
| 6110 | } |
|---|
| 6111 | |
|---|
| 6112 | if (nvram_match (nvramvar, "1")) |
|---|
| 6113 | { |
|---|
| 6114 | websWrite (wp, "\ |
|---|
| 6115 | <div class=\"setting\">\n\ |
|---|
| 6116 | <input type=\"hidden\" name=\"wl_wds%d_ipaddr\" value=\"4\">\n\ |
|---|
| 6117 | <div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n\ |
|---|
| 6118 | <input size=\"3\" maxlength=\"3\" name=\"wl_wds%d_ipaddr0\" value=\"%d\" onblur=\"valid_range(this,0,255,'IP')\" class=\"num\">.<input size=\"3\" maxlength=\"3\" name=\"wl_wds%d_ipaddr1\" value=\"%d\" onblur=\"valid_range(this,0,255,'IP')\" class=\"num\">.<input size=\"3\" maxlength=\"3\" name=\"wl_wds%d_ipaddr2\" value=\"%d\" onblur=\"valid_range(this,0,255,'IP')\" class=\"num\">.<input size=\"3\" maxlength=\"3\" name=\"wl_wds%d_ipaddr3\" value=\"%d\" onblur=\"valid_range(this,1,254,'IP')\" class=\"num\">\n\ |
|---|
| 6119 | </div>\n", index, index, ip[0], index, ip[1], index, ip[2], index, ip[3], index); |
|---|
| 6120 | |
|---|
| 6121 | websWrite (wp, "\ |
|---|
| 6122 | <div class=\"setting\">\n\ |
|---|
| 6123 | <div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n\ |
|---|
| 6124 | <input type=\"hidden\" name=\"wl_wds%d_netmask\" value=\"4\">\n\ |
|---|
| 6125 | <input name=\"wl_wds%d_netmask0\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>.<input name=\"wl_wds%d_netmask1\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>.<input name=\"wl_wds%d_netmask2\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>.<input name=\"wl_wds%d_netmask3\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>\n\ |
|---|
| 6126 | </div>\n", index, index, netmask[0], index, netmask[1], index, netmask[2], index, netmask[3]); |
|---|
| 6127 | |
|---|
| 6128 | /* |
|---|
| 6129 | websWrite (wp, "\ |
|---|
| 6130 | <div class=\"setting\">\n\ |
|---|
| 6131 | <input type=\"hidden\" name=\"%s_wds%d_ipaddr\" value=\"4\">\n\ |
|---|
| 6132 | <div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n\ |
|---|
| 6133 | <input size=\"3\" maxlength=\"3\" name=\"%s_wds%d_ipaddr0\" value=\"%d\" onblur=\"valid_range(this,0,255,'IP')\" class=\"num\">.<input size=\"3\" maxlength=\"3\" name=\"%s_wds%d_ipaddr1\" value=\"%d\" onblur=\"valid_range(this,0,255,'IP')\" class=\"num\">.<input size=\"3\" maxlength=\"3\" name=\"%s_wds%d_ipaddr2\" value=\"%d\" onblur=\"valid_range(this,0,255,'IP')\" class=\"num\">.<input size=\"3\" maxlength=\"3\" name=\"%s_wds%d_ipaddr3\" value=\"%d\" onblur=\"valid_range(this,1,254,'IP')\" class=\"num\">\n\ |
|---|
| 6134 | </div>\n", interface,index, interface,index, ip[0], interface,index, ip[1], interface,index, ip[2], interface,index, ip[3], interface,index); |
|---|
| 6135 | |
|---|
| 6136 | websWrite (wp, "\ |
|---|
| 6137 | <div class=\"setting\">\n\ |
|---|
| 6138 | <div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n\ |
|---|
| 6139 | <input type=\"hidden\" name=\"%s_wds%d_netmask\" value=\"4\">\n\ |
|---|
| 6140 | <input name=\"%s_wds%d_netmask0\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>.<input name=\"%s_wds%d_netmask1\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>.<input name=\"%s_wds%d_netmask2\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>.<input name=\"%s_wds%d_netmask3\" value=\"%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,255,'IP')\" class=num>\n\ |
|---|
| 6141 | </div>\n", interface,index, interface,index, netmask[0], interface,index, netmask[1], interface,index, netmask[2], interface,index, netmask[3]); |
|---|
| 6142 | */ |
|---|
| 6143 | } |
|---|
| 6144 | |
|---|
| 6145 | return; |
|---|
| 6146 | |
|---|
| 6147 | } |
|---|
| 6148 | |
|---|
| 6149 | void |
|---|
| 6150 | save_wds (webs_t wp) |
|---|
| 6151 | { |
|---|
| 6152 | char *wds_enable_val, wds_enable_var[32] = { 0 }; |
|---|
| 6153 | int h = 0; |
|---|
| 6154 | #ifdef HAVE_MADWIFI |
|---|
| 6155 | char *interface = websGetVar (wp, "interface", NULL); |
|---|
| 6156 | #else |
|---|
| 6157 | char *interface = "wl"; |
|---|
| 6158 | #endif |
|---|
| 6159 | for (h = 1; h <= MAX_WDS_DEVS; h++) |
|---|
| 6160 | { |
|---|
| 6161 | sprintf (wds_enable_var, "%s_wds%d_enable", interface, h); |
|---|
| 6162 | wds_enable_val = websGetVar (wp, wds_enable_var, NULL); |
|---|
| 6163 | nvram_set (wds_enable_var, wds_enable_val); |
|---|
| 6164 | } |
|---|
| 6165 | sprintf (wds_enable_var, "%s_br1_enable", interface); |
|---|
| 6166 | |
|---|
| 6167 | wds_enable_val = websGetVar (wp, wds_enable_var, NULL); |
|---|
| 6168 | nvram_set (wds_enable_var, wds_enable_val); |
|---|
| 6169 | |
|---|
| 6170 | return; |
|---|
| 6171 | |
|---|
| 6172 | } |
|---|
| 6173 | |
|---|
| 6174 | |
|---|
| 6175 | void |
|---|
| 6176 | get_filter_services (char *services) |
|---|
| 6177 | { |
|---|
| 6178 | /* |
|---|
| 6179 | typedef struct _l7filters //l7 and p2p filters |
|---|
| 6180 | { |
|---|
| 6181 | char *name; |
|---|
| 6182 | char *protocol; |
|---|
| 6183 | } l7filters; |
|---|
| 6184 | |
|---|
| 6185 | l7filters filters_list[] = { |
|---|
| 6186 | { "100bao", "l7" }, |
|---|
| 6187 | { "aim", "l7"}, |
|---|
| 6188 | { "aimwebcontent" , "l7" }, |
|---|
| 6189 | { "applejuice", "p2p" }, |
|---|
| 6190 | { "ares", "p2p" }, |
|---|
| 6191 | { "audiogalaxy", "l7" }, |
|---|
| 6192 | { "battlefield1942", "l7" }, |
|---|
| 6193 | { "battlefield2", "l7" }, |
|---|
| 6194 | { "bgp", "l7" }, |
|---|
| 6195 | { "biff", "l7" }, |
|---|
| 6196 | { "bittorrent", "p2p" }, |
|---|
| 6197 | { "chikka", "l7" }, |
|---|
| 6198 | { "cimd", "l7" }, |
|---|
| 6199 | { "ciscovpn", "l7" }, |
|---|
| 6200 | { "citrix", "l7" }, |
|---|
| 6201 | { "code_red", "l7" }, |
|---|
| 6202 | { "counterstrike-source", "l7" }, |
|---|
| 6203 | { "cvs", "l7" }, |
|---|
| 6204 | { "dayofdefeat-source", "l7" }, |
|---|
| 6205 | { "dhcp", "l7" }, |
|---|
| 6206 | { "directconnect", "p2p" }, |
|---|
| 6207 | { "dns", "l7" }, |
|---|
| 6208 | { "doom3", "l7" }, |
|---|
| 6209 | { "edonkey", "p2p" }, |
|---|
| 6210 | { "exe", "l7" }, |
|---|
| 6211 | { "fasttrack", "l7" }, |
|---|
| 6212 | { "finger", "l7" }, |
|---|
| 6213 | { "flash", "l7" }, |
|---|
| 6214 | { "freenet", "l7" }, |
|---|
| 6215 | { "ftp", "l7"}, |
|---|
| 6216 | { "gif", "l7" }, |
|---|
| 6217 | { "gkrellm", "l7" }, |
|---|
| 6218 | { "gnucleuslan", "l7" }, |
|---|
| 6219 | { "gnutella", "p2p" }, |
|---|
| 6220 | { "goboogy", "l7" }, |
|---|
| 6221 | { "gopher", "l7" }, |
|---|
| 6222 | { "h323", "l7" }, |
|---|
| 6223 | { "halflife2-deathmatch", "l7" }, |
|---|
| 6224 | { "hddtemp", "l7" }, |
|---|
| 6225 | { "hotline", "l7" }, |
|---|
| 6226 | { "html", "l7" }, |
|---|
| 6227 | { "http", "l7" }, |
|---|
| 6228 | { "http-dap", "l7" }, |
|---|
| 6229 | { "http-fresh", "l7" }, |
|---|
| 6230 | { "http-itunes", "l7" }, |
|---|
| 6231 | { "http-rtsp", "l7" }, |
|---|
| 6232 | { "httpaudio", "l7" }, |
|---|
| 6233 | { "httpcachehit", "l7" }, |
|---|
| 6234 | { "httpcachemiss", "l7" }, |
|---|
| 6235 | { "httpvideo", "l7" }, |
|---|
| 6236 | { "ident", "l7" }, |
|---|
| 6237 | { "imap", "l7" }, |
|---|
| 6238 | { "imesh", "l7" }, |
|---|
| 6239 | { "ipp", "l7" }, |
|---|
| 6240 | { "irc", "l7" }, |
|---|
| 6241 | { "jabber", "l7" }, |
|---|
| 6242 | { "jpeg", "l7" }, |
|---|
| 6243 | { "kugoo", "l7"}, |
|---|
| 6244 | { "live365", "l7" }, |
|---|
| 6245 | { "lpd", "l7" }, |
|---|
| 6246 | { "mohaa", "l7" }, |
|---|
| 6247 | { "msnmessenger", "l7" }, |
|---|
| 6248 | { "msn-filetransfer", "l7" }, |
|---|
| 6249 | { "mute", "l7" }, |
|---|
| 6250 | { "napster", "l7" }, |
|---|
| 6251 | { "nbns", "l7" }, |
|---|
| 6252 | { "ncp", "l7" }, |
|---|
| 6253 | { "netbios", "l7" }, |
|---|
| 6254 | { "nimda", "l7" }, |
|---|
| 6255 | { "nntp", "l7" }, |
|---|
| 6256 | { "ntp", "l7" }, |
|---|
| 6257 | { "ogg", "l7" }, |
|---|
| 6258 | { "openft", "l7" }, |
|---|
| 6259 | { "pcanywhere", "l7" }, |
|---|
| 6260 | { "pdf", "l7" }, |
|---|
| 6261 | { "perl", "l7" }, |
|---|
| 6262 | { "poco", "l7" }, |
|---|
| 6263 | { "pop3", "l7" }, |
|---|
| 6264 | { "postscript", "l7" }, |
|---|
| 6265 | { "pressplay", "l7" }, |
|---|
| 6266 | { "qq", "l7" }, |
|---|
| 6267 | { "quake-halflife", "l7" }, |
|---|
| 6268 | { "quake1", "l7" }, |
|---|
| 6269 | { "quicktime", "l7" }, |
|---|
| 6270 | { "radmin", "l7" }, |
|---|
| 6271 | { "rar", "l7"}, |
|---|
| 6272 | { "rdp", "l7" }, |
|---|
| 6273 | { "replaytv-ivs", "l7" }, |
|---|
| 6274 | { "rlogin", "l7" }, |
|---|
| 6275 | { "rpm", "l7" }, |
|---|
| 6276 | { "rtf", "l7" }, |
|---|
| 6277 | { "rtsp", "l7" }, |
|---|
| 6278 | { "shoutcast", "l7" }, |
|---|
| 6279 | { "sip", "l7" }, |
|---|
| 6280 | { "skypeout", "l7" }, |
|---|
| 6281 | { "skypetoskype", "l7" }, |
|---|
| 6282 | { "smb", "l7" }, |
|---|
| 6283 | { "smtp", "l7" }, |
|---|
| 6284 | { "snmp", "l7" }, |
|---|
| 6285 | { "snmp-mon", "l7" }, |
|---|
| 6286 | { "snmp-trap", "l7" }, |
|---|
| 6287 | { "socks", "l7" }, |
|---|
| 6288 | { "soribada", "l7" }, |
|---|
| 6289 | { "soulseek", "p2p" }, |
|---|
| 6290 | { "ssdp", "l7" }, |
|---|
| 6291 | { "ssh", "l7" }, |
|---|
| 6292 | { "ssl", "l7" }, |
|---|
| 6293 | { "stun", "l7" }, |
|---|
| 6294 | { "subspace", "l7" }, |
|---|
| 6295 | { "subversion", "l7" }, |
|---|
| 6296 | { "tar", "l7" }, |
|---|
| 6297 | { "teamspeak", "l7" }, |
|---|
| 6298 | { "telnet", "l7" }, |
|---|
| 6299 | { "tesla", "l7"}, |
|---|
| 6300 | { "tftp", "l7" }, |
|---|
| 6301 | { "thecircle", "l7" }, |
|---|
| 6302 | { "tls", "l7" }, |
|---|
| 6303 | { "tor" "l7" }, |
|---|
| 6304 | { "tsp", "l7" }, |
|---|
| 6305 | { "unknown", "l7" }, |
|---|
| 6306 | { "uucp", "l7" }, |
|---|
| 6307 | { "validcertssl", "l7" }, |
|---|
| 6308 | { "ventrilo", "l7" }, |
|---|
| 6309 | { "vnc", "l7" }, |
|---|
| 6310 | { "winmx", "p2p" }, |
|---|
| 6311 | { "whois", "l7" }, |
|---|
| 6312 | { "worldofwarcraft", "l7" }, |
|---|
| 6313 | { "x11", "l7" }, |
|---|
| 6314 | { "xboxlive", "l7" }, |
|---|
| 6315 | { "xunlei", "l7" }, |
|---|
| 6316 | { "yahoo", "l7" }, |
|---|
| 6317 | { "zip", "l7" }, |
|---|
| 6318 | { "zmaap", "l7" }, |
|---|
| 6319 | { 0, 0 } |
|---|
| 6320 | }; |
|---|
| 6321 | |
|---|
| 6322 | int i=0; |
|---|
| 6323 | int namelen, protolen; |
|---|
| 6324 | |
|---|
| 6325 | char services[8192] = ""; |
|---|
| 6326 | char temp[128] = ""; |
|---|
| 6327 | |
|---|
| 6328 | while (filters_list[i].name) //add l7 and p2p filters |
|---|
| 6329 | { |
|---|
| 6330 | namelen = strlen (filters_list[i].name); |
|---|
| 6331 | protolen = strlen (filters_list[i].protocol); |
|---|
| 6332 | |
|---|
| 6333 | sprintf (temp, "$NAME:%03d:%s$PROT:%03d:%s$PORT:003:0:0< >", namelen, filters_list[i].name, protolen, filters_list[i].protocol); |
|---|
| 6334 | strcat (services, temp); |
|---|
| 6335 | |
|---|
| 6336 | i++; |
|---|
| 6337 | } |
|---|
| 6338 | */ |
|---|
| 6339 | |
|---|
| 6340 | char svcs_var[32] = ""; |
|---|
| 6341 | int index = 0; |
|---|
| 6342 | |
|---|
| 6343 | do |
|---|
| 6344 | { |
|---|
| 6345 | snprintf (svcs_var, 31, "filter_services%d", index++); |
|---|
| 6346 | strcat (services, nvram_safe_get (svcs_var)); |
|---|
| 6347 | } |
|---|
| 6348 | while (strlen (nvram_safe_get (svcs_var)) > 0 && index < 8); |
|---|
| 6349 | |
|---|
| 6350 | return; |
|---|
| 6351 | } |
|---|
| 6352 | |
|---|
| 6353 | /* |
|---|
| 6354 | void |
|---|
| 6355 | ej_get_services_options (webs_t wp, int argc, char_t ** argv) |
|---|
| 6356 | { |
|---|
| 6357 | char word[1024], *next, *services; |
|---|
| 6358 | char delim[] = "< >"; |
|---|
| 6359 | |
|---|
| 6360 | //services = nvram_safe_get("filter_services"); |
|---|
| 6361 | services = get_filter_services (); |
|---|
| 6362 | |
|---|
| 6363 | split (word, services, next, delim) |
|---|
| 6364 | { |
|---|
| 6365 | int len = 0; |
|---|
| 6366 | char *name, *prot, *port; |
|---|
| 6367 | char protocol[100], ports[100]; |
|---|
| 6368 | int from = 0, to = 0; |
|---|
| 6369 | //int proto; |
|---|
| 6370 | |
|---|
| 6371 | if ((name = strstr (word, "$NAME:")) == NULL || |
|---|
| 6372 | (prot = strstr (word, "$PROT:")) == NULL || |
|---|
| 6373 | (port = strstr (word, "$PORT:")) == NULL) |
|---|
| 6374 | continue; |
|---|
| 6375 | |
|---|
| 6376 | // $NAME |
|---|
| 6377 | if (sscanf (name, "$NAME:%3d:", &len) != 1) |
|---|
| 6378 | continue; |
|---|
| 6379 | |
|---|
| 6380 | strncpy (name, name + sizeof ("$NAME:nnn:") - 1, len); |
|---|
| 6381 | name[len] = '\0'; |
|---|
| 6382 | |
|---|
| 6383 | // $PROT |
|---|
| 6384 | if (sscanf (prot, "$PROT:%3d:", &len) != 1) |
|---|
| 6385 | continue; |
|---|
| 6386 | |
|---|
| 6387 | strncpy (protocol, prot + sizeof ("$PROT:nnn:") - 1, len); |
|---|
| 6388 | protocol[len] = '\0'; |
|---|
| 6389 | |
|---|
| 6390 | // $PORT |
|---|
| 6391 | if (sscanf (port, "$PORT:%3d:", &len) != 1) |
|---|
| 6392 | continue; |
|---|
| 6393 | |
|---|
| 6394 | strncpy (ports, port + sizeof ("$PORT:nnn:") - 1, len); |
|---|
| 6395 | ports[len] = '\0'; |
|---|
| 6396 | |
|---|
| 6397 | if (sscanf (ports, "%d:%d", &from, &to) != 2) |
|---|
| 6398 | continue; |
|---|
| 6399 | |
|---|
| 6400 | //cprintf("match:: name=%s, protocol=%s, ports=%s\n", |
|---|
| 6401 | // word, protocol, ports); |
|---|
| 6402 | |
|---|
| 6403 | websWrite (wp, "<option value=\"%s\">%s</option>", name, name); |
|---|
| 6404 | |
|---|
| 6405 | } |
|---|
| 6406 | |
|---|
| 6407 | return; |
|---|
| 6408 | } |
|---|
| 6409 | */ |
|---|
| 6410 | int |
|---|
| 6411 | get_svc (char *svc, char *protocol, char *ports) |
|---|
| 6412 | { |
|---|
| 6413 | char word[1024], *next; |
|---|
| 6414 | char delim[] = "< >"; |
|---|
| 6415 | char services[8192]; |
|---|
| 6416 | // services = nvram_safe_get("filter_services"); |
|---|
| 6417 | memset (services, 0, 8192); |
|---|
| 6418 | get_filter_services (services); |
|---|
| 6419 | |
|---|
| 6420 | split (word, services, next, delim) |
|---|
| 6421 | { |
|---|
| 6422 | int len = 0; |
|---|
| 6423 | char *name, *prot, *port; |
|---|
| 6424 | int from = 0, to = 0; |
|---|
| 6425 | |
|---|
| 6426 | if ((name = strstr (word, "$NAME:")) == NULL || |
|---|
| 6427 | (prot = strstr (word, "$PROT:")) == NULL || |
|---|
| 6428 | (port = strstr (word, "$PORT:")) == NULL) |
|---|
| 6429 | continue; |
|---|
| 6430 | |
|---|
| 6431 | /* $NAME */ |
|---|
| 6432 | if (sscanf (name, "$NAME:%3d:", &len) != 1) |
|---|
| 6433 | return -1; |
|---|
| 6434 | |
|---|
| 6435 | strncpy (name, name + sizeof ("$NAME:nnn:") - 1, len); |
|---|
| 6436 | name[len] = '\0'; |
|---|
| 6437 | |
|---|
| 6438 | if (strcasecmp (svc, name)) |
|---|
| 6439 | continue; |
|---|
| 6440 | |
|---|
| 6441 | /* $PROT */ |
|---|
| 6442 | if (sscanf (prot, "$PROT:%3d:", &len) != 1) |
|---|
| 6443 | return -1; |
|---|
| 6444 | |
|---|
| 6445 | strncpy (protocol, prot + sizeof ("$PROT:nnn:") - 1, len); |
|---|
| 6446 | protocol[len] = '\0'; |
|---|
| 6447 | |
|---|
| 6448 | /* $PORT */ |
|---|
| 6449 | if (sscanf (port, "$PORT:%3d:", &len) != 1) |
|---|
| 6450 | return -1; |
|---|
| 6451 | |
|---|
| 6452 | strncpy (ports, port + sizeof ("$PORT:nnn:") - 1, len); |
|---|
| 6453 | ports[len] = '\0'; |
|---|
| 6454 | |
|---|
| 6455 | if (sscanf (ports, "%d:%d", &from, &to) != 2) |
|---|
| 6456 | return -1; |
|---|
| 6457 | |
|---|
| 6458 | |
|---|
| 6459 | if (strcasecmp (svc, name) == 0) |
|---|
| 6460 | return 0; |
|---|
| 6461 | } |
|---|
| 6462 | |
|---|
| 6463 | return -1; |
|---|
| 6464 | } |
|---|
| 6465 | |
|---|
| 6466 | void |
|---|
| 6467 | qos_add_svc (webs_t wp) |
|---|
| 6468 | { |
|---|
| 6469 | char *var = websGetVar (wp, "wshaper_enable", NULL); |
|---|
| 6470 | if (var != NULL) |
|---|
| 6471 | nvram_set ("wshaper_enable", var); |
|---|
| 6472 | |
|---|
| 6473 | char protocol[100] = { 0 }, ports[100] = |
|---|
| 6474 | { |
|---|
| 6475 | 0}; |
|---|
| 6476 | char *add_svc = websGetVar (wp, "add_svc", NULL); |
|---|
| 6477 | char *svqos_svcs = nvram_safe_get ("svqos_svcs"); |
|---|
| 6478 | char new_svcs[4096] = { 0 }; |
|---|
| 6479 | int i = 0; |
|---|
| 6480 | |
|---|
| 6481 | memset (new_svcs, 0, sizeof (new_svcs)); |
|---|
| 6482 | |
|---|
| 6483 | if (get_svc (add_svc, protocol, ports)) |
|---|
| 6484 | return; |
|---|
| 6485 | |
|---|
| 6486 | if (strcmp (protocol, "l7") == 0) |
|---|
| 6487 | { |
|---|
| 6488 | int slen = strlen (add_svc); |
|---|
| 6489 | for (i = 0; i < slen; i++) |
|---|
| 6490 | add_svc[i] = tolower (add_svc[i]); |
|---|
| 6491 | } |
|---|
| 6492 | |
|---|
| 6493 | /* if this service exists, return an error */ |
|---|
| 6494 | if (strstr (svqos_svcs, add_svc)) |
|---|
| 6495 | return; |
|---|
| 6496 | |
|---|
| 6497 | if (strlen (svqos_svcs) > 0) |
|---|
| 6498 | snprintf (new_svcs, 4095, "%s %s %s %s 30 |", svqos_svcs, add_svc, |
|---|
| 6499 | protocol, ports); |
|---|
| 6500 | else |
|---|
| 6501 | snprintf (new_svcs, 4095, "%s %s %s 30 |", add_svc, protocol, ports); |
|---|
| 6502 | |
|---|
| 6503 | if (strlen (new_svcs) >= sizeof (new_svcs)) |
|---|
| 6504 | return; |
|---|
| 6505 | |
|---|
| 6506 | nvram_set ("svqos_svcs", new_svcs); |
|---|
| 6507 | nvram_commit (); |
|---|
| 6508 | } |
|---|
| 6509 | |
|---|
| 6510 | |
|---|
| 6511 | void |
|---|
| 6512 | qos_add_ip (webs_t wp) |
|---|
| 6513 | { |
|---|
| 6514 | char *var = websGetVar (wp, "wshaper_enable", NULL); |
|---|
| 6515 | if (var != NULL) |
|---|
| 6516 | nvram_set ("wshaper_enable", var); |
|---|
| 6517 | |
|---|
| 6518 | char *add_ip0 = websGetVar (wp, "svqos_ipaddr0", NULL); |
|---|
| 6519 | char *add_ip1 = websGetVar (wp, "svqos_ipaddr1", NULL); |
|---|
| 6520 | char *add_ip2 = websGetVar (wp, "svqos_ipaddr2", NULL); |
|---|
| 6521 | char *add_ip3 = websGetVar (wp, "svqos_ipaddr3", NULL); |
|---|
| 6522 | char *add_nm = websGetVar (wp, "svqos_netmask", NULL); |
|---|
| 6523 | char add_ip[19] = { 0 }; |
|---|
| 6524 | char *svqos_ips = nvram_safe_get ("svqos_ips"); |
|---|
| 6525 | char new_ip[4096] = { 0 }; |
|---|
| 6526 | |
|---|
| 6527 | memset (new_ip, 0, sizeof (new_ip)); |
|---|
| 6528 | |
|---|
| 6529 | snprintf (add_ip, 19, "%s.%s.%s.%s/%s", add_ip0, add_ip1, add_ip2, add_ip3, |
|---|
| 6530 | add_nm); |
|---|
| 6531 | |
|---|
| 6532 | /* if this ip exists, return an error */ |
|---|
| 6533 | if (strstr (svqos_ips, add_ip)) |
|---|
| 6534 | return; |
|---|
| 6535 | #ifdef HAVE_AQOS |
|---|
| 6536 | snprintf (new_ip, 4095, "%s %s 100 100 |", svqos_ips, add_ip); |
|---|
| 6537 | #else |
|---|
| 6538 | snprintf (new_ip, 4095, "%s %s 30 |", svqos_ips, add_ip); |
|---|
| 6539 | #endif |
|---|
| 6540 | if (strlen (new_ip) >= sizeof (new_ip)) |
|---|
| 6541 | return; |
|---|
| 6542 | |
|---|
| 6543 | nvram_set ("svqos_ips", new_ip); |
|---|
| 6544 | nvram_commit (); |
|---|
| 6545 | |
|---|
| 6546 | } |
|---|
| 6547 | |
|---|
| 6548 | void |
|---|
| 6549 | qos_add_mac (webs_t wp) |
|---|
| 6550 | { |
|---|
| 6551 | char *var = websGetVar (wp, "wshaper_enable", NULL); |
|---|
| 6552 | if (var != NULL) |
|---|
| 6553 | nvram_set ("wshaper_enable", var); |
|---|
| 6554 | |
|---|
| 6555 | char *add_mac0 = websGetVar (wp, "svqos_hwaddr0", NULL); |
|---|
| 6556 | char *add_mac1 = websGetVar (wp, "svqos_hwaddr1", NULL); |
|---|
| 6557 | char *add_mac2 = websGetVar (wp, "svqos_hwaddr2", NULL); |
|---|
| 6558 | char *add_mac3 = websGetVar (wp, "svqos_hwaddr3", NULL); |
|---|
| 6559 | char *add_mac4 = websGetVar (wp, "svqos_hwaddr4", NULL); |
|---|
| 6560 | char *add_mac5 = websGetVar (wp, "svqos_hwaddr5", NULL); |
|---|
| 6561 | char add_mac[19] = { 0 }; |
|---|
| 6562 | char *svqos_macs = nvram_safe_get ("svqos_macs"); |
|---|
| 6563 | char new_mac[4096] = { 0 }; |
|---|
| 6564 | |
|---|
| 6565 | memset (new_mac, 0, sizeof (new_mac)); |
|---|
| 6566 | |
|---|
| 6567 | snprintf (add_mac, 18, "%s:%s:%s:%s:%s:%s", add_mac0, add_mac1, add_mac2, |
|---|
| 6568 | add_mac3, add_mac4, add_mac5); |
|---|
| 6569 | |
|---|
| 6570 | /* if this mac exists, return an error */ |
|---|
| 6571 | if (strstr (svqos_macs, add_mac)) |
|---|
| 6572 | return; |
|---|
| 6573 | #ifdef HAVE_AQOS |
|---|
| 6574 | snprintf (new_mac, 4095, "%s %s 100 100 |", svqos_macs, add_mac); |
|---|
| 6575 | #else |
|---|
| 6576 | snprintf (new_mac, 4095, "%s %s 30 |", svqos_macs, add_mac); |
|---|
| 6577 | #endif |
|---|
| 6578 | if (strlen (new_mac) >= sizeof (new_mac)) |
|---|
| 6579 | return; |
|---|
| 6580 | |
|---|
| 6581 | nvram_set ("svqos_macs", new_mac); |
|---|
| 6582 | nvram_commit (); |
|---|
| 6583 | |
|---|
| 6584 | } |
|---|
| 6585 | |
|---|
| 6586 | void |
|---|
| 6587 | qos_save (webs_t wp) |
|---|
| 6588 | { |
|---|
| 6589 | char *value = websGetVar (wp, "action", ""); |
|---|
| 6590 | char svqos_var[4096] = { 0 }; |
|---|
| 6591 | char field[32] = { 0 }; |
|---|
| 6592 | char *name, *data, *level, *level2, *delete; |
|---|
| 6593 | int no_svcs = atoi (websGetVar (wp, "svqos_nosvcs", NULL)); |
|---|
| 6594 | int no_ips = atoi (websGetVar (wp, "svqos_noips", NULL)); |
|---|
| 6595 | int no_macs = atoi (websGetVar (wp, "svqos_nomacs", NULL)); |
|---|
| 6596 | int i = 0, j = 0; |
|---|
| 6597 | |
|---|
| 6598 | /* reused wshaper fields - see src/router/rc/wshaper.c */ |
|---|
| 6599 | snprintf (field, 31, "wshaper_enable"); |
|---|
| 6600 | data = websGetVar (wp, field, NULL); |
|---|
| 6601 | nvram_set ("wshaper_enable", data); |
|---|
| 6602 | |
|---|
| 6603 | |
|---|
| 6604 | if (strcmp (data, "0") == 0) |
|---|
| 6605 | return; |
|---|
| 6606 | |
|---|
| 6607 | snprintf (field, 31, "enable_game"); |
|---|
| 6608 | data = websGetVar (wp, field, NULL); |
|---|
| 6609 | nvram_set ("enable_game", data); |
|---|
| 6610 | |
|---|
| 6611 | snprintf (field, 31, "default_uplevel"); |
|---|
| 6612 | data = websGetVar (wp, field, NULL); |
|---|
| 6613 | nvram_set ("default_uplevel", data); |
|---|
| 6614 | |
|---|
| 6615 | snprintf (field, 31, "default_downlevel"); |
|---|
| 6616 | data = websGetVar (wp, field, NULL); |
|---|
| 6617 | nvram_set ("default_downlevel", data); |
|---|
| 6618 | |
|---|
| 6619 | snprintf (field, 31, "wshaper_downlink"); |
|---|
| 6620 | data = websGetVar (wp, field, NULL); |
|---|
| 6621 | nvram_set ("wshaper_downlink", data); |
|---|
| 6622 | |
|---|
| 6623 | snprintf (field, 31, "wshaper_uplink"); |
|---|
| 6624 | data = websGetVar (wp, field, NULL); |
|---|
| 6625 | nvram_set ("wshaper_uplink", data); |
|---|
| 6626 | |
|---|
| 6627 | snprintf (field, 31, "wshaper_dev"); |
|---|
| 6628 | data = websGetVar (wp, field, NULL); |
|---|
| 6629 | nvram_set ("wshaper_dev", data); |
|---|
| 6630 | |
|---|
| 6631 | snprintf (field, 31, "qos_type"); |
|---|
| 6632 | data = websGetVar (wp, field, NULL); |
|---|
| 6633 | nvram_set ("qos_type", data); |
|---|
| 6634 | |
|---|
| 6635 | //nvram_commit (); |
|---|
| 6636 | |
|---|
| 6637 | memset (svqos_var, 0, sizeof (svqos_var)); |
|---|
| 6638 | |
|---|
| 6639 | /* services priorities */ |
|---|
| 6640 | for (i = 0; i < no_svcs; i++) |
|---|
| 6641 | { |
|---|
| 6642 | char protocol[100], ports[100]; |
|---|
| 6643 | |
|---|
| 6644 | memset (protocol, 0, 100); |
|---|
| 6645 | memset (ports, 0, 10); |
|---|
| 6646 | |
|---|
| 6647 | snprintf (field, 31, "svqos_svcdel%d", i); |
|---|
| 6648 | delete = websGetVar (wp, field, NULL); |
|---|
| 6649 | |
|---|
| 6650 | if (delete && strlen (delete) > 0) |
|---|
| 6651 | continue; |
|---|
| 6652 | |
|---|
| 6653 | snprintf (field, 31, "svqos_svcname%d", i); |
|---|
| 6654 | name = websGetVar (wp, field, NULL); |
|---|
| 6655 | |
|---|
| 6656 | snprintf (field, 31, "svqos_svcprio%d", i); |
|---|
| 6657 | level = websGetVar (wp, field, NULL); |
|---|
| 6658 | |
|---|
| 6659 | if (get_svc (name, protocol, ports)) |
|---|
| 6660 | continue; |
|---|
| 6661 | |
|---|
| 6662 | if (strcmp (protocol, "l7") == 0) |
|---|
| 6663 | { |
|---|
| 6664 | int slen = strlen (name); |
|---|
| 6665 | for (j = 0; j < slen; j++) |
|---|
| 6666 | name[j] = tolower (name[j]); |
|---|
| 6667 | } |
|---|
| 6668 | |
|---|
| 6669 | if (strlen (svqos_var) > 0) |
|---|
| 6670 | sprintf (svqos_var, "%s %s %s %s %s |", svqos_var, name, protocol, |
|---|
| 6671 | ports, level); |
|---|
| 6672 | else |
|---|
| 6673 | sprintf (svqos_var, "%s %s %s %s |", name, protocol, ports, level); |
|---|
| 6674 | |
|---|
| 6675 | } |
|---|
| 6676 | |
|---|
| 6677 | if (strlen (svqos_var) <= sizeof (svqos_var)) |
|---|
| 6678 | nvram_set ("svqos_svcs", svqos_var); |
|---|
| 6679 | //nvram_commit (); |
|---|
| 6680 | memset (svqos_var, 0, sizeof (svqos_var)); |
|---|
| 6681 | |
|---|
| 6682 | /* IP priorities */ |
|---|
| 6683 | for (i = 0; i < no_ips; i++) |
|---|
| 6684 | { |
|---|
| 6685 | |
|---|
| 6686 | snprintf (field, 31, "svqos_ipdel%d", i); |
|---|
| 6687 | delete = websGetVar (wp, field, NULL); |
|---|
| 6688 | |
|---|
| 6689 | if (delete && strlen (delete) > 0) |
|---|
| 6690 | continue; |
|---|
| 6691 | |
|---|
| 6692 | snprintf (field, 31, "svqos_ip%d", i); |
|---|
| 6693 | data = websGetVar (wp, field, NULL); |
|---|
| 6694 | |
|---|
| 6695 | #ifndef HAVE_AQOS |
|---|
| 6696 | snprintf (field, 31, "svqos_ipprio%d", i); |
|---|
| 6697 | level = websGetVar (wp, field, NULL); |
|---|
| 6698 | if (strlen (svqos_var) > 0) |
|---|
| 6699 | sprintf (svqos_var, "%s %s %s |", svqos_var, data, level); |
|---|
| 6700 | else |
|---|
| 6701 | sprintf (svqos_var, "%s %s |", data, level); |
|---|
| 6702 | #else |
|---|
| 6703 | snprintf (field, 31, "svqos_ipup%d", i); |
|---|
| 6704 | level = websGetVar (wp, field, NULL); |
|---|
| 6705 | snprintf (field, 31, "svqos_ipdown%d", i); |
|---|
| 6706 | level2 = websGetVar (wp, field, NULL); |
|---|
| 6707 | if (strlen (svqos_var) > 0) |
|---|
| 6708 | sprintf (svqos_var, "%s %s %s %s |", svqos_var, data, level, level2); |
|---|
| 6709 | else |
|---|
| 6710 | sprintf (svqos_var, "%s %s %s |", data, level, level2); |
|---|
| 6711 | |
|---|
| 6712 | |
|---|
| 6713 | #endif |
|---|
| 6714 | |
|---|
| 6715 | } |
|---|
| 6716 | |
|---|
| 6717 | if (strlen (svqos_var) <= sizeof (svqos_var)) |
|---|
| 6718 | nvram_set ("svqos_ips", svqos_var); |
|---|
| 6719 | //nvram_commit (); |
|---|
| 6720 | memset (svqos_var, 0, sizeof (svqos_var)); |
|---|
| 6721 | |
|---|
| 6722 | /* MAC priorities */ |
|---|
| 6723 | for (i = 0; i < no_macs; i++) |
|---|
| 6724 | { |
|---|
| 6725 | snprintf (field, 31, "svqos_macdel%d", i); |
|---|
| 6726 | delete = websGetVar (wp, field, NULL); |
|---|
| 6727 | |
|---|
| 6728 | if (delete && strlen (delete) > 0) |
|---|
| 6729 | continue; |
|---|
| 6730 | |
|---|
| 6731 | snprintf (field, 31, "svqos_mac%d", i); |
|---|
| 6732 | data = websGetVar (wp, field, NULL); |
|---|
| 6733 | |
|---|
| 6734 | #ifndef HAVE_AQOS |
|---|
| 6735 | snprintf (field, 31, "svqos_macprio%d", i); |
|---|
| 6736 | level = websGetVar (wp, field, NULL); |
|---|
| 6737 | |
|---|
| 6738 | if (strlen (svqos_var) > 0) |
|---|
| 6739 | sprintf (svqos_var, "%s %s %s |", svqos_var, data, level); |
|---|
| 6740 | else |
|---|
| 6741 | sprintf (svqos_var, "%s %s |", data, level); |
|---|
| 6742 | #else |
|---|
| 6743 | snprintf (field, 31, "svqos_macup%d", i); |
|---|
| 6744 | level = websGetVar (wp, field, NULL); |
|---|
| 6745 | snprintf (field, 31, "svqos_macdown%d", i); |
|---|
| 6746 | level2 = websGetVar (wp, field, NULL); |
|---|
| 6747 | |
|---|
| 6748 | if (strlen (svqos_var) > 0) |
|---|
| 6749 | sprintf (svqos_var, "%s %s %s %s |", svqos_var, data, level, level2); |
|---|
| 6750 | else |
|---|
| 6751 | sprintf (svqos_var, "%s %s %s |", data, level, level2); |
|---|
| 6752 | #endif |
|---|
| 6753 | |
|---|
| 6754 | |
|---|
| 6755 | } |
|---|
| 6756 | |
|---|
| 6757 | if (strlen (svqos_var) <= sizeof (svqos_var)) |
|---|
| 6758 | nvram_set ("svqos_macs", svqos_var); |
|---|
| 6759 | //nvram_commit (); |
|---|
| 6760 | |
|---|
| 6761 | /* adm6996 LAN port priorities */ |
|---|
| 6762 | nvram_set ("svqos_port1prio", websGetVar (wp, "svqos_port1prio", NULL)); |
|---|
| 6763 | nvram_set ("svqos_port2prio", websGetVar (wp, "svqos_port2prio", NULL)); |
|---|
| 6764 | nvram_set ("svqos_port3prio", websGetVar (wp, "svqos_port3prio", NULL)); |
|---|
| 6765 | nvram_set ("svqos_port4prio", websGetVar (wp, "svqos_port4prio", NULL)); |
|---|
| 6766 | |
|---|
| 6767 | nvram_set ("svqos_port1bw", websGetVar (wp, "svqos_port1bw", NULL)); |
|---|
| 6768 | nvram_set ("svqos_port2bw", websGetVar (wp, "svqos_port2bw", NULL)); |
|---|
| 6769 | nvram_set ("svqos_port3bw", websGetVar (wp, "svqos_port3bw", NULL)); |
|---|
| 6770 | nvram_set ("svqos_port4bw", websGetVar (wp, "svqos_port4bw", NULL)); |
|---|
| 6771 | |
|---|
| 6772 | addAction ("qos"); |
|---|
| 6773 | if (!strcmp (value, "ApplyTake")) |
|---|
| 6774 | { |
|---|
| 6775 | nvram_commit (); |
|---|
| 6776 | service_restart (); |
|---|
| 6777 | } |
|---|
| 6778 | |
|---|
| 6779 | |
|---|
| 6780 | } |
|---|
| 6781 | |
|---|
| 6782 | void |
|---|
| 6783 | ej_get_clone_wmac (webs_t wp, int argc, char_t ** argv) |
|---|
| 6784 | { |
|---|
| 6785 | #ifdef HAVE_RB500 |
|---|
| 6786 | return 0; |
|---|
| 6787 | #else |
|---|
| 6788 | |
|---|
| 6789 | char *c; |
|---|
| 6790 | int mac, which; |
|---|
| 6791 | int dofree = 0; |
|---|
| 6792 | if (ejArgs (argc, argv, "%d", &which) < 1) |
|---|
| 6793 | { |
|---|
| 6794 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 6795 | return; |
|---|
| 6796 | } |
|---|
| 6797 | |
|---|
| 6798 | if (nvram_match ("def_whwaddr", "00:00:00:00:00:00")) |
|---|
| 6799 | { |
|---|
| 6800 | if (nvram_match ("port_swap", "1")) |
|---|
| 6801 | c = strdup (nvram_safe_get ("et1macaddr")); |
|---|
| 6802 | else |
|---|
| 6803 | c = strdup (nvram_safe_get ("et0macaddr")); |
|---|
| 6804 | dofree = 1; |
|---|
| 6805 | if (c) |
|---|
| 6806 | { |
|---|
| 6807 | MAC_ADD (c); |
|---|
| 6808 | MAC_ADD (c); |
|---|
| 6809 | } |
|---|
| 6810 | } |
|---|
| 6811 | else |
|---|
| 6812 | c = nvram_safe_get ("def_whwaddr"); |
|---|
| 6813 | |
|---|
| 6814 | if (c) |
|---|
| 6815 | { |
|---|
| 6816 | mac = get_single_mac (c, which); |
|---|
| 6817 | websWrite (wp, "%02X", mac); |
|---|
| 6818 | if (dofree) |
|---|
| 6819 | free (c); |
|---|
| 6820 | } |
|---|
| 6821 | else |
|---|
| 6822 | websWrite (wp, "00"); |
|---|
| 6823 | |
|---|
| 6824 | return; |
|---|
| 6825 | #endif |
|---|
| 6826 | } |
|---|
| 6827 | |
|---|
| 6828 | |
|---|
| 6829 | |
|---|
| 6830 | /* todo stylesheet compatible code */ |
|---|
| 6831 | /* lonewolf additions */ |
|---|
| 6832 | |
|---|
| 6833 | // Note that there is no VLAN #16. It's just a convieniant way of denoting a "Tagged" port |
|---|
| 6834 | void |
|---|
| 6835 | ej_port_vlan_table (webs_t wp, int argc, char_t ** argv) |
|---|
| 6836 | { |
|---|
| 6837 | /* |
|---|
| 6838 | vlans[x][y] where |
|---|
| 6839 | x 0-15 are VLANS |
|---|
| 6840 | x 16 is tagging, 17 is auto-negotiation, 18 is 100/10 Mbit, and 19 is Full/Half duplex |
|---|
| 6841 | y 0-4 are switch ports (port 5 is set automaticly) |
|---|
| 6842 | y 5 it the bridge device (x 16 dosn't apply) |
|---|
| 6843 | */ |
|---|
| 6844 | |
|---|
| 6845 | int i, j, vlans[20][6], tmp, wl_br; |
|---|
| 6846 | char *c, *next, buff[32], portvlan[32]; |
|---|
| 6847 | |
|---|
| 6848 | for (i = 0; i < 20; i++) |
|---|
| 6849 | for (j = 0; j < 6; j++) |
|---|
| 6850 | vlans[i][j] = -1; |
|---|
| 6851 | |
|---|
| 6852 | wl_br = -1; |
|---|
| 6853 | |
|---|
| 6854 | for (i = 0; i < 8; i++) |
|---|
| 6855 | { |
|---|
| 6856 | if (i < 5) |
|---|
| 6857 | snprintf (buff, 31, "port%dvlans", i); |
|---|
| 6858 | else if (i == 5) |
|---|
| 6859 | snprintf (buff, 31, "%s", "lan_ifnames"); |
|---|
| 6860 | else |
|---|
| 6861 | snprintf (buff, 31, "ub%d_ifnames", i - 5); |
|---|
| 6862 | |
|---|
| 6863 | c = nvram_safe_get (buff); |
|---|
| 6864 | |
|---|
| 6865 | if (c) |
|---|
| 6866 | { |
|---|
| 6867 | foreach (portvlan, c, next) |
|---|
| 6868 | { |
|---|
| 6869 | if (portvlan[0] == 'e' && portvlan[1] == 't' && portvlan[2] == 'h' |
|---|
| 6870 | && portvlan[3] == '1') |
|---|
| 6871 | wl_br = i - 5; |
|---|
| 6872 | if (ISDIGIT (portvlan, 1) |
|---|
| 6873 | || (portvlan[0] == 'v' && portvlan[1] == 'l' |
|---|
| 6874 | && portvlan[2] == 'a' && portvlan[3] == 'n')) |
|---|
| 6875 | { |
|---|
| 6876 | if (ISDIGIT (portvlan, 1)) |
|---|
| 6877 | tmp = atoi (portvlan); |
|---|
| 6878 | else |
|---|
| 6879 | { |
|---|
| 6880 | portvlan[0] = portvlan[4]; |
|---|
| 6881 | portvlan[1] = portvlan[5]; |
|---|
| 6882 | portvlan[2] = '\0'; |
|---|
| 6883 | if (ISDIGIT (portvlan, 1)) |
|---|
| 6884 | tmp = atoi (portvlan); |
|---|
| 6885 | else |
|---|
| 6886 | continue; |
|---|
| 6887 | } |
|---|
| 6888 | |
|---|
| 6889 | if (i < 5) |
|---|
| 6890 | { |
|---|
| 6891 | vlans[tmp][i] = 1; |
|---|
| 6892 | } |
|---|
| 6893 | else |
|---|
| 6894 | { |
|---|
| 6895 | vlans[tmp][5] = i - 5; |
|---|
| 6896 | } |
|---|
| 6897 | } |
|---|
| 6898 | } |
|---|
| 6899 | } |
|---|
| 6900 | } |
|---|
| 6901 | |
|---|
| 6902 | for (i = 0; i < 20; i++) |
|---|
| 6903 | { |
|---|
| 6904 | websWrite (wp, " <tr>\n"); |
|---|
| 6905 | websWrite (wp, "<td>"); |
|---|
| 6906 | |
|---|
| 6907 | switch (i) |
|---|
| 6908 | { |
|---|
| 6909 | case 16: |
|---|
| 6910 | websWrite (wp, |
|---|
| 6911 | "<script type=\"text/javascript\">Capture(vlan.tagged)</script>"); |
|---|
| 6912 | break; |
|---|
| 6913 | case 17: |
|---|
| 6914 | websWrite (wp, |
|---|
| 6915 | "<script type=\"text/javascript\">Capture(vlan.negociate)</script>"); |
|---|
| 6916 | break; |
|---|
| 6917 | case 18: |
|---|
| 6918 | websWrite (wp, "100 Mbit"); |
|---|
| 6919 | break; |
|---|
| 6920 | case 19: |
|---|
| 6921 | websWrite (wp, "Full-Duplex"); |
|---|
| 6922 | break; |
|---|
| 6923 | default: |
|---|
| 6924 | snprintf (buff, 31, "%d", i); |
|---|
| 6925 | websWrite (wp, buff); |
|---|
| 6926 | break; |
|---|
| 6927 | } |
|---|
| 6928 | |
|---|
| 6929 | websWrite (wp, "</td>\n"); |
|---|
| 6930 | |
|---|
| 6931 | for (j = 0; j < 5; j++) |
|---|
| 6932 | { |
|---|
| 6933 | snprintf (buff, 31, "\"port%dvlan%d\"", j, i); |
|---|
| 6934 | websWrite (wp, "<td"); |
|---|
| 6935 | |
|---|
| 6936 | if (j % 2 == 0) |
|---|
| 6937 | websWrite (wp, " bgcolor=\"#CCCCCC\""); |
|---|
| 6938 | |
|---|
| 6939 | |
|---|
| 6940 | websWrite (wp, |
|---|
| 6941 | " height=\"20\"><div align=\"center\"><input type=\"checkbox\" value=\"on\" name="); |
|---|
| 6942 | websWrite (wp, buff); |
|---|
| 6943 | |
|---|
| 6944 | if (i < 17 || i > 19) |
|---|
| 6945 | { |
|---|
| 6946 | if (vlans[i][j] == 1) |
|---|
| 6947 | websWrite (wp, " checked=\"checked\""); |
|---|
| 6948 | } |
|---|
| 6949 | else |
|---|
| 6950 | { |
|---|
| 6951 | if (vlans[i][j] == -1) |
|---|
| 6952 | websWrite (wp, " checked=\"checked\""); |
|---|
| 6953 | } |
|---|
| 6954 | |
|---|
| 6955 | if (i < 17) |
|---|
| 6956 | { |
|---|
| 6957 | websWrite (wp, " onclick="); |
|---|
| 6958 | snprintf (buff, sizeof (buff), |
|---|
| 6959 | "\"SelVLAN(this.form,'port%d')\"", j); |
|---|
| 6960 | websWrite (wp, buff); |
|---|
| 6961 | } |
|---|
| 6962 | else if (i == 17) |
|---|
| 6963 | { |
|---|
| 6964 | websWrite (wp, " onclick="); |
|---|
| 6965 | snprintf (buff, sizeof (buff), |
|---|
| 6966 | "\"SelSpeed(this.form,'port%d')\"", j); |
|---|
| 6967 | websWrite (wp, buff); |
|---|
| 6968 | } |
|---|
| 6969 | websWrite (wp, " /></div></td>\n"); |
|---|
| 6970 | } |
|---|
| 6971 | |
|---|
| 6972 | if (i < 16) |
|---|
| 6973 | { |
|---|
| 6974 | websWrite (wp, " <td><select name="); |
|---|
| 6975 | snprintf (buff, 31, "\"vlan%d\"", i); |
|---|
| 6976 | websWrite (wp, buff); |
|---|
| 6977 | websWrite (wp, |
|---|
| 6978 | "><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"-1\\\""); |
|---|
| 6979 | if (vlans[i][5] < 0) |
|---|
| 6980 | websWrite (wp, " selected=\\\"selected\\\""); |
|---|
| 6981 | websWrite (wp, |
|---|
| 6982 | ">\" + share.none + \"</option>\");\n//]]>\n</script><option value=\"0\""); |
|---|
| 6983 | if (vlans[i][5] == 0) |
|---|
| 6984 | websWrite (wp, " selected=\"selected\""); |
|---|
| 6985 | websWrite (wp, ">LAN</option></select></td>\n"); |
|---|
| 6986 | } |
|---|
| 6987 | else |
|---|
| 6988 | { |
|---|
| 6989 | websWrite (wp, "<td> </td>\n"); |
|---|
| 6990 | } |
|---|
| 6991 | |
|---|
| 6992 | websWrite (wp, "</tr>\n"); |
|---|
| 6993 | |
|---|
| 6994 | if (i == 16 || i == 19) |
|---|
| 6995 | { |
|---|
| 6996 | websWrite (wp, "<tr><td> </td></tr>\n"); |
|---|
| 6997 | } |
|---|
| 6998 | } |
|---|
| 6999 | |
|---|
| 7000 | websWrite (wp, "<tr>\n"); |
|---|
| 7001 | websWrite (wp, |
|---|
| 7002 | "<td><script type=\"text/javascript\">Capture(share.wireless)</script></td>\n"); |
|---|
| 7003 | |
|---|
| 7004 | websWrite (wp, |
|---|
| 7005 | "<td colspan=\"6\"><select name=\"wireless\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"-1\\\""); |
|---|
| 7006 | if (wl_br < 0) |
|---|
| 7007 | websWrite (wp, " selected=\\\"selected\\\""); |
|---|
| 7008 | websWrite (wp, |
|---|
| 7009 | ">\" + share.none + \"</option>\");\n//]]>\n</script><option value=\"0\""); |
|---|
| 7010 | if (wl_br == 0) |
|---|
| 7011 | websWrite (wp, " selected=\"selected\""); |
|---|
| 7012 | websWrite (wp, ">LAN</option></select></td>\n"); |
|---|
| 7013 | websWrite (wp, "</tr>\n"); |
|---|
| 7014 | |
|---|
| 7015 | websWrite (wp, "<tr><td> </td></tr>\n"); |
|---|
| 7016 | |
|---|
| 7017 | websWrite (wp, "<tr>\n"); |
|---|
| 7018 | websWrite (wp, |
|---|
| 7019 | "<td><script type=\"text/javascript\">Capture(vlan.aggregation)</script></td>\n"); |
|---|
| 7020 | |
|---|
| 7021 | websWrite (wp, |
|---|
| 7022 | "<td colspan=\"6\"><select name=\"trunking\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"0\\\">\" + share.no + \"</option>\");\n//]]>\n</script><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"1\\\""); |
|---|
| 7023 | |
|---|
| 7024 | c = nvram_safe_get ("trunking"); |
|---|
| 7025 | |
|---|
| 7026 | snprintf (buff, 5, "%s", c); |
|---|
| 7027 | |
|---|
| 7028 | if (atoi (buff) == 1) |
|---|
| 7029 | websWrite (wp, " selected=\\\"selected\\\""); |
|---|
| 7030 | |
|---|
| 7031 | websWrite (wp, |
|---|
| 7032 | ">\" + vlan.trunk + \"</option>\");\n//]]>\n</script></select></td>\n"); |
|---|
| 7033 | websWrite (wp, " </tr>"); |
|---|
| 7034 | |
|---|
| 7035 | return; |
|---|
| 7036 | } |
|---|
| 7037 | |
|---|
| 7038 | /* Note: VLAN #16 designates tagging. There is no VLAN #16 (only 0-15) */ |
|---|
| 7039 | |
|---|
| 7040 | void |
|---|
| 7041 | port_vlan_table_save (webs_t wp) |
|---|
| 7042 | { |
|---|
| 7043 | int port = 0, vlan = 0, vlans[20], i; |
|---|
| 7044 | char portid[32], portvlan[64], *portval, buff[32], *c, *next, br0vlans[64], |
|---|
| 7045 | br1vlans[64], br2vlans[64]; |
|---|
| 7046 | |
|---|
| 7047 | strcpy (portvlan, ""); |
|---|
| 7048 | |
|---|
| 7049 | for (vlan = 0; vlan < 20; vlan++) |
|---|
| 7050 | vlans[vlan] = 0; |
|---|
| 7051 | |
|---|
| 7052 | vlans[16] = 1; |
|---|
| 7053 | |
|---|
| 7054 | for (port = 0; port < 5; port++) |
|---|
| 7055 | { |
|---|
| 7056 | for (vlan = 0; vlan < 20; vlan++) |
|---|
| 7057 | { |
|---|
| 7058 | snprintf (portid, 31, "port%dvlan%d", port, vlan); |
|---|
| 7059 | portval = websGetVar (wp, portid, ""); |
|---|
| 7060 | |
|---|
| 7061 | if (vlan < 17 || vlan > 19) |
|---|
| 7062 | i = (strcmp (portval, "on") == 0); |
|---|
| 7063 | else |
|---|
| 7064 | i = (strcmp (portval, "on") != 0); |
|---|
| 7065 | |
|---|
| 7066 | if (i) |
|---|
| 7067 | { |
|---|
| 7068 | if (strlen (portvlan) > 0) |
|---|
| 7069 | strcat (portvlan, " "); |
|---|
| 7070 | |
|---|
| 7071 | snprintf (buff, 4, "%d", vlan); |
|---|
| 7072 | strcat (portvlan, buff); |
|---|
| 7073 | vlans[vlan] = 1; |
|---|
| 7074 | } |
|---|
| 7075 | } |
|---|
| 7076 | |
|---|
| 7077 | snprintf (portid, 31, "port%dvlans", port); |
|---|
| 7078 | nvram_set (portid, portvlan); |
|---|
| 7079 | strcpy (portvlan, ""); |
|---|
| 7080 | } |
|---|
| 7081 | |
|---|
| 7082 | /* done with ports 0-4, now set up #5 automaticly */ |
|---|
| 7083 | /* if a VLAN is used, it also gets assigned to port #5 */ |
|---|
| 7084 | for (vlan = 0; vlan < 17; vlan++) |
|---|
| 7085 | { |
|---|
| 7086 | if (vlans[vlan]) |
|---|
| 7087 | { |
|---|
| 7088 | if (strlen (portvlan) > 0) |
|---|
| 7089 | strcat (portvlan, " "); |
|---|
| 7090 | |
|---|
| 7091 | snprintf (buff, 4, "%d", vlan); |
|---|
| 7092 | strcat (portvlan, buff); |
|---|
| 7093 | } |
|---|
| 7094 | } |
|---|
| 7095 | |
|---|
| 7096 | nvram_set ("port5vlans", portvlan); |
|---|
| 7097 | |
|---|
| 7098 | strcpy (br0vlans, ""); |
|---|
| 7099 | c = nvram_safe_get ("lan_ifnames"); |
|---|
| 7100 | if (c) |
|---|
| 7101 | { |
|---|
| 7102 | foreach (portid, c, next) |
|---|
| 7103 | { |
|---|
| 7104 | if (!(strncmp (portid, "vlan", 4) == 0) |
|---|
| 7105 | && !(strncmp (portid, "eth1", 4) == 0)) |
|---|
| 7106 | { |
|---|
| 7107 | if (strlen (br0vlans) > 0) |
|---|
| 7108 | strcat (br0vlans, " "); |
|---|
| 7109 | strcat (br0vlans, portid); |
|---|
| 7110 | } |
|---|
| 7111 | } |
|---|
| 7112 | } |
|---|
| 7113 | |
|---|
| 7114 | strcpy (br1vlans, ""); |
|---|
| 7115 | c = nvram_safe_get ("ub1_ifnames"); |
|---|
| 7116 | if (c) |
|---|
| 7117 | { |
|---|
| 7118 | foreach (portid, c, next) |
|---|
| 7119 | { |
|---|
| 7120 | if (!(strncmp (portid, "vlan", 4) == 0) |
|---|
| 7121 | && !(strncmp (portid, "eth1", 4) == 0)) |
|---|
| 7122 | { |
|---|
| 7123 | if (strlen (br1vlans) > 0) |
|---|
| 7124 | strcat (br1vlans, " "); |
|---|
| 7125 | strcat (br1vlans, portid); |
|---|
| 7126 | } |
|---|
| 7127 | } |
|---|
| 7128 | } |
|---|
| 7129 | |
|---|
| 7130 | strcpy (br2vlans, ""); |
|---|
| 7131 | c = nvram_safe_get ("ub2_ifnames"); |
|---|
| 7132 | if (c) |
|---|
| 7133 | { |
|---|
| 7134 | foreach (portid, c, next) |
|---|
| 7135 | { |
|---|
| 7136 | if (!(strncmp (portid, "vlan", 4) == 0) |
|---|
| 7137 | && !(strncmp (portid, "eth1", 4) == 0)) |
|---|
| 7138 | { |
|---|
| 7139 | if (strlen (br2vlans) > 0) |
|---|
| 7140 | strcat (br2vlans, " "); |
|---|
| 7141 | strcat (br2vlans, portid); |
|---|
| 7142 | } |
|---|
| 7143 | } |
|---|
| 7144 | } |
|---|
| 7145 | |
|---|
| 7146 | for (i = 0; i < 16; i++) |
|---|
| 7147 | { |
|---|
| 7148 | snprintf (buff, 31, "vlan%d", i); |
|---|
| 7149 | portval = websGetVar (wp, buff, ""); |
|---|
| 7150 | |
|---|
| 7151 | switch (atoi (portval)) |
|---|
| 7152 | { |
|---|
| 7153 | case 0: |
|---|
| 7154 | if (strlen (br0vlans) > 0) |
|---|
| 7155 | strcat (br0vlans, " "); |
|---|
| 7156 | strcat (br0vlans, buff); |
|---|
| 7157 | break; |
|---|
| 7158 | case 1: |
|---|
| 7159 | if (strlen (br1vlans) > 0) |
|---|
| 7160 | strcat (br1vlans, " "); |
|---|
| 7161 | strcat (br1vlans, buff); |
|---|
| 7162 | break; |
|---|
| 7163 | case 2: |
|---|
| 7164 | if (strlen (br2vlans) > 0) |
|---|
| 7165 | strcat (br2vlans, " "); |
|---|
| 7166 | strcat (br2vlans, buff); |
|---|
| 7167 | break; |
|---|
| 7168 | } |
|---|
| 7169 | } |
|---|
| 7170 | |
|---|
| 7171 | strcpy (buff, ""); |
|---|
| 7172 | |
|---|
| 7173 | switch (atoi (websGetVar (wp, "wireless", ""))) |
|---|
| 7174 | { |
|---|
| 7175 | case 0: |
|---|
| 7176 | if (strlen (br0vlans) > 0) |
|---|
| 7177 | strcat (br0vlans, " "); |
|---|
| 7178 | strcat (br0vlans, get_wdev ()); |
|---|
| 7179 | break; |
|---|
| 7180 | case 1: |
|---|
| 7181 | if (strlen (br1vlans) > 0) |
|---|
| 7182 | strcat (br1vlans, " "); |
|---|
| 7183 | strcat (br1vlans, get_wdev ()); |
|---|
| 7184 | break; |
|---|
| 7185 | case 2: |
|---|
| 7186 | if (strlen (br2vlans) > 0) |
|---|
| 7187 | strcat (br2vlans, " "); |
|---|
| 7188 | strcat (br2vlans, get_wdev ()); |
|---|
| 7189 | break; |
|---|
| 7190 | } |
|---|
| 7191 | |
|---|
| 7192 | snprintf (buff, 3, "%s", websGetVar (wp, "trunking", "")); |
|---|
| 7193 | |
|---|
| 7194 | nvram_set ("lan_ifnames", br0vlans); |
|---|
| 7195 | //nvram_set("ub1_ifnames", br1vlans); |
|---|
| 7196 | //nvram_set("ub2_ifnames", br2vlans); |
|---|
| 7197 | nvram_set ("trunking", buff); |
|---|
| 7198 | nvram_set ("vlans", "1"); |
|---|
| 7199 | |
|---|
| 7200 | nvram_commit (); |
|---|
| 7201 | |
|---|
| 7202 | } |
|---|
| 7203 | |
|---|
| 7204 | |
|---|
| 7205 | void |
|---|
| 7206 | ej_get_qossvcs2 (webs_t wp, int argc, char_t ** argv) |
|---|
| 7207 | { |
|---|
| 7208 | char *qos_svcs = nvram_safe_get ("svqos_svcs"); |
|---|
| 7209 | char name[32], type[32], data[32], level[32]; |
|---|
| 7210 | int no_svcs = 0, i = 0; |
|---|
| 7211 | |
|---|
| 7212 | // calc # of services |
|---|
| 7213 | // no_svcs = strspn(qos_svcs,"|"); |
|---|
| 7214 | |
|---|
| 7215 | while ((qos_svcs = strpbrk (qos_svcs, "|"))) |
|---|
| 7216 | { |
|---|
| 7217 | no_svcs++; |
|---|
| 7218 | qos_svcs++; |
|---|
| 7219 | } |
|---|
| 7220 | |
|---|
| 7221 | // write HTML data |
|---|
| 7222 | |
|---|
| 7223 | websWrite (wp, |
|---|
| 7224 | "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"svqos_nosvcs\" value=\"%d\" /></td></tr>", |
|---|
| 7225 | no_svcs); |
|---|
| 7226 | |
|---|
| 7227 | qos_svcs = nvram_safe_get ("svqos_svcs"); |
|---|
| 7228 | |
|---|
| 7229 | /* services format is "name type data level | name type data level |" ..etc */ |
|---|
| 7230 | for (i = 0; i < no_svcs && qos_svcs && qos_svcs[0]; i++) |
|---|
| 7231 | { |
|---|
| 7232 | if (sscanf (qos_svcs, "%31s %31s %31s %31s ", name, type, data, level) < |
|---|
| 7233 | 4) |
|---|
| 7234 | break; |
|---|
| 7235 | |
|---|
| 7236 | websWrite (wp, "<tr>\n\ |
|---|
| 7237 | <td>\n\ |
|---|
| 7238 | <input type=\"checkbox\" name=\"svqos_svcdel%d\" />\n\ |
|---|
| 7239 | <input type=\"hidden\" name=\"svqos_svcname%d\" value=\"%s\" />\n\ |
|---|
| 7240 | <input type=\"hidden\" name=\"svqos_svctype%d\" value=\"%s\" />\n\ |
|---|
| 7241 | </td>\n\ |
|---|
| 7242 | <td><em>%s</em></td>\n\ |
|---|
| 7243 | <td >\n", i, i, name, i, type, name); |
|---|
| 7244 | websWrite (wp, "<select name=\"svqos_svcprio%d\"> \n\ |
|---|
| 7245 | <script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"100\\\" %s >\" + qos.prio_x + \"</option>\");\n\ |
|---|
| 7246 | document.write(\"<option value=\\\"10\\\" %s >\" + qos.prio_p + \"</option>\");\n\ |
|---|
| 7247 | document.write(\"<option value=\\\"20\\\" %s >\" + qos.prio_e + \"</option>\");\n\ |
|---|
| 7248 | document.write(\"<option value=\\\"30\\\" %s >\" + share.standard + \"</option>\");\n\ |
|---|
| 7249 | document.write(\"<option value=\\\"40\\\" %s >\" + qos.prio_b + \"</option>\");\n//]]>\n</script>\n\ |
|---|
| 7250 | </select>\n\ |
|---|
| 7251 | </td>\n\ |
|---|
| 7252 | </tr>\n", i, strcmp (level, "100") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "10") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "20") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "30") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "40") == 0 ? "selected=\\\"selected\\\"" : ""); |
|---|
| 7253 | |
|---|
| 7254 | qos_svcs = strpbrk (++qos_svcs, "|"); |
|---|
| 7255 | qos_svcs++; |
|---|
| 7256 | |
|---|
| 7257 | } |
|---|
| 7258 | |
|---|
| 7259 | return; |
|---|
| 7260 | } |
|---|
| 7261 | |
|---|
| 7262 | #ifndef HAVE_AQOS |
|---|
| 7263 | void |
|---|
| 7264 | ej_get_qosips2 (webs_t wp, int argc, char_t ** argv) |
|---|
| 7265 | { |
|---|
| 7266 | char *qos_ips = nvram_safe_get ("svqos_ips"); |
|---|
| 7267 | char ip[32], level[32]; |
|---|
| 7268 | int no_ips = 0, i = 0; |
|---|
| 7269 | |
|---|
| 7270 | // calc # of ips |
|---|
| 7271 | while ((qos_ips = strpbrk (qos_ips, "|"))) |
|---|
| 7272 | { |
|---|
| 7273 | no_ips++; |
|---|
| 7274 | qos_ips++; |
|---|
| 7275 | } |
|---|
| 7276 | websWrite (wp, "<tr>\n\ |
|---|
| 7277 | <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\ |
|---|
| 7278 | <th><script type=\"text/javascript\">Capture(qos.ipmask)</script></th>\n\ |
|---|
| 7279 | <th><script type=\"text/javascript\">Capture(share.priority)</script></th>\n\ |
|---|
| 7280 | </tr>\n"); |
|---|
| 7281 | |
|---|
| 7282 | // write HTML data |
|---|
| 7283 | |
|---|
| 7284 | websWrite (wp, |
|---|
| 7285 | "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"svqos_noips\" value=\"%d\" /></td></tr>", |
|---|
| 7286 | no_ips); |
|---|
| 7287 | |
|---|
| 7288 | qos_ips = nvram_safe_get ("svqos_ips"); |
|---|
| 7289 | |
|---|
| 7290 | /* IP format is "data level | data level |" ..etc */ |
|---|
| 7291 | for (i = 0; i < no_ips && qos_ips && qos_ips[0]; i++) |
|---|
| 7292 | { |
|---|
| 7293 | if (sscanf (qos_ips, "%31s %31s ", ip, level) < 2) |
|---|
| 7294 | break; |
|---|
| 7295 | |
|---|
| 7296 | websWrite (wp, "<tr>\n\ |
|---|
| 7297 | <td>\n\ |
|---|
| 7298 | <input type=\"checkbox\" name=\"svqos_ipdel%d\" />\n\ |
|---|
| 7299 | <input type=\"hidden\" name=\"svqos_ip%d\" value=\"%s\" />\n\ |
|---|
| 7300 | </td>\n\ |
|---|
| 7301 | <td><em>%s</em></td>\n\ |
|---|
| 7302 | <td>\n", i, i, ip, ip); |
|---|
| 7303 | websWrite (wp, "<select name=\"svqos_ipprio%d\"> \n\ |
|---|
| 7304 | <script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"100\\\" %s >\" + qos.prio_x + \"</option>\");\n\ |
|---|
| 7305 | document.write(\"<option value=\\\"10\\\" %s >\" + qos.prio_p + \"</option>\");\n\ |
|---|
| 7306 | document.write(\"<option value=\\\"20\\\" %s >\" + qos.prio_e + \"</option>\");\n\ |
|---|
| 7307 | document.write(\"<option value=\\\"30\\\" %s >\" + share.standard + \"</option>\");\n\ |
|---|
| 7308 | document.write(\"<option value=\\\"40\\\" %s >\" + qos.prio_b + \"</option>\");\n//]]>\n</script>\n\ |
|---|
| 7309 | </select>\n\ |
|---|
| 7310 | </td>\n\ |
|---|
| 7311 | </tr>\n", i, strcmp (level, "100") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "10") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "20") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "30") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "40") == 0 ? "selected=\\\"selected\\\"" : ""); |
|---|
| 7312 | |
|---|
| 7313 | qos_ips = strpbrk (++qos_ips, "|"); |
|---|
| 7314 | qos_ips++; |
|---|
| 7315 | |
|---|
| 7316 | } |
|---|
| 7317 | |
|---|
| 7318 | return; |
|---|
| 7319 | } |
|---|
| 7320 | #else |
|---|
| 7321 | void |
|---|
| 7322 | ej_get_qosips2 (webs_t wp, int argc, char_t ** argv) |
|---|
| 7323 | { |
|---|
| 7324 | char *qos_ips = nvram_safe_get ("svqos_ips"); |
|---|
| 7325 | char ip[32], level[32], level2[32]; |
|---|
| 7326 | int no_ips = 0, i = 0; |
|---|
| 7327 | |
|---|
| 7328 | // calc # of ips |
|---|
| 7329 | while ((qos_ips = strpbrk (qos_ips, "|"))) |
|---|
| 7330 | { |
|---|
| 7331 | no_ips++; |
|---|
| 7332 | qos_ips++; |
|---|
| 7333 | } |
|---|
| 7334 | websWrite (wp, "<tr>\n\ |
|---|
| 7335 | <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\ |
|---|
| 7336 | <th><script type=\"text/javascript\">Capture(qos.ipmask)</script></th>\n\ |
|---|
| 7337 | <th><script type=\"text/javascript\">Capture(qos.maxuprate_b)</script></th>\n\ |
|---|
| 7338 | <th><script type=\"text/javascript\">Capture(qos.maxdownrate_b)</script></th>\n\ |
|---|
| 7339 | </tr>\n"); |
|---|
| 7340 | |
|---|
| 7341 | // write HTML data |
|---|
| 7342 | |
|---|
| 7343 | websWrite (wp, |
|---|
| 7344 | "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"svqos_noips\" value=\"%d\" /></td></tr>", |
|---|
| 7345 | no_ips); |
|---|
| 7346 | |
|---|
| 7347 | qos_ips = nvram_safe_get ("svqos_ips"); |
|---|
| 7348 | |
|---|
| 7349 | /* IP format is "data level | data level |" ..etc */ |
|---|
| 7350 | for (i = 0; i < no_ips && qos_ips && qos_ips[0]; i++) |
|---|
| 7351 | { |
|---|
| 7352 | if (sscanf (qos_ips, "%31s %31s %31s ", ip, level, level2) < 3) |
|---|
| 7353 | break; |
|---|
| 7354 | websWrite (wp, "<tr>\n\ |
|---|
| 7355 | <td>\n\ |
|---|
| 7356 | <input type=\"checkbox\" name=\"svqos_ipdel%d\" />\n\ |
|---|
| 7357 | <input type=\"hidden\" name=\"svqos_ip%d\" value=\"%s\" />\n\ |
|---|
| 7358 | </td>\n\ |
|---|
| 7359 | <td><em>%s</em></td>\n\ |
|---|
| 7360 | <td>\n\ |
|---|
| 7361 | <input name=\"svqos_ipup%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\ |
|---|
| 7362 | </td>\n\ |
|---|
| 7363 | <td>\n\ |
|---|
| 7364 | <input name=\"svqos_ipdown%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\ |
|---|
| 7365 | </td>\n\ |
|---|
| 7366 | </tr>\n", i, i, ip, ip, i, level, i, level2); |
|---|
| 7367 | |
|---|
| 7368 | qos_ips = strpbrk (++qos_ips, "|"); |
|---|
| 7369 | qos_ips++; |
|---|
| 7370 | |
|---|
| 7371 | } |
|---|
| 7372 | |
|---|
| 7373 | return; |
|---|
| 7374 | } |
|---|
| 7375 | #endif |
|---|
| 7376 | #ifndef HAVE_AQOS |
|---|
| 7377 | void |
|---|
| 7378 | ej_get_qosmacs2 (webs_t wp, int argc, char_t ** argv) |
|---|
| 7379 | { |
|---|
| 7380 | char *qos_macs = nvram_safe_get ("svqos_macs"); |
|---|
| 7381 | char mac[32], level[32]; |
|---|
| 7382 | int no_macs = 0, i = 0; |
|---|
| 7383 | |
|---|
| 7384 | |
|---|
| 7385 | // calc # of ips |
|---|
| 7386 | while ((qos_macs = strpbrk (qos_macs, "|"))) |
|---|
| 7387 | { |
|---|
| 7388 | no_macs++; |
|---|
| 7389 | qos_macs++; |
|---|
| 7390 | } |
|---|
| 7391 | |
|---|
| 7392 | websWrite (wp, "<tr>\n\ |
|---|
| 7393 | <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\ |
|---|
| 7394 | <th><script type=\"text/javascript\">Capture(share.mac)</script></th>\n\ |
|---|
| 7395 | <th><script type=\"text/javascript\">Capture(share.priority)</script></th>\n\ |
|---|
| 7396 | </tr>\n"); |
|---|
| 7397 | |
|---|
| 7398 | // write HTML data |
|---|
| 7399 | websWrite (wp, |
|---|
| 7400 | "<input type=\"hidden\" name=\"svqos_nomacs\" value=\"%d\" />", |
|---|
| 7401 | no_macs); |
|---|
| 7402 | |
|---|
| 7403 | qos_macs = nvram_safe_get ("svqos_macs"); |
|---|
| 7404 | |
|---|
| 7405 | /* IP format is "data level | data level |" ..etc */ |
|---|
| 7406 | for (i = 0; i < no_macs && qos_macs && qos_macs[0]; i++) |
|---|
| 7407 | { |
|---|
| 7408 | if (sscanf (qos_macs, "%31s %31s ", mac, level) < 2) |
|---|
| 7409 | break; |
|---|
| 7410 | |
|---|
| 7411 | websWrite (wp, "<tr>\n\ |
|---|
| 7412 | <td>\n\ |
|---|
| 7413 | <input type=\"checkbox\" name=\"svqos_macdel%d\" />\n\ |
|---|
| 7414 | <input type=\"hidden\" name=\"svqos_mac%d\" value=\"%s\" />\n\ |
|---|
| 7415 | </td>\n\ |
|---|
| 7416 | <td><em>%s</em></td>\n\ |
|---|
| 7417 | <td>\n", i, i, mac, mac); |
|---|
| 7418 | websWrite (wp, "<select name=\"svqos_macprio%d\"> \n\ |
|---|
| 7419 | <script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"100\\\" %s >\" + qos.prio_x + \"</option>\");\n\ |
|---|
| 7420 | document.write(\"<option value=\\\"10\\\" %s >\" + qos.prio_p + \"</option>\");\n\ |
|---|
| 7421 | document.write(\"<option value=\\\"20\\\" %s >\" + qos.prio_e + \"</option>\");\n\ |
|---|
| 7422 | document.write(\"<option value=\\\"30\\\" %s >\" + share.standard + \"</option>\");\n\ |
|---|
| 7423 | document.write(\"<option value=\\\"40\\\" %s >\" + qos.prio_b + \"</option>\");\n//]]>\n</script>\n\ |
|---|
| 7424 | </select>\n\ |
|---|
| 7425 | </td>\n\ |
|---|
| 7426 | </tr>\n", i, strcmp (level, "100") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "10") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "20") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "30") == 0 ? "selected=\\\"selected\\\"" : "", strcmp (level, "40") == 0 ? "selected=\\\"selected\\\"" : ""); |
|---|
| 7427 | |
|---|
| 7428 | qos_macs = strpbrk (++qos_macs, "|"); |
|---|
| 7429 | qos_macs++; |
|---|
| 7430 | |
|---|
| 7431 | } |
|---|
| 7432 | |
|---|
| 7433 | return; |
|---|
| 7434 | } |
|---|
| 7435 | |
|---|
| 7436 | #else |
|---|
| 7437 | void |
|---|
| 7438 | ej_get_qosmacs2 (webs_t wp, int argc, char_t ** argv) |
|---|
| 7439 | { |
|---|
| 7440 | char *qos_macs = nvram_safe_get ("svqos_macs"); |
|---|
| 7441 | char mac[32], level[32], level2[32]; |
|---|
| 7442 | int no_macs = 0, i = 0; |
|---|
| 7443 | |
|---|
| 7444 | |
|---|
| 7445 | // calc # of ips |
|---|
| 7446 | while ((qos_macs = strpbrk (qos_macs, "|"))) |
|---|
| 7447 | { |
|---|
| 7448 | no_macs++; |
|---|
| 7449 | qos_macs++; |
|---|
| 7450 | } |
|---|
| 7451 | websWrite (wp, "<tr>\n\ |
|---|
| 7452 | <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\ |
|---|
| 7453 | <th><script type=\"text/javascript\">Capture(share.mac)</script></th>\n\ |
|---|
| 7454 | <th><script type=\"text/javascript\">Capture(qos.maxuprate_b)</script></th>\n\ |
|---|
| 7455 | <th><script type=\"text/javascript\">Capture(qos.maxdownrate_b)</script></th>\n\ |
|---|
| 7456 | </tr>\n"); |
|---|
| 7457 | |
|---|
| 7458 | // write HTML data |
|---|
| 7459 | websWrite (wp, |
|---|
| 7460 | "<input type=\"hidden\" name=\"svqos_nomacs\" value=\"%d\" />", |
|---|
| 7461 | no_macs); |
|---|
| 7462 | |
|---|
| 7463 | qos_macs = nvram_safe_get ("svqos_macs"); |
|---|
| 7464 | |
|---|
| 7465 | /* IP format is "data level | data level |" ..etc */ |
|---|
| 7466 | for (i = 0; i < no_macs && qos_macs && qos_macs[0]; i++) |
|---|
| 7467 | { |
|---|
| 7468 | if (sscanf (qos_macs, "%31s %31s %31s ", mac, level, level2) < 3) |
|---|
| 7469 | break; |
|---|
| 7470 | websWrite (wp, "<tr>\n\ |
|---|
| 7471 | <td>\n\ |
|---|
| 7472 | <input type=\"checkbox\" name=\"svqos_macdel%d\" />\n\ |
|---|
| 7473 | <input type=\"hidden\" name=\"svqos_mac%d\" value=\"%s\" />\n\ |
|---|
| 7474 | </td>\n\ |
|---|
| 7475 | <td><em>%s</em></td>\n\ |
|---|
| 7476 | <td>\n\ |
|---|
| 7477 | <input name=\"svqos_macup%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\ |
|---|
| 7478 | </td>\n\ |
|---|
| 7479 | <td>\n\ |
|---|
| 7480 | <input name=\"svqos_macdown%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\ |
|---|
| 7481 | </td>\n\ |
|---|
| 7482 | </tr>\n", i, i, mac, mac, i, level, i, level2); |
|---|
| 7483 | |
|---|
| 7484 | qos_macs = strpbrk (++qos_macs, "|"); |
|---|
| 7485 | qos_macs++; |
|---|
| 7486 | |
|---|
| 7487 | } |
|---|
| 7488 | |
|---|
| 7489 | return; |
|---|
| 7490 | } |
|---|
| 7491 | #endif |
|---|
| 7492 | |
|---|
| 7493 | |
|---|
| 7494 | |
|---|
| 7495 | /* Added by Botho 03.April.06 */ |
|---|
| 7496 | void |
|---|
| 7497 | ej_dumpip_conntrack (webs_t wp, int argc, char_t ** argv) |
|---|
| 7498 | { |
|---|
| 7499 | int ip_count = 0; |
|---|
| 7500 | FILE *fp; |
|---|
| 7501 | int c; |
|---|
| 7502 | |
|---|
| 7503 | fp = fopen ("/proc/net/ip_conntrack", "rb"); |
|---|
| 7504 | if (fp == NULL) |
|---|
| 7505 | return; |
|---|
| 7506 | while (!feof (fp)) |
|---|
| 7507 | { |
|---|
| 7508 | c = getc (fp); |
|---|
| 7509 | if (c == EOF) |
|---|
| 7510 | break; |
|---|
| 7511 | if (c == 0xa) |
|---|
| 7512 | ip_count++; |
|---|
| 7513 | } |
|---|
| 7514 | |
|---|
| 7515 | websWrite (wp, "%d", ip_count); |
|---|
| 7516 | |
|---|
| 7517 | fclose (fp); |
|---|
| 7518 | |
|---|
| 7519 | return; |
|---|
| 7520 | } |
|---|
| 7521 | |
|---|
| 7522 | /* Added by Botho 28.Oct.06 */ |
|---|
| 7523 | static int |
|---|
| 7524 | search_hit (char *search, char *line, char *ret) |
|---|
| 7525 | { |
|---|
| 7526 | unsigned int searchLen; |
|---|
| 7527 | unsigned int i; |
|---|
| 7528 | unsigned int j; |
|---|
| 7529 | unsigned int lineLen; |
|---|
| 7530 | if (line == NULL || search == NULL || ret == NULL) |
|---|
| 7531 | return 1; |
|---|
| 7532 | lineLen = strlen (line); |
|---|
| 7533 | searchLen = strlen (search); |
|---|
| 7534 | |
|---|
| 7535 | if (searchLen > lineLen) |
|---|
| 7536 | return (1); // this can't match, invalid data? |
|---|
| 7537 | |
|---|
| 7538 | for (i = 0; i < lineLen - searchLen; i++) |
|---|
| 7539 | { |
|---|
| 7540 | if (!strncasecmp ((char *) &line[i], search, searchLen)) |
|---|
| 7541 | break; // we got hit |
|---|
| 7542 | } |
|---|
| 7543 | |
|---|
| 7544 | for (j = i + searchLen; j < i + 15 + searchLen; j++) |
|---|
| 7545 | { |
|---|
| 7546 | if (j >= lineLen) |
|---|
| 7547 | break; // end of line may be a delimiter too |
|---|
| 7548 | // return(1); // incomplete data |
|---|
| 7549 | if (line[j] == ' ') |
|---|
| 7550 | break; // we reach _space_ delimiter |
|---|
| 7551 | } |
|---|
| 7552 | memcpy (ret, &line[i + searchLen], j - (i + searchLen)); |
|---|
| 7553 | ret[j - (i + searchLen)] = 0; |
|---|
| 7554 | return (0); |
|---|
| 7555 | } |
|---|
| 7556 | |
|---|
| 7557 | static int |
|---|
| 7558 | string_search (char *string, char *search) |
|---|
| 7559 | { |
|---|
| 7560 | int searchLen; |
|---|
| 7561 | int i; |
|---|
| 7562 | if (search == NULL) |
|---|
| 7563 | return 0; |
|---|
| 7564 | searchLen = strlen (search); |
|---|
| 7565 | if (string == NULL) |
|---|
| 7566 | return 0; |
|---|
| 7567 | if (searchLen > strlen (string)) |
|---|
| 7568 | { |
|---|
| 7569 | return (0); // this can't match |
|---|
| 7570 | } |
|---|
| 7571 | int slen = strlen (string); |
|---|
| 7572 | for (i = 0; i < slen - searchLen; i++) |
|---|
| 7573 | { //+1 removed. |
|---|
| 7574 | if (!strncasecmp ((char *) &string[i], search, searchLen)) |
|---|
| 7575 | { |
|---|
| 7576 | return (1); // we got hit |
|---|
| 7577 | } |
|---|
| 7578 | } |
|---|
| 7579 | return (0); |
|---|
| 7580 | } |
|---|
| 7581 | |
|---|
| 7582 | |
|---|
| 7583 | void |
|---|
| 7584 | ej_ip_conntrack_table (webs_t wp, int argc, char_t ** argv) |
|---|
| 7585 | { |
|---|
| 7586 | FILE *fp; |
|---|
| 7587 | int ip_count = 1; |
|---|
| 7588 | char line[512]; |
|---|
| 7589 | char protocol[5] = ""; |
|---|
| 7590 | int timeout = 0; |
|---|
| 7591 | char srcip[16] = ""; |
|---|
| 7592 | char dstip[16] = ""; |
|---|
| 7593 | int _dport; |
|---|
| 7594 | struct servent *servp; |
|---|
| 7595 | char dstport[6] = ""; |
|---|
| 7596 | char state[12] = ""; |
|---|
| 7597 | char dum1[32]; |
|---|
| 7598 | int dum2; |
|---|
| 7599 | |
|---|
| 7600 | fp = fopen ("/proc/net/ip_conntrack", "rb"); |
|---|
| 7601 | if (fp == NULL) |
|---|
| 7602 | return; |
|---|
| 7603 | |
|---|
| 7604 | while (fgets (line, sizeof (line), fp) != NULL) |
|---|
| 7605 | { |
|---|
| 7606 | |
|---|
| 7607 | websWrite (wp, "<tr>\n"); |
|---|
| 7608 | |
|---|
| 7609 | // Nb |
|---|
| 7610 | websWrite (wp, "<td align=\"right\">%d</td>", ip_count); |
|---|
| 7611 | |
|---|
| 7612 | // Proto |
|---|
| 7613 | if (string_search (line, "tcp")) |
|---|
| 7614 | sprintf (protocol, "TCP"); |
|---|
| 7615 | else if (string_search (line, "udp")) |
|---|
| 7616 | sprintf (protocol, "UDP"); |
|---|
| 7617 | else if (string_search (line, "icmp")) |
|---|
| 7618 | sprintf (protocol, "ICMP"); |
|---|
| 7619 | else |
|---|
| 7620 | sprintf (protocol, live_translate ("share.unknown")); |
|---|
| 7621 | websWrite (wp, "<td>%s</td>", protocol); |
|---|
| 7622 | |
|---|
| 7623 | // Timeout |
|---|
| 7624 | sscanf (line, "%s %d %d", &dum1[0], &dum2, &timeout); |
|---|
| 7625 | websWrite (wp, "<td align=\"right\">%d</td>", timeout); |
|---|
| 7626 | |
|---|
| 7627 | // src |
|---|
| 7628 | search_hit ("src=", line, srcip); |
|---|
| 7629 | //char buf[200]; |
|---|
| 7630 | //getHostName (buf, srcip); |
|---|
| 7631 | //websWrite (wp, "<td align=\"right\" onmouseover='DisplayDiv(this, event, 15, 15, \"%s\")' onmouseout=\"unDisplayDiv()\">%s</td>", buf != "unknown" ? buf : live_translate ("share.unknown") , srcip); |
|---|
| 7632 | websWrite (wp, "<td align=\"right\">%s</td>", srcip); |
|---|
| 7633 | |
|---|
| 7634 | // dst |
|---|
| 7635 | search_hit ("dst=", line, dstip); |
|---|
| 7636 | //getHostName (buf, dstip); |
|---|
| 7637 | //websWrite (wp, "<td align=\"right\" onmouseover='DisplayDiv(this, event, 15, 15, \"%s\")' onmouseout=\"unDisplayDiv()\">%s</td>", buf != "unknown" ? buf : live_translate ("share.unknown") , dstip); |
|---|
| 7638 | websWrite (wp, "<td align=\"right\">%s</td>", dstip); |
|---|
| 7639 | |
|---|
| 7640 | // service |
|---|
| 7641 | search_hit ("dport=", line, dstport); |
|---|
| 7642 | _dport = atoi (dstport); |
|---|
| 7643 | servp = my_getservbyport (htons (_dport), protocol); |
|---|
| 7644 | websWrite (wp, "<td align=\"right\">%s</td>", |
|---|
| 7645 | servp ? servp->s_name : dstport); |
|---|
| 7646 | |
|---|
| 7647 | // State |
|---|
| 7648 | if (string_search (line, "ESTABLISHED")) |
|---|
| 7649 | sprintf (state, "ESTABLISHED"); |
|---|
| 7650 | else if (string_search (line, "TIME_WAIT")) |
|---|
| 7651 | sprintf (state, "TIME_WAIT"); |
|---|
| 7652 | else if (string_search (line, "UNREPLIED")) |
|---|
| 7653 | sprintf (state, "UNREPLIED"); |
|---|
| 7654 | else if (string_search (line, "CLOSE")) |
|---|
| 7655 | sprintf (state, "CLOSE"); |
|---|
| 7656 | else if (string_search (line, "ASSURED")) |
|---|
| 7657 | sprintf (state, "ASSURED"); |
|---|
| 7658 | else |
|---|
| 7659 | { |
|---|
| 7660 | if (string_search (line, "udp")) |
|---|
| 7661 | sprintf (state, "UNREPLIED"); |
|---|
| 7662 | else |
|---|
| 7663 | sprintf (state, " "); |
|---|
| 7664 | } |
|---|
| 7665 | websWrite (wp, "<td>%s</td>\n", state); |
|---|
| 7666 | websWrite (wp, "</tr>\n"); |
|---|
| 7667 | |
|---|
| 7668 | ip_count++; |
|---|
| 7669 | } |
|---|
| 7670 | |
|---|
| 7671 | fclose (fp); |
|---|
| 7672 | |
|---|
| 7673 | return; |
|---|
| 7674 | } |
|---|
| 7675 | |
|---|
| 7676 | |
|---|
| 7677 | void |
|---|
| 7678 | ej_gethostnamebyip (webs_t wp, int argc, char_t ** argv) |
|---|
| 7679 | { |
|---|
| 7680 | char buf[200]; |
|---|
| 7681 | char *argument; |
|---|
| 7682 | |
|---|
| 7683 | if (ejArgs (argc, argv, "%s", &argument) < 1) |
|---|
| 7684 | { |
|---|
| 7685 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 7686 | return; |
|---|
| 7687 | } |
|---|
| 7688 | |
|---|
| 7689 | if (argc == 1) |
|---|
| 7690 | { |
|---|
| 7691 | getHostName (buf, argument); |
|---|
| 7692 | websWrite (wp, "%s", |
|---|
| 7693 | buf != "unknown" ? buf : live_translate ("share.unknown")); |
|---|
| 7694 | } |
|---|
| 7695 | |
|---|
| 7696 | return; |
|---|
| 7697 | } |
|---|
| 7698 | |
|---|
| 7699 | |
|---|
| 7700 | /* BEGIN Added by Botho 10.May.06 */ |
|---|
| 7701 | void |
|---|
| 7702 | ej_show_wan_to_switch (webs_t wp, int argc, char_t ** argv) |
|---|
| 7703 | { |
|---|
| 7704 | if (!check_vlan_support ()) |
|---|
| 7705 | return; |
|---|
| 7706 | |
|---|
| 7707 | if (nvram_match ("wan_proto", "disabled") || !nvram_match ("wl_mode", "ap")) //WAN disabled OR Wirelles is not AP |
|---|
| 7708 | { |
|---|
| 7709 | websWrite (wp, "<fieldset>\n\ |
|---|
| 7710 | <legend><script type=\"text/javascript\">Capture(idx.legend2)</script></legend>\n\ |
|---|
| 7711 | <div class=\"setting\">\n\ |
|---|
| 7712 | <div class=\"label\"><script type=\"text/javascript\">Capture(idx.wantoswitch)</script></div>\n\ |
|---|
| 7713 | <input class=\"spaceradio\" type=\"checkbox\" name=\"_fullswitch\" value=\"1\" %s />\n\ |
|---|
| 7714 | </div>\n\ |
|---|
| 7715 | </fieldset><br />\n", nvram_match ("fullswitch", "1") ? "checked=\"checked\"" : ""); |
|---|
| 7716 | } |
|---|
| 7717 | |
|---|
| 7718 | return; |
|---|
| 7719 | } |
|---|
| 7720 | |
|---|
| 7721 | #define PROC_DEV "/proc/net/dev" |
|---|
| 7722 | |
|---|
| 7723 | void |
|---|
| 7724 | ej_wl_packet_get (webs_t wp, int argc, char_t ** argv) |
|---|
| 7725 | { |
|---|
| 7726 | char line[256]; |
|---|
| 7727 | FILE *fp; |
|---|
| 7728 | struct dev_info |
|---|
| 7729 | { |
|---|
| 7730 | char ifname[10]; |
|---|
| 7731 | unsigned long rx_bytes; |
|---|
| 7732 | unsigned long rx_pks; |
|---|
| 7733 | unsigned long rx_errs; |
|---|
| 7734 | unsigned long rx_drops; |
|---|
| 7735 | unsigned long rx_fifo; |
|---|
| 7736 | unsigned long rx_frame; |
|---|
| 7737 | unsigned long rx_com; |
|---|
| 7738 | unsigned long rx_mcast; |
|---|
| 7739 | unsigned long tx_bytes; |
|---|
| 7740 | unsigned long tx_pks; |
|---|
| 7741 | unsigned long tx_errs; |
|---|
| 7742 | unsigned long tx_drops; |
|---|
| 7743 | unsigned long tx_fifo; |
|---|
| 7744 | unsigned long tx_colls; |
|---|
| 7745 | unsigned long tx_carr; |
|---|
| 7746 | unsigned long tx_com; |
|---|
| 7747 | } info; |
|---|
| 7748 | |
|---|
| 7749 | info.rx_pks = info.rx_errs = info.rx_drops = 0; |
|---|
| 7750 | info.tx_pks = info.tx_errs = info.tx_drops = info.tx_colls = 0; |
|---|
| 7751 | |
|---|
| 7752 | if ((fp = fopen (PROC_DEV, "r")) == NULL) |
|---|
| 7753 | { |
|---|
| 7754 | websError (wp, 400, "Cann't open %s\n", PROC_DEV); |
|---|
| 7755 | return; |
|---|
| 7756 | } |
|---|
| 7757 | else |
|---|
| 7758 | { |
|---|
| 7759 | /* |
|---|
| 7760 | Inter-| Receive | Transmit |
|---|
| 7761 | face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed |
|---|
| 7762 | lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
|---|
| 7763 | eth0: 674829 5501 0 0 0 0 0 0 1249130 1831 0 0 0 0 0 0 |
|---|
| 7764 | eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
|---|
| 7765 | eth2: 0 0 0 0 0 719 0 0 1974 16 295 0 0 0 0 0 |
|---|
| 7766 | br0: 107114 1078 0 0 0 0 0 0 910094 1304 0 0 0 0 0 0 |
|---|
| 7767 | |
|---|
| 7768 | */ |
|---|
| 7769 | while (fgets (line, sizeof (line), fp) != NULL) |
|---|
| 7770 | { |
|---|
| 7771 | int ifl = 0; |
|---|
| 7772 | if (!strchr (line, ':')) |
|---|
| 7773 | continue; |
|---|
| 7774 | while (line[ifl] != ':') |
|---|
| 7775 | ifl++; |
|---|
| 7776 | line[ifl] = 0; /* interface */ |
|---|
| 7777 | #ifdef HAVE_MADWIFI |
|---|
| 7778 | if (strstr (line, nvram_safe_get ("wifi_display"))) |
|---|
| 7779 | #else |
|---|
| 7780 | if (strstr (line, nvram_safe_get ("wl0_ifname"))) |
|---|
| 7781 | #endif |
|---|
| 7782 | { |
|---|
| 7783 | sscanf (line + ifl + 1, |
|---|
| 7784 | "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", |
|---|
| 7785 | &info.rx_bytes, &info.rx_pks, &info.rx_errs, |
|---|
| 7786 | &info.rx_drops, &info.rx_fifo, &info.rx_frame, |
|---|
| 7787 | &info.rx_com, &info.rx_mcast, &info.tx_bytes, |
|---|
| 7788 | &info.tx_pks, &info.tx_errs, &info.tx_drops, |
|---|
| 7789 | &info.tx_fifo, &info.tx_colls, &info.tx_carr, |
|---|
| 7790 | &info.tx_com); |
|---|
| 7791 | } |
|---|
| 7792 | |
|---|
| 7793 | } |
|---|
| 7794 | fclose (fp); |
|---|
| 7795 | } |
|---|
| 7796 | |
|---|
| 7797 | websWrite (wp, "SWRXgoodPacket=%ld;", info.rx_pks); |
|---|
| 7798 | websWrite (wp, "SWRXerrorPacket=%ld;", info.rx_errs + info.rx_drops); |
|---|
| 7799 | |
|---|
| 7800 | websWrite (wp, "SWTXgoodPacket=%ld;", info.tx_pks); |
|---|
| 7801 | websWrite (wp, "SWTXerrorPacket=%ld;", |
|---|
| 7802 | info.tx_errs + info.tx_drops + info.tx_colls); |
|---|
| 7803 | |
|---|
| 7804 | return; |
|---|
| 7805 | } |
|---|
| 7806 | |
|---|
| 7807 | |
|---|
| 7808 | /* END Added by Botho 10.May.06 */ |
|---|
| 7809 | |
|---|
| 7810 | |
|---|
| 7811 | |
|---|
| 7812 | void |
|---|
| 7813 | do_logout (void) //static functions are not exportable, additionally this is no ej function |
|---|
| 7814 | { |
|---|
| 7815 | send_authenticate (auth_realm); |
|---|
| 7816 | } |
|---|
| 7817 | |
|---|
| 7818 | |
|---|
| 7819 | void |
|---|
| 7820 | ej_statfs (webs_t wp, int argc, char_t ** argv) |
|---|
| 7821 | { |
|---|
| 7822 | struct statfs sizefs; |
|---|
| 7823 | |
|---|
| 7824 | if (argc != 2) |
|---|
| 7825 | return; |
|---|
| 7826 | |
|---|
| 7827 | if ((statfs (argv[0], &sizefs) != 0) || (sizefs.f_type == 0x73717368)) |
|---|
| 7828 | memset (&sizefs, 0, sizeof (sizefs)); |
|---|
| 7829 | |
|---|
| 7830 | websWrite (wp, "var %s = {\n\ |
|---|
| 7831 | size: %llu,\n\ |
|---|
| 7832 | free: %llu\n\ |
|---|
| 7833 | };\n", argv[1], ((uint64_t) sizefs.f_bsize * sizefs.f_blocks), ((uint64_t) sizefs.f_bsize * sizefs.f_bfree)); |
|---|
| 7834 | } |
|---|
| 7835 | |
|---|
| 7836 | #ifdef HAVE_RSTATS |
|---|
| 7837 | /* |
|---|
| 7838 | |
|---|
| 7839 | rstats |
|---|
| 7840 | Copyright (C) 2006 Jonathan Zarate |
|---|
| 7841 | |
|---|
| 7842 | Licensed under GNU GPL v2 or later. |
|---|
| 7843 | |
|---|
| 7844 | */ |
|---|
| 7845 | |
|---|
| 7846 | void |
|---|
| 7847 | ej_bandwidth (webs_t wp, int argc, char_t ** argv) |
|---|
| 7848 | { |
|---|
| 7849 | char *name; |
|---|
| 7850 | int sig; |
|---|
| 7851 | char *argument; |
|---|
| 7852 | |
|---|
| 7853 | if (ejArgs (argc, argv, "%s", &argument) < 1) |
|---|
| 7854 | { |
|---|
| 7855 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 7856 | return; |
|---|
| 7857 | } |
|---|
| 7858 | |
|---|
| 7859 | if (argc == 1) |
|---|
| 7860 | { |
|---|
| 7861 | if (strcmp (argument, "speed") == 0) |
|---|
| 7862 | { |
|---|
| 7863 | sig = SIGUSR1; |
|---|
| 7864 | name = "/var/spool/rstats-speed.js"; |
|---|
| 7865 | } |
|---|
| 7866 | else |
|---|
| 7867 | { |
|---|
| 7868 | sig = SIGUSR2; |
|---|
| 7869 | name = "/var/spool/rstats-history.js"; |
|---|
| 7870 | } |
|---|
| 7871 | unlink (name); |
|---|
| 7872 | killall ("rstats", sig); |
|---|
| 7873 | wait_file_exists (name, 5, 0); |
|---|
| 7874 | do_file (name, wp); |
|---|
| 7875 | unlink (name); |
|---|
| 7876 | } |
|---|
| 7877 | } |
|---|
| 7878 | #endif |
|---|
| 7879 | |
|---|
| 7880 | |
|---|
| 7881 | #ifdef HAVE_PORTSETUP |
|---|
| 7882 | void |
|---|
| 7883 | ej_portsetup (webs_t wp, int argc, char_t ** argv) |
|---|
| 7884 | { |
|---|
| 7885 | char ssid[64]; |
|---|
| 7886 | char *next; |
|---|
| 7887 | char var[64]; |
|---|
| 7888 | char eths[256]; |
|---|
| 7889 | char eths2[256]; |
|---|
| 7890 | #ifdef HAVE_XSCALE |
|---|
| 7891 | if (getifcount ("ixp") == 1 && getifcount ("eth") == 0) |
|---|
| 7892 | return; |
|---|
| 7893 | #else |
|---|
| 7894 | if (getifcount ("eth") == 1) |
|---|
| 7895 | return; |
|---|
| 7896 | #endif |
|---|
| 7897 | websWrite (wp, |
|---|
| 7898 | "<h2><script type=\"text/javascript\">Capture(idx.portsetup)</script></h2>\n"); |
|---|
| 7899 | websWrite (wp, "<fieldset>\n"); |
|---|
| 7900 | websWrite (wp, |
|---|
| 7901 | "<legend><script type=\"text/javascript\">Capture(idx.portsetup)</script></legend>\n"); |
|---|
| 7902 | memset (eths, 0, 256); |
|---|
| 7903 | memset (eths2, 0, 256); |
|---|
| 7904 | #ifdef HAVE_XSCALE |
|---|
| 7905 | getinterfacelist ("eth", eths2); |
|---|
| 7906 | getinterfacelist ("ixp", eths); |
|---|
| 7907 | sprintf (eths, "%s %s", eths, eths2); |
|---|
| 7908 | #else |
|---|
| 7909 | getinterfacelist ("eth", eths); |
|---|
| 7910 | #endif |
|---|
| 7911 | websWrite (wp, |
|---|
| 7912 | "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(idx.wanport)</script></div>\n"); |
|---|
| 7913 | websWrite (wp, "<select name=\"wan_ifname\">\n"); |
|---|
| 7914 | websWrite (wp, "<option value=\"\" %s >Disabled</option>\n", |
|---|
| 7915 | nvram_match ("wan_ifname", "") ? "selected=\"selected\"" : ""); |
|---|
| 7916 | foreach (var, eths, next) |
|---|
| 7917 | { |
|---|
| 7918 | websWrite (wp, "<option value=\"%s\" %s >%s</option>\n", var, |
|---|
| 7919 | nvram_match ("wan_ifname", var) ? "selected=\"selected\"" : "", |
|---|
| 7920 | var); |
|---|
| 7921 | } |
|---|
| 7922 | websWrite (wp, "</select>\n"); |
|---|
| 7923 | |
|---|
| 7924 | foreach (var, eths, next) |
|---|
| 7925 | { |
|---|
| 7926 | if (nvram_match ("wan_ifnames", var)) |
|---|
| 7927 | continue; |
|---|
| 7928 | if (nvram_match ("wan_ifname", var)) |
|---|
| 7929 | continue; |
|---|
| 7930 | sprintf (ssid, "%s_bridged", var); |
|---|
| 7931 | websWrite (wp, |
|---|
| 7932 | "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.network)</script> %s</div>\n", |
|---|
| 7933 | var); |
|---|
| 7934 | websWrite (wp, |
|---|
| 7935 | "<input class=\"spaceradio\" type=\"radio\" value=\"0\" onclick=\"show_layer_ext(this, '%s_idnet', true);\" name=\"%s_bridged\" %s /><script type=\"text/javascript\">Capture(wl_basic.unbridged)</script> \n", |
|---|
| 7936 | var, var, nvram_match (ssid, |
|---|
| 7937 | "0") ? "checked=\"checked\"" : ""); |
|---|
| 7938 | websWrite (wp, |
|---|
| 7939 | "<input class=\"spaceradio\" type=\"radio\" value=\"1\" onclick=\"show_layer_ext(this, '%s_idnet', false);\" name=\"%s_bridged\" %s /><script type=\"text/javascript\">Capture(wl_basic.bridged)</script>\n", |
|---|
| 7940 | var, var, nvram_match (ssid, |
|---|
| 7941 | "1") ? "checked=\"checked\"" : ""); |
|---|
| 7942 | websWrite (wp, "</div>\n"); |
|---|
| 7943 | |
|---|
| 7944 | websWrite (wp, "<div id=\"%s_idnet\">\n", var); |
|---|
| 7945 | show_ipnetmask (wp, var); |
|---|
| 7946 | websWrite (wp, "</div>\n"); |
|---|
| 7947 | websWrite (wp, "<script>\n//<![CDATA[\n "); |
|---|
| 7948 | websWrite (wp, |
|---|
| 7949 | "show_layer_ext(document.getElementsByName(\"%s_bridged\"), \"%s_idnet\", %s);\n", |
|---|
| 7950 | var, var, nvram_match (ssid, "0") ? "true" : "false"); |
|---|
| 7951 | websWrite (wp, "//]]>\n</script>\n"); |
|---|
| 7952 | } |
|---|
| 7953 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 7954 | } |
|---|
| 7955 | #endif |
|---|
| 7956 | |
|---|
| 7957 | static void |
|---|
| 7958 | show_macfilter_if (webs_t wp, char *ifname) |
|---|
| 7959 | { |
|---|
| 7960 | websWrite (wp, "<fieldset>\n"); |
|---|
| 7961 | websWrite (wp, "<legend>%s - %s</legend>\n", ifname, |
|---|
| 7962 | live_translate ("wl_mac.legend")); |
|---|
| 7963 | websWrite (wp, "<div class=\"setting\">\n"); |
|---|
| 7964 | websWrite (wp, "<div class=\"label\">%s</div>\n", |
|---|
| 7965 | live_translate ("wl_mac.label")); |
|---|
| 7966 | char macmode[32]; |
|---|
| 7967 | sprintf (macmode, "%s_macmode1", ifname); |
|---|
| 7968 | rep (macmode, '.', 'X'); |
|---|
| 7969 | if (nvram_get (macmode) == NULL) |
|---|
| 7970 | nvram_set (macmode, "disabled"); |
|---|
| 7971 | char id[32]; |
|---|
| 7972 | sprintf (id, "idmac%s", ifname); |
|---|
| 7973 | rep (id, '.', 'X'); |
|---|
| 7974 | char mycopy[256]; |
|---|
| 7975 | strcpy (mycopy, live_translate ("share.enable")); |
|---|
| 7976 | websWrite (wp, |
|---|
| 7977 | "<input class=\"spaceradio\" type=\"radio\" value=\"other\" name=\"%s\" %s onclick=\"show_layer_ext(this, '%s', true)\" />%s \n", |
|---|
| 7978 | macmode, nvram_match (macmode, |
|---|
| 7979 | "other") ? "checked=\"checked\"" : "", id, |
|---|
| 7980 | mycopy); |
|---|
| 7981 | strcpy (mycopy, live_translate ("share.disable")); |
|---|
| 7982 | websWrite (wp, |
|---|
| 7983 | "<input class=\"spaceradio\" type=\"radio\" value=\"disabled\" name=\"%s\" %s onclick=\"show_layer_ext(this, '%s', false)\" />%s\n", |
|---|
| 7984 | macmode, nvram_match (macmode, |
|---|
| 7985 | "disabled") ? "checked=\"checked\"" : "", |
|---|
| 7986 | id, mycopy); |
|---|
| 7987 | websWrite (wp, "</div>\n"); |
|---|
| 7988 | websWrite (wp, "<div class=\"setting\" id=\"%s\">\n", id); |
|---|
| 7989 | websWrite (wp, "<div class=\"label\">%s<br /> </div>\n", |
|---|
| 7990 | live_translate ("wl_mac.label2")); |
|---|
| 7991 | sprintf (macmode, "%s_macmode", ifname); |
|---|
| 7992 | if (nvram_get (macmode) == NULL) |
|---|
| 7993 | nvram_set (macmode, "disabled"); |
|---|
| 7994 | strcpy (mycopy, live_translate ("wl_mac.deny")); |
|---|
| 7995 | websWrite (wp, |
|---|
| 7996 | "<input class=\"spaceradio\" type=\"radio\" value=\"deny\" name=\"%s\" %s />%s \n", |
|---|
| 7997 | macmode, nvram_invmatch (macmode, |
|---|
| 7998 | "allow") ? "checked=\"checked\"" : "", |
|---|
| 7999 | mycopy); |
|---|
| 8000 | websWrite (wp, "<br />\n"); |
|---|
| 8001 | strcpy (mycopy, live_translate ("wl_mac.allow")); |
|---|
| 8002 | websWrite (wp, |
|---|
| 8003 | "<input class=\"spaceradio\" type=\"radio\" value=\"allow\" name=\"%s\" %s />%s\n", |
|---|
| 8004 | macmode, nvram_match (macmode, |
|---|
| 8005 | "allow") ? "checked=\"checked\"" : "", |
|---|
| 8006 | mycopy); |
|---|
| 8007 | websWrite (wp, "</div><br />\n"); |
|---|
| 8008 | websWrite (wp, "<div class=\"center\">\n"); |
|---|
| 8009 | websWrite (wp, "<script type=\"text/javascript\">\n"); |
|---|
| 8010 | websWrite (wp, "//<![CDATA[\n"); |
|---|
| 8011 | websWrite (wp, |
|---|
| 8012 | "document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" name=\\\"mac_filter_button\\\" value=\\\"\" + sbutton.filterMac + \"\\\" onclick=\\\"openWindow('WL_FilterTable-%s.asp', 930, 740,'MACList');\\\" />\");\n", |
|---|
| 8013 | ifname); |
|---|
| 8014 | websWrite (wp, "//]]>\n"); |
|---|
| 8015 | websWrite (wp, "</script>\n"); |
|---|
| 8016 | websWrite (wp, "</div>\n"); |
|---|
| 8017 | websWrite (wp, "</fieldset><br />\n"); |
|---|
| 8018 | } |
|---|
| 8019 | |
|---|
| 8020 | void |
|---|
| 8021 | ej_list_mac_layers (webs_t wp, int argc, char_t ** argv) |
|---|
| 8022 | { |
|---|
| 8023 | #ifndef HAVE_MADWIFI |
|---|
| 8024 | websWrite (wp, |
|---|
| 8025 | "show_layer_ext(document.wireless.wl_macmode1, 'idmacwl', \"%s\" == \"other\");\n", |
|---|
| 8026 | nvram_match ("wl_macmode1", "other") ? "other" : "disabled"); |
|---|
| 8027 | |
|---|
| 8028 | #else |
|---|
| 8029 | |
|---|
| 8030 | int c = getdevicecount (); |
|---|
| 8031 | char devs[32]; |
|---|
| 8032 | int i; |
|---|
| 8033 | for (i = 0; i < c; i++) |
|---|
| 8034 | { |
|---|
| 8035 | char macmode[32]; |
|---|
| 8036 | char id[32]; |
|---|
| 8037 | sprintf (devs, "ath%d", i); |
|---|
| 8038 | sprintf (macmode, "%s_macmode1", devs); |
|---|
| 8039 | sprintf (id, "idmac%s", devs); |
|---|
| 8040 | rep (id, '.', 'X'); |
|---|
| 8041 | rep (macmode, '.', 'X'); |
|---|
| 8042 | websWrite (wp, |
|---|
| 8043 | "show_layer_ext(document.wireless.%s, '%s', \"%s\" == \"other\");\n", |
|---|
| 8044 | macmode, id, nvram_match (macmode, |
|---|
| 8045 | "other") ? "other" : "disabled"); |
|---|
| 8046 | //show_macfilter_if (wp, devs); |
|---|
| 8047 | char vif[32]; |
|---|
| 8048 | sprintf (vif, "%s_vifs", devs); |
|---|
| 8049 | char var[80], *next; |
|---|
| 8050 | char *vifs = nvram_safe_get (vif); |
|---|
| 8051 | if (vifs != NULL) |
|---|
| 8052 | foreach (var, vifs, next) |
|---|
| 8053 | { |
|---|
| 8054 | sprintf (macmode, "%s_macmode1", var); |
|---|
| 8055 | sprintf (id, "idmac%s", var); |
|---|
| 8056 | rep (id, '.', 'X'); |
|---|
| 8057 | rep (macmode, '.', 'X'); |
|---|
| 8058 | websWrite (wp, |
|---|
| 8059 | "show_layer_ext(document.wireless.%s, '%s', \"%s\" == \"other\");\n", |
|---|
| 8060 | macmode, id, nvram_match (macmode, |
|---|
| 8061 | "other") ? "other" : |
|---|
| 8062 | "disabled"); |
|---|
| 8063 | } |
|---|
| 8064 | } |
|---|
| 8065 | |
|---|
| 8066 | |
|---|
| 8067 | #endif |
|---|
| 8068 | } |
|---|
| 8069 | void |
|---|
| 8070 | ej_show_macfilter (webs_t wp, int argc, char_t ** argv) |
|---|
| 8071 | { |
|---|
| 8072 | #ifndef HAVE_MADWIFI |
|---|
| 8073 | show_macfilter_if (wp, "wl"); |
|---|
| 8074 | #else |
|---|
| 8075 | int c = getdevicecount (); |
|---|
| 8076 | char devs[32]; |
|---|
| 8077 | int i; |
|---|
| 8078 | for (i = 0; i < c; i++) |
|---|
| 8079 | { |
|---|
| 8080 | sprintf (devs, "ath%d", i); |
|---|
| 8081 | show_macfilter_if (wp, devs); |
|---|
| 8082 | char vif[32]; |
|---|
| 8083 | sprintf (vif, "%s_vifs", devs); |
|---|
| 8084 | char var[80], *next; |
|---|
| 8085 | char *vifs = nvram_safe_get (vif); |
|---|
| 8086 | if (vifs != NULL) |
|---|
| 8087 | foreach (var, vifs, next) |
|---|
| 8088 | { |
|---|
| 8089 | show_macfilter_if (wp, var); |
|---|
| 8090 | } |
|---|
| 8091 | } |
|---|
| 8092 | |
|---|
| 8093 | #endif |
|---|
| 8094 | } |
|---|
| 8095 | |
|---|
| 8096 | |
|---|
| 8097 | |
|---|
| 8098 | //and now the tricky part (more dirty as dirty) |
|---|
| 8099 | void |
|---|
| 8100 | do_filtertable (char *path, webs_t stream) |
|---|
| 8101 | { |
|---|
| 8102 | char *temp2 = &path[indexof (path, '-') + 1]; |
|---|
| 8103 | char ifname[16]; |
|---|
| 8104 | strcpy (ifname, temp2); |
|---|
| 8105 | ifname[indexof (ifname, '.')] = 0; |
|---|
| 8106 | FILE *web = getWebsFile ("WL_FilterTable.asp"); |
|---|
| 8107 | char temp[4096]; |
|---|
| 8108 | memset (temp, 0, 4096); |
|---|
| 8109 | unsigned int len = getWebsFileLen ("WL_FilterTable.asp"); |
|---|
| 8110 | char *webfile = (char *) malloc (len + 1); |
|---|
| 8111 | fread (webfile, len, 1, web); |
|---|
| 8112 | webfile[len] = 0; |
|---|
| 8113 | sprintf (temp, webfile, ifname, ifname, ifname, ifname); |
|---|
| 8114 | free (webfile); |
|---|
| 8115 | fclose (web); |
|---|
| 8116 | do_ej_buffer (temp, stream); |
|---|
| 8117 | } |
|---|
| 8118 | |
|---|
| 8119 | void |
|---|
| 8120 | do_wds (char *path, webs_t stream) |
|---|
| 8121 | { |
|---|
| 8122 | char *temp2 = &path[indexof (path, '-') + 1]; |
|---|
| 8123 | char ifname[16]; |
|---|
| 8124 | strcpy (ifname, temp2); |
|---|
| 8125 | ifname[indexof (ifname, '.')] = 0; |
|---|
| 8126 | FILE *web = getWebsFile ("Wireless_WDS.asp"); |
|---|
| 8127 | unsigned int len = getWebsFileLen ("Wireless_WDS.asp"); |
|---|
| 8128 | char *webfile = (char *) malloc (len + 1); |
|---|
| 8129 | fread (webfile, len, 1, web); |
|---|
| 8130 | webfile[len] = 0; |
|---|
| 8131 | fclose (web); |
|---|
| 8132 | |
|---|
| 8133 | char temp[32768]; |
|---|
| 8134 | memset (temp, 0, 32768); |
|---|
| 8135 | int ai = 0; |
|---|
| 8136 | int i = 0; |
|---|
| 8137 | int weblen = strlen (webfile); |
|---|
| 8138 | for (i = 0; i < weblen; i++) |
|---|
| 8139 | { |
|---|
| 8140 | if (webfile[i] == '%') |
|---|
| 8141 | { |
|---|
| 8142 | i++; |
|---|
| 8143 | switch (webfile[i]) |
|---|
| 8144 | { |
|---|
| 8145 | case '%': |
|---|
| 8146 | temp[ai++] = '%'; |
|---|
| 8147 | break; |
|---|
| 8148 | case 's': |
|---|
| 8149 | strcpy (&temp[ai], ifname); |
|---|
| 8150 | ai += strlen (ifname); |
|---|
| 8151 | break; |
|---|
| 8152 | default: |
|---|
| 8153 | temp[ai++] = webfile[i]; |
|---|
| 8154 | break; |
|---|
| 8155 | } |
|---|
| 8156 | } |
|---|
| 8157 | else |
|---|
| 8158 | temp[ai++] = webfile[i]; |
|---|
| 8159 | } |
|---|
| 8160 | free (webfile); |
|---|
| 8161 | do_ej_buffer (temp, stream); |
|---|
| 8162 | } |
|---|
| 8163 | |
|---|
| 8164 | static void |
|---|
| 8165 | save_macmode_if (webs_t wp, char *ifname) |
|---|
| 8166 | { |
|---|
| 8167 | |
|---|
| 8168 | char macmode[32]; |
|---|
| 8169 | char macmode1[32]; |
|---|
| 8170 | sprintf (macmode, "%s_macmode", ifname); |
|---|
| 8171 | sprintf (macmode1, "%s_macmode1", ifname); |
|---|
| 8172 | rep (macmode1, '.', 'X'); |
|---|
| 8173 | char *wl_macmode1, *wl_macmode; |
|---|
| 8174 | wl_macmode = websGetVar (wp, macmode, NULL); |
|---|
| 8175 | wl_macmode1 = websGetVar (wp, macmode1, NULL); |
|---|
| 8176 | |
|---|
| 8177 | if (!wl_macmode1) |
|---|
| 8178 | return; |
|---|
| 8179 | |
|---|
| 8180 | if (!strcmp (wl_macmode1, "disabled")) |
|---|
| 8181 | { |
|---|
| 8182 | nvram_set (macmode1, "disabled"); |
|---|
| 8183 | nvram_set (macmode, "disabled"); |
|---|
| 8184 | } |
|---|
| 8185 | else if (!strcmp (wl_macmode1, "other")) |
|---|
| 8186 | { |
|---|
| 8187 | if (!wl_macmode) |
|---|
| 8188 | nvram_set (macmode, "deny"); |
|---|
| 8189 | else |
|---|
| 8190 | nvram_set (macmode, wl_macmode); |
|---|
| 8191 | nvram_set (macmode1, "other"); |
|---|
| 8192 | } |
|---|
| 8193 | } |
|---|
| 8194 | |
|---|
| 8195 | |
|---|
| 8196 | void |
|---|
| 8197 | save_macmode (webs_t wp) |
|---|
| 8198 | { |
|---|
| 8199 | #ifndef HAVE_MADWIFI |
|---|
| 8200 | save_macmode_if (wp, "wl"); |
|---|
| 8201 | #else |
|---|
| 8202 | int c = getdevicecount (); |
|---|
| 8203 | char devs[32]; |
|---|
| 8204 | int i; |
|---|
| 8205 | for (i = 0; i < c; i++) |
|---|
| 8206 | { |
|---|
| 8207 | sprintf (devs, "ath%d", i); |
|---|
| 8208 | save_macmode_if (wp, devs); |
|---|
| 8209 | char vif[32]; |
|---|
| 8210 | sprintf (vif, "%s_vifs", devs); |
|---|
| 8211 | char var[80], *next; |
|---|
| 8212 | char *vifs = nvram_safe_get (vif); |
|---|
| 8213 | if (vifs != NULL) |
|---|
| 8214 | foreach (var, vifs, next) |
|---|
| 8215 | { |
|---|
| 8216 | save_macmode_if (wp, var); |
|---|
| 8217 | } |
|---|
| 8218 | } |
|---|
| 8219 | |
|---|
| 8220 | #endif |
|---|
| 8221 | return; |
|---|
| 8222 | |
|---|
| 8223 | } |
|---|