source: src/router/httpd/visuals/dd-wrt.c @ 10839

Last change on this file since 10839 was 10839, checked in by BrainSlayer, 5 years ago

quick hack for variable frequency offset

File size: 229.3 KB
Line 
1#define VISUALSOURCE 1
2/*
3 * dd-wrt.c
4 *
5 * Copyright (C) 2005 - 2007 Sebastian Gottschall <sebastian.gottschall@newmedia-net.de>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * $Id:
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <stdarg.h>
27#include <string.h>
28#include <unistd.h>
29#include <ctype.h>
30#include <signal.h>
31
32#include <sys/ioctl.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <sys/socket.h>
36#include <sys/statfs.h>
37#include <netinet/in.h>
38#include <arpa/inet.h>
39#include <broadcom.h>
40#include <cymac.h>
41#include <wlutils.h>
42#include <bcmparams.h>
43#include <dirent.h>
44#include <netdb.h>
45#include <utils.h>
46#include <wlutils.h>
47#include <bcmnvram.h>
48#include <l7protocols.h>
49
50#ifdef HAVE_OVERCLOCKING
51static unsigned int type3_clocks[3] = { 150, 200, 0 };
52static unsigned int type4_clocks[10] =
53    { 192, 200, 216, 228, 240, 252, 264, 280, 300, 0 };
54static unsigned int type7_clocks[10] =
55    { 183, 187, 198, 200, 216, 225, 233, 237, 250, 0 };
56#endif
57
58
59#ifdef HAVE_RT2880
60#define IFMAP(a) getRADev(a)
61#else
62#define IFMAP(a) (a)
63#endif
64
65void show_ipnetmask( webs_t wp, char *var )
66{
67    websWrite( wp, "<div class=\"setting\">\n" );
68    websWrite( wp,
69               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n" );
70
71    char *ipv = nvram_nget( "%s_ipaddr", var );
72
73    websWrite( wp,
74               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,1,223,share.ip)\" name=\"%s_ipaddr_0\" value=\"%d\" />.",
75               var, get_single_ip( ipv, 0 ) );
76    websWrite( wp,
77               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_1\" value=\"%d\" />.",
78               var, get_single_ip( ipv, 1 ) );
79    websWrite( wp,
80               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_2\" value=\"%d\" />.",
81               var, get_single_ip( ipv, 2 ) );
82    websWrite( wp,
83               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_3\" value=\"%d\" />\n",
84               var, get_single_ip( ipv, 3 ) );
85    websWrite( wp, "</div>\n" );
86
87    websWrite( wp, "<div class=\"setting\">\n" );
88    websWrite( wp,
89               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n" );
90    ipv = nvram_nget( "%s_netmask", var );
91
92    websWrite( wp,
93               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_0\" value=\"%d\" />.",
94               var, get_single_ip( ipv, 0 ) );
95    websWrite( wp,
96               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_1\" value=\"%d\" />.",
97               var, get_single_ip( ipv, 1 ) );
98    websWrite( wp,
99               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_2\" value=\"%d\" />.",
100               var, get_single_ip( ipv, 2 ) );
101    websWrite( wp,
102               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_3\" value=\"%d\" />",
103               var, get_single_ip( ipv, 3 ) );
104    websWrite( wp, "</div>\n<br />\n" );
105
106}
107
108#ifdef HAVE_OVERCLOCKING
109void ej_show_clocks( webs_t wp, int argc, char_t ** argv )
110{
111    int tab = cpu_plltype(  );
112    unsigned int *c;
113
114    if( tab == 3 )
115        c = type3_clocks;
116    else if( tab == 4 )
117        c = type4_clocks;
118    else if( tab == 7 )
119        c = type7_clocks;
120    else
121    {
122        websWrite( wp,
123                   "<script type=\"text/javascript\">Capture(management.clock_support)</script>\n</div>\n" );
124        return;
125    }
126
127    websWrite( wp,
128               "<div class=\"label\"><script type=\"text/javascript\">Capture(management.clock_frq)</script></div>\n" );
129    websWrite( wp, "<select name=\"overclocking\">\n" );
130
131    int i = 0;
132    char clock[16];
133
134    while( c[i] != 0 )
135    {
136        sprintf( clock, "%d", c[i] );
137        websWrite( wp, "<option value=\"%d\" %s >%d MHz</option>\n", c[i],
138                   nvram_match( "overclocking",
139                                clock ) ? "selected=\"selected\"" : "",
140                   c[i] );
141        i++;
142    }
143    websWrite( wp, "</select>\n</div>\n" );
144}
145#endif
146
147void ej_show_routing( webs_t wp, int argc, char_t ** argv )
148{
149    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
150    websWrite( wp,
151               "document.write(\"<option value=\\\"gateway\\\" %s >\" + share.gateway + \"</option>\");\n",
152               nvram_selmatch( wp, "wk_mode",
153                               "gateway" ) ? "selected=\\\"selected\\\"" :
154               "" );
155#ifdef HAVE_BIRD
156    websWrite( wp,
157               "document.write(\"<option value=\\\"bgp\\\" %s >BGP</option>\");\n",
158               nvram_selmatch( wp, "wk_mode",
159                               "bgp" ) ? "selected=\\\"selected\\\"" : "" );
160    websWrite( wp,
161               "document.write(\"<option value=\\\"router\\\" %s >\" + route.rip2_mod + \"</option>\");\n",
162               nvram_selmatch( wp, "wk_mode",
163                               "router" ) ? "selected=\\\"selected\\\"" :
164               "" );
165#endif
166#ifdef HAVE_QUAGGA
167    websWrite( wp,
168               "document.write(\"<option value=\\\"bgp\\\" %s >BGP</option>\");\n",
169               nvram_selmatch( wp, "wk_mode",
170                               "bgp" ) ? "selected=\\\"selected\\\"" : "" );
171    websWrite( wp,
172               "document.write(\"<option value=\\\"router\\\" %s >\" + route.rip2_mod + \"</option>\");\n",
173               nvram_selmatch( wp, "wk_mode",
174                               "router" ) ? "selected=\\\"selected\\\"" :
175               "" );
176    websWrite( wp,
177               "document.write(\"<option value=\\\"ospf\\\" %s >\" + route.ospf_mod + \"</option>\");\n",
178               nvram_selmatch( wp, "wk_mode",
179                               "ospf" ) ? "selected=\\\"selected\\\"" : "" );
180#endif
181#ifdef HAVE_OLSRD
182    websWrite( wp,
183               "document.write(\"<option value=\\\"olsr\\\" %s >\" + route.olsrd_mod + \"</option>\");\n",
184               nvram_selmatch( wp, "wk_mode",
185                               "olsr" ) ? "selected=\\\"selected\\\"" : "" );
186#endif
187    websWrite( wp,
188               "document.write(\"<option value=\\\"static\\\" %s >\" + share.router + \"</option>\");\n",
189               nvram_selmatch( wp, "wk_mode",
190                               "static" ) ? "selected=\\\"selected\\\"" :
191               "" );
192    websWrite( wp, "//]]>\n</script>\n" );
193    return;
194
195}
196
197void ej_show_connectiontype( webs_t wp, int argc, char_t ** argv )
198{
199
200    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
201    websWrite( wp,
202               "document.write(\"<option value=\\\"disabled\\\" %s >\" + share.disabled + \"</option>\");\n",
203               nvram_selmatch( wp, "wan_proto",
204                               "disabled" ) ? "selected=\\\"selected\\\"" :
205               "" );
206    websWrite( wp,
207               "document.write(\"<option value=\\\"static\\\" %s >\" + idx.static_ip + \"</option>\");\n",
208               nvram_selmatch( wp, "wan_proto",
209                               "static" ) ? "selected=\\\"selected\\\"" :
210               "" );
211    websWrite( wp,
212               "document.write(\"<option value=\\\"dhcp\\\" %s >\" + idx.dhcp + \"</option>\");\n",
213               nvram_selmatch( wp, "wan_proto",
214                               "dhcp" ) ? "selected=\\\"selected\\\"" : "" );
215    websWrite( wp, "\n//]]>\n</script>\n" );
216
217#ifdef HAVE_PPPOE
218    websWrite( wp, "<option value=\"pppoe\" %s >PPPoE</option>\n",
219               nvram_selmatch( wp, "wan_proto",
220                               "pppoe" ) ? "selected=\"selected\"" : "" );
221#endif
222#ifdef HAVE_PPTP
223    websWrite( wp, "<option value=\"pptp\" %s >PPTP</option>\n",
224               nvram_selmatch( wp, "wan_proto",
225                               "pptp" ) ? "selected=\"selected\"" : "" );
226#endif
227#ifdef HAVE_L2TP
228    websWrite( wp, "<option value=\"l2tp\" %s >L2TP</option>\n",
229               nvram_selmatch( wp, "wan_proto",
230                               "l2tp" ) ? "selected=\"selected\"" : "" );
231#endif
232#ifdef HAVE_HEARTBEAT
233    websWrite( wp,
234               "<option value=\"heartbeat\" %s >HeartBeat Signal</option>\n",
235               nvram_selmatch( wp, "wan_proto",
236                               "heartbeat" ) ? "selected=\"selected\"" : "" );
237#endif
238
239    return;
240}
241
242void ej_show_infopage( webs_t wp, int argc, char_t ** argv )
243{
244    /*
245     * #ifdef HAVE_NEWMEDIA websWrite(wp,"<dl>\n"); websWrite(wp,"<dd
246     * class=\"definition\">GGEW net GmbH</dd>\n"); websWrite(wp,"<dd
247     * class=\"definition\">Dammstrasse 68</dd>\n"); websWrite(wp,"<dd
248     * class=\"definition\">64625 Bensheim</dd>\n"); websWrite(wp,"<dd
249     * class=\"definition\"><a href=\"http://ggew-net.de\"><img
250     * src=\"images/ggewlogo.gif\" border=\"0\"/></a></dd>\n");
251     * websWrite(wp,"<dd class=\"definition\"> </dd>\n"); websWrite(wp,"<dd
252     * class=\"definition\"><a href=\"http://ggew-net.de\"/></dd>\n");
253     * websWrite(wp,"<dd class=\"definition\"> </dd>\n"); websWrite(wp,"<dd
254     * class=\"definition\">In Kooperation mit NewMedia-NET GmbH</dd>\n");
255     * websWrite(wp,"<dd class=\"definition\"><a
256     * href=\"http://www.newmedia-net.de\"/></dd>\n");
257     * websWrite(wp,"</dl>\n"); #endif
258     */
259    return;
260}
261
262void ej_dumpmeminfo( webs_t wp, int argc, char_t ** argv )
263{
264    FILE *fcpu = fopen( "/proc/meminfo", "r" );
265
266    if( fcpu == NULL )
267    {
268        return;
269    }
270    char buf[128];
271    int n = 0;
272
273  rept:;
274    if( n == EOF )
275    {
276        fclose( fcpu );
277        return;
278    }
279    if( n )
280        websWrite( wp, "'%s'", buf );
281    n = fscanf( fcpu, "%s", buf );
282    if( n != EOF )
283        websWrite( wp, "," );
284    goto rept;
285}
286
287#ifdef HAVE_RB500
288void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
289{
290    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
291
292    if( fp == NULL )
293    {
294        websWrite( wp, "unknown" );
295        return;
296    }
297    int cnt = 0;
298    int b = 0;
299
300    while( b != EOF )
301    {
302        b = getc( fp );
303        if( b == ':' )
304            cnt++;
305
306        if( cnt == 4 )
307        {
308            getc( fp );
309            char cpuclk[4];
310
311            cpuclk[0] = getc( fp );
312            cpuclk[1] = getc( fp );
313            cpuclk[2] = getc( fp );
314            cpuclk[3] = 0;
315            websWrite( wp, cpuclk );
316            fclose( fp );
317            return;
318        }
319    }
320
321    fclose( fp );
322    websWrite( wp, "unknown" );
323    return;
324}
325
326#elif HAVE_STORM
327void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
328{
329    websWrite( wp, "300" );
330    /*
331     * FILE *fp = fopen ("/proc/cpuinfo", "rb"); if (fp == NULL) { websWrite
332     * (wp, "unknown"); return; } int cnt = 0; int b = 0; while (b != EOF) {
333     * b = getc (fp); if (b == ':') cnt++; if (cnt == 2) { getc (fp); char
334     * cpuclk[4]; cpuclk[0] = getc (fp); cpuclk[1] = getc (fp); cpuclk[2] =
335     * getc (fp); cpuclk[3] = 0; websWrite (wp, cpuclk); fclose (fp); return;
336     * } }
337     *
338     * fclose (fp); websWrite (wp, "unknown");
339     */
340    return;
341}
342#elif HAVE_RT2880
343void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
344{
345    websWrite( wp, "384" );
346    /*
347     * FILE *fp = fopen ("/proc/cpuinfo", "rb"); if (fp == NULL) { websWrite
348     * (wp, "unknown"); return; } int cnt = 0; int b = 0; while (b != EOF) {
349     * b = getc (fp); if (b == ':') cnt++; if (cnt == 2) { getc (fp); char
350     * cpuclk[4]; cpuclk[0] = getc (fp); cpuclk[1] = getc (fp); cpuclk[2] =
351     * getc (fp); cpuclk[3] = 0; websWrite (wp, cpuclk); fclose (fp); return;
352     * } }
353     *
354     * fclose (fp); websWrite (wp, "unknown");
355     */
356    return;
357}
358#elif HAVE_XSCALE
359void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
360{
361    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
362
363    if( fp == NULL )
364    {
365        websWrite( wp, "unknown" );
366        return;
367    }
368    int cnt = 0;
369    int b = 0;
370
371    while( b != EOF )
372    {
373        b = getc( fp );
374        if( b == ':' )
375            cnt++;
376        if( cnt == 2 )
377        {
378            getc( fp );
379            char cpuclk[4];
380
381            cpuclk[0] = getc( fp );
382            cpuclk[1] = getc( fp );
383            cpuclk[2] = getc( fp );
384            cpuclk[3] = 0;
385            websWrite( wp, cpuclk );
386            fclose( fp );
387            return;
388        }
389    }
390
391    fclose( fp );
392    websWrite( wp, "unknown" );
393    return;
394}
395#elif HAVE_X86
396void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
397{
398    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
399
400    if( fp == NULL )
401    {
402        websWrite( wp, "unknown" );
403        return;
404    }
405    int cnt = 0;
406    int b = 0;
407
408    while( b != EOF )
409    {
410        b = getc( fp );
411        if( b == ':' )
412            cnt++;
413        if( cnt == 7 )
414        {
415            getc( fp );
416            char cpuclk[32];
417            int i = 0;
418
419            b = getc( fp );
420            while( b != 0xa && b != 0xd && b != 0x20 )
421            {
422                cpuclk[i++] = b;
423                b = getc( fp );
424            }
425            cpuclk[i++] = 0;
426            websWrite( wp, cpuclk );
427            fclose( fp );
428            return;
429        }
430    }
431
432    fclose( fp );
433    websWrite( wp, "unknown" );
434    return;
435}
436#elif HAVE_MAGICBOX
437void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
438{
439    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
440
441    if( fp == NULL )
442    {
443        websWrite( wp, "unknown" );
444        return;
445    }
446    int cnt = 0;
447    int b = 0;
448
449    while( b != EOF )
450    {
451        b = getc( fp );
452        if( b == ':' )
453            cnt++;
454        if( cnt == 3 )
455        {
456            getc( fp );
457            char cpuclk[4];
458
459            cpuclk[0] = getc( fp );
460            cpuclk[1] = getc( fp );
461            cpuclk[2] = getc( fp );
462            cpuclk[3] = 0;
463            websWrite( wp, cpuclk );
464            fclose( fp );
465            return;
466        }
467    }
468
469    fclose( fp );
470    websWrite( wp, "unknown" );
471    return;
472}
473#elif HAVE_FONERA
474void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
475{
476    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
477
478    if( fp == NULL )
479    {
480        websWrite( wp, "unknown" );
481        return;
482    }
483    int cnt = 0;
484    int b = 0;
485
486    while( b != EOF )
487    {
488        b = getc( fp );
489        if( b == ':' )
490            cnt++;
491        if( cnt == 4 )
492        {
493            getc( fp );
494            char cpuclk[4];
495
496            cpuclk[0] = getc( fp );
497            cpuclk[1] = getc( fp );
498            cpuclk[2] = getc( fp );
499            cpuclk[3] = 0;
500            websWrite( wp, cpuclk );
501            fclose( fp );
502            return;
503        }
504    }
505
506    fclose( fp );
507    websWrite( wp, "unknown" );
508    return;
509}
510#elif HAVE_ADM5120
511void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
512{
513    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
514
515    if( fp == NULL )
516    {
517        websWrite( wp, "unknown" );
518        return;
519    }
520    int cnt = 0;
521    int b = 0;
522
523    while( b != EOF )
524    {
525        b = getc( fp );
526        if( b == ':' )
527            cnt++;
528        if( cnt == 4 )
529        {
530            getc( fp );
531            char cpuclk[4];
532
533            cpuclk[0] = getc( fp );
534            cpuclk[1] = getc( fp );
535            cpuclk[2] = getc( fp );
536            cpuclk[3] = 0;
537            websWrite( wp, cpuclk );
538            fclose( fp );
539            return;
540        }
541    }
542
543    fclose( fp );
544    websWrite( wp, "unknown" );
545    return;
546}
547#elif HAVE_MERAKI
548void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
549{
550    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
551
552    if( fp == NULL )
553    {
554        websWrite( wp, "unknown" );
555        return;
556    }
557    int cnt = 0;
558    int b = 0;
559
560    while( b != EOF )
561    {
562        b = getc( fp );
563        if( b == ':' )
564            cnt++;
565        if( cnt == 4 )
566        {
567            getc( fp );
568            char cpuclk[4];
569
570            cpuclk[0] = getc( fp );
571            cpuclk[1] = getc( fp );
572            cpuclk[2] = getc( fp );
573            cpuclk[3] = 0;
574            websWrite( wp, cpuclk );
575            fclose( fp );
576            return;
577        }
578    }
579
580    fclose( fp );
581    websWrite( wp, "unknown" );
582    return;
583}
584#elif HAVE_LS2
585void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
586{
587    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
588
589    if( fp == NULL )
590    {
591        websWrite( wp, "unknown" );
592        return;
593    }
594    int cnt = 0;
595    int b = 0;
596
597    while( b != EOF )
598    {
599        b = getc( fp );
600        if( b == ':' )
601            cnt++;
602        if( cnt == 4 )
603        {
604            getc( fp );
605            char cpuclk[4];
606
607            cpuclk[0] = getc( fp );
608            cpuclk[1] = getc( fp );
609            cpuclk[2] = getc( fp );
610            cpuclk[3] = 0;
611            websWrite( wp, cpuclk );
612            fclose( fp );
613            return;
614        }
615    }
616
617    fclose( fp );
618    websWrite( wp, "unknown" );
619    return;
620}
621#elif HAVE_LS5
622void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
623{
624    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
625
626    if( fp == NULL )
627    {
628        websWrite( wp, "unknown" );
629        return;
630    }
631    int cnt = 0;
632    int b = 0;
633
634    while( b != EOF )
635    {
636        b = getc( fp );
637        if( b == ':' )
638            cnt++;
639        if( cnt == 4 )
640        {
641            getc( fp );
642            char cpuclk[4];
643
644            cpuclk[0] = getc( fp );
645            cpuclk[1] = getc( fp );
646            cpuclk[2] = getc( fp );
647            cpuclk[3] = 0;
648            websWrite( wp, cpuclk );
649            fclose( fp );
650            return;
651        }
652    }
653
654    fclose( fp );
655    websWrite( wp, "unknown" );
656    return;
657}
658#elif HAVE_WHRAG108
659void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
660{
661    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
662
663    if( fp == NULL )
664    {
665        websWrite( wp, "unknown" );
666        return;
667    }
668    int cnt = 0;
669    int b = 0;
670
671    while( b != EOF )
672    {
673        b = getc( fp );
674        if( b == ':' )
675            cnt++;
676        if( cnt == 4 )
677        {
678            getc( fp );
679            char cpuclk[4];
680
681            cpuclk[0] = getc( fp );
682            cpuclk[1] = getc( fp );
683            cpuclk[2] = getc( fp );
684            cpuclk[3] = 0;
685            websWrite( wp, cpuclk );
686            fclose( fp );
687            return;
688        }
689    }
690
691    fclose( fp );
692    websWrite( wp, "unknown" );
693    return;
694}
695#elif defined(HAVE_PB42) || defined(HAVE_LSX) || defined(HAVE_DANUBE)
696void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
697{
698    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
699
700    if( fp == NULL )
701    {
702        websWrite( wp, "unknown" );
703        return;
704    }
705    int cnt = 0;
706    int b = 0;
707
708    while( b != EOF )
709    {
710        b = getc( fp );
711        if( b == ':' )
712            cnt++;
713        if( cnt == 5 )
714        {
715            getc( fp );
716            char cpuclk[4];
717
718            cpuclk[0] = getc( fp );
719            cpuclk[1] = getc( fp );
720            cpuclk[2] = getc( fp );
721            cpuclk[3] = 0;
722            websWrite( wp, cpuclk );
723            fclose( fp );
724            return;
725        }
726    }
727
728    fclose( fp );
729    websWrite( wp, "unknown" );
730    return;
731}
732#elif HAVE_TW6600
733void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
734{
735    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
736
737    if( fp == NULL )
738    {
739        websWrite( wp, "unknown" );
740        return;
741    }
742    int cnt = 0;
743    int b = 0;
744
745    while( b != EOF )
746    {
747        b = getc( fp );
748        if( b == ':' )
749            cnt++;
750        if( cnt == 4 )
751        {
752            getc( fp );
753            char cpuclk[4];
754
755            cpuclk[0] = getc( fp );
756            cpuclk[1] = getc( fp );
757            cpuclk[2] = getc( fp );
758            cpuclk[3] = 0;
759            websWrite( wp, cpuclk );
760            fclose( fp );
761            return;
762        }
763    }
764
765    fclose( fp );
766    websWrite( wp, "unknown" );
767    return;
768}
769#elif HAVE_CA8
770void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
771{
772    FILE *fp = fopen( "/proc/cpuinfo", "rb" );
773
774    if( fp == NULL )
775    {
776        websWrite( wp, "unknown" );
777        return;
778    }
779    int cnt = 0;
780    int b = 0;
781
782    while( b != EOF )
783    {
784        b = getc( fp );
785        if( b == ':' )
786            cnt++;
787        if( cnt == 4 )
788        {
789            getc( fp );
790            char cpuclk[4];
791
792            cpuclk[0] = getc( fp );
793            cpuclk[1] = getc( fp );
794            cpuclk[2] = getc( fp );
795            cpuclk[3] = 0;
796            websWrite( wp, cpuclk );
797            fclose( fp );
798            return;
799        }
800    }
801
802    fclose( fp );
803    websWrite( wp, "unknown" );
804    return;
805}
806
807#else
808
809void ej_get_clkfreq( webs_t wp, int argc, char_t ** argv )
810{
811    char *clk = nvram_get( "clkfreq" );
812
813    if( clk == NULL )
814    {
815        if( getcpurev(  ) == 0 )        //BCM4710
816            websWrite( wp, "125" );
817        else if( getcpurev(  ) == 29 )  //BCM5354
818            websWrite( wp, "240" );
819        else
820            websWrite( wp, "unknown" );
821        return;
822    }
823    char buf[64];
824
825    strcpy( buf, clk );
826    int i = 0;
827
828    while( buf[i++] != 0 )
829    {
830        if( buf[i] == ',' )
831            buf[i] = 0;
832    }
833    websWrite( wp, buf );
834    return;
835}
836#endif
837
838void ej_show_cpuinfo( webs_t wp, int argc, char_t ** argv )
839{
840    FILE *fcpu = fopen( "/proc/cpuinfo", "r" );
841
842    if( fcpu == NULL )
843    {
844        websWrite( wp, "Not Detected!\n" );
845        return;
846    }
847    char buf[256];
848    int i;
849
850#ifdef HAVE_MAGICBOX
851    int cnt = 0;
852#endif
853#ifdef HAVE_X86
854    int cnt = 0;
855#endif
856    for( i = 0; i < 256; i++ )
857    {
858        int c = getc( fcpu );
859
860        if( c == EOF )
861        {
862            websWrite( wp, "Not Detected!\n" );
863            fclose( fcpu );
864            return;
865        }
866        if( c == ':' )
867#ifdef HAVE_MAGICBOX
868            cnt++;
869        if( cnt == 2 )
870            break;
871#elif HAVE_X86
872            cnt++;
873        if( cnt == 5 )
874            break;
875#else
876            break;
877#endif
878    }
879    getc( fcpu );
880    for( i = 0; i < 256; i++ )
881    {
882        int c = getc( fcpu );
883
884        if( c == EOF )
885        {
886            websWrite( wp, "Not Detected!\n" );
887            fclose( fcpu );
888            return;
889        }
890        if( c == 0xa || c == 0xd )
891            break;
892        buf[i] = c;
893    }
894    buf[i] = 0;
895    websWrite( wp, buf );
896    fclose( fcpu );
897    return;
898}
899
900#define ASSOCLIST_TMP   "/tmp/.wl_assoclist"
901#define RSSI_TMP        "/tmp/.rssi"
902#define ASSOCLIST_CMD   "wl assoclist"
903#define RSSI_CMD        "wl rssi"
904#define NOISE_CMD       "wl noise"
905
906void ej_show_wds_subnet( webs_t wp, int argc, char_t ** argv )
907{
908    int index = -1;
909    char *interface;
910
911#ifdef FASTWEB
912    ejArgs( argc, argv, "%d %s", &index, &interface );
913#else
914    if( ejArgs( argc, argv, "%d %s", &index, &interface ) < 2 )
915    {
916        websError( wp, 400, "Insufficient args\n" );
917        return;
918    }
919#endif
920    char br1[32];
921
922    sprintf( br1, "%s_br1_enable", interface );
923    if( nvram_invmatch( br1, "1" ) )
924        return;
925    char buf[16];
926
927    sprintf( buf, "%s_wds%d_enable", interface, index );
928    websWrite( wp,
929               "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"2\\\" %s >\" + wds.subnet + \"</option>\");\n//]]>\n</script>\n",
930               nvram_selmatch( wp, buf,
931                               "2" ) ? "selected=\\\"selected\\\"" : "" );
932    return;
933}
934
935#ifdef HAVE_SKYTRON
936void ej_active_wireless2( webs_t wp, int argc, char_t ** argv )
937{
938    int rssi = 0, noise = 0;
939    FILE *fp, *fp2;
940    char *mode;
941    char mac[30];
942    char list[2][30];
943    char line[80];
944
945    unlink( ASSOCLIST_TMP );
946    unlink( RSSI_TMP );
947
948    mode = nvram_safe_get( "wl_mode" );
949    sysprintf( "%s > %s", ASSOCLIST_CMD, ASSOCLIST_TMP );
950
951    int connected = 0;
952
953    if( ( fp = fopen( ASSOCLIST_TMP, "r" ) ) )
954    {
955        while( fgets( line, sizeof( line ), fp ) != NULL )
956        {
957            if( sscanf( line, "%s %s", list[0], mac ) != 2 )    // assoclist
958                // 00:11:22:33:44:55
959                continue;
960
961            if( strcmp( list[0], "assoclist" ) )
962                break;
963
964            rssi = 0;
965            noise = 0;
966            // get rssi value
967            if( strcmp( mode, "ap" ) )
968                sysprintf( "%s > %s", RSSI_CMD, RSSI_TMP );
969            else
970                sysprintf( "%s \"%s\" > %s", RSSI_CMD, mac, RSSI_TMP );
971
972            // get noise value if not ap mode
973            if( strcmp( mode, "ap" ) )
974                sysprintf( "%s >> %s", NOISE_CMD, RSSI_TMP );
975
976            fp2 = fopen( RSSI_TMP, "r" );
977            if( fgets( line, sizeof( line ), fp2 ) != NULL )
978            {
979
980                // get rssi
981                if( sscanf( line, "%s %s %d", list[0], list[1], &rssi ) != 3 )
982                    continue;
983
984                // get noise for client/wet mode
985                if( strcmp( mode, "ap" ) &&
986                    fgets( line, sizeof( line ), fp2 ) != NULL &&
987                    sscanf( line, "%s %s %d", list[0], list[1],
988                            &noise ) != 3 )
989                    continue;
990
991                fclose( fp2 );
992            }
993            if( nvram_match( "maskmac", "1" ) )
994            {
995                mac[0] = 'x';
996                mac[1] = 'x';
997                mac[3] = 'x';
998                mac[4] = 'x';
999                mac[6] = 'x';
1000                mac[7] = 'x';
1001                mac[9] = 'x';
1002                mac[10] = 'x';
1003            }
1004            if( strcmp( mode, "ap" ) != 0 )
1005            {
1006                connected = 1;
1007                websWrite( wp, "<tr>\n" );
1008                websWrite( wp,
1009                           "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\"><b>Verbindungsstatus</b></font></td>\n" );
1010                websWrite( wp, "<td bgcolor=\"#B2B2B2\"></td>\n" );
1011                websWrite( wp, "<td bgcolor=\"#FFFFFF\"></td>\n" );
1012                websWrite( wp,
1013                           "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Verbunden</font></td>\n" );
1014                websWrite( wp, "</tr>\n" );
1015                websWrite( wp, "<tr>\n" );
1016                websWrite( wp,
1017                           "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Signal</font></td>\n" );
1018                websWrite( wp, "<td bgcolor=\"#B2B2B2\"></td>\n" );
1019                websWrite( wp, "<td bgcolor=\"#FFFFFF\"></td>\n" );
1020                websWrite( wp,
1021                           "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">%d dBm</font></td>\n",
1022                           rssi );
1023                websWrite( wp, "</tr>\n" );
1024                websWrite( wp, "<tr>\n" );
1025                websWrite( wp,
1026                           "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Rauschen</font></td>\n" );
1027                websWrite( wp, "<td bgcolor=\"#B2B2B2\"></td>\n" );
1028                websWrite( wp, "<td bgcolor=\"#FFFFFF\"></td>\n" );
1029                websWrite( wp,
1030                           "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">%d dBm</font></td>\n",
1031                           noise );
1032                websWrite( wp, "</tr>\n" );
1033            }
1034        }
1035        fclose( fp );
1036    }
1037
1038    unlink( ASSOCLIST_TMP );
1039    unlink( RSSI_TMP );
1040    if( !connected )
1041    {
1042        connected = 1;
1043        websWrite( wp, "<tr>\n" );
1044        websWrite( wp,
1045                   "<td bgcolor=\"#B2B2B2\" valign=\"middle\" align=\"right\" width=\"200\" height=\"25\"><font face=\"Arial\" color=\"#000000\" size=\"2\"><b>Verbindungsstatus</b></font></td>\n" );
1046        websWrite( wp, "<td bgcolor=\"#B2B2B2\"></td>\n" );
1047        websWrite( wp, "<td bgcolor=\"#FFFFFF\"></td>\n" );
1048        websWrite( wp,
1049                   "<td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"middle\" align=\"left\"><font face=\"Arial\" color=\"#000000\" size=\"2\">Nicht Verbunden</font></td>\n" );
1050        websWrite( wp, "</tr>\n" );
1051
1052    }
1053
1054    return 0;
1055}
1056#endif
1057
1058void ej_show_paypal( webs_t wp, int argc, char_t ** argv )
1059{
1060#ifdef HAVE_DDLAN
1061    websWrite( wp,
1062               "<a href=\"mailto:support@mcdd.de\">support@mcdd.de</a><br />" );
1063#endif
1064
1065#ifndef CONFIG_BRANDING
1066    websWrite( wp, "<a href=\"http://www.dd-wrt.com/\">DD-WRT</a><br />" );
1067    websWrite( wp,
1068               "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" target=\"_blank\">" );
1069    websWrite( wp,
1070               "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\" />" );
1071    websWrite( wp,
1072               "<input type=\"hidden\" name=\"business\" value=\"paypal@dd-wrt.com\" />" );
1073    websWrite( wp,
1074               "<input type=\"hidden\" name=\"item_name\" value=\"DD-WRT Development Support\" />" );
1075    websWrite( wp, "<input type=\"hidden\" name=\"no_note\" value=\"1\" />" );
1076    websWrite( wp,
1077               "<input type=\"hidden\" name=\"currency_code\" value=\"EUR\" />" );
1078    websWrite( wp, "<input type=\"hidden\" name=\"lc\" value=\"en\" />" );
1079    websWrite( wp, "<input type=\"hidden\" name=\"tax\" value=\"0\" />" );
1080    websWrite( wp,
1081               "<input type=\"image\" src=\"images/paypal.gif\" name=\"submit\" />" );
1082    websWrite( wp, "</form>" );
1083    websWrite( wp,
1084               "<br /><script type=\"text/javascript\">Capture(donate.mb)</script><br />\n" );
1085    websWrite( wp,
1086               "<a href=\"https://www.moneybookers.com/app/send.pl\" target=\"_blank\">\n" );
1087    // #ifdef HAVE_MICRO
1088    // websWrite (wp,
1089    // "<img style=\"border-width: 1px; border-color: #8B8583;\"
1090    // src=\"http://www.moneybookers.com/images/banners/88_en_interpayments.gif\"
1091    // alt=\"donate thru moneybookers\" />\n");
1092    // #else
1093    websWrite( wp,
1094               "<img style=\"border-width: 1px; border-color: #8B8583;\" src=\"images/88_en_interpayments.png\" alt=\"donate thru interpayments\" />\n" );
1095    // #endif
1096    websWrite( wp, "</a>\n" );
1097#endif
1098    return;
1099}
1100
1101#ifdef HAVE_RADLOCAL
1102
1103void ej_show_iradius_check( webs_t wp, int argc, char_t ** argv )
1104{
1105    char *sln = nvram_safe_get( "iradius_count" );
1106
1107    if( sln == NULL || strlen( sln ) == 0 )
1108        return;
1109    int leasenum = atoi( sln );
1110    int i;
1111
1112    for( i = 0; i < leasenum; i++ )
1113    {
1114        websWrite( wp, "if(F._iradius%d_active)\n", i );
1115        websWrite( wp, "if(F._iradius%d_active.checked == true)\n", i );
1116        websWrite( wp, "F.iradius%d_active.value=1\n", i );
1117        websWrite( wp, "else\n" );
1118        websWrite( wp, "F.iradius%d_active.value=0\n", i );
1119
1120        websWrite( wp, "if(F._iradius%d_delete)\n", i );
1121        websWrite( wp, "if(F._iradius%d_delete.checked == true)\n", i );
1122        websWrite( wp, "F.iradius%d_delete.value=1\n", i );
1123        websWrite( wp, "else\n" );
1124        websWrite( wp, "F.iradius%d_delete.value=0\n", i );
1125    }
1126
1127}
1128void ej_show_iradius( webs_t wp, int argc, char_t ** argv )
1129{
1130    char *sln = nvram_safe_get( "iradius_count" );
1131
1132    if( sln == NULL || strlen( sln ) == 0 )
1133        return;
1134    int leasenum = atoi( sln );
1135
1136    if( leasenum == 0 )
1137        return;
1138    int i;
1139    char username[32];
1140    char *o, *userlist;
1141
1142    cprintf( "get collection\n" );
1143    char *u = nvram_get_collection( "iradius" );
1144
1145    cprintf( "collection result %s", u );
1146    if( u != NULL )
1147    {
1148        userlist = ( char * )malloc( strlen( u ) + 1 );
1149        strcpy( userlist, u );
1150        free( u );
1151        o = userlist;
1152    }
1153    else
1154    {
1155        userlist = NULL;
1156        o = NULL;
1157    }
1158    cprintf( "display = chain\n" );
1159    struct timeval now;
1160
1161    gettimeofday( &now, NULL );
1162    for( i = 0; i < leasenum; i++ )
1163    {
1164        snprintf( username, 31, "iradius%d_name", i );
1165        char *sep = NULL;
1166
1167        if( userlist )
1168            sep = strsep( &userlist, " " );
1169        websWrite( wp, "<tr><td>\n" );
1170        websWrite( wp, "<input name=\"%s\" type=\"hidden\" />", username );
1171        websWrite( wp,
1172                   "<input name=\"%s\" value=\"%s\" size=\"25\" maxlength=\"63\" />\n",
1173                   username, sep != NULL ? sep : "" );
1174        websWrite( wp, "</td>\n" );
1175        if( userlist )
1176            sep = strsep( &userlist, " " );
1177
1178        char active[32];
1179
1180        snprintf( active, 31, "iradius%d_active", i );
1181
1182        websWrite( wp, "<td>\n" );
1183        websWrite( wp, "<input name=\"%s\" type=\"hidden\" />", active );
1184        websWrite( wp,
1185                   "<input type=\"checkbox\" value=\"%s\" name=\"_%s\" %s />\n",
1186                   sep, active, sep != NULL ? strcmp( sep,
1187                                                      "1" ) ==
1188                   0 ? "checked=\"checked\"" : "" : "" );
1189        websWrite( wp, "</td>\n" );
1190        websWrite( wp, "<td>\n" );
1191        if( userlist )
1192            sep = strsep( &userlist, " " );
1193        long t = atol( sep );
1194
1195        if( t != -1 )
1196        {
1197            t -= now.tv_sec;
1198            t /= 60;
1199        }
1200
1201        snprintf( active, 31, "iradius%d_lease", i );
1202        char st[32];
1203
1204        if( t >= 0 )
1205            sprintf( st, "%d", t );
1206        else
1207            sprintf( st, "over" );
1208        websWrite( wp, "<input type=\"num\" name=\"%s\" value='%s' />\n",
1209                   active, st );
1210        websWrite( wp, "</td>\n" );
1211
1212        websWrite( wp, "<td>\n" );
1213        snprintf( active, 31, "iradius%d_delete", i );
1214        websWrite( wp, "<input name=\"%s\" type=\"hidden\" />", active );
1215        websWrite( wp, "<input type=\"checkbox\" name=\"_%s\"/>\n", active );
1216        websWrite( wp, "</td></tr>\n" );
1217    }
1218    if( o != NULL )
1219        free( o );
1220    return;
1221}
1222
1223#endif
1224
1225#ifdef HAVE_CHILLILOCAL
1226
1227void ej_show_userlist( webs_t wp, int argc, char_t ** argv )
1228{
1229    char *sln = nvram_safe_get( "fon_usernames" );
1230
1231    if( sln == NULL || strlen( sln ) == 0 )
1232        return;
1233    int leasenum = atoi( sln );
1234
1235    if( leasenum == 0 )
1236        return;
1237    int i;
1238    char username[32];
1239    char password[32];
1240    char *u = nvram_safe_get( "fon_userlist" );
1241    char *userlist = ( char * )malloc( strlen( u ) + 1 );
1242
1243    strcpy( userlist, u );
1244    char *o = userlist;
1245
1246    for( i = 0; i < leasenum; i++ )
1247    {
1248        snprintf( username, 31, "fon_user%d_name", i );
1249        char *sep = strsep( &userlist, "=" );
1250
1251        websWrite( wp, "<tr><td>\n" );
1252        websWrite( wp,
1253                   "<input name=\"%s\" value=\"%s\" size=\"25\" maxlength=\"63\" />\n",
1254                   username, sep != NULL ? sep : "" );
1255        websWrite( wp, "</td>\n" );
1256        sep = strsep( &userlist, " " );
1257        snprintf( password, 31, "fon_user%d_password", i );
1258        websWrite( wp, "<td>\n" );
1259        websWrite( wp,
1260                   "<input type=\"password\" name=\"%s\" value=\"blahblahblah\" size=\"25\" maxlength=\"63\" />\n",
1261                   password );
1262        websWrite( wp, "</td></tr>\n" );
1263    }
1264    free( o );
1265    return;
1266}
1267
1268#endif
1269
1270void ej_show_staticleases( webs_t wp, int argc, char_t ** argv )
1271{
1272    int i;
1273
1274    // cprintf("get static leasenum");
1275
1276    char *sln = nvram_safe_get( "static_leasenum" );
1277
1278    // cprintf("check null");
1279    if( sln == NULL || strlen( sln ) == 0 )
1280        return;
1281    // cprintf("atoi");
1282
1283    int leasenum = atoi( sln );
1284
1285    // cprintf("leasenum==0");
1286    if( leasenum == 0 )
1287        return;
1288    // cprintf("get leases");
1289    char *nvleases = nvram_safe_get( "static_leases" );
1290    char *leases = ( char * )malloc( strlen( nvleases ) + 1 );
1291    char *originalpointer = leases;     // strsep destroys the pointer by
1292
1293    // moving it
1294    strcpy( leases, nvleases );
1295    for( i = 0; i < leasenum; i++ )
1296    {
1297        char *sep = strsep( &leases, "=" );
1298
1299        websWrite( wp,
1300                   "<tr><td><input name=\"lease%d_hwaddr\" value=\"%s\" size=\"18\" maxlength=\"18\" onblur=\"valid_name(this,share.mac,SPACE_NO)\" /></td>",
1301                   i, sep != NULL ? sep : "" );
1302        sep = strsep( &leases, "=" );
1303        websWrite( wp,
1304                   "<td><input name=\"lease%d_hostname\" value=\"%s\" size=\"24\" maxlength=\"24\" onblur=\"valid_name(this,share.hostname,SPACE_NO)\" /></td>",
1305                   i, sep != NULL ? sep : "" );
1306        sep = strsep( &leases, " " );
1307        websWrite( wp,
1308                   "<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",
1309                   i, sep != NULL ? sep : "" );
1310    }
1311    free( originalpointer );
1312    return;
1313}
1314
1315void ej_show_control( webs_t wp, int argc, char_t ** argv )
1316{
1317#ifdef CONFIG_BRANDING
1318    websWrite( wp, "Control Panel" );
1319#else
1320    websWrite( wp, "DD-WRT Control Panel" );
1321#endif
1322    return;
1323}
1324
1325#ifndef HAVE_AQOS
1326void ej_show_default_level( webs_t wp, int argc, char_t ** argv )
1327{
1328    return;
1329}
1330
1331#else
1332void ej_show_default_level( webs_t wp, int argc, char_t ** argv )
1333{
1334    websWrite( wp, "<fieldset>\n" );
1335    websWrite( wp,
1336               "<legend><script type=\"text/javascript\">Capture(qos.legend6)</script></legend>\n" );
1337    websWrite( wp, "<div class=\"setting\">\n" );
1338    websWrite( wp,
1339               "<div class=\"label\"><script type=\"text/javascript\">Capture(qos.bandwidth)</script> Up</div>\n" );
1340    websWrite( wp,
1341               "<input type=\"num\" name=\"default_uplevel\" size=\"6\" value=\"%s\" /> Down\n",
1342               nvram_safe_get( "default_uplevel" ) );
1343    websWrite( wp,
1344               "<input type=\"num\" name=\"default_downlevel\" size=\"6\" value=\"%s\" />\n",
1345               nvram_safe_get( "default_downlevel" ) );
1346    websWrite( wp, "</div>\n" );
1347    websWrite( wp, "</fieldset><br />\n" );
1348    return;
1349}
1350#endif
1351
1352#ifndef HAVE_MSSID
1353
1354char *selmatch( char *var, char *is, char *ret )
1355{
1356    if( nvram_match( var, is ) )
1357        return ret;
1358    return "";
1359}
1360
1361void ej_show_security( webs_t wp, int argc, char_t ** argv )
1362{
1363    websWrite( wp, "<div class=\"setting\">\n" );
1364    websWrite( wp,
1365               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.secmode)</script></div>\n" );
1366    websWrite( wp,
1367               "<select name=\"security_mode\" onchange=\"SelMode('security_mode',this.form.security_mode.selectedIndex,this.form)\">\n" );
1368    websWrite( wp,
1369               "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"disabled\\\" %s >\" + share.disabled + \"</option>\");\n//]]>\n</script>\n",
1370               selmatch( "security_mode", "disabled",
1371                         "selected=\\\"selected\\\"" ) );
1372    websWrite( wp, "<option value=\"psk\" %s>WPA Personal</option>\n",
1373               selmatch( "security_mode", "psk", "selected=\"selected\"" ) );
1374    websWrite( wp, "<option value=\"wpa\" %s>WPA Enterprise</option>\n",
1375               selmatch( "security_mode", "wpa", "selected=\"selected\"" ) );
1376#ifndef HAVE_RT2880
1377    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
1378#endif
1379    {
1380        websWrite( wp,
1381                   "<option value=\"psk2\" %s>WPA2 Personal</option>\n",
1382                   selmatch( "security_mode", "psk2", "selected" ) );
1383        websWrite( wp, "<option value=\"wpa2\" %s>WPA2 Enterprise</option>\n",
1384                   selmatch( "security_mode", "wpa2",
1385                             "selected=\"selected\"" ) );
1386    }
1387
1388    websWrite( wp,
1389               "<option value=\"psk psk2\" %s>WPA2 Personal Mixed</option>\n",
1390               selmatch( "security_mode", "psk psk2", "selected" ) );
1391    websWrite( wp,
1392               "<option value=\"wpa wpa2\" %s>WPA2 Enterprise Mixed</option>\n",
1393               selmatch( "security_mode", "wpa wpa2",
1394                         "selected=\"selected\"" ) );
1395    websWrite( wp, "<option value=\"radius\" %s>RADIUS</option>\n",
1396               selmatch( "security_mode", "radius",
1397                         "selected=\"selected\"" ) );
1398    websWrite( wp, "<option value=\"wep\" %s>WEP</option></select>\n",
1399               selmatch( "security_mode", "wep", "selected=\"selected\"" ) );
1400    websWrite( wp, "</div>\n" );
1401    ej_show_wpa_setting( wp, argc, argv );
1402    return;
1403}
1404#else
1405#ifdef HAVE_MADWIFI
1406struct wifi_channels
1407{
1408    int channel;
1409    int freq;
1410int noise};
1411extern struct wifi_channels *list_channels( char *devnr );
1412
1413// extern int getchannelcount (void);
1414extern int getdevicecount( void );
1415#endif
1416
1417char *selmatch( char *var, char *is, char *ret )
1418{
1419    if( nvram_match( var, is ) )
1420        return ret;
1421    return "";
1422}
1423
1424static void
1425show_security_prefix( webs_t wp, int argc, char_t ** argv, char *prefix,
1426                      int primary )
1427{
1428    char var[80];
1429    char sta[80];
1430
1431    // char p2[80];
1432    cprintf( "show security prefix\n" );
1433    sprintf( var, "%s_security_mode", prefix );
1434    // strcpy(p2,prefix);
1435    // rep(p2,'X','.');
1436    // websWrite (wp, "<input type=\"hidden\"
1437    // name=\"%s_security_mode\"/>\n",p2);
1438    websWrite( wp, "<div class=\"setting\">\n" );
1439    websWrite( wp,
1440               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.secmode)</script></div>\n" );
1441    websWrite( wp,
1442               "<select name=\"%s_security_mode\" onchange=\"SelMode('%s_security_mode',this.form.%s_security_mode.selectedIndex,this.form)\">\n",
1443               prefix, prefix, prefix );
1444    websWrite( wp,
1445               "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"disabled\\\" %s >\" + share.disabled + \"</option>\");\n//]]>\n</script>\n",
1446               selmatch( var, "disabled", "selected=\\\"selected\\\"" ) );
1447    websWrite( wp, "<option value=\"psk\" %s>WPA Personal</option>\n",
1448               selmatch( var, "psk", "selected=\"selected\"" ) );
1449    sprintf( sta, "%s_mode", prefix );
1450    if( !primary || nvram_match( sta, "ap" ) || nvram_match( sta, "wdsap" ) )
1451    {
1452        websWrite( wp, "<option value=\"wpa\" %s>WPA Enterprise</option>\n",
1453                   selmatch( var, "wpa", "selected=\"selected\"" ) );
1454    }
1455    websWrite( wp,
1456               "<option value=\"psk2\" %s>WPA2 Personal</option>\n",
1457               selmatch( var, "psk2", "selected=\"selected\"" ) );
1458    if( !primary || nvram_match( sta, "ap" ) || nvram_match( sta, "wdsap" ) )
1459    {
1460        websWrite( wp, "<option value=\"wpa2\" %s>WPA2 Enterprise</option>\n",
1461                   selmatch( var, "wpa2", "selected=\"selected\"" ) );
1462    }
1463#ifdef HAVE_RT2880
1464    if( !primary || nvram_match( sta, "ap" ))
1465#endif
1466    websWrite( wp,
1467               "<option value=\"psk psk2\" %s>WPA2 Personal Mixed</option>\n",
1468               selmatch( var, "psk psk2", "selected=\"selected\"" ) );
1469               
1470    if( !primary || nvram_match( sta, "ap" ) || nvram_match( sta, "wdsap" ) )
1471    {
1472        websWrite( wp,
1473                   "<option value=\"wpa wpa2\" %s>WPA2 Enterprise Mixed</option>\n",
1474                   selmatch( var, "wpa wpa2", "selected=\"selected\"" ) );
1475
1476        websWrite( wp, "<option value=\"radius\" %s>RADIUS</option>\n",
1477                   selmatch( var, "radius", "selected=\"selected\"" ) );
1478    }
1479
1480    websWrite( wp, "<option value=\"wep\" %s>WEP</option>\n",
1481               selmatch( var, "wep", "selected=\"selected\"" ) );
1482#ifdef HAVE_WPA_SUPPLICANT
1483#ifndef HAVE_MICRO
1484#ifndef HAVE_RT2880
1485    if( !primary || nvram_match( sta, "sta" ) || nvram_match( sta, "wdssta" )
1486        || nvram_match( sta, "apsta" ) || nvram_match( sta, "wet" ) )
1487    {
1488        websWrite( wp, "<option value=\"8021X\" %s>802.1x</option>\n",
1489                   selmatch( var, "8021X", "selected=\"selected\"" ) );
1490    }
1491#else
1492    if( nvram_match( sta, "sta" ) || nvram_match( sta, "wet" ) )
1493    {
1494        websWrite( wp, "<option value=\"8021X\" %s>802.1x</option>\n",
1495                   selmatch( var, "8021X", "selected=\"selected\"" ) );
1496    }
1497#endif
1498#endif
1499#endif
1500
1501    websWrite( wp, "</select></div>\n" );
1502    rep( prefix, 'X', '.' );
1503    cprintf( "ej show wpa\n" );
1504    ej_show_wpa_setting( wp, argc, argv, prefix );
1505
1506}
1507
1508static void
1509ej_show_security_single( webs_t wp, int argc, char_t ** argv, char *prefix )
1510{
1511    char *next;
1512    char var[80];
1513    char ssid[80];
1514    char mac[16];
1515
1516    sprintf( mac, "%s_hwaddr", prefix );
1517    char *vifs = nvram_nget( "%s_vifs", prefix );
1518
1519    if( vifs == NULL )
1520        return;
1521    sprintf( ssid, "%s_ssid", prefix );
1522    websWrite( wp,
1523               "<h2><script type=\"text/javascript\">Capture(wpa.h2)</script> %s</h2>\n",
1524               prefix );
1525    websWrite( wp, "<fieldset>\n" );
1526    // cprintf("getting %s %s\n",ssid,nvram_safe_get(ssid));
1527    websWrite( wp,
1528               "<legend><script type=\"text/javascript\">Capture(share.pintrface)</script> %s SSID [",
1529               IFMAP(prefix) );
1530    tf_webWriteESCNV( wp, ssid );       // fix for broken html page if ssid
1531    // contains html tag
1532    websWrite( wp, "] HWAddr [%s]</legend>\n", nvram_safe_get( mac ) );
1533    show_security_prefix( wp, argc, argv, prefix, 1 );
1534    websWrite( wp, "</fieldset>\n<br />\n" );
1535    foreach( var, vifs, next )
1536    {
1537        sprintf( ssid, "%s_ssid", var );
1538        websWrite( wp, "<fieldset>\n" );
1539        // cprintf("getting %s %s\n", ssid,nvram_safe_get(ssid));
1540        websWrite( wp,
1541                   "<legend><script type=\"text/javascript\">Capture(share.vintrface)</script> %s SSID [",
1542                   IFMAP(var) );
1543        tf_webWriteESCNV( wp, ssid );   // fix for broken html page if ssid
1544        // contains html tag
1545        websWrite( wp, "]</legend>\n" );
1546        rep( var, '.', 'X' );
1547        show_security_prefix( wp, argc, argv, var, 0 );
1548        websWrite( wp, "</fieldset>\n<br />\n" );
1549    }
1550
1551}
1552
1553void ej_show_security( webs_t wp, int argc, char_t ** argv )
1554{
1555#ifndef HAVE_MADWIFI
1556    int c = get_wl_instances(  );
1557    int i;
1558
1559    for( i = 0; i < c; i++ )
1560    {
1561        char buf[16];
1562
1563        sprintf( buf, "wl%d", i );
1564        ej_show_security_single( wp, argc, argv, buf );
1565    }
1566    return;
1567#else
1568    int c = getdevicecount(  );
1569    int i;
1570
1571    for( i = 0; i < c; i++ )
1572    {
1573        char buf[16];
1574
1575        sprintf( buf, "ath%d", i );
1576        ej_show_security_single( wp, argc, argv, buf );
1577    }
1578    return;
1579#endif
1580}
1581
1582#endif
1583
1584void ej_show_dhcpd_settings( webs_t wp, int argc, char_t ** argv )
1585{
1586    int i;
1587
1588    if( nvram_match( "wl0_mode", "wet" ) )      // dhcpd settings disabled in
1589        // client bridge mode, so we
1590        // wont display it
1591        return;
1592    if( nvram_match( "wl0_mode", "apstawet" ) ) // dhcpd settings disabled in
1593        // client bridge mode, so we
1594        // wont display it
1595        return;
1596    websWrite( wp,
1597               "<fieldset><legend><script type=\"text/javascript\">Capture(idx.dhcp_legend)</script></legend>\n" );
1598    websWrite( wp, "<div class=\"setting\">\n" );
1599    websWrite( wp,
1600               "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_type)</script></div>\n" );
1601    websWrite( wp,
1602               "<select class=\"num\" size=\"1\" name=\"dhcpfwd_enable\" onchange=SelDHCPFWD(this.form.dhcpfwd_enable.selectedIndex,this.form)>\n" );
1603    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
1604    websWrite( wp,
1605               "document.write(\"<option value=\\\"0\\\" %s >\" + idx.dhcp_srv + \"</option>\");\n",
1606               nvram_match( "dhcpfwd_enable",
1607                            "0" ) ? "selected=\\\"selected\\\"" : "" );
1608    websWrite( wp,
1609               "document.write(\"<option value=\\\"1\\\" %s >\" + idx.dhcp_fwd + \"</option>\");\n",
1610               nvram_match( "dhcpfwd_enable",
1611                            "1" ) ? "selected=\\\"selected\\\"" : "" );
1612    websWrite( wp, "//]]>\n</script>\n" );
1613    websWrite( wp, "</select>\n" );
1614    websWrite( wp, "</div>\n" );
1615    if( nvram_match( "dhcpfwd_enable", "1" ) )
1616    {
1617        websWrite( wp, "<div class=\"setting\">\n" );
1618        websWrite( wp,
1619                   "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_srv)</script></div>\n" );
1620        char *ipfwd = nvram_safe_get( "dhcpfwd_ip" );
1621
1622        websWrite( wp,
1623                   "<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",
1624                   get_single_ip( ipfwd, 0 ), get_single_ip( ipfwd, 1 ),
1625                   get_single_ip( ipfwd, 2 ), get_single_ip( ipfwd, 3 ) );
1626    }
1627    else
1628    {
1629        char buf[20];
1630
1631        prefix_ip_get( "lan_ipaddr", buf, 1 );
1632        websWrite( wp, "<div class=\"setting\">\n" );
1633        // char *nv = nvram_safe_get ("wan_wins");
1634        websWrite( wp,
1635                   "<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>&nbsp;\n",
1636                   nvram_match( "lan_proto",
1637                                "dhcp" ) ? "checked=\"checked\"" : "" );
1638        websWrite( wp,
1639                   "<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",
1640                   nvram_match( "lan_proto",
1641                                "static" ) ? "checked=\"checked\"" : "" );
1642        websWrite( wp,
1643                   "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_start)</script></div>%s",
1644                   buf );
1645        websWrite( wp,
1646                   "<input class=\"num\" name=\"dhcp_start\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,1,254,idx.dhcp_start)\" value=\"%s\" />",
1647                   nvram_safe_get( "dhcp_start" ) );
1648        websWrite( wp, "</div>\n" );
1649        websWrite( wp, "<div class=\"setting\">\n" );
1650        websWrite( wp,
1651                   "<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,0,253,idx.dhcp_maxusers)\" value=\"%s\" /></div>\n",
1652                   nvram_safe_get( "dhcp_num" ) );
1653        websWrite( wp, "<div class=\"setting\">\n" );
1654        websWrite( wp,
1655                   "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_lease)</script></div><input class=\"num\" name=\"dhcp_lease\" size=\"5\" maxlength=\"5\" onblur=\"valid_range(this,0,99999,idx.dhcp_lease)\" value=\"%s\" > <script type=\"text/javascript\">Capture(share.minutes)</script></input></div>\n",
1656                   nvram_safe_get( "dhcp_lease" ) );
1657        if( nvram_invmatch( "wan_proto", "static" ) )
1658        {
1659            websWrite( wp, "<div class=\"setting\">\n" );
1660            websWrite( wp,
1661                       "<div class=\"label\"><script type=\"text/javascript\">Capture(idx_static.dns)</script> 1</div>" );
1662            websWrite( wp,
1663                       "<input type=\"hidden\" name=\"wan_dns\" value=\"4\" />" );
1664            for( i = 0; i < 4; i++ )
1665                websWrite( wp,
1666                           "<input class=\"num\" name=\"wan_dns0_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,idx_static.dns)\" value=\"%d\" />%s",
1667                           i, i == 3 ? 254 : 255, get_dns_ip( "wan_dns", 0,
1668                                                              i ),
1669                           i < 3 ? "." : "" );
1670
1671            websWrite( wp, "\n</div>\n<div class=\"setting\">\n" );
1672            websWrite( wp,
1673                       "<div class=\"label\"><script type=\"text/javascript\">Capture(idx_static.dns)</script> 2</div>" );
1674            for( i = 0; i < 4; i++ )
1675                websWrite( wp,
1676                           "<input class=\"num\" name=\"wan_dns1_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,idx_static.dns)\" value=\"%d\" />%s",
1677                           i, i == 3 ? 254 : 255, get_dns_ip( "wan_dns", 1,
1678                                                              i ),
1679                           i < 3 ? "." : "" );
1680
1681            websWrite( wp, "\n</div>\n<div class=\"setting\">\n" );
1682            websWrite( wp,
1683                       "<div class=\"label\"><script type=\"text/javascript\">Capture(idx_static.dns)</script> 3</div>" );
1684            for( i = 0; i < 4; i++ )
1685                websWrite( wp,
1686                           "<input class=\"num\" name=\"wan_dns2_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,idx_static.dns)\" value=\"%d\" />%s",
1687                           i, i == 3 ? 254 : 255, get_dns_ip( "wan_dns", 2,
1688                                                              i ),
1689                           i < 3 ? "." : "" );
1690            websWrite( wp, "\n</div>" );
1691        }
1692        websWrite( wp, "<div class=\"setting\">\n" );
1693        websWrite( wp, "<div class=\"label\">WINS</div>\n" );
1694        websWrite( wp,
1695                   "<input type=\"hidden\" name=\"wan_wins\" value=\"4\" />\n" );
1696        char *wins = nvram_safe_get( "wan_wins" );
1697
1698        for( i = 0; i < 4; i++ )
1699        {
1700            websWrite( wp,
1701                       "<input class=\"num\" name=\"wan_wins_%d\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,%d,&#34;WINS&#34;)\" value=\"%d\" />%s",
1702                       i, i == 3 ? 254 : 255, get_single_ip( wins, i ),
1703                       i < 3 ? "." : "" );
1704        }
1705
1706        websWrite( wp, "</div>\n<div class=\"setting\">\n" );
1707        websWrite( wp,
1708                   "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dhcp_dnsmasq)</script></div>\n" );
1709        websWrite( wp,
1710                   "<input type=\"checkbox\" name=\"_dhcp_dnsmasq\" value=\"1\" onclick=\"setDNSMasq(this.form)\" %s />\n",
1711                   nvram_match( "dhcp_dnsmasq",
1712                                "1" ) ? "checked=\"checked\"" : "" );
1713        websWrite( wp, "</div>\n<div class=\"setting\">\n" );
1714        websWrite( wp,
1715                   "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.dns_dnsmasq)</script></div>\n" );
1716        websWrite( wp,
1717                   "<input type=\"checkbox\" name=\"_dns_dnsmasq\" value=\"1\" %s />\n",
1718                   nvram_match( "dns_dnsmasq",
1719                                "1" ) ? "checked=\"checked\"" : "" );
1720        websWrite( wp, "</div>\n<div class=\"setting\">\n" );
1721        websWrite( wp,
1722                   "<div class=\"label\"><script type=\"text/javascript\">Capture(idx.auth_dnsmasq)</script></div>\n" );
1723        websWrite( wp,
1724                   "<input type=\"checkbox\" name=\"_auth_dnsmasq\" value=\"1\" %s />\n",
1725                   nvram_match( "auth_dnsmasq",
1726                                "1" ) ? "checked=\"checked\"" : "" );
1727        websWrite( wp, "</div>\n" );
1728    }
1729
1730    websWrite( wp, "</fieldset><br />\n" );
1731    return;
1732}
1733
1734#ifdef HAVE_MADWIFI
1735void ej_show_wifiselect( webs_t wp, int argc, char_t ** argv )
1736{
1737    char *next;
1738    char var[32];
1739    int count = getifcount( "wifi" );
1740
1741    if( count < 2 )
1742        return;
1743    websWrite( wp, "<div class=\"setting\">\n" );
1744    websWrite( wp,
1745               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.intrface)</script></div>\n" );
1746    websWrite( wp,
1747               "<select name=\"wifi_display\" onchange=\"refresh(this.form)\">\n" );
1748    int i;
1749
1750    for( i = 0; i < count; i++ )
1751    {
1752        sprintf( var, "ath%d", i );
1753        websWrite( wp, "<option value=\"%s\" %s >%s</option>\n",
1754                   var, nvram_match( "wifi_display",
1755                                     var ) ? "selected=\"selected\"" : "",
1756                   var );
1757        char *names = nvram_nget( "ath%d_vifs", i );
1758
1759        foreach( var, names, next )
1760        {
1761            websWrite( wp, "<option value=\"%s\" %s >%s</option>\n",
1762                       var, nvram_match( "wifi_display",
1763                                         var ) ? "selected=\"selected\"" : "",
1764                       var );
1765        }
1766    }
1767    websWrite( wp, "</select>\n" );
1768    websWrite( wp, "</div>\n" );
1769
1770}
1771#else
1772void ej_show_wifiselect( webs_t wp, int argc, char_t ** argv )
1773{
1774    // nothing for now
1775}
1776
1777#endif
1778#if 0
1779static void showOption( webs_t wp, char *propname, char *nvname )
1780{
1781    websWrite( wp, "<div class=\"setting\">\n" );
1782    websWrite( wp,
1783               "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>\n<select name=\"%s\">\n",
1784               propname, nvname );
1785    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
1786    websWrite( wp,
1787               "document.write(\"<option value=\\\"0\\\" %s >\" + share.disabled + \"</option>\");\n",
1788               nvram_default_match( nvname, "0",
1789                                    "0" ) ? "selected=\\\"selected\\\"" :
1790               "" );
1791    websWrite( wp,
1792               "document.write(\"<option value=\\\"1\\\" %s >\" + share.enabled + \"</option>\");\n",
1793               nvram_default_match( nvname, "1",
1794                                    "0" ) ? "selected=\\\"selected\\\"" :
1795               "" );
1796    websWrite( wp, "//]]>\n</script>\n</select>\n</div>\n" );
1797
1798}
1799#endif
1800static void showRadio( webs_t wp, char *propname, char *nvname )
1801{
1802    websWrite( wp, "<div class=\"setting\">\n" );
1803    websWrite( wp,
1804               "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>\n",
1805               propname );
1806    websWrite( wp,
1807               "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input>&nbsp;\n",
1808               nvname, nvram_default_match( nvname, "1",
1809                                            "0" ) ? "checked=\"checked\"" :
1810               "" );
1811    websWrite( wp,
1812               "<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>&nbsp;\n",
1813               nvname, nvram_default_match( nvname, "0",
1814                                            "0" ) ? "checked=\"checked\"" :
1815               "" );
1816    websWrite( wp, "</div>\n" );
1817}
1818
1819#ifdef HAVE_MADWIFI
1820static void showAutoOption( webs_t wp, char *propname, char *nvname )
1821{
1822    websWrite( wp, "<div class=\"setting\">\n" );
1823    websWrite( wp,
1824               "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>\n<select name=\"%s\">\n",
1825               propname, nvname );
1826    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
1827    websWrite( wp,
1828               "document.write(\"<option value=\\\"-1\\\" %s >\" + share.auto + \"</option>\");\n",
1829               nvram_default_match( nvname, "0",
1830                                    "-1" ) ? "selected=\\\"selected\\\"" :
1831               "" );
1832    websWrite( wp,
1833               "document.write(\"<option value=\\\"1\\\" %s >\" + share.enabled + \"</option>\");\n",
1834               nvram_default_match( nvname, "1",
1835                                    "-1" ) ? "selected=\\\"selected\\\"" :
1836               "" );
1837    websWrite( wp,
1838               "document.write(\"<option value=\\\"0\\\" %s >\" + share.disabled + \"</option>\");\n",
1839               nvram_default_match( nvname, "0",
1840                                    "-1" ) ? "selected=\\\"selected\\\"" :
1841               "" );
1842    websWrite( wp, "//]]>\n</script>\n</select>\n</div>\n" );
1843
1844}
1845#endif
1846
1847static void
1848showOptions( webs_t wp, char *propname, char *names, char *select )
1849{
1850    char *next;
1851    char var[80];
1852
1853    websWrite( wp, "<select name=\"%s\">\n", propname );
1854    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
1855    foreach( var, names, next )
1856    {
1857        websWrite( wp,
1858                   "document.write(\"<option value=\\\"%s\\\" %s >%s</option>\");\n",
1859                   var, !strcmp( var,
1860                                 select ) ? "selected=\\\"selected\\\"" : "",
1861                   var );
1862    }
1863    websWrite( wp, "//]]>\n</script>\n</select>\n" );
1864}
1865
1866#ifdef HAVE_MADWIFI
1867static void
1868showOptionsChoose( webs_t wp, char *propname, char *names, char *select )
1869{
1870    char *next;
1871    char var[80];
1872
1873    websWrite( wp, "<select name=\"%s\">\n", propname );
1874    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
1875    websWrite( wp,
1876               "document.write(\"<option value=\\\"null\\\" >Please choose...</option>\");\n" );
1877    foreach( var, names, next )
1878    {
1879        websWrite( wp,
1880                   "document.write(\"<option value=\\\"%s\\\" %s >%s</option>\");\n",
1881                   var, !strcmp( var,
1882                                 select ) ? "selected=\\\"selected\\\"" : "",
1883                   var );
1884    }
1885    websWrite( wp, "//]]>\n</script>\n</select>\n" );
1886}
1887#endif
1888static void
1889showOptionsLabel( webs_t wp, char *labelname, char *propname, char *names,
1890                  char *select )
1891{
1892    websWrite( wp, "<div class=\"setting\">\n" );
1893    websWrite( wp,
1894               "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>",
1895               labelname );
1896    showOptions( wp, propname, names, select );
1897    websWrite( wp, "</div>\n" );
1898
1899}
1900
1901void
1902show_inputlabel( webs_t wp, char *labelname, char *propertyname,
1903                 int propertysize, char *inputclassname, int inputmaxlength )
1904{
1905    websWrite( wp, "<div class=\"setting\">\n" );
1906    websWrite( wp,
1907               "<div class=\"label\"><script type=\"text/javascript\">Capture(%s)</script></div>",
1908               labelname );
1909    websWrite( wp,
1910               "<input class=\"%s\" size=\"%d\" maxlength=\"%d\" name=\"%s\" value=\"%s\" />\n",
1911               inputclassname, propertysize, inputmaxlength, propertyname,
1912               nvram_safe_get( propertyname ) );
1913    websWrite( wp, "</div>\n" );
1914}
1915
1916void
1917show_custominputlabel( webs_t wp, char *labelname, char *propertyname,
1918                       char *property, int propertysize )
1919{
1920    websWrite( wp, "<div class=\"setting\">\n" );
1921    websWrite( wp, "<div class=\"label\">%s</div>", labelname );
1922    websWrite( wp, "<input size=\"%d\" name=\"%s\" value=\"%s\" />\n",
1923               propertysize, propertyname, property );
1924    websWrite( wp, "</div>\n" );
1925}
1926
1927void show_legend( webs_t wp, char *labelname, int translate )
1928{
1929    /*
1930     * char buf[2]; sprintf(buf,"%d",translate); websWrite (wp,
1931     * "<legend>%s%s%s</legend>\n", !strcmp (buf, "1") ? "<script
1932     * type=\"text/javascript\">Capture(" : "", labelname, !strcmp (buf, "1")
1933     * ? ")</script>" : "");
1934     */
1935    if( translate )
1936        websWrite( wp,
1937                   "<legend><script type=\"text/javascript\">Capture(%s)</script></legend>\n",
1938                   labelname );
1939    else
1940        websWrite( wp, "<legend>%s</legend>\n", labelname );
1941
1942}
1943
1944#ifdef HAVE_OLSRD
1945
1946void ej_show_olsrd( webs_t wp, int argc, char_t ** argv )
1947{
1948    char *var = websGetVar( wp, "wk_mode", NULL );
1949
1950    if( var == NULL )
1951        var = nvram_safe_get( "wk_mode" );
1952    if( !strcmp( var, "olsr" ) )
1953    {
1954        websWrite( wp, "<fieldset>\n" );
1955        show_legend( wp, "route.olsrd_legend", 1 );
1956        show_inputlabel( wp, "route.olsrd_hna", "olsrd_hna", 32, "num", 32 );
1957        show_inputlabel( wp, "route.olsrd_poll", "olsrd_pollsize", 5, "num",
1958                         5 );
1959        showOptionsLabel( wp, "route.olsrd_tc", "olsrd_redundancy", "0 1 2",
1960                          nvram_default_get( "olsrd_redundancy", "2" ) );
1961        show_inputlabel( wp, "route.olsrd_mpr", "olsrd_coverage", 5, "num",
1962                         5 );
1963        showRadio( wp, "route.olsrd_lqfe", "olsrd_lqfisheye" );
1964        show_inputlabel( wp, "route.olsrd_lqag", "olsrd_lqaging", 5, "num",
1965                         5 );
1966
1967        websWrite( wp, "<div class=\"setting\">\n" );
1968        websWrite( wp,
1969                   "<div class=\"label\"><script type=\"text/javascript\">Capture(route.olsrd_lqdmin)</script></div>" );
1970        websWrite( wp,
1971                   "<input class=\"num\" size=\"5\" maxlength=\"5\" name=\"olsrd_lqdijkstramin\" onblur=\"olsrd_checkDijkstra(this.form)\" value=\"%s\" />\n",
1972                   nvram_safe_get( "olsrd_lqdijkstramin" ) );
1973        websWrite( wp, "</div>\n" );
1974        websWrite( wp, "<div class=\"setting\">\n" );
1975        websWrite( wp,
1976                   "<div class=\"label\"><script type=\"text/javascript\">Capture(route.olsrd_lqdmax)</script></div>" );
1977        websWrite( wp,
1978                   "<input class=\"num\" size=\"5\" maxlength=\"5\" name=\"olsrd_lqdijkstramax\" onblur=\"olsrd_checkDijkstra(this.form)\" value=\"%s\" />\n",
1979                   nvram_safe_get( "olsrd_lqdijkstramax" ) );
1980        websWrite( wp, "</div>\n" );
1981
1982        showOptionsLabel( wp, "route.olsrd_lqlvl", "olsrd_lqlevel",
1983                          "0 1 2", nvram_default_get( "olsrd_lqlevel",
1984                                                      "2" ) );
1985        showRadio( wp, "route.olsrd_hysteresis", "olsrd_hysteresis" );
1986        char *wordlist = nvram_safe_get( "olsrd_interfaces" );
1987        char *next;
1988        char word[128];
1989        int count = 0;
1990
1991        foreach( word, wordlist, next )
1992        {
1993            char *interface = word;
1994            char *hellointerval = interface;
1995
1996            strsep( &hellointerval, ">" );
1997            char *hellovaliditytime = hellointerval;
1998
1999            strsep( &hellovaliditytime, ">" );
2000            char *tcinterval = hellovaliditytime;
2001
2002            strsep( &tcinterval, ">" );
2003            char *tcvaliditytime = tcinterval;
2004
2005            strsep( &tcvaliditytime, ">" );
2006            char *midinterval = tcvaliditytime;
2007
2008            strsep( &midinterval, ">" );
2009            char *midvaliditytime = midinterval;
2010
2011            strsep( &midvaliditytime, ">" );
2012            char *hnainterval = midvaliditytime;
2013
2014            strsep( &hnainterval, ">" );
2015            char *hnavaliditytime = hnainterval;
2016
2017            strsep( &hnavaliditytime, ">" );
2018            websWrite( wp, "<fieldset>\n" );
2019            show_legend( wp, interface, 0 );
2020            char valuename[32];
2021
2022            sprintf( valuename, "%s_hellointerval", interface );
2023            show_custominputlabel( wp, "Hello Interval", valuename,
2024                                   hellointerval, 5 );
2025            sprintf( valuename, "%s_hellovaliditytime", interface );
2026            show_custominputlabel( wp, "Hello Validity Time", valuename,
2027                                   hellovaliditytime, 5 );
2028
2029            sprintf( valuename, "%s_tcinterval", interface );
2030            show_custominputlabel( wp, "TC Interval", valuename, tcinterval,
2031                                   5 );
2032            sprintf( valuename, "%s_tcvaliditytime", interface );
2033            show_custominputlabel( wp, "TC Validity Time", valuename,
2034                                   tcvaliditytime, 5 );
2035
2036            sprintf( valuename, "%s_midinterval", interface );
2037            show_custominputlabel( wp, "MID Interval", valuename, midinterval,
2038                                   5 );
2039            sprintf( valuename, "%s_midvaliditytime", interface );
2040            show_custominputlabel( wp, "MID Validity Time", valuename,
2041                                   midvaliditytime, 5 );
2042
2043            sprintf( valuename, "%s_hnainterval", interface );
2044            show_custominputlabel( wp, "HNA Interval", valuename, hnainterval,
2045                                   5 );
2046            sprintf( valuename, "%s_hnavaliditytime", interface );
2047            show_custominputlabel( wp, "HNA Validity Time", valuename,
2048                                   hnavaliditytime, 5 );
2049            websWrite( wp,
2050                       "<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",
2051                       count );
2052
2053            websWrite( wp, "</fieldset>\n" );
2054            count++;
2055        }
2056        websWrite( wp, "<div class=\"setting\">\n" );
2057        websWrite( wp,
2058                   "<div class=\"label\"><script type=\"text/javascript\">Capture(route.olsrd_newiface)</script></div>\n" );
2059        char buffer[256];
2060
2061        memset( buffer, 0, 256 );
2062        getIfList( buffer, NULL );
2063        showOptions( wp, "olsrd_ifname", buffer, "" );
2064        websWrite( wp, "&nbsp;&nbsp;" );
2065        websWrite( wp,
2066                   "<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" );
2067        websWrite( wp, "</div>\n" );
2068        websWrite( wp, "</fieldset><br />\n" );
2069    }
2070}
2071#else //!HAVE_OLSRD
2072void ej_show_olsrd( webs_t wp, int argc, char_t ** argv )
2073{
2074    return;
2075}
2076#endif
2077
2078#ifdef HAVE_VLANTAGGING
2079#ifdef HAVE_BONDING
2080
2081void ej_show_bondings( webs_t wp, int argc, char_t ** argv )
2082{
2083    char buffer[256];
2084    char bufferif[512];
2085    char bondnames[256];
2086    int count = 0;
2087    static char word[256];
2088    char *next, *wordlist;
2089
2090    memset( buffer, 0, 256 );
2091    memset( bondnames, 0, 256 );
2092    memset( bufferif, 0, 512 );
2093    websWrite( wp, "<h2>Bonding</h2>\n" );
2094    websWrite( wp, "<fieldset>\n" );
2095    websWrite( wp, "<legend>Bonding</legend>\n" );
2096    websWrite( wp, "<div class=\"setting\">\n" );
2097    websWrite( wp, "<div class=\"label\">Bonding Type</div>\n", count );
2098    showOptions( wp, "bonding_type",
2099                 "balance-rr active-backup balance-xor broadcast 802.3ad balance-tlb balance-alb",
2100                 nvram_default_get( "bonding_type", "balance-rr" ) );
2101    websWrite( wp, "&nbsp;Bonding Interfaces&nbsp;" );
2102    websWrite( wp,
2103               "<input class=\"num\" name=\"bonding_number\"size=\"5\" value=\"%s\" />\n",
2104               nvram_default_get( "bonding_number", "1" ) );
2105    websWrite( wp, "</div>\n" );
2106
2107    getIfList( bufferif, "eth" );
2108    int i;
2109
2110#ifdef HAVE_XSCALE
2111    memset( buffer, 0, 256 );
2112    getIfList( buffer, "ixp" );
2113    sprintf( bufferif, "%s %s", bufferif, buffer );
2114#endif
2115    memset( buffer, 0, 256 );
2116    getIfList( buffer, "br" );
2117    sprintf( bufferif, "%s %s", bufferif, buffer );
2118#ifdef HAVE_MADWIFI
2119    int c = getifcount( "wifi" );
2120
2121    for( i = 0; i < c; i++ )
2122    {
2123        char ath[32];
2124
2125        sprintf( ath, "ath%d_bridged", i );
2126        if( nvram_default_match( ath, "0", "1" ) )
2127        {
2128            sprintf( bufferif, "%s ath%d", bufferif, i );
2129            char vifs[32];
2130
2131            sprintf( vifs, "ath%d_vifs", i );
2132            sprintf( bufferif, "%s %s", bufferif, nvram_safe_get( vifs ) );
2133        }
2134    }
2135#endif
2136
2137    for( i = 0; i < atoi( nvram_safe_get( "bonding_number" ) ); i++ )
2138    {
2139        sprintf( bondnames, "%s bond%d", bondnames, i );
2140    }
2141    int totalcount = 0;
2142    int realcount = atoi( nvram_default_get( "bonding_count", "0" ) );
2143
2144    wordlist = nvram_safe_get( "bondings" );
2145    foreach( word, wordlist, next )
2146    {
2147        char *port = word;
2148        char *tag = strsep( &port, ">" );
2149
2150        if( !tag || !port )
2151            break;
2152        char vlan_name[32];
2153
2154        // sprintf (vlan_name, "%s.%s", tag, port);
2155        websWrite( wp, "<div class=\"setting\">\n" );
2156        websWrite( wp, "<div class=\"label\">Bonding %d Assignment</div>\n",
2157                   count );
2158        websWrite( wp, "&nbsp;Bond&nbsp;" );
2159        sprintf( vlan_name, "bondingifname%d", count );
2160        showOptions( wp, vlan_name, bondnames, tag );
2161        sprintf( vlan_name, "bondingattach%d", count );
2162        websWrite( wp, "&nbsp;Slave&nbsp;" );
2163        showOptions( wp, vlan_name, bufferif, port );
2164        websWrite( wp,
2165                   "<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",
2166                   count );
2167        websWrite( wp, "</div>\n" );
2168        count++;
2169    }
2170    totalcount = count;
2171    for( i = count; i < realcount; i++ )
2172    {
2173        char vlan_name[32];
2174
2175        websWrite( wp, "<div class=\"setting\">\n" );
2176        websWrite( wp, "<div class=\"label\">Bonding %d Interface</div>\n",
2177                   i );
2178        websWrite( wp, "&nbsp;Bond&nbsp;" );
2179        sprintf( vlan_name, "bondingifname%d", i );
2180        showOptions( wp, vlan_name, bondnames, "" );
2181        sprintf( vlan_name, "bondingattach%d", i );
2182        websWrite( wp, "&nbsp;Slave&nbsp;" );
2183        showOptions( wp, vlan_name, bufferif, "" );
2184        websWrite( wp,
2185                   "<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",
2186                   i );
2187        websWrite( wp, "</div>\n" );
2188        totalcount++;
2189    }
2190    char var[32];
2191
2192    sprintf( var, "%d", totalcount );
2193    nvram_set( "bonding_count", var );
2194    websWrite( wp,
2195               "<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" );
2196    websWrite( wp, "</fieldset><br />\n" );
2197}
2198#else //!HAVE_BONDING
2199void ej_show_bondings( webs_t wp, int argc, char_t ** argv )
2200{
2201    return;
2202}
2203#endif
2204
2205void ej_show_vlantagging( webs_t wp, int argc, char_t ** argv )
2206{
2207    char buffer[256];
2208    int count = 0;
2209    static char word[256];
2210    char *next, *wordlist;
2211
2212    memset( buffer, 0, 256 );
2213    getIfList( buffer, NULL );
2214    int totalcount = 0;
2215    int realcount = atoi( nvram_default_get( "vlan_tagcount", "0" ) );
2216
2217    wordlist = nvram_safe_get( "vlan_tags" );
2218    foreach( word, wordlist, next )
2219    {
2220        char *port = word;
2221        char *tag = strsep( &port, ">" );
2222
2223        if( !tag || !port )
2224            break;
2225        char vlan_name[32];
2226
2227        // sprintf (vlan_name, "%s.%s", tag, port);
2228        websWrite( wp, "<div class=\"setting\">\n" );
2229        websWrite( wp, "<div class=\"label\">VLAN%d Interface</div>\n",
2230                   count );
2231        sprintf( vlan_name, "vlanifname%d", count );
2232        showOptions( wp, vlan_name, buffer, tag );
2233        sprintf( vlan_name, "vlantag%d", count );
2234        websWrite( wp, "&nbsp;Tag Number&nbsp;" );
2235        websWrite( wp,
2236                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2237                   vlan_name, port );
2238        websWrite( wp,
2239                   "<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",
2240                   count );
2241        websWrite( wp, "</div>\n" );
2242        count++;
2243    }
2244    totalcount = count;
2245    int i;
2246
2247    for( i = count; i < realcount; i++ )
2248    {
2249        websWrite( wp, "<div class=\"setting\">\n" );
2250        websWrite( wp, "<div class=\"label\">VLAN%d Interface</div>\n", i );
2251        char vlan_name[32];
2252
2253        sprintf( vlan_name, "vlanifname%d", i );
2254        showOptions( wp, vlan_name, buffer, "" );
2255        sprintf( vlan_name, "vlantag%d", i );
2256        websWrite( wp, "&nbsp;Tag Number&nbsp;" );
2257        websWrite( wp,
2258                   "<input class=\"num\" name=\"%s\" size=\"5\" value=\"0\" />\n",
2259                   vlan_name );
2260        websWrite( wp,
2261                   "<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",
2262                   i );
2263        websWrite( wp, "</div>\n" );
2264        totalcount++;
2265    }
2266    char var[32];
2267
2268    sprintf( var, "%d", totalcount );
2269    nvram_set( "vlan_tagcount", var );
2270    websWrite( wp,
2271               "<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" );
2272}
2273
2274void ej_show_mdhcp( webs_t wp, int argc, char_t ** argv )
2275{
2276    char buffer[256];
2277    int count = 0;
2278    static char word[256];
2279    char *next, *wordlist;
2280
2281    websWrite( wp, "<h2>%s</h2>\n<fieldset>\n",
2282               live_translate( "networking.h5" ) );
2283    websWrite( wp, "<legend>%s</legend>\n",
2284               live_translate( "networking.legend5" ) );
2285
2286    memset( buffer, 0, 256 );
2287    getIfList( buffer, NULL );
2288    int totalcount = 0;
2289    int realcount = atoi( nvram_default_get( "mdhcpd_count", "0" ) );
2290
2291    wordlist = nvram_safe_get( "mdhcpd" );
2292    foreach( word, wordlist, next )
2293    {
2294        char *interface = word;
2295        char *dhcpon = interface;
2296
2297        interface = strsep( &dhcpon, ">" );
2298        char *start = dhcpon;
2299
2300        dhcpon = strsep( &start, ">" );
2301        char *max = start;
2302
2303        start = strsep( &max, ">" );
2304        char *leasetime = max;
2305
2306        max = strsep( &leasetime, ">" );
2307        if( !interface || !start || !dhcpon || !max || !leasetime )
2308            break;
2309        char vlan_name[32];
2310
2311        // interface
2312        char *ipaddr = nvram_nget( "%s_ipaddr", interface );
2313        char *netmask = nvram_nget( "%s_netmask", interface );
2314
2315        if( strlen( ipaddr ) > 0 && strlen( netmask ) > 0 )
2316        {
2317            websWrite( wp, "Interface %s: IP %s/%s\n", interface, ipaddr,
2318                       netmask );
2319        }
2320        websWrite( wp, "<div class=\"setting\">\n" );
2321        websWrite( wp, "<div class=\"label\">DHCP %d</div>\n", count );
2322        sprintf( vlan_name, "mdhcpifname%d", count );
2323        showOptions( wp, vlan_name, buffer, interface );
2324        // on off
2325        sprintf( vlan_name, "mdhcpon%d", count );
2326        showOptions( wp, vlan_name, "On Off", dhcpon );
2327        // start
2328        sprintf( vlan_name, "mdhcpstart%d", count );
2329        websWrite( wp, "&nbsp;Start&nbsp;" );
2330        websWrite( wp,
2331                   "<input class=\"num\" name=\"%s\" size=\"3\" value=\"%s\" />\n",
2332                   vlan_name, start );
2333        // max
2334        sprintf( vlan_name, "mdhcpmax%d", count );
2335        websWrite( wp, "&nbsp;Max&nbsp;" );
2336        websWrite( wp,
2337                   "<input class=\"num\" name=\"%s\" size=\"3\" value=\"%s\" />\n",
2338                   vlan_name, max );
2339        sprintf( vlan_name, "mdhcpleasetime%d", count );
2340        websWrite( wp, "&nbsp;Leasetime&nbsp;" );
2341        websWrite( wp,
2342                   "<input class=\"num\" name=\"%s\" size=\"5\" value=\"%s\" />\n",
2343                   vlan_name, leasetime );
2344        //
2345        websWrite( wp,
2346                   "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"mdhcp_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n",
2347                   count );
2348        websWrite( wp, "</div>\n" );
2349        count++;
2350    }
2351    totalcount = count;
2352    int i;
2353
2354    for( i = count; i < realcount; i++ )
2355    {
2356        char vlan_name[32];
2357
2358        // sprintf (mdhcp_name, "%s.%s", tag, port);
2359        websWrite( wp, "<div class=\"setting\">\n" );
2360        websWrite( wp, "<div class=\"label\">DHCP %d</div>\n", count );
2361        // interface
2362        sprintf( vlan_name, "mdhcpifname%d", count );
2363        showOptions( wp, vlan_name, buffer, "" );
2364        // on off
2365        sprintf( vlan_name, "mdhcpon%d", count );
2366        showOptions( wp, vlan_name, "On Off", "" );
2367        // start
2368        sprintf( vlan_name, "mdhcpstart%d", count );
2369        websWrite( wp, "&nbsp;Start&nbsp;" );
2370        websWrite( wp,
2371                   "<input class=\"num\" name=\"%s\" size=\"3\" value=\"%s\" />\n",
2372                   vlan_name, "100" );
2373        // max
2374        sprintf( vlan_name, "mdhcpmax%d", count );
2375        websWrite( wp, "&nbsp;Max&nbsp;" );
2376        websWrite( wp,
2377                   "<input class=\"num\" name=\"%s\" size=\"3\" value=\"%s\" />\n",
2378                   vlan_name, "50" );
2379        sprintf( vlan_name, "mdhcpleasetime%d", count );
2380        websWrite( wp, "&nbsp;Leasetime&nbsp;" );
2381        websWrite( wp,
2382                   "<input class=\"num\" name=\"%s\" size=\"5\" value=\"%s\" />\n",
2383                   vlan_name, "3600" );
2384        websWrite( wp,
2385                   "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.del + \"\\\" onclick=\\\"mdhcp_del_submit(this.form,%d)\\\" />\");\n//]]>\n</script>\n",
2386                   i );
2387        websWrite( wp, "</div>\n" );
2388        totalcount++;
2389    }
2390    char var[32];
2391
2392    sprintf( var, "%d", totalcount );
2393    nvram_set( "mdhcpd_count", var );
2394    websWrite( wp,
2395               "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" value=\\\"\" + sbutton.add + \"\\\" onclick=\\\"mdhcp_add_submit(this.form)\\\" />\");\n//]]>\n</script>\n" );
2396    websWrite( wp, "</fieldset><br />\n" );
2397
2398}
2399
2400void ej_show_bridgenames( webs_t wp, int argc, char_t ** argv )
2401{
2402    char buffer[256];
2403    int count = 0;
2404    static char word[256];
2405    char *next, *wordlist;
2406
2407    memset( buffer, 0, 256 );
2408    getIfList( buffer, NULL );
2409    int realcount = atoi( nvram_default_get( "bridges_count", "0" ) );
2410
2411    wordlist = nvram_safe_get( "bridges" );
2412    foreach( word, wordlist, next )
2413    {
2414
2415        char *stp = word;
2416        char *bridge = strsep( &stp, ">" );
2417        char *prio = stp;
2418
2419        stp = strsep( &prio, ">" );
2420        char *mtu = prio;
2421
2422        prio = strsep( &mtu, ">" );
2423        if( !prio )
2424        {
2425            prio = mtu;
2426            mtu = "1500";
2427        }
2428
2429/*      char *stp = word;
2430        char *bridge = strsep( &stp, ">" );
2431        char *mtu = stp;
2432        char *prio = strsep( &mtu, ">" );
2433*/
2434        if( !bridge || !stp )
2435            break;
2436
2437        char vlan_name[32];
2438
2439        websWrite( wp, "<div class=\"setting\">\n" );
2440        websWrite( wp, "<div class=\"label\">Bridge %d</div>\n", count );
2441        sprintf( vlan_name, "bridgename%d", count );
2442        websWrite( wp,
2443                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2444                   vlan_name, bridge );
2445        websWrite( wp, "&nbsp;STP&nbsp;" );
2446        sprintf( vlan_name, "bridgestp%d", count );
2447        showOptions( wp, vlan_name, "On Off", stp );
2448        websWrite( wp, "&nbsp;Prio&nbsp;" );
2449        sprintf( vlan_name, "bridgeprio%d", count );
2450        websWrite( wp,
2451                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2452                   vlan_name, prio != NULL ? prio : "32768" );
2453        websWrite( wp, "&nbsp;MTU&nbsp;" );
2454        sprintf( vlan_name, "bridgemtu%d", count );
2455        websWrite( wp,
2456                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2457                   vlan_name, mtu != NULL ? mtu : "1500" );
2458        websWrite( wp,
2459                   "<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",
2460                   count );
2461        websWrite( wp, "</div>\n" );
2462        show_ipnetmask( wp, bridge );
2463        count++;
2464    }
2465    int i;
2466    int totalcount = count;
2467
2468    for( i = count; i < realcount; i++ )
2469    {
2470        char vlan_name[32];
2471
2472        websWrite( wp, "<div class=\"setting\">\n" );
2473        websWrite( wp, "<div class=\"label\">Bridge %d</div>\n", i );
2474        sprintf( vlan_name, "bridgename%d", i );
2475        websWrite( wp, "<input class=\"num\" name=\"%s\"size=\"5\" />\n",
2476                   vlan_name );
2477        websWrite( wp, "&nbsp;STP&nbsp;" );
2478        sprintf( vlan_name, "bridgestp%d", i );
2479        showOptions( wp, vlan_name, "On Off", "On" );
2480        websWrite( wp, "&nbsp;Prio&nbsp;" );
2481        sprintf( vlan_name, "bridgeprio%d", i );
2482        websWrite( wp,
2483                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2484                   vlan_name, "32768" );
2485        websWrite( wp, "&nbsp;MTU&nbsp;" );
2486        sprintf( vlan_name, "bridgemtu%d", count );
2487        websWrite( wp,
2488                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2489                   vlan_name, "1500" );
2490        websWrite( wp,
2491                   "<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",
2492                   i );
2493        websWrite( wp, "</div>\n" );
2494        totalcount++;
2495    }
2496    websWrite( wp,
2497               "<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" );
2498    char var[32];
2499
2500    sprintf( var, "%d", totalcount );
2501    nvram_set( "bridges_count", var );
2502}
2503
2504void ej_show_bridgetable( webs_t wp, int argc, char_t ** argv )
2505{
2506#ifdef HAVE_MICRO               // brctl N/A in micro
2507    return;
2508#endif
2509
2510    FILE *f;
2511    char buf[128];
2512    char brname[32];
2513    char brstp[8];
2514    char brif[16];
2515    int count = 0;
2516
2517    system2( "brctl show > /tmp/.brtable" );
2518
2519    if( ( f = fopen( "/tmp/.brtable", "r" ) ) != NULL )
2520    {
2521
2522        while( fgets( buf, sizeof( buf ), f ) )
2523        {
2524
2525            if( count )         // skip line 0
2526            {
2527                strcpy( brname, "" );
2528                strcpy( brstp, "" );
2529                strcpy( brif, "" );
2530
2531                if( strncmp( buf, "\t\t\t", 3 ) != 0 )
2532                {
2533                    if( count != 1 )
2534                        websWrite( wp, "\'," ); // close
2535                    sscanf( buf, "%s %*s %s %s", brname, brstp, brif );
2536                    websWrite( wp, "\'%s\',\'%s\',\'%s ", brname, brstp,
2537                               brif );
2538                }
2539                else
2540                {
2541                    sscanf( buf, "%s", brif );
2542                    websWrite( wp, "%s ", brif );
2543                }
2544            }
2545            count++;
2546        }
2547
2548        websWrite( wp, "\'" );  // close
2549        fclose( f );
2550        unlink( "/tmp/.brtable" );
2551    }
2552    return;
2553}
2554
2555void ej_show_bridgeifnames( webs_t wp, int argc, char_t ** argv )
2556{
2557    char bufferif[512];
2558    char bufferif2[256];
2559    char finalbuffer[512];
2560    int count = 0;
2561    static char word[256];
2562    char *next, *wordlist;
2563
2564    memset( bufferif, 0, 512 );
2565    memset( bufferif2, 0, 256 );
2566    getIfList( bufferif, "eth" );
2567#ifdef HAVE_GATEWORX
2568    getIfList( bufferif2, "ixp" );
2569    sprintf( bufferif, "%s %s", bufferif, bufferif2 );
2570#endif
2571
2572    memset( bufferif2, 0, 256 );
2573    getIfList( bufferif2, "vlan" );
2574    sprintf( bufferif, "%s %s", bufferif, bufferif2 );
2575
2576    memset( bufferif2, 0, 256 );
2577    getIfList( bufferif2, "wl" );
2578    sprintf( bufferif, "%s %s", bufferif, bufferif2 );
2579
2580    memset( bufferif2, 0, 256 );
2581    getIfList( bufferif2, "ofdm" );
2582    sprintf( bufferif, "%s %s", bufferif, bufferif2 );
2583#ifdef HAVE_RT2880
2584    memset( bufferif2, 0, 256 );
2585    getIfList( bufferif2, "ra" );
2586    sprintf( bufferif, "%s %s", bufferif, bufferif2 );
2587#endif
2588    memset( bufferif2, 0, 256 );
2589    getIfList( bufferif2, "br" );
2590    foreach( word, bufferif2, next )
2591    {
2592        if( contains( word, '.' ) )
2593            sprintf( bufferif, "%s %s", bufferif, word );
2594    }
2595    int i;
2596
2597#ifdef HAVE_MADWIFI
2598    memset( bufferif2, 0, 256 );
2599    getIfList( bufferif2, "ath" );
2600    foreach( word, bufferif2, next )
2601    {
2602        if( contains( word, '.' ) )
2603            sprintf( bufferif, "%s %s", bufferif, word );
2604    }
2605    int c = getifcount( "wifi" );
2606
2607    for( i = 0; i < c; i++ )
2608    {
2609        char ath[32];
2610
2611        sprintf( ath, "ath%d_bridged", i );
2612        if( nvram_default_match( ath, "1", "1" ) )
2613        {
2614            sprintf( bufferif, "%s ath%d", bufferif, i );
2615            char vifs[32];
2616
2617            sprintf( vifs, "ath%d_vifs", i );
2618            sprintf( bufferif, "%s %s", bufferif, nvram_safe_get( vifs ) );
2619        }
2620    }
2621#endif
2622#ifdef HAVE_BONDING
2623    c = atoi( nvram_default_get( "bonding_number", "1" ) );
2624    for( i = 0; i < c; i++ )
2625    {
2626        sprintf( bufferif, "%s bond%d", bufferif, i );
2627    }
2628#endif
2629#ifdef HAVE_EOP_TUNNEL
2630    for( i = 1; i < 11; i++ )
2631    {
2632        char EOP[32];
2633
2634        if( nvram_nmatch( "1", "oet%d_en", i ) && nvram_nmatch( "1", "oet%d_bridged", i ) )
2635        {
2636            sprintf( EOP, "oet%d", i );
2637            sprintf( bufferif, "%s %s", bufferif, EOP );
2638        }
2639    }
2640#endif
2641    char buffer[256];
2642
2643    memset( buffer, 0, 256 );
2644    getIfList( buffer, "br" );
2645
2646    memset( finalbuffer, 0, 256 );
2647    foreach( word, buffer, next )
2648    {
2649        if( !contains( word, '.' ) )
2650            sprintf( finalbuffer, "%s %s", finalbuffer, word );
2651    }
2652
2653    int realcount = atoi( nvram_default_get( "bridgesif_count", "0" ) );
2654
2655    wordlist = nvram_safe_get( "bridgesif" );
2656    foreach( word, wordlist, next )
2657    {
2658        char *port = word;
2659        char *tag = strsep( &port, ">" );
2660        char *prio = port;
2661
2662        strsep( &prio, ">" );
2663        if( !tag || !port )
2664            break;
2665        char vlan_name[32];
2666
2667        websWrite( wp, "<div class=\"setting\">\n" );
2668        websWrite( wp, "<div class=\"label\">Assignment %d</div>\n", count );
2669        sprintf( vlan_name, "bridge%d", count );
2670        showOptions( wp, vlan_name, finalbuffer, tag );
2671        websWrite( wp, "&nbsp;Interface&nbsp;" );
2672        sprintf( vlan_name, "bridgeif%d", count );
2673        showOptions( wp, vlan_name, bufferif, port );
2674        websWrite( wp, "&nbsp;Prio&nbsp;" );
2675        sprintf( vlan_name, "bridgeifprio%d", count );
2676        websWrite( wp,
2677                   "<input class=\"num\" name=\"%s\"size=\"3\" value=\"%s\" />\n",
2678                   vlan_name, prio != NULL ? prio : "63" );
2679        websWrite( wp,
2680                   "<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",
2681                   count );
2682        websWrite( wp, "</div>\n" );
2683        count++;
2684    }
2685    int totalcount = count;
2686
2687    for( i = count; i < realcount; i++ )
2688    {
2689        char vlan_name[32];
2690
2691        websWrite( wp, "<div class=\"setting\">\n" );
2692        websWrite( wp, "<div class=\"label\">Assignment %d</div>\n", i );
2693        sprintf( vlan_name, "bridge%d", i );
2694        showOptions( wp, vlan_name, finalbuffer, "" );
2695        websWrite( wp, "&nbsp;Interface&nbsp;" );
2696        sprintf( vlan_name, "bridgeif%d", i );
2697        showOptions( wp, vlan_name, bufferif, "" );
2698        websWrite( wp, "&nbsp;Prio&nbsp;" );
2699        sprintf( vlan_name, "bridgeifprio%d", i );
2700        websWrite( wp,
2701                   "<input class=\"num\" name=\"%s\"size=\"5\" value=\"%s\" />\n",
2702                   vlan_name, "63" );
2703        websWrite( wp,
2704                   "<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",
2705                   i );
2706        websWrite( wp, "</div>\n" );
2707        totalcount++;
2708    }
2709    websWrite( wp,
2710               "<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" );
2711    char var[32];
2712
2713    sprintf( var, "%d", totalcount );
2714    nvram_set( "bridgesif_count", var );
2715}
2716
2717#endif
2718#if 0
2719static void
2720showDynOption( webs_t wp, char *propname, char *nvname, char *options[],
2721               char *names[] )
2722{
2723    int i;
2724
2725    websWrite( wp, "<div class=\"setting\">\n" );
2726    websWrite( wp,
2727               "<div class=\"label\">%s</div><select name=\"%s\">\n",
2728               propname, nvname );
2729    for( i = 0; options[i] != NULL; i++ )
2730    {
2731        websWrite( wp,
2732                   "<option value=\"%s\" %s>Off</option>\n",
2733                   names[i], nvram_match( nvname,
2734                                          options[i] ) ?
2735                   "selected=\"selected\"" : "" );
2736    }
2737    websWrite( wp, "</div>\n" );
2738
2739}
2740#endif
2741#ifdef HAVE_MSSID
2742
2743static void show_channel( webs_t wp, char *dev, char *prefix, int type )
2744{
2745    char wl_mode[16];
2746
2747    sprintf( wl_mode, "%s_mode", prefix );
2748    char wl_net_mode[16];
2749
2750    sprintf( wl_net_mode, "%s_net_mode", prefix );
2751    if( nvram_match( wl_net_mode, "disabled" ) )
2752        return;
2753    if( nvram_match( wl_mode, "ap" ) || nvram_match( wl_mode, "wdsap" )
2754        || nvram_match( wl_mode, "infra" ) )
2755    {
2756        char wl_channel[16];
2757
2758        sprintf( wl_channel, "%s_channel", prefix );
2759        char wl_wchannel[16];
2760
2761        sprintf( wl_wchannel, "%s_wchannel", prefix );
2762        char wl_nbw[16];
2763        nvram_default_get(wl_wchannel,"0");
2764        sprintf( wl_nbw, "%s_nbw", prefix );
2765
2766        websWrite( wp, "<div class=\"setting\">\n" );
2767        websWrite( wp,
2768                   "<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",
2769                   wl_channel );
2770#ifdef HAVE_MADWIFI
2771        struct wifi_channels *chan;
2772        char cn[32];
2773        char fr[32];
2774
2775        chan = list_channels( prefix );
2776        if( chan == NULL )
2777            chan = list_channels( dev );
2778        if( chan != NULL )
2779        {
2780            // int cnt = getchannelcount ();
2781            websWrite( wp,
2782                       "document.write(\"<option value=\\\"0\\\" %s>\" + share.auto + \"</option>\");\n",
2783                       nvram_match( wl_channel,
2784                                    "0" ) ? "selected=\\\"selected\\\"" :
2785                       "" );
2786            int i = 0;
2787
2788            while( chan[i].freq != -1 )
2789            {
2790                cprintf( "%d\n", chan[i].channel );
2791                cprintf( "%d\n", chan[i].freq );
2792
2793                sprintf( cn, "%d", chan[i].channel );
2794                sprintf( fr, "%d", chan[i].freq );
2795                websWrite( wp,
2796                           "document.write(\"<option value=\\\"%s\\\" %s>%s - %d MHz</option>\");\n",
2797                           fr, nvram_match( wl_channel,
2798                                            fr ) ? "selected=\\\"selected\\\""
2799                           : "", cn,
2800                           ( chan[i].freq + get_wifioffset( prefix ) ) );
2801                // free (chan[i].freq);
2802                i++;
2803            }
2804            free( chan );
2805        }
2806#else
2807        int instance = 0;
2808
2809        if( !strcmp( prefix, "wl1" ) )
2810            instance = 1;
2811        if( type == 1 && !nvram_match( wl_net_mode, "g-only" )
2812            && !nvram_match( wl_net_mode, "a-only" )
2813            && !nvram_match( wl_net_mode, "na-only" )
2814            && !nvram_match( wl_net_mode, "bg-mixed" )
2815            && nvram_match( wl_nbw, "40" ) )
2816        {
2817            int ch = atoi( nvram_nget( "wl%d_wchannel", instance ) );
2818
2819            websWrite( wp, "var max_channel = 2;\n" );
2820            websWrite( wp, "var wl%d_channel = '%s';\n", instance,
2821                       nvram_safe_get( wl_wchannel ) );
2822            websWrite( wp,
2823                       "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" );
2824            char *sel = "";
2825
2826            if( nvram_nmatch( "lower", "wl%d_nctrlsb", instance ) )
2827                sel = "selected";
2828
2829            websWrite( wp,
2830                       " document.write(\"<option value=%d %s>%d - \"+freq[%d]+\" GHz</option>\");\n",
2831                       ch - 2, sel, ch - 2, ch - 2 );
2832            if( nvram_nmatch( "upper", "wl%d_nctrlsb", instance ) )
2833                sel = "selected";
2834            websWrite( wp,
2835                       " document.write(\"<option value=%d %s>%d - \"+freq[%d]+\" GHz</option>\");\n",
2836                       ch + 2, sel, ch + 2, ch + 2 );
2837
2838        }
2839        else
2840        {
2841
2842            unsigned int chanlist[128];
2843            char *ifn = get_wl_instance_name( instance );
2844            int chancount = getchannels( chanlist, ifn );
2845
2846//          websWrite( wp, "var max_channel = %d;\n", chancount );
2847//          websWrite( wp, "var wl%d_channel = '%s';\n", instance, nvram_safe_get( wl_channel ) );
2848//          websWrite( wp, "var offset = %d;\n", chanlist[0] );
2849//          websWrite( wp, "var buf = \"\";\n" );
2850//      websWrite( wp, "var freq = new Array(\"Auto\"" );
2851            int i;
2852
2853            websWrite( wp,
2854                       "document.write(\"<option value=\\\"0\\\" %s>\" + share.auto + \"</option>\");\n",
2855                       nvram_nmatch( "0", "%s_channel",
2856                                     prefix ) ? "selected=\\\"selected\\\"" :
2857                       "" );
2858            for( i = 0; i < chancount; i++ )
2859            {
2860                float ofs;
2861
2862                if( chanlist[i] < 25 )
2863                    ofs = 2.407f;
2864                else
2865                    ofs = 5.000f;
2866                ofs += ( float )( chanlist[i] * 0.005f );
2867                if( ofs == 2.477f )
2868                    ofs = 2.484f;       // fix: ch 14 is 2.484, not 2.477 GHz
2869//              websWrite( wp, ", \"%0.3f\"", ofs );
2870                char channelstring[32];
2871
2872                sprintf( channelstring, "%d", chanlist[i] );
2873                websWrite( wp,
2874                           "document.write(\"<option value=\\\"%d\\\" %s>%d - %0.3f GHz</option>\");\n",
2875                           chanlist[i], nvram_nmatch( channelstring,
2876                                                      "%s_channel",
2877                                                      prefix ) ?
2878                           "selected=\\\"selected\\\"" : "", chanlist[i],
2879                           ofs );
2880            }
2881//          websWrite( wp, ");\n" );
2882//          websWrite( wp, "for(i=0; i<=max_channel ; i++) {\n" );
2883//          websWrite( wp, "    if(i == wl%d_channel) buf = \"selected\";\n",
2884//                     instance );
2885//          websWrite( wp, "    else buf = \"\";\n" );
2886//          websWrite( wp, "    if (i==0)\n" );
2887//          websWrite( wp,
2888//                     "                document.write(\"<option value=\"+i+\" \"+buf+\">\" + share.auto + \"</option>\");\n" );
2889//          websWrite( wp, "    else\n" );
2890//          websWrite( wp,
2891//                     "                document.write(\"<option value=\"+i+\" \"+buf+\">\"+(i+offset-1)+\" - \"+freq[i]+\" GHz</option>\");\n" );
2892//          websWrite( wp, "}\n" );
2893        }
2894#endif
2895        websWrite( wp, "//]]>\n</script></select></div>\n" );
2896    }
2897}
2898
2899#ifdef HAVE_MADWIFI
2900static char *ag_rates[] = { "6", "9", "12", "18", "24", "36", "48", "54" };
2901static char *turbo_rates[] =
2902    { "12", "18", "24", "36", "48", "72", "96", "108" };
2903static char *b_rates[] = { "1", "2", "5.5", "11" };
2904static char *bg_rates[] =
2905    { "1", "2", "5.5", "6", "9", "11", "12", "18", "24", "36", "48", "54" };
2906// static char *g_rates[] = { "1", "2", "5.5", "11", "12", "18", "24", "36",
2907// "48", "54" };
2908//static char *xr_rates[] =
2909//    { "0.25", "0.5", "1", "2", "3", "6", "9", "12", "18", "24", "36", "48",
2910//    "54"
2911//};
2912static char *half_rates[] = { "3", "4.5", "6", "9", "12", "18", "24", "27" };
2913static char *quarter_rates[] =
2914    { "1.5", "2", "3", "4.5", "6", "9", "12", "13.5" };
2915
2916void show_rates( webs_t wp, char *prefix, int maxrate )
2917{
2918    websWrite( wp, "<div class=\"setting\">\n" );
2919    if( maxrate )
2920    {
2921        websWrite( wp,
2922                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label21)</script></div>\n" );
2923        websWrite( wp, "<select name=\"%s_maxrate\">\n", prefix );
2924    }
2925    else
2926    {
2927        websWrite( wp,
2928                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label23)</script></div>\n" );
2929        websWrite( wp, "<select name=\"%s_minrate\">\n", prefix );
2930    }
2931    websWrite( wp, "<script type=\"text/javascript\">\n" );
2932    websWrite( wp, "//<![CDATA[\n" );
2933    char srate[32];
2934
2935    sprintf( srate, "%s_minrate", prefix );
2936    char mxrate[32];
2937
2938    sprintf( mxrate, "%s_maxrate", prefix );
2939    websWrite( wp,
2940               "document.write(\"<option value=\\\"0\\\" %s >\" + share.auto + \"</option>\");\n",
2941               nvram_match( srate, "0" ) ? "selected" : "" );
2942    websWrite( wp, "//]]>\n" );
2943    websWrite( wp, "</script>\n" );
2944    char **rate;
2945    char **showrates = NULL;
2946    int len;
2947    char mode[32];
2948    char bw[16];
2949
2950    sprintf( bw, "%s_channelbw", prefix );
2951
2952    sprintf( mode, "%s_net_mode", prefix );
2953    if( nvram_match( mode, "b-only" ) )
2954    {
2955        rate = b_rates;
2956        len = sizeof( b_rates ) / sizeof( char * );
2957    }
2958    if( nvram_match( mode, "g-only" ) )
2959    {
2960        rate = ag_rates;
2961        len = sizeof( ag_rates ) / sizeof( char * );
2962        if( nvram_match( bw, "40" ) )
2963        {
2964            showrates = turbo_rates;
2965        }
2966        if( nvram_match( bw, "10" ) )
2967        {
2968            rate = half_rates;
2969            len = sizeof( half_rates ) / sizeof( char * );
2970        }
2971        if( nvram_match( bw, "5" ) )
2972        {
2973            rate = quarter_rates;
2974            len = sizeof( quarter_rates ) / sizeof( char * );
2975        }
2976    }
2977    if( nvram_match( mode, "a-only" ) )
2978    {
2979        rate = ag_rates;
2980        len = sizeof( ag_rates ) / sizeof( char * );
2981        if( nvram_match( bw, "40" ) )
2982        {
2983            showrates = turbo_rates;
2984        }
2985        if( nvram_match( bw, "10" ) )
2986        {
2987            rate = half_rates;
2988            len = sizeof( half_rates ) / sizeof( char * );
2989        }
2990        if( nvram_match( bw, "5" ) )
2991        {
2992            rate = quarter_rates;
2993            len = sizeof( quarter_rates ) / sizeof( char * );
2994        }
2995    }
2996    if( nvram_match( mode, "bg-mixed" ) )
2997    {
2998        rate = bg_rates;
2999        len = sizeof( bg_rates ) / sizeof( char * );
3000        if( nvram_match( bw, "10" ) )
3001        {
3002            rate = half_rates;
3003            len = sizeof( half_rates ) / sizeof( char * );
3004        }
3005        if( nvram_match( bw, "5" ) )
3006        {
3007            rate = quarter_rates;
3008            len = sizeof( quarter_rates ) / sizeof( char * );
3009        }
3010    }
3011    if( nvram_match( mode, "mixed" ) )
3012    {
3013        rate = bg_rates;
3014        len = sizeof( bg_rates ) / sizeof( char * );
3015        if( nvram_match( bw, "40" ) )
3016        {
3017            rate = ag_rates;
3018            len = sizeof( ag_rates ) / sizeof( char * );
3019            showrates = turbo_rates;
3020        }
3021        if( nvram_match( bw, "10" ) )
3022        {
3023            rate = half_rates;
3024            len = sizeof( half_rates ) / sizeof( char * );
3025        }
3026        if( nvram_match( bw, "5" ) )
3027        {
3028            rate = quarter_rates;
3029            len = sizeof( quarter_rates ) / sizeof( char * );
3030        }
3031    }
3032    int i;
3033
3034    for( i = 0; i < len; i++ )
3035    {
3036        if( maxrate )
3037        {
3038            int offset = 0;
3039
3040            if( nvram_match( mode, "g-only" ) && nvram_match( bw, "20" ) )
3041                offset = 4;
3042            char comp[32];
3043
3044            sprintf( comp, "%d", i + 1 + offset );
3045            if( showrates )
3046                websWrite( wp, "<option value=\"%d\" %s >%s Mbps</option>\n",
3047                           i + 1 + offset, nvram_match( mxrate,
3048                                                        comp ) ? "selected" :
3049                           "", showrates[i] );
3050            else
3051                websWrite( wp, "<option value=\"%d\" %s >%s Mbps</option>\n",
3052                           i + 1 + offset, nvram_match( mxrate,
3053                                                        comp ) ? "selected" :
3054                           "", rate[i] );
3055        }
3056        else
3057        {
3058            int offset = 0;
3059
3060            if( nvram_match( mode, "g-only" ) && nvram_match( bw, "20" ) )
3061                offset = 4;
3062            char comp[32];
3063
3064            sprintf( comp, "%d", i + 1 + offset );
3065            if( showrates )
3066                websWrite( wp, "<option value=\"%d\" %s >%s Mbps</option>\n",
3067                           i + 1 + offset, nvram_match( srate,
3068                                                        comp ) ? "selected" :
3069                           "", showrates[i] );
3070            else
3071                websWrite( wp, "<option value=\"%d\" %s >%s Mbps</option>\n",
3072                           i + 1 + offset, nvram_match( srate,
3073                                                        comp ) ? "selected" :
3074                           "", rate[i] );
3075
3076        }
3077    }
3078    websWrite( wp, "</select>\n" );
3079    websWrite( wp, "<span class=\"default\">\n" );
3080    websWrite( wp, "<script type=\"text/javascript\">\n" );
3081    websWrite( wp, "//<![CDATA[\n" );
3082    websWrite( wp,
3083               "document.write(\"(\" + share.deflt + \": \" + share.auto + \")\");\n" );
3084    websWrite( wp, "//]]\n" );
3085    websWrite( wp, "</script></span></div>\n" );
3086
3087}
3088#endif
3089static void show_netmode( webs_t wp, char *prefix )
3090{
3091    char wl_net_mode[16];
3092
3093    sprintf( wl_net_mode, "%s_net_mode", prefix );
3094
3095    websWrite( wp, "<div class=\"setting\">\n" );
3096    websWrite( wp,
3097               "<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",
3098               wl_net_mode, wl_net_mode );
3099    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
3100    websWrite( wp,
3101               "document.write(\"<option value=\\\"disabled\\\" %s>\" + share.disabled + \"</option>\");\n",
3102               nvram_match( wl_net_mode,
3103                            "disabled" ) ? "selected=\\\"selected\\\"" : "" );
3104    websWrite( wp,
3105               "document.write(\"<option value=\\\"mixed\\\" %s>\" + wl_basic.mixed + \"</option>\");\n",
3106               nvram_match( wl_net_mode,
3107                            "mixed" ) ? "selected=\\\"selected\\\"" : "" );
3108    if( has_mimo( prefix ) )
3109    {
3110        websWrite( wp,
3111                   "document.write(\"<option value=\\\"bg-mixed\\\" %s>\" + wl_basic.bg + \"</option>\");\n",
3112                   nvram_match( wl_net_mode,
3113                                "bg-mixed" ) ? "selected=\\\"selected\\\"" :
3114                   "" );
3115    }
3116#ifdef HAVE_WHRAG108
3117    if( !strcmp( prefix, "ath1" ) )
3118#endif
3119#ifdef HAVE_TW6600
3120        if( !strcmp( prefix, "ath1" ) )
3121#endif
3122            websWrite( wp,
3123                       "document.write(\"<option value=\\\"b-only\\\" %s>\" + wl_basic.b + \"</option>\");\n",
3124                       nvram_match( wl_net_mode,
3125                                    "b-only" ) ? "selected=\\\"selected\\\"" :
3126                       "" );
3127#ifdef HAVE_MADWIFI
3128#ifdef HAVE_WHRAG108
3129    if( !strcmp( prefix, "ath1" ) )
3130#endif
3131#ifdef HAVE_TW6600
3132        if( !strcmp( prefix, "ath1" ) )
3133#endif
3134            websWrite( wp,
3135                       "document.write(\"<option value=\\\"g-only\\\" %s>\" + wl_basic.g + \"</option>\");\n",
3136                       nvram_match( wl_net_mode,
3137                                    "g-only" ) ? "selected=\\\"selected\\\"" :
3138                       "" );
3139#ifdef HAVE_WHRAG108
3140    if( !strcmp( prefix, "ath1" ) )
3141#endif
3142#ifdef HAVE_TW6600
3143        if( !strcmp( prefix, "ath1" ) )
3144#endif
3145#ifndef HAVE_LS5
3146            websWrite( wp,
3147                       "document.write(\"<option value=\\\"bg-mixed\\\" %s>\" + wl_basic.bg + \"</option>\");\n",
3148                       nvram_match( wl_net_mode,
3149                                    "bg-mixed" ) ? "selected=\\\"selected\\\""
3150                       : "" );
3151#endif
3152#else
3153#ifdef HAVE_WHRAG108
3154    if( !strcmp( prefix, "ath1" ) )
3155#endif
3156#ifndef HAVE_LS5
3157        websWrite( wp,
3158                   "document.write(\"<option value=\\\"g-only\\\" %s>\" + wl_basic.g + \"</option>\");\n",
3159                   nvram_match( wl_net_mode,
3160                                "g-only" ) ? "selected=\\\"selected\\\"" :
3161                   "" );
3162#endif
3163#endif
3164    if( has_mimo( prefix ) )
3165    {
3166        websWrite( wp,
3167                   "document.write(\"<option value=\\\"n-only\\\" %s>\" + wl_basic.n + \"</option>\");\n",
3168                   nvram_match( wl_net_mode,
3169                                "n-only" ) ? "selected=\\\"selected\\\"" :
3170                   "" );
3171    }
3172#if !defined(HAVE_FONERA) && !defined(HAVE_LS2) && !defined(HAVE_MERAKI)
3173#ifndef HAVE_MADWIFI
3174
3175    if( nvram_nmatch( "ga", "%s_phytypes", prefix )
3176        || nvram_nmatch( "a", "%s_phytypes", prefix ) )
3177        websWrite( wp,
3178                   "document.write(\"<option value=\\\"a-only\\\" %s>\" + wl_basic.a + \"</option>\");\n",
3179                   nvram_match( wl_net_mode,
3180                                "a-only" ) ? "selected=\\\"selected\\\"" :
3181                   "" );
3182
3183    if( has_mimo( prefix ) )
3184    {
3185        char band[64];
3186
3187        sprintf( band, "%s_bandlist", prefix );
3188        char *b = nvram_safe_get( band );
3189
3190        if( contains( b, 'a' ) )
3191        {
3192            websWrite( wp,
3193                       "document.write(\"<option value=\\\"a-only\\\" %s>\" + wl_basic.a + \"</option>\");\n",
3194                       nvram_match( wl_net_mode,
3195                                    "a-only" ) ? "selected=\\\"selected\\\"" :
3196                       "" );
3197            websWrite( wp,
3198                       "document.write(\"<option value=\\\"na-only\\\" %s>\" + wl_basic.na + \"</option>\");\n",
3199                       nvram_match( wl_net_mode,
3200                                    "na-only" ) ? "selected=\\\"selected\\\""
3201                       : "" );
3202        }
3203    }
3204#else
3205#if HAVE_WHRAG108
3206    if( !strcmp( prefix, "ath0" ) )
3207#endif
3208#ifdef HAVE_TW6600
3209        if( !strcmp( prefix, "ath0" ) )
3210#endif
3211            websWrite( wp,
3212                       "document.write(\"<option value=\\\"a-only\\\" %s>\" + wl_basic.a + \"</option>\");\n",
3213                       nvram_match( wl_net_mode,
3214                                    "a-only" ) ? "selected=\\\"selected\\\"" :
3215                       "" );
3216#endif
3217
3218#endif
3219    websWrite( wp, "//]]>\n</script>\n" );
3220    websWrite( wp, "</select>\n" );
3221    websWrite( wp, "</div>\n" );
3222
3223#ifdef HAVE_RT2880
3224if (nvram_nmatch("n-only","%s_net_mode",prefix))
3225   {
3226    char wl_greenfield[32];
3227    sprintf(wl_greenfield,"%s_greenfield",prefix);
3228    websWrite( wp, "<div class=\"setting\">\n" );
3229    websWrite( wp,
3230               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label7)</script></div><select name=\"%s\" >\n",
3231               wl_greenfield );
3232    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
3233    websWrite( wp,
3234               "document.write(\"<option value=\\\"0\\\" %s>\" + wl_basic.mixed + \"</option>\");\n",
3235               nvram_default_match( wl_greenfield,"0","0" ) ? "selected=\\\"selected\\\"" : "");
3236    websWrite( wp,
3237               "document.write(\"<option value=\\\"1\\\" %s>\" + wl_basic.greenfield + \"</option>\");\n",
3238               nvram_default_match( wl_greenfield,
3239                            "1","0" ) ? "selected=\\\"selected\\\"" : "");
3240    websWrite( wp, "//]]>\n</script>\n" );
3241    websWrite( wp, "</select>\n" );
3242    websWrite( wp, "</div>\n" );
3243    }
3244#endif
3245}
3246
3247#ifdef HAVE_MADWIFI
3248static void showrtssettings( webs_t wp, char *var )
3249{
3250    char ssid[32];
3251    char vvar[32];
3252
3253    strcpy( vvar, var );
3254    rep( vvar, '.', 'X' );
3255    sprintf( ssid, "%s_rts", var );
3256    websWrite( wp,
3257               "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.rts)</script></div>\n" );
3258    websWrite( wp,
3259               "<input class=\"spaceradio\" type=\"radio\" value=\"1\" onclick=\"show_layer_ext(this, '%s_idrts', true);\" name=\"%s_rts\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input>\n",
3260               vvar, var, nvram_default_match( ssid, "1",
3261                                               "0" ) ? "checked=\"checked\"" :
3262               "" );
3263    websWrite( wp,
3264               "<input class=\"spaceradio\" type=\"radio\" value=\"0\" onclick=\"show_layer_ext(this, '%s_idrts', false);\" name=\"%s_rts\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>&nbsp;\n",
3265               vvar, var, nvram_default_match( ssid, "0",
3266                                               "0" ) ? "checked=\"checked\"" :
3267               "" );
3268    websWrite( wp, "</div>\n" );
3269
3270    websWrite( wp, "<div id=\"%s_idrts\">\n", vvar );
3271    websWrite( wp, "<div class=\"setting\">\n" );
3272    websWrite( wp,
3273               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.rtsvalue)</script></div>\n" );
3274    char ip[32];
3275
3276    sprintf( ip, "%s_rtsvalue", var );
3277    websWrite( wp,
3278               "<input class=\"num\" maxlength=\"4\" size=\"4\" onblur=\"valid_range(this,1,2346,share.ip)\" name=\"%s_rtsvalue\" value=\"%s\" />",
3279               var, nvram_default_get( ip, "2346" ) );
3280    websWrite( wp, "</div>\n" );
3281    websWrite( wp, "</div>\n" );
3282
3283    websWrite( wp, "<script>\n//<![CDATA[\n " );
3284    websWrite( wp,
3285               "show_layer_ext(document.getElementsByName(\"%s_rts\"), \"%s_idrts\", %s);\n",
3286               var, vvar, nvram_match( ssid, "1" ) ? "true" : "false" );
3287    websWrite( wp, "//]]>\n</script>\n" );
3288
3289}
3290#endif
3291static void showbridgesettings( webs_t wp, char *var, int mcast , int dual)
3292{
3293
3294    char ssid[32];
3295
3296    sprintf( ssid, "%s_bridged", var );
3297    char vvar[32];
3298
3299    strcpy( vvar, var );
3300    rep( vvar, '.', 'X' );
3301    websWrite( wp,
3302               "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.network)</script></div>\n" );
3303    websWrite( wp,
3304               "<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>&nbsp;\n",
3305               vvar, var, nvram_default_match( ssid, "0",
3306                                               "1" ) ? "checked=\"checked\"" :
3307               "" );
3308    websWrite( wp,
3309               "<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",
3310               vvar, var, nvram_default_match( ssid, "1",
3311                                               "1" ) ? "checked=\"checked\"" :
3312               "" );
3313    websWrite( wp, "</div>\n" );
3314
3315    websWrite( wp, "<div id=\"%s_idnetvifs\">\n", vvar );
3316    if( mcast )
3317    {
3318        char mcast[32];
3319
3320        sprintf( mcast, "%s_multicast", var );
3321        nvram_default_get( mcast, "0" );
3322        showRadio( wp, "wl_basic.multicast", mcast );
3323    }
3324    websWrite( wp, "<div class=\"setting\">\n" );
3325    websWrite( wp,
3326               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n" );
3327    char ip[32];
3328
3329    sprintf( ip, "%s_ipaddr", var );
3330    char *ipv = nvram_safe_get( ip );
3331
3332    websWrite( wp,
3333               "<input type=\"hidden\" name=\"%s_ipaddr\" value=\"4\" />\n",
3334               var );
3335    websWrite( wp,
3336               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,1,223,share.ip)\" name=\"%s_ipaddr_0\" value=\"%d\" />.",
3337               var, get_single_ip( ipv, 0 ) );
3338    websWrite( wp,
3339               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_1\" value=\"%d\" />.",
3340               var, get_single_ip( ipv, 1 ) );
3341    websWrite( wp,
3342               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_2\" value=\"%d\" />.",
3343               var, get_single_ip( ipv, 2 ) );
3344    websWrite( wp,
3345               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.ip)\" name=\"%s_ipaddr_3\" value=\"%d\" />\n",
3346               var, get_single_ip( ipv, 3 ) );
3347    websWrite( wp, "</div>\n" );
3348    websWrite( wp, "<div class=\"setting\">\n" );
3349    websWrite( wp,
3350               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n" );
3351    sprintf( ip, "%s_netmask", var );
3352    ipv = nvram_safe_get( ip );
3353
3354    websWrite( wp,
3355               "<input type=\"hidden\" name=\"%s_netmask\" value=\"4\" />\n",
3356               var );
3357    websWrite( wp,
3358               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_0\" value=\"%d\" />.",
3359               var, get_single_ip( ipv, 0 ) );
3360    websWrite( wp,
3361               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_1\" value=\"%d\" />.",
3362               var, get_single_ip( ipv, 1 ) );
3363    websWrite( wp,
3364               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_2\" value=\"%d\" />.",
3365               var, get_single_ip( ipv, 2 ) );
3366    websWrite( wp,
3367               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_netmask_3\" value=\"%d\" />.",
3368               var, get_single_ip( ipv, 3 ) );
3369    websWrite( wp, "</div>\n" );
3370
3371#ifdef HAVE_MADWIFI
3372/*if (dual)
3373{
3374    char dl[32];
3375    sprintf(dl,"%s_duallink",var);
3376    websWrite( wp,
3377               "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.duallink)</script></div>\n" );
3378    websWrite( wp,
3379               "<input class=\"spaceradio\" type=\"radio\" value=\"1\" onclick=\"show_layer_ext(this, '%s_idduallink', true);\" name=\"%s_duallink\" %s><script type=\"text/javascript\">Capture(shared.enable)</script></input>&nbsp;\n",
3380               var, var, nvram_default_match( dl, "1",
3381                                               "0" ) ? "checked=\"checked\"" :
3382               "" );
3383    websWrite( wp,
3384               "<input class=\"spaceradio\" type=\"radio\" value=\"0\" onclick=\"show_layer_ext(this, '%s_idduallink', false);\" name=\"%s_duallink\" %s><script type=\"text/javascript\">Capture(shared.disable)</script></input>\n",
3385               var, var, nvram_default_match( dl, "0",
3386                                               "0" ) ? "checked=\"checked\"" :
3387               "" );
3388    websWrite( wp, "</div>\n" );
3389
3390    websWrite( wp, "<div id=\"%s_iddualink\">\n", var );
3391
3392    sprintf( ip, "%s_duallink_parent", var );
3393    websWrite( wp, "<div class=\"setting\">\n" );
3394    websWrite( wp,"<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.parent)</script></div>\n" );
3395    ipv = nvram_default_get( ip,"0.0.0.0" );
3396    websWrite( wp,
3397               "<input type=\"hidden\" name=\"%s_duallink_parent\" value=\"4\" />\n",
3398               var );
3399    websWrite( wp,
3400               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_duallink_parent_0\" value=\"%d\" />.",
3401               var, get_single_ip( ipv, 0 ) );
3402    websWrite( wp,
3403               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_duallink_parent_1\" value=\"%d\" />.",
3404               var, get_single_ip( ipv, 1 ) );
3405    websWrite( wp,
3406               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_duallink_parent_2\" value=\"%d\" />.",
3407               var, get_single_ip( ipv, 2 ) );
3408    websWrite( wp,
3409               "<input class=\"num\" maxlength=\"3\" size=\"3\" onblur=\"valid_range(this,0,255,share.subnet)\" name=\"%s_duallink_parent_3\" value=\"%d\" />.",
3410               var, get_single_ip( ipv, 3 ) );
3411    websWrite( wp, "</div>\n" );
3412
3413    websWrite( wp, "</div>\n" );
3414
3415    websWrite( wp, "<script>\n//<![CDATA[\n " );
3416    websWrite( wp,
3417               "show_layer_ext(document.getElementsByName(\"%s_duallink\"), \"%s_idduallink\", %s);\n",
3418               var, vvar, nvram_match( dl, "1" ) ? "true" : "false" );
3419    websWrite( wp, "//]]>\n</script>\n" );
3420}*/
3421#endif
3422
3423    websWrite( wp, "</div>\n" );
3424
3425
3426
3427
3428
3429
3430    websWrite( wp, "<script>\n//<![CDATA[\n " );
3431    websWrite( wp,
3432               "show_layer_ext(document.getElementsByName(\"%s_bridged\"), \"%s_idnetvifs\", %s);\n",
3433               var, vvar, nvram_match( ssid, "0" ) ? "true" : "false" );
3434    websWrite( wp, "//]]>\n</script>\n" );
3435
3436
3437}
3438
3439#ifdef HAVE_MADWIFI
3440static void show_chanshift( webs_t wp, char *prefix )
3441{
3442    char wl_chanshift[32];
3443    char wl_channelbw[32];
3444
3445    sprintf( wl_channelbw, "%s_channelbw", prefix );
3446    sprintf( wl_chanshift, "%s_chanshift", prefix );
3447    if( atoi( nvram_safe_get( wl_channelbw ) ) > 5
3448        && ( atoi( nvram_safe_get( wl_chanshift ) ) & 0xf ) > 10 )
3449        nvram_set( wl_chanshift, "10" );
3450    if( atoi( nvram_safe_get( wl_channelbw ) ) > 10
3451        && ( atoi( nvram_safe_get( wl_chanshift ) ) & 0xf ) > 0 )
3452        nvram_set( wl_chanshift, "0" );
3453
3454    if( nvram_match( wl_channelbw, "5" )
3455        || nvram_match( wl_channelbw, "10" ) )
3456    {
3457
3458        websWrite( wp, "<div class=\"setting\">\n" );
3459        websWrite( wp,
3460                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.chanshift)</script></div>\n<select name=\"%s\">\n",
3461                   wl_chanshift );
3462        websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
3463        if( nvram_match( wl_channelbw, "5" ) )
3464            websWrite( wp,
3465                       "document.write(\"<option value=\\\"-15\\\" %s >-15 Mhz</option>\");\n",
3466                       nvram_default_match( wl_chanshift, "-15",
3467                                            "0" ) ?
3468                       "selected=\\\"selected\\\"" : "" );
3469        if( nvram_match( wl_channelbw, "5" )
3470            || nvram_match( wl_channelbw, "10" ) )
3471            websWrite( wp,
3472                       "document.write(\"<option value=\\\"-10\\\" %s >-10 Mhz</option>\");\n",
3473                       nvram_default_match( wl_chanshift, "-10",
3474                                            "0" ) ?
3475                       "selected=\\\"selected\\\"" : "" );
3476        if( nvram_match( wl_channelbw, "5" )
3477            || nvram_match( wl_channelbw, "10" ) )
3478            websWrite( wp,
3479                       "document.write(\"<option value=\\\"-5\\\" %s >-5 Mhz</option>\");\n",
3480                       nvram_default_match( wl_chanshift, "-5",
3481                                            "0" ) ?
3482                       "selected=\\\"selected\\\"" : "" );
3483        websWrite( wp,
3484                   "document.write(\"<option value=\\\"0\\\" %s >0 Mhz</option>\");\n",
3485                   nvram_default_match( wl_chanshift, "0",
3486                                        "0" ) ? "selected=\\\"selected\\\"" :
3487                   "" );
3488        if( nvram_match( wl_channelbw, "5" )
3489            || nvram_match( wl_channelbw, "10" ) )
3490            websWrite( wp,
3491                       "document.write(\"<option value=\\\"5\\\" %s >+5 Mhz</option>\");\n",
3492                       nvram_default_match( wl_chanshift, "5",
3493                                            "0" ) ?
3494                       "selected=\\\"selected\\\"" : "" );
3495        if( nvram_match( wl_channelbw, "5" )
3496            || nvram_match( wl_channelbw, "10" ) )
3497            websWrite( wp,
3498                       "document.write(\"<option value=\\\"10\\\" %s >+10 Mhz</option>\");\n",
3499                       nvram_default_match( wl_chanshift, "10",
3500                                            "0" ) ?
3501                       "selected=\\\"selected\\\"" : "" );
3502        if( nvram_match( wl_channelbw, "5" ) )
3503            websWrite( wp,
3504                       "document.write(\"<option value=\\\"15\\\" %s >+15 Mhz</option>\");\n",
3505                       nvram_default_match( wl_chanshift, "15",
3506                                            "0" ) ?
3507                       "selected=\\\"selected\\\"" : "" );
3508        websWrite( wp, "//]]>\n</script>\n</select>\n</div>\n" );
3509    }
3510}
3511#endif
3512static int show_virtualssid( webs_t wp, char *prefix )
3513{
3514    char *next;
3515    char var[80];
3516    char ssid[80];
3517    char vif[16];
3518    char power[32];
3519#ifdef HAVE_MADWIFI
3520    char wmm[32];
3521    char wl_protmode[32];
3522#endif
3523    sprintf( vif, "%s_vifs", prefix );
3524    char *vifs = nvram_safe_get( vif );
3525
3526    if( vifs == NULL )
3527        return 0;
3528#ifndef HAVE_MADWIFI
3529    if( !nvram_match( "wl0_mode", "ap" )
3530        && !nvram_match( "wl0_mode", "apsta" )
3531        && !nvram_match( "wl0_mode", "apstawet" ) )
3532        return 0;
3533#endif
3534    int count = 1;
3535
3536    websWrite( wp,
3537               "<h2><script type=\"text/javascript\">Capture(wl_basic.h2_vi)</script></h2>\n" );
3538    foreach( var, vifs, next )
3539    {
3540        sprintf( ssid, "%s_ssid", var );
3541        websWrite( wp,
3542                   "<fieldset><legend><script type=\"text/javascript\">Capture(share.vintrface)</script> %s SSID [",
3543                   IFMAP(var) );
3544        tf_webWriteESCNV( wp, ssid );   // fix for broken html page if ssid
3545        // contains html tag
3546        websWrite( wp, "]</legend>\n" );
3547        websWrite( wp, "<div class=\"setting\">\n" );
3548        websWrite( wp,
3549                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label3)</script></div>\n" );
3550
3551        websWrite( wp,
3552                   "<input name=\"%s_ssid\" size=\"20\" maxlength=\"32\" onblur=\"valid_name(this,wl_basic.label3)\" value=\"%s\" /></div>\n",
3553                   var, nvram_safe_get( ssid ) );
3554
3555#ifdef HAVE_MADWIFI
3556//      sprintf( wl_chanshift, "%s_chanshift", var );
3557//      show_chanshift( wp, wl_chanshift );
3558
3559        sprintf( wl_protmode, "%s_protmode", var );
3560        showOptionsLabel( wp, "wl_basic.protmode", wl_protmode,
3561                          "None CTS RTS/CTS", nvram_default_get( wl_protmode,
3562                                                                 "None" ) );
3563        showrtssettings( wp, var );
3564#endif
3565
3566        websWrite( wp, "<div class=\"setting\">\n" );
3567        websWrite( wp,
3568                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label5)</script></div>" );
3569        sprintf( ssid, "%s_closed", var );
3570        websWrite( wp,
3571                   "<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s_closed\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input>&nbsp;\n",
3572                   var, nvram_match( ssid,
3573                                     "0" ) ? "checked=\"checked\"" : "" );
3574        websWrite( wp,
3575                   "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s_closed\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>\n",
3576                   var, nvram_match( ssid,
3577                                     "1" ) ? "checked=\"checked\"" : "" );
3578        websWrite( wp, "</div>\n" );
3579        char wl_mode[16];
3580
3581#ifdef HAVE_MADWIFI
3582        sprintf( wl_mode, "%s_mode", var );
3583        websWrite( wp,
3584                   "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label)</script></div><select name=\"%s\" >\n",
3585                   wl_mode );
3586        websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
3587        websWrite( wp,
3588                   "document.write(\"<option value=\\\"ap\\\" %s >\" + wl_basic.ap + \"</option>\");\n",
3589                   nvram_match( wl_mode,
3590                                "ap" ) ? "selected=\\\"selected\\\"" : "" );
3591        // websWrite (wp,
3592        // "document.write(\"<option value=\\\"wdssta\\\" %s >\" +
3593        // wl_basic.wdssta + \"</option>\");\n",
3594        // nvram_match (wl_mode,
3595        // "wdssta") ? "selected=\\\"selected\\\"" : "");
3596        websWrite( wp,
3597                   "document.write(\"<option value=\\\"wdsap\\\" %s >\" + wl_basic.wdsap + \"</option>\");\n",
3598                   nvram_match( wl_mode,
3599                                "wdsap" ) ? "selected=\\\"selected\\\"" :
3600                   "" );
3601        websWrite( wp, "//]]>\n</script>\n" );
3602        websWrite( wp, "</select>\n" );
3603        websWrite( wp, "</div>\n" );
3604        sprintf( wmm, "%s_wmm", var );
3605        showRadio( wp, "wl_adv.label18", wmm );
3606#endif
3607        sprintf( ssid, "%s_ap_isolate", var );
3608        showRadio( wp, "wl_adv.label11", ssid );
3609
3610        sprintf( power, "%s_maxassoc", prefix );
3611        websWrite( wp, "<div class=\"setting\">\n" );
3612        websWrite( wp,
3613               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label10)</script></div>\n" );
3614        websWrite( wp,
3615               "<input class=\"num\" name=\"%s\" size=\"4\" maxlength=\"4\" onblur=\"valid_range(this,0,256,wl_adv.label10)\" value=\"%s\" />\n",
3616               power, nvram_default_get( power, "256" ) );
3617        websWrite( wp,
3618               "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 256 \" + share.user + \")\");\n//]]>\n</script></span>\n" );
3619        websWrite( wp, "</div>\n" );
3620#ifdef HAVE_RT2880
3621        showbridgesettings( wp, getRADev(var), 1,0 );
3622#else
3623        showbridgesettings( wp, var, 1,0 );
3624#endif
3625        websWrite( wp, "</fieldset><br />\n" );
3626        count++;
3627    }
3628
3629    websWrite( wp, "<div class=\"center\">\n" );
3630#ifdef HAVE_MADWIFI
3631    if( count < 8 )
3632#elif HAVE_RT2880
3633    if( count < 7 )
3634#else
3635    if( count < WL_MAXBSSCFG )
3636#endif
3637        websWrite( wp,
3638                   "<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",
3639                   prefix );
3640
3641    if( count > 1 )
3642        websWrite( wp,
3643                   "<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",
3644                   prefix );
3645
3646    websWrite( wp, "</div><br />\n" );
3647
3648    return 0;
3649}
3650
3651#endif
3652
3653void ej_showad( webs_t wp, int argc, char_t ** argv )
3654{
3655#ifndef HAVE_FON
3656#ifndef CONFIG_BRANDING
3657#ifdef HAVE_CHILLI
3658    // if (nvram_invmatch ("fon_enable", "1"))
3659    // websWrite (wp,
3660    // "<a href=\"fon.cgi\"><img src=\"images/turn.gif\" border=0 /></a>");
3661#endif
3662#endif
3663#endif
3664
3665#ifndef HAVE_NOAD
3666    /*
3667     * if (nvram_match("wanup","1")) { websWrite(wp,"<script
3668     * type=\"text/javascript\"><!--\n//<![CDATA[\n ");
3669     * websWrite(wp,"google_ad_client = \"pub-8308593183433068\";\n");
3670     * websWrite(wp,"google_ad_width = 728;\n");
3671     * websWrite(wp,"google_ad_height = 90;\n");
3672     * websWrite(wp,"google_ad_format = \"728x90_as\";\n");
3673     * websWrite(wp,"google_ad_type = \"text_image\";\n");
3674     * websWrite(wp,"google_ad_channel =\"8866414571\";\n");
3675     * websWrite(wp,"google_color_border = \"333333\";\n");
3676     * websWrite(wp,"google_color_bg = \"000000\";\n");
3677     * websWrite(wp,"google_color_link = \"FFFFFF\";\n");
3678     * websWrite(wp,"google_color_url = \"999999\";\n");
3679     * websWrite(wp,"google_color_text = \"CCCCCC\";\n");
3680     * websWrite(wp,"//-->//]]>\n</script>\n"); websWrite(wp,"<script
3681     * type=\"text/javascript\"\n"); websWrite(wp,"
3682     * src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n");
3683     * websWrite(wp,"</script>\n"); }
3684     */
3685#endif
3686    return;
3687}
3688
3689#ifdef HAVE_MSSID
3690
3691#ifndef HAVE_SUPERCHANNEL
3692int inline issuperchannel( void )
3693{
3694#ifdef HAVE_MR3202A
3695    return 0;
3696#elif HAVE_MAKSAT
3697    return 1;
3698#else
3699    return 0;
3700#endif
3701}
3702#endif
3703
3704#ifdef HAVE_MADWIFI
3705void ej_show_countrylist( webs_t wp, int argc, char_t ** argv )
3706{
3707    if( argc < 1 )
3708    {
3709        return;
3710    }
3711    char *list = getCountryList(  );
3712
3713    showOptionsChoose( wp, argv[0], list, nvram_safe_get( argv[0] ) );
3714}
3715#endif
3716void ej_show_wireless_single( webs_t wp, char *prefix )
3717{
3718    char wl_mode[16];
3719    char wl_macaddr[16];
3720    char wl_ssid[16];
3721
3722    sprintf( wl_mode, "%s_mode", prefix );
3723    sprintf( wl_macaddr, "%s_hwaddr", prefix );
3724    sprintf( wl_ssid, "%s_ssid", prefix );
3725
3726    // wireless mode
3727    websWrite( wp,
3728               "<h2><script type=\"text/javascript\">Capture(wl_basic.h2_v24)</script> %s</h2>\n",
3729               prefix );
3730    websWrite( wp, "<fieldset>\n" );
3731    websWrite( wp, "<legend><script type=\"text/javascript\">Capture(share.pintrface)</script> %s - SSID [", IFMAP(prefix) );
3732    tf_webWriteESCNV( wp, wl_ssid );    // fix
3733    websWrite( wp, "] HWAddr [%s]</legend>\n", nvram_safe_get( wl_macaddr ) );
3734    char power[16];
3735
3736    // char maxpower[16];
3737#ifdef HAVE_MADWIFI
3738    char wl_regdomain[16];
3739
3740    sprintf( wl_regdomain, "%s_regdomain", prefix );
3741    if( nvram_match( "ath_regulatory", "1" ) || !issuperchannel(  ) )
3742    {
3743        websWrite( wp,
3744                   "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.regdom)</script></div>\n" );
3745        char *list = getCountryList(  );
3746
3747        showOptions( wp, wl_regdomain, list, nvram_safe_get( wl_regdomain ) );
3748        websWrite( wp, "</div>\n" );
3749    }
3750    /*
3751     * while (regdomains[domcount].name != NULL) { char domcode[16]; sprintf
3752     * (domcode, "%d", regdomains[domcount].code); websWrite (wp, "<option
3753     * value=\"%d\" %s>%s</option>\n", regdomains[domcount].code, nvram_match
3754     * (wl_regdomain, domcode) ? " selected=\"selected\"" : "",
3755     * regdomains[domcount].name); domcount++; } websWrite (wp,
3756     * "</select>\n"); websWrite (wp, "</div>\n");
3757     */
3758    // power adjustment
3759    sprintf( power, "%s_txpwrdbm", prefix );
3760    // sprintf (maxpower, "%s_maxpower", prefix);
3761    if( !strcmp( prefix, "ath0" ) && issuperchannel(  ) )       // show
3762        // client
3763        // only on
3764        // first
3765        // interface
3766    {
3767
3768        websWrite( wp, "        <div class=\"setting\">\n" );
3769        websWrite( wp,
3770                   "            <div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.regulatory)</script></div>\n" );
3771        websWrite( wp,
3772                   "            <input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"ath_regulatory\" %s /><script type=\"text/javascript\">Capture(share.enable)</script>&nbsp;\n",
3773                   nvram_match( "ath_regulatory", "0" ) ? "checked" : "" );
3774        websWrite( wp,
3775                   "            <input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"ath_regulatory\" %s /><script type=\"text/javascript\">Capture(share.disable)</script>\n",
3776                   nvram_match( "ath_regulatory", "1" ) ? "checked" : "" );
3777        websWrite( wp, "        </div>\n" );
3778
3779    }
3780    websWrite( wp, "<div class=\"setting\">\n" );
3781    websWrite( wp,
3782               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.TXpower)</script></div><input class=\"num\" name=\"%s\" size=\"6\" maxlength=\"3\" value=\"%d\" /> dBm\n",
3783               power,
3784               atoi( nvram_safe_get( power ) ) +
3785               wifi_gettxpoweroffset( prefix ) );
3786    websWrite( wp, "</div>\n" );
3787    sprintf( power, "%s_antgain", prefix );
3788#ifndef HAVE_MAKSAT
3789    if( nvram_match( "ath_regulatory", "1" ) )
3790#endif
3791    {
3792        websWrite( wp, "<div class=\"setting\">\n" );
3793        websWrite( wp,
3794                   "<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",
3795                   power, nvram_safe_get( power ) );
3796        websWrite( wp, "</div>\n" );
3797    }
3798#endif
3799
3800#ifdef HAVE_MADWIFI
3801    // if (!strcmp (prefix, "ath0"))
3802#endif
3803    {
3804        // #ifdef HAVE_MADWIFI
3805        // if (!strcmp (prefix, "ath0")) //show client only on first
3806        // interface
3807        // #endif
3808        {
3809#ifdef HAVE_MADWIFI
3810            // if (!strcmp (prefix, "ath0")) //show client only on first
3811            // interface
3812            // if (nvram_match ("ath0_mode", "wdsap")
3813            // || nvram_match ("ath0_mode", "wdssta"))
3814            // showOption (wp, "wl_basic.wifi_bonding", "wifi_bonding");
3815#endif
3816            websWrite( wp,
3817                       "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label)</script></div><select name=\"%s\" >\n",
3818                       wl_mode );
3819            websWrite( wp,
3820                       "<script type=\"text/javascript\">\n//<![CDATA[\n" );
3821            websWrite( wp,
3822                       "document.write(\"<option value=\\\"ap\\\" %s >\" + wl_basic.ap + \"</option>\");\n",
3823                       nvram_match( wl_mode,
3824                                    "ap" ) ? "selected=\\\"selected\\\"" :
3825                       "" );
3826            websWrite( wp,
3827                       "document.write(\"<option value=\\\"sta\\\" %s >\" + wl_basic.client + \"</option>\");\n",
3828                       nvram_match( wl_mode,
3829                                    "sta" ) ? "selected=\\\"selected\\\"" :
3830                       "" );
3831#ifndef HAVE_RT2880
3832            websWrite( wp,
3833                       "document.write(\"<option value=\\\"wet\\\" %s >\" + wl_basic.clientBridge + \"</option>\");\n",
3834                       nvram_match( wl_mode,
3835                                    "wet" ) ? "selected=\\\"selected\\\"" :
3836                       "" );
3837#endif
3838            websWrite( wp,
3839                       "document.write(\"<option value=\\\"infra\\\" %s >\" + wl_basic.adhoc + \"</option>\");\n",
3840                       nvram_match( wl_mode,
3841                                    "infra" ) ? "selected=\\\"selected\\\"" :
3842                       "" );
3843#ifndef HAVE_MADWIFI
3844            websWrite( wp,
3845                       "document.write(\"<option value=\\\"apsta\\\" %s >\" + wl_basic.repeater + \"</option>\");\n",
3846                       nvram_match( wl_mode,
3847                                    "apsta" ) ? "selected=\\\"selected\\\"" :
3848                       "" );
3849#ifndef HAVE_RT2880
3850            websWrite( wp,
3851                       "document.write(\"<option value=\\\"apstawet\\\" %s >\" + wl_basic.repeaterbridge + \"</option>\");\n",
3852                       nvram_match( wl_mode,
3853                                    "apstawet" ) ? "selected=\\\"selected\\\""
3854                       : "" );
3855#endif
3856#else
3857            websWrite( wp,
3858                       "document.write(\"<option value=\\\"wdssta\\\" %s >\" + wl_basic.wdssta + \"</option>\");\n",
3859                       nvram_match( wl_mode,
3860                                    "wdssta" ) ? "selected=\\\"selected\\\"" :
3861                       "" );
3862            websWrite( wp,
3863                       "document.write(\"<option value=\\\"wdsap\\\" %s >\" + wl_basic.wdsap + \"</option>\");\n",
3864                       nvram_match( wl_mode,
3865                                    "wdsap" ) ? "selected=\\\"selected\\\"" :
3866                       "" );
3867#endif
3868            websWrite( wp, "//]]>\n</script>\n" );
3869            websWrite( wp, "</select>\n" );
3870            websWrite( wp, "</div>\n" );
3871        }
3872        /*
3873         * #ifdef HAVE_MADWIFI else {
3874         *
3875         *
3876         * websWrite (wp, "<div class=\"setting\"><div
3877         * class=\"label\"><script
3878         * type=\"text/javascript\">Capture(wl_basic.label)</script></div><select
3879         * name=\"%s\">\n", wl_mode); websWrite (wp, "<script
3880         * type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option
3881         * value=\\\"ap\\\" %s >\" + wl_basic.ap +
3882         * \"</option>\");\n//]]>\n</script>\n", nvram_match (wl_mode, "ap")
3883         * ? "selected=\\\"selected\\\"" : ""); websWrite (wp, "<script
3884         * type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option
3885         * value=\\\"infra\\\" %s >\" + wl_basic.adhoc +
3886         * \"</option>\");\n//]]>\n</script>\n", nvram_match (wl_mode,
3887         * "infra") ? "selected=\\\"selected\\\"" : ""); websWrite (wp,
3888         * "<script type=\"text/javascript\">\n//<![CDATA[\n
3889         * document.write(\"<option value=\\\"wdssta\\\" %s >\" +
3890         * wl_basic.wdssta + \"</option>\");\n//]]>\n</script>\n",
3891         * nvram_match (wl_mode, "wdssta") ? "selected=\\\"selected\\\"" :
3892         * ""); websWrite (wp, "<script
3893         * type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option
3894         * value=\\\"wdsap\\\" %s >\" + wl_basic.wdsap +
3895         * \"</option>\");\n//]]>\n</script>\n", nvram_match (wl_mode,
3896         * "wdsap") ? "selected=\\\"selected\\\"" : ""); websWrite (wp,
3897         * "</select>\n"); websWrite (wp, "</div>\n"); } #endif
3898         */
3899    }
3900    // writeless net mode
3901    show_netmode( wp, prefix );
3902    // turbo options
3903#ifdef HAVE_MADWIFI
3904
3905    // char wl_xchanmode[16];
3906    char wl_outdoor[16];
3907    char wl_diversity[16];
3908    char wl_rxantenna[16];
3909    char wl_txantenna[16];
3910    char wl_width[16];
3911    char wl_preamble[16];
3912    char wl_xr[16];
3913    char wl_comp[32];
3914    char wl_ff[16];
3915    char wmm[32];
3916    char wl_isolate[32];
3917    char wl_sifstime[32];
3918    char wl_preambletime[32];
3919    char wl_intmit[32];
3920    char wl_noise_immunity[32];
3921    char wl_ofdm_weak_det[32];
3922    char wl_protmode[32];
3923    char wl_doth[32];
3924
3925    sprintf( wl_doth, "%s_doth", prefix );
3926    sprintf( wl_protmode, "%s_protmode", prefix );
3927    sprintf( wl_outdoor, "%s_outdoor", prefix );
3928    sprintf( wl_diversity, "%s_diversity", prefix );
3929    sprintf( wl_rxantenna, "%s_rxantenna", prefix );
3930    sprintf( wl_txantenna, "%s_txantenna", prefix );
3931    sprintf( wl_width, "%s_channelbw", prefix );
3932//    sprintf( wl_comp, "%s_compression", prefix );
3933    sprintf( wl_ff, "%s_ff", prefix );
3934    sprintf( wl_preamble, "%s_preamble", prefix );
3935    sprintf( wl_preambletime, "%s_preambletime", prefix );
3936    sprintf( wl_sifstime, "%s_sifstime", prefix );
3937    sprintf( wl_xr, "%s_xr", prefix );
3938
3939    sprintf( wl_intmit, "%s_intmit", prefix );
3940    sprintf( wl_noise_immunity, "%s_noise_immunity", prefix );
3941    sprintf( wl_ofdm_weak_det, "%s_ofdm_weak_det", prefix );
3942    showAutoOption( wp, "wl_basic.intmit", wl_intmit );
3943
3944    websWrite( wp, "<div class=\"setting\">\n" );
3945    websWrite( wp,
3946               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.noise_immunity)</script></div>\n<select name=\"%s\">\n",
3947               wl_noise_immunity );
3948    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
3949    websWrite( wp,
3950               "document.write(\"<option value=\\\"-1\\\" %s >\" + share.auto + \"</option>\");\n",
3951               nvram_default_match( wl_noise_immunity, "-1",
3952                                    "0" ) ? "selected=\\\"selected\\\"" :
3953               "" );
3954    websWrite( wp,
3955               "document.write(\"<option value=\\\"0\\\" %s >0</option>\");\n",
3956               nvram_default_match( wl_noise_immunity, "0",
3957                                    "0" ) ? "selected=\\\"selected\\\"" :
3958               "" );
3959    websWrite( wp,
3960               "document.write(\"<option value=\\\"1\\\" %s >1</option>\");\n",
3961               nvram_default_match( wl_noise_immunity, "1",
3962                                    "0" ) ? "selected=\\\"selected\\\"" :
3963               "" );
3964    websWrite( wp,
3965               "document.write(\"<option value=\\\"2\\\" %s >2</option>\");\n",
3966               nvram_default_match( wl_noise_immunity, "2",
3967                                    "0" ) ? "selected=\\\"selected\\\"" :
3968               "" );
3969    websWrite( wp,
3970               "document.write(\"<option value=\\\"3\\\" %s >3</option>\");\n",
3971               nvram_default_match( wl_noise_immunity, "3",
3972                                    "0" ) ? "selected=\\\"selected\\\"" :
3973               "" );
3974    websWrite( wp,
3975               "document.write(\"<option value=\\\"4\\\" %s >4</option>\");\n",
3976               nvram_default_match( wl_noise_immunity, "4",
3977                                    "0" ) ? "selected=\\\"selected\\\"" :
3978               "" );
3979    websWrite( wp, "//]]>\n</script>\n</select>\n</div>\n" );
3980
3981    showRadio( wp, "wl_basic.ofdm_weak_det", wl_ofdm_weak_det );
3982
3983    showOptionsLabel( wp, "wl_basic.protmode", wl_protmode,
3984                      "None CTS RTS/CTS", nvram_default_get( wl_protmode,
3985                                                             "None" ) );
3986    showrtssettings( wp, prefix );
3987    show_rates( wp, prefix, 0 );
3988    show_rates( wp, prefix, 1 );
3989    showRadio( wp, "wl_basic.preamble", wl_preamble );
3990    showRadio( wp, "wl_basic.extrange", wl_xr );
3991//    showRadio( wp, "wl_basic.supergcomp", wl_comp );
3992    showRadio( wp, "wl_basic.supergff", wl_ff );
3993
3994    // showOption (wp, "wl_basic.extchannel", wl_xchanmode);
3995#if !defined(HAVE_FONERA) && !defined(HAVE_LS2) && !defined(HAVE_MERAKI)
3996    if( nvram_match( "ath_regulatory", "1" ) || !issuperchannel(  ) )
3997    {
3998        showRadio( wp, "wl_basic.outband", wl_outdoor );
3999    }
4000#endif
4001    websWrite( wp,
4002               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.channel_width)</script></div><select name=\"%s\" >\n",
4003               wl_width );
4004    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
4005    websWrite( wp,
4006               "document.write(\"<option value=\\\"40\\\" %s >\" + share.turbo + \"</option>\");\n",
4007               nvram_match( wl_width,
4008                            "40" ) ? "selected=\\\"selected\\\"" : "" );
4009    websWrite( wp,
4010               "document.write(\"<option value=\\\"20\\\" %s >\" + share.full + \"</option>\");\n",
4011               nvram_match( wl_width,
4012                            "20" ) ? "selected=\\\"selected\\\"" : "" );
4013    websWrite( wp,
4014               "document.write(\"<option value=\\\"10\\\" %s >\" + share.half + \"</option>\");\n",
4015               nvram_match( wl_width,
4016                            "10" ) ? "selected=\\\"selected\\\"" : "" );
4017    websWrite( wp,
4018               "document.write(\"<option value=\\\"5\\\" %s >\" + share.quarter + \"</option>\");\n",
4019               nvram_match( wl_width,
4020                            "5" ) ? "selected=\\\"selected\\\"" : "" );
4021    websWrite( wp, "//]]>\n</script>\n" );
4022    websWrite( wp, "</select>\n" );
4023    websWrite( wp, "</div>\n" );
4024
4025#if defined(HAVE_NS2) || defined(HAVE_NS5)
4026
4027    websWrite( wp,
4028               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label24)</script></div><select name=\"%s\" >\n",
4029               wl_txantenna );
4030    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
4031    websWrite( wp,
4032               "document.write(\"<option value=\\\"0\\\" %s >\" + wl_basic.vertical + \"</option>\");\n",
4033               nvram_match( wl_txantenna,
4034                            "0" ) ? "selected=\\\"selected\\\"" : "" );
4035    websWrite( wp,
4036               "document.write(\"<option value=\\\"1\\\" %s >\" + wl_basic.horizontal + \"</option>\");\n",
4037               nvram_match( wl_txantenna,
4038                            "1" ) ? "selected=\\\"selected\\\"" : "" );
4039    websWrite( wp,
4040               "document.write(\"<option value=\\\"3\\\" %s >\" + wl_basic.adaptive + \"</option>\");\n",
4041               nvram_match( wl_txantenna,
4042                            "3" ) ? "selected=\\\"selected\\\"" : "" );
4043    websWrite( wp,
4044               "document.write(\"<option value=\\\"2\\\" %s >\" + wl_basic.external + \"</option>\");\n",
4045               nvram_match( wl_txantenna,
4046                            "2" ) ? "selected=\\\"selected\\\"" : "" );
4047    websWrite( wp, "//]]>\n</script>\n" );
4048    websWrite( wp, "</select>\n" );
4049    websWrite( wp, "</div>\n" );
4050
4051#else
4052    showRadio( wp, "wl_basic.diversity", wl_diversity );
4053    websWrite( wp,
4054               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label12)</script></div><select name=\"%s\" >\n",
4055               wl_txantenna );
4056    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
4057    websWrite( wp,
4058               "document.write(\"<option value=\\\"0\\\" %s >\" + wl_basic.diversity + \"</option>\");\n",
4059               nvram_match( wl_txantenna,
4060                            "0" ) ? "selected=\\\"selected\\\"" : "" );
4061    websWrite( wp,
4062               "document.write(\"<option value=\\\"1\\\" %s >\" + wl_basic.primary + \"</option>\");\n",
4063               nvram_match( wl_txantenna,
4064                            "1" ) ? "selected=\\\"selected\\\"" : "" );
4065    websWrite( wp,
4066               "document.write(\"<option value=\\\"2\\\" %s >\" + wl_basic.secondary + \"</option>\");\n",
4067               nvram_match( wl_txantenna,
4068                            "2" ) ? "selected=\\\"selected\\\"" : "" );
4069    websWrite( wp, "//]]>\n</script>\n" );
4070    websWrite( wp, "</select>\n" );
4071    websWrite( wp, "</div>\n" );
4072
4073    websWrite( wp,
4074               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label13)</script></div><select name=\"%s\" >\n",
4075               wl_rxantenna );
4076    websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n" );
4077    websWrite( wp,
4078               "document.write(\"<option value=\\\"0\\\" %s >\" + wl_basic.diversity + \"</option>\");\n",
4079               nvram_match( wl_rxantenna,
4080                            "0" ) ? "selected=\\\"selected\\\"" : "" );
4081    websWrite( wp,
4082               "document.write(\"<option value=\\\"1\\\" %s >\" + wl_basic.primary + \"</option>\");\n",
4083               nvram_match( wl_rxantenna,
4084                            "1" ) ? "selected=\\\"selected\\\"" : "" );
4085    websWrite( wp,
4086               "document.write(\"<option value=\\\"2\\\" %s >\" + wl_basic.secondary + \"</option>\");\n",
4087               nvram_match( wl_rxantenna,
4088                            "2" ) ? "selected=\\\"selected\\\"" : "" );
4089    websWrite( wp, "//]]>\n</script>\n" );
4090    websWrite( wp, "</select>\n" );
4091    websWrite( wp, "</div>\n" );
4092#endif
4093#endif
4094#ifdef HAVE_MADWIFI
4095    sprintf( wl_isolate, "%s_ap_isolate", prefix );
4096    showRadio( wp, "wl_adv.label11", wl_isolate );
4097
4098#if 0
4099    websWrite( wp, "<div class=\"setting\">\n" );
4100    websWrite( wp,
4101               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.sifstime)</script></div>\n" );
4102    websWrite( wp,
4103               "<input class=\"num\" name=\"%s\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,99999999,wl_basic.sifstime)\" value=\"%s\" />\n",
4104               wl_sifstime, nvram_default_get( wl_sifstime, "16" ) );
4105    websWrite( wp, "</div>\n" );
4106
4107    websWrite( wp, "<div class=\"setting\">\n" );
4108    websWrite( wp,
4109               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.preambletime)</script></div>\n" );
4110    websWrite( wp,
4111               "<input class=\"num\" name=\"%s\" size=\"3\" maxlength=\"3\" onblur=\"valid_range(this,0,99999999,wl_basic.preambletime)\" value=\"%s\" />\n",
4112               wl_preambletime, nvram_default_get( wl_preambletime, "20" ) );
4113    websWrite( wp, "</div>\n" );
4114#endif
4115    sprintf( wmm, "%s_wmm", prefix );
4116    showRadio( wp, "wl_adv.label18", wmm );
4117#endif
4118
4119    websWrite( wp, "<div class=\"setting\">\n" );
4120    websWrite( wp,
4121               "<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",
4122               wl_ssid, nvram_safe_get( wl_ssid ) );
4123
4124#ifdef HAVE_MADWIFI
4125    showRadio( wp, "wl_basic.radar", wl_doth );
4126    show_chanshift( wp, prefix );
4127#endif
4128    if( nvram_match( wl_mode, "ap" ) || nvram_match( wl_mode, "wdsap" )
4129        || nvram_match( wl_mode, "infra" ) )
4130    {
4131
4132        if( has_mimo( prefix )
4133            && ( nvram_nmatch( "n-only", "%s_net_mode", prefix )
4134                 || nvram_nmatch( "mixed," "%s_net_mode", prefix )
4135                 || nvram_nmatch( "na-only", "%s_net_mode", prefix ) ) )
4136        {
4137
4138            websWrite( wp, "<div class=\"setting\">\n" );
4139            websWrite( wp,
4140                       "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.channel_width)</script></div>\n" );
4141            websWrite( wp, "<select name=\"%s_nbw\">\n", prefix );
4142#ifdef HAVE_RT2880
4143            websWrite( wp,
4144                       "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"20\\\" %s >20 Mhz</option>\");\n//]]>\n</script>\n",
4145                       nvram_nmatch( "20", "%s_nbw",
4146                                     prefix ) ? "selected=\\\"selected\\\"" :
4147                       "" );
4148            websWrite( wp, "<option value=\"40\" %s>40 MHz</option>",
4149                       nvram_nmatch( "40", "%s_nbw",
4150                                     prefix ) ? "selected=\\\"selected\\\"" :
4151                       "" );
4152#else
4153            websWrite( wp,
4154                       "<script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"0\\\" %s >\" + share.auto + \"</option>\");\n//]]>\n</script>\n",
4155                       nvram_nmatch( "0", "%s_nbw",
4156                                     prefix ) ? "selected=\\\"selected\\\"" :
4157                       "" );
4158            websWrite( wp, "<option value=\"10\" %s>10 MHz</option>",
4159                       nvram_nmatch( "10", "%s_nbw",
4160                                     prefix ) ? "selected=\\\"selected\\\"" :
4161                       "" );
4162            websWrite( wp, "<option value=\"20\" %s>20 MHz</option>",
4163                       nvram_nmatch( "20", "%s_nbw",
4164                                     prefix ) ? "selected=\\\"selected\\\"" :
4165                       "" );
4166            websWrite( wp, "<option value=\"40\" %s>40 MHz</option>",
4167                       nvram_nmatch( "40", "%s_nbw",
4168                                     prefix ) ? "selected=\\\"selected\\\"" :
4169                       "" );
4170#endif
4171            websWrite( wp, "</select>\n" );
4172            websWrite( wp, "</div>\n" );
4173
4174            websWrite( wp, "<div class=\"setting\">\n" );
4175            websWrite( wp,"<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.channel_wide)</script></div>\n" );
4176            websWrite( wp, "<select name=\"%s_wchannel\" ></select>\n",prefix );
4177            websWrite( wp, "</div>\n" );
4178            show_channel( wp, prefix, prefix, 1 );
4179        }
4180        else
4181
4182            show_channel( wp, prefix, prefix, 0 );
4183
4184        char wl_closed[16];
4185
4186        sprintf( wl_closed, "%s_closed", prefix );
4187        websWrite( wp, "<div class=\"setting\">\n" );
4188        websWrite( wp,
4189                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label5)</script></div>\n" );
4190        websWrite( wp,
4191                   "<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input>&nbsp;\n",
4192                   wl_closed, nvram_match( wl_closed,
4193                                           "0" ) ? "checked=\"checked\"" :
4194                   "" );
4195        websWrite( wp,
4196                   "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>\n",
4197                   wl_closed, nvram_match( wl_closed,
4198                                           "1" ) ? "checked=\"checked\"" :
4199                   "" );
4200        websWrite( wp, "</div>\n" );
4201    }
4202#ifdef HAVE_MADWIFI
4203    // if (nvram_match (wl_mode, "sta") || nvram_match (wl_mode, "wdssta")
4204    // || nvram_match (wl_mode, "wet"))
4205    {
4206        char wl_scanlist[32];
4207
4208        sprintf( wl_scanlist, "%s_scanlist", prefix );
4209        websWrite( wp, "<div class=\"setting\">\n" );
4210        websWrite( wp,
4211                   "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.scanlist)</script></div>\n" );
4212        websWrite( wp,
4213                   "<input name=\"%s\" size=\"32\" maxlength=\"512\" value=\"%s\" />\n",
4214                   wl_scanlist, nvram_default_get( wl_scanlist, "default" ) );
4215        websWrite( wp, "</div>\n" );
4216    }
4217#endif
4218
4219    // ACK timing
4220#if defined(HAVE_ACK) || defined(HAVE_MADWIFI)  // temp fix for v24 broadcom
4221    // ACKnot working
4222
4223    sprintf( power, "%s_distance", prefix );
4224    websWrite( wp, "<br />\n" );
4225    websWrite( wp, "<div class=\"setting\">\n" );
4226    websWrite( wp,
4227               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.label6)</script></div>\n" );
4228    websWrite( wp,
4229               "<input class=\"num\" name=\"%s\" size=\"8\" maxlength=\"8\" onblur=\"valid_range(this,0,99999999,wl_basic.label6)\" value=\"%s\" />\n",
4230               power, nvram_default_get( power, "2000" ) );
4231    websWrite( wp,
4232               "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 2000 \" + share.meters + \")\");\n//]]>\n</script></span>\n" );
4233    websWrite( wp, "</div>\n" );
4234    // end ACK timing
4235#endif
4236#ifdef HAVE_MADWIFI
4237    sprintf( power, "%s_maxassoc", prefix );
4238    websWrite( wp, "<div class=\"setting\">\n" );
4239    websWrite( wp,
4240               "<div class=\"label\"><script type=\"text/javascript\">Capture(wl_adv.label10)</script></div>\n" );
4241    websWrite( wp,
4242               "<input class=\"num\" name=\"%s\" size=\"4\" maxlength=\"4\" onblur=\"valid_range(this,0,256,wl_basic.label6)\" value=\"%s\" />\n",
4243               power, nvram_default_get( power, "256" ) );
4244    websWrite( wp,
4245               "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 256 \" + share.user + \")\");\n//]]>\n</script></span>\n" );
4246    websWrite( wp, "</div>\n" );
4247    showbridgesettings( wp, prefix, 1 ,1);
4248#elif HAVE_RT2880
4249    showbridgesettings( wp, "ra0", 1 ,1);
4250#else
4251    if( !strcmp( prefix, "wl0" ) )
4252        showbridgesettings( wp, get_wl_instance_name( 0 ), 1 ,1);
4253    if( !strcmp( prefix, "wl1" ) )
4254        showbridgesettings( wp, get_wl_instance_name( 1 ), 1 ,1);
4255#endif
4256    websWrite( wp, "</fieldset>\n" );
4257    websWrite( wp, "<br />\n" );
4258    show_virtualssid( wp, prefix );
4259}
4260
4261void ej_show_wireless( webs_t wp, int argc, char_t ** argv )
4262{
4263#ifdef HAVE_MADWIFI
4264    int c = getdevicecount(  );
4265    int i;
4266
4267    for( i = 0; i < c; i++ )
4268    {
4269        char buf[16];
4270
4271        sprintf( buf, "ath%d", i );
4272        ej_show_wireless_single( wp, buf );
4273    }
4274#else
4275    int c = get_wl_instances(  );
4276    int i;
4277
4278    for( i = 0; i < c; i++ )
4279    {
4280        char buf[16];
4281
4282        sprintf( buf, "wl%d", i );
4283        ej_show_wireless_single( wp, buf );
4284    }
4285#endif
4286    return;
4287}
4288
4289void show_preshared( webs_t wp, char *prefix )
4290{
4291    char var[80];
4292
4293    cprintf( "show preshared" );
4294    sprintf( var, "%s_crypto", prefix );
4295    websWrite( wp, "<div><div class=\"setting\">\n" );
4296    websWrite( wp,
4297               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.algorithms)</script></div>\n" );
4298    websWrite( wp, "<select name=\"%s_crypto\">\n", prefix );
4299    websWrite( wp, "<option value=\"tkip\" %s>TKIP</option>\n",
4300               selmatch( var, "tkip", "selected=\"selected\"" ) );
4301    websWrite( wp, "<option value=\"aes\" %s>AES</option>\n",
4302               selmatch( var, "aes", "selected=\"selected\"" ) );
4303    websWrite( wp, "<option value=\"tkip+aes\" %s>TKIP+AES</option>\n",
4304               selmatch( var, "tkip+aes", "selected=\"selected\"" ) );
4305    websWrite( wp, "</select>\n" );
4306    websWrite( wp, "</div>\n" );
4307    websWrite( wp, "<div class=\"setting\">\n" );
4308    websWrite( wp,
4309               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.shared_key)</script></div>\n" );
4310    sprintf( var, "%s_wpa_psk", prefix );
4311    websWrite( wp,
4312               "<input type=\"password\" id=\"%s_wpa_psk\" name=\"%s_wpa_psk\" onblur=\"valid_psk_length(this)\" maxlength=\"64\" size=\"32\" value=\"",
4313               prefix, prefix );
4314    tf_webWriteESCNV( wp, var );
4315    websWrite( wp, "\" />&nbsp;&nbsp;&nbsp;\n" );
4316    websWrite( wp,
4317               "<input type=\"checkbox\" name=\"%s_wl_unmask\" value=\"0\" onclick=\"setElementMask('%s_wpa_psk', this.checked)\" >&nbsp;<script type=\"text/javascript\">Capture(share.unmask)</script></input>\n",
4318               prefix, prefix );
4319    websWrite( wp, "</div>\n" );
4320    websWrite( wp, "<div class=\"setting\">\n" );
4321    websWrite( wp,
4322               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.rekey)</script></div>\n" );
4323    sprintf( var, "%s_wpa_gtk_rekey", prefix );
4324    websWrite( wp,
4325               "<input class=\"num\" name=\"%s_wpa_gtk_rekey\" maxlength=\"5\" size=\"5\" onblur=\"valid_range(this,0,99999,wpa.rekey)\" value=\"%s\" />\n",
4326               prefix, nvram_default_get( var, "3600" ) );
4327    websWrite( wp,
4328               "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 3600, \" + share.range + \": 1 - 99999)\");\n//]]>\n</script></span>\n" );
4329    websWrite( wp, "</div>\n" );
4330    websWrite( wp, "</div>\n" );
4331}
4332
4333void show_radius( webs_t wp, char *prefix, int showmacformat )
4334{
4335    char var[80];
4336
4337    cprintf( "show radius\n" );
4338    if( showmacformat )
4339    {
4340        websWrite( wp, "<div class=\"setting\">\n" );
4341        websWrite( wp,
4342                   "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label2)</script></div>\n" );
4343        websWrite( wp, "<select name=\"%s_radmactype\">\n", prefix );
4344        websWrite( wp, "<option value=\"0\" %s >aabbcc-ddeeff</option>\n",
4345                   nvram_prefix_match( "radmactype", prefix,
4346                                       "0" ) ? "selected" : "" );
4347        websWrite( wp, "<option value=\"1\" %s >aabbccddeeff</option>\n",
4348                   nvram_prefix_match( "radmactype", prefix,
4349                                       "1" ) ? "selected" : "" );
4350        websWrite( wp, "<option value=\"2\" %s >aa:bb:cc:dd:ee:ff</option>\n",
4351                   nvram_prefix_match( "radmactype", prefix,
4352                                       "2" ) ? "selected" : "" );
4353        websWrite( wp, "<option value=\"3\" %s >aa-bb-cc-dd-ee-ff</option>\n",
4354                   nvram_prefix_match( "radmactype", prefix,
4355                                       "3" ) ? "selected" : "" );
4356        websWrite( wp, "</select>\n" );
4357        websWrite( wp, "</div>\n" );
4358    }
4359    char *rad = nvram_nget( "%s_radius_ipaddr", prefix );
4360
4361    websWrite( wp, "<div class=\"setting\">\n" );
4362    websWrite( wp,
4363               "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label3)</script></div>\n" );
4364    websWrite( wp,
4365               "<input type=\"hidden\" name=\"%s_radius_ipaddr\" value=\"4\" />\n",
4366               prefix );
4367    websWrite( wp,
4368               "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_0\" onblur=\"valid_range(this,0,255,radius.label3)\" class=\"num\" value=\"%d\" />.",
4369               prefix, get_single_ip( rad, 0 ) );
4370    websWrite( wp,
4371               "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_1\" onblur=\"valid_range(this,0,255,radius.label3)\" class=\"num\" value=\"%d\" />.",
4372               prefix, get_single_ip( rad, 1 ) );
4373    websWrite( wp,
4374               "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_2\" onblur=\"valid_range(this,0,255,radius.label3)\" class=\"num\" value=\"%d\" />.",
4375               prefix, get_single_ip( rad, 2 ) );
4376    websWrite( wp,
4377               "<input size=\"3\" maxlength=\"3\" name=\"%s_radius_ipaddr_3\" onblur=\"valid_range(this,1,254,radius.label3)\" class=\"num\" value=\"%d\" />\n",
4378               prefix, get_single_ip( rad, 3 ) );
4379    websWrite( wp, "</div>\n" );
4380
4381    websWrite( wp, "<div class=\"setting\">\n" );
4382    websWrite( wp,
4383               "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label4)</script></div>\n" );
4384    sprintf( var, "%s_radius_port", prefix );
4385    websWrite( wp,
4386               "<input name=\"%s_radius_port\" size=\"3\" maxlength=\"5\" onblur=\"valid_range(this,1,65535,radius.label4)\" value=\"%s\" />\n",
4387               prefix, nvram_default_get( var, "1812" ) );
4388    websWrite( wp,
4389               "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 1812)\");\n//]]>\n</script></span>\n</div>\n" );
4390    websWrite( wp, "<div class=\"setting\">\n" );
4391    websWrite( wp,
4392               "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label7)</script></div>\n" );
4393    sprintf( var, "%s_radius_key", prefix );
4394    websWrite( wp,
4395               "<input type=\"password\" id=\"%s_radius_key\" name=\"%s_radius_key\" maxlength=\"79\" size=\"32\" value=\"",
4396               prefix, prefix );
4397    tf_webWriteESCNV( wp, var );
4398    websWrite( wp, "\" />&nbsp;&nbsp;&nbsp;\n" );
4399    websWrite( wp,
4400               "<input type=\"checkbox\" name=\"%s_radius_unmask\" value=\"0\" onclick=\"setElementMask('%s_radius_key', this.checked)\" >&nbsp;<script type=\"text/javascript\">Capture(share.unmask)</script></input>\n",
4401               prefix, prefix );
4402    websWrite( wp, "</div>\n" );
4403#ifdef HAVE_MADWIFI
4404    if( !showmacformat )
4405    {
4406        char acct[32];
4407        char vvar[32];
4408
4409        strcpy( vvar, var );
4410        rep( vvar, '.', 'X' );
4411        sprintf( acct, "%s_acct", prefix );
4412        websWrite( wp,
4413                   "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label18)</script></div>\n" );
4414        websWrite( wp,
4415                   "<input class=\"spaceradio\" type=\"radio\" value=\"1\" onclick=\"show_layer_ext(this, '%s_idacct', true);\" name=\"%s_acct\" %s><script type=\"text/javascript\">Capture(share.enable)</script></input>\n",
4416                   vvar, prefix, nvram_default_match( acct, "1",
4417                                                      "0" ) ?
4418                   "checked=\"checked\"" : "" );
4419        websWrite( wp,
4420                   "<input class=\"spaceradio\" type=\"radio\" value=\"0\" onclick=\"show_layer_ext(this, '%s_idacct, false);\" name=\"%s_acct\" %s><script type=\"text/javascript\">Capture(share.disable)</script></input>&nbsp;\n",
4421                   vvar, prefix, nvram_default_match( acct, "0",
4422                                                      "0" ) ?
4423                   "checked=\"checked\"" : "" );
4424        websWrite( wp, "</div>\n" );
4425        char *rad = nvram_nget( "%s_acct_ipaddr", prefix );
4426
4427        websWrite( wp, "<div id=\"%s_idacct\">\n", vvar );
4428        websWrite( wp, "<div class=\"setting\">\n" );
4429        websWrite( wp,
4430                   "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label13)</script></div>\n" );
4431        websWrite( wp,
4432                   "<input type=\"hidden\" name=\"%s_acct_ipaddr\" value=\"4\" />\n",
4433                   prefix );
4434        websWrite( wp,
4435                   "<input size=\"3\" maxlength=\"3\" name=\"%s_acct_ipaddr_0\" onblur=\"valid_range(this,0,255,radius.label13)\" class=\"num\" value=\"%d\" />.",
4436                   prefix, get_single_ip( rad, 0 ) );
4437        websWrite( wp,
4438                   "<input size=\"3\" maxlength=\"3\" name=\"%s_acct_ipaddr_1\" onblur=\"valid_range(this,0,255,radius.label13)\" class=\"num\" value=\"%d\" />.",
4439                   prefix, get_single_ip( rad, 1 ) );
4440        websWrite( wp,
4441                   "<input size=\"3\" maxlength=\"3\" name=\"%s_acct_ipaddr_2\" onblur=\"valid_range(this,0,255,radius.label13)\" class=\"num\" value=\"%d\" />.",
4442                   prefix, get_single_ip( rad, 2 ) );
4443        websWrite( wp,
4444                   "<input size=\"3\" maxlength=\"3\" name=\"%s_acct_ipaddr_3\" onblur=\"valid_range(this,1,254,radius.label13)\" class=\"num\" value=\"%d\" />\n",
4445                   prefix, get_single_ip( rad, 3 ) );
4446        websWrite( wp, "</div>\n" );
4447
4448        websWrite( wp, "<div class=\"setting\">\n" );
4449        websWrite( wp,
4450                   "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label14)</script></div>\n" );
4451        sprintf( var, "%s_acct_port", prefix );
4452        websWrite( wp,
4453                   "<input name=\"%s_acct_port\" size=\"3\" maxlength=\"5\" onblur=\"valid_range(this,1,65535,radius.label14)\" value=\"%s\" />\n",
4454                   prefix, nvram_default_get( var, "1813" ) );
4455        websWrite( wp,
4456                   "<span class=\"default\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"(\" + share.deflt + \": 1812)\");\n//]]>\n</script></span>\n</div>\n" );
4457        websWrite( wp, "<div class=\"setting\">\n" );
4458        websWrite( wp,
4459                   "<div class=\"label\"><script type=\"text/javascript\">Capture(radius.label17)</script></div>\n" );
4460        sprintf( var, "%s_acct_key", prefix );
4461        websWrite( wp,
4462                   "<input type=\"password\" id=\"%s_acct_key\" name=\"%s_acct_key\" maxlength=\"79\" size=\"32\" value=\"",
4463                   prefix, prefix );
4464        tf_webWriteESCNV( wp, var );
4465        websWrite( wp, "\" />&nbsp;&nbsp;&nbsp;\n" );
4466        websWrite( wp,
4467                   "<input type=\"checkbox\" name=\"%s_acct_unmask\" value=\"0\" onclick=\"setElementMask('%s_acct_key', this.checked)\" >&nbsp;<script type=\"text/javascript\">Capture(share.unmask)</script></input>\n",
4468                   prefix, prefix );
4469        websWrite( wp, "</div>\n" );
4470        websWrite( wp, "</div>\n" );
4471        websWrite( wp, "<script>\n//<![CDATA[\n " );
4472        websWrite( wp,
4473                   "show_layer_ext(document.getElementsByName(\"%s_acct\"), \"%s_idacct\", %s);\n",
4474                   prefix, vvar, nvram_match( acct,
4475                                              "1" ) ? "true" : "false" );
4476        websWrite( wp, "//]]>\n</script>\n" );
4477    }
4478#endif
4479}
4480
4481#ifdef HAVE_WPA_SUPPLICANT
4482
4483static void init_80211x_layers( webs_t wp, char *prefix )
4484{
4485    if( nvram_prefix_match( "8021xtype", prefix, "tls" ) )
4486    {
4487        websWrite( wp, "enable_idtls(\"%s\");\n", prefix );
4488    }
4489    if( nvram_prefix_match( "8021xtype", prefix, "leap" ) )
4490    {
4491        websWrite( wp, "enable_idleap(\"%s\");\n", prefix );
4492    }
4493    if( nvram_prefix_match( "8021xtype", prefix, "ttls" ) )
4494    {
4495        websWrite( wp, "enable_idttls(\"%s\");\n", prefix );
4496    }
4497    if( nvram_prefix_match( "8021xtype", prefix, "peap" ) )
4498    {
4499        websWrite( wp, "enable_idpeap(\"%s\");\n", prefix );
4500    }
4501}
4502
4503void ej_init_80211x_layers( webs_t wp, int argc, char_t ** argv )
4504{
4505#ifndef HAVE_MADWIFI
4506    int c = get_wl_instances(  );
4507    int i;
4508
4509    for( i = 0; i < c; i++ )
4510    {
4511        char buf[16];
4512
4513        sprintf( buf, "wl%d", i );
4514        init_80211x_layers( wp, buf );
4515    }
4516    return;
4517#else
4518    int c = getdevicecount(  );
4519    int i;
4520
4521    for( i = 0; i < c; i++ )
4522    {
4523        char buf[16];
4524
4525        sprintf( buf, "ath%d", i );
4526        init_80211x_layers( wp, buf );
4527    }
4528    return;
4529#endif
4530
4531}
4532
4533void show_80211X( webs_t wp, char *prefix )
4534{
4535    /*
4536     * fields
4537     * _8021xtype
4538     * _8021xuser
4539     * _8021xpasswd
4540     * _8021xca
4541     * _8021xpem
4542     * _8021xprv
4543     */
4544    char type[32];
4545
4546    sprintf( type, "%s_8021xtype", prefix );
4547    nvram_default_get( type, "ttls" );
4548    websWrite( wp, "<div class=\"setting\">\n" );
4549    websWrite( wp,
4550               "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.xsuptype)</script></div>\n" );
4551    websWrite( wp,
4552               "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"peap\" onclick=\"enable_idpeap('%s')\" %s />Peap&nbsp;\n",
4553               prefix, prefix, nvram_prefix_match( "8021xtype", prefix,
4554                                                   "peap" ) ?
4555               "checked=\"checked\"" : "" );
4556    websWrite( wp,
4557               "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"leap\" onclick=\"enable_idleap('%s')\" %s />Leap&nbsp;\n",
4558               prefix, prefix, nvram_prefix_match( "8021xtype", prefix,
4559                                                   "leap" ) ?
4560               "checked=\"checked\"" : "" );
4561    websWrite( wp,
4562               "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"tls\" onclick=\"enable_idtls('%s')\" %s />TLS&nbsp;\n",
4563               prefix, prefix, nvram_prefix_match( "8021xtype", prefix,
4564                                                   "tls" ) ?
4565               "checked=\"checked\"" : "" );
4566    websWrite( wp,
4567               "<input class=\"spaceradio\" type=\"radio\" name=\"%s_8021xtype\" value=\"ttls\" onclick=\"enable_idttls('%s')\" %s />TTLS&nbsp;\n",
4568               prefix, prefix, nvram_prefix_match( "8021xtype", prefix,
4569                                                   "ttls" ) ?
4570               "checked=\"checked\"" : "" );
4571    websWrite( wp, "</div>\n" );
4572    // ttls authentication
4573    websWrite( wp, "<div id=\"idttls%s\">\n", prefix );
4574    websWrite( wp, "<div class=\"setting\">\n" );
4575    websWrite( wp,
4576               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n" );
4577    websWrite( wp,
4578               "<input name=\"%s_ttls8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4579               prefix, nvram_prefix_get( "ttls8021xuser", prefix ) );
4580    websWrite( wp, "<div class=\"setting\">\n" );
4581    websWrite( wp,
4582               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n" );
4583    websWrite( wp,
4584               "<input name=\"%s_ttls8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4585               prefix, nvram_prefix_get( "ttls8021xpasswd", prefix ) );
4586    websWrite( wp, "<div class=\"setting\">\n" );
4587    websWrite( wp,
4588               "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.servercertif)</script></div>\n" );
4589    websWrite( wp,
4590               "<textarea cols=\"60\" rows=\"6\" id=\"%s_ttls8021xca\" name=\"%s_ttls8021xca\"></textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\n ",
4591               prefix, prefix );
4592    websWrite( wp, "var %s_ttls8021xca = fix_cr( '%s' );\n", prefix,
4593               nvram_prefix_get( "ttls8021xca", prefix ) );
4594    websWrite( wp,
4595               "document.getElementById(\"%s_ttls8021xca\").value = %s_ttls8021xca;\n",
4596               prefix, prefix );
4597    websWrite( wp, "//]]>\n</script>\n" );
4598    websWrite( wp, "</div>\n" );
4599    websWrite( wp, "</div>\n" );
4600
4601    // peap authentication
4602    websWrite( wp, "<div id=\"idpeap%s\">\n", prefix );
4603    websWrite( wp, "<div class=\"setting\">\n" );
4604    websWrite( wp,
4605               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n" );
4606    websWrite( wp,
4607               "<input name=\"%s_peap8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4608               prefix, nvram_prefix_get( "peap8021xuser", prefix ) );
4609    websWrite( wp, "<div class=\"setting\">\n" );
4610    websWrite( wp,
4611               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n" );
4612    websWrite( wp,
4613               "<input name=\"%s_peap8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4614               prefix, nvram_prefix_get( "peap8021xpasswd", prefix ) );
4615    websWrite( wp, "<div class=\"setting\">\n" );
4616    websWrite( wp,
4617               "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.servercertif)</script></div>\n" );
4618    websWrite( wp,
4619               "<textarea cols=\"60\" rows=\"6\" id=\"%s_peap8021xca\" name=\"%s_peap8021xca\"></textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\n ",
4620               prefix, prefix );
4621    websWrite( wp, "var %s_peap8021xca = fix_cr( '%s' );\n", prefix,
4622               nvram_prefix_get( "peap8021xca", prefix ) );
4623    websWrite( wp,
4624               "document.getElementById(\"%s_peap8021xca\").value = %s_peap8021xca;\n",
4625               prefix, prefix );
4626    websWrite( wp, "//]]>\n</script>\n" );
4627    websWrite( wp, "</div>\n" );
4628    websWrite( wp, "</div>\n" );
4629    // leap authentication
4630    websWrite( wp, "<div id=\"idleap%s\">\n", prefix );
4631    websWrite( wp, "<div class=\"setting\">\n" );
4632    websWrite( wp,
4633               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n" );
4634    websWrite( wp,
4635               "<input name=\"%s_leap8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4636               prefix, nvram_prefix_get( "leap8021xuser", prefix ) );
4637    websWrite( wp, "<div class=\"setting\">\n" );
4638    websWrite( wp,
4639               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n" );
4640    websWrite( wp,
4641               "<input name=\"%s_leap8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4642               prefix, nvram_prefix_get( "leap8021xpasswd", prefix ) );
4643    websWrite( wp, "</div>\n" );
4644
4645    // tls authentication
4646    websWrite( wp, "<div id=\"idtls%s\">\n", prefix );
4647    websWrite( wp, "<div class=\"setting\">\n" );
4648    websWrite( wp,
4649               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.user)</script></div>\n" );
4650    websWrite( wp,
4651               "<input name=\"%s_tls8021xuser\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4652               prefix, nvram_prefix_get( "tls8021xuser", prefix ) );
4653    websWrite( wp, "<div class=\"setting\">\n" );
4654    websWrite( wp,
4655               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.passwd)</script></div>\n" );
4656    websWrite( wp,
4657               "<input name=\"%s_tls8021xpasswd\" type=\"password\" size=\"20\" maxlength=\"79\" value=\"%s\" /></div>\n",
4658               prefix, nvram_prefix_get( "tls8021xpasswd", prefix ) );
4659
4660    websWrite( wp, "<div class=\"setting\">\n" );
4661    websWrite( wp,
4662               "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.servercertif)</script></div>\n" );
4663    websWrite( wp,
4664               "<textarea cols=\"60\" rows=\"6\" id=\"%s_tls8021xca\" name=\"%s_tls8021xca\"></textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\n ",
4665               prefix, prefix );
4666    websWrite( wp, "var %s_tls8021xca = fix_cr( '%s' );\n", prefix,
4667               nvram_prefix_get( "tls8021xca", prefix ) );
4668    websWrite( wp,
4669               "document.getElementById(\"%s_tls8021xca\").value = %s_tls8021xca;\n",
4670               prefix, prefix );
4671    websWrite( wp, "//]]>\n</script>\n" );
4672    websWrite( wp, "</div>\n" );
4673
4674    websWrite( wp, "<div class=\"setting\">\n" );
4675    websWrite( wp,
4676               "<div class=\"label\"><script type=\"text/javascript\">Capture(sec80211x.clientcertif)</script></div>\n" );
4677    websWrite( wp,
4678               "<textarea cols=\"60\" rows=\"6\" id=\"%s_tls8021xpem\" name=\"%s_tls8021xpem\"></textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\n ",
4679               prefix, prefix );
4680    websWrite( wp, "var %s_tls8021xpem = fix_cr( '%s' );\n", prefix,
4681               nvram_prefix_get( "tls8021xpem", prefix ) );
4682    websWrite( wp,
4683               "document.getElementById(\"%s_tls8021xpem\").value = %s_tls8021xpem;\n",
4684               prefix, prefix );
4685    websWrite( wp, "//]]>\n</script>\n" );
4686    websWrite( wp, "</div>\n" );
4687
4688    websWrite( wp, "<div class=\"setting\">\n" );
4689    websWrite( wp,
4690               "<div class=\"label\"><script type=\"text/javascript\">Capture(share.privatekey)</script></div>\n" );
4691    websWrite( wp,
4692               "<textarea cols=\"60\" rows=\"6\" id=\"%s_tls8021xprv\" name=\"%s_tls8021xprv\"></textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\n ",
4693               prefix, prefix );
4694    websWrite( wp, "var %s_tls8021xprv = fix_cr( '%s' );\n", prefix,
4695               nvram_prefix_get( "tls8021xprv", prefix ) );
4696    websWrite( wp,
4697               "document.getElementById(\"%s_tls8021xprv\").value = %s_tls8021xprv;\n",
4698               prefix, prefix );
4699    websWrite( wp, "//]]>\n</script>\n" );
4700    websWrite( wp, "</div>\n" );
4701
4702    websWrite( wp, "</div>\n" );
4703    websWrite( wp, "<script>\n//<![CDATA[\n " );
4704    // websWrite
4705    // (wp,"show_layer_ext(document.getElementsByName(\"%s_bridged\"),
4706    // \"%s_idnetvifs\", %s);\n",var, vvar, nvram_match (ssid, "0") ? "true"
4707    // : "false");
4708    char peap[32];
4709
4710    sprintf( peap, "%s_8021xtype", prefix );
4711    websWrite( wp,
4712               "show_layer_ext(document.wpa.%s_8021xtype, 'idpeap%s', %s);\n",
4713               prefix, prefix, nvram_match( peap,
4714                                            "peap" ) ? "true" : "false" );
4715    websWrite( wp,
4716               "show_layer_ext(document.wpa.%s_8021xtype, 'idtls%s', %s);\n",
4717               prefix, prefix, nvram_match( peap,
4718                                            "tls" ) ? "true" : "false" );
4719    websWrite( wp,
4720               "show_layer_ext(document.wpa.%s_8021xtype, 'idleap%s', %s);\n",
4721               prefix, prefix, nvram_match( peap,
4722                                            "leap" ) ? "true" : "false" );
4723    websWrite( wp, "//]]>\n</script>\n" );
4724
4725}
4726#endif
4727
4728#ifndef HAVE_WPA_SUPPLICANT
4729void ej_init_80211x_layers( webs_t wp, int argc, char_t ** argv )
4730{
4731    return;
4732}
4733#endif
4734
4735void show_wparadius( webs_t wp, char *prefix )
4736{
4737    char var[80];
4738
4739    websWrite( wp, "<div>\n" );
4740    websWrite( wp, "<div class=\"setting\">\n" );
4741    websWrite( wp,
4742               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.algorithms)</script></div>\n" );
4743    websWrite( wp, "<select name=\"%s_crypto\">\n", prefix );
4744    sprintf( var, "%s_crypto", prefix );
4745    websWrite( wp, "<option value=\"tkip\" %s>TKIP</option>\n",
4746               selmatch( var, "tkip", "selected=\"selected\"" ) );
4747    websWrite( wp, "<option value=\"aes\" %s>AES</option>\n",
4748               selmatch( var, "aes", "selected=\"selected\"" ) );
4749    websWrite( wp, "<option value=\"tkip+aes\" %s>TKIP+AES</option>\n",
4750               selmatch( var, "tkip+aes", "selected=\"selected\"" ) );
4751    websWrite( wp, "</select></div>\n" );
4752    show_radius( wp, prefix, 0 );
4753    websWrite( wp, "<div class=\"setting\">\n" );
4754    websWrite( wp,
4755               "<div class=\"label\"><script type=\"text/javascript\">Capture(wpa.rekey)</script></div>\n" );
4756    sprintf( var, "%s_wpa_gtk_rekey", prefix );
4757    websWrite( wp,
4758               "<input name=\"%s_wpa_gtk_rekey\" maxlength=\"5\" size=\"10\" onblur=\"valid_range(this,0,99999,wpa.rekey)\" value=\"%s\" />",
4759               prefix, nvram_default_get( var, "3600" ) );
4760    websWrite( wp, "</div>\n" );
4761    websWrite( wp, "</div>\n" );
4762}
4763
4764void show_wep( webs_t wp, char *prefix )
4765{
4766    char var[80];
4767    char *bit;
4768
4769    cprintf( "show wep\n" );
4770    websWrite( wp,
4771               "<div><div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(wep.defkey)</script></div>" );
4772    websWrite( wp, "<input type=\"hidden\" name=\"%s_WEP_key\" />", prefix );
4773    websWrite( wp,
4774               "<input type=\"hidden\" name=\"%s_wep\" value=\"restricted\" />",
4775               prefix );
4776    sprintf( var, "%s_key", prefix );
4777    nvram_default_get( var, "1" );
4778    websWrite( wp,
4779               "<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s_key\" %s />1&nbsp;\n",
4780               prefix, selmatch( var, "1", "checked=\"checked\"" ) );
4781    websWrite( wp,
4782               "<input class=\"spaceradio\" type=\"radio\" value=\"2\" name=\"%s_key\" %s />2&nbsp;\n",
4783               prefix, selmatch( var, "2", "checked=\"checked\"" ) );
4784    websWrite( wp,
4785               "<input class=\"spaceradio\" type=\"radio\" value=\"3\" name=\"%s_key\" %s />3&nbsp;\n",
4786               prefix, selmatch( var, "3", "checked=\"checked\"" ) );
4787    websWrite( wp,
4788               "<input class=\"spaceradio\" type=\"radio\" value=\"4\" name=\"%s_key\" %s />4&nbsp;\n",
4789               prefix, selmatch( var, "4", "checked=\"checked\"" ) );
4790    websWrite( wp, "</div>" );
4791    websWrite( wp,
4792               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.encrypt)</script></div>" );
4793
4794    sprintf( var, "%s_wep_bit", prefix );
4795    bit = nvram_safe_get( var );
4796
4797    cprintf( "bit %s\n", bit );
4798
4799    websWrite( wp,
4800               "<select name=\"%s_wep_bit\" size=\"1\" onchange=keyMode(this.form)>",
4801               prefix );
4802    websWrite( wp, "<option value=\"64\" %s >64 bits 10 hex digits</option>",
4803               selmatch( var, "64", "selected=\"selected\"" ) );
4804    websWrite( wp,
4805               "<option value=\"128\" %s >128 bits 26 hex digits</option>",
4806               selmatch( var, "128", "selected=\"selected\"" ) );
4807    websWrite( wp,
4808               "</select>\n</div>\n<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wep.passphrase)</script></div>\n" );
4809    websWrite( wp,
4810               "<input name=%s_passphrase maxlength=\"16\" size=\"20\" value=\"",
4811               prefix );
4812
4813    char p_temp[128];
4814    char temp[256];
4815
4816    sprintf( p_temp, "%s", get_wep_value( temp, "passphrase", bit, prefix ) );
4817    nvram_set( "passphrase_temp", p_temp );
4818    tf_webWriteESCNV( wp, "passphrase_temp" );
4819    nvram_unset( "passphrase_temp" );
4820
4821    websWrite( wp, "\" />" );
4822    websWrite( wp,
4823               "<input type=\"hidden\" value=\"Null\" name=\"generateButton\" />\n" );
4824    websWrite( wp,
4825               "<input class=\"button\" type=\"button\" value=\"Generate\" onclick=generateKey(this.form,\"%s\") name=wepGenerate />\n</div>",
4826               prefix );
4827
4828    char *mlen = "10";
4829    char *mlen2 = "12";
4830
4831    if( !strcmp( bit, "128" ) )
4832    {
4833        mlen = "26";
4834        mlen2 = "30";
4835    }
4836    websWrite( wp,
4837               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 1</div>\n" );
4838    websWrite( wp,
4839               "<input name=%s_key1 size=\"%s\" maxlength=\"%s\" value=\"%s\" /></div>\n",
4840               prefix, mlen2, mlen, get_wep_value( temp, "key1", bit,
4841                                                   prefix ) );
4842    websWrite( wp,
4843               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 2</div>\n" );
4844    websWrite( wp,
4845               "<input name=%s_key2 size=\"%s\" maxlength=\"%s\" value=\"%s\" /></div>\n",
4846               prefix, mlen2, mlen, get_wep_value( temp, "key2", bit,
4847                                                   prefix ) );
4848    websWrite( wp,
4849               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 3</div>\n" );
4850    websWrite( wp,
4851               "<input name=%s_key3 size=\"%s\" maxlength=\"%s\" value=\"%s\" /></div>\n",
4852               prefix, mlen2, mlen, get_wep_value( temp, "key3", bit,
4853                                                   prefix ) );
4854    websWrite( wp,
4855               "<div class=\"setting\"><div class=\"label\"><script type=\"text/javascript\">Capture(share.key)</script> 4</div>\n" );
4856    websWrite( wp,
4857               "<input name=%s_key4 size=\"%s\" maxlength=\"%s\" value=\"%s\" /></div>\n",
4858               prefix, mlen2, mlen, get_wep_value( temp, "key4", bit,
4859                                                   prefix ) );
4860    websWrite( wp, "</div>\n" );
4861}
4862
4863#endif
4864
4865void ej_get_wds_mac( webs_t wp, int argc, char_t ** argv )
4866{
4867    int mac = -1, wds_idx = -1, mac_idx = -1;
4868    char *c, wds_var[32] = "";
4869
4870    char *interface;
4871
4872    if( ejArgs( argc, argv, "%d %d %s", &wds_idx, &mac_idx, &interface ) < 3 )
4873    {
4874        websError( wp, 400, "Insufficient args\n" );
4875        return;
4876    }
4877    else if( wds_idx < 1 || wds_idx > MAX_WDS_DEVS )
4878        return;
4879    else if( mac_idx < 0 || mac_idx > 5 )
4880        return;
4881
4882    snprintf( wds_var, 31, "%s_wds%d_hwaddr", interface, wds_idx );
4883
4884    c = nvram_safe_get( wds_var );
4885
4886    if( c )
4887    {
4888        mac = get_single_mac( c, mac_idx );
4889        websWrite( wp, "%02X", mac );
4890    }
4891    else
4892        websWrite( wp, "00" );
4893
4894    return;
4895
4896}
4897
4898void ej_showbridgesettings( webs_t wp, int argc, char_t ** argv )
4899{
4900    char *interface;
4901    int mcast;
4902
4903#ifdef FASTWEB
4904    ejArgs( argc, argv, "%s %d", &interface, &mcast );
4905#else
4906    if( ejArgs( argc, argv, "%s %d", &interface, &mcast ) < 2 )
4907    {
4908        websError( wp, 400, "Insufficient args\n" );
4909        return;
4910    }
4911#endif
4912    showbridgesettings( wp, interface, mcast,0 );
4913}
4914
4915void ej_get_wds_ip( webs_t wp, int argc, char_t ** argv )
4916{
4917    int ip = -1, wds_idx = -1, ip_idx = -1;
4918    char *c, wds_var[32] = "";
4919
4920    char *interface;
4921
4922#ifdef FASTWEB
4923    ejArgs( argc, argv, "%d %d %s", &wds_idx, &ip_idx, &interface );
4924#else
4925    if( ejArgs( argc, argv, "%d %d %s", &wds_idx, &ip_idx, &interface ) < 3 )
4926    {
4927        websError( wp, 400, "Insufficient args\n" );
4928        return;
4929    }
4930#endif
4931    if( wds_idx < 1 || wds_idx > MAX_WDS_DEVS )
4932        return;
4933    else if( ip_idx < 0 || ip_idx > 3 )
4934        return;
4935
4936    snprintf( wds_var, 31, "%s_wds%d_ipaddr", interface, wds_idx );
4937
4938    c = nvram_safe_get( wds_var );
4939
4940    if( c )
4941    {
4942        ip = get_single_ip( c, ip_idx );
4943        websWrite( wp, "%d", ip );
4944    }
4945    else
4946        websWrite( wp, "0" );
4947
4948    return;
4949
4950}
4951
4952void ej_get_wds_netmask( webs_t wp, int argc, char_t ** argv )
4953{
4954    int nm = -1, wds_idx = -1, nm_idx = -1;
4955    char *c, wds_var[32] = "";
4956
4957    char *interface;
4958
4959#ifdef FASTWEB
4960    ejArgs( argc, argv, "%d %d %s", &wds_idx, &nm_idx, &interface );
4961#else
4962    if( ejArgs( argc, argv, "%d %d %s", &wds_idx, &nm_idx, &interface ) < 3 )
4963    {
4964        websError( wp, 400, "Insufficient args\n" );
4965        return;
4966    }
4967#endif
4968
4969    if( wds_idx < 1 || wds_idx > 6 )
4970        return;
4971    else if( nm_idx < 0 || nm_idx > 3 )
4972        return;
4973
4974    snprintf( wds_var, 31, "%s_wds%d_netmask", interface, wds_idx );
4975
4976    c = nvram_safe_get( wds_var );
4977
4978    if( c )
4979    {
4980        nm = get_single_ip( c, nm_idx );
4981        websWrite( wp, "%d", nm );
4982    }
4983    else
4984        websWrite( wp, "255" );
4985
4986    return;
4987
4988}
4989
4990void ej_get_wds_gw( webs_t wp, int argc, char_t ** argv )
4991{
4992    int gw = -1, wds_idx = -1, gw_idx = -1;
4993    char *c, wds_var[32] = "";
4994
4995    char *interface;
4996
4997#ifdef FASTWEB
4998    ejArgs( argc, argv, "%d %d %s", &wds_idx, &gw_idx, &interface );
4999#else
5000    if( ejArgs( argc, argv, "%d %d %s", &wds_idx, &gw_idx, &interface ) < 3 )
5001    {
5002        websError( wp, 400, "Insufficient args\n" );
5003        return;
5004    }
5005#endif
5006
5007    if( wds_idx < 1 || wds_idx > MAX_WDS_DEVS )
5008        return;
5009    else if( gw_idx < 0 || gw_idx > 3 )
5010        return;
5011
5012    snprintf( wds_var, 31, "%s_wds%d_gw", interface, wds_idx );
5013
5014    c = nvram_safe_get( wds_var );
5015
5016    if( c )
5017    {
5018        gw = get_single_ip( c, gw_idx );
5019        websWrite( wp, "%d", gw );
5020    }
5021    else
5022        websWrite( wp, "0" );
5023
5024    return;
5025
5026}
5027
5028void ej_get_br1_ip( webs_t wp, int argc, char_t ** argv )
5029{
5030    int ip = -1, ip_idx = -1;
5031    char *c;
5032
5033    char *interface;
5034
5035#ifdef FASTWEB
5036    ejArgs( argc, argv, "%d %s", &ip_idx, &interface );
5037#else
5038    if( ejArgs( argc, argv, "%d %s", &ip_idx, &interface ) < 2 )
5039    {
5040        websError( wp, 400, "Insufficient args\n" );
5041        return;
5042    }
5043#endif
5044    if( ip_idx < 0 || ip_idx > 3 )
5045        return;
5046    char br1[32];
5047
5048    sprintf( br1, "%s_br1_ipaddr", interface );
5049    c = nvram_safe_get( br1 );
5050
5051    if( c )
5052    {
5053        ip = get_single_ip( c, ip_idx );
5054        websWrite( wp, "%d", ip );
5055    }
5056    else
5057        websWrite( wp, "0" );
5058
5059    return;
5060
5061}
5062
5063void ej_get_br1_netmask( webs_t wp, int argc, char_t ** argv )
5064{
5065    int nm = -1, nm_idx = -1;
5066    char *c;
5067
5068    char *interface;
5069
5070#ifdef FASTWEB
5071    ejArgs( argc, argv, "%d %s", &nm_idx, &interface );
5072#else
5073    if( ejArgs( argc, argv, "%d %s", &nm_idx, &interface ) < 2 )
5074    {
5075        websError( wp, 400, "Insufficient args\n" );
5076        return;
5077    }
5078#endif
5079    if( nm_idx < 0 || nm_idx > 3 )
5080        return;
5081    char nms[32];
5082
5083    sprintf( nms, "%s_br1_netmask", interface );
5084    c = nvram_safe_get( nms );
5085
5086    if( c )
5087    {
5088        nm = get_single_ip( c, nm_idx );
5089        websWrite( wp, "%d", nm );
5090    }
5091    else
5092        websWrite( wp, "255" );
5093
5094    return;
5095
5096}
5097
5098#ifdef HAVE_MADWIFI
5099
5100int get_acktiming( void )
5101{
5102    char path[64];
5103    int ifcount, ack = 0;
5104
5105    strcpy( path, nvram_safe_get( "wifi_display" ) );
5106    sscanf( path, "ath%d", &ifcount );
5107    sprintf( path, "/proc/sys/dev/wifi%d/acktimeout", ifcount );
5108    FILE *in = fopen( path, "rb" );
5109
5110    if( in != NULL )
5111    {
5112        fscanf( in, "%d", &ack );
5113        fclose( in );
5114    }
5115    return ack;
5116}
5117
5118void ej_show_acktiming( webs_t wp, int argc, char_t ** argv )
5119{
5120    websWrite( wp, "<div class=\"setting\">\n" );
5121    websWrite( wp, "<div class=\"label\">%s</div>\n",
5122               live_translate( "share.acktiming" ) );
5123    int ack = get_acktiming(  );
5124    int distance = ( ( ack - 3 ) / 2 ) * 300;
5125
5126    websWrite( wp, "<span id=\"wl_ack\">%d&#181;s (%dm)</span> &nbsp;\n", ack,
5127               distance );
5128    websWrite( wp, "</div>\n" );
5129}
5130
5131void ej_update_acktiming( webs_t wp, int argc, char_t ** argv )
5132{
5133    int ack = get_acktiming(  );
5134    int distance = ( ( ack - 3 ) / 2 ) * 300;
5135
5136    websWrite( wp, "%d&#181;s (%dm)", ack, distance );
5137}
5138
5139extern float wifi_getrate( char *ifname );
5140
5141#define KILO    1e3
5142#define MEGA    1e6
5143#define GIGA    1e9
5144
5145void ej_get_currate( webs_t wp, int argc, char_t ** argv )
5146{
5147    char mode[32];
5148    int state = get_radiostate( nvram_safe_get( "wifi_display" ) );
5149
5150    if( state == 0 || state == -1 )
5151    {
5152        websWrite( wp, "%s", live_translate( "share.disabled" ) );
5153        return;
5154    }
5155    float rate = wifi_getrate( nvram_safe_get( "wifi_display" ) );
5156    char scale;
5157    int divisor;
5158
5159    if( rate >= GIGA )
5160    {
5161        scale = 'G';
5162        divisor = GIGA;
5163    }
5164    else
5165    {
5166        if( rate >= MEGA )
5167        {
5168            scale = 'M';
5169            divisor = MEGA;
5170        }
5171        else
5172        {
5173            scale = 'k';
5174            divisor = KILO;
5175        }
5176    }
5177    sprintf( mode, "%s_channelbw", nvram_safe_get( "wifi_display" ) );
5178    if( nvram_match( mode, "40" ) )
5179        rate *= 2;
5180    if( rate > 0.0 )
5181    {
5182        websWrite( wp, "%g %cb/s", rate / divisor, scale );
5183    }
5184    else
5185        websWrite( wp, "%s", live_translate( "share.auto" ) );
5186
5187}
5188
5189#elif HAVE_RT2880
5190extern float wifi_getrate( char *ifname );
5191
5192#define KILO    1e3
5193#define MEGA    1e6
5194#define GIGA    1e9
5195
5196void ej_get_currate( webs_t wp, int argc, char_t ** argv )
5197{
5198    char mode[32];
5199    int state = get_radiostate( "wl0" );
5200
5201    if( state == 0 || state == -1 )
5202    {
5203        websWrite( wp, "%s", live_translate( "share.disabled" ) );
5204        return;
5205    }
5206    float rate = wifi_getrate( "ra0" );
5207    char scale;
5208    int divisor;
5209
5210    if( rate >= GIGA )
5211    {
5212        scale = 'G';
5213        divisor = GIGA;
5214    }
5215    else
5216    {
5217        if( rate >= MEGA )
5218        {
5219            scale = 'M';
5220            divisor = MEGA;
5221        }
5222        else
5223        {
5224            scale = 'k';
5225            divisor = KILO;
5226        }
5227    }
5228    if( rate > 0.0 )
5229    {
5230        websWrite( wp, "%g %cb/s", rate / divisor, scale );
5231    }
5232    else
5233        websWrite( wp, "%s", live_translate( "share.auto" ) );
5234
5235}
5236
5237
5238void ej_show_acktiming( webs_t wp, int argc, char_t ** argv )
5239{
5240    return;
5241}
5242
5243void ej_update_acktiming( webs_t wp, int argc, char_t ** argv )
5244{
5245    return;
5246}
5247
5248
5249#else
5250
5251void ej_get_currate( webs_t wp, int argc, char_t ** argv )
5252{
5253    int rate = 0;
5254
5255    wl_ioctl( get_wdev(  ), WLC_GET_RATE, &rate, sizeof( rate ) );
5256
5257    if( rate > 0 )
5258        websWrite( wp, "%d%s Mbps", ( rate / 2 ), ( rate & 1 ) ? ".5" : "" );
5259    else
5260        websWrite( wp, "%s", live_translate( "share.unknown" ) );
5261
5262    return;
5263}
5264
5265void ej_show_acktiming( webs_t wp, int argc, char_t ** argv )
5266{
5267    return;
5268}
5269
5270void ej_update_acktiming( webs_t wp, int argc, char_t ** argv )
5271{
5272    return;
5273}
5274
5275
5276#endif
5277
5278void ej_get_uptime( webs_t wp, int argc, char_t ** argv )
5279{
5280    char line[256];
5281    FILE *fp;
5282
5283    if( ( fp = popen( "uptime", "r" ) ) )
5284    {
5285        fgets( line, sizeof( line ), fp );
5286        line[strlen( line ) - 1] = '\0';        // replace new line with null
5287        websWrite( wp, "%s", line );
5288        pclose( fp );
5289    }
5290    return;
5291}
5292
5293void ej_get_wan_uptime( webs_t wp, int argc, char_t ** argv )
5294{
5295    float sys_uptime;
5296    float uptime;
5297    int days, minutes;
5298    FILE *fp, *fp2;
5299
5300    if( nvram_match( "wan_proto", "disabled" ) )
5301        return;
5302    if( !( fp = fopen( "/tmp/.wanuptime", "r" ) ) )
5303    {
5304        websWrite( wp, "%s", live_translate( "status_router.notavail" ) );
5305        return;
5306    }
5307    if( !feof( fp ) && fscanf( fp, "%f", &uptime ) == 1 )
5308    {
5309        fp2 = fopen( "/proc/uptime", "r" );
5310        fscanf( fp2, "%f", &sys_uptime );
5311        fclose( fp2 );
5312        uptime = sys_uptime - uptime;
5313        days = ( int )uptime / ( 60 * 60 * 24 );
5314        if( days )
5315            websWrite( wp, "%d day%s, ", days, ( days == 1 ? "" : "s" ) );
5316        minutes = ( int )uptime / 60;
5317        websWrite( wp, "%d:%02d:%02d", ( minutes / 60 ) % 24, minutes % 60,
5318                   ( int )uptime % 60 );
5319    }
5320    fclose( fp );
5321
5322    return;
5323
5324}
5325
5326#ifdef HAVE_MADWIFI
5327
5328void ej_get_curchannel( webs_t wp, int argc, char_t ** argv )
5329{
5330    int channel = wifi_getchannel( nvram_safe_get( "wifi_display" ) );
5331
5332    if( channel > 0 && channel < 1000 )
5333    {
5334        websWrite( wp, "%d (%d Mhz)", channel,
5335                   ( wifi_getfreq( nvram_safe_get( "wifi_display" ) ) +
5336                     get_wifioffset( nvram_safe_get( "wifi_display" ) ) ) );
5337    }
5338    else
5339        // websWrite (wp, "unknown");
5340        websWrite( wp, "%s", live_translate( "share.unknown" ) );
5341    return;
5342}
5343
5344#elif HAVE_RT2880
5345void ej_get_curchannel( webs_t wp, int argc, char_t ** argv )
5346{
5347    int channel = wifi_getchannel( "ra0");
5348
5349    if( channel > 0 && channel < 1000 )
5350    {
5351        websWrite( wp, "%d (%d Mhz)", channel,wifi_getfreq( "ra0" ) );
5352    }
5353    else
5354        // websWrite (wp, "unknown");
5355        websWrite( wp, "%s", live_translate( "share.unknown" ) );
5356    return;
5357}
5358
5359
5360#else
5361
5362void ej_get_curchannel( webs_t wp, int argc, char_t ** argv )
5363{
5364    channel_info_t ci;
5365
5366    memset( &ci, 0, sizeof( ci ) );
5367    wl_ioctl( get_wdev(  ), WLC_GET_CHANNEL, &ci, sizeof( ci ) );
5368    if( ci.scan_channel > 0 )
5369    {
5370        websWrite( wp, "%d (scanning)", ci.scan_channel );
5371    }
5372    else if( ci.hw_channel > 0 )
5373    {
5374        websWrite( wp, "%d", ci.hw_channel );
5375    }
5376    else
5377        // websWrite (wp, "unknown");
5378        websWrite( wp, "%s", live_translate( "share.unknown" ) );
5379    return;
5380
5381}
5382
5383#endif
5384#ifdef HAVE_MADWIFI
5385#include <sys/types.h>
5386#include <sys/file.h>
5387#include <sys/ioctl.h>
5388#include <sys/socket.h>
5389#include <stdio.h>
5390#include <stdlib.h>
5391#include <string.h>
5392#include <stdint.h>
5393#include <ctype.h>
5394#include <getopt.h>
5395#include <err.h>
5396
5397#include "wireless_copy.h"
5398#include "net80211/ieee80211.h"
5399#include "net80211/ieee80211_crypto.h"
5400#include "net80211/ieee80211_ioctl.h"
5401static const char *ieee80211_ntoa( const uint8_t mac[IEEE80211_ADDR_LEN] )
5402{
5403    static char a[18];
5404    int i;
5405
5406    i = snprintf( a, sizeof( a ), "%02x:%02x:%02x:%02x:%02x:%02x",
5407                  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
5408    return ( i < 17 ? NULL : a );
5409}
5410
5411int
5412ej_active_wireless_if( webs_t wp, int argc, char_t ** argv,
5413                       char *ifname, int cnt, int turbo, int macmask )
5414{
5415    // unsigned char buf[24 * 1024];
5416
5417    unsigned char *cp;
5418    int s, len;
5419    struct iwreq iwr;
5420
5421    if( !ifexists( ifname ) )
5422    {
5423        printf( "IOCTL_STA_INFO ifresolv %s failed!\n", ifname );
5424        return cnt;
5425    }
5426    int state = get_radiostate( ifname );
5427
5428    if( state == 0 || state == -1 )
5429    {
5430        printf( "IOCTL_STA_INFO radio %s not enabled!\n", ifname );
5431        return cnt;
5432    }
5433    s = socket( AF_INET, SOCK_DGRAM, 0 );
5434    if( s < 0 )
5435    {
5436        fprintf( stderr, "socket(SOCK_DRAGM)\n" );
5437        return cnt;
5438    }
5439    ( void )memset( &iwr, 0, sizeof( struct iwreq ) );
5440    ( void )strncpy( iwr.ifr_name, ifname, sizeof( iwr.ifr_name ) );
5441    unsigned char *buf = ( unsigned char * )malloc( 24 * 1024 );
5442
5443    iwr.u.data.pointer = ( void * )buf;
5444    iwr.u.data.length = 24 * 1024;
5445    if( ioctl( s, IEEE80211_IOCTL_STA_INFO, &iwr ) < 0 )
5446    {
5447        fprintf( stderr, "IOCTL_STA_INFO for %s failed!\n", ifname );
5448        close( s );
5449        free( buf );
5450        return cnt;
5451    }
5452    len = iwr.u.data.length;
5453    if( len < sizeof( struct ieee80211req_sta_info ) )
5454    {
5455        // fprintf(stderr,"IOCTL_STA_INFO len<struct %s failed!\n",ifname);
5456        close( s );
5457        free( buf );
5458        return cnt;
5459    }
5460    cp = buf;
5461    do
5462    {
5463        struct ieee80211req_sta_info *si;
5464        uint8_t *vp;
5465
5466        si = ( struct ieee80211req_sta_info * )cp;
5467        vp = ( u_int8_t * ) ( si + 1 );
5468
5469        if( cnt )
5470            websWrite( wp, "," );
5471        cnt++;
5472        char mac[32];
5473
5474        strcpy( mac, ieee80211_ntoa( si->isi_macaddr ) );
5475        if( nvram_match( "maskmac", "1" ) && macmask )
5476        {
5477            mac[0] = 'x';
5478            mac[1] = 'x';
5479            mac[3] = 'x';
5480            mac[4] = 'x';
5481            mac[6] = 'x';
5482            mac[7] = 'x';
5483            mac[9] = 'x';
5484            mac[10] = 'x';
5485        }
5486        if( si->isi_noise == 0 )
5487        {
5488            si->isi_noise = -95;
5489        }
5490        if( si->isi_rates
5491            && ( ( si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL ) != 0 )
5492            && ( ( si->isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL ) !=
5493                 0 ) )
5494        {
5495            websWrite( wp, "'%s','%s','%3dM','%3dM','%d','%d','%d'",
5496                       mac, ifname,
5497                       ( ( si->
5498                           isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL ) /
5499                         2 ) * turbo,
5500                       ( ( si->
5501                           isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL ) /
5502                         2 ) * turbo, si->isi_noise + si->isi_rssi,
5503                       si->isi_noise, si->isi_rssi );
5504        }
5505        else
5506        {
5507            websWrite( wp, "'%s','%s','N/A','N/A','%d','%d','%d'", mac,
5508                       ifname, si->isi_noise + si->isi_rssi, si->isi_noise,
5509                       si->isi_rssi );
5510        }
5511        cp += si->isi_len;
5512        len -= si->isi_len;
5513    }
5514    while( len >= sizeof( struct ieee80211req_sta_info ) );
5515    free( buf );
5516    close( s );
5517
5518    return cnt;
5519}
5520extern char *getiflist( void );
5521
5522void ej_active_wireless( webs_t wp, int argc, char_t ** argv )
5523{
5524    int c = getdevicecount(  );
5525    char devs[32];
5526    int i;
5527    int cnt = 0;
5528    char turbo[32];
5529    int t;
5530    int macmask;
5531
5532#ifdef FASTWEB
5533    ejArgs( argc, argv, "%d", &macmask );
5534#else
5535    if( ejArgs( argc, argv, "%d", &macmask ) < 1 )
5536    {
5537        websError( wp, 400, "Insufficient args\n" );
5538        return;
5539    }
5540#endif
5541    for( i = 0; i < c; i++ )
5542    {
5543        sprintf( devs, "ath%d", i );
5544        sprintf( turbo, "%s_channelbw", devs );
5545        if( nvram_match( turbo, "40" ) )
5546            t = 2;
5547        else
5548            t = 1;
5549        cnt = ej_active_wireless_if( wp, argc, argv, devs, cnt, t, macmask );
5550        char vif[32];
5551
5552        sprintf( vif, "%s_vifs", devs );
5553        char var[80], *next;
5554        char *vifs = nvram_get( vif );
5555
5556        if( vifs != NULL )
5557            foreach( var, vifs, next )
5558        {
5559            cnt =
5560                ej_active_wireless_if( wp, argc, argv, var, cnt, t, macmask );
5561        }
5562    }
5563
5564    // show wds links
5565    for( i = 0; i < c; i++ )
5566    {
5567
5568        int s;
5569
5570        for( s = 1; s <= 10; s++ )
5571        {
5572            char wdsvarname[32] = { 0 };
5573            char wdsdevname[32] = { 0 };
5574            char wdsmacname[32] = { 0 };
5575            char *dev;
5576            char *hwaddr;
5577            char var[80];
5578
5579            sprintf( wdsvarname, "ath%d_wds%d_enable", i, s );
5580            sprintf( wdsdevname, "ath%d_wds%d_if", i, s );
5581            sprintf( wdsmacname, "ath%d_wds%d_hwaddr", i, s );
5582            sprintf( turbo, "ath%d_channelbw", i );
5583            if( nvram_match( turbo, "40" ) )
5584                t = 2;
5585            else
5586                t = 1;
5587
5588            dev = nvram_safe_get( wdsdevname );
5589            if( dev == NULL || strlen( dev ) == 0 )
5590                continue;
5591            if( nvram_match( wdsvarname, "0" ) )
5592                continue;
5593            cnt =
5594                ej_active_wireless_if( wp, argc, argv, dev, cnt, t, macmask );
5595        }
5596    }
5597}
5598
5599#elif HAVE_RT2880
5600
5601#include <sys/types.h>
5602#include <sys/file.h>
5603#include <sys/ioctl.h>
5604#include <sys/socket.h>
5605#include <stdio.h>
5606#include <stdlib.h>
5607#include <string.h>
5608#include <stdint.h>
5609#include <ctype.h>
5610#include <getopt.h>
5611#include <err.h>
5612
5613#include "wireless_copy.h"
5614static const char *ieee80211_ntoa( const uint8_t mac[6] )
5615{
5616    static char a[18];
5617    int i;
5618
5619    i = snprintf( a, sizeof( a ), "%02x:%02x:%02x:%02x:%02x:%02x",
5620                  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
5621    return ( i < 17 ? NULL : a );
5622}
5623typedef union _MACHTTRANSMIT_SETTING {
5624        struct  {
5625                unsigned short  MCS:7;  // MCS
5626                unsigned short  BW:1;   //channel bandwidth 20MHz or 40 MHz
5627                unsigned short  ShortGI:1;
5628                unsigned short  STBC:2; //SPACE
5629                unsigned short  rsv:3;
5630                unsigned short  MODE:2; // Use definition MODE_xxx.
5631        } field;
5632        unsigned short      word;
5633} MACHTTRANSMIT_SETTING;
5634
5635typedef struct _RT_802_11_MAC_ENTRY {
5636        unsigned char            Addr[6];
5637        unsigned char            Aid;
5638        unsigned char            Psm;     // 0:PWR_ACTIVE, 1:PWR_SAVE
5639        unsigned char            MimoPs;  // 0:MMPS_STATIC, 1:MMPS_DYNAMIC, 3:MMPS_Enabled
5640        char                     AvgRssi0;
5641        char                     AvgRssi1;
5642        char                     AvgRssi2;
5643        unsigned int             ConnectedTime;
5644        MACHTTRANSMIT_SETTING    TxRate;
5645} RT_802_11_MAC_ENTRY;
5646
5647typedef struct _RT_802_11_MAC_TABLE {
5648        unsigned long            Num;
5649        RT_802_11_MAC_ENTRY      Entry[32]; //MAX_LEN_OF_MAC_TABLE = 32
5650} RT_802_11_MAC_TABLE;
5651
5652#define RTPRIV_IOCTL_GET_MAC_TABLE              (SIOCIWFIRSTPRIV + 0x0F)
5653
5654typedef struct STAINFO {
5655        char mac[6];
5656        char rssi;
5657        char noise;
5658        char ifname[32];
5659} STAINFO;
5660
5661
5662int
5663ej_active_wireless_if( webs_t wp, int argc, char_t ** argv,
5664                       char *ifname, int cnt, int turbo, int macmask )
5665{
5666
5667    RT_802_11_MAC_TABLE table = {0};
5668
5669    unsigned char *cp;
5670    int s, len,i;
5671    struct iwreq iwr;
5672    int ignore=0;
5673
5674    if( !ifexists( ifname ) )
5675    {
5676        printf( "IOCTL_STA_INFO ifresolv %s failed!\n", ifname );
5677        return cnt;
5678    }
5679    int state = get_radiostate( ifname );
5680
5681    if( state == 0 || state == -1 )
5682    {
5683        return cnt;
5684    }
5685    s = socket( AF_INET, SOCK_DGRAM, 0 );
5686    if( s < 0 )
5687    {
5688        return cnt;
5689    }
5690    ( void )memset( &iwr, 0, sizeof( struct iwreq ) );
5691    ( void )strncpy( iwr.ifr_name, ifname, sizeof( iwr.ifr_name ) );
5692
5693    iwr.u.data.pointer = (caddr_t) &table;
5694//    iwr.u.data.length = 24 * 1024;
5695    if( ioctl( s, RTPRIV_IOCTL_GET_MAC_TABLE, &iwr ) < 0 )
5696    {
5697        ignore=1;
5698    }
5699if (!ignore)
5700for (i = 0; i < table.Num; i++) {
5701        if( cnt )
5702            websWrite( wp, "," );
5703        cnt++;
5704        char mac[32];
5705        strcpy( mac, ieee80211_ntoa( table.Entry[i].Addr ) );
5706        if( nvram_match( "maskmac", "1" ) && macmask )
5707        {
5708            mac[0] = 'x';
5709            mac[1] = 'x';
5710            mac[3] = 'x';
5711            mac[4] = 'x';
5712            mac[6] = 'x';
5713            mac[7] = 'x';
5714            mac[9] = 'x';
5715            mac[10] = 'x';
5716        }
5717#if 0   
5718        if( si->isi_rates
5719            && ( ( si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL ) != 0 )
5720            && ( ( si->isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL ) !=
5721                 0 ) )
5722        {
5723            websWrite( wp, "'%s','%s','%3dM','%3dM','%d','%d','%d'",
5724                       mac, ifname,
5725                       ( ( si->
5726                           isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL ) /
5727                         2 ) * turbo,
5728                       ( ( si->
5729                           isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL ) /
5730                         2 ) * turbo, -95 + table.Entry[i].AvgRssi0,
5731                       -95, table.Entry[i].AvgRssi0 );
5732        }
5733        else
5734#endif 
5735        {
5736            websWrite( wp, "'%s','%s','N/A','N/A','%d','%d','%d'", mac,
5737                       ifname, table.Entry[i].AvgRssi0, -95,
5738                        (table.Entry[i].AvgRssi0 - (-95)) );
5739        }
5740    }
5741STAINFO *sta = getRaStaInfo("wl0");
5742    if (sta)
5743        {
5744        char mac[32];
5745        strcpy( mac, ieee80211_ntoa( sta->mac ) );
5746            websWrite( wp, "'%s','%s','N/A','N/A','%d','%d','%d'", mac,sta->ifname, sta->rssi, sta->noise,(sta->rssi - (sta->noise)) );
5747        free(sta);
5748       
5749        }
5750   
5751close(s);
5752    return cnt;
5753}
5754extern char *getiflist( void );
5755
5756void ej_active_wireless( webs_t wp, int argc, char_t ** argv )
5757{
5758    char devs[32];
5759    int i;
5760    int cnt = 0;
5761    char turbo[32];
5762    int t;
5763    int macmask;
5764
5765#ifdef FASTWEB
5766    ejArgs( argc, argv, "%d", &macmask );
5767#else
5768    if( ejArgs( argc, argv, "%d", &macmask ) < 1 )
5769    {
5770        websError( wp, 400, "Insufficient args\n" );
5771        return;
5772    }
5773#endif
5774        sprintf( devs, "ra0");
5775        t = 1;
5776        cnt = ej_active_wireless_if( wp, argc, argv, "ra0", cnt, t, macmask );
5777
5778}
5779
5780
5781#else
5782
5783#define RSSI_TMP        "/tmp/.rssi"
5784#define ASSOCLIST_CMD   "wl assoclist"
5785#define RSSI_CMD        "wl rssi"
5786#define NOISE_CMD       "wl noise"
5787
5788#ifndef HAVE_MSSID
5789void ej_active_wireless( webs_t wp, int argc, char_t ** argv )
5790{
5791    int rssi = 0, noise = 0;
5792    FILE *fp2;
5793    char *mode;
5794    char mac[30];
5795    char list[2][30];
5796    char line[80];
5797    char cmd[80];
5798    int macmask;
5799
5800#ifdef FASTWEB
5801    ejArgs( argc, argv, "%d", &macmask );
5802#else
5803    if( ejArgs( argc, argv, "%d", &macmask ) < 1 )
5804    {
5805        websError( wp, 400, "Insufficient args\n" );
5806        return;
5807    }
5808#endif
5809
5810    unlink( RSSI_TMP );
5811    int cnt = 0;
5812
5813    mode = nvram_safe_get( "wl_mode" );
5814    unsigned char buf[WLC_IOCTL_MAXLEN];
5815
5816    memset( buf, 0, WLC_IOCTL_MAXLEN );
5817    char *iface = get_wdev(  );
5818
5819    if( !ifexists( iface ) )
5820        return;
5821    int r = getassoclist( iface, buf );
5822
5823    if( r < 0 )
5824        return;
5825    struct maclist *maclist = ( struct maclist * )buf;
5826    int i;
5827
5828    for( i = 0; i < maclist->count; i++ )
5829    {
5830        ether_etoa( ( uint8 * ) & maclist->ea[i], mac );
5831
5832        rssi = 0;
5833        noise = 0;
5834        // get rssi value
5835        if( strcmp( mode, "ap" ) && strcmp( mode, "apsta" )
5836            && strcmp( mode, "apstawet" ) )
5837            sysprintf( "%s > %s", RSSI_CMD, RSSI_TMP );
5838        else
5839            sysprintf( "%s \"%s\" > %s", RSSI_CMD, mac, RSSI_TMP );
5840
5841        // get noise value if not ap mode
5842        if( strcmp( mode, "ap" ) )
5843            sysprintf( "%s >> %s", NOISE_CMD, RSSI_TMP );
5844
5845        fp2 = fopen( RSSI_TMP, "r" );
5846        if( fgets( line, sizeof( line ), fp2 ) != NULL )
5847        {
5848
5849            // get rssi
5850            // #ifdef HAVE_MSSID
5851            if( sscanf( line, "%d", &rssi ) != 1 )
5852                continue;
5853
5854            // noise=getNoise(iface);
5855
5856            if( strcmp( mode, "ap" ) &&
5857                fgets( line, sizeof( line ), fp2 ) != NULL &&
5858                sscanf( line, "%d", &noise ) != 1 )
5859                continue;
5860            /*
5861             * #else if (sscanf (line, "%s %s %d", list[0], list[1], &rssi)
5862             * != 3) continue; // noise=getNoise(iface); if (strcmp (mode,
5863             * "ap") && fgets (line, sizeof (line), fp2) != NULL && sscanf
5864             * (line, "%s %s %d", list[0], list[1], &noise) != 3) continue;
5865             * #endif
5866             */
5867            // get noise for client/wet mode
5868
5869            fclose( fp2 );
5870        }
5871        if( nvram_match( "maskmac", "1" ) && macmask )
5872        {
5873            mac[0] = 'x';
5874            mac[1] = 'x';
5875            mac[3] = 'x';
5876            mac[4] = 'x';
5877            mac[6] = 'x';
5878            mac[7] = 'x';
5879            mac[9] = 'x';
5880            mac[10] = 'x';
5881        }
5882        if( cnt )
5883            websWrite( wp, "," );
5884        cnt++;
5885        if( !strcmp( mode, "ap" ) )
5886        {
5887            // char *ref = nvram_get ("noise_reference");
5888            noise = -98;
5889            // if (ref)
5890            // noise = atoi (ref);
5891        }
5892        websWrite( wp, "'%s','%d','%d','%d'", mac, rssi, noise,
5893                   rssi - noise );
5894    }
5895    unlink( RSSI_TMP );
5896
5897    return;
5898}
5899#else
5900int
5901ej_active_wireless_if( webs_t wp, int argc, char_t ** argv,
5902                       char *iface, char *visible, int cnt )
5903{
5904    int rssi = 0, noise = 0;
5905    FILE *fp2;
5906    char *mode;
5907    char mac[30];
5908    char line[80];
5909    int macmask;
5910
5911#ifdef FASTWEB
5912    ejArgs( argc, argv, "%d", &macmask );
5913#else
5914    if( ejArgs( argc, argv, "%d", &macmask ) < 1 )
5915    {
5916        websError( wp, 400, "Insufficient args\n" );
5917        return 0;
5918    }
5919#endif
5920    if( !ifexists( iface ) )
5921        return cnt;
5922    unlink( RSSI_TMP );
5923    char wlmode[32];
5924
5925    sprintf( wlmode, "%s_mode", visible );
5926    mode = nvram_safe_get( wlmode );
5927    unsigned char buf[WLC_IOCTL_MAXLEN];
5928
5929    memset( buf, 0, WLC_IOCTL_MAXLEN ); // get_wdev
5930    int r = getassoclist( iface, buf );
5931
5932    if( r < 0 )
5933        return cnt;
5934    struct maclist *maclist = ( struct maclist * )buf;
5935    int i;
5936
5937    for( i = 0; i < maclist->count; i++ )
5938    {
5939        ether_etoa( ( uint8 * ) & maclist->ea[i], mac );
5940
5941        rssi = 0;
5942        noise = 0;
5943        // get rssi value
5944        if( strcmp( mode, "ap" ) && strcmp( mode, "apsta" )
5945            && strcmp( mode, "apstawet" ) )
5946            sysprintf( "wl -i %s rssi > %s", iface, RSSI_TMP );
5947        else
5948            sysprintf( "wl -i %s rssi \"%s\" > %s", iface, mac, RSSI_TMP );
5949
5950        // get noise value if not ap mode
5951        // if (strcmp (mode, "ap"))
5952        // snprintf (cmd, sizeof (cmd), "wl -i %s noise >> %s", iface,
5953        // RSSI_TMP);
5954        // system2 (cmd); // get RSSI value for mac
5955
5956        fp2 = fopen( RSSI_TMP, "r" );
5957        if( fgets( line, sizeof( line ), fp2 ) != NULL )
5958        {
5959
5960            // get rssi
5961            if( sscanf( line, "%d", &rssi ) != 1 )
5962                continue;
5963            noise = getNoise( iface, NULL );
5964            /*
5965             * if (strcmp (mode, "ap") && fgets (line, sizeof (line), fp2) !=
5966             * NULL && sscanf (line, "%d", &noise) != 1) continue;
5967             */
5968            // get noise for client/wet mode
5969
5970            fclose( fp2 );
5971        }
5972        if( nvram_match( "maskmac", "1" ) && macmask )
5973        {
5974            mac[0] = 'x';
5975            mac[1] = 'x';
5976            mac[3] = 'x';
5977            mac[4] = 'x';
5978            mac[6] = 'x';
5979            mac[7] = 'x';
5980            mac[9] = 'x';
5981            mac[10] = 'x';
5982        }
5983        if( cnt )
5984            websWrite( wp, "," );
5985        cnt++;
5986        /*
5987         * if (!strcmp (mode, "ap")) { noise = getNoise(iface,NULL); // null
5988         * only for broadcom }
5989         */
5990        websWrite( wp, "'%s','%s','N/A','N/A','%d','%d','%d'", mac, iface,
5991                   rssi, noise, rssi - noise );
5992    }
5993    unlink( RSSI_TMP );
5994
5995    return cnt;
5996}
5997
5998void ej_active_wireless( webs_t wp, int argc, char_t ** argv )
5999{
6000    int cnt = 0;
6001    int c = get_wl_instances(  );
6002    int i;
6003
6004    for( i = 0; i < c; i++ )
6005    {
6006        char wlif[32];
6007
6008        sprintf( wlif, "wl%d", i );
6009        cnt =
6010            ej_active_wireless_if( wp, argc, argv, get_wl_instance_name( i ),
6011                                   wlif, cnt );
6012        char *next;
6013        char var[80];
6014        char *vifs = nvram_nget( "wl%d_vifs", i );
6015
6016        if( vifs == NULL )
6017            return;
6018
6019        foreach( var, vifs, next )
6020        {
6021            cnt = ej_active_wireless_if( wp, argc, argv, var, var, cnt );
6022        }
6023    }
6024}
6025
6026#endif
6027
6028#endif
6029
6030#define WDS_RSSI_TMP    "/tmp/.rssi"
6031void ej_active_wds_instance( webs_t wp, int argc, char_t ** argv,
6032                             int instance );
6033void ej_active_wds( webs_t wp, int argc, char_t ** argv )
6034{
6035    int cnt = get_wl_instances(  );
6036    int c;
6037
6038    for( c = 0; c < cnt; c++ )
6039        ej_active_wds_instance( wp, argc, argv, c );
6040}
6041
6042void
6043ej_active_wds_instance( webs_t wp, int argc, char_t ** argv, int instance )
6044{
6045#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
6046    int rssi = 0, i;
6047    FILE *fp2;
6048    char *mode;
6049    char mac[30];
6050    char line[80];
6051
6052    // char title[30];
6053    char wdsvar[30];
6054    char desc[30];
6055    int cnt = 0;
6056    int macmask;
6057
6058    if( ejArgs( argc, argv, "%d", &macmask ) < 1 )
6059    {
6060        websError( wp, 400, "Insufficient args\n" );
6061        return;
6062    }
6063
6064    unlink( WDS_RSSI_TMP );
6065
6066    mode = nvram_nget( "wl%d_mode", instance );
6067
6068    if( strcmp( mode, "ap" ) && strcmp( mode, "apsta" )
6069        && strcmp( mode, "apstawet" ) )
6070        return;
6071    unsigned char buf[WLC_IOCTL_MAXLEN];
6072    char *iface = get_wl_instance_name( instance );
6073
6074    if( !ifexists( iface ) )
6075        return;
6076    int r = getwdslist( iface, buf );
6077
6078    if( r < 0 )
6079        return;
6080    struct maclist *maclist = ( struct maclist * )buf;
6081    int e;
6082
6083    for( e = 0; e < maclist->count; e++ )
6084    {
6085
6086        ether_etoa( ( uint8 * ) & maclist->ea[e], mac );
6087
6088        rssi = 0;
6089        memset( desc, 0, 30 );
6090        for( i = 1; i <= 10; i++ )
6091        {
6092            snprintf( wdsvar, 30, "wl%d_wds%d_hwaddr", instance, i );
6093            if( nvram_match( wdsvar, mac ) )
6094            {
6095                snprintf( wdsvar, 30, "wl%d_wds%d_desc", instance, i );
6096                snprintf( desc, sizeof( desc ), "%s", nvram_get( wdsvar ) );
6097                if( !strcmp( nvram_get( wdsvar ), "" ) )
6098                    strcpy( desc, "&nbsp;" );
6099            }
6100        }
6101
6102        sysprintf( "%s \"%s\" > %s", RSSI_CMD, mac, RSSI_TMP );
6103
6104        fp2 = fopen( RSSI_TMP, "r" );
6105        if( fgets( line, sizeof( line ), fp2 ) != NULL )
6106        {
6107
6108            // get rssi
6109            if( sscanf( line, "%d", &rssi ) != 1 )
6110                continue;
6111            fclose( fp2 );
6112        }
6113        if( nvram_match( "maskmac", "1" ) && macmask )
6114        {
6115            mac[0] = 'x';
6116            mac[1] = 'x';
6117            mac[3] = 'x';
6118            mac[4] = 'x';
6119            mac[6] = 'x';
6120            mac[7] = 'x';
6121            mac[9] = 'x';
6122            mac[10] = 'x';
6123        }
6124        if( cnt )
6125            websWrite( wp, "," );
6126        cnt++;
6127        int noise = getNoise( iface, NULL );
6128
6129        websWrite( wp,
6130                   "\"%s\",\"%s\",\"%d\",\"%d\",\"%d\"",
6131                   mac, desc, rssi, noise, rssi - noise );
6132    }
6133
6134    unlink( WDS_RSSI_TMP );
6135#endif
6136    return;
6137}
6138
6139void ej_get_wdsp2p( webs_t wp, int argc, char_t ** argv )
6140{
6141    int index = -1, ip[4] = { 0, 0, 0, 0 }, netmask[4] =
6142    {
6143    0, 0, 0, 0};
6144    char nvramvar[32] = { 0 };
6145    char *interface;
6146
6147#ifdef FASTWEB
6148    ejArgs( argc, argv, "%d %s", &index, &interface );
6149#else
6150    if( ejArgs( argc, argv, "%d %s", &index, &interface ) < 2 )
6151    {
6152        websError( wp, 400, "Insufficient args\n" );
6153        return;
6154    }
6155#endif
6156    char wlwds[32];
6157
6158    sprintf( wlwds, "%s_wds1_enable", interface );
6159    if( nvram_selmatch( wp, "wk_mode", "ospf" ) &&
6160        nvram_selmatch( wp, "expert_mode", "1" ) &&
6161        nvram_selmatch( wp, wlwds, "1" ) )
6162    {
6163        char buf[16];
6164
6165        sprintf( buf, "%s_wds%d_ospf", interface, index );
6166        websWrite( wp,
6167                   "<input name=\"%s\" size=\"2\" maxlength=\"5\" value=\"%s\" />\n",
6168                   buf, nvram_safe_get( buf ) );
6169    }
6170
6171    snprintf( nvramvar, 31, "%s_wds%d_ipaddr", interface, index );
6172    sscanf( nvram_safe_get( nvramvar ), "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2],
6173            &ip[3] );
6174    snprintf( nvramvar, 31, "%s_wds%d_netmask", interface, index );
6175    sscanf( nvram_safe_get( nvramvar ), "%d.%d.%d.%d", &netmask[0],
6176            &netmask[1], &netmask[2], &netmask[3] );
6177    snprintf( nvramvar, 31, "%s_wds%d_enable", interface, index );
6178
6179    // set netmask to a suggested default if blank
6180    if( netmask[0] == 0 &&
6181        netmask[1] == 0 && netmask[2] == 0 && netmask[3] == 0 )
6182    {
6183        netmask[0] = 255;
6184        netmask[1] = 255;
6185        netmask[2] = 255;
6186        netmask[3] = 252;
6187    }
6188
6189    if( nvram_match( nvramvar, "1" ) )
6190    {
6191        websWrite( wp, "\
6192        <div class=\"setting\">\n\
6193                  <input type=\"hidden\" name=\"%s_wds%d_ipaddr\" value=\"4\">\n\
6194                  <div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n\
6195                  <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\
6196       </div>\n", interface, index, interface, index, ip[0], interface, index, ip[1], interface, index, ip[2], interface, index, ip[3] );
6197
6198        websWrite( wp, "\
6199          <div class=\"setting\">\n\
6200          <div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n\
6201          <input type=\"hidden\" name=\"%s_wds%d_netmask\" value=\"4\">\n\
6202          <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\
6203          </div>\n", interface, index, interface, index, netmask[0], interface, index, netmask[1], interface, index, netmask[2], interface, index, netmask[3] );
6204
6205    }
6206
6207    return;
6208
6209}
6210
6211/*
6212 * void ej_get_services_options (webs_t wp, int argc, char_t ** argv) { char
6213 * word[1024], *next, *services; char delim[] = "<&nbsp;>";
6214 *
6215 * //services = nvram_safe_get("filter_services"); services =
6216 * get_filter_services ();
6217 *
6218 * split (word, services, next, delim) { int len = 0; char *name, *prot,
6219 * *port; char protocol[100], ports[100]; int from = 0, to = 0; //int proto;
6220 *
6221 * if ((name = strstr (word, "$NAME:")) == NULL || (prot = strstr (word,
6222 * "$PROT:")) == NULL || (port = strstr (word, "$PORT:")) == NULL) continue;
6223 *
6224 * // $NAME if (sscanf (name, "$NAME:%3d:", &len) != 1) continue;
6225 *
6226 * strncpy (name, name + sizeof ("$NAME:nnn:") - 1, len); name[len] = '\0';
6227 *
6228 * // $PROT if (sscanf (prot, "$PROT:%3d:", &len) != 1) continue;
6229 *
6230 * strncpy (protocol, prot + sizeof ("$PROT:nnn:") - 1, len); protocol[len] =
6231 * '\0';
6232 *
6233 * // $PORT if (sscanf (port, "$PORT:%3d:", &len) != 1) continue;
6234 *
6235 * strncpy (ports, port + sizeof ("$PORT:nnn:") - 1, len); ports[len] = '\0';
6236 *
6237 * if (sscanf (ports, "%d:%d", &from, &to) != 2) continue;
6238 *
6239 * //cprintf("match:: name=%s, protocol=%s, ports=%s\n", // word, protocol,
6240 * ports);
6241 *
6242 * websWrite (wp, "<option value=\"%s\">%s</option>", name, name);
6243 *
6244 * }
6245 *
6246 * return; }
6247 */
6248
6249void ej_get_clone_wmac( webs_t wp, int argc, char_t ** argv )
6250{
6251#ifdef HAVE_RB500
6252    return 0;
6253#else
6254
6255    char *c;
6256    int mac, which;
6257    int dofree = 0;
6258
6259#ifdef FASTWEB
6260    ejArgs( argc, argv, "%d", &which );
6261#else
6262    if( ejArgs( argc, argv, "%d", &which ) < 1 )
6263    {
6264        websError( wp, 400, "Insufficient args\n" );
6265        return;
6266    }
6267#endif
6268
6269    if( nvram_match( "def_whwaddr", "00:00:00:00:00:00" ) )
6270    {
6271        // if (strlen (nvram_safe_get ("il0macaddr")) == 0)
6272        // {
6273        // if (nvram_match ("port_swap", "1"))
6274        // c = strdup (nvram_safe_get ("et1macaddr"));
6275        // else
6276        // c = strdup (nvram_safe_get ("et0macaddr"));
6277        // MAC_ADD (c);
6278        // }
6279        // else
6280        // {
6281        // c = strdup (nvram_safe_get ("il0macaddr"));
6282        // }
6283        // dofree = 1;
6284
6285        if( nvram_match( "port_swap", "1" ) )
6286        {
6287            if( strlen( nvram_safe_get( "et1macaddr" ) ) != 0 ) // safe:
6288                // maybe
6289                // et1macaddr
6290                // not there?
6291            {
6292                c = strdup( nvram_safe_get( "et1macaddr" ) );
6293            }
6294            else
6295            {
6296                c = strdup( nvram_safe_get( "et0macaddr" ) );
6297                MAC_ADD( c );   // et0macaddr +3
6298            }
6299        }
6300        else
6301        {
6302            c = strdup( nvram_safe_get( "et0macaddr" ) );
6303        }
6304
6305        dofree = 1;
6306        if( c )
6307        {
6308            MAC_ADD( c );
6309            MAC_ADD( c );
6310        }
6311
6312    }
6313    else
6314        c = nvram_safe_get( "def_whwaddr" );
6315
6316    if( c )
6317    {
6318        mac = get_single_mac( c, which );
6319        websWrite( wp, "%02X", mac );
6320        if( dofree )
6321            free( c );
6322    }
6323    else
6324        websWrite( wp, "00" );
6325
6326    return;
6327#endif
6328}
6329
6330/*
6331 * todo stylesheet compatible code
6332 */
6333/*
6334 * lonewolf additions
6335 */
6336
6337// Note that there is no VLAN #16.  It's just a convieniant way of denoting a
6338// "Tagged" port
6339void ej_port_vlan_table( webs_t wp, int argc, char_t ** argv )
6340{
6341    /*
6342     * vlans[x][y] where x 0-15 are VLANS x 16 is tagging, 17 is
6343     * auto-negotiation, 18 is 100/10 Mbit, and 19 is Full/Half duplex y 0-4
6344     * are switch ports (port 5 is set automaticly) y 5 it the bridge device
6345     * (x 16 dosn't apply)
6346     */
6347
6348    int i, j, vlans[21][6], tmp, wl_br;
6349    char *c, *next, buff[32], portvlan[32];
6350
6351    for( i = 0; i < 21; i++ )
6352        for( j = 0; j < 6; j++ )
6353            vlans[i][j] = -1;
6354
6355    wl_br = -1;
6356
6357    for( i = 0; i < 8; i++ )
6358    {
6359        if( i < 5 )
6360            snprintf( buff, 31, "port%dvlans", i );
6361        else if( i == 5 )
6362            snprintf( buff, 31, "%s", "lan_ifnames" );
6363        else
6364            snprintf( buff, 31, "ub%d_ifnames", i - 5 );
6365
6366        c = nvram_safe_get( buff );
6367
6368        if( c )
6369        {
6370            foreach( portvlan, c, next )
6371            {
6372                if( portvlan[0] == 'e' && portvlan[1] == 't'
6373                    && portvlan[2] == 'h' && portvlan[3] == '1' )
6374                    wl_br = i - 5;
6375                if( ISDIGIT( portvlan, 1 )
6376                    || ( portvlan[0] == 'v' && portvlan[1] == 'l'
6377                         && portvlan[2] == 'a' && portvlan[3] == 'n' ) )
6378                {
6379                    if( ISDIGIT( portvlan, 1 ) )
6380                        tmp = atoi( portvlan );
6381                    else
6382                    {
6383                        portvlan[0] = portvlan[4];
6384                        portvlan[1] = portvlan[5];
6385                        portvlan[2] = '\0';
6386                        if( ISDIGIT( portvlan, 1 ) )
6387                            tmp = atoi( portvlan );
6388                        else
6389                            continue;
6390                    }
6391
6392                    if( i < 5 )
6393                    {
6394                        vlans[tmp][i] = 1;
6395                    }
6396                    else
6397                    {
6398                        vlans[tmp][5] = i - 5;
6399                    }
6400                }
6401            }
6402        }
6403    }
6404
6405    for( i = 0; i < 21; i++ )
6406    {
6407        websWrite( wp, "              <tr>\n" );
6408        websWrite( wp, "<td>" );
6409
6410        switch ( i )
6411        {
6412            case 16:
6413                websWrite( wp,
6414                           "<script type=\"text/javascript\">Capture(vlan.tagged)</script>" );
6415                break;
6416            case 17:
6417                websWrite( wp,
6418                           "<script type=\"text/javascript\">Capture(vlan.negociate)</script>" );
6419                break;
6420            case 18:
6421                websWrite( wp, "100 Mbit" );
6422                break;
6423            case 19:
6424                websWrite( wp, "Full-Duplex" );
6425                break;
6426            case 20:
6427                websWrite( wp, "Enabled" );
6428                break;
6429            default:
6430                snprintf( buff, 31, "%d", i );
6431                websWrite( wp, buff );
6432                break;
6433        }
6434
6435        websWrite( wp, "</td>\n" );
6436
6437        for( j = 0; j < 5; j++ )
6438        {
6439            snprintf( buff, 31, "\"port%dvlan%d\"", j, i );
6440            websWrite( wp, "<td" );
6441
6442            if( j % 2 == 0 )
6443                websWrite( wp, " bgcolor=\"#CCCCCC\"" );
6444
6445            websWrite( wp,
6446                       " height=\"20\"><div align=\"center\"><input type=\"checkbox\" value=\"on\" name=" );
6447            websWrite( wp, buff );
6448
6449            if( i < 17 || i > 20 )
6450            {
6451                if( vlans[i][j] == 1 )
6452                    websWrite( wp, " checked=\"checked\"" );
6453            }
6454            else
6455            {
6456                if( vlans[i][j] == -1 )
6457                    websWrite( wp, " checked=\"checked\"" );
6458            }
6459
6460            if( i < 17 )
6461            {
6462                websWrite( wp, " onclick=" );
6463                snprintf( buff, sizeof( buff ),
6464                          "\"SelVLAN(this.form,'port%d')\"", j );
6465                websWrite( wp, buff );
6466            }
6467            else if( i == 17 || i == 20 )
6468            {
6469                websWrite( wp, " onclick=" );
6470                snprintf( buff, sizeof( buff ),
6471                          "\"SelSpeed(this.form,'port%d')\"", j );
6472                websWrite( wp, buff );
6473            }
6474            websWrite( wp, " /></div></td>\n" );
6475        }
6476
6477        if( i < 16 )
6478        {
6479            websWrite( wp, "                    <td><select name=" );
6480            snprintf( buff, 31, "\"vlan%d\"", i );
6481            websWrite( wp, buff );
6482            websWrite( wp,
6483                       "><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"-1\\\"" );
6484            if( vlans[i][5] < 0 )
6485                websWrite( wp, " selected=\\\"selected\\\"" );
6486            websWrite( wp,
6487                       ">\" + share.none + \"</option>\");\n//]]>\n</script><option value=\"0\"" );
6488            if( vlans[i][5] == 0 )
6489                websWrite( wp, " selected=\"selected\"" );
6490            websWrite( wp, ">LAN</option></select></td>\n" );
6491        }
6492        else
6493        {
6494            websWrite( wp, "<td>&nbsp;</td>\n" );
6495        }
6496
6497        websWrite( wp, "</tr>\n" );
6498
6499        if( i == 16 || i == 20 )
6500        {
6501            websWrite( wp, "<tr><td>&nbsp;</td></tr>\n" );
6502        }
6503    }
6504
6505    websWrite( wp, "<tr>\n" );
6506    websWrite( wp,
6507               "<td><script type=\"text/javascript\">Capture(share.wireless)</script></td>\n" );
6508
6509    websWrite( wp,
6510               "<td colspan=\"6\"><select name=\"wireless\"><script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"-1\\\"" );
6511    if( wl_br < 0 )
6512        websWrite( wp, " selected=\\\"selected\\\"" );
6513    websWrite( wp,
6514               ">\" + share.none + \"</option>\");\n//]]>\n</script><option value=\"0\"" );
6515    if( wl_br == 0 )
6516        websWrite( wp, " selected=\"selected\"" );
6517    websWrite( wp, ">LAN</option></select></td>\n" );
6518    websWrite( wp, "</tr>\n" );
6519
6520    websWrite( wp, "<tr><td>&nbsp;</td></tr>\n" );
6521
6522    websWrite( wp, "<tr>\n" );
6523    websWrite( wp,
6524               "<td><script type=\"text/javascript\">Capture(vlan.aggregation)</script></td>\n" );
6525
6526    websWrite( wp,
6527               "<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\\\"" );
6528
6529    c = nvram_safe_get( "trunking" );
6530
6531    snprintf( buff, 5, "%s", c );
6532
6533    if( atoi( buff ) == 1 )
6534        websWrite( wp, " selected=\\\"selected\\\"" );
6535
6536    websWrite( wp,
6537               ">\" + vlan.trunk + \"</option>\");\n//]]>\n</script></select></td>\n" );
6538    websWrite( wp, "              </tr>" );
6539
6540    return;
6541}
6542
6543/*
6544 * Note: VLAN #16 designates tagging.  There is no VLAN #16 (only 0-15)
6545 */
6546
6547void ej_get_qossvcs( webs_t wp, int argc, char_t ** argv )
6548{
6549    char *qos_svcs = nvram_safe_get( "svqos_svcs" );
6550    char name[32], type[32], data[32], level[32];
6551    int no_svcs = 0, i = 0;
6552
6553    // calc # of services
6554    // no_svcs = strspn(qos_svcs,"|");
6555
6556    while( ( qos_svcs = strpbrk( qos_svcs, "|" ) ) )
6557    {
6558        no_svcs++;
6559        qos_svcs++;
6560    }
6561
6562    // write HTML data
6563
6564    websWrite( wp,
6565               "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"svqos_nosvcs\" value=\"%d\" /></td></tr>",
6566               no_svcs );
6567
6568    qos_svcs = nvram_safe_get( "svqos_svcs" );
6569
6570    /*
6571     * services format is "name type data level | name type data level |"
6572     * ..etc
6573     */
6574    for( i = 0; i < no_svcs && qos_svcs && qos_svcs[0]; i++ )
6575    {
6576        if( sscanf
6577            ( qos_svcs, "%31s %31s %31s %31s ", name, type, data,
6578              level ) < 4 )
6579            break;
6580
6581        websWrite( wp, "<tr>\n\
6582                                        <td>\n\
6583                                                <input type=\"checkbox\" name=\"svqos_svcdel%d\" />\n\
6584                                                <input type=\"hidden\" name=\"svqos_svcname%d\" value=\"%s\" />\n\
6585                                                <input type=\"hidden\" name=\"svqos_svctype%d\" value=\"%s\" />\n\
6586                                        </td>\n\
6587                                        <td><em>%s</em></td>\n\
6588                                        <td >\n", i, i, name, i, type, name );
6589        websWrite( wp, "<select name=\"svqos_svcprio%d\"> \n\
6590                                                        <script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"100\\\" %s >\" + qos.prio_x + \"</option>\");\n\
6591                                                        document.write(\"<option value=\\\"10\\\" %s >\" + qos.prio_p + \"</option>\");\n\
6592                                                        document.write(\"<option value=\\\"20\\\" %s >\" + qos.prio_e + \"</option>\");\n\
6593                                                        document.write(\"<option value=\\\"30\\\" %s >\" + share.standard + \"</option>\");\n\
6594                                                        document.write(\"<option value=\\\"40\\\" %s >\" + qos.prio_b + \"</option>\");\n//]]>\n</script>\n\
6595                                                </select>\n\
6596                           </td>\n\
6597                                </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\\\"" : "" );
6598
6599        qos_svcs = strpbrk( ++qos_svcs, "|" );
6600        qos_svcs++;
6601
6602    }
6603
6604    return;
6605}
6606
6607#ifndef HAVE_AQOS
6608void ej_get_qosips( webs_t wp, int argc, char_t ** argv )
6609{
6610    char *qos_ips = nvram_safe_get( "svqos_ips" );
6611    char ip[32], level[32];
6612    int no_ips = 0, i = 0;
6613
6614    // calc # of ips
6615    while( ( qos_ips = strpbrk( qos_ips, "|" ) ) )
6616    {
6617        no_ips++;
6618        qos_ips++;
6619    }
6620    websWrite( wp, "<tr>\n\
6621                                        <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\
6622                                        <th><script type=\"text/javascript\">Capture(qos.ipmask)</script></th>\n\
6623                                        <th><script type=\"text/javascript\">Capture(share.priority)</script></th>\n\
6624                                </tr>\n" );
6625
6626    // write HTML data
6627
6628    websWrite( wp,
6629               "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"svqos_noips\" value=\"%d\" /></td></tr>",
6630               no_ips );
6631
6632    qos_ips = nvram_safe_get( "svqos_ips" );
6633
6634    /*
6635     * IP format is "data level | data level |" ..etc
6636     */
6637    for( i = 0; i < no_ips && qos_ips && qos_ips[0]; i++ )
6638    {
6639        if( sscanf( qos_ips, "%31s %31s ", ip, level ) < 2 )
6640            break;
6641
6642        websWrite( wp, "<tr>\n\
6643                                        <td>\n\
6644                                                <input type=\"checkbox\" name=\"svqos_ipdel%d\" />\n\
6645                                                <input type=\"hidden\" name=\"svqos_ip%d\" value=\"%s\" />\n\
6646                                        </td>\n\
6647                                        <td><em>%s</em></td>\n\
6648                                        <td>\n", i, i, ip, ip );
6649        websWrite( wp, "<select name=\"svqos_ipprio%d\"> \n\
6650                                                        <script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"100\\\" %s >\" + qos.prio_x + \"</option>\");\n\
6651                                                        document.write(\"<option value=\\\"10\\\" %s >\" + qos.prio_p + \"</option>\");\n\
6652                                                        document.write(\"<option value=\\\"20\\\" %s >\" + qos.prio_e + \"</option>\");\n\
6653                                                        document.write(\"<option value=\\\"30\\\" %s >\" + share.standard + \"</option>\");\n\
6654                                                        document.write(\"<option value=\\\"40\\\" %s >\" + qos.prio_b + \"</option>\");\n//]]>\n</script>\n\
6655                                                </select>\n\
6656                                        </td>\n\
6657                                </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\\\"" : "" );
6658
6659        qos_ips = strpbrk( ++qos_ips, "|" );
6660        qos_ips++;
6661
6662    }
6663
6664    return;
6665}
6666#else
6667void ej_get_qosips( webs_t wp, int argc, char_t ** argv )
6668{
6669    char *qos_ips = nvram_safe_get( "svqos_ips" );
6670    char ip[32], level[32], level2[32];
6671    int no_ips = 0, i = 0;
6672
6673    // calc # of ips
6674    while( ( qos_ips = strpbrk( qos_ips, "|" ) ) )
6675    {
6676        no_ips++;
6677        qos_ips++;
6678    }
6679    websWrite( wp, "<tr>\n\
6680                                        <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\
6681                                        <th><script type=\"text/javascript\">Capture(qos.ipmask)</script></th>\n\
6682                                        <th><script type=\"text/javascript\">Capture(qos.maxuprate_b)</script></th>\n\
6683                                        <th><script type=\"text/javascript\">Capture(qos.maxdownrate_b)</script></th>\n\
6684                                </tr>\n" );
6685
6686    // write HTML data
6687
6688    websWrite( wp,
6689               "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"svqos_noips\" value=\"%d\" /></td></tr>",
6690               no_ips );
6691
6692    qos_ips = nvram_safe_get( "svqos_ips" );
6693
6694    /*
6695     * IP format is "data level | data level |" ..etc
6696     */
6697    for( i = 0; i < no_ips && qos_ips && qos_ips[0]; i++ )
6698    {
6699        if( sscanf( qos_ips, "%31s %31s %31s ", ip, level, level2 ) < 3 )
6700            break;
6701        websWrite( wp, "<tr>\n\
6702                                        <td>\n\
6703                                                <input type=\"checkbox\" name=\"svqos_ipdel%d\" />\n\
6704                                                <input type=\"hidden\" name=\"svqos_ip%d\" value=\"%s\" />\n\
6705                                        </td>\n\
6706                                        <td><em>%s</em></td>\n\
6707                                        <td>\n\
6708                                                <input name=\"svqos_ipup%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\
6709                                        </td>\n\
6710                                        <td>\n\
6711                                                <input name=\"svqos_ipdown%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\
6712                                        </td>\n\
6713                                </tr>\n", i, i, ip, ip, i, level, i, level2 );
6714
6715        qos_ips = strpbrk( ++qos_ips, "|" );
6716        qos_ips++;
6717
6718    }
6719
6720    return;
6721}
6722#endif
6723#ifndef HAVE_AQOS
6724void ej_get_qosmacs( webs_t wp, int argc, char_t ** argv )
6725{
6726    char *qos_macs = nvram_safe_get( "svqos_macs" );
6727    char mac[32], level[32];
6728    int no_macs = 0, i = 0;
6729
6730    // calc # of ips
6731    while( ( qos_macs = strpbrk( qos_macs, "|" ) ) )
6732    {
6733        no_macs++;
6734        qos_macs++;
6735    }
6736
6737    websWrite( wp, "<tr>\n\
6738                                        <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\
6739                                        <th><script type=\"text/javascript\">Capture(share.mac)</script></th>\n\
6740                                        <th><script type=\"text/javascript\">Capture(share.priority)</script></th>\n\
6741                                </tr>\n" );
6742
6743    // write HTML data
6744    websWrite( wp,
6745               "<input type=\"hidden\" name=\"svqos_nomacs\" value=\"%d\" />",
6746               no_macs );
6747
6748    qos_macs = nvram_safe_get( "svqos_macs" );
6749
6750    /*
6751     * IP format is "data level | data level |" ..etc
6752     */
6753    for( i = 0; i < no_macs && qos_macs && qos_macs[0]; i++ )
6754    {
6755        if( sscanf( qos_macs, "%31s %31s ", mac, level ) < 2 )
6756            break;
6757
6758        websWrite( wp, "<tr>\n\
6759                                        <td>\n\
6760                                                <input type=\"checkbox\" name=\"svqos_macdel%d\" />\n\
6761                                                <input type=\"hidden\" name=\"svqos_mac%d\" value=\"%s\" />\n\
6762                                        </td>\n\
6763                                        <td><em>%s</em></td>\n\
6764                                        <td>\n", i, i, mac, mac );
6765        websWrite( wp, "<select name=\"svqos_macprio%d\"> \n\
6766                                                        <script type=\"text/javascript\">\n//<![CDATA[\n document.write(\"<option value=\\\"100\\\" %s >\" + qos.prio_x + \"</option>\");\n\
6767                                                        document.write(\"<option value=\\\"10\\\" %s >\" + qos.prio_p + \"</option>\");\n\
6768                                                        document.write(\"<option value=\\\"20\\\" %s >\" + qos.prio_e + \"</option>\");\n\
6769                                                        document.write(\"<option value=\\\"30\\\" %s >\" + share.standard + \"</option>\");\n\
6770                                                        document.write(\"<option value=\\\"40\\\" %s >\" + qos.prio_b + \"</option>\");\n//]]>\n</script>\n\
6771                                                </select>\n\
6772                                        </td>\n\
6773                                </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\\\"" : "" );
6774
6775        qos_macs = strpbrk( ++qos_macs, "|" );
6776        qos_macs++;
6777
6778    }
6779
6780    return;
6781}
6782
6783#else
6784void ej_get_qosmacs( webs_t wp, int argc, char_t ** argv )
6785{
6786    char *qos_macs = nvram_safe_get( "svqos_macs" );
6787    char mac[32], level[32], level2[32];
6788    int no_macs = 0, i = 0;
6789
6790    // calc # of ips
6791    while( ( qos_macs = strpbrk( qos_macs, "|" ) ) )
6792    {
6793        no_macs++;
6794        qos_macs++;
6795    }
6796    websWrite( wp, "<tr>\n\
6797                                        <th><script type=\"text/javascript\">Capture(share.del)</script></th>\n\
6798                                        <th><script type=\"text/javascript\">Capture(share.mac)</script></th>\n\
6799                                        <th><script type=\"text/javascript\">Capture(qos.maxuprate_b)</script></th>\n\
6800                                        <th><script type=\"text/javascript\">Capture(qos.maxdownrate_b)</script></th>\n\
6801                                </tr>\n" );
6802
6803    // write HTML data
6804    websWrite( wp,
6805               "<input type=\"hidden\" name=\"svqos_nomacs\" value=\"%d\" />",
6806               no_macs );
6807
6808    qos_macs = nvram_safe_get( "svqos_macs" );
6809
6810    /*
6811     * IP format is "data level | data level |" ..etc
6812     */
6813    for( i = 0; i < no_macs && qos_macs && qos_macs[0]; i++ )
6814    {
6815        if( sscanf( qos_macs, "%31s %31s %31s ", mac, level, level2 ) < 3 )
6816            break;
6817        websWrite( wp, "<tr>\n\
6818                                        <td>\n\
6819                                                <input type=\"checkbox\" name=\"svqos_macdel%d\" />\n\
6820                                                <input type=\"hidden\" name=\"svqos_mac%d\" value=\"%s\" />\n\
6821                                        </td>\n\
6822                                        <td><em>%s</em></td>\n\
6823                                        <td>\n\
6824                                                <input name=\"svqos_macup%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\
6825                                        </td>\n\
6826                                        <td>\n\
6827                                                <input name=\"svqos_macdown%d\" class=\"num\" size=\"5\" maxlength=\"5\" value=\"%s\" /> \n\
6828                                        </td>\n\
6829                                </tr>\n", i, i, mac, mac, i, level, i, level2 );
6830
6831        qos_macs = strpbrk( ++qos_macs, "|" );
6832        qos_macs++;
6833
6834    }
6835
6836    return;
6837}
6838#endif
6839
6840/*
6841 * Added by Botho 03.April.06
6842 */
6843void ej_dumpip_conntrack( webs_t wp, int argc, char_t ** argv )
6844{
6845    int ip_count = 0;
6846    FILE *fp;
6847    int c;
6848
6849    fp = fopen( "/proc/net/ip_conntrack", "rb" );
6850    if( fp == NULL )
6851        return;
6852    while( !feof( fp ) )
6853    {
6854        c = getc( fp );
6855        if( c == EOF )
6856            break;
6857        if( c == 0xa )
6858            ip_count++;
6859    }
6860
6861    websWrite( wp, "%d", ip_count );
6862
6863    fclose( fp );
6864
6865    return;
6866}
6867
6868/*
6869 * Added by Botho 28.Oct.06
6870 */
6871static int search_hit( char *search, char *line, char *ret )
6872{
6873    unsigned int searchLen;
6874    unsigned int i;
6875    unsigned int j;
6876    unsigned int lineLen;
6877
6878    if( line == NULL || search == NULL || ret == NULL )
6879        return 1;
6880    lineLen = strlen( line );
6881    searchLen = strlen( search );
6882
6883    if( searchLen > lineLen )
6884        return ( 1 );           // this can't match, invalid data?
6885
6886    for( i = 0; i < lineLen - searchLen; i++ )
6887    {
6888        if( !strncasecmp( ( char * )&line[i], search, searchLen ) )
6889            break;              // we got hit
6890    }
6891
6892    for( j = i + searchLen; j < i + 15 + searchLen; j++ )
6893    {
6894        if( j >= lineLen )
6895            break;              // end of line may be a delimiter too
6896        // return(1); // incomplete data
6897        if( line[j] == ' ' )
6898            break;              // we reach _space_ delimiter
6899    }
6900    memcpy( ret, &line[i + searchLen], j - ( i + searchLen ) );
6901    ret[j - ( i + searchLen )] = 0;
6902    return ( 0 );
6903}
6904
6905static int string_search( char *string, char *search )
6906{
6907    int searchLen;
6908    int i;
6909
6910    if( search == NULL )
6911        return 0;
6912    searchLen = strlen( search );
6913    if( string == NULL )
6914        return 0;
6915    if( searchLen > strlen( string ) )
6916    {
6917        return ( 0 );           // this can't match
6918    }
6919    int slen = strlen( string );
6920
6921    for( i = 0; i < slen - searchLen; i++ )
6922    {                           // +1 removed.
6923        if( !strncasecmp( ( char * )&string[i], search, searchLen ) )
6924        {
6925            return ( 1 );       // we got hit
6926        }
6927    }
6928    return ( 0 );
6929}
6930
6931void ej_ip_conntrack_table( webs_t wp, int argc, char_t ** argv )
6932{
6933    FILE *fp;
6934    int ip_count = 1;
6935    char line[512];
6936    char protocol[16] = "";
6937    int timeout = 0;
6938    char srcip[16] = "";
6939    char dstip[16] = "";
6940    int _dport;
6941    struct servent *servp;
6942    char dstport[6] = "";
6943    char state[12] = "";
6944    char dum1[32];
6945    int dum2;
6946
6947    fp = fopen( "/proc/net/ip_conntrack", "rb" );
6948    if( fp == NULL )
6949        return;
6950
6951    while( fgets( line, sizeof( line ), fp ) != NULL )
6952    {
6953
6954        websWrite( wp, "<tr>\n" );
6955
6956        // Nb
6957        websWrite( wp, "<td align=\"right\">%d</td>", ip_count );
6958
6959        // Proto
6960        if( string_search( line, "tcp" ) )
6961            sprintf( protocol, "TCP" );
6962        else if( string_search( line, "udp" ) )
6963            sprintf( protocol, "UDP" );
6964        else if( string_search( line, "icmp" ) )
6965            sprintf( protocol, "ICMP" );
6966        else
6967            sprintf( protocol, live_translate( "share.unknown" ) );
6968        websWrite( wp, "<td>%s</td>", protocol );
6969
6970        // Timeout
6971        sscanf( line, "%s %d %d", &dum1[0], &dum2, &timeout );
6972        websWrite( wp, "<td align=\"right\">%d</td>", timeout );
6973
6974        // src
6975        search_hit( "src=", line, srcip );
6976        // char buf[200];
6977        // getHostName (buf, srcip);
6978        // websWrite (wp, "<td align=\"right\" onmouseover='DisplayDiv(this,
6979        // event, 15, 15, \"%s\")' onmouseout=\"unDisplayDiv()\">%s</td>",
6980        // buf != "unknown" ? buf : live_translate ("share.unknown") ,
6981        // srcip);
6982        websWrite( wp, "<td align=\"right\">%s</td>", srcip );
6983
6984        // dst
6985        search_hit( "dst=", line, dstip );
6986        // getHostName (buf, dstip);
6987        // websWrite (wp, "<td align=\"right\" onmouseover='DisplayDiv(this,
6988        // event, 15, 15, \"%s\")' onmouseout=\"unDisplayDiv()\">%s</td>",
6989        // buf != "unknown" ? buf : live_translate ("share.unknown") ,
6990        // dstip);
6991        websWrite( wp, "<td align=\"right\">%s</td>", dstip );
6992
6993        // service
6994        search_hit( "dport=", line, dstport );
6995        _dport = atoi( dstport );
6996        servp = my_getservbyport( htons( _dport ), protocol );
6997        websWrite( wp, "<td align=\"right\">%s</td>",
6998                   servp ? servp->s_name : dstport );
6999
7000        // State
7001        if( string_search( line, "ESTABLISHED" ) )
7002            sprintf( state, "ESTABLISHED" );
7003        else if( string_search( line, "TIME_WAIT" ) )
7004            sprintf( state, "TIME_WAIT" );
7005        else if( string_search( line, "UNREPLIED" ) )
7006            sprintf( state, "UNREPLIED" );
7007        else if( string_search( line, "CLOSE" ) )
7008            sprintf( state, "CLOSE" );
7009        else if( string_search( line, "ASSURED" ) )
7010            sprintf( state, "ASSURED" );
7011        else
7012        {
7013            if( string_search( line, "udp" ) )
7014                sprintf( state, "UNREPLIED" );
7015            else
7016                sprintf( state, "&nbsp;" );
7017        }
7018        websWrite( wp, "<td>%s</td>\n", state );
7019        websWrite( wp, "</tr>\n" );
7020
7021        ip_count++;
7022    }
7023
7024    fclose( fp );
7025
7026    return;
7027}
7028
7029void ej_gethostnamebyip( webs_t wp, int argc, char_t ** argv )
7030{
7031    char buf[200];
7032    char *argument;
7033
7034#ifdef FASTWEB
7035    ejArgs( argc, argv, "%s", &argument );
7036#else
7037    if( ejArgs( argc, argv, "%s", &argument ) < 1 )
7038    {
7039        websError( wp, 400, "Insufficient args\n" );
7040        return;
7041    }
7042#endif
7043
7044    if( argc == 1 )
7045    {
7046        getHostName( buf, argument );
7047        websWrite( wp, "%s",
7048                   buf !=
7049                   "unknown" ? buf : live_translate( "share.unknown" ) );
7050    }
7051
7052    return;
7053}
7054
7055/*
7056 * BEGIN Added by Botho 10.May.06
7057 */
7058void ej_show_wan_to_switch( webs_t wp, int argc, char_t ** argv )
7059{
7060
7061    if( nvram_match( "wan_proto", "disabled" ) || !nvram_match( "wl_mode", "ap" ) )     // WAN
7062        // disabled
7063        // OR
7064        // Wirelles
7065        // is
7066        // not
7067        // AP
7068    {
7069        websWrite( wp, "<fieldset>\n\
7070                                                        <legend><script type=\"text/javascript\">Capture(idx.legend2)</script></legend>\n\
7071                                                                <div class=\"setting\">\n\
7072                                                                        <div class=\"label\"><script type=\"text/javascript\">Capture(idx.wantoswitch)</script></div>\n\
7073                                                                        <input class=\"spaceradio\" type=\"checkbox\" name=\"_fullswitch\" value=\"1\" %s />\n\
7074                                                                </div>\n\
7075                                                        </fieldset><br />\n", nvram_match( "fullswitch", "1" ) ? "checked=\"checked\"" : "" );
7076    }
7077
7078    return;
7079}
7080
7081#define PROC_DEV "/proc/net/dev"
7082
7083void ej_wl_packet_get( webs_t wp, int argc, char_t ** argv )
7084{
7085    char line[256];
7086    FILE *fp;
7087
7088#ifdef HAVE_MADWIFI
7089    char *ifname = nvram_safe_get( "wifi_display" );
7090#elif HAVE_RT2880
7091    char *ifname = "ra0";
7092#else
7093    char *ifname = nvram_safe_get( "wl0_ifname" );
7094#endif
7095    struct dev_info
7096    {
7097        // unsigned long rx_bytes;
7098        unsigned long rx_pks;
7099        unsigned long rx_errs;
7100        unsigned long rx_drops;
7101        // unsigned long rx_fifo;
7102        // unsigned long rx_frame;
7103        // unsigned long rx_com;
7104        // unsigned long rx_mcast;
7105        // unsigned long tx_bytes;
7106        unsigned long tx_pks;
7107        unsigned long tx_errs;
7108        unsigned long tx_drops;
7109        // unsigned long tx_fifo;
7110        unsigned long tx_colls;
7111        // unsigned long tx_carr;
7112        // unsigned long tx_com;
7113    } info;
7114
7115    info.rx_pks = info.rx_errs = info.rx_drops = 0;
7116    info.tx_pks = info.tx_errs = info.tx_drops = info.tx_colls = 0;
7117
7118    if( ( fp = fopen( PROC_DEV, "r" ) ) == NULL )
7119    {
7120        websError( wp, 400, "Can't open %s\n", PROC_DEV );
7121        return;
7122    }
7123    else
7124    {
7125        /*
7126         * Inter-| Receive | Transmit face |bytes packets errs drop fifo
7127         * frame compressed multicast|bytes packets errs drop fifo colls
7128         * carrier compressed lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth0:
7129         * 674829 5501 0 0 0 0 0 0 1249130 1831 0 0 0 0 0 0 eth1: 0 0 0 0 0 0
7130         * 0 0 0 0 0 0 0 0 0 0 eth2: 0 0 0 0 0 719 0 0 1974 16 295 0 0 0 0 0
7131         * br0: 107114 1078 0 0 0 0 0 0 910094 1304 0 0 0 0 0 0
7132         *
7133         */
7134        while( fgets( line, sizeof( line ), fp ) != NULL )
7135        {
7136            int ifl = 0;
7137
7138            if( !strchr( line, ':' ) )
7139                continue;
7140            while( line[ifl] != ':' )
7141                ifl++;
7142            line[ifl] = 0;      /* interface */
7143
7144            if( strstr( line, ifname ) )
7145            {
7146                /*
7147                 * sscanf (line + ifl + 1, "%ld %ld %ld %ld %ld %ld %ld %ld
7148                 * %ld %ld %ld %ld %ld %ld %ld %ld", &info.rx_bytes,
7149                 * &info.rx_pks, &info.rx_errs, &info.rx_drops,
7150                 * &info.rx_fifo, &info.rx_frame, &info.rx_com,
7151                 * &info.rx_mcast, &info.tx_bytes, &info.tx_pks,
7152                 * &info.tx_errs, &info.tx_drops, &info.tx_fifo,
7153                 * &info.tx_colls, &info.tx_carr, &info.tx_com);
7154                 */
7155                sscanf( line + ifl + 1,
7156                        "%*ld %ld %ld %ld %*ld %*ld %*ld %*ld %*ld %ld %ld %ld %*ld %ld %*ld %*ld",
7157                        &info.rx_pks, &info.rx_errs,
7158                        &info.rx_drops,
7159                        &info.tx_pks, &info.tx_errs, &info.tx_drops,
7160                        &info.tx_colls );
7161            }
7162
7163        }
7164        fclose( fp );
7165    }
7166
7167    websWrite( wp, "SWRXgoodPacket=%ld;", info.rx_pks );
7168    websWrite( wp, "SWRXerrorPacket=%ld;", info.rx_errs + info.rx_drops );
7169
7170    websWrite( wp, "SWTXgoodPacket=%ld;", info.tx_pks );
7171    websWrite( wp, "SWTXerrorPacket=%ld;",
7172               info.tx_errs + info.tx_drops + info.tx_colls );
7173
7174    return;
7175}
7176
7177/*
7178 * END Added by Botho 10.May.06
7179 */
7180
7181void ej_statfs( webs_t wp, int argc, char_t ** argv )
7182{
7183    struct statfs sizefs;
7184
7185    if( argc != 2 )
7186        return;
7187
7188    if( ( statfs( argv[0], &sizefs ) != 0 )
7189        || ( sizefs.f_type == 0x73717368 ) )
7190        memset( &sizefs, 0, sizeof( sizefs ) );
7191
7192    websWrite( wp, "var %s = {\n\
7193        size: %llu,\n\
7194        free: %llu\n\
7195        };\n", argv[1], ( ( uint64_t ) sizefs.f_bsize * sizefs.f_blocks ), ( ( uint64_t ) sizefs.f_bsize * sizefs.f_bfree ) );
7196}
7197
7198#ifdef HAVE_RSTATS
7199/*
7200 *
7201 * rstats Copyright (C) 2006 Jonathan Zarate
7202 *
7203 * Licensed under GNU GPL v2 or later.
7204 *
7205 */
7206
7207void ej_bandwidth( webs_t wp, int argc, char_t ** argv )
7208{
7209    char *name;
7210    int sig;
7211    char *argument;
7212
7213#ifdef FASTWEB
7214    ejArgs( argc, argv, "%s", &argument );
7215#else
7216    if( ejArgs( argc, argv, "%s", &argument ) < 1 )
7217    {
7218        websError( wp, 400, "Insufficient args\n" );
7219        return;
7220    }
7221#endif
7222
7223    if( argc == 1 )
7224    {
7225        if( strcmp( argument, "speed" ) == 0 )
7226        {
7227            sig = SIGUSR1;
7228            name = "/var/spool/rstats-speed.js";
7229        }
7230        else
7231        {
7232            sig = SIGUSR2;
7233            name = "/var/spool/rstats-history.js";
7234        }
7235        unlink( name );
7236        killall( "rstats", sig );
7237        wait_file_exists( name, 5, 0 );
7238        do_file( name, wp, NULL );
7239        unlink( name );
7240    }
7241}
7242#endif
7243
7244#ifdef HAVE_PORTSETUP
7245void ej_portsetup( webs_t wp, int argc, char_t ** argv )
7246{
7247    char ssid[64];
7248    char *next;
7249    char var[64];
7250    char eths[256];
7251
7252    websWrite( wp,
7253               "<h2><script type=\"text/javascript\">Capture(idx.portsetup)</script></h2>\n" );
7254    websWrite( wp, "<fieldset>\n" );
7255
7256    char *wanifname = nvram_safe_get( "wan_ifname2" );
7257
7258    if( strlen( wanifname ) == 0 )
7259        wanifname = nvram_safe_get( "wan_ifname" );
7260    if( strlen( wanifname ) > 0 )
7261    {
7262
7263        websWrite( wp,
7264                   "<legend><script type=\"text/javascript\">Capture(idx.portsetup)</script></legend>\n" );
7265        memset( eths, 0, 256 );
7266        getIfLists( eths, 256 );
7267        websWrite( wp,
7268                   "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(idx.wanport)</script></div>\n" );
7269        websWrite( wp, "<select name=\"wan_ifname\">\n" );
7270
7271        websWrite( wp, "<option value=\"\" %s >Disabled</option>\n",
7272                   strlen( wanifname ) == 0 ? "selected=\"selected\"" : "" );
7273        foreach( var, eths, next )
7274        {
7275            websWrite( wp, "<option value=\"%s\" %s >%s</option>\n", var,
7276                       !strcmp( wanifname,
7277                                var ) ? "selected=\"selected\"" : "", var );
7278        }
7279        websWrite( wp, "</select></div>\n" );
7280    }
7281    foreach( var, eths, next )
7282    {
7283        if( !strcmp( get_wan_face(  ), var ) )
7284            continue;
7285        if( !strcmp( nvram_safe_get( "lan_ifname" ), var ) )
7286            continue;
7287        if( !strncmp( var, "br", 2 ) && !contains( var, '.' ) )
7288            continue;
7289
7290        sprintf( ssid, "%s_bridged", var );
7291        websWrite( wp,
7292                   "<div class=\"setting\">\n<div class=\"label\"><script type=\"text/javascript\">Capture(wl_basic.network)</script> %s</div>\n",
7293                   var );
7294        char layer[64];
7295
7296        strcpy( layer, var );
7297        rep( layer, '.', 'X' );
7298        websWrite( wp,
7299                   "<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>&nbsp;\n",
7300                   layer, var, nvram_default_match( ssid,
7301                                                    "0",
7302                                                    "1" ) ?
7303                   "checked=\"checked\"" : "" );
7304        websWrite( wp,
7305                   "<input class=\"spaceradio\" type=\"radio\" value=\"1\" onclick=\"show_layer_ext(this, '%s_idnet', false);\" name=\"%s_bridged\" %s /><script type=\"text/javascript\">Capture(share.deflt)</script>\n",
7306                   layer, var, nvram_default_match( ssid, "1",
7307                                                    "1" ) ?
7308                   "checked=\"checked\"" : "" );
7309        websWrite( wp, "</div>\n" );
7310
7311        websWrite( wp, "<div id=\"%s_idnet\">\n", layer );
7312        char mcast[32];
7313
7314        sprintf( mcast, "%s_multicast", var );
7315        nvram_default_get( mcast, "0" );
7316        showRadio( wp, "wl_basic.multicast", mcast );
7317        show_ipnetmask( wp, var );
7318        websWrite( wp, "</div>\n" );
7319        websWrite( wp, "<script type=\"text/javascript\">\n//<![CDATA[\n " );
7320        websWrite( wp,
7321                   "show_layer_ext(document.getElementsByName(\"%s_bridged\"), \"%s_idnet\", %s);\n",
7322                   var, layer, nvram_match( ssid, "0" ) ? "true" : "false" );
7323        websWrite( wp, "//]]>\n</script>\n" );
7324    }
7325    websWrite( wp, "</fieldset><br />\n" );
7326}
7327#endif
7328
7329static void show_macfilter_if( webs_t wp, char *ifname )
7330{
7331    char rifname[32];
7332
7333#ifdef HAVE_RT2880
7334    strcpy( rifname, ifname );
7335#else
7336    strcpy( rifname, ifname );
7337    if( !strcmp( ifname, "wl" ) )
7338        strcpy( rifname, nvram_safe_get( "wl0_ifname" ) );
7339    if( !strcmp( ifname, "wl0" ) )
7340        strcpy( rifname, nvram_safe_get( "wl0_ifname" ) );
7341#endif
7342    websWrite( wp, "<fieldset>\n" );
7343    websWrite( wp, "<legend>%s - %s</legend>\n", IFMAP(rifname),
7344               live_translate( "wl_mac.legend" ) );
7345    websWrite( wp, "<div class=\"setting\">\n" );
7346    websWrite( wp, "<div class=\"label\">%s</div>\n",
7347               live_translate( "wl_mac.label" ) );
7348    char macmode[32];
7349
7350    sprintf( macmode, "%s_macmode1", ifname );
7351    rep( macmode, '.', 'X' );
7352    if( nvram_get( macmode ) == NULL )
7353        nvram_set( macmode, "disabled" );
7354    char id[32];
7355
7356    sprintf( id, "idmac%s", ifname );
7357    rep( id, '.', 'X' );
7358    char mycopy[256];
7359
7360    strcpy( mycopy, live_translate( "share.enable" ) );
7361    websWrite( wp,
7362               "<input class=\"spaceradio\" type=\"radio\" value=\"other\" name=\"%s\" %s onclick=\"show_layer_ext(this, '%s', true)\" />%s&nbsp;\n",
7363               macmode, nvram_match( macmode,
7364                                     "other" ) ? "checked=\"checked\"" : "",
7365               id, mycopy );
7366    strcpy( mycopy, live_translate( "share.disable" ) );
7367    websWrite( wp,
7368               "<input class=\"spaceradio\" type=\"radio\" value=\"disabled\" name=\"%s\" %s onclick=\"show_layer_ext(this, '%s', false)\" />%s\n",
7369               macmode, nvram_match( macmode,
7370                                     "disabled" ) ? "checked=\"checked\"" :
7371               "", id, mycopy );
7372    websWrite( wp, "</div>\n" );
7373    websWrite( wp, "<div class=\"setting\" id=\"%s\">\n", id );
7374    websWrite( wp, "<div class=\"label\">%s<br />&nbsp;</div>\n",
7375               live_translate( "wl_mac.label2" ) );
7376    sprintf( macmode, "%s_macmode", ifname );
7377    if( nvram_get( macmode ) == NULL )
7378        nvram_set( macmode, "disabled" );
7379    strcpy( mycopy, live_translate( "wl_mac.deny" ) );
7380    websWrite( wp,
7381               "<input class=\"spaceradio\" type=\"radio\" value=\"deny\" name=\"%s\" %s />%s&nbsp;\n",
7382               macmode, nvram_invmatch( macmode,
7383                                        "allow" ) ? "checked=\"checked\"" :
7384               "", mycopy );
7385    websWrite( wp, "<br />\n" );
7386    strcpy( mycopy, live_translate( "wl_mac.allow" ) );
7387    websWrite( wp,
7388               "<input class=\"spaceradio\" type=\"radio\" value=\"allow\" name=\"%s\" %s />%s\n",
7389               macmode, nvram_match( macmode,
7390                                     "allow" ) ? "checked=\"checked\"" : "",
7391               mycopy );
7392    websWrite( wp, "</div><br />\n" );
7393    websWrite( wp, "<div class=\"center\">\n" );
7394    websWrite( wp, "<script type=\"text/javascript\">\n" );
7395    websWrite( wp, "//<![CDATA[\n" );
7396    websWrite( wp,
7397               "document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" name=\\\"mac_filter_button\\\" value=\\\"\" + sbutton.filterMac + \"\\\" onclick=\\\"openWindow('WL_FilterTable-%s.asp', 930, 740,'MACList');\\\" />\");\n",
7398               ifname );
7399    websWrite( wp, "//]]>\n" );
7400    websWrite( wp, "</script>\n" );
7401    websWrite( wp, "</div>\n" );
7402    websWrite( wp, "</fieldset><br />\n" );
7403}
7404
7405void ej_list_mac_layers( webs_t wp, int argc, char_t ** argv )
7406{
7407#ifndef HAVE_MADWIFI
7408    int c = get_wl_instances(  );
7409    char devs[32];
7410    int i;
7411
7412    for( i = 0; i < c; i++ )
7413    {
7414        char macmode[32];
7415        char id[32];
7416
7417        sprintf( devs, "wl%d", i );
7418        sprintf( macmode, "%s_macmode1", devs );
7419        sprintf( id, "idmac%s", devs );
7420        rep( id, '.', 'X' );
7421        rep( macmode, '.', 'X' );
7422        websWrite( wp,
7423                   "show_layer_ext(document.wireless.%s, '%s', \"%s\" == \"other\");\n",
7424                   macmode, id, nvram_match( macmode,
7425                                             "other" ) ? "other" :
7426                   "disabled" );
7427    }
7428
7429#else
7430
7431    int c = getdevicecount(  );
7432    char devs[32];
7433    int i;
7434
7435    for( i = 0; i < c; i++ )
7436    {
7437        char macmode[32];
7438        char id[32];
7439
7440        sprintf( devs, "ath%d", i );
7441        sprintf( macmode, "%s_macmode1", devs );
7442        sprintf( id, "idmac%s", devs );
7443        rep( id, '.', 'X' );
7444        rep( macmode, '.', 'X' );
7445        websWrite( wp,
7446                   "show_layer_ext(document.wireless.%s, '%s', \"%s\" == \"other\");\n",
7447                   macmode, id, nvram_match( macmode,
7448                                             "other" ) ? "other" :
7449                   "disabled" );
7450        // show_macfilter_if (wp, devs);
7451        char vif[32];
7452
7453        sprintf( vif, "%s_vifs", devs );
7454        char var[80], *next;
7455        char *vifs = nvram_safe_get( vif );
7456
7457        if( vifs != NULL )
7458            foreach( var, vifs, next )
7459        {
7460            sprintf( macmode, "%s_macmode1", var );
7461            sprintf( id, "idmac%s", var );
7462            rep( id, '.', 'X' );
7463            rep( macmode, '.', 'X' );
7464            websWrite( wp,
7465                       "show_layer_ext(document.wireless.%s, '%s', \"%s\" == \"other\");\n",
7466                       macmode, id, nvram_match( macmode,
7467                                                 "other" ) ? "other" :
7468                       "disabled" );
7469        }
7470    }
7471
7472#endif
7473}
7474void ej_show_macfilter( webs_t wp, int argc, char_t ** argv )
7475{
7476#ifndef HAVE_MADWIFI
7477    int c = get_wl_instances(  );
7478    char devs[32];
7479    int i;
7480
7481    for( i = 0; i < c; i++ )
7482    {
7483        sprintf( devs, "wl%d", i );
7484        show_macfilter_if( wp, devs );
7485    }
7486#else
7487    int c = getdevicecount(  );
7488    char devs[32];
7489    int i;
7490
7491    for( i = 0; i < c; i++ )
7492    {
7493        sprintf( devs, "ath%d", i );
7494        show_macfilter_if( wp, devs );
7495        char vif[32];
7496
7497        sprintf( vif, "%s_vifs", devs );
7498        char var[80], *next;
7499        char *vifs = nvram_safe_get( vif );
7500
7501        if( vifs != NULL )
7502            foreach( var, vifs, next )
7503        {
7504            show_macfilter_if( wp, var );
7505        }
7506    }
7507
7508#endif
7509}
7510
7511#ifdef HAVE_CHILLI
7512void ej_show_chilliif( webs_t wp, int argc, char_t ** argv )
7513{
7514    websWrite( wp, "<select name=\"chilli_interface\">\n" );
7515    websWrite( wp, "<option value=\"%s\" %s >LAN</option>\n",
7516               nvram_safe_get( "lan_ifname" ),
7517               nvram_match( "chilli_interface",
7518                            nvram_safe_get( "lan_ifname" ) ) ?
7519               "selected=\"selected\"" : "" );
7520    char *next;
7521    char var[80];
7522    char eths[256];
7523
7524    memset( eths, 0, 256 );
7525    getIfLists( eths, 256 );
7526    foreach( var, eths, next )
7527    {
7528        if( !strcmp( get_wan_face(  ), var ) )
7529            continue;
7530        if( !strcmp( nvram_safe_get( "lan_ifname" ), var ) )
7531            continue;
7532        websWrite( wp, "<option value=\"%s\" %s >%s</option>\n", var,
7533                   nvram_match( "chilli_interface", var ) ? "selected" : "",
7534                   var );
7535    }
7536
7537    websWrite( wp, "</select>\n" );
7538}
7539#endif
7540
7541#ifdef HAVE_RFLOW
7542void ej_show_rflowif( webs_t wp, int argc, char_t ** argv )
7543{
7544    websWrite( wp, "<option value=\"%s\" %s >LAN &amp; WLAN</option>\n",
7545               nvram_safe_get( "lan_ifname" ), nvram_match( "rflow_if",
7546                                                            nvram_safe_get
7547                                                            ( "lan_ifname" ) )
7548               ? "selected=\"selected\"" : "" );
7549
7550    char *lanifs = nvram_safe_get( "lan_ifnames" );
7551    char tmp[128];
7552    char *lanif;
7553
7554    if( strlen( lanifs ) != 0 )
7555    {
7556        strcpy( tmp, lanifs );
7557        lanif = strtok( tmp, " " );
7558        websWrite( wp, "<option value=\"%s\" %s >LAN</option>\n",
7559                   lanif, nvram_match( "rflow_if",
7560                                       lanif ) ? "selected=\"selected\"" :
7561                   "" );
7562    }
7563
7564    websWrite( wp, "<option value=\"%s\" %s >WLAN</option>\n",
7565               nvram_safe_get( "wl0_ifname" ), nvram_match( "rflow_if",
7566                                                            nvram_safe_get
7567                                                            ( "wl0_ifname" ) )
7568               ? "selected=\"selected\"" : "" );
7569
7570    char *wanif = nvram_safe_get( "wan_ifname" );
7571
7572    if( strlen( wanif ) != 0 )
7573    {
7574        websWrite( wp, "<option value=\"%s\" %s >WAN</option>\n",
7575                   wanif, nvram_match( "rflow_if",
7576                                       wanif ) ? "selected=\"selected\"" :
7577                   "" );
7578    }
7579}
7580#endif
Note: See TracBrowser for help on using the repository browser.