| 1 |
#define VISUALSOURCE 1 |
|---|
| 2 |
|
|---|
| 3 |
#include <stdio.h> |
|---|
| 4 |
#include <stdlib.h> |
|---|
| 5 |
#include <stdarg.h> |
|---|
| 6 |
#include <string.h> |
|---|
| 7 |
#include <unistd.h> |
|---|
| 8 |
#include <ctype.h> |
|---|
| 9 |
#include <signal.h> |
|---|
| 10 |
|
|---|
| 11 |
#include <sys/ioctl.h> |
|---|
| 12 |
#include <sys/types.h> |
|---|
| 13 |
#include <sys/stat.h> |
|---|
| 14 |
#include <sys/socket.h> |
|---|
| 15 |
#include <sys/statfs.h> |
|---|
| 16 |
#include <netinet/in.h> |
|---|
| 17 |
#include <arpa/inet.h> |
|---|
| 18 |
#include <broadcom.h> |
|---|
| 19 |
#include <cymac.h> |
|---|
| 20 |
#include <wlutils.h> |
|---|
| 21 |
#include <bcmparams.h> |
|---|
| 22 |
#include <dirent.h> |
|---|
| 23 |
#include <netdb.h> |
|---|
| 24 |
#include <utils.h> |
|---|
| 25 |
#include <bcmnvram.h> |
|---|
| 26 |
#include <revision.h> |
|---|
| 27 |
|
|---|
| 28 |
void (*do_ej_buffer) (char *buffer, webs_t stream) = NULL; |
|---|
| 29 |
int (*httpd_filter_name) (char *old_name, char *new_name, size_t size, |
|---|
| 30 |
int type) = NULL; |
|---|
| 31 |
char *(*websGetVar) (webs_t wp, char *var, char *d) = NULL; |
|---|
| 32 |
int (*websWrite) (webs_t wp, char *fmt, ...) = NULL; |
|---|
| 33 |
struct wl_client_mac *wl_client_macs = NULL; |
|---|
| 34 |
void (*do_ej) (struct mime_handler * handler, char *path, webs_t stream, char *query) = NULL; // jimmy, |
|---|
| 35 |
// https, |
|---|
| 36 |
// 8/4/2003 |
|---|
| 37 |
int (*ejArgs) (int argc, char_t ** argv, char_t * fmt, ...) = NULL; |
|---|
| 38 |
FILE *(*getWebsFile) (char *path) = NULL; |
|---|
| 39 |
int (*wfflush) (webs_t fp) = NULL; |
|---|
| 40 |
int (*wfputc) (char c, webs_t fp) = NULL; |
|---|
| 41 |
int (*wfputs) (char *buf, webs_t fp) = NULL; |
|---|
| 42 |
char *(*live_translate) (char *tran) = NULL; |
|---|
| 43 |
websRomPageIndexType *websRomPageIndex = NULL; |
|---|
| 44 |
char *(*GOZILA_GET) (webs_t wp, char *name) = NULL; |
|---|
| 45 |
|
|---|
| 46 |
#ifdef HAVE_HTTPS |
|---|
| 47 |
int do_ssl; |
|---|
| 48 |
#endif |
|---|
| 49 |
|
|---|
| 50 |
void initWeb(struct Webenvironment *env) |
|---|
| 51 |
{ |
|---|
| 52 |
|
|---|
| 53 |
cprintf("set websgetwar %p:%p->%p:%p\n", env, env->PwebsGetVar, |
|---|
| 54 |
&websGetVar, websGetVar); |
|---|
| 55 |
websGetVar = env->PwebsGetVar; |
|---|
| 56 |
httpd_filter_name = env->Phttpd_filter_name; |
|---|
| 57 |
cprintf("set wl_client_macs\n"); |
|---|
| 58 |
wl_client_macs = env->Pwl_client_macs; |
|---|
| 59 |
cprintf("set webswrite\n"); |
|---|
| 60 |
websWrite = env->PwebsWrite; |
|---|
| 61 |
cprintf("set do_ej_buffer\n"); |
|---|
| 62 |
do_ej_buffer = env->Pdo_ej_buffer; |
|---|
| 63 |
cprintf("set do_ej\n"); |
|---|
| 64 |
do_ej = env->Pdo_ej; |
|---|
| 65 |
#ifdef HAVE_HTTPS |
|---|
| 66 |
cprintf("set do_ssl\n"); |
|---|
| 67 |
do_ssl = env->Pdo_ssl; |
|---|
| 68 |
#endif |
|---|
| 69 |
cprintf("set ejargs\n"); |
|---|
| 70 |
ejArgs = env->PejArgs; |
|---|
| 71 |
cprintf("set getwebsfile\n"); |
|---|
| 72 |
getWebsFile = env->PgetWebsFile; |
|---|
| 73 |
cprintf("set wwflush\n"); |
|---|
| 74 |
wfflush = env->Pwfflush; |
|---|
| 75 |
cprintf("set wfputs\n"); |
|---|
| 76 |
wfputc = env->Pwfputc; |
|---|
| 77 |
cprintf("set wfputs\n"); |
|---|
| 78 |
wfputs = env->Pwfputs; |
|---|
| 79 |
cprintf("set websrompageindex\n"); |
|---|
| 80 |
websRomPageIndex = env->PwebsRomPageIndex; |
|---|
| 81 |
cprintf("set live_translate\n"); |
|---|
| 82 |
live_translate = env->Plive_translate; |
|---|
| 83 |
GOZILA_GET = env->PGOZILA_GET; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
struct onload onloads[] = { |
|---|
| 87 |
// { "Filters", filter_onload }, |
|---|
| 88 |
{"WL_ActiveTable-wl0", wl_active_onload}, |
|---|
| 89 |
{"WL_ActiveTable-wl1", wl_active_onload}, |
|---|
| 90 |
{"MACClone", macclone_onload}, |
|---|
| 91 |
{"FilterSummary", filtersummary_onload}, |
|---|
| 92 |
{"Ping", ping_onload}, |
|---|
| 93 |
// {"Traceroute", traceroute_onload}, |
|---|
| 94 |
}; |
|---|
| 95 |
|
|---|
| 96 |
void ej_onload(webs_t wp, int argc, char_t ** argv) |
|---|
| 97 |
{ |
|---|
| 98 |
char *type, *arg; |
|---|
| 99 |
struct onload *v; |
|---|
| 100 |
|
|---|
| 101 |
#ifndef FASTWEB |
|---|
| 102 |
if (argc < 2) { |
|---|
| 103 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 104 |
return; |
|---|
| 105 |
} |
|---|
| 106 |
#endif |
|---|
| 107 |
type = argv[0]; |
|---|
| 108 |
arg = argv[1]; |
|---|
| 109 |
|
|---|
| 110 |
for (v = onloads; v < &onloads[STRUCT_LEN(onloads)]; v++) { |
|---|
| 111 |
if (!strcmp(v->name, type)) { |
|---|
| 112 |
v->go(wp, arg); |
|---|
| 113 |
return; |
|---|
| 114 |
} |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
return; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
/* |
|---|
| 121 |
* Meta tag command that will no allow page cached by browsers. The will |
|---|
| 122 |
* force the page to be refreshed when visited. |
|---|
| 123 |
*/ |
|---|
| 124 |
void ej_no_cache(webs_t wp, int argc, char_t ** argv) |
|---|
| 125 |
{ |
|---|
| 126 |
websWrite(wp, "<meta http-equiv=\"expires\" content=\"0\">\n"); |
|---|
| 127 |
websWrite(wp, |
|---|
| 128 |
"<meta http-equiv=\"cache-control\" content=\"no-cache\">\n"); |
|---|
| 129 |
websWrite(wp, "<meta http-equiv=\"pragma\" content=\"no-cache\">\n"); |
|---|
| 130 |
|
|---|
| 131 |
return; |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
void prefix_ip_get(char *name, char *buf, int type) |
|---|
| 135 |
{ |
|---|
| 136 |
if (type == 1) |
|---|
| 137 |
sprintf(buf, "%d.%d.%d.", |
|---|
| 138 |
get_single_ip(nvram_safe_get(name), 0), |
|---|
| 139 |
get_single_ip(nvram_safe_get(name), 1), |
|---|
| 140 |
get_single_ip(nvram_safe_get(name), 2)); |
|---|
| 141 |
if (type == 2) |
|---|
| 142 |
sprintf(buf, "%d.%d.", get_single_ip(nvram_safe_get(name), 0), |
|---|
| 143 |
get_single_ip(nvram_safe_get(name), 1)); |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
/* |
|---|
| 147 |
* Example: |
|---|
| 148 |
* lan_ipaddr=192.168.1.1 |
|---|
| 149 |
* <% prefix_ip_get("lan_ipaddr",1); %> produces "192.168.1." |
|---|
| 150 |
*/ |
|---|
| 151 |
void ej_prefix_ip_get(webs_t wp, int argc, char_t ** argv) |
|---|
| 152 |
{ |
|---|
| 153 |
char *name; |
|---|
| 154 |
int type; |
|---|
| 155 |
|
|---|
| 156 |
#ifndef FASTWEB |
|---|
| 157 |
if (argc < 2) { |
|---|
| 158 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 159 |
return; |
|---|
| 160 |
} |
|---|
| 161 |
#endif |
|---|
| 162 |
name = argv[0]; |
|---|
| 163 |
type = atoi(argv[1]); |
|---|
| 164 |
|
|---|
| 165 |
if (type == 1) |
|---|
| 166 |
websWrite(wp, "%d.%d.%d.", |
|---|
| 167 |
get_single_ip(nvram_safe_get(name), 0), |
|---|
| 168 |
get_single_ip(nvram_safe_get(name), 1), |
|---|
| 169 |
get_single_ip(nvram_safe_get(name), 2)); |
|---|
| 170 |
if (type == 2) |
|---|
| 171 |
websWrite(wp, "%d.%d.", get_single_ip(nvram_safe_get(name), 0), |
|---|
| 172 |
get_single_ip(nvram_safe_get(name), 1)); |
|---|
| 173 |
|
|---|
| 174 |
return; |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
/* |
|---|
| 178 |
* Example: |
|---|
| 179 |
* lan_ipaddr = 192.168.1.1 |
|---|
| 180 |
* <% nvram_get("lan_ipaddr"); %> produces "192.168.1.1" |
|---|
| 181 |
*/ |
|---|
| 182 |
void ej_nvram_get(webs_t wp, int argc, char_t ** argv) |
|---|
| 183 |
{ |
|---|
| 184 |
|
|---|
| 185 |
#ifndef FASTWEB |
|---|
| 186 |
if (argc < 1) { |
|---|
| 187 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 188 |
return; |
|---|
| 189 |
} |
|---|
| 190 |
#endif |
|---|
| 191 |
|
|---|
| 192 |
#if COUNTRY == JAPAN |
|---|
| 193 |
websWrite(wp, "%s", nvram_safe_get(argv[0])); |
|---|
| 194 |
#else |
|---|
| 195 |
/* |
|---|
| 196 |
* for (c = nvram_safe_get (name); *c; c++) { if (isprint ((int) *c)) // |
|---|
| 197 |
* && // *c != '"' && *c != '&' && *c != '<' && *c != '>') ret += |
|---|
| 198 |
* websWrite (wp, "%c", *c); else { if (*c == '"') ret += websWrite (wp, |
|---|
| 199 |
* """); else if (*c == '&') ret += websWrite (wp, "&"); else if |
|---|
| 200 |
* (*c == '<') ret += websWrite (wp, "<"); else if (*c == '>') ret += |
|---|
| 201 |
* websWrite (wp, ">"); else if (*c == 13) continue; else ret += |
|---|
| 202 |
* websWrite (wp, "&#%d", *c); } } |
|---|
| 203 |
*/ |
|---|
| 204 |
|
|---|
| 205 |
tf_webWriteESCNV(wp, argv[0]); // test: buffered version of above |
|---|
| 206 |
|
|---|
| 207 |
return; |
|---|
| 208 |
#endif |
|---|
| 209 |
|
|---|
| 210 |
return; |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
void ej_nvram_real_get(webs_t wp, int argc, char_t ** argv) |
|---|
| 214 |
{ |
|---|
| 215 |
|
|---|
| 216 |
#ifndef FASTWEB |
|---|
| 217 |
if (argc < 1) { |
|---|
| 218 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 219 |
return; |
|---|
| 220 |
} |
|---|
| 221 |
#endif |
|---|
| 222 |
websWrite(wp, "%s", nvram_safe_get(argv[0])); |
|---|
| 223 |
|
|---|
| 224 |
return; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
/* |
|---|
| 228 |
* Example: |
|---|
| 229 |
* lan_ipaddr = 192.168.1.1, gozila_action = 0 |
|---|
| 230 |
* <% nvram_selget("lan_ipaddr"); %> produces "192.168.1.1" |
|---|
| 231 |
* lan_ipaddr = 192.168.1.1, gozila_action = 1, websGetVar(wp, "lan_proto", NULL) = 192.168.1.2; |
|---|
| 232 |
* <% nvram_selget("lan_ipaddr"); %> produces "192.168.1.2" |
|---|
| 233 |
*/ |
|---|
| 234 |
void ej_nvram_selget(webs_t wp, int argc, char_t ** argv) |
|---|
| 235 |
{ |
|---|
| 236 |
char *name; |
|---|
| 237 |
|
|---|
| 238 |
#ifndef FASTWEB |
|---|
| 239 |
if (argc < 1) { |
|---|
| 240 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 241 |
return; |
|---|
| 242 |
} |
|---|
| 243 |
#endif |
|---|
| 244 |
name = argv[0]; |
|---|
| 245 |
if (nvram_match("gozila_action", "1")) { |
|---|
| 246 |
char *buf = websGetVar(wp, name, NULL); |
|---|
| 247 |
|
|---|
| 248 |
if (buf) { |
|---|
| 249 |
websWrite(wp, "%s", buf); |
|---|
| 250 |
return; |
|---|
| 251 |
} |
|---|
| 252 |
} |
|---|
| 253 |
tf_webWriteESCNV(wp, name); // test: buffered version of above |
|---|
| 254 |
|
|---|
| 255 |
return; |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
/* |
|---|
| 259 |
* Example: |
|---|
| 260 |
* wan_mac = 00:11:22:33:44:55 |
|---|
| 261 |
* <% nvram_mac_get("wan_mac"); %> produces "00-11-22-33-44-55" |
|---|
| 262 |
*/ |
|---|
| 263 |
void ej_nvram_mac_get(webs_t wp, int argc, char_t ** argv) |
|---|
| 264 |
{ |
|---|
| 265 |
char *c; |
|---|
| 266 |
char *mac; |
|---|
| 267 |
int i; |
|---|
| 268 |
|
|---|
| 269 |
#ifndef FASTWEB |
|---|
| 270 |
if (argc < 1) { |
|---|
| 271 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 272 |
return; |
|---|
| 273 |
} |
|---|
| 274 |
#endif |
|---|
| 275 |
c = nvram_safe_get(argv[0]); |
|---|
| 276 |
|
|---|
| 277 |
if (c) { |
|---|
| 278 |
mac = strdup(c); |
|---|
| 279 |
for (i = 0; *(mac + i); i++) { |
|---|
| 280 |
if (*(mac + i) == ':') |
|---|
| 281 |
*(mac + i) = '-'; |
|---|
| 282 |
} |
|---|
| 283 |
websWrite(wp, "%s", mac); |
|---|
| 284 |
free(mac); // leak, thx tofu |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
return; |
|---|
| 288 |
|
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
/* |
|---|
| 292 |
* Example: |
|---|
| 293 |
* wan_proto = dhcp; gozilla = 0; |
|---|
| 294 |
* <% nvram_gozila_get("wan_proto"); %> produces "dhcp" |
|---|
| 295 |
* |
|---|
| 296 |
* wan_proto = dhcp; gozilla = 1; websGetVar(wp, "wan_proto", NULL) = static; |
|---|
| 297 |
* <% nvram_gozila_get("wan_proto"); %> produces "static" |
|---|
| 298 |
*/ |
|---|
| 299 |
void ej_nvram_gozila_get(webs_t wp, int argc, char_t ** argv) |
|---|
| 300 |
{ |
|---|
| 301 |
char *type; |
|---|
| 302 |
|
|---|
| 303 |
#ifndef FASTWEB |
|---|
| 304 |
if (argc < 1) { |
|---|
| 305 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 306 |
return; |
|---|
| 307 |
} |
|---|
| 308 |
#endif |
|---|
| 309 |
type = GOZILA_GET(wp, argv[0]); |
|---|
| 310 |
if (type == NULL) |
|---|
| 311 |
type = nvram_safe_get(argv[0]); |
|---|
| 312 |
|
|---|
| 313 |
websWrite(wp, "%s", type); |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
void ej_webs_get(webs_t wp, int argc, char_t ** argv) |
|---|
| 317 |
{ |
|---|
| 318 |
char *value; |
|---|
| 319 |
|
|---|
| 320 |
#ifndef FASTWEB |
|---|
| 321 |
if (argc < 1) { |
|---|
| 322 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 323 |
return; |
|---|
| 324 |
} |
|---|
| 325 |
#endif |
|---|
| 326 |
|
|---|
| 327 |
value = websGetVar(wp, argv[0], NULL); |
|---|
| 328 |
|
|---|
| 329 |
if (value) |
|---|
| 330 |
websWrite(wp, "%s", value); |
|---|
| 331 |
|
|---|
| 332 |
return; |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
/* |
|---|
| 336 |
* Example: |
|---|
| 337 |
* lan_ipaddr = 192.168.1.1 |
|---|
| 338 |
* <% get_single_ip("lan_ipaddr","1"); %> produces "168" |
|---|
| 339 |
*/ |
|---|
| 340 |
void ej_get_single_ip(webs_t wp, int argc, char_t ** argv) |
|---|
| 341 |
{ |
|---|
| 342 |
char *c; |
|---|
| 343 |
|
|---|
| 344 |
#ifndef FASTWEB |
|---|
| 345 |
if (argc < 1) { |
|---|
| 346 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 347 |
return; |
|---|
| 348 |
} |
|---|
| 349 |
#endif |
|---|
| 350 |
|
|---|
| 351 |
c = nvram_safe_get(argv[0]); |
|---|
| 352 |
if (c) { |
|---|
| 353 |
if (!strcmp(c, PPP_PSEUDO_IP) || !strcmp(c, PPP_PSEUDO_GW)) |
|---|
| 354 |
c = "0.0.0.0"; |
|---|
| 355 |
else if (!strcmp(c, PPP_PSEUDO_NM)) |
|---|
| 356 |
c = "255.255.255.0"; |
|---|
| 357 |
|
|---|
| 358 |
websWrite(wp, "%d", get_single_ip(c, atoi(argv[1]))); |
|---|
| 359 |
} else |
|---|
| 360 |
websWrite(wp, "0"); |
|---|
| 361 |
|
|---|
| 362 |
return; |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
/* |
|---|
| 366 |
* Example: wan_mac = 00:11:22:33:44:55 get_single_mac("wan_mac", 1); |
|---|
| 367 |
* produces "11" |
|---|
| 368 |
*/ |
|---|
| 369 |
int get_single_mac(char *macaddr, int which) |
|---|
| 370 |
{ |
|---|
| 371 |
int mac[6] = { 0, 0, 0, 0, 0, 0 }; |
|---|
| 372 |
int ret; |
|---|
| 373 |
|
|---|
| 374 |
ret = |
|---|
| 375 |
sscanf(macaddr, "%2X:%2X:%2X:%2X:%2X:%2X", &mac[0], &mac[1], |
|---|
| 376 |
&mac[2], &mac[3], &mac[4], &mac[5]); |
|---|
| 377 |
return mac[which]; |
|---|
| 378 |
} |
|---|
| 379 |
|
|---|
| 380 |
/* |
|---|
| 381 |
* Example: |
|---|
| 382 |
* wan_mac = 00:11:22:33:44:55 |
|---|
| 383 |
* <% get_single_mac("wan_mac","1"); %> produces "11" |
|---|
| 384 |
*/ |
|---|
| 385 |
void ej_get_single_mac(webs_t wp, int argc, char_t ** argv) |
|---|
| 386 |
{ |
|---|
| 387 |
char *c; |
|---|
| 388 |
int mac; |
|---|
| 389 |
|
|---|
| 390 |
#ifndef FASTWEB |
|---|
| 391 |
if (argc < 2) { |
|---|
| 392 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 393 |
return; |
|---|
| 394 |
} |
|---|
| 395 |
#endif |
|---|
| 396 |
|
|---|
| 397 |
c = nvram_safe_get(argv[0]); |
|---|
| 398 |
if (c) { |
|---|
| 399 |
mac = get_single_mac(c, atoi(argv[1])); |
|---|
| 400 |
websWrite(wp, "%02X", mac); |
|---|
| 401 |
} else |
|---|
| 402 |
websWrite(wp, "00"); |
|---|
| 403 |
|
|---|
| 404 |
return; |
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
/* |
|---|
| 408 |
* Example: |
|---|
| 409 |
* wan_proto = dhcp; gozilla = 0; |
|---|
| 410 |
* <% nvram_selmatch("wan_proto", "dhcp", "selected"); %> produces "selected" |
|---|
| 411 |
* |
|---|
| 412 |
* wan_proto = dhcp; gozilla = 1; websGetVar(wp, "wan_proto", NULL) = static; |
|---|
| 413 |
* <% nvram_selmatch("wan_proto", "static", "selected"); %> produces "selected" |
|---|
| 414 |
*/ |
|---|
| 415 |
|
|---|
| 416 |
int nvram_selmatch(webs_t wp, char *name, char *match) |
|---|
| 417 |
{ |
|---|
| 418 |
char *type = GOZILA_GET(wp, name); |
|---|
| 419 |
|
|---|
| 420 |
if (!type) { |
|---|
| 421 |
if (nvram_match(name, match)) { |
|---|
| 422 |
return 1; |
|---|
| 423 |
} |
|---|
| 424 |
} else { |
|---|
| 425 |
if (!strcmp(type, match)) { |
|---|
| 426 |
return 1; |
|---|
| 427 |
} |
|---|
| 428 |
} |
|---|
| 429 |
return 0; |
|---|
| 430 |
} |
|---|
| 431 |
|
|---|
| 432 |
void ej_nvram_selmatch(webs_t wp, int argc, char_t ** argv) |
|---|
| 433 |
{ |
|---|
| 434 |
|
|---|
| 435 |
#ifndef FASTWEB |
|---|
| 436 |
if (argv < 3) { |
|---|
| 437 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 438 |
return; |
|---|
| 439 |
} |
|---|
| 440 |
#endif |
|---|
| 441 |
if (nvram_selmatch(wp, argv[0], argv[1])) { |
|---|
| 442 |
websWrite(wp, argv[2]); |
|---|
| 443 |
} |
|---|
| 444 |
return; |
|---|
| 445 |
} |
|---|
| 446 |
|
|---|
| 447 |
void ej_nvram_else_selmatch(webs_t wp, int argc, char_t ** argv) |
|---|
| 448 |
{ |
|---|
| 449 |
char *type; |
|---|
| 450 |
|
|---|
| 451 |
#ifndef FASTWEB |
|---|
| 452 |
if (argc < 4) { |
|---|
| 453 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 454 |
return; |
|---|
| 455 |
} |
|---|
| 456 |
#endif |
|---|
| 457 |
|
|---|
| 458 |
type = GOZILA_GET(wp, argv[0]); |
|---|
| 459 |
|
|---|
| 460 |
if (!type) { |
|---|
| 461 |
if (nvram_match(argv[0], argv[1])) { |
|---|
| 462 |
websWrite(wp, argv[2]); |
|---|
| 463 |
} else |
|---|
| 464 |
websWrite(wp, argv[3]); |
|---|
| 465 |
} else { |
|---|
| 466 |
if (!strcmp(type, argv[1])) { |
|---|
| 467 |
websWrite(wp, argv[2]); |
|---|
| 468 |
} else |
|---|
| 469 |
websWrite(wp, argv[3]); |
|---|
| 470 |
} |
|---|
| 471 |
|
|---|
| 472 |
return; |
|---|
| 473 |
} |
|---|
| 474 |
|
|---|
| 475 |
/* |
|---|
| 476 |
* Example: |
|---|
| 477 |
* wan_proto=dhcp |
|---|
| 478 |
* <% nvram_else_match("wan_proto", "dhcp", "0","1"); %> produces "0" |
|---|
| 479 |
* <% nvram_else_match("wan_proto", "static", "0","1"); %> produces "1" |
|---|
| 480 |
*/ |
|---|
| 481 |
void ej_nvram_else_match(webs_t wp, int argc, char_t ** argv) |
|---|
| 482 |
{ |
|---|
| 483 |
|
|---|
| 484 |
#ifndef FASTWEB |
|---|
| 485 |
if (argc < 4) { |
|---|
| 486 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 487 |
return; |
|---|
| 488 |
} |
|---|
| 489 |
#endif |
|---|
| 490 |
|
|---|
| 491 |
if (nvram_match(argv[0], argv[1])) |
|---|
| 492 |
websWrite(wp, argv[2]); |
|---|
| 493 |
else |
|---|
| 494 |
websWrite(wp, argv[3]); |
|---|
| 495 |
|
|---|
| 496 |
return; |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
void ej_startswith(webs_t wp, int argc, char_t ** argv) |
|---|
| 500 |
{ |
|---|
| 501 |
|
|---|
| 502 |
#ifndef FASTWEB |
|---|
| 503 |
if (argc < 3) { |
|---|
| 504 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 505 |
return; |
|---|
| 506 |
} |
|---|
| 507 |
#endif |
|---|
| 508 |
if (startswith(nvram_safe_get(argv[0]), argv[1])) |
|---|
| 509 |
websWrite(wp, argv[2]); |
|---|
| 510 |
|
|---|
| 511 |
return; |
|---|
| 512 |
} |
|---|
| 513 |
|
|---|
| 514 |
void ej_ifdef(webs_t wp, int argc, char_t ** argv) |
|---|
| 515 |
{ |
|---|
| 516 |
char *name, *output; |
|---|
| 517 |
|
|---|
| 518 |
#ifndef FASTWEB |
|---|
| 519 |
if (argc < 2) { |
|---|
| 520 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 521 |
return; |
|---|
| 522 |
} |
|---|
| 523 |
#endif |
|---|
| 524 |
name = argv[0]; |
|---|
| 525 |
output = argv[1]; |
|---|
| 526 |
#ifdef HAVE_MICRO |
|---|
| 527 |
if (!strcmp(name, "MICRO")) { |
|---|
| 528 |
websWrite(wp, output); |
|---|
| 529 |
return; |
|---|
| 530 |
} |
|---|
| 531 |
#endif |
|---|
| 532 |
#ifdef HAVE_EXTHELP |
|---|
| 533 |
if (!strcmp(name, "EXTHELP")) { |
|---|
| 534 |
websWrite(wp, output); |
|---|
| 535 |
return; |
|---|
| 536 |
} |
|---|
| 537 |
#endif |
|---|
| 538 |
if (!strcmp(name, "MINI")) // to include mini + mini-special |
|---|
| 539 |
{ |
|---|
| 540 |
if (startswith(nvram_safe_get("dist_type"), "mini")) { |
|---|
| 541 |
websWrite(wp, output); |
|---|
| 542 |
return; |
|---|
| 543 |
} |
|---|
| 544 |
} |
|---|
| 545 |
if (!strcmp(name, "VPN")) // to include vpn + vpn-special |
|---|
| 546 |
{ |
|---|
| 547 |
if (startswith(nvram_safe_get("dist_type"), "vpn")) { |
|---|
| 548 |
websWrite(wp, output); |
|---|
| 549 |
return; |
|---|
| 550 |
} |
|---|
| 551 |
} |
|---|
| 552 |
#ifdef HAVE_MULTICAST |
|---|
| 553 |
if (!strcmp(name, "MULTICAST")) { |
|---|
| 554 |
websWrite(wp, output); |
|---|
| 555 |
return; |
|---|
| 556 |
} |
|---|
| 557 |
#endif |
|---|
| 558 |
#ifdef HAVE_WIVIZ |
|---|
| 559 |
if (!strcmp(name, "WIVIZ")) { |
|---|
| 560 |
websWrite(wp, output); |
|---|
| 561 |
return; |
|---|
| 562 |
} |
|---|
| 563 |
#endif |
|---|
| 564 |
#ifdef HAVE_RSTATS |
|---|
| 565 |
if (!strcmp(name, "RSTATS")) { |
|---|
| 566 |
websWrite(wp, output); |
|---|
| 567 |
return; |
|---|
| 568 |
} |
|---|
| 569 |
#endif |
|---|
| 570 |
#ifdef HAVE_ACK |
|---|
| 571 |
if (!strcmp(name, "ACK")) { |
|---|
| 572 |
websWrite(wp, output); |
|---|
| 573 |
return; |
|---|
| 574 |
} |
|---|
| 575 |
#endif |
|---|
| 576 |
#ifdef HAVE_SSHD |
|---|
| 577 |
if (!strcmp(name, "SSHD")) { |
|---|
| 578 |
websWrite(wp, output); |
|---|
| 579 |
return; |
|---|
| 580 |
} |
|---|
| 581 |
#endif |
|---|
| 582 |
if (!strcmp(name, "WET")) { |
|---|
| 583 |
if (getWET()) |
|---|
| 584 |
websWrite(wp, output); |
|---|
| 585 |
return; |
|---|
| 586 |
} |
|---|
| 587 |
if (!strcmp(name, "STA")) { |
|---|
| 588 |
if (getSTA()) |
|---|
| 589 |
websWrite(wp, output); |
|---|
| 590 |
return; |
|---|
| 591 |
} |
|---|
| 592 |
|
|---|
| 593 |
return; |
|---|
| 594 |
} |
|---|
| 595 |
|
|---|
| 596 |
void ej_ifndef(webs_t wp, int argc, char_t ** argv) |
|---|
| 597 |
{ |
|---|
| 598 |
char *name, *output; |
|---|
| 599 |
|
|---|
| 600 |
#ifndef FASTWEB |
|---|
| 601 |
if (argc < 2) { |
|---|
| 602 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 603 |
return; |
|---|
| 604 |
} |
|---|
| 605 |
#endif |
|---|
| 606 |
name = argv[0]; |
|---|
| 607 |
output = argv[1]; |
|---|
| 608 |
|
|---|
| 609 |
#ifdef HAVE_MICRO |
|---|
| 610 |
if (!strcmp(name, "MICRO")) |
|---|
| 611 |
return; |
|---|
| 612 |
#endif |
|---|
| 613 |
#ifdef HAVE_MULTICAST |
|---|
| 614 |
if (!strcmp(name, "MULTICAST")) |
|---|
| 615 |
return; |
|---|
| 616 |
#endif |
|---|
| 617 |
#ifdef HAVE_WIVIZ |
|---|
| 618 |
if (!strcmp(name, "WIVIZ")) |
|---|
| 619 |
return; |
|---|
| 620 |
#endif |
|---|
| 621 |
#ifdef HAVE_RSTATS |
|---|
| 622 |
if (!strcmp(name, "RSTATS")) |
|---|
| 623 |
return; |
|---|
| 624 |
#endif |
|---|
| 625 |
#ifdef HAVE_ACK |
|---|
| 626 |
if (!strcmp(name, "ACK")) |
|---|
| 627 |
return; |
|---|
| 628 |
#endif |
|---|
| 629 |
#ifdef HAVE_SAMBA |
|---|
| 630 |
if (!strcmp(name, "SAMBA")) |
|---|
| 631 |
return; |
|---|
| 632 |
#endif |
|---|
| 633 |
#ifdef HAVE_JFFS2 |
|---|
| 634 |
if (!strcmp(name, "JFFS2")) |
|---|
| 635 |
return; |
|---|
| 636 |
#endif |
|---|
| 637 |
#ifdef HAVE_GPSI |
|---|
| 638 |
if (!strcmp(name, "GPSI")) |
|---|
| 639 |
return; |
|---|
| 640 |
#endif |
|---|
| 641 |
#ifdef HAVE_MMC |
|---|
| 642 |
if (!strcmp(name, "MMC")) |
|---|
| 643 |
return; |
|---|
| 644 |
#endif |
|---|
| 645 |
#ifdef HAVE_SPUTNIK_APD |
|---|
| 646 |
if (!strcmp(name, "SPUTNIK_APD")) |
|---|
| 647 |
return; |
|---|
| 648 |
#endif |
|---|
| 649 |
#ifdef HAVE_RFLOW |
|---|
| 650 |
if (!strcmp(name, "RFLOW")) |
|---|
| 651 |
return; |
|---|
| 652 |
#endif |
|---|
| 653 |
#ifdef HAVE_USB |
|---|
| 654 |
if (!strcmp(name, "USB")) |
|---|
| 655 |
return; |
|---|
| 656 |
#endif |
|---|
| 657 |
#ifdef HAVE_SSHD |
|---|
| 658 |
if (!strcmp(name, "SSHD")) |
|---|
| 659 |
return; |
|---|
| 660 |
#endif |
|---|
| 661 |
#ifdef HAVE_PPPOESERVER |
|---|
| 662 |
if (!strcmp(name, "PPPOESERVER")) |
|---|
| 663 |
return; |
|---|
| 664 |
#endif |
|---|
| 665 |
#ifdef HAVE_MILKFISH |
|---|
| 666 |
if (!strcmp(name, "MILKFISH")) |
|---|
| 667 |
return; |
|---|
| 668 |
#endif |
|---|
| 669 |
// HAVE_AFTERBURNER |
|---|
| 670 |
if (!strncmp(name, "AFTERBURNER", 11)) { |
|---|
| 671 |
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) |
|---|
| 672 |
return; |
|---|
| 673 |
#else |
|---|
| 674 |
int afterburner = 0; |
|---|
| 675 |
char cap[WLC_IOCTL_SMLEN]; |
|---|
| 676 |
char caps[WLC_IOCTL_SMLEN]; |
|---|
| 677 |
char *ifname; |
|---|
| 678 |
name = name + 11; |
|---|
| 679 |
if (!strncmp(name, "_wl0", 4)) |
|---|
| 680 |
ifname = nvram_safe_get("wl0_ifname"); |
|---|
| 681 |
else // "_wl1" |
|---|
| 682 |
ifname = nvram_safe_get("wl1_ifname"); |
|---|
| 683 |
char *next; |
|---|
| 684 |
|
|---|
| 685 |
if (wl_iovar_get(ifname, "cap", (void *)caps, WLC_IOCTL_SMLEN) |
|---|
| 686 |
== 0) { |
|---|
| 687 |
foreach(cap, caps, next) { |
|---|
| 688 |
if (!strcmp(cap, "afterburner")) |
|---|
| 689 |
afterburner = 1; |
|---|
| 690 |
} |
|---|
| 691 |
|
|---|
| 692 |
if (afterburner) |
|---|
| 693 |
return; |
|---|
| 694 |
} |
|---|
| 695 |
#endif |
|---|
| 696 |
} |
|---|
| 697 |
// end HAVE_AFTERBURNER |
|---|
| 698 |
// HAVE_HASWIFI |
|---|
| 699 |
if (!strcmp(name, "HASWIFI")) { |
|---|
| 700 |
if (haswifi()) |
|---|
| 701 |
return; |
|---|
| 702 |
} |
|---|
| 703 |
// end HAVE_HASWIFI |
|---|
| 704 |
if (!strcmp(name, "WET")) { |
|---|
| 705 |
if (getWET()) |
|---|
| 706 |
return; |
|---|
| 707 |
} |
|---|
| 708 |
if (!strcmp(name, "STA")) { |
|---|
| 709 |
if (getSTA()) |
|---|
| 710 |
return; |
|---|
| 711 |
} |
|---|
| 712 |
|
|---|
| 713 |
websWrite(wp, output); |
|---|
| 714 |
|
|---|
| 715 |
return; |
|---|
| 716 |
} |
|---|
| 717 |
|
|---|
| 718 |
/* |
|---|
| 719 |
* Example: |
|---|
| 720 |
* wan_proto=dhcp |
|---|
| 721 |
* <% nvram_match("wan_proto", "dhcp", "selected"); %> produces "selected" |
|---|
| 722 |
* <% nvram_match("wan_proto", "static", "selected"); %> does not produce |
|---|
| 723 |
*/ |
|---|
| 724 |
void ej_nvram_match(webs_t wp, int argc, char_t ** argv) |
|---|
| 725 |
{ |
|---|
| 726 |
|
|---|
| 727 |
#ifndef FASTWEB |
|---|
| 728 |
if (argc < 3) { |
|---|
| 729 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 730 |
return; |
|---|
| 731 |
} |
|---|
| 732 |
#endif |
|---|
| 733 |
|
|---|
| 734 |
if (nvram_match(argv[0], argv[1])) |
|---|
| 735 |
websWrite(wp, argv[2]); |
|---|
| 736 |
|
|---|
| 737 |
return; |
|---|
| 738 |
} |
|---|
| 739 |
|
|---|
| 740 |
/* |
|---|
| 741 |
* Example: |
|---|
| 742 |
* wan_proto=dhcp |
|---|
| 743 |
* <% nvram_invmatch("wan_proto", "dhcp", "disabled"); %> does not produce |
|---|
| 744 |
* <% nvram_invmatch("wan_proto", "static", "disabled"); %> produces "disabled" |
|---|
| 745 |
*/ |
|---|
| 746 |
void ej_nvram_invmatch(webs_t wp, int argc, char_t ** argv) |
|---|
| 747 |
{ |
|---|
| 748 |
char *name, *invmatch, *output; |
|---|
| 749 |
|
|---|
| 750 |
#ifdef FASTWEB |
|---|
| 751 |
ejArgs(argc, argv, "%s %s %s", &name, &invmatch, &output); |
|---|
| 752 |
#else |
|---|
| 753 |
if (ejArgs(argc, argv, "%s %s %s", &name, &invmatch, &output) < 3) { |
|---|
| 754 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 755 |
return; |
|---|
| 756 |
} |
|---|
| 757 |
#endif |
|---|
| 758 |
|
|---|
| 759 |
if (!nvram_match(name, invmatch)) |
|---|
| 760 |
websWrite(wp, output); |
|---|
| 761 |
|
|---|
| 762 |
return; |
|---|
| 763 |
} |
|---|
| 764 |
|
|---|
| 765 |
/* |
|---|
| 766 |
* static void ej_scroll (webs_t wp, int argc, char_t ** argv) { char *type; |
|---|
| 767 |
* int y; |
|---|
| 768 |
* |
|---|
| 769 |
* #ifdef FASTWEB ejArgs (argc, argv, "%s %d", &type, &y); #else if (ejArgs |
|---|
| 770 |
* (argc, argv, "%s %d", &type, &y) < 2) { websError (wp, 400, "Insufficient |
|---|
| 771 |
* args\n"); return; } #endif if (gozila_action) websWrite (wp, "%d", y); |
|---|
| 772 |
* else websWrite (wp, "0"); |
|---|
| 773 |
* |
|---|
| 774 |
* return; } |
|---|
| 775 |
*/ |
|---|
| 776 |
/* |
|---|
| 777 |
* Example: |
|---|
| 778 |
* filter_mac=00:12:34:56:78:00 00:87:65:43:21:00 |
|---|
| 779 |
* <% nvram_list("filter_mac", 1); %> produces "00:87:65:43:21:00" |
|---|
| 780 |
* <% nvram_list("filter_mac", 100); %> produces "" |
|---|
| 781 |
*/ |
|---|
| 782 |
void ej_nvram_list(webs_t wp, int argc, char_t ** argv) |
|---|
| 783 |
{ |
|---|
| 784 |
int which; |
|---|
| 785 |
char word[256], *next; |
|---|
| 786 |
|
|---|
| 787 |
#ifndef FASTWEB |
|---|
| 788 |
if (argc < 2) { |
|---|
| 789 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 790 |
return; |
|---|
| 791 |
} |
|---|
| 792 |
#endif |
|---|
| 793 |
which = atoi(argv[1]); |
|---|
| 794 |
char *list = nvram_safe_get(argv[0]); |
|---|
| 795 |
|
|---|
| 796 |
foreach(word, list, next) { |
|---|
| 797 |
if (which-- == 0) |
|---|
| 798 |
websWrite(wp, word); |
|---|
| 799 |
} |
|---|
| 800 |
|
|---|
| 801 |
return; |
|---|
| 802 |
} |
|---|
| 803 |
|
|---|
| 804 |
/* |
|---|
| 805 |
* Example: wan_dns = 1.2.3.4 10.20.30.40 15.25.35.45 get_dns_ip("wan_dns", |
|---|
| 806 |
* 1, 2); produces "20" |
|---|
| 807 |
*/ |
|---|
| 808 |
int get_dns_ip(char *name, int which, int count) |
|---|
| 809 |
{ |
|---|
| 810 |
static char word[256]; |
|---|
| 811 |
char *next; |
|---|
| 812 |
int ip; |
|---|
| 813 |
char *list = nvram_safe_get(name); |
|---|
| 814 |
|
|---|
| 815 |
foreach(word, list, next) { |
|---|
| 816 |
if (which-- == 0) { |
|---|
| 817 |
ip = get_single_ip(word, count); |
|---|
| 818 |
return ip; |
|---|
| 819 |
} |
|---|
| 820 |
} |
|---|
| 821 |
return 0; |
|---|
| 822 |
} |
|---|
| 823 |
|
|---|
| 824 |
/* |
|---|
| 825 |
* Example: wan_dns = 168.95.1.1 210.66.161.125 168.95.192.1 <% |
|---|
| 826 |
* get_dns_ip("wan_dns", "1", "2"); %> produces "161" <% |
|---|
| 827 |
* get_dns_ip("wan_dns", "2", "3"); %> produces "1" |
|---|
| 828 |
*/ |
|---|
| 829 |
void ej_get_dns_ip(webs_t wp, int argc, char_t ** argv) |
|---|
| 830 |
{ |
|---|
| 831 |
int which; |
|---|
| 832 |
char word[256], *next; |
|---|
| 833 |
|
|---|
| 834 |
#ifndef FASTWEB |
|---|
| 835 |
if (argc < 3) { |
|---|
| 836 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 837 |
return; |
|---|
| 838 |
} |
|---|
| 839 |
#endif |
|---|
| 840 |
which = atoi(argv[1]); |
|---|
| 841 |
char *list = nvram_safe_get(argv[0]); |
|---|
| 842 |
|
|---|
| 843 |
foreach(word, list, next) { |
|---|
| 844 |
if (which-- == 0) { |
|---|
| 845 |
websWrite(wp, "%d", get_single_ip(word, atoi(argv[2]))); |
|---|
| 846 |
return; |
|---|
| 847 |
} |
|---|
| 848 |
} |
|---|
| 849 |
|
|---|
| 850 |
websWrite(wp, "0"); // not find |
|---|
| 851 |
} |
|---|
| 852 |
|
|---|
| 853 |
void ej_get_http_prefix(webs_t wp, int argc, char_t ** argv) |
|---|
| 854 |
{ |
|---|
| 855 |
char http[10]; |
|---|
| 856 |
char ipaddr[20]; |
|---|
| 857 |
char port[10]; |
|---|
| 858 |
|
|---|
| 859 |
char *http_enable = websGetVar(wp, "http_enable", NULL); |
|---|
| 860 |
|
|---|
| 861 |
#ifdef HAVE_HTTPS |
|---|
| 862 |
char *https_enable = websGetVar(wp, "https_enable", NULL); |
|---|
| 863 |
|
|---|
| 864 |
if (do_ssl && http_enable == NULL && https_enable == NULL) { |
|---|
| 865 |
strcpy(http, "https"); |
|---|
| 866 |
} else if (do_ssl && http_enable && https_enable) { |
|---|
| 867 |
if (atoi(https_enable) && atoi(http_enable)) |
|---|
| 868 |
strcpy(http, "https"); |
|---|
| 869 |
else if (atoi(https_enable) && !atoi(http_enable)) |
|---|
| 870 |
strcpy(http, "https"); |
|---|
| 871 |
else // !atoi(https_enable) && atoi(http_enable) |
|---|
| 872 |
strcpy(http, "http"); |
|---|
| 873 |
} else if (do_ssl && !http_enable && !https_enable) { |
|---|
| 874 |
strcpy(http, "http"); |
|---|
| 875 |
} else if (!do_ssl && http_enable && https_enable) { |
|---|
| 876 |
if (atoi(https_enable) && atoi(http_enable)) |
|---|
| 877 |
strcpy(http, "http"); |
|---|
| 878 |
else if (atoi(https_enable) && !atoi(http_enable)) |
|---|
| 879 |
strcpy(http, "https"); |
|---|
| 880 |
else // !atoi(https_enable) && atoi(http_enable) |
|---|
| 881 |
strcpy(http, "http"); |
|---|
| 882 |
} else |
|---|
| 883 |
#endif |
|---|
| 884 |
strcpy(http, "http"); |
|---|
| 885 |
|
|---|
| 886 |
if (nvram_match("browser_method", "USE_LAN")) { // Use LAN to browser |
|---|
| 887 |
if (nvram_match("restore_defaults", "1") |
|---|
| 888 |
|| nvram_match("sv_restore_defaults", "1")) { |
|---|
| 889 |
|
|---|
| 890 |
strcpy(http, "http"); |
|---|
| 891 |
} else |
|---|
| 892 |
strcpy(ipaddr, nvram_safe_get("lan_ipaddr")); |
|---|
| 893 |
strcpy(port, ""); |
|---|
| 894 |
} else { |
|---|
| 895 |
|
|---|
| 896 |
if (nvram_match("wan_proto", "pptp")) |
|---|
| 897 |
strcpy(ipaddr, nvram_safe_get("pptp_get_ip")); |
|---|
| 898 |
else if (nvram_match("wan_proto", "l2tp")) |
|---|
| 899 |
strcpy(ipaddr, nvram_safe_get("l2tp_get_ip")); |
|---|
| 900 |
else |
|---|
| 901 |
strcpy(ipaddr, nvram_safe_get("wan_ipaddr")); |
|---|
| 902 |
|
|---|
| 903 |
sprintf(port, ":%s", nvram_safe_get("http_wanport")); |
|---|
| 904 |
} |
|---|
| 905 |
|
|---|
| 906 |
websWrite(wp, "%s://%s%s/", http, ipaddr, port); |
|---|
| 907 |
|
|---|
| 908 |
return; |
|---|
| 909 |
} |
|---|
| 910 |
|
|---|
| 911 |
void ej_get_mtu(webs_t wp, int argc, char_t ** argv) |
|---|
| 912 |
{ |
|---|
| 913 |
struct mtu_lists *mtu_list; |
|---|
| 914 |
char *type; |
|---|
| 915 |
char *proto = GOZILA_GET(wp, "wan_proto"); |
|---|
| 916 |
|
|---|
| 917 |
type = argv[1]; |
|---|
| 918 |
#ifndef FASTWEB |
|---|
| 919 |
if (argc < 1) { |
|---|
| 920 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 921 |
return; |
|---|
| 922 |
} |
|---|
| 923 |
#endif |
|---|
| 924 |
if (proto == NULL) |
|---|
| 925 |
proto = nvram_safe_get("wan_proto"); |
|---|
| 926 |
mtu_list = get_mtu(proto); |
|---|
| 927 |
|
|---|
| 928 |
if (!strcmp(type, "min")) |
|---|
| 929 |
websWrite(wp, "%s", mtu_list->min); |
|---|
| 930 |
else if (!strcmp(type, "max")) |
|---|
| 931 |
websWrite(wp, "%s", mtu_list->max); |
|---|
| 932 |
|
|---|
| 933 |
return; |
|---|
| 934 |
} |
|---|
| 935 |
|
|---|
| 936 |
void ej_show_forward(webs_t wp, int argc, char_t ** argv) |
|---|
| 937 |
// ej_show_forward(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, |
|---|
| 938 |
// char_t *url, char_t *path, char_t *query) |
|---|
| 939 |
{ |
|---|
| 940 |
int i; |
|---|
| 941 |
char *count; |
|---|
| 942 |
int c = 0; |
|---|
| 943 |
|
|---|
| 944 |
count = nvram_safe_get("forward_entries"); |
|---|
| 945 |
if (count == NULL || strlen(count) == 0 || (c = atoi(count)) <= 0) { |
|---|
| 946 |
// return -1; botho 07/03/06 add "- None -" if empty |
|---|
| 947 |
websWrite(wp, "<tr>\n"); |
|---|
| 948 |
websWrite(wp, |
|---|
| 949 |
"<td colspan=\"6\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n"); |
|---|
| 950 |
websWrite(wp, "</tr>\n"); |
|---|
| 951 |
} |
|---|
| 952 |
for (i = 0; i < c; i++) { |
|---|
| 953 |
websWrite(wp, "<tr><td>\n"); |
|---|
| 954 |
websWrite(wp, |
|---|
| 955 |
"<input maxlength=\"12\" size=\"12\" name=\"name%d\" onblur=\"valid_name(this,'Name')\" value=\"", |
|---|
| 956 |
i); |
|---|
| 957 |
port_forward_table(wp, "name", i); |
|---|
| 958 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 959 |
websWrite(wp, "<td>\n"); |
|---|
| 960 |
websWrite(wp, |
|---|
| 961 |
"<input class=\"num\" maxlength=\"5\" size=\"5\" name=\"from%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 962 |
i); |
|---|
| 963 |
port_forward_table(wp, "from", i); |
|---|
| 964 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 965 |
websWrite(wp, "<td>\n"); |
|---|
| 966 |
websWrite(wp, |
|---|
| 967 |
"<input class=\"num\" maxlength=\"5\" size=\"5\" name=\"to%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 968 |
i); |
|---|
| 969 |
port_forward_table(wp, "to", i); |
|---|
| 970 |
websWrite(wp, "\"/></td>\n"); |
|---|
| 971 |
websWrite(wp, "<td><select size=\"1\" name=\"pro%d\">\n", i); |
|---|
| 972 |
websWrite(wp, "<option value=\"tcp\" "); |
|---|
| 973 |
port_forward_table(wp, "sel_tcp", i); |
|---|
| 974 |
websWrite(wp, ">TCP</option>\n"); |
|---|
| 975 |
websWrite(wp, "<option value=\"udp\" "); |
|---|
| 976 |
port_forward_table(wp, "sel_udp", i); |
|---|
| 977 |
websWrite(wp, ">UDP</option>\n"); |
|---|
| 978 |
websWrite(wp, "<script type=\"text/javascript\">\n//<![CDATA[\n\ |
|---|
| 979 |
document.write(\"<option value=\\\"both\\\" "); |
|---|
| 980 |
port_forward_table(wp, "sel_both", i); |
|---|
| 981 |
websWrite(wp, " >\" + share.both + \"</option>\");\n\ |
|---|
| 982 |
\n//]]>\n</script>\n"); |
|---|
| 983 |
websWrite(wp, "</select></td>\n"); |
|---|
| 984 |
websWrite(wp, "<td>\n"); |
|---|
| 985 |
websWrite(wp, |
|---|
| 986 |
"<input class=\"num\" maxlength=\"15\" size=\"15\" name=\"ip%d\" value=\"", |
|---|
| 987 |
i); |
|---|
| 988 |
port_forward_table(wp, "ip", i); |
|---|
| 989 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 990 |
websWrite(wp, "<td>\n"); |
|---|
| 991 |
websWrite(wp, |
|---|
| 992 |
"<input type=\"checkbox\" value=\"on\" name=\"enable%d\" ", |
|---|
| 993 |
i); |
|---|
| 994 |
port_forward_table(wp, "enable", i); |
|---|
| 995 |
websWrite(wp, " /></td>\n"); |
|---|
| 996 |
websWrite(wp, "</tr>\n"); |
|---|
| 997 |
} |
|---|
| 998 |
return; |
|---|
| 999 |
} |
|---|
| 1000 |
|
|---|
| 1001 |
void ej_show_forward_spec(webs_t wp, int argc, char_t ** argv) |
|---|
| 1002 |
// ej_show_forward(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, |
|---|
| 1003 |
// char_t *url, char_t *path, char_t *query) |
|---|
| 1004 |
{ |
|---|
| 1005 |
int i; |
|---|
| 1006 |
char *count; |
|---|
| 1007 |
int c = 0; |
|---|
| 1008 |
|
|---|
| 1009 |
count = nvram_safe_get("forwardspec_entries"); |
|---|
| 1010 |
if (count == NULL || strlen(count) == 0 || (c = atoi(count)) <= 0) { |
|---|
| 1011 |
// return -1; botho 07/03/06 add "- None -" if empty |
|---|
| 1012 |
// websWrite (wp, "<tr></tr><tr></tr>\n"); |
|---|
| 1013 |
websWrite(wp, "<tr>\n"); |
|---|
| 1014 |
websWrite(wp, |
|---|
| 1015 |
"<td colspan=\"6\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n"); |
|---|
| 1016 |
websWrite(wp, "</tr>\n"); |
|---|
| 1017 |
} |
|---|
| 1018 |
for (i = 0; i < c; i++) { |
|---|
| 1019 |
websWrite(wp, "<tr><td>\n"); |
|---|
| 1020 |
websWrite(wp, |
|---|
| 1021 |
"<input maxlength=\"12\" size=\"12\" name=\"name%d\" onblur=\"valid_name(this,'Name')\" value=\"", |
|---|
| 1022 |
i); |
|---|
| 1023 |
port_forward_spec(wp, "name", i); |
|---|
| 1024 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1025 |
websWrite(wp, "<td>\n"); |
|---|
| 1026 |
websWrite(wp, |
|---|
| 1027 |
"<input class=\"num\" maxlength=\"5\" size=\"5\" name=\"from%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 1028 |
i); |
|---|
| 1029 |
port_forward_spec(wp, "from", i); |
|---|
| 1030 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1031 |
websWrite(wp, "<td><select size=\"1\" name=\"pro%d\">\n", i); |
|---|
| 1032 |
websWrite(wp, "<option value=\"tcp\" "); |
|---|
| 1033 |
port_forward_spec(wp, "sel_tcp", i); |
|---|
| 1034 |
websWrite(wp, ">TCP</option>\n"); |
|---|
| 1035 |
websWrite(wp, "<option value=\"udp\" "); |
|---|
| 1036 |
port_forward_spec(wp, "sel_udp", i); |
|---|
| 1037 |
websWrite(wp, ">UDP</option>\n"); |
|---|
| 1038 |
websWrite(wp, "<script type=\"text/javascript\">\n//<![CDATA[\n\ |
|---|
| 1039 |
document.write(\"<option value=\\\"both\\\" "); |
|---|
| 1040 |
port_forward_spec(wp, "sel_both", i); |
|---|
| 1041 |
websWrite(wp, " >\" + share.both + \"</option>\");\n\ |
|---|
| 1042 |
\n//]]>\n</script>\n"); |
|---|
| 1043 |
websWrite(wp, "</select></td>\n"); |
|---|
| 1044 |
websWrite(wp, "<td>\n"); |
|---|
| 1045 |
websWrite(wp, |
|---|
| 1046 |
"<input class=\"num\" maxlength=\"15\" size=\"15\" name=\"ip%d\" value=\"", |
|---|
| 1047 |
i); |
|---|
| 1048 |
port_forward_spec(wp, "ip", i); |
|---|
| 1049 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1050 |
websWrite(wp, "<td>\n"); |
|---|
| 1051 |
websWrite(wp, |
|---|
| 1052 |
"<input class=\"num\" maxlength=\"5\" size=\"5\" name=\"to%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 1053 |
i); |
|---|
| 1054 |
port_forward_spec(wp, "to", i); |
|---|
| 1055 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1056 |
websWrite(wp, "<td>\n"); |
|---|
| 1057 |
websWrite(wp, |
|---|
| 1058 |
"<input type=\"checkbox\" value=\"on\" name=\"enable%d\" ", |
|---|
| 1059 |
i); |
|---|
| 1060 |
port_forward_spec(wp, "enable", i); |
|---|
| 1061 |
websWrite(wp, " /></td>\n"); |
|---|
| 1062 |
websWrite(wp, "</tr>\n"); |
|---|
| 1063 |
} |
|---|
| 1064 |
return; |
|---|
| 1065 |
} |
|---|
| 1066 |
|
|---|
| 1067 |
void ej_show_triggering(webs_t wp, int argc, char_t ** argv) |
|---|
| 1068 |
{ |
|---|
| 1069 |
int i; |
|---|
| 1070 |
char *count; |
|---|
| 1071 |
int c = 0; |
|---|
| 1072 |
|
|---|
| 1073 |
count = nvram_safe_get("trigger_entries"); |
|---|
| 1074 |
if (count == NULL || strlen(count) == 0 || (c = atoi(count)) <= 0) { |
|---|
| 1075 |
websWrite(wp, "<tr>\n"); |
|---|
| 1076 |
websWrite(wp, |
|---|
| 1077 |
"<td colspan=\"6\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n"); |
|---|
| 1078 |
websWrite(wp, "</tr>\n"); |
|---|
| 1079 |
} |
|---|
| 1080 |
for (i = 0; i < c; i++) { |
|---|
| 1081 |
websWrite(wp, "<tr>\n"); |
|---|
| 1082 |
websWrite(wp, |
|---|
| 1083 |
"<td><input maxlength=\"12\" size=\"12\" name=\"name%d\" onblur=\"valid_name(this,'Name')\" value=\"", |
|---|
| 1084 |
i); |
|---|
| 1085 |
port_trigger_table(wp, "name", i); |
|---|
| 1086 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1087 |
websWrite(wp, |
|---|
| 1088 |
"<td><input class=\"num\" maxlength=\"5\" size=\"5\" name=\"i_from%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 1089 |
i); |
|---|
| 1090 |
port_trigger_table(wp, "i_from", i); |
|---|
| 1091 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1092 |
websWrite(wp, |
|---|
| 1093 |
"<td><input class=\"num\" maxlength=\"5\" size=\"5\" name=\"i_to%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 1094 |
i); |
|---|
| 1095 |
port_trigger_table(wp, "i_to", i); |
|---|
| 1096 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1097 |
websWrite(wp, "<td><select size=\"1\" name=\"pro%d\">\n", i); |
|---|
| 1098 |
websWrite(wp, "<option value=\"tcp\" "); |
|---|
| 1099 |
port_trigger_table(wp, "sel_tcp", i); |
|---|
| 1100 |
websWrite(wp, ">TCP</option>\n"); |
|---|
| 1101 |
websWrite(wp, "<option value=\"udp\" "); |
|---|
| 1102 |
port_trigger_table(wp, "sel_udp", i); |
|---|
| 1103 |
websWrite(wp, ">UDP</option>\n"); |
|---|
| 1104 |
websWrite(wp, "<script type=\"text/javascript\">\n//<![CDATA[\n\ |
|---|
| 1105 |
document.write(\"<option value=\\\"both\\\" "); |
|---|
| 1106 |
port_trigger_table(wp, "sel_both", i); |
|---|
| 1107 |
websWrite(wp, " >\" + share.both + \"</option>\");\n\ |
|---|
| 1108 |
\n//]]>\n</script>\n"); |
|---|
| 1109 |
websWrite(wp, "</select></td>\n"); |
|---|
| 1110 |
websWrite(wp, |
|---|
| 1111 |
"<td><input class=\"num\" maxlength=\"5\" size=\"5\" name=\"o_from%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 1112 |
i); |
|---|
| 1113 |
port_trigger_table(wp, "o_from", i); |
|---|
| 1114 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1115 |
websWrite(wp, |
|---|
| 1116 |
"<td><input class=\"num\" maxlength=\"5\" size=\"5\" name=\"o_to%d\" onblur=\"valid_range(this,1,65535,'Port')\" value=\"", |
|---|
| 1117 |
i); |
|---|
| 1118 |
port_trigger_table(wp, "o_to", i); |
|---|
| 1119 |
websWrite(wp, "\" /></td>\n"); |
|---|
| 1120 |
websWrite(wp, |
|---|
| 1121 |
"<td><input type=\"checkbox\" value=\"on\" name=\"enable%d\" ", |
|---|
| 1122 |
i); |
|---|
| 1123 |
port_trigger_table(wp, "enable", i); |
|---|
| 1124 |
websWrite(wp, " /></td>\n"); |
|---|
| 1125 |
websWrite(wp, "</tr>\n"); |
|---|
| 1126 |
} |
|---|
| 1127 |
return; |
|---|
| 1128 |
} |
|---|
| 1129 |
|
|---|
| 1130 |
// SEG DD-WRT addition |
|---|
| 1131 |
void ej_show_styles(webs_t wp, int argc, char_t ** argv) |
|---|
| 1132 |
{ |
|---|
| 1133 |
// <option value="blue" <% nvram_selected("router_style", "blue"); |
|---|
| 1134 |
// %>>Blue</option> |
|---|
| 1135 |
DIR *directory; |
|---|
| 1136 |
char buf[256]; |
|---|
| 1137 |
|
|---|
| 1138 |
directory = opendir("/www/style"); |
|---|
| 1139 |
struct dirent *entry; |
|---|
| 1140 |
|
|---|
| 1141 |
while ((entry = readdir(directory)) != NULL) { |
|---|
| 1142 |
sprintf(buf, "style/%s/style.css", entry->d_name); |
|---|
| 1143 |
FILE *web = getWebsFile(buf); |
|---|
| 1144 |
|
|---|
| 1145 |
if (web == NULL) { |
|---|
| 1146 |
sprintf(buf, "/www/style/%s/style.css", entry->d_name); |
|---|
| 1147 |
FILE *test = fopen(buf, "rb"); |
|---|
| 1148 |
|
|---|
| 1149 |
if (test == NULL) |
|---|
| 1150 |
continue; |
|---|
| 1151 |
fclose(test); |
|---|
| 1152 |
} |
|---|
| 1153 |
fclose(web); |
|---|
| 1154 |
|
|---|
| 1155 |
websWrite(wp, "<option value=\"%s\" %s>%s</option>\n", |
|---|
| 1156 |
entry->d_name, nvram_match("router_style", |
|---|
| 1157 |
entry->d_name) ? |
|---|
| 1158 |
"selected=\"selected\"" : "", entry->d_name); |
|---|
| 1159 |
} |
|---|
| 1160 |
closedir(directory); |
|---|
| 1161 |
return; |
|---|
| 1162 |
} |
|---|
| 1163 |
|
|---|
| 1164 |
#ifdef HAVE_LANGUAGE |
|---|
| 1165 |
// extern websRomPageIndexType websRomPageIndex[]; |
|---|
| 1166 |
void ej_show_languages(webs_t wp, int argc, char_t ** argv) |
|---|
| 1167 |
{ |
|---|
| 1168 |
char buf[256]; |
|---|
| 1169 |
|
|---|
| 1170 |
websWrite(wp, "<script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 1171 |
int i = 0; |
|---|
| 1172 |
|
|---|
| 1173 |
while (websRomPageIndex[i].path != NULL) { |
|---|
| 1174 |
cprintf("checking %s\n", websRomPageIndex[i].path); |
|---|
| 1175 |
if (!strncmp |
|---|
| 1176 |
(websRomPageIndex[i].path, "lang_pack/", |
|---|
| 1177 |
strlen("lang_pack/"))) { |
|---|
| 1178 |
cprintf("found language\n"); |
|---|
| 1179 |
if (strlen(websRomPageIndex[i].path) < 14) |
|---|
| 1180 |
continue; |
|---|
| 1181 |
strcpy(buf, websRomPageIndex[i].path); |
|---|
| 1182 |
char *mybuf = &buf[strlen("lang_pack/")]; |
|---|
| 1183 |
|
|---|
| 1184 |
mybuf[strlen(mybuf) - 3] = 0; // strip .js |
|---|
| 1185 |
websWrite(wp, |
|---|
| 1186 |
"document.write(\"<option value=\\\"%s\\\" %s >\" + management.lang_%s + \"</option>\");\n", |
|---|
| 1187 |
mybuf, nvram_match("language", |
|---|
| 1188 |
mybuf) ? |
|---|
| 1189 |
"selected=\\\"selected\\\"" : "", mybuf); |
|---|
| 1190 |
} |
|---|
| 1191 |
i++; |
|---|
| 1192 |
} |
|---|
| 1193 |
websWrite(wp, "//]]>\n</script>\n"); |
|---|
| 1194 |
return; |
|---|
| 1195 |
} |
|---|
| 1196 |
#endif |
|---|
| 1197 |
|
|---|
| 1198 |
static char *directories[] = { |
|---|
| 1199 |
"/etc/config", |
|---|
| 1200 |
"/jffs/etc/config", |
|---|
| 1201 |
"/mmc/etc/config" |
|---|
| 1202 |
}; |
|---|
| 1203 |
|
|---|
| 1204 |
void ej_show_modules(webs_t wp, int argc, char_t ** argv) |
|---|
| 1205 |
{ |
|---|
| 1206 |
char buf[256]; |
|---|
| 1207 |
struct dirent *entry; |
|---|
| 1208 |
DIR *directory; |
|---|
| 1209 |
|
|---|
| 1210 |
// display modules |
|---|
| 1211 |
int idx; |
|---|
| 1212 |
|
|---|
| 1213 |
for (idx = 0; idx < 3; idx++) { |
|---|
| 1214 |
directory = opendir(directories[idx]); |
|---|
| 1215 |
if (directory == NULL) |
|---|
| 1216 |
continue; |
|---|
| 1217 |
// list all files in this directory |
|---|
| 1218 |
while ((entry = readdir(directory)) != NULL) { |
|---|
| 1219 |
if (argc > 0) { |
|---|
| 1220 |
if (endswith(entry->d_name, argv[0])) { |
|---|
| 1221 |
#ifdef HAVE_ERC |
|---|
| 1222 |
if (strcmp(entry->d_name, "base.webconfig") && !wp->userid) //show only base.webconfig for this user and nothing else |
|---|
| 1223 |
{ |
|---|
| 1224 |
continue; |
|---|
| 1225 |
} |
|---|
| 1226 |
#endif |
|---|
| 1227 |
sprintf(buf, "%s/%s", directories[idx], |
|---|
| 1228 |
entry->d_name); |
|---|
| 1229 |
do_ej(NULL, buf, wp, NULL); |
|---|
| 1230 |
} |
|---|
| 1231 |
} else { |
|---|
| 1232 |
if (endswith(entry->d_name, ".webconfig")) { |
|---|
| 1233 |
sprintf(buf, "%s/%s", directories[idx], |
|---|
| 1234 |
entry->d_name); |
|---|
| 1235 |
do_ej(NULL, buf, wp, NULL); |
|---|
| 1236 |
} |
|---|
| 1237 |
} |
|---|
| 1238 |
} |
|---|
| 1239 |
closedir(directory); |
|---|
| 1240 |
} |
|---|
| 1241 |
return; |
|---|
| 1242 |
} |
|---|
| 1243 |
|
|---|
| 1244 |
void ej_get_sysmodel(webs_t wp, int argc, char_t ** argv) |
|---|
| 1245 |
{ |
|---|
| 1246 |
#ifdef HAVE_XIOCOM |
|---|
| 1247 |
websWrite(wp, "XWR"); |
|---|
| 1248 |
#else |
|---|
| 1249 |
websWrite(wp, "%s", nvram_safe_get("DD_BOARD")); |
|---|
| 1250 |
#endif |
|---|
| 1251 |
} |
|---|
| 1252 |
|
|---|
| 1253 |
void ej_get_totaltraff(webs_t wp, int argc, char_t ** argv) |
|---|
| 1254 |
{ |
|---|
| 1255 |
char *type; |
|---|
| 1256 |
static char wanface[32]; |
|---|
| 1257 |
char line[256]; |
|---|
| 1258 |
unsigned long rcvd, sent, megcounti, megcounto; |
|---|
| 1259 |
FILE *in; |
|---|
| 1260 |
|
|---|
| 1261 |
#ifndef FASTWEB |
|---|
| 1262 |
if (argc < 1) { |
|---|
| 1263 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 1264 |
return; |
|---|
| 1265 |
} |
|---|
| 1266 |
#endif |
|---|
| 1267 |
type = argv[0]; |
|---|
| 1268 |
|
|---|
| 1269 |
if (!nvram_match("ttraff_enable", "1")) |
|---|
| 1270 |
return; |
|---|
| 1271 |
|
|---|
| 1272 |
if (nvram_match("ttraff_iface", "") || !nvram_get("ttraff_iface")) |
|---|
| 1273 |
strncpy(wanface, get_wan_face(), sizeof(wanface)); |
|---|
| 1274 |
else |
|---|
| 1275 |
strncpy(wanface, nvram_safe_get("ttraff_iface"), |
|---|
| 1276 |
sizeof(wanface)); |
|---|
| 1277 |
|
|---|
| 1278 |
in = fopen("/proc/net/dev", "rb"); |
|---|
| 1279 |
if (in == NULL) |
|---|
| 1280 |
return; |
|---|
| 1281 |
|
|---|
| 1282 |
while (fgets(line, sizeof(line), in) != NULL) { |
|---|
| 1283 |
int ifl = 0; |
|---|
| 1284 |
|
|---|
| 1285 |
if (!strchr(line, ':')) |
|---|
| 1286 |
continue; |
|---|
| 1287 |
while (line[ifl] != ':') |
|---|
| 1288 |
ifl++; |
|---|
| 1289 |
line[ifl] = 0; /* interface */ |
|---|
| 1290 |
if (strstr(line, wanface)) { |
|---|
| 1291 |
sscanf(line + ifl + 1, |
|---|
| 1292 |
"%lu %*ld %*ld %*ld %*ld %*ld %*ld %*ld %lu %*ld %*ld %*ld %*ld %*ld %*ld %*ld", |
|---|
| 1293 |
&rcvd, &sent); |
|---|
| 1294 |
|
|---|
| 1295 |
} |
|---|
| 1296 |
} |
|---|
| 1297 |
|
|---|
| 1298 |
fclose(in); |
|---|
| 1299 |
|
|---|
| 1300 |
rcvd >>= 20; // output in MBytes |
|---|
| 1301 |
sent >>= 20; |
|---|
| 1302 |
|
|---|
| 1303 |
if ((in = fopen("/tmp/.megc", "r")) != NULL) { |
|---|
| 1304 |
fgets(line, sizeof(line), in); |
|---|
| 1305 |
sscanf(line, "%lu:%lu", &megcounti, &megcounto); |
|---|
| 1306 |
rcvd += megcounti; |
|---|
| 1307 |
sent += megcounto; |
|---|
| 1308 |
fclose(in); |
|---|
| 1309 |
} |
|---|
| 1310 |
|
|---|
| 1311 |
if (!strcmp(type, "in")) { |
|---|
| 1312 |
websWrite(wp, "%lu", rcvd); // output in MBytes |
|---|
| 1313 |
} else if (!strcmp(type, "out")) { |
|---|
| 1314 |
websWrite(wp, "%lu", sent); |
|---|
| 1315 |
} |
|---|
| 1316 |
return; |
|---|
| 1317 |
} |
|---|
| 1318 |
|
|---|
| 1319 |
void show_bwif(webs_t wp, char *ifname, char *name) |
|---|
| 1320 |
{ |
|---|
| 1321 |
websWrite(wp, "<h2>%s - %s</h2>\n", live_translate("status_band.h2"), |
|---|
| 1322 |
name); |
|---|
| 1323 |
websWrite(wp, "<fieldset>\n"); |
|---|
| 1324 |
websWrite(wp, |
|---|
| 1325 |
"<iframe src=\"/graph_if.svg?%s\" width=\"555\" height=\"275\" frameborder=\"0\" type=\"image/svg+xml\">\n", |
|---|
| 1326 |
ifname); |
|---|
| 1327 |
websWrite(wp, "</iframe>\n"); |
|---|
| 1328 |
websWrite(wp, "</fieldset>\n"); |
|---|
| 1329 |
websWrite(wp, "<br />\n"); |
|---|
| 1330 |
} |
|---|
| 1331 |
|
|---|
| 1332 |
void ej_show_bandwidth(webs_t wp, int argc, char_t ** argv) |
|---|
| 1333 |
{ |
|---|
| 1334 |
show_bwif(wp, nvram_safe_get("lan_ifname"), "LAN"); |
|---|
| 1335 |
if (!nvram_match("wan_proto", "disabled")) { |
|---|
| 1336 |
if (strlen(nvram_safe_get("wan_iface")) > 0) { |
|---|
| 1337 |
show_bwif(wp, nvram_safe_get("wan_iface"), "WAN"); |
|---|
| 1338 |
} else { |
|---|
| 1339 |
if (strlen(nvram_safe_get("wan_ifname")) > 0) { |
|---|
| 1340 |
show_bwif(wp, nvram_safe_get("wan_ifname"), |
|---|
| 1341 |
"WAN"); |
|---|
| 1342 |
} |
|---|
| 1343 |
} |
|---|
| 1344 |
if (nvram_match("dtag_vlan8", "1")) |
|---|
| 1345 |
show_bwif(wp, "eth0.0008", "IPTV"); |
|---|
| 1346 |
|
|---|
| 1347 |
} |
|---|
| 1348 |
#ifdef HAVE_MADWIFI |
|---|
| 1349 |
char var[80]; |
|---|
| 1350 |
char *next; |
|---|
| 1351 |
int c = getdevicecount(); |
|---|
| 1352 |
int i; |
|---|
| 1353 |
|
|---|
| 1354 |
for (i = 0; i < c; i++) { |
|---|
| 1355 |
char dev[32]; |
|---|
| 1356 |
|
|---|
| 1357 |
sprintf(dev, "ath%d", i); |
|---|
| 1358 |
char name[32]; |
|---|
| 1359 |
|
|---|
| 1360 |
sprintf(name, "%s (%s)", live_translate("share.wireless"), dev); |
|---|
| 1361 |
show_bwif(wp, dev, name); |
|---|
| 1362 |
char *vifs = nvram_nget("%s_vifs", dev); |
|---|
| 1363 |
|
|---|
| 1364 |
if (vifs == NULL) |
|---|
| 1365 |
continue; |
|---|
| 1366 |
foreach(var, vifs, next) { |
|---|
| 1367 |
sprintf(name, "%s (%s)", |
|---|
| 1368 |
live_translate("share.wireless"), var); |
|---|
| 1369 |
show_bwif(wp, var, name); |
|---|
| 1370 |
} |
|---|
| 1371 |
int s; |
|---|
| 1372 |
|
|---|
| 1373 |
for (s = 1; s <= 10; s++) { |
|---|
| 1374 |
char *wdsdev; |
|---|
| 1375 |
|
|---|
| 1376 |
wdsdev = nvram_nget("%s_wds%d_if", dev, s); |
|---|
| 1377 |
if (strlen(wdsdev) == 0) |
|---|
| 1378 |
continue; |
|---|
| 1379 |
if (nvram_nmatch("0", "%s_wds%d_enable", dev, s)) |
|---|
| 1380 |
continue; |
|---|
| 1381 |
sprintf(name, "%s (%s)", |
|---|
| 1382 |
live_translate("share.wireless"), wdsdev); |
|---|
| 1383 |
show_bwif(wp, wdsdev, name); |
|---|
| 1384 |
} |
|---|
| 1385 |
|
|---|
| 1386 |
} |
|---|
| 1387 |
|
|---|
| 1388 |
#else |
|---|
| 1389 |
char name[32]; |
|---|
| 1390 |
int cnt = get_wl_instances(); |
|---|
| 1391 |
int c; |
|---|
| 1392 |
|
|---|
| 1393 |
for (c = 0; c < cnt; c++) { |
|---|
| 1394 |
sprintf(name, "%s (wl%d)", live_translate("share.wireless"), c); |
|---|
| 1395 |
show_bwif(wp, get_wl_instance_name(c), name); |
|---|
| 1396 |
} |
|---|
| 1397 |
#endif |
|---|
| 1398 |
#ifdef HAVE_WAVESAT |
|---|
| 1399 |
char name[32]; |
|---|
| 1400 |
|
|---|
| 1401 |
sprintf(name, "%s", live_translate("wl_wimax.titl")); |
|---|
| 1402 |
show_bwif(wp, "ofdm", name); |
|---|
| 1403 |
#endif |
|---|
| 1404 |
} |
|---|
| 1405 |
|
|---|
| 1406 |
void ej_do_menu(webs_t wp, int argc, char_t ** argv) |
|---|
| 1407 |
{ |
|---|
| 1408 |
char *mainmenu, *submenu; |
|---|
| 1409 |
|
|---|
| 1410 |
#ifndef FASTWEB |
|---|
| 1411 |
if (argc < 2) { |
|---|
| 1412 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 1413 |
return; |
|---|
| 1414 |
} |
|---|
| 1415 |
#endif |
|---|
| 1416 |
mainmenu = argv[0]; |
|---|
| 1417 |
submenu = argv[1]; |
|---|
| 1418 |
|
|---|
| 1419 |
int vlan_supp = check_vlan_support(); |
|---|
| 1420 |
|
|---|
| 1421 |
#ifdef HAVE_SPUTNIK_APD |
|---|
| 1422 |
int sputnik = nvram_match("apd_enable", "1"); |
|---|
| 1423 |
#else |
|---|
| 1424 |
int sputnik = 0; |
|---|
| 1425 |
#endif |
|---|
| 1426 |
int openvpn = nvram_match("openvpn_enable", |
|---|
| 1427 |
"1") | nvram_match("openvpncl_enable", |
|---|
| 1428 |
"1"); |
|---|
| 1429 |
int auth = nvram_match("status_auth", "1"); |
|---|
| 1430 |
int registered = 1; |
|---|
| 1431 |
#ifdef HAVE_REGISTER |
|---|
| 1432 |
if (!isregistered_real()) |
|---|
| 1433 |
registered = 0; |
|---|
| 1434 |
int cpeonly = iscpe(); |
|---|
| 1435 |
#else |
|---|
| 1436 |
int cpeonly = 0; |
|---|
| 1437 |
#endif |
|---|
| 1438 |
|
|---|
| 1439 |
#ifdef HAVE_MADWIFI |
|---|
| 1440 |
#ifdef HAVE_NOWIFI |
|---|
| 1441 |
int wifi = 0; |
|---|
| 1442 |
#else |
|---|
| 1443 |
int wifi = haswifi(); |
|---|
| 1444 |
#endif |
|---|
| 1445 |
#endif |
|---|
| 1446 |
#ifdef HAVE_MADWIFI |
|---|
| 1447 |
int wimaxwifi = 0; |
|---|
| 1448 |
#endif |
|---|
| 1449 |
#ifdef HAVE_ERC |
|---|
| 1450 |
static char menu_s[8][11][32] = |
|---|
| 1451 |
{ {"index.asp", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1452 |
{"Wireless_Basic.asp", "WL_WPATable.asp", "", "", "", "", "", "", "", |
|---|
| 1453 |
"", ""}, |
|---|
| 1454 |
{"ForwardSpec.asp", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1455 |
{"Management.asp", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1456 |
{"", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1457 |
{"", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1458 |
{"", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1459 |
{"", "", "", "", "", "", "", "", "", "", ""} |
|---|
| 1460 |
}; |
|---|
| 1461 |
/* |
|---|
| 1462 |
* real name is bmenu.menuname[i][j] |
|---|
| 1463 |
*/ |
|---|
| 1464 |
static char menuname_s[8][12][32] = |
|---|
| 1465 |
{ {"setup", "setupbasic", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1466 |
{"wireless", "wirelessBasic", "wirelessSecurity", "", "", "", "", "", |
|---|
| 1467 |
"", "", "", ""}, |
|---|
| 1468 |
{"applications", "applicationspforwarding", "", "", "", "", "", "", "", |
|---|
| 1469 |
"", "", ""}, |
|---|
| 1470 |
{"admin", "adminManagement", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1471 |
{"", "", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1472 |
{"", "", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1473 |
{"", "", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1474 |
{"", "", "", "", "", "", "", "", "", "", "", ""} |
|---|
| 1475 |
}; |
|---|
| 1476 |
|
|---|
| 1477 |
#endif |
|---|
| 1478 |
|
|---|
| 1479 |
static char menu_t[8][11][32] = |
|---|
| 1480 |
{ {"index.asp", "DDNS.asp", "WanMAC.asp", "Routing.asp", "Vlan.asp", |
|---|
| 1481 |
"Networking.asp", "", "", "", "", ""}, |
|---|
| 1482 |
{"Wireless_Basic.asp", "SuperChannel.asp", "WiMAX.asp", |
|---|
| 1483 |
"Wireless_radauth.asp", "WL_WPATable.asp", "Wireless_MAC.asp", |
|---|
| 1484 |
"Wireless_Advanced.asp", "Wireless_WDS.asp", "", "", ""}, |
|---|
| 1485 |
{"Services.asp", "PPPoE_Server.asp", "PPTP.asp", "USB.asp", "NAS.asp", |
|---|
| 1486 |
"Hotspot.asp", "Milkfish.asp", "eop-tunnel.asp", "AnchorFree.asp", "", |
|---|
| 1487 |
""}, |
|---|
| 1488 |
{"Firewall.asp", "VPN.asp", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1489 |
{"Filters.asp", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1490 |
{"ForwardSpec.asp", "Forward.asp", "Triggering.asp", "UPnP.asp", |
|---|
| 1491 |
"DMZ.asp", "QoS.asp", "P2P.asp", "", "", "", ""}, |
|---|
| 1492 |
{"Management.asp", "Alive.asp", "Diagnostics.asp", "Wol.asp", |
|---|
| 1493 |
"Factory_Defaults.asp", "Upgrade.asp", "config.asp", "", "", "", ""}, |
|---|
| 1494 |
{"Status_Router.asp", "Status_Internet.asp", "Status_Lan.asp", |
|---|
| 1495 |
"Status_Wireless.asp", "Status_SputnikAPD.asp", "Status_OpenVPN.asp", |
|---|
| 1496 |
"Status_Bandwidth.asp", "Info.htm", "register.asp", "", ""} |
|---|
| 1497 |
}; |
|---|
| 1498 |
/* |
|---|
| 1499 |
* real name is bmenu.menuname[i][j] |
|---|
| 1500 |
*/ |
|---|
| 1501 |
static char menuname_t[8][12][32] = |
|---|
| 1502 |
{ {"setup", "setupbasic", "setupddns", "setupmacclone", |
|---|
| 1503 |
"setuprouting", "setupvlan", "networking", "", "", "", "", ""}, |
|---|
| 1504 |
{"wireless", "wirelessBasic", "wirelessSuperchannel", "wimax", |
|---|
| 1505 |
"wirelessRadius", "wirelessSecurity", "wirelessMac", |
|---|
| 1506 |
"wirelessAdvanced", "wirelessWds", "", "", ""}, |
|---|
| 1507 |
{"services", "servicesServices", "servicesPppoesrv", "servicesPptp", |
|---|
| 1508 |
"servicesUSB", "servicesNAS", "servicesHotspot", "servicesMilkfish", |
|---|
| 1509 |
"setupeop", "servicesAnchorFree", "", ""}, |
|---|
| 1510 |
{"security", "firwall", "vpn", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1511 |
{"accrestriction", "webaccess", "", "", "", "", "", "", "", "", "", ""}, |
|---|
| 1512 |
{"applications", "applicationspforwarding", "applicationsprforwarding", |
|---|
| 1513 |
"applicationsptriggering", "applicationsUpnp", "applicationsDMZ", |
|---|
| 1514 |
"applicationsQoS", "applicationsP2P", "", "", "", ""}, |
|---|
| 1515 |
{"admin", "adminManagement", "adminAlive", "adminDiag", "adminWol", |
|---|
| 1516 |
"adminFactory", "adminUpgrade", "adminBackup", "", "", "", ""}, |
|---|
| 1517 |
{"statu", "statuRouter", "statuInet", "statuLAN", "statuWLAN", |
|---|
| 1518 |
"statuSputnik", "statuVPN", "statuBand", "statuSysInfo", |
|---|
| 1519 |
"statuActivate", "", ""} |
|---|
| 1520 |
}; |
|---|
| 1521 |
|
|---|
| 1522 |
static char menu[8][11][32]; |
|---|
| 1523 |
static char menuname[8][12][32]; |
|---|
| 1524 |
memcpy(menu, menu_t, 8 * 11 * 32); |
|---|
| 1525 |
memcpy(menuname, menuname_t, 8 * 12 * 32); |
|---|
| 1526 |
#ifdef HAVE_ERC |
|---|
| 1527 |
if (!wp->userid) { |
|---|
| 1528 |
memcpy(menu, menu_s, 8 * 11 * 32); |
|---|
| 1529 |
memcpy(menuname, menuname_s, 8 * 12 * 32); |
|---|
| 1530 |
} |
|---|
| 1531 |
#endif |
|---|
| 1532 |
//fprintf(stderr,"generate menu content\n"); |
|---|
| 1533 |
#ifdef HAVE_MADWIFI |
|---|
| 1534 |
// fill up WDS |
|---|
| 1535 |
int ifcount = getifcount("wifi"); |
|---|
| 1536 |
int a; |
|---|
| 1537 |
|
|---|
| 1538 |
for (a = 0; a < ifcount; a++) { |
|---|
| 1539 |
sprintf(&menu[1][a + 7][0], "Wireless_WDS-ath%d.asp", a); |
|---|
| 1540 |
if (ifcount == 1) |
|---|
| 1541 |
sprintf(&menuname[1][a + 8][0], "wirelessWds"); |
|---|
| 1542 |
else |
|---|
| 1543 |
sprintf(&menuname[1][a + 8][0], "wirelessWds%d", a); |
|---|
| 1544 |
} |
|---|
| 1545 |
#else |
|---|
| 1546 |
#ifdef HAVE_ERC |
|---|
| 1547 |
if (wp->userid) { |
|---|
| 1548 |
#endif |
|---|
| 1549 |
|
|---|
| 1550 |
int ifcount = get_wl_instances(); |
|---|
| 1551 |
int a; |
|---|
| 1552 |
|
|---|
| 1553 |
for (a = 0; a < ifcount; a++) { |
|---|
| 1554 |
sprintf(&menu[1][a * 2 + 6][0], |
|---|
| 1555 |
"Wireless_Advanced-wl%d.asp", a); |
|---|
| 1556 |
sprintf(&menu[1][a * 2 + 7][0], "Wireless_WDS-wl%d.asp", |
|---|
| 1557 |
a); |
|---|
| 1558 |
if (ifcount == 1) { |
|---|
| 1559 |
sprintf(&menuname[1][a * 2 + 7][0], |
|---|
| 1560 |
"wirelessAdvanced"); |
|---|
| 1561 |
sprintf(&menuname[1][a * 2 + 8][0], |
|---|
| 1562 |
"wirelessWds"); |
|---|
| 1563 |
} else { |
|---|
| 1564 |
sprintf(&menuname[1][a * 2 + 7][0], |
|---|
| 1565 |
"wirelessAdvancedwl%d", a); |
|---|
| 1566 |
sprintf(&menuname[1][a * 2 + 8][0], |
|---|
| 1567 |
"wirelessWdswl%d", a); |
|---|
| 1568 |
} |
|---|
| 1569 |
} |
|---|
| 1570 |
#ifdef HAVE_ERC |
|---|
| 1571 |
} |
|---|
| 1572 |
#endif |
|---|
| 1573 |
#endif |
|---|
| 1574 |
//fprintf(stderr,"generate menu header content\n"); |
|---|
| 1575 |
|
|---|
| 1576 |
int i, j; |
|---|
| 1577 |
|
|---|
| 1578 |
websWrite(wp, "<div id=\"menu\">\n"); |
|---|
| 1579 |
websWrite(wp, " <div id=\"menuMain\">\n"); |
|---|
| 1580 |
websWrite(wp, " <ul id=\"menuMainList\">\n"); |
|---|
| 1581 |
#ifdef HAVE_WAVESAT |
|---|
| 1582 |
wimaxwifi = 1; |
|---|
| 1583 |
#endif |
|---|
| 1584 |
for (i = 0; i < 8; i++) { |
|---|
| 1585 |
if (strlen(menu[i][0]) == 0) |
|---|
| 1586 |
continue; |
|---|
| 1587 |
#ifdef HAVE_MADWIFI |
|---|
| 1588 |
if (!wifi && !wimaxwifi |
|---|
| 1589 |
&& !strcmp(menu[i][0], "Wireless_Basic.asp")) |
|---|
| 1590 |
i++; |
|---|
| 1591 |
#endif |
|---|
| 1592 |
//fprintf(stderr,"generate menu %s\n",menu[i][0]); |
|---|
| 1593 |
if (!strcmp(menu[i][0], mainmenu)) { |
|---|
| 1594 |
#ifdef HAVE_MADWIFI |
|---|
| 1595 |
if (!wifi && wimaxwifi |
|---|
| 1596 |
&& !strcmp(menu[i][0], "Wireless_Basic.asp")) |
|---|
| 1597 |
websWrite(wp, |
|---|
| 1598 |
" <li class=\"current\"><span><script type=\"text/javascript\">Capture(bmenu.wimax)</script></span>\n"); |
|---|
| 1599 |
else |
|---|
| 1600 |
#endif |
|---|
| 1601 |
websWrite(wp, |
|---|
| 1602 |
" <li class=\"current\"><span><script type=\"text/javascript\">Capture(bmenu.%s)</script></span>\n", |
|---|
| 1603 |
menuname[i][0]); |
|---|
| 1604 |
websWrite(wp, " <div id=\"menuSub\">\n"); |
|---|
| 1605 |
websWrite(wp, " <ul id=\"menuSubList\">\n"); |
|---|
| 1606 |
|
|---|
| 1607 |
for (j = 0; j < 11; j++) { |
|---|
| 1608 |
|
|---|
| 1609 |
#ifdef HAVE_MADWIFI |
|---|
| 1610 |
if (!wifi |
|---|
| 1611 |
&& !strncmp(menu[i][j], |
|---|
| 1612 |
"Wireless_Basic.asp", 8)) |
|---|
| 1613 |
j++; |
|---|
| 1614 |
#ifndef HAVE_SUPERCHANNEL |
|---|
| 1615 |
if (!strcmp(menu[i][j], "SuperChannel.asp")) // jump over |
|---|
| 1616 |
// PPTP in |
|---|
| 1617 |
// micro |
|---|
| 1618 |
// build |
|---|
| 1619 |
j++; |
|---|
| 1620 |
#else |
|---|
| 1621 |
if (!strcmp(menu[i][j], "SuperChannel.asp") && (issuperchannel() || !wifi)) // jump |
|---|
| 1622 |
// over |
|---|
| 1623 |
// PPTP |
|---|
| 1624 |
// in |
|---|
| 1625 |
// micro |
|---|
| 1626 |
// build |
|---|
| 1627 |
j++; |
|---|
| 1628 |
#endif |
|---|
| 1629 |
#else |
|---|
| 1630 |
if (!strcmp(menu[i][j], "SuperChannel.asp")) // jump over |
|---|
| 1631 |
// PPTP in |
|---|
| 1632 |
// micro |
|---|
| 1633 |
// build |
|---|
| 1634 |
j++; |
|---|
| 1635 |
#endif |
|---|
| 1636 |
#ifndef HAVE_WAVESAT |
|---|
| 1637 |
if (!strcmp(menu[i][j], "WiMAX.asp")) // jump over |
|---|
| 1638 |
// WiMAX |
|---|
| 1639 |
j++; |
|---|
| 1640 |
#else |
|---|
| 1641 |
if (!wimaxwifi && !strcmp(menu[i][j], "WiMAX.asp")) // jump |
|---|
| 1642 |
// over |
|---|
| 1643 |
// WiMAX |
|---|
| 1644 |
j++; |
|---|
| 1645 |
#endif |
|---|
| 1646 |
#ifdef HAVE_MADWIFI |
|---|
| 1647 |
if (!wifi && !strcmp(menu[i][j], "WL_WPATable.asp")) // jump |
|---|
| 1648 |
// over |
|---|
| 1649 |
// PPTP |
|---|
| 1650 |
// in |
|---|
| 1651 |
// micro |
|---|
| 1652 |
// build |
|---|
| 1653 |
j++; |
|---|
| 1654 |
if (!strcmp(menu[i][j], "Wireless_radauth.asp")) |
|---|
| 1655 |
j++; |
|---|
| 1656 |
if (!wifi |
|---|
| 1657 |
&& !strncmp(menu[i][j], "Wireless_MAC.asp", |
|---|
| 1658 |
8)) |
|---|
| 1659 |
j++; |
|---|
| 1660 |
if (!strncmp |
|---|
| 1661 |
(menu[i][j], "Wireless_Advanced", 17)) |
|---|
| 1662 |
j++; |
|---|
| 1663 |
if ((!wifi||cpeonly) && !strncmp(menu[i][j], "Wireless_WDS", 12)) |
|---|
| 1664 |
j++; |
|---|
| 1665 |
if (!wifi |
|---|
| 1666 |
&& !strcmp(menu[i][j], |
|---|
| 1667 |
"Status_Wireless.asp")) |
|---|
| 1668 |
j++; |
|---|
| 1669 |
|
|---|
| 1670 |
#endif |
|---|
| 1671 |
if ((!vlan_supp) && !strcmp(menu[i][j], "Vlan.asp")) // jump |
|---|
| 1672 |
// over |
|---|
| 1673 |
// VLANs |
|---|
| 1674 |
// if |
|---|
| 1675 |
// vlan |
|---|
| 1676 |
// not |
|---|
| 1677 |
// supported |
|---|
| 1678 |
j++; |
|---|
| 1679 |
|
|---|
| 1680 |
#ifndef HAVE_PPPOESERVER |
|---|
| 1681 |
if (!strcmp(menu[i][j], "PPPoE_Server.asp")) |
|---|
| 1682 |
j++; |
|---|
| 1683 |
#endif |
|---|
| 1684 |
#ifdef HAVE_MICRO |
|---|
| 1685 |
if (!strcmp(menu[i][j], "PPTP.asp")) // jump over PPTP in |
|---|
| 1686 |
// micro build |
|---|
| 1687 |
j++; |
|---|
| 1688 |
#endif |
|---|
| 1689 |
#ifndef HAVE_USB |
|---|
| 1690 |
if (!strcmp(menu[i][j], "USB.asp")) // jump over USB |
|---|
| 1691 |
j++; |
|---|
| 1692 |
#endif |
|---|
| 1693 |
#ifndef HAVE_NAS_SERVER |
|---|
| 1694 |
if (!strcmp(menu[i][j], "NAS.asp")) // jump over NAS |
|---|
| 1695 |
j++; |
|---|
| 1696 |
#endif |
|---|
| 1697 |
#ifdef HAVE_GLAUCO |
|---|
| 1698 |
if (!strcmp(menu[i][j], "Factory_Defaults.asp")) |
|---|
| 1699 |
j++; |
|---|
| 1700 |
if (!strcmp(menu[i][j], "Upgrade.asp")) |
|---|
| 1701 |
j++; |
|---|
| 1702 |
#endif |
|---|
| 1703 |
#ifndef HAVE_MILKFISH |
|---|
| 1704 |
if (!strcmp(menu[i][j], "Milkfish.asp")) |
|---|
| 1705 |
j++; |
|---|
| 1706 |
#endif |
|---|
| 1707 |
#ifndef HAVE_WOL |
|---|
| 1708 |
if (!strcmp(menu[i][j], "Wol.asp")) |
|---|
| 1709 |
j++; |
|---|
| 1710 |
#endif |
|---|
| 1711 |
#ifndef HAVE_EOP_TUNNEL |
|---|
| 1712 |
if (!strcmp(menu[i][j], "eop-tunnel.asp")) |
|---|
| 1713 |
j++; |
|---|
| 1714 |
#endif |
|---|
| 1715 |
#ifndef HAVE_VLANTAGGING |
|---|
| 1716 |
if (!strcmp(menu[i][j], "Networking.asp")) |
|---|
| 1717 |
j++; |
|---|
| 1718 |
#endif |
|---|
| 1719 |
#ifndef HAVE_CTORRENT |
|---|
| 1720 |
if (!strcmp(menu[i][j], "P2P.asp")) |
|---|
| 1721 |
j++; |
|---|
| 1722 |
#endif |
|---|
| 1723 |
if ((!sputnik) && !strcmp(menu[i][j], "Status_SputnikAPD.asp")) // jump |
|---|
| 1724 |
// over |
|---|
| 1725 |
// Sputnik |
|---|
| 1726 |
j++; |
|---|
| 1727 |
if ((!openvpn) && !strcmp(menu[i][j], "Status_OpenVPN.asp")) // jump |
|---|
| 1728 |
// over |
|---|
| 1729 |
// OpenVPN |
|---|
| 1730 |
j++; |
|---|
| 1731 |
if ((!auth) && !strcmp(menu[i][j], "Info.htm")) // jump |
|---|
| 1732 |
// over |
|---|
| 1733 |
// Sys-Info |
|---|
| 1734 |
j++; |
|---|
| 1735 |
|
|---|
| 1736 |
if ((registered) && !cpeonly && !strcmp(menu[i][j], "register.asp")) // jump |
|---|
| 1737 |
// over |
|---|
| 1738 |
// Sys-Info |
|---|
| 1739 |
j++; |
|---|
| 1740 |
#ifdef HAVE_MADWIFI |
|---|
| 1741 |
if (!strcmp(menu[i][j], submenu) |
|---|
| 1742 |
&& (strlen(menu[i][j]) |
|---|
| 1743 |
&& !strcmp(menu[i][j], |
|---|
| 1744 |
"Wireless_Basic.asp") |
|---|
| 1745 |
&& !wifi && wimaxwifi)) { |
|---|
| 1746 |
websWrite(wp, |
|---|
| 1747 |
" <li><span><script type=\"text/javascript\">Capture(bmenu.wimax)</script></span></li>\n"); |
|---|
| 1748 |
} |
|---|
| 1749 |
#endif |
|---|
| 1750 |
else if (!strcmp(menu[i][j], submenu) |
|---|
| 1751 |
&& (strlen(menu[i][j]))) { |
|---|
| 1752 |
websWrite(wp, |
|---|
| 1753 |
" <li><span><script type=\"text/javascript\">Capture(bmenu.%s)</script></span></li>\n", |
|---|
| 1754 |
menuname[i][j + 1]); |
|---|
| 1755 |
} |
|---|
| 1756 |
#ifdef HAVE_HTTPS // until https will allow upgrade and backup |
|---|
| 1757 |
#ifdef HAVE_MATRIXSSL |
|---|
| 1758 |
else if ((strlen(menu[i][j]) != 0) && (do_ssl) |
|---|
| 1759 |
&& ((!strcmp(menu[i][j], "Upgrade.asp") |
|---|
| 1760 |
|| |
|---|
| 1761 |
(!strcmp |
|---|
| 1762 |
(menu[i][j], "config.asp"))))) { |
|---|
| 1763 |
websWrite(wp, |
|---|
| 1764 |
" <script type=\"text/javascript\">\n//<![CDATA[\n"); |
|---|
| 1765 |
websWrite(wp, |
|---|
| 1766 |
" document.write(\"<li><a style=\\\"cursor:pointer\\\" title=\\\"\" + errmsg.err46 + \"\\\" onclick=\\\"alert(errmsg.err45)\\\" ><em>\" + bmenu.%s + \"</em></a></li>\");\n", |
|---|
| 1767 |
menuname[i][j + 1]); |
|---|
| 1768 |
websWrite(wp, |
|---|
| 1769 |
" \n//]]>\n</script>\n"); |
|---|
| 1770 |
} |
|---|
| 1771 |
#endif |
|---|
| 1772 |
#endif |
|---|
| 1773 |
#ifdef HAVE_MADWIFI |
|---|
| 1774 |
else if (strlen(menu[i][j]) |
|---|
| 1775 |
&& !strcmp(menu[i][j], |
|---|
| 1776 |
"Wireless_Basic.asp") |
|---|
| 1777 |
&& !wifi && wimaxwifi) { |
|---|
| 1778 |
websWrite(wp, |
|---|
| 1779 |
" <li><a href=\"WiMAX.asp\"><script type=\"text/javascript\">Capture(bmenu.wimax)</script></a></li>\n"); |
|---|
| 1780 |
} |
|---|
| 1781 |
#endif |
|---|
| 1782 |
else if (strlen(menu[i][j])) { |
|---|
| 1783 |
websWrite(wp, |
|---|
| 1784 |
" <li><a href=\"%s\"><script type=\"text/javascript\">Capture(bmenu.%s)</script></a></li>\n", |
|---|
| 1785 |
menu[i][j], |
|---|
| 1786 |
menuname[i][j + 1]); |
|---|
| 1787 |
} |
|---|
| 1788 |
} |
|---|
| 1789 |
websWrite(wp, " </ul>\n"); |
|---|
| 1790 |
websWrite(wp, " </div>\n"); |
|---|
| 1791 |
websWrite(wp, " </li>\n"); |
|---|
| 1792 |
} |
|---|
| 1793 |
#ifdef HAVE_MADWIFI |
|---|
| 1794 |
else if (!strcmp(menu[i][0], "Wireless_Basic.asp") && !wifi |
|---|
| 1795 |
&& wimaxwifi) { |
|---|
| 1796 |
websWrite(wp, |
|---|
| 1797 |
" <li><a href=\"WiMAX.asp\"><script type=\"text/javascript\">Capture(bmenu.wimax)</script></a></li>\n"); |
|---|
| 1798 |
} |
|---|
| 1799 |
#endif |
|---|
| 1800 |
else { |
|---|
| 1801 |
websWrite(wp, |
|---|
| 1802 |
" <li><a href=\"%s\"><script type=\"text/javascript\">Capture(bmenu.%s)</script></a></li>\n", |
|---|
| 1803 |
menu[i][0], menuname[i][0]); |
|---|
| 1804 |
} |
|---|
| 1805 |
} |
|---|
| 1806 |
websWrite(wp, " </ul>\n"); |
|---|
| 1807 |
websWrite(wp, " </div>\n"); |
|---|
| 1808 |
websWrite(wp, "</div>\n"); |
|---|
| 1809 |
|
|---|
| 1810 |
return; |
|---|
| 1811 |
} |
|---|
| 1812 |
|
|---|
| 1813 |
void ej_do_pagehead(webs_t wp, int argc, char_t ** argv) // Eko |
|---|
| 1814 |
{ |
|---|
| 1815 |
char *style = nvram_get("router_style"); |
|---|
| 1816 |
|
|---|
| 1817 |
#ifndef FASTWEB |
|---|
| 1818 |
if (argc < 1) { |
|---|
| 1819 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 1820 |
return; |
|---|
| 1821 |
} |
|---|
| 1822 |
#endif |
|---|
| 1823 |
|
|---|
| 1824 |
/* |
|---|
| 1825 |
* websWrite (wp, "<\?xml version=\"1.0\" encoding=\"%s\"\?>\n", |
|---|
| 1826 |
* live_translate("lang_charset.set")); IE Problem ... |
|---|
| 1827 |
*/ |
|---|
| 1828 |
websWrite(wp, |
|---|
| 1829 |
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"); |
|---|
| 1830 |
websWrite(wp, "<html>\n"); |
|---|
| 1831 |
websWrite(wp, "\t<head>\n"); |
|---|
| 1832 |
websWrite(wp, |
|---|
| 1833 |
"\t\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=%s\" />\n", |
|---|
| 1834 |
live_translate("lang_charset.set")); |
|---|
| 1835 |
#ifndef HAVE_MICRO |
|---|
| 1836 |
websWrite(wp, |
|---|
| 1837 |
"\t\t<link rel=\"icon\" href=\"images/favicon.ico\" type=\"image/x-icon\" />\n"); |
|---|
| 1838 |
websWrite(wp, |
|---|
| 1839 |
"\t\t<link rel=\"shortcut icon\" href=\"images/favicon.ico\" type=\"image/x-icon\" />\n"); |
|---|
| 1840 |
#endif |
|---|
| 1841 |
websWrite(wp, |
|---|
| 1842 |
"\t\t<script type=\"text/javascript\" src=\"common.js\"></script>\n"); |
|---|
| 1843 |
websWrite(wp, |
|---|
| 1844 |
"\t\t<script type=\"text/javascript\" src=\"lang_pack/english.js\"></script>\n"); |
|---|
| 1845 |
#ifdef HAVE_LANGUAGE |
|---|
| 1846 |
websWrite(wp, |
|---|
| 1847 |
"\t\t<script type=\"text/javascript\" src=\"lang_pack/language.js\"></script>\n"); |
|---|
| 1848 |
#endif |
|---|
| 1849 |
websWrite(wp, |
|---|
| 1850 |
"\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"style/%s/style.css\" />\n", |
|---|
| 1851 |
style); |
|---|
| 1852 |
websWrite(wp, |
|---|
| 1853 |
"\t\t<!--[if IE]><link type=\"text/css\" rel=\"stylesheet\" href=\"style/%s/style_ie.css\" /><![endif]-->\n", |
|---|
| 1854 |
style); |
|---|
| 1855 |
|
|---|
| 1856 |
#ifdef HAVE_PWC |
|---|
| 1857 |
websWrite(wp, |
|---|
| 1858 |
"\t\t<script type=\"text/javascript\" src=\"js/prototype.js\"></script>\n"); |
|---|
| 1859 |
websWrite(wp, |
|---|
| 1860 |
"\t\t<script type=\"text/javascript\" src=\"js/effects.js\"></script>\n"); |
|---|
| 1861 |
websWrite(wp, |
|---|
| 1862 |
"\t\t<script type=\"text/javascript\" src=\"js/window.js\"></script>\n"); |
|---|
| 1863 |
websWrite(wp, |
|---|
| 1864 |
"\t\t<script type=\"text/javascript\" src=\"js/window_effects.js\"></script>\n"); |
|---|
| 1865 |
websWrite(wp, |
|---|
| 1866 |
"\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"style/pwc/default.css\" />\n"); |
|---|
| 1867 |
websWrite(wp, |
|---|
| 1868 |
"\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"style/pwc/ddwrt.css\" />\n"); |
|---|
| 1869 |
#endif |
|---|
| 1870 |
websWrite(wp, "\t\t<title>%s (build %s)", nvram_get("router_name"),SVN_REVISION); |
|---|
| 1871 |
if (strlen(argv[0]) != 0) { |
|---|
| 1872 |
websWrite(wp, " - %s", live_translate(argv[0])); |
|---|
| 1873 |
} |
|---|
| 1874 |
websWrite(wp, "</title>\n"); |
|---|
| 1875 |
|
|---|
| 1876 |
} |
|---|
| 1877 |
|
|---|
| 1878 |
void ej_do_hpagehead(webs_t wp, int argc, char_t ** argv) // Eko |
|---|
| 1879 |
{ |
|---|
| 1880 |
char *htitle; |
|---|
| 1881 |
|
|---|
| 1882 |
#ifdef FASTWEB |
|---|
| 1883 |
ejArgs(argc, argv, "%s", &htitle); |
|---|
| 1884 |
#else |
|---|
| 1885 |
if (ejArgs(argc, argv, "%s", &htitle) < 1) { |
|---|
| 1886 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 1887 |
return; |
|---|
| 1888 |
} |
|---|
| 1889 |
#endif |
|---|
| 1890 |
websWrite(wp, |
|---|
| 1891 |
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"); |
|---|
| 1892 |
if (!strcmp(htitle, "doctype_only")) |
|---|
| 1893 |
return; // stop here, for About.htm |
|---|
| 1894 |
websWrite(wp, "<html>\n"); |
|---|
| 1895 |
websWrite(wp, "\t<head>\n"); |
|---|
| 1896 |
websWrite(wp, |
|---|
| 1897 |
"\t\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=%s\" />\n", |
|---|
| 1898 |
live_translate("lang_charset.set")); |
|---|
| 1899 |
websWrite(wp, |
|---|
| 1900 |
"\t\t<script type=\"text/javascript\" src=\"../common.js\"></script>\n"); |
|---|
| 1901 |
websWrite(wp, |
|---|
| 1902 |
"\t\t<script type=\"text/javascript\" src=\"../lang_pack/english.js\"></script>\n"); |
|---|
| 1903 |
#ifdef HAVE_LANGUAGE |
|---|
| 1904 |
websWrite(wp, |
|---|
| 1905 |
"\t\t<script type=\"text/javascript\" src=\"../lang_pack/language.js\"></script>\n"); |
|---|
| 1906 |
#endif |
|---|
| 1907 |
websWrite(wp, |
|---|
| 1908 |
"\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\"help.css\">\n"); |
|---|
| 1909 |
websWrite(wp, "\t\t<title>%s (build %s)", live_translate("share.help"),SVN_REVISION); |
|---|
| 1910 |
websWrite(wp, " - %s</title>\n", live_translate(htitle)); |
|---|
| 1911 |
websWrite(wp, "\t</head>\n"); |
|---|
| 1912 |
|
|---|
| 1913 |
} |
|---|
| 1914 |
|
|---|
| 1915 |
void ej_show_timeoptions(webs_t wp, int argc, char_t ** argv) // Eko |
|---|
| 1916 |
{ |
|---|
| 1917 |
|
|---|
| 1918 |
char timediffs[39][8] = |
|---|
| 1919 |
{ "-12", "-11", "-10", "-09.5", "-09", "-08", "-07", "-06", "-05", |
|---|
| 1920 |
"-04.5", "-04", |
|---|
| 1921 |
"-03.5", "-03", "-02", "-01", "+00", |
|---|
| 1922 |
"+01", "+02", "+03", "+03.5", "+04", "+04.5", "+05", "+05.5", |
|---|
| 1923 |
"+05.75", |
|---|
| 1924 |
"+06", |
|---|
| 1925 |
"+06.5", "+07", "+08", "+09", "+09.5", "+10", "+10.5", "+11", |
|---|
| 1926 |
"+11.5", |
|---|
| 1927 |
"+12", "+12.75", "+13", "+14" |
|---|
| 1928 |
}; |
|---|
| 1929 |
|
|---|
| 1930 |
char timezones[39][8] = |
|---|
| 1931 |
{ "-12:00", "-11:00", "-10:00", "-09:30", "-09:00", "-08:00", |
|---|
| 1932 |
"-07:00", |
|---|
| 1933 |
"-06:00", "-05:00", "-04:30", "-04:00", "-03:30", "-03:00", |
|---|
| 1934 |
"-02:00", |
|---|
| 1935 |
"-01:00", "", |
|---|
| 1936 |
"+01:00", "+02:00", "+03:00", "+03:30", "+04:00", "+04:30", |
|---|
| 1937 |
"+05:00", |
|---|
| 1938 |
"+05:30", |
|---|
| 1939 |
"+05:45", "+06:00", "+06:30", "+07:00", "+08:00", "+09:00", |
|---|
| 1940 |
"+09:30", |
|---|
| 1941 |
"+10:00", "+10:30", "+11:00", "+11:30", "+12:00", "+12:45", |
|---|
| 1942 |
"+13:00", |
|---|
| 1943 |
"+14:00" |
|---|
| 1944 |
}; |
|---|
| 1945 |
|
|---|
| 1946 |
int i; |
|---|
| 1947 |
|
|---|
| 1948 |
for (i = 0; i < 39; i++) { |
|---|
| 1949 |
websWrite(wp, |
|---|
| 1950 |
"<option value=\"%s\" %s>UTC%s</option>\");\n", |
|---|
| 1951 |
timediffs[i], nvram_match("time_zone", |
|---|
| 1952 |
timediffs[i]) ? |
|---|
| 1953 |
"selected=\"selected\"" : "", timezones[i]); |
|---|
| 1954 |
|
|---|
| 1955 |
} |
|---|
| 1956 |
|
|---|
| 1957 |
} |
|---|
| 1958 |
|
|---|
| 1959 |
void ej_show_wanipinfo(webs_t wp, int argc, char_t ** argv) // Eko |
|---|
| 1960 |
{ |
|---|
| 1961 |
char *wan_ipaddr; |
|---|
| 1962 |
int wan_link; |
|---|
| 1963 |
|
|---|
| 1964 |
if (getWET() || nvram_match("wan_proto", "disabled")) { |
|---|
| 1965 |
websWrite(wp, ": %s", live_translate("share.disabled")); |
|---|
| 1966 |
return; |
|---|
| 1967 |
} |
|---|
| 1968 |
|
|---|
| 1969 |
wan_link = check_wan_link(0); |
|---|
| 1970 |
|
|---|
| 1971 |
if (nvram_match("wan_proto", "pptp")) { |
|---|
| 1972 |
wan_ipaddr = |
|---|
| 1973 |
wan_link ? nvram_safe_get("pptp_get_ip") : |
|---|
| 1974 |
nvram_safe_get("wan_ipaddr"); |
|---|
| 1975 |
} else if (!strcmp(nvram_safe_get("wan_proto"), "pppoe")) { |
|---|
| 1976 |
wan_ipaddr = |
|---|
| 1977 |
wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; |
|---|
| 1978 |
} else if (!strcmp(nvram_safe_get("wan_proto"), "3g")) { |
|---|
| 1979 |
wan_ipaddr = |
|---|
| 1980 |
wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; |
|---|
| 1981 |
} else if (nvram_match("wan_proto", "l2tp")) { |
|---|
| 1982 |
wan_ipaddr = |
|---|
| 1983 |
wan_link ? nvram_safe_get("l2tp_get_ip") : |
|---|
| 1984 |
nvram_safe_get("wan_ipaddr"); |
|---|
| 1985 |
} else { |
|---|
| 1986 |
wan_ipaddr = nvram_safe_get("wan_ipaddr"); |
|---|
| 1987 |
} |
|---|
| 1988 |
|
|---|
| 1989 |
websWrite(wp, " IP: %s", wan_ipaddr); |
|---|
| 1990 |
|
|---|
| 1991 |
return; |
|---|
| 1992 |
} |
|---|
| 1993 |
|
|---|
| 1994 |
/* |
|---|
| 1995 |
* Example: |
|---|
| 1996 |
* wan_proto=dhcp |
|---|
| 1997 |
* <% nvram_selected("wan_proto", "dhcp",); %> produces: selected="selected" |
|---|
| 1998 |
* <% nvram_selected_js("wan_proto", "dhcp"); %> produces: selected=\"selected\" |
|---|
| 1999 |
* <% nvram_selected("wan_proto", "static"); %> does not produce |
|---|
| 2000 |
*/ |
|---|
| 2001 |
void ej_nvram_selected(webs_t wp, int argc, char_t ** argv) |
|---|
| 2002 |
{ |
|---|
| 2003 |
|
|---|
| 2004 |
#ifndef FASTWEB |
|---|
| 2005 |
if (argc < 2) ; |
|---|
| 2006 |
{ |
|---|
| 2007 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 2008 |
return; |
|---|
| 2009 |
} |
|---|
| 2010 |
#endif |
|---|
| 2011 |
|
|---|
| 2012 |
if (nvram_match(argv[0], argv[1])) { |
|---|
| 2013 |
websWrite(wp, "selected=\"selected\""); |
|---|
| 2014 |
} |
|---|
| 2015 |
return; |
|---|
| 2016 |
} |
|---|
| 2017 |
|
|---|
| 2018 |
void ej_nvram_selected_js(webs_t wp, int argc, char_t ** argv) |
|---|
| 2019 |
{ |
|---|
| 2020 |
|
|---|
| 2021 |
#ifndef FASTWEB |
|---|
| 2022 |
if (argc < 2) ; |
|---|
| 2023 |
{ |
|---|
| 2024 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 2025 |
return; |
|---|
| 2026 |
} |
|---|
| 2027 |
#endif |
|---|
| 2028 |
|
|---|
| 2029 |
if (nvram_match(argv[0], argv[1])) { |
|---|
| 2030 |
websWrite(wp, "selected=\\\"selected\\\""); |
|---|
| 2031 |
} |
|---|
| 2032 |
return; |
|---|
| 2033 |
} |
|---|
| 2034 |
|
|---|
| 2035 |
void ej_getrebootflags(webs_t wp, int argc, char_t ** argv) |
|---|
| 2036 |
{ |
|---|
| 2037 |
#ifdef HAVE_RB500 |
|---|
| 2038 |
websWrite(wp, "1"); |
|---|
| 2039 |
#elif HAVE_MAGICBOX |
|---|
| 2040 |
websWrite(wp, "2"); |
|---|
| 2041 |
#elif HAVE_FONERA |
|---|
| 2042 |
websWrite(wp, "2"); |
|---|
| 2043 |
#elif HAVE_MERAKI |
|---|
| 2044 |
websWrite(wp, "2"); |
|---|
| 2045 |
#elif HAVE_LS2 |
|---|
| 2046 |
websWrite(wp, "2"); |
|---|
| 2047 |
#elif HAVE_LS5 |
|---|
| 2048 |
websWrite(wp, "2"); |
|---|
| 2049 |
#elif HAVE_WHRAG108 |
|---|
| 2050 |
websWrite(wp, "2"); |
|---|
| 2051 |
#elif HAVE_TW6600 |
|---|
| 2052 |
websWrite(wp, "2"); |
|---|
| 2053 |
#elif HAVE_CA8 |
|---|
| 2054 |
websWrite(wp, "2"); |
|---|
| 2055 |
#elif HAVE_GATEWORX |
|---|
| 2056 |
websWrite(wp, "1"); |
|---|
| 2057 |
#elif HAVE_X86 |
|---|
| 2058 |
websWrite(wp, "1"); |
|---|
| 2059 |
#else |
|---|
| 2060 |
websWrite(wp, "0"); |
|---|
| 2061 |
#endif |
|---|
| 2062 |
} |
|---|
| 2063 |
|
|---|
| 2064 |
void ej_tran(webs_t wp, int argc, char_t ** argv) |
|---|
| 2065 |
{ |
|---|
| 2066 |
|
|---|
| 2067 |
#ifndef FASTWEB |
|---|
| 2068 |
if (argc != 1) |
|---|
| 2069 |
return; |
|---|
| 2070 |
#endif |
|---|
| 2071 |
websWrite(wp, "<script type=\"text/javascript\">Capture(%s)</script>", |
|---|
| 2072 |
argv[0]); |
|---|
| 2073 |
return; |
|---|
| 2074 |
} |
|---|
| 2075 |
|
|---|
| 2076 |
/* |
|---|
| 2077 |
* Example: |
|---|
| 2078 |
* wan_proto=dhcp |
|---|
| 2079 |
* <% nvram_checked("wan_proto", "dhcp"); %> produces: checked="checked" |
|---|
| 2080 |
* <% nvram_checked_js("wan_proto", "dhcp"); %> produces: checked=\"checked\" |
|---|
| 2081 |
* <% nvram_checked("wan_proto", "static"); %> does not produce |
|---|
| 2082 |
*/ |
|---|
| 2083 |
void ej_nvram_checked(webs_t wp, int argc, char_t ** argv) |
|---|
| 2084 |
{ |
|---|
| 2085 |
|
|---|
| 2086 |
#ifdef FASTWEB |
|---|
| 2087 |
if (argc < 2) { |
|---|
| 2088 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 2089 |
return; |
|---|
| 2090 |
} |
|---|
| 2091 |
#endif |
|---|
| 2092 |
|
|---|
| 2093 |
if (nvram_match(argv[0], argv[1])) { |
|---|
| 2094 |
websWrite(wp, "checked=\"checked\""); |
|---|
| 2095 |
} |
|---|
| 2096 |
|
|---|
| 2097 |
return; |
|---|
| 2098 |
} |
|---|
| 2099 |
|
|---|
| 2100 |
void ej_nvram_checked_js(webs_t wp, int argc, char_t ** argv) |
|---|
| 2101 |
{ |
|---|
| 2102 |
|
|---|
| 2103 |
#ifndef FASTWEB |
|---|
| 2104 |
if (argc < 2) { |
|---|
| 2105 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 2106 |
return; |
|---|
| 2107 |
} |
|---|
| 2108 |
#endif |
|---|
| 2109 |
|
|---|
| 2110 |
if (nvram_match(argv[0], argv[1])) { |
|---|
| 2111 |
websWrite(wp, "checked=\\\"checked\\\""); |
|---|
| 2112 |
} |
|---|
| 2113 |
|
|---|
| 2114 |
return; |
|---|
| 2115 |
} |
|---|
| 2116 |
|
|---|
| 2117 |
void ej_make_time_list(webs_t wp, int argc, char_t ** argv) |
|---|
| 2118 |
{ |
|---|
| 2119 |
int i, st, en; |
|---|
| 2120 |
char ic[16]; |
|---|
| 2121 |
|
|---|
| 2122 |
#ifndef FASTWEB |
|---|
| 2123 |
if (argc < 3) { |
|---|
| 2124 |
websError(wp, 400, "Insufficient args\n"); |
|---|
| 2125 |
return; |
|---|
| 2126 |
} |
|---|
| 2127 |
#endif |
|---|
| 2128 |
|
|---|
| 2129 |
st = atoi(argv[1]); |
|---|
| 2130 |
en = atoi(argv[2]); |
|---|
| 2131 |
|
|---|
| 2132 |
for (i = st; i <= en; i++) { |
|---|
| 2133 |
sprintf(ic, "%d", i); |
|---|
| 2134 |
websWrite(wp, "<option value=\"%d\" %s >%02d</option>\n", i, |
|---|
| 2135 |
nvram_match(argv[0], |
|---|
| 2136 |
ic) ? "selected=\"selected\"" : "", i); |
|---|
| 2137 |
} |
|---|
| 2138 |
|
|---|
| 2139 |
return; |
|---|
| 2140 |
} |
|---|
| 2141 |
|
|---|
| 2142 |
#ifdef HAVE_CPUTEMP |
|---|
| 2143 |
void ej_get_cputemp(webs_t wp, int argc, char_t ** argv) |
|---|
| 2144 |
{ |
|---|
| 2145 |
#ifdef HAVE_GATEWORX |
|---|
| 2146 |
int TEMP_MUL = 100; |
|---|
| 2147 |
|
|---|
| 2148 |
if (getRouterBrand() == ROUTER_BOARD_GATEWORX_SWAP) |
|---|
| 2149 |
TEMP_MUL = 200; |
|---|
| 2150 |
|
|---|
| 2151 |
FILE *fp = |
|---|
| 2152 |
fopen |
|---|
| 2153 |
("/sys/devices/platform/IXP4XX-I2C.0/i2c-adapter:i2c-0/0-0028/temp_input", |
|---|
| 2154 |
"rb"); |
|---|
| 2155 |
#else |
|---|
| 2156 |
#define TEMP_MUL 1000 |
|---|
| 2157 |
#ifdef HAVE_X86 |
|---|
| 2158 |
FILE *fp = |
|---|
| 2159 |
fopen("/sys/devices/platform/i2c-1/1-0048/temp1_input", "rb"); |
|---|
| 2160 |
#else |
|---|
| 2161 |
FILE *fp = |
|---|
| 2162 |
fopen("/sys/devices/platform/i2c-0/0-0048/temp1_input", "rb"); |
|---|
| 2163 |
#endif |
|---|
| 2164 |
#endif |
|---|
| 2165 |
|
|---|
| 2166 |
if (fp == NULL) { |
|---|
| 2167 |
websWrite(wp, "%s", live_translate("status_router.notavail")); // no |
|---|
| 2168 |
// i2c |
|---|
| 2169 |
// lm75 |
|---|
| 2170 |
// found |
|---|
| 2171 |
return; |
|---|
| 2172 |
} |
|---|
| 2173 |
int temp; |
|---|
| 2174 |
|
|---|
| 2175 |
fscanf(fp, "%d", &temp); |
|---|
| 2176 |
fclose(fp); |
|---|
| 2177 |
int high = temp / TEMP_MUL; |
|---|
| 2178 |
int low = (temp - (high * TEMP_MUL)) / (TEMP_MUL / 10); |
|---|
| 2179 |
|
|---|
| 2180 |
websWrite(wp, "%d.%d °C", high, low); // no i2c lm75 found |
|---|
| 2181 |
} |
|---|
| 2182 |
|
|---|
| 2183 |
void ej_show_cpu_temperature(webs_t wp, int argc, char_t ** argv) |
|---|
| 2184 |
{ |
|---|
| 2185 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2186 |
websWrite(wp, |
|---|
| 2187 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(status_router.cputemp)</script></div>\n"); |
|---|
| 2188 |
websWrite(wp, "<span id=\"cpu_temp\">"); |
|---|
| 2189 |
ej_get_cputemp(wp, argc, argv); |
|---|
| 2190 |
websWrite(wp, "</span> \n"); |
|---|
| 2191 |
websWrite(wp, "</div>\n"); |
|---|
| 2192 |
} |
|---|
| 2193 |
#else |
|---|
| 2194 |
void ej_get_cputemp(webs_t wp, int argc, char_t ** argv) |
|---|
| 2195 |
{ |
|---|
| 2196 |
return; |
|---|
| 2197 |
} |
|---|
| 2198 |
|
|---|
| 2199 |
void ej_show_cpu_temperature(webs_t wp, int argc, char_t ** argv) |
|---|
| 2200 |
{ |
|---|
| 2201 |
return; |
|---|
| 2202 |
} |
|---|
| 2203 |
#endif |
|---|
| 2204 |
|
|---|
| 2205 |
#ifdef HAVE_VOLT |
|---|
| 2206 |
void ej_get_voltage(webs_t wp, int argc, char_t ** argv) |
|---|
| 2207 |
{ |
|---|
| 2208 |
FILE *fp = |
|---|
| 2209 |
fopen |
|---|
| 2210 |
("/sys/devices/platform/IXP4XX-I2C.0/i2c-adapter:i2c-0/0-0028/volt", |
|---|
| 2211 |
"rb"); |
|---|
| 2212 |
|
|---|
| 2213 |
if (fp == NULL) { |
|---|
| 2214 |
websWrite(wp, "%s", live_translate("status_router.notavail")); // no |
|---|
| 2215 |
// i2c |
|---|
| 2216 |
// lm75 |
|---|
| 2217 |
// found |
|---|
| 2218 |
return; |
|---|
| 2219 |
} |
|---|
| 2220 |
int temp; |
|---|
| 2221 |
|
|---|
| 2222 |
fscanf(fp, "%d", &temp); |
|---|
| 2223 |
fclose(fp); |
|---|
| 2224 |
// temp*=564; |
|---|
| 2225 |
int high = temp / 1000; |
|---|
| 2226 |
int low = (temp - (high * 1000)) / 100; |
|---|
| 2227 |
|
|---|
| 2228 |
websWrite(wp, "%d.%d V", high, low); // no i2c lm75 found |
|---|
| 2229 |
} |
|---|
| 2230 |
|
|---|
| 2231 |
void ej_show_voltage(webs_t wp, int argc, char_t ** argv) |
|---|
| 2232 |
{ |
|---|
| 2233 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2234 |
websWrite(wp, |
|---|
| 2235 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(status_router.inpvolt)</script></div>\n"); |
|---|
| 2236 |
websWrite(wp, "<span id=\"voltage\">"); |
|---|
| 2237 |
ej_get_voltage(wp, argc, argv); |
|---|
| 2238 |
websWrite(wp, "</span> \n"); |
|---|
| 2239 |
websWrite(wp, "</div>\n"); |
|---|
| 2240 |
} |
|---|
| 2241 |
#else |
|---|
| 2242 |
void ej_get_voltage(webs_t wp, int argc, char_t ** argv) |
|---|
| 2243 |
{ |
|---|
| 2244 |
return; |
|---|
| 2245 |
} |
|---|
| 2246 |
|
|---|
| 2247 |
void ej_show_voltage(webs_t wp, int argc, char_t ** argv) |
|---|
| 2248 |
{ |
|---|
| 2249 |
return; |
|---|
| 2250 |
} |
|---|
| 2251 |
#endif |
|---|
| 2252 |
|
|---|
| 2253 |
static void showencstatus(webs_t wp, char *prefix) |
|---|
| 2254 |
{ |
|---|
| 2255 |
char akm[64]; |
|---|
| 2256 |
|
|---|
| 2257 |
sprintf(akm, "%s_akm", prefix); |
|---|
| 2258 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2259 |
websWrite(wp, |
|---|
| 2260 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(share.encrypt)</script> - <script type=\"text/javascript\">Capture(share.intrface)</script> %s</div>\n", |
|---|
| 2261 |
prefix); |
|---|
| 2262 |
websWrite(wp, "<script type=\"text/javascript\">"); |
|---|
| 2263 |
if (nvram_match(akm, "disabled")) { |
|---|
| 2264 |
websWrite(wp, "Capture(share.disabled)"); |
|---|
| 2265 |
websWrite(wp, "</script>"); |
|---|
| 2266 |
} else { |
|---|
| 2267 |
websWrite(wp, "Capture(share.enabled)"); |
|---|
| 2268 |
websWrite(wp, "</script>, "); |
|---|
| 2269 |
|
|---|
| 2270 |
if (nvram_match(akm, "psk")) |
|---|
| 2271 |
websWrite(wp, "WPA Personal"); |
|---|
| 2272 |
if (nvram_match(akm, "wpa")) |
|---|
| 2273 |
websWrite(wp, "WPA Enterprise"); |
|---|
| 2274 |
if (nvram_match(akm, "psk2")) |
|---|
| 2275 |
websWrite(wp, "WPA2 Personal"); |
|---|
| 2276 |
if (nvram_match(akm, "wpa2")) |
|---|
| 2277 |
websWrite(wp, "WPA2 Enterprise"); |
|---|
| 2278 |
if (nvram_match(akm, "psk psk2")) |
|---|
| 2279 |
websWrite(wp, "WPA2 Personal Mixed"); |
|---|
| 2280 |
if (nvram_match(akm, "wpa wpa2")) |
|---|
| 2281 |
websWrite(wp, "WPA Enterprise Mixed"); |
|---|
| 2282 |
if (nvram_match(akm, "radius")) |
|---|
| 2283 |
websWrite(wp, "RADIUS"); |
|---|
| 2284 |
if (nvram_match(akm, "wep")) |
|---|
| 2285 |
websWrite(wp, "WEP"); |
|---|
| 2286 |
} |
|---|
| 2287 |
|
|---|
| 2288 |
websWrite(wp, "\n</div>\n"); |
|---|
| 2289 |
return; |
|---|
| 2290 |
} |
|---|
| 2291 |
|
|---|
| 2292 |
void ej_get_txpower(webs_t wp, int argc, char_t ** argv) |
|---|
| 2293 |
{ |
|---|
| 2294 |
char txpwr[32]; |
|---|
| 2295 |
char m[32]; |
|---|
| 2296 |
|
|---|
| 2297 |
strncpy(m, nvram_safe_get("wifi_display"), 4); |
|---|
| 2298 |
m[4] = 0; |
|---|
| 2299 |
sprintf(txpwr, "%s_txpwr", m); |
|---|
| 2300 |
#ifdef HAVE_MADWIFI |
|---|
| 2301 |
websWrite(wp, "%d dBm", wifi_gettxpower(m)); |
|---|
| 2302 |
#elif HAVE_RT2880 |
|---|
| 2303 |
websWrite(wp, "%s mW", nvram_safe_get(txpwr)); |
|---|
| 2304 |
#else //broadcom |
|---|
| 2305 |
websWrite(wp, "%d mW", bcm_gettxpower(m)); |
|---|
| 2306 |
#endif |
|---|
| 2307 |
} |
|---|
| 2308 |
|
|---|
| 2309 |
void ej_getencryptionstatus(webs_t wp, int argc, char_t ** argv) |
|---|
| 2310 |
{ |
|---|
| 2311 |
char *mode = nvram_safe_get("wifi_display"); |
|---|
| 2312 |
|
|---|
| 2313 |
showencstatus(wp, mode); |
|---|
| 2314 |
} |
|---|
| 2315 |
|
|---|
| 2316 |
void ej_getwirelessstatus(webs_t wp, int argc, char_t ** argv) |
|---|
| 2317 |
{ |
|---|
| 2318 |
char mode[32]; |
|---|
| 2319 |
char m[32]; |
|---|
| 2320 |
|
|---|
| 2321 |
strncpy(m, nvram_safe_get("wifi_display"), 4); |
|---|
| 2322 |
m[4] = 0; |
|---|
| 2323 |
sprintf(mode, "%s_mode", m); |
|---|
| 2324 |
|
|---|
| 2325 |
if (nvram_match(mode, "wet") || nvram_match(mode, "sta") |
|---|
| 2326 |
|| nvram_match(mode, "infra")) |
|---|
| 2327 |
websWrite(wp, |
|---|
| 2328 |
"<script type=\"text/javascript\">Capture(info.ap)</script>"); |
|---|
| 2329 |
else if (nvram_match(mode, "apsta") || nvram_match(mode, "apstawet")) { |
|---|
| 2330 |
websWrite(wp, |
|---|
| 2331 |
"<script type=\"text/javascript\">Capture(info.ap)</script>"); |
|---|
| 2332 |
websWrite(wp, " & "); |
|---|
| 2333 |
websWrite(wp, |
|---|
| 2334 |
"<script type=\"text/javascript\">Capture(status_wireless.legend3)</script>"); |
|---|
| 2335 |
} else |
|---|
| 2336 |
websWrite(wp, |
|---|
| 2337 |
"<script type=\"text/javascript\">Capture(status_wireless.legend3)</script>"); |
|---|
| 2338 |
} |
|---|
| 2339 |
|
|---|
| 2340 |
void ej_getwirelessssid(webs_t wp, int argc, char_t ** argv) |
|---|
| 2341 |
{ |
|---|
| 2342 |
char ssid[32]; |
|---|
| 2343 |
|
|---|
| 2344 |
sprintf(ssid, "%s_ssid", nvram_safe_get("wifi_display")); |
|---|
| 2345 |
tf_webWriteESCNV(wp, ssid); |
|---|
| 2346 |
|
|---|
| 2347 |
} |
|---|
| 2348 |
|
|---|
| 2349 |
void ej_getwirelessmode(webs_t wp, int argc, char_t ** argv) |
|---|
| 2350 |
{ |
|---|
| 2351 |
char mode[32]; |
|---|
| 2352 |
char m[32]; |
|---|
| 2353 |
|
|---|
| 2354 |
strncpy(m, nvram_safe_get("wifi_display"), 4); |
|---|
| 2355 |
m[4] = 0; |
|---|
| 2356 |
sprintf(mode, "%s_mode", m); |
|---|
| 2357 |
|
|---|
| 2358 |
websWrite(wp, "<script type=\"text/javascript\">"); |
|---|
| 2359 |
if (nvram_match(mode, "wet")) |
|---|
| 2360 |
websWrite(wp, "Capture(wl_basic.clientBridge)"); |
|---|
| 2361 |
if (nvram_match(mode, "ap")) |
|---|
| 2362 |
websWrite(wp, "Capture(wl_basic.ap)"); |
|---|
| 2363 |
if (nvram_match(mode, "sta")) |
|---|
| 2364 |
websWrite(wp, "Capture(wl_basic.client)"); |
|---|
| 2365 |
if (nvram_match(mode, "infra")) |
|---|
| 2366 |
websWrite(wp, "Capture(wl_basic.adhoc)"); |
|---|
| 2367 |
if (nvram_match(mode, "apsta")) |
|---|
| 2368 |
websWrite(wp, "Capture(wl_basic.repeater)"); |
|---|
| 2369 |
if (nvram_match(mode, "apstawet")) |
|---|
| 2370 |
websWrite(wp, "Capture(wl_basic.repeaterbridge)"); |
|---|
| 2371 |
if (nvram_match(mode, "wdssta")) |
|---|
| 2372 |
websWrite(wp, "Capture(wl_basic.wdssta)"); |
|---|
| 2373 |
if (nvram_match(mode, "wdsap")) |
|---|
| 2374 |
websWrite(wp, "Capture(wl_basic.wdsap)"); |
|---|
| 2375 |
websWrite(wp, "</script> \n"); |
|---|
| 2376 |
} |
|---|
| 2377 |
|
|---|
| 2378 |
void ej_getwirelessnetmode(webs_t wp, int argc, char_t ** argv) |
|---|
| 2379 |
{ |
|---|
| 2380 |
|
|---|
| 2381 |
char mode[32]; |
|---|
| 2382 |
char m[32]; |
|---|
| 2383 |
|
|---|
| 2384 |
strncpy(m, nvram_safe_get("wifi_display"), 4); |
|---|
| 2385 |
m[4] = 0; |
|---|
| 2386 |
sprintf(mode, "%s_net_mode", m); |
|---|
| 2387 |
|
|---|
| 2388 |
websWrite(wp, "<script type=\"text/javascript\">"); |
|---|
| 2389 |
if (nvram_match(mode, "disabled")) |
|---|
| 2390 |
websWrite(wp, "Capture(share.disabled)"); |
|---|
| 2391 |
if (nvram_match(mode, "mixed")) |
|---|
| 2392 |
websWrite(wp, "Capture(wl_basic.mixed)"); |
|---|
| 2393 |
if (nvram_match(mode, "bg-mixed")) |
|---|
| 2394 |
websWrite(wp, "Capture(wl_basic.bg)"); |
|---|
| 2395 |
if (nvram_match(mode, "g-only")) |
|---|
| 2396 |
websWrite(wp, "Capture(wl_basic.g)"); |
|---|
| 2397 |
if (nvram_match(mode, "b-only")) |
|---|
| 2398 |
websWrite(wp, "Capture(wl_basic.b)"); |
|---|
| 2399 |
if (nvram_match(mode, "n-only")) |
|---|
| 2400 |
websWrite(wp, "Capture(wl_basic.n)"); |
|---|
| 2401 |
if (nvram_match(mode, "a-only")) |
|---|
| 2402 |
websWrite(wp, "Capture(wl_basic.a)"); |
|---|
| 2403 |
if (nvram_match(mode, "na-only")) |
|---|
| 2404 |
websWrite(wp, "Capture(wl_basic.na)"); |
|---|
| 2405 |
websWrite(wp, "</script> \n"); |
|---|
| 2406 |
} |
|---|
| 2407 |
|
|---|
| 2408 |
void ej_show_openvpn_status(webs_t wp, int argc, char_t ** argv) |
|---|
| 2409 |
{ |
|---|
| 2410 |
websWrite(wp, |
|---|
| 2411 |
"<fieldset>\n<legend><script type=\"text/javascript\">Capture(share.state)</script></legend>\n"); |
|---|
| 2412 |
|
|---|
| 2413 |
system2("/etc/openvpnstate.sh > /tmp/.temp"); |
|---|
| 2414 |
FILE *in = fopen("/tmp/.temp", "r"); |
|---|
| 2415 |
|
|---|
| 2416 |
while (!feof(in)) { |
|---|
| 2417 |
int b = getc(in); |
|---|
| 2418 |
|
|---|
| 2419 |
if (b != EOF) |
|---|
| 2420 |
wfputc(b, wp); |
|---|
| 2421 |
} |
|---|
| 2422 |
fclose(in); |
|---|
| 2423 |
websWrite(wp, "</fieldset><br />"); |
|---|
| 2424 |
websWrite(wp, |
|---|
| 2425 |
"<fieldset>\n<legend><script type=\"text/javascript\">Capture(share.statu)</script></legend>\n"); |
|---|
| 2426 |
system2("/etc/openvpnstatus.sh > /tmp/.temp"); |
|---|
| 2427 |
in = fopen("/tmp/.temp", "r"); |
|---|
| 2428 |
while (!feof(in)) { |
|---|
| 2429 |
int b = getc(in); |
|---|
| 2430 |
|
|---|
| 2431 |
if (b != EOF) |
|---|
| 2432 |
wfputc(b, wp); |
|---|
| 2433 |
} |
|---|
| 2434 |
fclose(in); |
|---|
| 2435 |
websWrite(wp, "</fieldset><br />"); |
|---|
| 2436 |
websWrite(wp, |
|---|
| 2437 |
"<fieldset>\n<legend><script type=\"text/javascript\">Capture(log.legend)</script></legend>\n"); |
|---|
| 2438 |
system2("/etc/openvpnlog.sh > /tmp/.temp"); |
|---|
| 2439 |
in = fopen("/tmp/.temp", "r"); |
|---|
| 2440 |
while (!feof(in)) { |
|---|
| 2441 |
int b = getc(in); |
|---|
| 2442 |
|
|---|
| 2443 |
if (b != EOF) |
|---|
| 2444 |
wfputc(b, wp); |
|---|
| 2445 |
} |
|---|
| 2446 |
fclose(in); |
|---|
| 2447 |
websWrite(wp, "</fieldset><br />"); |
|---|
| 2448 |
|
|---|
| 2449 |
} |
|---|
| 2450 |
|
|---|
| 2451 |
void ej_radio_on(webs_t wp, int argc, char_t ** argv) |
|---|
| 2452 |
{ |
|---|
| 2453 |
int radiooff = -1; |
|---|
| 2454 |
|
|---|
| 2455 |
#ifdef HAVE_MADWIFI |
|---|
| 2456 |
char *ifname = nvram_safe_get("wifi_display"); |
|---|
| 2457 |
|
|---|
| 2458 |
if (strlen(ifname) > 0) { |
|---|
| 2459 |
int state = get_radiostate(ifname); |
|---|
| 2460 |
|
|---|
| 2461 |
switch (state) { |
|---|
| 2462 |
case 1: |
|---|
| 2463 |
websWrite(wp, "1"); |
|---|
| 2464 |
break; |
|---|
| 2465 |
default: |
|---|
| 2466 |
websWrite(wp, "0"); |
|---|
| 2467 |
break; |
|---|
| 2468 |
} |
|---|
| 2469 |
} else { |
|---|
| 2470 |
websWrite(wp, "0"); |
|---|
| 2471 |
} |
|---|
| 2472 |
#elif HAVE_RT2880 |
|---|
| 2473 |
|
|---|
| 2474 |
int state = get_radiostate("wl0"); |
|---|
| 2475 |
|
|---|
| 2476 |
switch (state) { |
|---|
| 2477 |
case 1: |
|---|
| 2478 |
websWrite(wp, "1"); |
|---|
| 2479 |
break; |
|---|
| 2480 |
default: |
|---|
| 2481 |
websWrite(wp, "0"); |
|---|
| 2482 |
break; |
|---|
| 2483 |
} |
|---|
| 2484 |
|
|---|
| 2485 |
#else |
|---|
| 2486 |
char name[32]; |
|---|
| 2487 |
sprintf(name, "%s_ifname", nvram_safe_get("wifi_display")); |
|---|
| 2488 |
|
|---|
| 2489 |
char *ifname = nvram_safe_get(name); |
|---|
| 2490 |
|
|---|
| 2491 |
wl_ioctl(ifname, WLC_GET_RADIO, &radiooff, sizeof(int)); |
|---|
| 2492 |
|
|---|
| 2493 |
switch ((radiooff & WL_RADIO_SW_DISABLE)) { |
|---|
| 2494 |
case 0: |
|---|
| 2495 |
websWrite(wp, "1"); |
|---|
| 2496 |
break; |
|---|
| 2497 |
default: |
|---|
| 2498 |
websWrite(wp, "0"); |
|---|
| 2499 |
break; |
|---|
| 2500 |
} |
|---|
| 2501 |
#endif |
|---|
| 2502 |
} |
|---|
| 2503 |
|
|---|
| 2504 |
void ej_get_radio_state(webs_t wp, int argc, char_t ** argv) |
|---|
| 2505 |
{ |
|---|
| 2506 |
int radiooff = -1; |
|---|
| 2507 |
|
|---|
| 2508 |
#ifdef HAVE_MADWIFI |
|---|
| 2509 |
char *ifname = nvram_safe_get("wifi_display"); |
|---|
| 2510 |
|
|---|
| 2511 |
if (strlen(ifname) > 0) { |
|---|
| 2512 |
int state = get_radiostate(ifname); |
|---|
| 2513 |
|
|---|
| 2514 |
switch (state) { |
|---|
| 2515 |
case 1: |
|---|
| 2516 |
websWrite(wp, "%s", |
|---|
| 2517 |
live_translate("wl_basic.radio_on")); |
|---|
| 2518 |
break; |
|---|
| 2519 |
case -1: |
|---|
| 2520 |
websWrite(wp, "%s", live_translate("share.unknown")); |
|---|
| 2521 |
break; |
|---|
| 2522 |
default: // 1: software disabled, 2: hardware |
|---|
| 2523 |
// disabled, 3: both are disabled |
|---|
| 2524 |
websWrite(wp, "%s", |
|---|
| 2525 |
live_translate("wl_basic.radio_off")); |
|---|
| 2526 |
break; |
|---|
| 2527 |
} |
|---|
| 2528 |
} else { |
|---|
| 2529 |
websWrite(wp, "%s", live_translate("share.unknown")); |
|---|
| 2530 |
} |
|---|
| 2531 |
#elif HAVE_RT2880 |
|---|
| 2532 |
|
|---|
| 2533 |
int state = get_radiostate("wl0"); |
|---|
| 2534 |
|
|---|
| 2535 |
switch (state) { |
|---|
| 2536 |
case 1: |
|---|
| 2537 |
websWrite(wp, "%s", live_translate("wl_basic.radio_on")); |
|---|
| 2538 |
break; |
|---|
| 2539 |
case -1: |
|---|
| 2540 |
websWrite(wp, "%s", live_translate("share.unknown")); |
|---|
| 2541 |
break; |
|---|
| 2542 |
default: // 1: software disabled, 2: hardware |
|---|
| 2543 |
// disabled, 3: both are disabled |
|---|
| 2544 |
websWrite(wp, "%s", live_translate("wl_basic.radio_off")); |
|---|
| 2545 |
break; |
|---|
| 2546 |
} |
|---|
| 2547 |
|
|---|
| 2548 |
#else |
|---|
| 2549 |
char name[32]; |
|---|
| 2550 |
sprintf(name, "%s_ifname", nvram_safe_get("wifi_display")); |
|---|
| 2551 |
|
|---|
| 2552 |
char *ifname = nvram_safe_get(name); |
|---|
| 2553 |
|
|---|
| 2554 |
wl_ioctl(ifname, WLC_GET_RADIO, &radiooff, sizeof(int)); |
|---|
| 2555 |
|
|---|
| 2556 |
switch ((radiooff & WL_RADIO_SW_DISABLE)) { |
|---|
| 2557 |
case 0: |
|---|
| 2558 |
websWrite(wp, "%s", live_translate("wl_basic.radio_on")); |
|---|
| 2559 |
break; |
|---|
| 2560 |
case -1: |
|---|
| 2561 |
websWrite(wp, "%s", live_translate("share.unknown")); |
|---|
| 2562 |
break; |
|---|
| 2563 |
default: // 1: software disabled, 2: hardware |
|---|
| 2564 |
// disabled, 3: both are disabled |
|---|
| 2565 |
websWrite(wp, "%s", live_translate("wl_basic.radio_off")); |
|---|
| 2566 |
break; |
|---|
| 2567 |
} |
|---|
| 2568 |
#endif |
|---|
| 2569 |
} |
|---|
| 2570 |
|
|---|
| 2571 |
void ej_dumparptable(webs_t wp, int argc, char_t ** argv) |
|---|
| 2572 |
{ |
|---|
| 2573 |
FILE *f; |
|---|
| 2574 |
FILE *host; |
|---|
| 2575 |
FILE *conn; |
|---|
| 2576 |
char buf[256]; |
|---|
| 2577 |
char hostname[128]; |
|---|
| 2578 |
char ip[16]; |
|---|
| 2579 |
char ip2[20]; |
|---|
| 2580 |
char fullip[18]; |
|---|
| 2581 |
char mac[18]; |
|---|
| 2582 |
char landev[16]; |
|---|
| 2583 |
int count = 0; |
|---|
| 2584 |
int conn_count = 0; |
|---|
| 2585 |
|
|---|
| 2586 |
if ((f = fopen("/proc/net/arp", "r")) != NULL) { |
|---|
| 2587 |
while (fgets(buf, sizeof(buf), f)) { |
|---|
| 2588 |
if (sscanf |
|---|
| 2589 |
(buf, "%15s %*s %*s %17s %*s %s", ip, mac, |
|---|
| 2590 |
landev) != 3) |
|---|
| 2591 |
continue; |
|---|
| 2592 |
if ((strlen(mac) != 17) |
|---|
| 2593 |
|| (strcmp(mac, "00:00:00:00:00:00") == 0)) |
|---|
| 2594 |
continue; |
|---|
| 2595 |
if (strcmp(landev, nvram_safe_get("wan_iface")) == 0) |
|---|
| 2596 |
continue; // skip all but LAN arp entries |
|---|
| 2597 |
strcpy(hostname, "*"); // set name to * |
|---|
| 2598 |
|
|---|
| 2599 |
/* |
|---|
| 2600 |
* count open connections per IP |
|---|
| 2601 |
*/ |
|---|
| 2602 |
if ((conn = |
|---|
| 2603 |
fopen("/proc/net/ip_conntrack", "r")) != NULL) { |
|---|
| 2604 |
strcpy(ip2, ip); |
|---|
| 2605 |
strcat(ip2, " "); |
|---|
| 2606 |
|
|---|
| 2607 |
while (fgets(buf, sizeof(buf), conn)) { |
|---|
| 2608 |
if (strstr(buf, ip2)) |
|---|
| 2609 |
conn_count++; |
|---|
| 2610 |
} |
|---|
| 2611 |
fclose(conn); |
|---|
| 2612 |
} |
|---|
| 2613 |
|
|---|
| 2614 |
/* |
|---|
| 2615 |
* end count |
|---|
| 2616 |
*/ |
|---|
| 2617 |
|
|---|
| 2618 |
/* |
|---|
| 2619 |
* do nslookup |
|---|
| 2620 |
*/ |
|---|
| 2621 |
|
|---|
| 2622 |
// struct servent *servp; |
|---|
| 2623 |
// char buf1[256]; |
|---|
| 2624 |
// |
|---|
| 2625 |
// getHostName (buf1, ip); |
|---|
| 2626 |
// if (strcmp(buf1, "unknown")) |
|---|
| 2627 |
// strcpy (hostname, buf1); |
|---|
| 2628 |
/* |
|---|
| 2629 |
* end nslookup |
|---|
| 2630 |
*/ |
|---|
| 2631 |
|
|---|
| 2632 |
/* |
|---|
| 2633 |
* look into hosts file for hostnames (static leases) |
|---|
| 2634 |
*/ |
|---|
| 2635 |
if ((host = fopen("/tmp/hosts", "r")) != NULL |
|---|
| 2636 |
&& !strcmp(hostname, "*")) { |
|---|
| 2637 |
while (fgets(buf, sizeof(buf), host)) { |
|---|
| 2638 |
sscanf(buf, "%15s %*s", fullip); |
|---|
| 2639 |
|
|---|
| 2640 |
if (!strcmp(ip, fullip)) { |
|---|
| 2641 |
sscanf(buf, "%*15s %s", |
|---|
| 2642 |
hostname); |
|---|
| 2643 |
} |
|---|
| 2644 |
} |
|---|
| 2645 |
fclose(host); |
|---|
| 2646 |
} |
|---|
| 2647 |
/* |
|---|
| 2648 |
* end hosts file lookup |
|---|
| 2649 |
*/ |
|---|
| 2650 |
|
|---|
| 2651 |
/* |
|---|
| 2652 |
* check for dnsmasq leases in /tmp/dnsmasq.leases and /jffs/ if |
|---|
| 2653 |
* hostname is still unknown |
|---|
| 2654 |
*/ |
|---|
| 2655 |
|
|---|
| 2656 |
if (!strcmp(hostname, "*") |
|---|
| 2657 |
&& nvram_match("dhcp_dnsmasq", "1") |
|---|
| 2658 |
&& nvram_match("dhcpd_usenvram", "0")) { |
|---|
| 2659 |
if (!(host = fopen("/tmp/dnsmasq.leases", "r"))) |
|---|
| 2660 |
host = |
|---|
| 2661 |
fopen("/jffs/dnsmasq.leases", "r"); |
|---|
| 2662 |
|
|---|
| 2663 |
if (host) { |
|---|
| 2664 |
|
|---|
| 2665 |
while (fgets(buf, sizeof(buf), host)) { |
|---|
| 2666 |
sscanf(buf, "%*s %*s %15s %*s", |
|---|
| 2667 |
fullip); |
|---|
| 2668 |
|
|---|
| 2669 |
if (strcmp(ip, fullip) == 0) { |
|---|
| 2670 |
sscanf(buf, |
|---|
| 2671 |
"%*s %*s %*s %s", |
|---|
| 2672 |
hostname); |
|---|
| 2673 |
} |
|---|
| 2674 |
} |
|---|
| 2675 |
fclose(host); |
|---|
| 2676 |
} |
|---|
| 2677 |
} |
|---|
| 2678 |
/* |
|---|
| 2679 |
* end dnsmasq.leases check |
|---|
| 2680 |
*/ |
|---|
| 2681 |
|
|---|
| 2682 |
/* |
|---|
| 2683 |
* check nvram for dnsmasq leases in nvram if hostname is still |
|---|
| 2684 |
* unknown |
|---|
| 2685 |
*/ |
|---|
| 2686 |
|
|---|
| 2687 |
if (!strcmp(hostname, "*") |
|---|
| 2688 |
&& nvram_match("dhcp_dnsmasq", "1") |
|---|
| 2689 |
&& nvram_match("dhcpd_usenvram", "1")) { |
|---|
| 2690 |
sscanf(nvram_nget("dnsmasq_lease_%s", ip), |
|---|
| 2691 |
"%*s %*s %*s %s", hostname); |
|---|
| 2692 |
} |
|---|
| 2693 |
/* |
|---|
| 2694 |
* end nvram check |
|---|
| 2695 |
*/ |
|---|
| 2696 |
|
|---|
| 2697 |
websWrite(wp, "%c'%s','%s','%s','%d'", |
|---|
| 2698 |
(count ? ',' : ' '), hostname, ip, mac, |
|---|
| 2699 |
conn_count); |
|---|
| 2700 |
++count; |
|---|
| 2701 |
conn_count = 0; |
|---|
| 2702 |
} |
|---|
| 2703 |
fclose(f); |
|---|
| 2704 |
} |
|---|
| 2705 |
} |
|---|
| 2706 |
|
|---|
| 2707 |
#ifdef HAVE_EOP_TUNNEL |
|---|
| 2708 |
|
|---|
| 2709 |
void ej_show_eop_tunnels(webs_t wp, int argc, char_t ** argv) |
|---|
| 2710 |
{ |
|---|
| 2711 |
|
|---|
| 2712 |
int tun; |
|---|
| 2713 |
char temp[32]; |
|---|
| 2714 |
|
|---|
| 2715 |
for (tun = 1; tun < 11; tun++) { |
|---|
| 2716 |
|
|---|
| 2717 |
websWrite(wp, "<fieldset>\n"); |
|---|
| 2718 |
websWrite(wp, |
|---|
| 2719 |
"<legend><script type=\"text/javascript\">Capture(eoip.tunnel)</script> %d</legend>\n", |
|---|
| 2720 |
tun); |
|---|
| 2721 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2722 |
websWrite(wp, |
|---|
| 2723 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.srv)</script></div>\n"); |
|---|
| 2724 |
sprintf(temp, "oet%d_en", tun); |
|---|
| 2725 |
websWrite(wp, |
|---|
| 2726 |
"<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s onclick=\"show_layer_ext(this, 'idoet%d', true)\" /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 2727 |
temp, |
|---|
| 2728 |
(nvram_match(temp, "1") ? "checked=\"checked\"" : ""), |
|---|
| 2729 |
tun); |
|---|
| 2730 |
websWrite(wp, |
|---|
| 2731 |
"<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s onclick=\"show_layer_ext(this, 'idoet%d', false)\" /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 2732 |
temp, |
|---|
| 2733 |
(nvram_match(temp, "0") ? "checked=\"checked\"" : ""), |
|---|
| 2734 |
tun); |
|---|
| 2735 |
websWrite(wp, "</div>\n"); |
|---|
| 2736 |
websWrite(wp, "<div id=\"idoet%d\">\n", tun); |
|---|
| 2737 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2738 |
websWrite(wp, |
|---|
| 2739 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.remoteIP)</script></div>\n"); |
|---|
| 2740 |
websWrite(wp, |
|---|
| 2741 |
"<input type=\"hidden\" name=\"oet%d_rem\" value=\"0.0.0.0\"/>\n", |
|---|
| 2742 |
tun); |
|---|
| 2743 |
sprintf(temp, "oet%d_rem", tun); |
|---|
| 2744 |
websWrite(wp, |
|---|
| 2745 |
"<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_0\" onblur=\"valid_range(this,0,255,eoip.remoteIP)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_1\" onblur=\"valid_range(this,0,255,eoip.tunnelID)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_2\" onblur=\"valid_range(this,0,255,eoip.tunnelID)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_3\" onblur=\"valid_range(this,1,254,eoip.tunnelID)\" value=\"%d\" />\n", |
|---|
| 2746 |
temp, get_single_ip(nvram_safe_get(temp), 0), temp, |
|---|
| 2747 |
get_single_ip(nvram_safe_get(temp), 1), temp, |
|---|
| 2748 |
get_single_ip(nvram_safe_get(temp), 2), temp, |
|---|
| 2749 |
get_single_ip(nvram_safe_get(temp), 3)); |
|---|
| 2750 |
websWrite(wp, "</div>\n"); |
|---|
| 2751 |
/* |
|---|
| 2752 |
websWrite( wp, "<div class=\"setting\">\n" ); |
|---|
| 2753 |
websWrite( wp, |
|---|
| 2754 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.tunnelID)</script></div>\n" ); |
|---|
| 2755 |
sprintf( temp, "oet%d_id", tun ); |
|---|
| 2756 |
websWrite( wp, |
|---|
| 2757 |
"<input size=\"4\" maxlength=\"3\" class=\"num\" name=\"%s\" onblur=\"valid_range(this,0,999,eoip.tunnelID)\" value=\"%s\" />\n", |
|---|
| 2758 |
temp, nvram_get( temp ) ); |
|---|
| 2759 |
websWrite( wp, "</div>\n" ); |
|---|
| 2760 |
|
|---|
| 2761 |
websWrite( wp, "<div class=\"setting\">\n" ); |
|---|
| 2762 |
websWrite( wp, |
|---|
| 2763 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.comp)</script></div>\n" ); |
|---|
| 2764 |
sprintf( temp, "oet%d_comp", tun ); |
|---|
| 2765 |
websWrite( wp, |
|---|
| 2766 |
"<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 2767 |
temp, |
|---|
| 2768 |
( nvram_match( temp, "1" ) ? "checked=\"checked\"" : |
|---|
| 2769 |
"" ) ); |
|---|
| 2770 |
websWrite( wp, |
|---|
| 2771 |
"<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 2772 |
temp, |
|---|
| 2773 |
( nvram_match( temp, "0" ) ? "checked=\"checked\"" : |
|---|
| 2774 |
"" ) ); |
|---|
| 2775 |
websWrite( wp, "</div>\n" ); |
|---|
| 2776 |
websWrite( wp, "<div class=\"setting\">\n" ); |
|---|
| 2777 |
websWrite( wp, |
|---|
| 2778 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.passtos)</script></div>\n" ); |
|---|
| 2779 |
sprintf( temp, "oet%d_pt", tun ); |
|---|
| 2780 |
websWrite( wp, |
|---|
| 2781 |
"<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 2782 |
temp, |
|---|
| 2783 |
( nvram_match( temp, "1" ) ? "checked=\"checked\"" : |
|---|
| 2784 |
"" ) ); |
|---|
| 2785 |
websWrite( wp, |
|---|
| 2786 |
"<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 2787 |
temp, |
|---|
| 2788 |
( nvram_match( temp, "0" ) ? "checked=\"checked\"" : |
|---|
| 2789 |
"" ) ); |
|---|
| 2790 |
websWrite( wp, "</div>\n" ); |
|---|
| 2791 |
websWrite( wp, "<div class=\"setting\">\n" ); |
|---|
| 2792 |
websWrite( wp, |
|---|
| 2793 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.frag)</script></div>\n" ); |
|---|
| 2794 |
sprintf( temp, "oet%d_fragment", tun ); |
|---|
| 2795 |
websWrite( wp, |
|---|
| 2796 |
"<input size=\"4\" maxlength=\"4\" class=\"num\" name=\"%s\" onblur=\"valid_range(this,0,1500,eoip.frag)\" value=\"%s\" />\n", |
|---|
| 2797 |
temp, nvram_get( temp ) ); |
|---|
| 2798 |
websWrite( wp, "</div>\n" ); |
|---|
| 2799 |
websWrite( wp, "<div class=\"setting\">\n" ); |
|---|
| 2800 |
websWrite( wp, |
|---|
| 2801 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.mssfix)</script></div>\n" ); |
|---|
| 2802 |
sprintf( temp, "oet%d_mssfix", tun ); |
|---|
| 2803 |
websWrite( wp, |
|---|
| 2804 |
"<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 2805 |
temp, |
|---|
| 2806 |
( nvram_match( temp, "1" ) ? "checked=\"checked\"" : |
|---|
| 2807 |
"" ) ); |
|---|
| 2808 |
websWrite( wp, |
|---|
| 2809 |
"<input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 2810 |
temp, |
|---|
| 2811 |
( nvram_match( temp, "0" ) ? "checked=\"checked\"" : |
|---|
| 2812 |
"" ) ); |
|---|
| 2813 |
websWrite( wp, "</div>\n" ); |
|---|
| 2814 |
websWrite( wp, "<div class=\"setting\">\n" ); |
|---|
| 2815 |
websWrite( wp, |
|---|
| 2816 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.shaper)</script></div>\n" ); |
|---|
| 2817 |
sprintf( temp, "oet%d_shaper", tun ); |
|---|
| 2818 |
websWrite( wp, |
|---|
| 2819 |
"<input size=\"6\" maxlength=\"6\" class=\"num\" name=\"%s\" onblur=\"valid_range(this,0,100000,eoip.shaper)\" value=\"%s\" />\n", |
|---|
| 2820 |
temp, nvram_get( temp ) ); |
|---|
| 2821 |
websWrite( wp, "</div>\n" ); |
|---|
| 2822 |
*/ |
|---|
| 2823 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2824 |
websWrite(wp, |
|---|
| 2825 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(eoip.bridging)</script></div>\n"); |
|---|
| 2826 |
sprintf(temp, "oet%d_bridged", tun); |
|---|
| 2827 |
websWrite(wp, |
|---|
| 2828 |
"<input class=\"spaceradio\" type=\"radio\" value=\"1\" name=\"%s\" %s onclick=\"show_layer_ext(this, 'idbridged%d', false)\" /><script type=\"text/javascript\">Capture(share.enable)</script> \n", |
|---|
| 2829 |
temp, |
|---|
| 2830 |
(nvram_match(temp, "1") ? "checked=\"checked\"" : ""), |
|---|
| 2831 |
tun); |
|---|
| 2832 |
websWrite(wp, |
|---|
| 2833 |
" <input class=\"spaceradio\" type=\"radio\" value=\"0\" name=\"%s\" %s onclick=\"show_layer_ext(this, 'idbridged%d', true)\" /><script type=\"text/javascript\">Capture(share.disable)</script>\n", |
|---|
| 2834 |
temp, |
|---|
| 2835 |
(nvram_match(temp, "0") ? "checked=\"checked\"" : ""), |
|---|
| 2836 |
tun); |
|---|
| 2837 |
websWrite(wp, "</div>\n"); |
|---|
| 2838 |
websWrite(wp, "<div id=\"idbridged%d\">\n", tun); |
|---|
| 2839 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2840 |
websWrite(wp, |
|---|
| 2841 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(share.ip)</script></div>\n"); |
|---|
| 2842 |
websWrite(wp, |
|---|
| 2843 |
"<input type=\"hidden\" name=\"oet%d_ipaddr\" value=\"0.0.0.0\"/>\n", |
|---|
| 2844 |
tun); |
|---|
| 2845 |
sprintf(temp, "oet%d_ipaddr", tun); |
|---|
| 2846 |
websWrite(wp, |
|---|
| 2847 |
"<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_0\" onblur=\"valid_range(this,0,255,share.ip)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_1\" onblur=\"valid_range(this,0,255,share.ip)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_2\" onblur=\"valid_range(this,0,255,share.ip)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_3\" onblur=\"valid_range(this,1,254,share.ip)\" value=\"%d\" />\n", |
|---|
| 2848 |
temp, get_single_ip(nvram_safe_get(temp), 0), temp, |
|---|
| 2849 |
get_single_ip(nvram_safe_get(temp), 1), temp, |
|---|
| 2850 |
get_single_ip(nvram_safe_get(temp), 2), temp, |
|---|
| 2851 |
get_single_ip(nvram_safe_get(temp), 3)); |
|---|
| 2852 |
websWrite(wp, "</div>\n"); |
|---|
| 2853 |
websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 2854 |
websWrite(wp, |
|---|
| 2855 |
"<div class=\"label\"><script type=\"text/javascript\">Capture(share.subnet)</script></div>\n"); |
|---|
| 2856 |
websWrite(wp, |
|---|
| 2857 |
"<input type=\"hidden\" name=\"oet%d_netmask\" value=\"0.0.0.0\"/>\n", |
|---|
| 2858 |
tun); |
|---|
| 2859 |
sprintf(temp, "oet%d_netmask", tun); |
|---|
| 2860 |
websWrite(wp, |
|---|
| 2861 |
"<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_0\" onblur=\"valid_range(this,0,255,share.subnet)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_1\" onblur=\"valid_range(this,0,255,share.subnet)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_2\" onblur=\"valid_range(this,0,255,share.subnet)\" value=\"%d\" />.<input size=\"3\" maxlength=\"3\" class=\"num\" name=\"%s_3\" onblur=\"valid_range(this,0,254,share.subnet)\" value=\"%d\" />\n", |
|---|
| 2862 |
temp, get_single_ip(nvram_safe_get(temp), 0), temp, |
|---|
| 2863 |
get_single_ip(nvram_safe_get(temp), 1), temp, |
|---|
| 2864 |
get_single_ip(nvram_safe_get(temp), 2), temp, |
|---|
| 2865 |
get_single_ip(nvram_safe_get(temp), 3)); |
|---|
| 2866 |
websWrite(wp, "</div>\n"); |
|---|
| 2867 |
websWrite(wp, "</div>\n"); |
|---|
| 2868 |
websWrite(wp, "</div>\n"); |
|---|
| 2869 |
websWrite(wp, "</fieldset><br/>\n"); |
|---|
| 2870 |
} |
|---|
| 2871 |
} |
|---|
| 2872 |
|
|---|
| 2873 |
#endif |
|---|
| 2874 |
|
|---|
| 2875 |
// web-writes html escaped (&#xxx;) nvram entries / test buffered |
|---|
| 2876 |
int tf_webWriteESCNV(webs_t wp, const char *nvname) |
|---|
| 2877 |
{ |
|---|
| 2878 |
char buf[512]; |
|---|
| 2879 |
int n; |
|---|
| 2880 |
int r; |
|---|
| 2881 |
const char *c; |
|---|
| 2882 |
|
|---|
| 2883 |
n = 0; |
|---|
| 2884 |
r = 0; |
|---|
| 2885 |
for (c = nvram_safe_get(nvname); *c; c++) { |
|---|
| 2886 |
if ((isprint(*c)) && (*c != '"') && (*c != '&') |
|---|
| 2887 |
&& (*c != '<') && (*c != '>') && (*c != '\'') |
|---|
| 2888 |
&& (*c != '\\')) { |
|---|
| 2889 |
buf[n++] = *c; |
|---|
| 2890 |
} else { |
|---|
| 2891 |
sprintf(buf + n, "&#%d;", *c); |
|---|
| 2892 |
n += strlen(buf + n); |
|---|
| 2893 |
} |
|---|
| 2894 |
if (n > (sizeof(buf) - 10)) { // ! extra space for &... |
|---|
| 2895 |
buf[n] = 0; |
|---|
| 2896 |
n = 0; |
|---|
| 2897 |
r += wfputs(buf, wp); |
|---|
| 2898 |
} |
|---|
| 2899 |
} |
|---|
| 2900 |
if (n > 0) { |
|---|
| 2901 |
buf[n] = 0; |
|---|
| 2902 |
r += wfputs(buf, wp); |
|---|
| 2903 |
} |
|---|
| 2904 |
wfflush(wp); |
|---|
| 2905 |
return r; |
|---|
| 2906 |
} |
|---|
| 2907 |
|
|---|
| 2908 |
int tf_webWriteJS(webs_t wp, const char *s) |
|---|
| 2909 |
{ |
|---|
| 2910 |
char buf[512]; |
|---|
| 2911 |
int n; |
|---|
| 2912 |
int r; |
|---|
| 2913 |
|
|---|
| 2914 |
n = 0; |
|---|
| 2915 |
r = 0; |
|---|
| 2916 |
for (; *s; s++) { |
|---|
| 2917 |
if (*s == '<') { |
|---|
| 2918 |
sprintf(buf + n, "<"); |
|---|
| 2919 |
n += 4; |
|---|
| 2920 |
} else if (*s == '>') { |
|---|
| 2921 |
sprintf(buf + n, ">"); |
|---|
| 2922 |
n += 4; |
|---|
| 2923 |
} else if ((*s != '"') && (*s != '\\') && (*s != '/') |
|---|
| 2924 |
&& (*s != '*') && (*s != '\'') && (isprint(*s))) { |
|---|
| 2925 |
buf[n++] = *s; |
|---|
| 2926 |
} else { |
|---|
| 2927 |
sprintf(buf + n, "\\x%02x", *s); |
|---|
| 2928 |
n += 4; |
|---|
| 2929 |
} |
|---|
| 2930 |
if (n > (sizeof(buf) - 10)) { // ! extra space for \xHH |
|---|
| 2931 |
buf[n] = 0; |
|---|
| 2932 |
n = 0; |
|---|
| 2933 |
r += wfputs(buf, wp); |
|---|
| 2934 |
} |
|---|
| 2935 |
} |
|---|
| 2936 |
if (n > 0) { |
|---|
| 2937 |
buf[n] = 0; |
|---|
| 2938 |
r += wfputs(buf, wp); |
|---|
| 2939 |
} |
|---|
| 2940 |
wfflush(wp); |
|---|
| 2941 |
return r; |
|---|
| 2942 |
} |
|---|
| 2943 |
|
|---|
| 2944 |
#ifdef HAVE_UPNP |
|---|
| 2945 |
// changed by steve |
|---|
| 2946 |
// writes javascript-string safe text |
|---|
| 2947 |
|
|---|
| 2948 |
// <% tf_upnp(); %> |
|---|
| 2949 |
// returns all "forward_port#" nvram entries containing upnp port forwardings |
|---|
| 2950 |
void ej_tf_upnp(webs_t wp, int argc, char_t ** argv) |
|---|
| 2951 |
{ |
|---|
| 2952 |
int i; |
|---|
| 2953 |
int len, pos, count; |
|---|
| 2954 |
char *temp; |
|---|
| 2955 |
|
|---|
| 2956 |
if (nvram_match("upnp_enable", "1")) { |
|---|
| 2957 |
for (i = 0; i < 50; i++) { |
|---|
| 2958 |
websWrite(wp, (i > 0) ? ",'" : "'"); |
|---|
| 2959 |
|
|---|
| 2960 |
// fix: some entries are missing the desc. - this breaks the |
|---|
| 2961 |
// upnp.asp page, so we add ,* |
|---|
| 2962 |
temp = nvram_nget("forward_port%d", i); |
|---|
| 2963 |
count = 0; |
|---|
| 2964 |
len = strlen(temp); |
|---|
| 2965 |
|
|---|
| 2966 |
for (pos = len; pos != 0; pos--) { |
|---|
| 2967 |
if (temp[pos] == ',') |
|---|
| 2968 |
count++; |
|---|
| 2969 |
} |
|---|
| 2970 |
|
|---|
| 2971 |
tf_webWriteJS(wp, temp); |
|---|
| 2972 |
if (count == 2) |
|---|
| 2973 |
websWrite(wp, ",*"); |
|---|
| 2974 |
|
|---|
| 2975 |
websWrite(wp, "'"); |
|---|
| 2976 |
} |
|---|
| 2977 |
} |
|---|
| 2978 |
} |
|---|
| 2979 |
|
|---|
| 2980 |
// end changed by steve |
|---|
| 2981 |
#endif |
|---|