| 1 | |
|---|
| 2 | /* |
|---|
| 3 | * Broadcom Home Gateway Reference Design |
|---|
| 4 | * Web Page Configuration Support Routines |
|---|
| 5 | * |
|---|
| 6 | * Copyright 2001-2003, Broadcom Corporation |
|---|
| 7 | * All Rights Reserved. |
|---|
| 8 | * |
|---|
| 9 | * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY |
|---|
| 10 | * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM |
|---|
| 11 | * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS |
|---|
| 12 | * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. |
|---|
| 13 | * $Id: broadcom.c,v 1.9 2005/11/30 11:53:42 seg Exp $ |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #ifdef WEBS |
|---|
| 17 | #include <webs.h> |
|---|
| 18 | #include <uemf.h> |
|---|
| 19 | #include <ej.h> |
|---|
| 20 | #else /* !WEBS */ |
|---|
| 21 | #include <stdio.h> |
|---|
| 22 | #include <stdlib.h> |
|---|
| 23 | #include <string.h> |
|---|
| 24 | #include <ctype.h> |
|---|
| 25 | #include <unistd.h> |
|---|
| 26 | #include <limits.h> |
|---|
| 27 | #include <sys/types.h> |
|---|
| 28 | #include <sys/stat.h> |
|---|
| 29 | #include <sys/socket.h> |
|---|
| 30 | #include <netinet/in.h> |
|---|
| 31 | #include <arpa/inet.h> |
|---|
| 32 | #include <httpd.h> |
|---|
| 33 | #include <errno.h> |
|---|
| 34 | #endif /* WEBS */ |
|---|
| 35 | |
|---|
| 36 | #include <proto/ethernet.h> |
|---|
| 37 | #include <fcntl.h> |
|---|
| 38 | #include <signal.h> |
|---|
| 39 | #include <time.h> |
|---|
| 40 | #include <sys/klog.h> |
|---|
| 41 | #include <sys/wait.h> |
|---|
| 42 | #include <cyutils.h> |
|---|
| 43 | #include <support.h> |
|---|
| 44 | #include <cy_conf.h> |
|---|
| 45 | // #ifdef EZC_SUPPORT |
|---|
| 46 | #include <ezc.h> |
|---|
| 47 | // #endif |
|---|
| 48 | #include <broadcom.h> |
|---|
| 49 | #include <wlutils.h> |
|---|
| 50 | #include <netdb.h> |
|---|
| 51 | #include <utils.h> |
|---|
| 52 | #include <dlfcn.h> |
|---|
| 53 | |
|---|
| 54 | int debug_value = 0; |
|---|
| 55 | |
|---|
| 56 | // static char * rfctime(const time_t *timep); |
|---|
| 57 | // static char * reltime(unsigned int seconds); |
|---|
| 58 | |
|---|
| 59 | // #if defined(linux) |
|---|
| 60 | |
|---|
| 61 | #include <fcntl.h> |
|---|
| 62 | #include <signal.h> |
|---|
| 63 | #include <time.h> |
|---|
| 64 | #include <sys/klog.h> |
|---|
| 65 | #include <sys/wait.h> |
|---|
| 66 | #define sys_stats(url) eval("stats", (url)) |
|---|
| 67 | |
|---|
| 68 | // tofu |
|---|
| 69 | |
|---|
| 70 | char *live_translate(char *tran); |
|---|
| 71 | #ifdef HAVE_BUFFALO |
|---|
| 72 | void do_vsp_page(struct mime_handler *handler, char *url, webs_t stream, |
|---|
| 73 | char *query); |
|---|
| 74 | #endif |
|---|
| 75 | /* |
|---|
| 76 | * Deal with side effects before committing |
|---|
| 77 | */ |
|---|
| 78 | int sys_commit(void) |
|---|
| 79 | { |
|---|
| 80 | if (nvram_match("dhcpnvram", "1")) { |
|---|
| 81 | killall("dnsmasq", SIGUSR2); // update lease -- tofu |
|---|
| 82 | sleep(1); |
|---|
| 83 | } |
|---|
| 84 | // if (nvram_match("wan_proto", "pppoe") || nvram_match("wan_proto", |
|---|
| 85 | // "pptp") ) |
|---|
| 86 | // nvram_set("wan_ifname", "ppp0"); |
|---|
| 87 | // else |
|---|
| 88 | // nvram_set("wan_ifname", nvram_get("pppoe_ifname")); |
|---|
| 89 | return nvram_commit(); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | /* |
|---|
| 93 | * Variables are set in order (put dependent variables later). Set |
|---|
| 94 | * nullok to TRUE to ignore zero-length values of the variable itself. |
|---|
| 95 | * For more complicated validation that cannot be done in one pass or |
|---|
| 96 | * depends on additional form components or can throw an error in a |
|---|
| 97 | * unique painful way, write your own validation routine and assign it |
|---|
| 98 | * to a hidden variable (e.g. filter_ip). |
|---|
| 99 | */ |
|---|
| 100 | /* |
|---|
| 101 | * DD-WRT enhancement by seg This functions parses all |
|---|
| 102 | * /etc/config/xxxxx.nvramconfig files and creates the web var tab. so these |
|---|
| 103 | * vars arent defined anymore staticly |
|---|
| 104 | */ |
|---|
| 105 | |
|---|
| 106 | #include <stdlib.h> |
|---|
| 107 | #include <malloc.h> |
|---|
| 108 | #include <dirent.h> |
|---|
| 109 | #include <stdlib.h> |
|---|
| 110 | |
|---|
| 111 | char *toUP(char *a) |
|---|
| 112 | { |
|---|
| 113 | int i; |
|---|
| 114 | int slen = strlen(a); |
|---|
| 115 | |
|---|
| 116 | for (i = 0; i < slen; i++) { |
|---|
| 117 | if (a[i] > 'a' - 1 && a[i] < 'z' + 1) |
|---|
| 118 | a[i] -= 'a' + 'A'; |
|---|
| 119 | } |
|---|
| 120 | return a; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | int stricmp(char *a, char *b) |
|---|
| 124 | { |
|---|
| 125 | if (strlen(a) != strlen(b)) |
|---|
| 126 | return -1; |
|---|
| 127 | return strcmp(toUP(a), toUP(b)); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | void StringStart(FILE * in) |
|---|
| 131 | { |
|---|
| 132 | while (getc(in) != '"') { |
|---|
| 133 | if (feof(in)) |
|---|
| 134 | return; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | char *getFileString(FILE * in) |
|---|
| 139 | { |
|---|
| 140 | char *buf; |
|---|
| 141 | int i, b; |
|---|
| 142 | |
|---|
| 143 | buf = safe_malloc(1024); |
|---|
| 144 | StringStart(in); |
|---|
| 145 | for (i = 0; i < 1024; i++) { |
|---|
| 146 | b = getc(in); |
|---|
| 147 | if (b == EOF) |
|---|
| 148 | return NULL; |
|---|
| 149 | if (b == '"') { |
|---|
| 150 | buf[i] = 0; |
|---|
| 151 | buf = realloc(buf, strlen(buf) + 1); |
|---|
| 152 | return buf; |
|---|
| 153 | } |
|---|
| 154 | buf[i] = b; |
|---|
| 155 | } |
|---|
| 156 | return buf; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | void skipFileString(FILE * in) |
|---|
| 160 | { |
|---|
| 161 | int i, b; |
|---|
| 162 | |
|---|
| 163 | StringStart(in); |
|---|
| 164 | for (i = 0; i < 1024; i++) { |
|---|
| 165 | b = getc(in); |
|---|
| 166 | if (b == EOF) |
|---|
| 167 | return; |
|---|
| 168 | if (b == '"') { |
|---|
| 169 | return; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | return; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | static char *directories[] = { |
|---|
| 176 | "/etc/config", |
|---|
| 177 | "/jffs/etc/config", |
|---|
| 178 | "/mmc/etc/config" |
|---|
| 179 | }; |
|---|
| 180 | |
|---|
| 181 | struct SIMPLEVAL { |
|---|
| 182 | char *name; |
|---|
| 183 | char *validator; |
|---|
| 184 | int args; |
|---|
| 185 | }; |
|---|
| 186 | |
|---|
| 187 | struct variable **variables; |
|---|
| 188 | void Initnvramtab() |
|---|
| 189 | { |
|---|
| 190 | struct dirent *entry; |
|---|
| 191 | DIR *directory; |
|---|
| 192 | FILE *in; |
|---|
| 193 | int varcount = 0, len, i; |
|---|
| 194 | char *tmpstr; |
|---|
| 195 | struct variable *tmp; |
|---|
| 196 | static struct SIMPLEVAL simpleval[] = { |
|---|
| 197 | {"WMEPARAM", "validate_wl_wme_params", 0}, |
|---|
| 198 | {"WMETXPARAM", "validate_wl_wme_tx_params", 0}, |
|---|
| 199 | {"WANIPADDR", "validate_wan_ipaddr", 0}, |
|---|
| 200 | {"MERGEREMOTEIP", "validate_remote_ip", 0}, |
|---|
| 201 | {"MERGEIPADDRS", "validate_merge_ipaddrs", 0}, |
|---|
| 202 | {"DNS", "validate_dns", 0}, |
|---|
| 203 | {"SAVEWDS", "save_wds", 0}, |
|---|
| 204 | {"DHCP", "dhcp_check", 0}, |
|---|
| 205 | {"STATICS", "validate_statics", 0}, |
|---|
| 206 | #ifdef HAVE_PORTSETUP |
|---|
| 207 | {"PORTSETUP", "validate_portsetup", 0}, |
|---|
| 208 | #endif |
|---|
| 209 | {"REBOOT", "validate_reboot", 0}, |
|---|
| 210 | {"IPADDR", "validate_ipaddr", 0}, |
|---|
| 211 | {"STATICLEASES", "validate_staticleases", 0}, |
|---|
| 212 | #ifdef HAVE_CHILLILOCAL |
|---|
| 213 | {"USERLIST", "validate_userlist", 0}, |
|---|
| 214 | #endif |
|---|
| 215 | #ifdef HAVE_RADLOCAL |
|---|
| 216 | {"IRADIUSUSERLIST", "validate_iradius", 0}, |
|---|
| 217 | #endif |
|---|
| 218 | {"IPADDRS", "validate_ipaddrs", 0}, |
|---|
| 219 | {"NETMASK", "validate_netmask", 0}, |
|---|
| 220 | {"MERGENETMASK", "validate_merge_netmask", 0}, |
|---|
| 221 | {"WDS", "validate_wds", 0}, |
|---|
| 222 | {"STATICROUTE", "validate_static_route", 0}, |
|---|
| 223 | {"MERGEMAC", "validate_merge_mac", 0}, |
|---|
| 224 | {"FILTERPOLICY", "validate_filter_policy", 0}, |
|---|
| 225 | {"FILTERIPGRP", "validate_filter_ip_grp", 0}, |
|---|
| 226 | {"FILTERPORT", "validate_filter_port", 0}, |
|---|
| 227 | {"FILTERDPORTGRP", "validate_filter_dport_grp", 0}, |
|---|
| 228 | {"BLOCKEDSERVICE", "validate_blocked_service", 0}, |
|---|
| 229 | {"FILTERP2P", "validate_catchall", 0}, |
|---|
| 230 | {"FILTERMACGRP", "validate_filter_mac_grp", 0}, |
|---|
| 231 | {"FILTERWEB", "validate_filter_web", 0}, |
|---|
| 232 | {"WLHWADDRS", "validate_wl_hwaddrs", 0}, |
|---|
| 233 | {"FORWARDPROTO", "validate_forward_proto", 0}, |
|---|
| 234 | {"FORWARDSPEC", "validate_forward_spec", 0}, |
|---|
| 235 | {"PORTTRIGGER", "validate_port_trigger", 0}, |
|---|
| 236 | {"HWADDR", "validate_hwaddr", 0}, |
|---|
| 237 | {"HWADDRS", "validate_hwaddrs", 0}, |
|---|
| 238 | {"WLWEPKEY", "validate_wl_wep_key", 0}, |
|---|
| 239 | #ifdef HAVE_PPPOESERVER |
|---|
| 240 | {"CHAPTABLE", "validate_chaps", 0}, |
|---|
| 241 | #endif |
|---|
| 242 | #ifdef HAVE_MILKFISH |
|---|
| 243 | {"MFSUBSCRIBERS", "validate_subscribers", 0}, |
|---|
| 244 | {"MFALIASES", "validate_aliases", 0}, |
|---|
| 245 | #endif |
|---|
| 246 | {"RANGE", "validate_range", 2}, |
|---|
| 247 | {"CHOICE", "validate_choice", -1}, |
|---|
| 248 | {"NOACK", "validate_noack", 2}, |
|---|
| 249 | {"NAME", "validate_name", 1}, |
|---|
| 250 | {"PASSWORD", "validate_password", 1}, |
|---|
| 251 | {"PASSWORD2", "validate_password2", 1}, |
|---|
| 252 | {"LANIPADDR", "validate_lan_ipaddr", 1}, |
|---|
| 253 | {"WPAPSK", "validate_wpa_psk", 1}, |
|---|
| 254 | {"WLAUTH", "validate_wl_auth", 2}, |
|---|
| 255 | {"WLWEP", "validate_wl_wep", -1}, |
|---|
| 256 | {"DYNAMICROUTE", "validate_dynamic_route", -1}, |
|---|
| 257 | {"WLGMODE", "validate_wl_gmode", -1}, |
|---|
| 258 | {"WLNETMODE", "validate_wl_net_mode", -1}, |
|---|
| 259 | {"AUTHMODE", "validate_auth_mode", -1}, |
|---|
| 260 | {NULL, NULL}, |
|---|
| 261 | }; |
|---|
| 262 | |
|---|
| 263 | variables = NULL; |
|---|
| 264 | char buf[1024]; |
|---|
| 265 | |
|---|
| 266 | // format = VARNAME VARDESC VARVALID VARVALIDARGS FLAGS FLAGS |
|---|
| 267 | // open config directory directory = |
|---|
| 268 | int idx; |
|---|
| 269 | |
|---|
| 270 | for (idx = 0; idx < 3; idx++) { |
|---|
| 271 | directory = opendir(directories[idx]); |
|---|
| 272 | if (directory == NULL) |
|---|
| 273 | continue; |
|---|
| 274 | // list all files in this directory |
|---|
| 275 | while ((entry = readdir(directory)) != NULL) { |
|---|
| 276 | if (endswith(entry->d_name, ".nvramconfig")) { |
|---|
| 277 | sprintf(buf, "%s/%s", directories[idx], |
|---|
| 278 | entry->d_name); |
|---|
| 279 | in = fopen(buf, "rb"); |
|---|
| 280 | if (in == NULL) { |
|---|
| 281 | return; |
|---|
| 282 | } |
|---|
| 283 | while (1) { |
|---|
| 284 | tmp = (struct variable *) |
|---|
| 285 | safe_malloc(sizeof |
|---|
| 286 | (struct variable)); |
|---|
| 287 | memset(tmp, 0, sizeof(struct variable)); |
|---|
| 288 | tmp->name = getFileString(in); |
|---|
| 289 | if (tmp->name == NULL) |
|---|
| 290 | break; |
|---|
| 291 | skipFileString(in); // long string |
|---|
| 292 | tmpstr = getFileString(in); |
|---|
| 293 | tmp->argv = NULL; |
|---|
| 294 | if (!stricmp(tmpstr, "NULL")) { |
|---|
| 295 | } |
|---|
| 296 | #ifdef HAVE_SPUTNIK_APD |
|---|
| 297 | if (!stricmp(tmpstr, "MJIDTYPE")) { |
|---|
| 298 | tmp->validatename = |
|---|
| 299 | "validate_choice"; |
|---|
| 300 | free(tmpstr); |
|---|
| 301 | tmpstr = getFileString(in); |
|---|
| 302 | len = atoi(tmpstr); |
|---|
| 303 | tmp->argv = (char **) |
|---|
| 304 | safe_malloc(sizeof(char **) |
|---|
| 305 | * (len + 1)); |
|---|
| 306 | for (i = 0; i < len; i++) { |
|---|
| 307 | tmp->argv[i] = |
|---|
| 308 | getFileString(in); |
|---|
| 309 | } |
|---|
| 310 | tmp->argv[i] = NULL; |
|---|
| 311 | nvram_set("sputnik_rereg", "1"); |
|---|
| 312 | } |
|---|
| 313 | #endif |
|---|
| 314 | if (tmp->validatename == NULL) { |
|---|
| 315 | int scount = 0; |
|---|
| 316 | while (simpleval[scount].name != NULL) { // |
|---|
| 317 | if (!stricmp(tmpstr, simpleval[scount].name)) { // |
|---|
| 318 | // fprintf(stderr,"match %s %s\n",tmpstr,tmp->name); |
|---|
| 319 | tmp->validatename = simpleval[scount].validator; // |
|---|
| 320 | int arglen = 0; |
|---|
| 321 | if (simpleval[scount].args == -1) { // |
|---|
| 322 | free(tmpstr); |
|---|
| 323 | tmpstr = getFileString(in); // |
|---|
| 324 | arglen = atoi(tmpstr); // |
|---|
| 325 | } |
|---|
| 326 | if (simpleval[scount].args > 0) { // |
|---|
| 327 | arglen = simpleval[scount].args; // |
|---|
| 328 | } |
|---|
| 329 | if (arglen) { // |
|---|
| 330 | tmp->argv = (char **)safe_malloc(sizeof(char **) * (arglen + 1)); // |
|---|
| 331 | for (i = 0; i < arglen; i++) { // |
|---|
| 332 | tmp->argv[i] = getFileString(in); // |
|---|
| 333 | } |
|---|
| 334 | tmp->argv[arglen] = NULL; // |
|---|
| 335 | |
|---|
| 336 | } |
|---|
| 337 | break; |
|---|
| 338 | } |
|---|
| 339 | scount++; |
|---|
| 340 | } |
|---|
| 341 | // if (simpleval[scount].name == |
|---|
| 342 | // NULL) { |
|---|
| 343 | // fprintf(stderr, |
|---|
| 344 | // "danger %s is missing\n", |
|---|
| 345 | // tmpstr); |
|---|
| 346 | // } |
|---|
| 347 | } |
|---|
| 348 | free(tmpstr); |
|---|
| 349 | tmpstr = getFileString(in); |
|---|
| 350 | if (!stricmp(tmpstr, "TRUE")) { |
|---|
| 351 | tmp->nullok = TRUE; |
|---|
| 352 | } else { |
|---|
| 353 | tmp->nullok = FALSE; |
|---|
| 354 | } |
|---|
| 355 | free(tmpstr); |
|---|
| 356 | skipFileString(in); // todo: remove it |
|---|
| 357 | // tmpstr = getFileString (in); |
|---|
| 358 | // tmp->ezc_flags = atoi (tmpstr); |
|---|
| 359 | // free (tmpstr); |
|---|
| 360 | variables = (struct variable **) |
|---|
| 361 | realloc(variables, |
|---|
| 362 | sizeof(struct variable **) * |
|---|
| 363 | (varcount + 2)); |
|---|
| 364 | variables[varcount++] = tmp; |
|---|
| 365 | variables[varcount] = NULL; |
|---|
| 366 | } |
|---|
| 367 | fclose(in); |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | closedir(directory); |
|---|
| 371 | } |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | #ifdef HAVE_MACBIND |
|---|
| 375 | #include "../../../opt/mac.h" |
|---|
| 376 | #endif |
|---|
| 377 | // Added by Daniel(2004-07-29) for EZC |
|---|
| 378 | int variables_arraysize(void) |
|---|
| 379 | { |
|---|
| 380 | int varcount = 0; |
|---|
| 381 | |
|---|
| 382 | if (variables == NULL) |
|---|
| 383 | return 0; |
|---|
| 384 | while (variables[varcount] != NULL) { |
|---|
| 385 | varcount++; |
|---|
| 386 | } |
|---|
| 387 | // return ARRAYSIZE(variables); |
|---|
| 388 | return varcount; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | // and now the tricky part (more dirty as dirty) |
|---|
| 392 | void do_filtertable(struct mime_handler *handler, char *path, webs_t stream, |
|---|
| 393 | char *query) |
|---|
| 394 | { |
|---|
| 395 | char *temp2 = &path[indexof(path, '-') + 1]; |
|---|
| 396 | char ifname[16]; |
|---|
| 397 | |
|---|
| 398 | strcpy(ifname, temp2); |
|---|
| 399 | |
|---|
| 400 | char *temp3 = websGetVar(stream, "ifname", NULL); |
|---|
| 401 | if (temp3 != NULL) { |
|---|
| 402 | if (strlen(temp3) > 0) { |
|---|
| 403 | strcpy(ifname, temp3); |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | ifname[indexof(ifname, '.')] = 0; |
|---|
| 408 | FILE *web = getWebsFile("WL_FilterTable.asp"); |
|---|
| 409 | char temp[4096]; |
|---|
| 410 | |
|---|
| 411 | memset(temp, 0, 4096); |
|---|
| 412 | unsigned int len = getWebsFileLen("WL_FilterTable.asp"); |
|---|
| 413 | char *webfile = (char *)safe_malloc(len + 1); |
|---|
| 414 | |
|---|
| 415 | fread(webfile, len, 1, web); |
|---|
| 416 | webfile[len] = 0; |
|---|
| 417 | rep(ifname, '.', 'X'); |
|---|
| 418 | sprintf(temp, webfile, ifname, ifname, ifname, ifname, ifname, ifname); |
|---|
| 419 | free(webfile); |
|---|
| 420 | fclose(web); |
|---|
| 421 | do_ej_buffer(temp, stream); |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | #ifdef HAVE_FREERADIUS |
|---|
| 425 | #include <radiusdb.h> |
|---|
| 426 | |
|---|
| 427 | static void cert_file_out(struct mime_handler *handler, char *path, |
|---|
| 428 | webs_t stream, char *query) |
|---|
| 429 | { |
|---|
| 430 | char *temp2 = &path[indexof(path, '/') + 1]; |
|---|
| 431 | fprintf(stderr, "down %s\n", temp2); |
|---|
| 432 | char link[128]; |
|---|
| 433 | sprintf(link, "/jffs/etc/freeradius/certs/clients/%s", temp2); |
|---|
| 434 | do_file_attach(handler, link, stream, NULL, temp2); |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | static void show_certfield(webs_t wp, char *title, char *file) |
|---|
| 438 | { |
|---|
| 439 | websWrite(wp, "<div class=\"setting\">\n"); |
|---|
| 440 | websWrite(wp, "<div class=\"label\">%s</div>\n", title); |
|---|
| 441 | websWrite(wp, "<script type=\"text/javascript\">\n"); |
|---|
| 442 | websWrite(wp, "//<![CDATA[\n"); |
|---|
| 443 | websWrite(wp, |
|---|
| 444 | "document.write(\"<input class=\\\"button\\\" type=\\\"button\\\" name=\\\"download_button\\\" value=\\\"\" + sbutton.download + \"\\\" onclick=\\\"window.location.href='/freeradius-certs/%s';\\\" />\");\n", |
|---|
| 445 | file); |
|---|
| 446 | websWrite(wp, "//]]>\n"); |
|---|
| 447 | websWrite(wp, "</script>\n"); |
|---|
| 448 | websWrite(wp, "</div>\n"); |
|---|
| 449 | |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | void do_radiuscert(struct mime_handler *handler, char *path, webs_t stream, |
|---|
| 453 | char *query) |
|---|
| 454 | { |
|---|
| 455 | char *temp2 = &path[indexof(path, '-') + 1]; |
|---|
| 456 | char number[16]; |
|---|
| 457 | webs_t wp = stream; |
|---|
| 458 | strcpy(number, temp2); |
|---|
| 459 | number[indexof(number, '.')] = 0; |
|---|
| 460 | int radiusindex = atoi(number); |
|---|
| 461 | |
|---|
| 462 | if (radiusindex == -1) |
|---|
| 463 | return; |
|---|
| 464 | struct radiusdb *db = loadradiusdb(); |
|---|
| 465 | if (db == NULL) // database empty |
|---|
| 466 | return; |
|---|
| 467 | if (radiusindex >= db->usercount) // index out of bound |
|---|
| 468 | { |
|---|
| 469 | goto out; |
|---|
| 470 | } |
|---|
| 471 | if (db->users[radiusindex].usersize == 0 |
|---|
| 472 | || db->users[radiusindex].passwordsize == 0 |
|---|
| 473 | || strlen(db->users[radiusindex].user) == 0 |
|---|
| 474 | || strlen(db->users[radiusindex].passwd) == 0) { |
|---|
| 475 | //define username fail |
|---|
| 476 | char *argv[] = { "freeradius.clientcert" }; |
|---|
| 477 | call_ej("do_pagehead", NULL, wp, 1, argv); // thats dirty |
|---|
| 478 | websWrite(wp, "</head>\n" |
|---|
| 479 | "<body>\n" |
|---|
| 480 | "<div id=\"main\">\n" "<div id=\"contentsInfo\">\n" |
|---|
| 481 | "<h2>%s</h2>\n" |
|---|
| 482 | "Error: please specify a value username and password\n" |
|---|
| 483 | "<div class=\"submitFooter\">\n" |
|---|
| 484 | "<script type=\"text/javascript\">\n" |
|---|
| 485 | "//<![CDATA[\n" |
|---|
| 486 | "submitFooterButton(0,0,0,0,0,1);\n" |
|---|
| 487 | "//]]>\n" |
|---|
| 488 | "</script>\n" |
|---|
| 489 | "</div>\n" |
|---|
| 490 | "</div>\n" |
|---|
| 491 | "</div>\n" |
|---|
| 492 | "</body>\n" |
|---|
| 493 | "</html>\n", live_translate("freeradius.clientcert")); |
|---|
| 494 | goto out; |
|---|
| 495 | } |
|---|
| 496 | char filename[128]; |
|---|
| 497 | char exec[512]; |
|---|
| 498 | int generate = 0; |
|---|
| 499 | sprintf(filename, "/jffs/etc/freeradius/certs/clients/%s-cert.pem", |
|---|
| 500 | db->users[radiusindex].user); |
|---|
| 501 | if (!f_exists(filename)) |
|---|
| 502 | generate = 1; |
|---|
| 503 | sprintf(filename, "/jffs/etc/freeradius/certs/clients/%s-cert.p12", |
|---|
| 504 | db->users[radiusindex].user); |
|---|
| 505 | if (!f_exists(filename)) |
|---|
| 506 | generate = 1; |
|---|
| 507 | sprintf(filename, "/jffs/etc/freeradius/certs/clients/%s-key.pem", |
|---|
| 508 | db->users[radiusindex].user); |
|---|
| 509 | if (!f_exists(filename)) |
|---|
| 510 | generate = 1; |
|---|
| 511 | sprintf(filename, "/jffs/etc/freeradius/certs/clients/%s-req.pem", |
|---|
| 512 | db->users[radiusindex].user); |
|---|
| 513 | if (!f_exists(filename)) |
|---|
| 514 | generate = 1; |
|---|
| 515 | |
|---|
| 516 | if (generate) //do not regenerate certificates if they are already created |
|---|
| 517 | { |
|---|
| 518 | |
|---|
| 519 | char expiration_days[64]; |
|---|
| 520 | strcpy(expiration_days, nvram_safe_get("radius_expiration")); |
|---|
| 521 | long expiration = 0; //never |
|---|
| 522 | if (db->users[radiusindex].expiration) { |
|---|
| 523 | time_t tm; |
|---|
| 524 | time(&tm); |
|---|
| 525 | long curtime = ((tm / 60) / 60) / 24; //in days |
|---|
| 526 | expiration = |
|---|
| 527 | db->users[radiusindex].expiration - curtime; |
|---|
| 528 | sprintf(expiration_days, "%ld", expiration); |
|---|
| 529 | } |
|---|
| 530 | //erase line from database |
|---|
| 531 | FILE *fp = fopen("/jffs/etc/freeradius/certs/index.txt", "rb"); |
|---|
| 532 | if (fp) { |
|---|
| 533 | fseek(fp, 0, SEEK_END); |
|---|
| 534 | int len = ftell(fp); |
|---|
| 535 | rewind(fp); |
|---|
| 536 | char *serial = safe_malloc(len + 1); |
|---|
| 537 | char *output = safe_malloc(len + 1); |
|---|
| 538 | fread(serial, len, 1, fp); |
|---|
| 539 | fclose(fp); |
|---|
| 540 | //look for existing entry |
|---|
| 541 | char common[128]; |
|---|
| 542 | sprintf(common, "CN=%s", db->users[radiusindex].user); |
|---|
| 543 | int i; |
|---|
| 544 | int clen = strlen(common); |
|---|
| 545 | int llen = len - clen; |
|---|
| 546 | int line = -1; |
|---|
| 547 | int oc = 0; |
|---|
| 548 | for (i = 0; i < llen; i++) { |
|---|
| 549 | if (serial[i] == 0xa) { |
|---|
| 550 | if (line == -1) |
|---|
| 551 | line++; |
|---|
| 552 | line++; |
|---|
| 553 | } |
|---|
| 554 | if (!strncmp |
|---|
| 555 | (&serial[i], common, strlen(common))) { |
|---|
| 556 | //found line |
|---|
| 557 | int lines = 0; |
|---|
| 558 | int ic = 0; |
|---|
| 559 | while (1) { |
|---|
| 560 | if (serial[ic] == 0xa) { |
|---|
| 561 | lines++; |
|---|
| 562 | } |
|---|
| 563 | if (line != lines) |
|---|
| 564 | output[oc++] = |
|---|
| 565 | serial[ic]; |
|---|
| 566 | ic++; |
|---|
| 567 | if (ic == len) |
|---|
| 568 | break; |
|---|
| 569 | } |
|---|
| 570 | break; |
|---|
| 571 | } |
|---|
| 572 | } |
|---|
| 573 | if (oc) { |
|---|
| 574 | fp = fopen |
|---|
| 575 | ("/jffs/etc/freeradius/certs/index.txt", |
|---|
| 576 | "wb"); |
|---|
| 577 | if (fp) { |
|---|
| 578 | fwrite(output, oc, 1, fp); |
|---|
| 579 | fclose(fp); |
|---|
| 580 | } |
|---|
| 581 | } |
|---|
| 582 | free(output); |
|---|
| 583 | free(serial); |
|---|
| 584 | } |
|---|
| 585 | sprintf(exec, |
|---|
| 586 | "cd /jffs/etc/freeradius/certs && ./doclientcert \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", |
|---|
| 587 | expiration_days, |
|---|
| 588 | nvram_safe_get("radius_country"), |
|---|
| 589 | nvram_safe_get("radius_state"), |
|---|
| 590 | nvram_safe_get("radius_locality"), |
|---|
| 591 | nvram_safe_get("radius_organisation"), |
|---|
| 592 | nvram_safe_get("radius_email"), |
|---|
| 593 | db->users[radiusindex].user, |
|---|
| 594 | db->users[radiusindex].passwd, |
|---|
| 595 | nvram_safe_get("radius_passphrase")); |
|---|
| 596 | system(exec); |
|---|
| 597 | } |
|---|
| 598 | char *argv[] = { |
|---|
| 599 | "freeradius.clientcert" |
|---|
| 600 | }; |
|---|
| 601 | call_ej("do_pagehead", NULL, wp, 1, argv); // thats dirty |
|---|
| 602 | websWrite(wp, "</head>\n" |
|---|
| 603 | "<body>\n" |
|---|
| 604 | "<div id=\"main\">\n" |
|---|
| 605 | "<div id=\"contentsInfo\">\n" |
|---|
| 606 | "<h2>%s</h2>\n", live_translate("freeradius.clientcert")); |
|---|
| 607 | sprintf(filename, "%s-cert.pem", db->users[radiusindex].user); |
|---|
| 608 | show_certfield(wp, "Certificate PEM", filename); |
|---|
| 609 | sprintf(filename, "%s-cert.p12", db->users[radiusindex].user); |
|---|
| 610 | show_certfield(wp, "Certificate P12 (Windows)", filename); |
|---|
| 611 | sprintf(filename, "%s-req.pem", db->users[radiusindex].user); |
|---|
| 612 | show_certfield(wp, "Certificate Request", filename); |
|---|
| 613 | sprintf(filename, "%s-key.pem", db->users[radiusindex].user); |
|---|
| 614 | show_certfield(wp, "Private Key PEM", filename); |
|---|
| 615 | websWrite(wp, "<div class=\"submitFooter\">\n" |
|---|
| 616 | "<script type=\"text/javascript\">\n" |
|---|
| 617 | "//<![CDATA[\n" |
|---|
| 618 | "submitFooterButton(0,0,0,0,0,1);\n" |
|---|
| 619 | "//]]>\n" |
|---|
| 620 | "</script>\n" |
|---|
| 621 | "</div>\n" "</div>\n" "</div>\n" "</body>\n" "</html>\n"); |
|---|
| 622 | |
|---|
| 623 | //make certificates |
|---|
| 624 | out:; |
|---|
| 625 | freeradiusdb(db); |
|---|
| 626 | |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | #endif |
|---|
| 630 | void do_activetable(struct mime_handler *handler, char *path, webs_t stream, |
|---|
| 631 | char *query) |
|---|
| 632 | { |
|---|
| 633 | char *temp2 = &path[indexof(path, '-') + 1]; |
|---|
| 634 | char ifname[16]; |
|---|
| 635 | |
|---|
| 636 | strcpy(ifname, temp2); |
|---|
| 637 | |
|---|
| 638 | char *temp3 = websGetVar(stream, "ifname", NULL); |
|---|
| 639 | if (temp3 != NULL) { |
|---|
| 640 | if (strlen(temp3) > 0) { |
|---|
| 641 | strcpy(ifname, temp3); |
|---|
| 642 | } |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | ifname[indexof(ifname, '.')] = 0; |
|---|
| 646 | FILE *web = getWebsFile("WL_ActiveTable.asp"); |
|---|
| 647 | unsigned int len = getWebsFileLen("WL_ActiveTable.asp"); |
|---|
| 648 | char *webfile = (char *)safe_malloc(len + 1); |
|---|
| 649 | |
|---|
| 650 | fread(webfile, len, 1, web); |
|---|
| 651 | webfile[len] = 0; |
|---|
| 652 | fclose(web); |
|---|
| 653 | |
|---|
| 654 | char temp[32768]; |
|---|
| 655 | |
|---|
| 656 | memset(temp, 0, 32768); |
|---|
| 657 | int ai = 0; |
|---|
| 658 | int i = 0; |
|---|
| 659 | int weblen = strlen(webfile); |
|---|
| 660 | |
|---|
| 661 | for (i = 0; i < weblen; i++) { |
|---|
| 662 | if (webfile[i] == '%') { |
|---|
| 663 | i++; |
|---|
| 664 | switch (webfile[i]) { |
|---|
| 665 | case '%': |
|---|
| 666 | temp[ai++] = '%'; |
|---|
| 667 | break; |
|---|
| 668 | case 's': |
|---|
| 669 | strcpy(&temp[ai], ifname); |
|---|
| 670 | ai += strlen(ifname); |
|---|
| 671 | break; |
|---|
| 672 | default: |
|---|
| 673 | temp[ai++] = webfile[i]; |
|---|
| 674 | break; |
|---|
| 675 | } |
|---|
| 676 | } else |
|---|
| 677 | temp[ai++] = webfile[i]; |
|---|
| 678 | } |
|---|
| 679 | free(webfile); |
|---|
| 680 | do_ej_buffer(temp, stream); |
|---|
| 681 | } |
|---|
| 682 | |
|---|
| 683 | void do_wds(struct mime_handler *handler, char *path, webs_t stream, |
|---|
| 684 | char *query) |
|---|
| 685 | { |
|---|
| 686 | char *temp2 = &path[indexof(path, '-') + 1]; |
|---|
| 687 | char ifname[16]; |
|---|
| 688 | |
|---|
| 689 | strcpy(ifname, temp2); |
|---|
| 690 | ifname[indexof(ifname, '.')] = 0; |
|---|
| 691 | FILE *web = getWebsFile("Wireless_WDS.asp"); |
|---|
| 692 | unsigned int len = getWebsFileLen("Wireless_WDS.asp"); |
|---|
| 693 | char *webfile = (char *)safe_malloc(len + 1); |
|---|
| 694 | |
|---|
| 695 | fread(webfile, len, 1, web); |
|---|
| 696 | webfile[len] = 0; |
|---|
| 697 | fclose(web); |
|---|
| 698 | |
|---|
| 699 | char temp[32768]; |
|---|
| 700 | |
|---|
| 701 | memset(temp, 0, 32768); |
|---|
| 702 | int ai = 0; |
|---|
| 703 | int i = 0; |
|---|
| 704 | int weblen = strlen(webfile); |
|---|
| 705 | |
|---|
| 706 | for (i = 0; i < weblen; i++) { |
|---|
| 707 | if (webfile[i] == '%') { |
|---|
| 708 | i++; |
|---|
| 709 | switch (webfile[i]) { |
|---|
| 710 | case '%': |
|---|
| 711 | temp[ai++] = '%'; |
|---|
| 712 | break; |
|---|
| 713 | case 's': |
|---|
| 714 | strcpy(&temp[ai], ifname); |
|---|
| 715 | ai += strlen(ifname); |
|---|
| 716 | break; |
|---|
| 717 | default: |
|---|
| 718 | temp[ai++] = webfile[i]; |
|---|
| 719 | break; |
|---|
| 720 | } |
|---|
| 721 | } else |
|---|
| 722 | temp[ai++] = webfile[i]; |
|---|
| 723 | } |
|---|
| 724 | free(webfile); |
|---|
| 725 | do_ej_buffer(temp, stream); |
|---|
| 726 | } |
|---|
| 727 | |
|---|
| 728 | void do_wireless_adv(struct mime_handler *handler, char *path, webs_t stream, |
|---|
| 729 | char *query) |
|---|
| 730 | { |
|---|
| 731 | char *temp2 = &path[indexof(path, '-') + 1]; |
|---|
| 732 | char ifname[16]; |
|---|
| 733 | |
|---|
| 734 | strcpy(ifname, temp2); |
|---|
| 735 | ifname[indexof(ifname, '.')] = 0; |
|---|
| 736 | FILE *web = getWebsFile("Wireless_Advanced.asp"); |
|---|
| 737 | unsigned int len = getWebsFileLen("Wireless_Advanced.asp"); |
|---|
| 738 | char *webfile = (char *)safe_malloc(len + 1); |
|---|
| 739 | |
|---|
| 740 | char index[2]; |
|---|
| 741 | substring(strlen(ifname) - 1, strlen(ifname), ifname, index); |
|---|
| 742 | |
|---|
| 743 | fread(webfile, len, 1, web); |
|---|
| 744 | webfile[len] = 0; |
|---|
| 745 | fclose(web); |
|---|
| 746 | |
|---|
| 747 | char temp[65536]; |
|---|
| 748 | |
|---|
| 749 | memset(temp, 0, 65536); |
|---|
| 750 | int ai = 0; |
|---|
| 751 | int i = 0; |
|---|
| 752 | int weblen = strlen(webfile); |
|---|
| 753 | |
|---|
| 754 | for (i = 0; i < weblen; i++) { |
|---|
| 755 | if (webfile[i] == '%') { |
|---|
| 756 | i++; |
|---|
| 757 | switch (webfile[i]) { |
|---|
| 758 | case '%': |
|---|
| 759 | temp[ai++] = '%'; |
|---|
| 760 | break; |
|---|
| 761 | case 'd': |
|---|
| 762 | strcpy(&temp[ai], index); |
|---|
| 763 | ai++; |
|---|
| 764 | break; |
|---|
| 765 | case 's': |
|---|
| 766 | strcpy(&temp[ai], ifname); |
|---|
| 767 | ai += strlen(ifname); |
|---|
| 768 | break; |
|---|
| 769 | default: |
|---|
| 770 | temp[ai++] = webfile[i]; |
|---|
| 771 | break; |
|---|
| 772 | } |
|---|
| 773 | } else |
|---|
| 774 | temp[ai++] = webfile[i]; |
|---|
| 775 | } |
|---|
| 776 | free(webfile); |
|---|
| 777 | do_ej_buffer(temp, stream); |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | void validate_cgi(webs_t wp) |
|---|
| 781 | { |
|---|
| 782 | char *value; |
|---|
| 783 | int i; |
|---|
| 784 | |
|---|
| 785 | #ifdef HAVE_MACBIND |
|---|
| 786 | if (!nvram_match("et0macaddr", MACBRAND)) |
|---|
| 787 | return; |
|---|
| 788 | #endif |
|---|
| 789 | int alen = variables_arraysize(); |
|---|
| 790 | void *handle = NULL; |
|---|
| 791 | |
|---|
| 792 | for (i = 0; i < alen; i++) { |
|---|
| 793 | if (variables[i] == NULL) |
|---|
| 794 | return; |
|---|
| 795 | value = websGetVar(wp, variables[i]->name, NULL); |
|---|
| 796 | if (!value) |
|---|
| 797 | continue; |
|---|
| 798 | if ((!*value && variables[i]->nullok) |
|---|
| 799 | || (!variables[i]->validate2name |
|---|
| 800 | && !variables[i]->validatename)) |
|---|
| 801 | nvram_set(variables[i]->name, value); |
|---|
| 802 | else { |
|---|
| 803 | if (variables[i]->validatename) { |
|---|
| 804 | cprintf("call validator_nofree %s\n", |
|---|
| 805 | variables[i]->validatename); |
|---|
| 806 | handle = |
|---|
| 807 | start_validator_nofree(variables |
|---|
| 808 | [i]->validatename, |
|---|
| 809 | handle, wp, value, |
|---|
| 810 | variables[i]); |
|---|
| 811 | } else if (variables[i]->validate2name) { |
|---|
| 812 | cprintf("call gozila %s\n", |
|---|
| 813 | variables[i]->validate2name); |
|---|
| 814 | start_gozila(variables[i]->validate2name, wp); |
|---|
| 815 | // fprintf(stderr,"validating %s = |
|---|
| 816 | // %s\n",variables[i]->name,value); |
|---|
| 817 | // variables[i]->validate (wp, value, variables[i]); |
|---|
| 818 | } else { |
|---|
| 819 | // variables[i]->validate2 (wp); |
|---|
| 820 | } |
|---|
| 821 | } |
|---|
| 822 | |
|---|
| 823 | } |
|---|
| 824 | cprintf("close handle\n"); |
|---|
| 825 | if (handle) |
|---|
| 826 | dlclose(handle); |
|---|
| 827 | cprintf("all vars validated\n"); |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | enum { |
|---|
| 831 | NOTHING, |
|---|
| 832 | REBOOT, |
|---|
| 833 | RESTART, |
|---|
| 834 | SERVICE_RESTART, |
|---|
| 835 | SYS_RESTART, |
|---|
| 836 | REFRESH, |
|---|
| 837 | }; |
|---|
| 838 | static struct gozila_action gozila_actions[] = { |
|---|
| 839 | /* |
|---|
| 840 | * SETUP |
|---|
| 841 | */ |
|---|
| 842 | {"index", "wan_proto", "", 1, REFRESH, "wan_proto"}, |
|---|
| 843 | {"index", "dhcpfwd", "", 1, REFRESH, "dhcpfwd"}, |
|---|
| 844 | // {"index", "clone_mac", "", 1, REFRESH, clone_mac}, //OBSOLETE |
|---|
| 845 | #ifdef HAVE_CCONTROL |
|---|
| 846 | {"ccontrol", "execute", "", 1, REFRESH, "execute"}, |
|---|
| 847 | #endif |
|---|
| 848 | {"WanMAC", "clone_mac", "", 1, REFRESH, "clone_mac"}, // for cisco |
|---|
| 849 | // style |
|---|
| 850 | {"DHCPTable", "delete", "", 2, REFRESH, "delete_leases"}, |
|---|
| 851 | #ifdef HAVE_PPTPD |
|---|
| 852 | {"DHCPTable", "deletepptp", "", 2, REFRESH, "delete_pptp"}, |
|---|
| 853 | #endif |
|---|
| 854 | {"Info", "refresh", "", 0, REFRESH, "save_wifi"}, |
|---|
| 855 | {"Status_Wireless", "refresh", "", 0, REFRESH, "save_wifi"}, |
|---|
| 856 | // {"Status", "release", "dhcp_release", 0, SYS_RESTART, "dhcp_release"}, |
|---|
| 857 | // {"Status", "renew", "", 3, REFRESH, "dhcp_renew"}, |
|---|
| 858 | // {"Status", "Connect", "start_pppoe", 1, RESTART, NULL}, |
|---|
| 859 | {"Status_Internet", "release", "dhcp_release", 0, SERVICE_RESTART, "dhcp_release"}, // for |
|---|
| 860 | {"Status_Internet", "renew", "", 3, REFRESH, "dhcp_renew"}, // for cisco |
|---|
| 861 | {"Status_Internet", "Disconnect", "stop_pppoe", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 862 | #ifdef HAVE_3G |
|---|
| 863 | {"Status_Internet", "Connect_3g", "start_3g", 1, RESTART, NULL}, // for |
|---|
| 864 | {"Status_Internet", "Disconnect_3g", "stop_3g", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 865 | #endif |
|---|
| 866 | #ifdef HAVE_PPPOATM |
|---|
| 867 | {"Status_Internet", "Connect_pppoa", "start_pppoa", 1, RESTART, NULL}, // for |
|---|
| 868 | {"Status_Internet", "Disconnect_pppoa", "stop_pppoa", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 869 | #endif |
|---|
| 870 | {"Status_Internet", "Connect_pppoe", "start_pppoe", 1, RESTART, NULL}, // for |
|---|
| 871 | {"Status_Internet", "Disconnect_pppoe", "stop_pppoe", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 872 | |
|---|
| 873 | {"Status_Internet", "Connect_pptp", "start_pptp", 1, RESTART, NULL}, // for |
|---|
| 874 | {"Status_Internet", "Disconnect_pptp", "stop_pptp", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 875 | {"Status_Internet", "Connect_l2tp", "start_l2tp", 1, RESTART, NULL}, // for |
|---|
| 876 | {"Status_Internet", "Disconnect_l2tp", "stop_l2tp", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 877 | // cisco |
|---|
| 878 | // style{ |
|---|
| 879 | // "Status_Router", |
|---|
| 880 | // "Connect_heartbeat", |
|---|
| 881 | // "start_heartbeat", |
|---|
| 882 | // 1, |
|---|
| 883 | // RESTART, |
|---|
| 884 | // NULL}, |
|---|
| 885 | // // |
|---|
| 886 | // for |
|---|
| 887 | // cisco |
|---|
| 888 | // style |
|---|
| 889 | {"Status_Internet", "Disconnect_heartbeat", "stop_heartbeat", 2, SERVICE_RESTART, "stop_ppp"}, // for |
|---|
| 890 | // cisco |
|---|
| 891 | // style |
|---|
| 892 | {"Status_Internet", "delete_ttraffdata", "", 0, REFRESH, |
|---|
| 893 | "ttraff_erase"}, |
|---|
| 894 | {"Filters", "save", "filters", 1, REFRESH, "save_policy"}, |
|---|
| 895 | {"Filters", "delete", "filters", 1, REFRESH, "single_delete_policy"}, |
|---|
| 896 | {"FilterSummary", "delete", "filters", 1, REFRESH, |
|---|
| 897 | "summary_delete_policy"}, |
|---|
| 898 | {"Routing", "del", "static_route_del", 1, REFRESH, |
|---|
| 899 | "delete_static_route"}, |
|---|
| 900 | {"RouteStatic", "del", "static_route_del", 1, REFRESH, |
|---|
| 901 | "delete_static_route"}, |
|---|
| 902 | {"WL_WPATable", "wep_key_generate", "", 1, REFRESH, "generate_wep_key"}, |
|---|
| 903 | {"WL_WPATable", "security", "", 1, REFRESH, "set_security"}, |
|---|
| 904 | {"WL_WPATable", "save", "wireless_2", 1, REFRESH, "security_save"}, |
|---|
| 905 | {"WL_WPATable", "keysize", "wireless_2", 1, REFRESH, "security_save"}, |
|---|
| 906 | {"WL_ActiveTable", "add_mac", "", 1, REFRESH, "add_active_mac"}, |
|---|
| 907 | {"WL_ActiveTable-wl0", "add_mac", "", 1, REFRESH, "add_active_mac"}, |
|---|
| 908 | {"WL_ActiveTable-wl1", "add_mac", "", 1, REFRESH, "add_active_mac"}, |
|---|
| 909 | /* |
|---|
| 910 | * Siafu addition |
|---|
| 911 | */ |
|---|
| 912 | {"Ping", "wol", "", 1, REFRESH, "ping_wol"}, |
|---|
| 913 | /* |
|---|
| 914 | * Sveasoft addition |
|---|
| 915 | */ |
|---|
| 916 | // {"Wireless_WDS", "save", "", 0, REFRESH, save_wds}, |
|---|
| 917 | #ifndef HAVE_MADWIFI |
|---|
| 918 | {"Wireless_WDS-wl0", "save", "wireless_2", 0, REFRESH, "save_wds"}, |
|---|
| 919 | {"Wireless_WDS-wl1", "save", "wireless_2", 0, REFRESH, "save_wds"}, |
|---|
| 920 | {"Wireless_Advanced-wl0", "save", "wireless_2", 0, REFRESH, |
|---|
| 921 | "save_wireless_advanced"}, |
|---|
| 922 | {"Wireless_Advanced-wl1", "save", "wireless_2", 0, REFRESH, |
|---|
| 923 | "save_wireless_advanced"}, |
|---|
| 924 | #else |
|---|
| 925 | {"Wireless_WDS-ath0", "save", "wireless_2", 0, REFRESH, "save_wds"}, |
|---|
| 926 | {"Wireless_WDS-ath1", "save", "wireless_2", 0, REFRESH, "save_wds"}, |
|---|
| 927 | {"Wireless_WDS-ath2", "save", "wireless_2", 0, REFRESH, "save_wds"}, |
|---|
| 928 | {"Wireless_WDS-ath3", "save", "wireless_2", 0, REFRESH, "save_wds"}, |
|---|
| 929 | #endif |
|---|
| 930 | {"Ping", "startup", "", 1, REFRESH, "ping_startup"}, |
|---|
| 931 | {"Ping", "shutdown", "", 1, REFRESH, "ping_shutdown"}, |
|---|
| 932 | {"Ping", "firewall", "", 1, SYS_RESTART, "ping_firewall"}, |
|---|
| 933 | {"Ping", "custom", "", 0, REFRESH, "ping_custom"}, |
|---|
| 934 | {"QoS", "add_svc", "", 0, REFRESH, "qos_add_svc"}, |
|---|
| 935 | {"QoS", "add_ip", "", 0, REFRESH, "qos_add_ip"}, |
|---|
| 936 | {"QoS", "add_mac", "", 0, REFRESH, "qos_add_mac"}, |
|---|
| 937 | {"QoS", "save", "filters", 1, REFRESH, "qos_save"}, |
|---|
| 938 | /* |
|---|
| 939 | * end Sveasoft addition |
|---|
| 940 | */ |
|---|
| 941 | {"Forward", "add_forward", "", 0, REFRESH, "forward_add"}, |
|---|
| 942 | {"Forward", "remove_forward", "", 0, REFRESH, "forward_remove"}, |
|---|
| 943 | {"Wireless_Basic", "add_vifs", "", 0, REFRESH, "add_vifs"}, |
|---|
| 944 | {"Wireless_Basic", "remove_vifs", "", 0, REFRESH, "remove_vifs"}, |
|---|
| 945 | #ifdef HAVE_FREERADIUS |
|---|
| 946 | {"FreeRadius", "generate_certificate", "", 0, REFRESH, |
|---|
| 947 | "radius_generate_certificate"}, |
|---|
| 948 | {"FreeRadius", "add_radius_user", "", 0, REFRESH, "add_radius_user"}, |
|---|
| 949 | {"FreeRadius", "del_radius_user", "", 0, REFRESH, "del_radius_user"}, |
|---|
| 950 | {"FreeRadius", "add_radius_client", "", 0, REFRESH, |
|---|
| 951 | "add_radius_client"}, |
|---|
| 952 | {"FreeRadius", "del_radius_client", "", 0, REFRESH, |
|---|
| 953 | "del_radius_client"}, |
|---|
| 954 | {"FreeRadius", "save_radius_user", "", 0, REFRESH, "save_radius_user"}, |
|---|
| 955 | #endif |
|---|
| 956 | #ifdef HAVE_POKER |
|---|
| 957 | {"Poker", "add_poker_user", "", 0, REFRESH, "add_poker_user"}, |
|---|
| 958 | {"Poker", "del_poker_user", "", 0, REFRESH, "del_poker_user"}, |
|---|
| 959 | {"Poker", "save_poker_user", "", 0, REFRESH, "save_poker_user"}, |
|---|
| 960 | {"PokerEdit", "poker_loaduser", "", 0, REFRESH, "poker_loaduser"}, |
|---|
| 961 | {"PokerEdit", "poker_checkout", "", 0, REFRESH, "poker_checkout"}, |
|---|
| 962 | {"PokerEdit", "poker_buy", "", 0, REFRESH, "poker_buy"}, |
|---|
| 963 | {"PokerEdit", "poker_credit", "", 0, REFRESH, "poker_credit"}, |
|---|
| 964 | {"PokerEdit", "poker_back", "", 0, REFRESH, "poker_back"}, |
|---|
| 965 | #endif |
|---|
| 966 | #ifdef HAVE_BONDING |
|---|
| 967 | {"Networking", "add_bond", "", 0, REFRESH, "add_bond"}, |
|---|
| 968 | {"Networking", "del_bond", "", 0, REFRESH, "del_bond"}, |
|---|
| 969 | #endif |
|---|
| 970 | #ifdef HAVE_OLSRD |
|---|
| 971 | {"Routing", "add_olsrd", "", 0, REFRESH, "add_olsrd"}, |
|---|
| 972 | {"Routing", "del_olsrd", "", 0, REFRESH, "del_olsrd"}, |
|---|
| 973 | #endif |
|---|
| 974 | #ifdef HAVE_VLANTAGGING |
|---|
| 975 | {"Networking", "add_vlan", "", 0, REFRESH, "add_vlan"}, |
|---|
| 976 | {"Networking", "add_bridge", "", 0, REFRESH, "add_bridge"}, |
|---|
| 977 | {"Networking", "add_bridgeif", "", 0, REFRESH, "add_bridgeif"}, |
|---|
| 978 | {"Networking", "del_vlan", "", 0, REFRESH, "del_vlan"}, |
|---|
| 979 | {"Networking", "del_bridge", "", 0, REFRESH, "del_bridge"}, |
|---|
| 980 | {"Networking", "del_bridgeif", "", 0, REFRESH, "del_bridgeif"}, |
|---|
| 981 | {"Networking", "save_networking", "index", 0, REFRESH, |
|---|
| 982 | "save_networking"}, |
|---|
| 983 | {"Networking", "add_mdhcp", "", 0, REFRESH, "add_mdhcp"}, |
|---|
| 984 | {"Networking", "del_mdhcp", "", 0, REFRESH, "del_mdhcp"}, |
|---|
| 985 | #endif |
|---|
| 986 | {"Wireless_Basic", "save", "wireless", 1, REFRESH, "wireless_save"}, |
|---|
| 987 | #ifdef HAVE_WIVIZ |
|---|
| 988 | {"Wiviz_Survey", "Set", "", 0, REFRESH, "set_wiviz"}, |
|---|
| 989 | #endif |
|---|
| 990 | #ifdef HAVE_REGISTER |
|---|
| 991 | {"Register", "activate", "", 1, RESTART, "reg_validate"}, |
|---|
| 992 | #endif |
|---|
| 993 | {"index", "changepass", "", 1, REFRESH, "changepass"}, |
|---|
| 994 | #ifdef HAVE_SUPERCHANNEL |
|---|
| 995 | {"SuperChannel", "activate", "", 1, REFRESH, "superchannel_validate"}, |
|---|
| 996 | #endif |
|---|
| 997 | {"Services", "add_lease", "", 0, REFRESH, "lease_add"}, |
|---|
| 998 | {"Services", "remove_lease", "", 0, REFRESH, "lease_remove"}, |
|---|
| 999 | #ifdef HAVE_PPPOESERVER |
|---|
| 1000 | {"PPPoE_Server", "add_chap_user", "", 0, REFRESH, "chap_user_add"}, |
|---|
| 1001 | {"PPPoE_Server", "remove_chap_user", "", 0, REFRESH, |
|---|
| 1002 | "chap_user_remove"}, |
|---|
| 1003 | #endif |
|---|
| 1004 | #ifdef HAVE_CHILLILOCAL |
|---|
| 1005 | {"Hotspot", "add_user", "", 0, REFRESH, "user_add"}, |
|---|
| 1006 | {"Hotspot", "remove_user", "", 0, REFRESH, "user_remove"}, |
|---|
| 1007 | #endif |
|---|
| 1008 | #ifdef HAVE_RADLOCAL |
|---|
| 1009 | {"Hotspot", "add_iradius", "", 0, REFRESH, "raduser_add"}, |
|---|
| 1010 | #endif |
|---|
| 1011 | {"ForwardSpec", "add_forward_spec", "", 0, REFRESH, "forwardspec_add"}, |
|---|
| 1012 | {"ForwardSpec", "remove_forward_spec", "", 0, REFRESH, |
|---|
| 1013 | "forwardspec_remove"}, |
|---|
| 1014 | {"Triggering", "add_trigger", "", 0, REFRESH, "trigger_add"}, |
|---|
| 1015 | {"Triggering", "remove_trigger", "", 0, REFRESH, "trigger_remove"}, |
|---|
| 1016 | {"Port_Services", "save_services", "filters", 2, REFRESH, |
|---|
| 1017 | "save_services_port"}, |
|---|
| 1018 | {"QOSPort_Services", "save_qosservices", "filters", 2, REFRESH, |
|---|
| 1019 | "save_services_port"}, |
|---|
| 1020 | {"Ping", "start", "", 1, SERVICE_RESTART, "diag_ping_start"}, |
|---|
| 1021 | {"Ping", "stop", "", 0, REFRESH, "diag_ping_stop"}, |
|---|
| 1022 | {"Ping", "clear", "", 0, REFRESH, "diag_ping_clear"}, |
|---|
| 1023 | #ifdef HAVE_MILKFISH |
|---|
| 1024 | {"Milkfish_database", "add_milkfish_user", "", 0, REFRESH, |
|---|
| 1025 | "milkfish_user_add"}, |
|---|
| 1026 | {"Milkfish_database", "remove_milkfish_user", "", 0, REFRESH, |
|---|
| 1027 | "milkfish_user_remove"}, |
|---|
| 1028 | {"Milkfish_aliases", "add_milkfish_alias", "", 0, REFRESH, |
|---|
| 1029 | "milkfish_alias_add"}, |
|---|
| 1030 | {"Milkfish_aliases", "remove_milkfish_alias", "", 0, REFRESH, |
|---|
| 1031 | "milkfish_alias_remove"}, |
|---|
| 1032 | {"Milkfish_messaging", "send_message", "", 1, SERVICE_RESTART, |
|---|
| 1033 | "milkfish_sip_message"}, |
|---|
| 1034 | #endif |
|---|
| 1035 | #ifdef HAVE_BUFFALO |
|---|
| 1036 | {"SetupAssistant", "save", "setupassistant", 1, REFRESH, |
|---|
| 1037 | "setupassistant_save"}, |
|---|
| 1038 | {"SetupAssistant", "wep_key_generate", "setupassistant", 1, REFRESH, |
|---|
| 1039 | "generate_wep_key"}, |
|---|
| 1040 | {"SetupAssistant", "security", "setupassistant", 1, REFRESH, |
|---|
| 1041 | "set_security"}, |
|---|
| 1042 | {"SetupAssistant", "keysize", "setupassistant", 1, REFRESH, |
|---|
| 1043 | "security_save"}, |
|---|
| 1044 | {"AOSS", "save", "aoss", 1, REFRESH, "aoss_save"}, |
|---|
| 1045 | {"AOSS", "start", "aoss", 1, REFRESH, "aoss_start"}, |
|---|
| 1046 | {"Upgrade", "get_upgrades", "firmware", 1, REFRESH, |
|---|
| 1047 | "get_airstation_upgrades"}, |
|---|
| 1048 | #ifdef HAVE_WPS |
|---|
| 1049 | {"AOSS", "wps_register", "aoss", 1, REFRESH, "wps_register"}, |
|---|
| 1050 | {"AOSS", "wps_ap_register", "aoss", 1, REFRESH, "wps_ap_register"}, |
|---|
| 1051 | {"AOSS", "wps_forcerelease", "aoss", 1, REFRESH, "wps_forcerelease"}, |
|---|
| 1052 | {"AOSS", "wps_configure", "aoss", 1, REFRESH, "wps_configure"}, |
|---|
| 1053 | #endif |
|---|
| 1054 | #ifdef HAVE_SPOTPASS |
|---|
| 1055 | {"Nintendo", "save", "spotpass", 1, REFRESH, "nintendo_save"}, |
|---|
| 1056 | #endif |
|---|
| 1057 | #endif |
|---|
| 1058 | {"Join", "Join", "wireless", 1, REFRESH, "wireless_join"}, |
|---|
| 1059 | #ifdef HAVE_NAS_SERVER |
|---|
| 1060 | {"NAS", "save", "nassrv", 1, REFRESH, "nassrv_save"}, |
|---|
| 1061 | #endif |
|---|
| 1062 | }; |
|---|
| 1063 | |
|---|
| 1064 | struct gozila_action *handle_gozila_action(char *name, char *type) |
|---|
| 1065 | { |
|---|
| 1066 | struct gozila_action *v; |
|---|
| 1067 | |
|---|
| 1068 | if (!name || !type) |
|---|
| 1069 | return NULL; |
|---|
| 1070 | |
|---|
| 1071 | for (v = gozila_actions; |
|---|
| 1072 | v < &gozila_actions[STRUCT_LEN(gozila_actions)]; v++) { |
|---|
| 1073 | if (!strcmp(v->name, name) && !strcmp(v->type, type)) { |
|---|
| 1074 | return v; |
|---|
| 1075 | } |
|---|
| 1076 | } |
|---|
| 1077 | return NULL; |
|---|
| 1078 | } |
|---|
| 1079 | |
|---|
| 1080 | char my_next_page[30] = ""; |
|---|
| 1081 | int gozila_cgi(webs_t wp, char_t * urlPrefix, char_t * webDir, int arg, |
|---|
| 1082 | char_t * url, char_t * path, char_t * query) |
|---|
| 1083 | { |
|---|
| 1084 | char *submit_button, *submit_type, *next_page; |
|---|
| 1085 | int action = REFRESH; |
|---|
| 1086 | int sleep_time; |
|---|
| 1087 | struct gozila_action *act; |
|---|
| 1088 | |
|---|
| 1089 | nvram_set("gozila_action", "1"); |
|---|
| 1090 | my_next_page[0] = '\0'; |
|---|
| 1091 | submit_button = websGetVar(wp, "submit_button", NULL); /* every html |
|---|
| 1092 | * must have |
|---|
| 1093 | * the name */ |
|---|
| 1094 | submit_type = websGetVar(wp, "submit_type", NULL); /* add, del, |
|---|
| 1095 | * renew, |
|---|
| 1096 | * release |
|---|
| 1097 | * ..... */ |
|---|
| 1098 | |
|---|
| 1099 | fprintf(stderr, "submit_button=[%s] submit_type=[%s]\n", submit_button, |
|---|
| 1100 | submit_type); |
|---|
| 1101 | act = handle_gozila_action(submit_button, submit_type); |
|---|
| 1102 | |
|---|
| 1103 | if (act) { |
|---|
| 1104 | fprintf(stderr, |
|---|
| 1105 | "name=[%s] type=[%s] service=[%s] sleep=[%d] action=[%d]\n", |
|---|
| 1106 | act->name, act->type, act->service, act->sleep_time, |
|---|
| 1107 | act->action); |
|---|
| 1108 | addAction(act->service); |
|---|
| 1109 | sleep_time = act->sleep_time; |
|---|
| 1110 | action = act->action; |
|---|
| 1111 | if (act->goname) { |
|---|
| 1112 | start_gozila(act->goname, wp); |
|---|
| 1113 | } |
|---|
| 1114 | } else { |
|---|
| 1115 | sleep_time = 0; |
|---|
| 1116 | action = REFRESH; |
|---|
| 1117 | } |
|---|
| 1118 | |
|---|
| 1119 | if (action == REFRESH) { |
|---|
| 1120 | sleep(sleep_time); |
|---|
| 1121 | } else if (action == SERVICE_RESTART) { |
|---|
| 1122 | sys_commit(); |
|---|
| 1123 | service_restart(); |
|---|
| 1124 | sleep(sleep_time); |
|---|
| 1125 | } else if (action == SYS_RESTART) { |
|---|
| 1126 | sys_commit(); |
|---|
| 1127 | sys_restart(); |
|---|
| 1128 | } else if (action == RESTART) { |
|---|
| 1129 | sys_commit(); |
|---|
| 1130 | sys_restart(); |
|---|
| 1131 | } |
|---|
| 1132 | |
|---|
| 1133 | if (my_next_page[0] != '\0') { |
|---|
| 1134 | sprintf(path, "%s", my_next_page); |
|---|
| 1135 | } else { |
|---|
| 1136 | next_page = websGetVar(wp, "next_page", NULL); |
|---|
| 1137 | if (next_page) |
|---|
| 1138 | sprintf(path, "%s", next_page); |
|---|
| 1139 | else |
|---|
| 1140 | sprintf(path, "%s.asp", submit_button); |
|---|
| 1141 | } |
|---|
| 1142 | |
|---|
| 1143 | cprintf("refresh to %s\n", path); |
|---|
| 1144 | if (!strncmp(path, "WL_FilterTable", 14)) |
|---|
| 1145 | do_filtertable(NULL, path, wp, NULL); // refresh |
|---|
| 1146 | #ifdef HAVE_FREERADIUS |
|---|
| 1147 | else if (!strncmp(path, "FreeRadiusCert", 14)) |
|---|
| 1148 | do_radiuscert(NULL, path, wp, NULL); // refresh |
|---|
| 1149 | #endif |
|---|
| 1150 | // #ifdef HAVE_MADWIFI |
|---|
| 1151 | else if (!strncmp(path, "WL_ActiveTable", 14)) |
|---|
| 1152 | do_activetable(NULL, path, wp, NULL); // refresh |
|---|
| 1153 | else if (!strncmp(path, "Wireless_WDS", 12)) |
|---|
| 1154 | do_wds(NULL, path, wp, NULL); // refresh |
|---|
| 1155 | // #endif |
|---|
| 1156 | else if (!strncmp(path, "Wireless_Advanced", 17)) |
|---|
| 1157 | do_wireless_adv(NULL, path, wp, NULL); // refresh |
|---|
| 1158 | else |
|---|
| 1159 | do_ej(NULL, path, wp, NULL); // refresh |
|---|
| 1160 | websDone(wp, 200); |
|---|
| 1161 | |
|---|
| 1162 | nvram_set("gozila_action", "0"); |
|---|
| 1163 | nvram_set("generate_key", "0"); |
|---|
| 1164 | nvram_set("clone_wan_mac", "0"); |
|---|
| 1165 | |
|---|
| 1166 | return 1; |
|---|
| 1167 | } |
|---|
| 1168 | |
|---|
| 1169 | struct apply_action apply_actions[] = { |
|---|
| 1170 | /* |
|---|
| 1171 | * name, service, sleep_time, action, function_to_execute |
|---|
| 1172 | */ |
|---|
| 1173 | |
|---|
| 1174 | /* |
|---|
| 1175 | * SETUP |
|---|
| 1176 | */ |
|---|
| 1177 | {"index", "index", 0, SERVICE_RESTART, NULL}, |
|---|
| 1178 | {"DDNS", "ddns", 0, SERVICE_RESTART, "ddns_save_value"}, |
|---|
| 1179 | {"Routing", "routing", 0, SERVICE_RESTART, NULL}, |
|---|
| 1180 | {"Vlan", "", 0, SYS_RESTART, "port_vlan_table_save"}, |
|---|
| 1181 | {"eop-tunnel", "eop", 0, SERVICE_RESTART, NULL}, |
|---|
| 1182 | |
|---|
| 1183 | /* |
|---|
| 1184 | * WIRELESS |
|---|
| 1185 | */ |
|---|
| 1186 | {"Wireless_Basic", "wireless", 0, SERVICE_RESTART, NULL}, // Only for |
|---|
| 1187 | // V23, since |
|---|
| 1188 | // V24 it's a |
|---|
| 1189 | // gozilla |
|---|
| 1190 | // save |
|---|
| 1191 | {"Wireless_Advanced-wl0", "wireless_2", 0, SERVICE_RESTART, |
|---|
| 1192 | "save_wireless_advanced"}, |
|---|
| 1193 | {"Wireless_Advanced-wl1", "wireless_2", 0, SERVICE_RESTART, |
|---|
| 1194 | "save_wireless_advanced"}, |
|---|
| 1195 | {"Wireless_MAC", "wireless_2", 0, SERVICE_RESTART, "save_macmode"}, |
|---|
| 1196 | {"WL_FilterTable", "macfilter", 0, SERVICE_RESTART, NULL}, |
|---|
| 1197 | {"Wireless_WDS", "wireless_2", 0, SERVICE_RESTART, NULL}, |
|---|
| 1198 | {"WL_WPATable", "wireless_2", 0, SERVICE_RESTART, NULL}, |
|---|
| 1199 | |
|---|
| 1200 | /* |
|---|
| 1201 | * MANAGEMENT |
|---|
| 1202 | */ |
|---|
| 1203 | {"Management", "management", 0, SYS_RESTART, NULL}, |
|---|
| 1204 | {"Services", "services", 0, SERVICE_RESTART, NULL}, |
|---|
| 1205 | {"Alive", "alive", 0, SERVICE_RESTART, NULL}, |
|---|
| 1206 | |
|---|
| 1207 | /* |
|---|
| 1208 | * SERVICES |
|---|
| 1209 | */ |
|---|
| 1210 | {"PPPoE_Server", "services", 0, SERVICE_RESTART, NULL}, |
|---|
| 1211 | {"PPTP", "services", 0, SERVICE_RESTART, NULL}, |
|---|
| 1212 | {"USB", "usbdrivers", 0, SERVICE_RESTART, NULL}, |
|---|
| 1213 | {"NAS", "nassrv", 0, SERVICE_RESTART, NULL}, |
|---|
| 1214 | {"Hotspot", "hotspot", 0, SERVICE_RESTART, "hotspot_save"}, |
|---|
| 1215 | {"Hotspot", "hotspot", 0, SERVICE_RESTART, NULL}, |
|---|
| 1216 | {"AnchorFree", "anchorfree", 0, SERVICE_RESTART, NULL}, |
|---|
| 1217 | {"Nintendo", "nintendo", 0, SERVICE_RESTART, NULL}, |
|---|
| 1218 | |
|---|
| 1219 | /* |
|---|
| 1220 | * APP & GAMING |
|---|
| 1221 | */ |
|---|
| 1222 | {"Forward", "forward", 0, SERVICE_RESTART, NULL}, |
|---|
| 1223 | {"ForwardSpec", "forward", 0, SERVICE_RESTART, NULL}, |
|---|
| 1224 | {"Triggering", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1225 | {"DMZ", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1226 | {"Filters", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1227 | {"FilterIPMAC", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1228 | #ifdef HAVE_UPNP |
|---|
| 1229 | {"UPnP", "forward_upnp", 0, SERVICE_RESTART, "tf_upnp"}, |
|---|
| 1230 | #endif |
|---|
| 1231 | /* |
|---|
| 1232 | * SECURITY |
|---|
| 1233 | */ |
|---|
| 1234 | {"Firewall", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1235 | {"VPN", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1236 | #ifdef HAVE_MILKFISH |
|---|
| 1237 | {"Milkfish", "milkfish", 0, SERVICE_RESTART, NULL}, |
|---|
| 1238 | #endif |
|---|
| 1239 | /* |
|---|
| 1240 | * Obsolete {"WL_WEPTable", "", 0, SERVICE_RESTART, NULL}, {"Security", |
|---|
| 1241 | * "", 1, RESTART, NULL}, {"System", "", 0, RESTART, NULL}, {"DHCP", |
|---|
| 1242 | * "dhcp", 0, SERVICE_RESTART, NULL}, {"FilterIP", "filters", 0, |
|---|
| 1243 | * SERVICE_RESTART, NULL}, {"FilterMAC", "filters", 0, SERVICE_RESTART, |
|---|
| 1244 | * NULL}, {"FilterPort", "filters", 0, SERVICE_RESTART, NULL}, |
|---|
| 1245 | * {"Wireless", "wireless", 0, SERVICE_RESTART, NULL}, {"Log", "logging", |
|---|
| 1246 | * 0, SERVICE_RESTART, NULL}, //moved to Firewall {"QoS", "qos", 0, |
|---|
| 1247 | * SERVICE_RESTART, NULL}, //gozilla does the save |
|---|
| 1248 | */ |
|---|
| 1249 | |
|---|
| 1250 | }; |
|---|
| 1251 | |
|---|
| 1252 | struct apply_action *handle_apply_action(char *name) |
|---|
| 1253 | { |
|---|
| 1254 | struct apply_action *v; |
|---|
| 1255 | |
|---|
| 1256 | cprintf("apply name = \n", name); |
|---|
| 1257 | if (!name) |
|---|
| 1258 | return NULL; |
|---|
| 1259 | |
|---|
| 1260 | for (v = apply_actions; v < &apply_actions[STRUCT_LEN(apply_actions)]; |
|---|
| 1261 | v++) { |
|---|
| 1262 | if (!strcmp(v->name, name)) { |
|---|
| 1263 | return v; |
|---|
| 1264 | } |
|---|
| 1265 | } |
|---|
| 1266 | return NULL; |
|---|
| 1267 | } |
|---|
| 1268 | |
|---|
| 1269 | int getFileLen(FILE * in) |
|---|
| 1270 | { |
|---|
| 1271 | int len; |
|---|
| 1272 | |
|---|
| 1273 | fseek(in, 0, SEEK_END); |
|---|
| 1274 | len = ftell(in); |
|---|
| 1275 | rewind(in); |
|---|
| 1276 | return len; |
|---|
| 1277 | } |
|---|
| 1278 | |
|---|
| 1279 | void do_logout(void) // static functions are not exportable, |
|---|
| 1280 | // additionally this is no ej function |
|---|
| 1281 | { |
|---|
| 1282 | send_authenticate(auth_realm); |
|---|
| 1283 | } static char *getdisc(void) // works only for squashfs |
|---|
| 1284 | { |
|---|
| 1285 | int i; |
|---|
| 1286 | static char ret[4]; |
|---|
| 1287 | unsigned char *disks[] = { |
|---|
| 1288 | "sda2", "sdb2", "sdc2", "sdd2", "sde2", "sdf2", "sdg2", "sdh2", |
|---|
| 1289 | "sdi2" |
|---|
| 1290 | }; |
|---|
| 1291 | for (i = 0; i < 9; i++) { |
|---|
| 1292 | char dev[64]; |
|---|
| 1293 | |
|---|
| 1294 | sprintf(dev, "/dev/%s", disks[i]); |
|---|
| 1295 | FILE *in = fopen(dev, "rb"); |
|---|
| 1296 | |
|---|
| 1297 | if (in == NULL) |
|---|
| 1298 | continue; // no second partition or disc does not |
|---|
| 1299 | // exist, skipping |
|---|
| 1300 | char buf[4]; |
|---|
| 1301 | |
|---|
| 1302 | fread(buf, 4, 1, in); |
|---|
| 1303 | if (buf[0] == 'h' && buf[1] == 's' && buf[2] == 'q' |
|---|
| 1304 | && buf[3] == 't') { |
|---|
| 1305 | fclose(in); |
|---|
| 1306 | // filesystem detected |
|---|
| 1307 | strncpy(ret, disks[i], 3); |
|---|
| 1308 | return ret; |
|---|
| 1309 | } |
|---|
| 1310 | fclose(in); |
|---|
| 1311 | } |
|---|
| 1312 | return NULL; |
|---|
| 1313 | } |
|---|
| 1314 | |
|---|
| 1315 | static int |
|---|
| 1316 | apply_cgi(webs_t wp, char_t * urlPrefix, char_t * webDir, int arg, |
|---|
| 1317 | char_t * url, char_t * path, char_t * query) |
|---|
| 1318 | { |
|---|
| 1319 | int action = NOTHING; |
|---|
| 1320 | char *value; |
|---|
| 1321 | char *submit_button, *next_page; |
|---|
| 1322 | int sleep_time = 0; |
|---|
| 1323 | int need_commit = 1; |
|---|
| 1324 | |
|---|
| 1325 | cprintf("need reboot\n"); |
|---|
| 1326 | int need_reboot = atoi(websGetVar(wp, "need_reboot", "0")); |
|---|
| 1327 | |
|---|
| 1328 | cprintf("apply"); |
|---|
| 1329 | |
|---|
| 1330 | /********** get "change_action" and launch gozila_cgi if needed **********/ |
|---|
| 1331 | |
|---|
| 1332 | value = websGetVar(wp, "change_action", ""); |
|---|
| 1333 | cprintf("get change_action = %s\n", value); |
|---|
| 1334 | |
|---|
| 1335 | if (value && !strcmp(value, "gozila_cgi")) { |
|---|
| 1336 | gozila_cgi(wp, urlPrefix, webDir, arg, url, path, query); |
|---|
| 1337 | return 1; |
|---|
| 1338 | } |
|---|
| 1339 | |
|---|
| 1340 | /***************************************************************************/ |
|---|
| 1341 | if (!query) { |
|---|
| 1342 | goto footer; |
|---|
| 1343 | } |
|---|
| 1344 | if (legal_ip_netmask |
|---|
| 1345 | ("lan_ipaddr", "lan_netmask", |
|---|
| 1346 | nvram_safe_get("http_client_ip")) == TRUE) |
|---|
| 1347 | nvram_set("browser_method", "USE_LAN"); |
|---|
| 1348 | else |
|---|
| 1349 | nvram_set("browser_method", "USE_WAN"); |
|---|
| 1350 | |
|---|
| 1351 | /********** get all webs var **********/ |
|---|
| 1352 | |
|---|
| 1353 | submit_button = websGetVar(wp, "submit_button", ""); |
|---|
| 1354 | cprintf("get submit_button = %s\n", submit_button); |
|---|
| 1355 | |
|---|
| 1356 | need_commit = atoi(websGetVar(wp, "commit", "1")); |
|---|
| 1357 | cprintf("get need_commit = %d\n", need_commit); |
|---|
| 1358 | |
|---|
| 1359 | value = websGetVar(wp, "action", ""); |
|---|
| 1360 | cprintf("get action = %s\n", value); |
|---|
| 1361 | |
|---|
| 1362 | /********** check action to do **********/ |
|---|
| 1363 | |
|---|
| 1364 | /** Apply **/ |
|---|
| 1365 | if (!strcmp(value, "Apply") || !strcmp(value, "ApplyTake")) { |
|---|
| 1366 | struct apply_action *act; |
|---|
| 1367 | |
|---|
| 1368 | cprintf("validate cgi"); |
|---|
| 1369 | validate_cgi(wp); |
|---|
| 1370 | cprintf("handle apply action\n"); |
|---|
| 1371 | act = handle_apply_action(submit_button); |
|---|
| 1372 | cprintf("done\n"); |
|---|
| 1373 | // If web page configuration is changed, the EZC configuration |
|---|
| 1374 | // function should be disabled.(2004-07-29) |
|---|
| 1375 | nvram_set("is_default", "0"); |
|---|
| 1376 | nvram_set("is_modified", "1"); |
|---|
| 1377 | if (act) { |
|---|
| 1378 | fprintf(stderr, |
|---|
| 1379 | "%s:submit_button=[%s] service=[%s] sleep_time=[%d] action=[%d]\n", |
|---|
| 1380 | value, act->name, act->service, act->sleep_time, |
|---|
| 1381 | act->action); |
|---|
| 1382 | |
|---|
| 1383 | if ((act->action == SYS_RESTART) |
|---|
| 1384 | || (act->action == SERVICE_RESTART)) { |
|---|
| 1385 | |
|---|
| 1386 | addAction(act->service); |
|---|
| 1387 | } |
|---|
| 1388 | sleep_time = act->sleep_time; |
|---|
| 1389 | action = act->action; |
|---|
| 1390 | |
|---|
| 1391 | if (act->goname) |
|---|
| 1392 | start_gozila(act->goname, wp); |
|---|
| 1393 | } else { |
|---|
| 1394 | // nvram_set ("action_service", ""); |
|---|
| 1395 | sleep_time = 1; |
|---|
| 1396 | action = RESTART; |
|---|
| 1397 | } |
|---|
| 1398 | diag_led(DIAG, STOP_LED); |
|---|
| 1399 | sys_commit(); |
|---|
| 1400 | } |
|---|
| 1401 | |
|---|
| 1402 | /** Restore defaults **/ |
|---|
| 1403 | else if (!strncmp(value, "Restore", 7)) { |
|---|
| 1404 | ACTION("ACT_SW_RESTORE"); |
|---|
| 1405 | nvram_set("sv_restore_defaults", "1"); |
|---|
| 1406 | #ifdef HAVE_BUFFALO_SA |
|---|
| 1407 | int region_sa = 0; |
|---|
| 1408 | if(nvram_default_match("region", "SA", "")) |
|---|
| 1409 | region_sa = 0; |
|---|
| 1410 | #endif |
|---|
| 1411 | killall("udhcpc", SIGKILL); |
|---|
| 1412 | sys_commit(); |
|---|
| 1413 | #ifdef HAVE_X86 |
|---|
| 1414 | #ifdef HAVE_ERC |
|---|
| 1415 | eval("nvram", "restore", "/etc/defaults/x86ree.backup"); |
|---|
| 1416 | eval("reboot"); |
|---|
| 1417 | eval("event", "5", "1", "15"); |
|---|
| 1418 | #endif |
|---|
| 1419 | char drive[64]; |
|---|
| 1420 | sprintf(drive, "/dev/%s", getdisc()); |
|---|
| 1421 | FILE *in = fopen(drive, "r+b"); |
|---|
| 1422 | fseeko(in, 0, SEEK_END); |
|---|
| 1423 | __off_t mtdlen = ftell(in); |
|---|
| 1424 | fseeko(in, mtdlen - (65536 * 2), SEEK_SET); |
|---|
| 1425 | int i; |
|---|
| 1426 | for (i = 0; i < 65536; i++) |
|---|
| 1427 | putc(0, in); // erase backup area |
|---|
| 1428 | fclose(in); |
|---|
| 1429 | eval("mount", "/usr/local", "-o", "remount,rw"); |
|---|
| 1430 | eval("rm", "-f", "/tmp/nvram/*"); // delete nvram database |
|---|
| 1431 | eval("rm", "-f", "/tmp/nvram/.lock"); // delete nvram database |
|---|
| 1432 | eval("rm", "-f", "/usr/local/nvram/*"); // delete nvram |
|---|
| 1433 | // database |
|---|
| 1434 | eval("mount", "/usr/local", "-o", "remount,ro"); |
|---|
| 1435 | eval("sync"); |
|---|
| 1436 | #elif HAVE_RB600 |
|---|
| 1437 | char drive[64]; |
|---|
| 1438 | sprintf(drive, "/dev/sda"); |
|---|
| 1439 | FILE *in = fopen(drive, "r+b"); |
|---|
| 1440 | fseeko(in, 0, SEEK_END); |
|---|
| 1441 | __off_t mtdlen = ftell(in); |
|---|
| 1442 | fseeko(in, mtdlen - (65536 * 2), SEEK_SET); |
|---|
| 1443 | int i; |
|---|
| 1444 | for (i = 0; i < 65536; i++) |
|---|
| 1445 | putc(0, in); // erase backup area |
|---|
| 1446 | fclose(in); |
|---|
| 1447 | eval("rm", "-f", "/tmp/nvram/*"); // delete nvram database |
|---|
| 1448 | eval("rm", "-f", "/tmp/nvram/.lock"); // delete nvram database |
|---|
| 1449 | eval("rm", "-f", "/usr/local/nvram/*"); // delete nvram |
|---|
| 1450 | eval("sync"); |
|---|
| 1451 | #elif HAVE_OPENRISC |
|---|
| 1452 | #ifdef HAVE_ERC |
|---|
| 1453 | eval("cp", "-f", "/etc/defaults/nvram.bin", |
|---|
| 1454 | "/usr/local/nvram/nvram.bin"); |
|---|
| 1455 | eval("sync"); |
|---|
| 1456 | eval("sync"); |
|---|
| 1457 | sleep(5); |
|---|
| 1458 | eval("event", "5", "1", "15"); |
|---|
| 1459 | #endif |
|---|
| 1460 | eval("mount", "/usr/local", "-o", "remount,rw"); |
|---|
| 1461 | eval("rm", "-f", "/tmp/nvram/*"); // delete nvram database |
|---|
| 1462 | eval("rm", "-f", "/tmp/nvram/.lock"); // delete nvram database |
|---|
| 1463 | eval("rm", "-f", "/usr/local/nvram/*"); // delete nvram |
|---|
| 1464 | // database |
|---|
| 1465 | eval("mount", "/usr/local", "-o", "remount,ro"); |
|---|
| 1466 | #elif HAVE_RB500 |
|---|
| 1467 | eval("rm", "-f", "/tmp/nvram/*"); // delete nvram database |
|---|
| 1468 | eval("rm", "-f", "/tmp/nvram/.lock"); // delete nvram database |
|---|
| 1469 | eval("rm", "-f", "/etc/nvram/*"); // delete nvram database |
|---|
| 1470 | #elif HAVE_MAGICBOX |
|---|
| 1471 | eval("rm", "-f", "/tmp/nvram/*"); // delete nvram database |
|---|
| 1472 | eval("rm", "-f", "/tmp/nvram/.lock"); // delete nvram database |
|---|
| 1473 | eval("erase", "nvram"); |
|---|
| 1474 | #else |
|---|
| 1475 | eval("erase", "nvram"); |
|---|
| 1476 | #endif |
|---|
| 1477 | #ifdef HAVE_BUFFALO_SA |
|---|
| 1478 | if(region_sa) |
|---|
| 1479 | { |
|---|
| 1480 | nvram_set("sv_restore_defaults", "1"); |
|---|
| 1481 | nvram_set("region", "SA"); |
|---|
| 1482 | } |
|---|
| 1483 | #endif |
|---|
| 1484 | sys_commit(); |
|---|
| 1485 | |
|---|
| 1486 | action = REBOOT; |
|---|
| 1487 | } |
|---|
| 1488 | |
|---|
| 1489 | /** Reboot **/ |
|---|
| 1490 | else if (!strncmp(value, "Reboot", 6)) { |
|---|
| 1491 | action = REBOOT; |
|---|
| 1492 | } |
|---|
| 1493 | |
|---|
| 1494 | /** GUI Logout **/// Experimental, not work yet ... |
|---|
| 1495 | else if (!strncmp(value, "Logout", 6)) { |
|---|
| 1496 | do_ej(NULL, "Logout.asp", wp, NULL); |
|---|
| 1497 | websDone(wp, 200); |
|---|
| 1498 | do_logout(); |
|---|
| 1499 | return 1; |
|---|
| 1500 | } |
|---|
| 1501 | |
|---|
| 1502 | /* |
|---|
| 1503 | * DEBUG : Invalid action |
|---|
| 1504 | */ |
|---|
| 1505 | else |
|---|
| 1506 | websDebugWrite(wp, "Invalid action %s<br />", value); |
|---|
| 1507 | |
|---|
| 1508 | footer: |
|---|
| 1509 | |
|---|
| 1510 | if (nvram_match("do_reboot", "1")) { |
|---|
| 1511 | action = REBOOT; |
|---|
| 1512 | } |
|---|
| 1513 | /* |
|---|
| 1514 | * The will let PC to re-get a new IP Address automatically |
|---|
| 1515 | */ |
|---|
| 1516 | if (need_reboot) |
|---|
| 1517 | action = REBOOT; |
|---|
| 1518 | |
|---|
| 1519 | if (!strcmp(value, "Apply")) { |
|---|
| 1520 | action = NOTHING; |
|---|
| 1521 | } |
|---|
| 1522 | |
|---|
| 1523 | if (action != REBOOT) { |
|---|
| 1524 | if (my_next_page[0] != '\0') |
|---|
| 1525 | sprintf(path, "%s", my_next_page); |
|---|
| 1526 | else { |
|---|
| 1527 | next_page = websGetVar(wp, "next_page", NULL); |
|---|
| 1528 | if (next_page) |
|---|
| 1529 | sprintf(path, "%s", next_page); |
|---|
| 1530 | else |
|---|
| 1531 | sprintf(path, "%s.asp", submit_button); |
|---|
| 1532 | } |
|---|
| 1533 | |
|---|
| 1534 | cprintf("refresh to %s\n", path); |
|---|
| 1535 | if (!strncmp(path, "WL_FilterTable", 14)) |
|---|
| 1536 | do_filtertable(NULL, path, wp, NULL); // refresh |
|---|
| 1537 | #ifdef HAVE_FREERADIUS |
|---|
| 1538 | else if (!strncmp(path, "FreeRadiusCert", 14)) |
|---|
| 1539 | do_radiuscert(NULL, path, wp, NULL); // refresh |
|---|
| 1540 | #endif |
|---|
| 1541 | else if (!strncmp(path, "WL_ActiveTable", 14)) |
|---|
| 1542 | do_activetable(NULL, path, wp, NULL); // refresh |
|---|
| 1543 | else if (!strncmp(path, "Wireless_WDS", 12)) |
|---|
| 1544 | do_wds(NULL, path, wp, NULL); // refresh |
|---|
| 1545 | else if (!strncmp(path, "Wireless_Advanced", 17)) |
|---|
| 1546 | do_wireless_adv(NULL, path, wp, NULL); // refresh |
|---|
| 1547 | else |
|---|
| 1548 | do_ej(NULL, path, wp, NULL); // refresh |
|---|
| 1549 | websDone(wp, 200); |
|---|
| 1550 | } else { |
|---|
| 1551 | #ifndef HAVE_WRK54G |
|---|
| 1552 | do_ej(NULL, "Reboot.asp", wp, NULL); |
|---|
| 1553 | websDone(wp, 200); |
|---|
| 1554 | #endif |
|---|
| 1555 | // sleep (5); |
|---|
| 1556 | sys_reboot(); |
|---|
| 1557 | return 1; |
|---|
| 1558 | } |
|---|
| 1559 | |
|---|
| 1560 | nvram_set("upnp_wan_proto", ""); |
|---|
| 1561 | sleep(sleep_time); |
|---|
| 1562 | if ((action == RESTART) || (action == SYS_RESTART)) |
|---|
| 1563 | sys_restart(); |
|---|
| 1564 | else if (action == SERVICE_RESTART) |
|---|
| 1565 | service_restart(); |
|---|
| 1566 | |
|---|
| 1567 | return 1; |
|---|
| 1568 | |
|---|
| 1569 | } |
|---|
| 1570 | |
|---|
| 1571 | //int auth_check( char *dirname, char *authorization ) |
|---|
| 1572 | int do_auth(webs_t wp, char *userid, char *passwd, char *realm, |
|---|
| 1573 | char *authorisation, int (*auth_check) (char *userid, char *passwd, |
|---|
| 1574 | char *dirname, |
|---|
| 1575 | char *authorisation)) |
|---|
| 1576 | { |
|---|
| 1577 | strncpy(userid, nvram_safe_get("http_username"), AUTH_MAX); |
|---|
| 1578 | strncpy(passwd, nvram_safe_get("http_passwd"), AUTH_MAX); |
|---|
| 1579 | // strncpy(realm, MODEL_NAME, AUTH_MAX); |
|---|
| 1580 | #if defined(HAVE_ERC) || defined(HAVE_IPR) |
|---|
| 1581 | strncpy(realm, "LOGIN", AUTH_MAX); |
|---|
| 1582 | wp->userid = 0; |
|---|
| 1583 | if (auth_check(userid, passwd, realm, authorisation)) |
|---|
| 1584 | return 1; |
|---|
| 1585 | wp->userid = 1; |
|---|
| 1586 | strncpy(userid, zencrypt("SuperAdmin"), AUTH_MAX); |
|---|
| 1587 | strncpy(passwd, nvram_safe_get("newhttp_passwd"), AUTH_MAX); |
|---|
| 1588 | if (auth_check(userid, passwd, realm, authorisation)) |
|---|
| 1589 | return 1; |
|---|
| 1590 | userid = 0; |
|---|
| 1591 | #else |
|---|
| 1592 | wp->userid = 0; |
|---|
| 1593 | strncpy(realm, nvram_safe_get("router_name"), AUTH_MAX); |
|---|
| 1594 | if (auth_check(userid, passwd, realm, authorisation)) |
|---|
| 1595 | return 1; |
|---|
| 1596 | #endif |
|---|
| 1597 | return 0; |
|---|
| 1598 | } |
|---|
| 1599 | |
|---|
| 1600 | int do_cauth(webs_t wp, char *userid, char *passwd, char *realm, |
|---|
| 1601 | char *authorisation, int (*auth_check) (char *userid, char *passwd, |
|---|
| 1602 | char *dirname, |
|---|
| 1603 | char *authorisation)) |
|---|
| 1604 | { |
|---|
| 1605 | if (nvram_match("info_passwd", "0")) |
|---|
| 1606 | return 1; |
|---|
| 1607 | return do_auth(wp, userid, passwd, realm, authorisation, auth_check); |
|---|
| 1608 | } |
|---|
| 1609 | |
|---|
| 1610 | #ifdef HAVE_REGISTER |
|---|
| 1611 | int do_auth_reg(webs_t wp, char *userid, char *passwd, char *realm, |
|---|
| 1612 | char *authorisation, int (*auth_check) (char *userid, |
|---|
| 1613 | char *passwd, |
|---|
| 1614 | char *dirname, |
|---|
| 1615 | char *authorisation)) |
|---|
| 1616 | { |
|---|
| 1617 | if (!isregistered()) |
|---|
| 1618 | return 1; |
|---|
| 1619 | return do_auth(wp, userid, passwd, realm, authorisation, auth_check); |
|---|
| 1620 | } |
|---|
| 1621 | #endif |
|---|
| 1622 | |
|---|
| 1623 | #undef HAVE_DDLAN |
|---|
| 1624 | |
|---|
| 1625 | #ifdef HAVE_DDLAN |
|---|
| 1626 | int do_auth2(webs_t wp, char *userid, char *passwd, char *realm, |
|---|
| 1627 | char *authorisation, int (*auth_check) (char *userid, char *passwd, |
|---|
| 1628 | char *dirname, |
|---|
| 1629 | char *authorisation)) |
|---|
| 1630 | { |
|---|
| 1631 | strncpy(userid, nvram_safe_get("http2_username"), AUTH_MAX); |
|---|
| 1632 | strncpy(passwd, nvram_safe_get("http2_passwd"), AUTH_MAX); |
|---|
| 1633 | // strncpy(realm, MODEL_NAME, AUTH_MAX); |
|---|
| 1634 | strncpy(realm, nvram_safe_get("router_name"), AUTH_MAX); |
|---|
| 1635 | if (auth_check(wp, userid, passwd, realm, authorisation)) |
|---|
| 1636 | return 1; |
|---|
| 1637 | return 0; |
|---|
| 1638 | } |
|---|
| 1639 | #endif |
|---|
| 1640 | // #ifdef EZC_SUPPORT |
|---|
| 1641 | char ezc_version[128]; |
|---|
| 1642 | |
|---|
| 1643 | // #endif |
|---|
| 1644 | |
|---|
| 1645 | extern int post; |
|---|
| 1646 | |
|---|
| 1647 | static char *post_buf = NULL; |
|---|
| 1648 | void // support GET and POST 2003-08-22 |
|---|
| 1649 | do_apply_post(char *url, webs_t stream, int len, char *boundary) |
|---|
| 1650 | { |
|---|
| 1651 | unsigned char buf[1024]; |
|---|
| 1652 | int count; |
|---|
| 1653 | if (post == 1) { |
|---|
| 1654 | if (post_buf) |
|---|
| 1655 | post_buf = (char *)realloc(post_buf, len + 1); |
|---|
| 1656 | else |
|---|
| 1657 | post_buf = (char *)safe_malloc(len + 1); |
|---|
| 1658 | |
|---|
| 1659 | if (!post_buf) { |
|---|
| 1660 | cprintf("The POST data exceed length limit!\n"); |
|---|
| 1661 | return; |
|---|
| 1662 | } |
|---|
| 1663 | /* |
|---|
| 1664 | * Get query |
|---|
| 1665 | */ |
|---|
| 1666 | if (!(count = wfread(post_buf, 1, len, stream))) |
|---|
| 1667 | return; |
|---|
| 1668 | post_buf[count] = '\0';; |
|---|
| 1669 | len -= strlen(post_buf); |
|---|
| 1670 | |
|---|
| 1671 | /* |
|---|
| 1672 | * Slurp anything remaining in the request |
|---|
| 1673 | */ |
|---|
| 1674 | while (--len > 0) |
|---|
| 1675 | #ifdef HAVE_HTTPS |
|---|
| 1676 | if (do_ssl) |
|---|
| 1677 | wfgets(buf, 1, stream); |
|---|
| 1678 | else |
|---|
| 1679 | #endif |
|---|
| 1680 | (void)fgetc(stream->fp); |
|---|
| 1681 | init_cgi(post_buf); |
|---|
| 1682 | } |
|---|
| 1683 | } |
|---|
| 1684 | |
|---|
| 1685 | #if !defined(HAVE_X86) && !defined(HAVE_MAGICBOX) |
|---|
| 1686 | static void do_cfebackup(struct mime_handler *handler, char *url, |
|---|
| 1687 | webs_t stream, char *query) |
|---|
| 1688 | { |
|---|
| 1689 | system2("cat /dev/mtd/0 > /tmp/cfe.bin"); |
|---|
| 1690 | do_file_attach(handler, "/tmp/cfe.bin", stream, NULL, "cfe.bin"); |
|---|
| 1691 | unlink("/tmp/cfe.bin"); |
|---|
| 1692 | } |
|---|
| 1693 | #endif |
|---|
| 1694 | #ifdef HAVE_ROUTERSTYLE |
|---|
| 1695 | static void do_stylecss(struct mime_handler *handler, char *url, |
|---|
| 1696 | webs_t stream, char *query) |
|---|
| 1697 | { |
|---|
| 1698 | char *style = nvram_get("router_style"); |
|---|
| 1699 | |
|---|
| 1700 | if (query != NULL) |
|---|
| 1701 | style = query; |
|---|
| 1702 | |
|---|
| 1703 | long sdata[30]; |
|---|
| 1704 | memset(sdata,0, sizeof(sdata)); |
|---|
| 1705 | long blue[30] = { |
|---|
| 1706 | 0x36f, 0xfff, 0x68f, 0x24d, 0x24d, 0x68f, 0x57f, 0xccf, 0x78f, |
|---|
| 1707 | 0x35d, |
|---|
| 1708 | 0x35c, 0x78f, |
|---|
| 1709 | 0x78f, 0xfff, 0x9af, 0x46e, 0x46e, 0x9af, 0x36f, |
|---|
| 1710 | 0xccf, 0xfff, 0x69f, 0xfff, 0xfff, 0x999, 0x69f, |
|---|
| 1711 | 0x69f, 0xccf, 0x78f, 0xfff |
|---|
| 1712 | }; |
|---|
| 1713 | |
|---|
| 1714 | long cyan[30] = { |
|---|
| 1715 | 0x099, 0xfff, 0x3bb, 0x066, 0x066, 0x3bb, 0x3bb, 0xcff, 0x4cc, |
|---|
| 1716 | 0x1aa, |
|---|
| 1717 | 0x1aa, 0x4cc, |
|---|
| 1718 | 0x6cc, 0xfff, 0x8dd, 0x5bb, 0x5bb, 0x8dd, 0x099, |
|---|
| 1719 | 0xcff, 0xfff, 0x3bb, 0xfff, 0xfff, 0x999, 0x3bb, |
|---|
| 1720 | 0x3bb, 0xcff, 0x6cc, 0xfff |
|---|
| 1721 | }; |
|---|
| 1722 | |
|---|
| 1723 | long elegant[30] = { |
|---|
| 1724 | 0x30519c, 0xfff, 0x496fc7, 0x496fc7, 0x496fc7, 0x496fc7, |
|---|
| 1725 | 0x496fc7, 0xfff, 0x6384cf, 0x6384cf, 0x6384cf, |
|---|
| 1726 | 0x6384cf, 0x6384cf, 0xfff, 0x849dd9, 0x849dd9, |
|---|
| 1727 | 0x849dd9, 0x849dd9, 0x30519c, 0xfff, 0xfff, |
|---|
| 1728 | 0x496fc7, 0xfff, 0xfff, 0x999, 0x496fc7, 0x496fc7, |
|---|
| 1729 | 0xfff, 0x6384cf, 0xfff |
|---|
| 1730 | }; |
|---|
| 1731 | |
|---|
| 1732 | long green[30] = { |
|---|
| 1733 | 0x090, 0xfff, 0x3b3, 0x060, 0x060, 0x3b3, 0x3b3, 0xcfc, 0x4c4, |
|---|
| 1734 | 0x1a1, |
|---|
| 1735 | 0x1a1, 0x4c4, |
|---|
| 1736 | 0x6c6, 0xfff, 0x8d8, 0x5b5, 0x5b5, 0x8d8, 0x090, |
|---|
| 1737 | 0xcfc, 0xfff, 0x3b3, 0xfff, 0xfff, 0x999, 0x3b3, |
|---|
| 1738 | 0x3b3, 0xcfc, 0x6c6, 0xfff |
|---|
| 1739 | }; |
|---|
| 1740 | |
|---|
| 1741 | long orange[30] = { |
|---|
| 1742 | 0xf26522, 0xfff, 0xff8400, 0xff8400, 0xff8400, 0xff8400, |
|---|
| 1743 | 0xff8400, 0xfff, 0xfeb311, 0xfeb311, 0xfeb311, |
|---|
| 1744 | 0xfeb311, 0xff9000, 0xfff, 0xffa200, 0xffa200, |
|---|
| 1745 | 0xffa200, 0xffa200, 0xf26522, 0xfff, 0xfff, |
|---|
| 1746 | 0xff8400, 0xfff, 0xfff, 0x999, 0xff8400, 0xff8400, |
|---|
| 1747 | 0xfff, 0xff9000, 0xfff |
|---|
| 1748 | }; |
|---|
| 1749 | |
|---|
| 1750 | long red[30] = { |
|---|
| 1751 | 0xc00, 0xfff, 0xe33, 0x800, 0x800, 0xe33, 0xd55, 0xfcc, 0xe77, |
|---|
| 1752 | 0xc44, |
|---|
| 1753 | 0xc44, 0xe77, |
|---|
| 1754 | 0xe77, 0xfff, 0xf99, 0xd55, 0xd55, 0xf99, 0xc00, |
|---|
| 1755 | 0xfcc, 0xfff, 0xd55, 0xfff, 0xfff, 0x999, 0xd55, |
|---|
| 1756 | 0xd55, 0xfcc, 0xe77, 0xfff |
|---|
| 1757 | }; |
|---|
| 1758 | |
|---|
| 1759 | long yellow[30] = { |
|---|
| 1760 | 0xeec900, 0x000, 0xee3, 0x880, 0x880, 0xee3, 0xffd700, 0x660, |
|---|
| 1761 | 0xee7, |
|---|
| 1762 | 0xbb4, |
|---|
| 1763 | 0xbb4, 0xee7, |
|---|
| 1764 | 0xeec900, 0x000, 0xff9, 0xcc5, 0xcc5, 0xff9, |
|---|
| 1765 | 0xeec900, 0x660, 0x000, 0xffd700, 0x000, 0xfff, |
|---|
| 1766 | 0x999, 0xffd700, 0xeec900, 0x660, 0xffd700, 0x000 |
|---|
| 1767 | }; |
|---|
| 1768 | |
|---|
| 1769 | if (!strcmp(style, "blue")) |
|---|
| 1770 | memcpy(sdata, blue, sizeof(blue)); |
|---|
| 1771 | else if (!strcmp(style, "cyan")) |
|---|
| 1772 | memcpy(sdata, cyan, sizeof(cyan)); |
|---|
| 1773 | else if (!strcmp(style, "yellow")) |
|---|
| 1774 | memcpy(sdata, yellow, sizeof(yellow)); |
|---|
| 1775 | else if (!strcmp(style, "green")) |
|---|
| 1776 | memcpy(sdata, green, sizeof(green)); |
|---|
| 1777 | else if (!strcmp(style, "orange")) |
|---|
| 1778 | memcpy(sdata, orange, sizeof(orange)); |
|---|
| 1779 | else if (!strcmp(style, "red")) |
|---|
| 1780 | memcpy(sdata, red, sizeof(red)); |
|---|
| 1781 | else // default to elegant |
|---|
| 1782 | memcpy(sdata, elegant, sizeof(elegant)); |
|---|
| 1783 | |
|---|
| 1784 | websWrite(stream, |
|---|
| 1785 | "@import url(../common.css);\n#menuSub,\n#menuMainList li span,\n#help h2 {\nbackground:#%03x;\n", |
|---|
| 1786 | sdata[0]); |
|---|
| 1787 | websWrite(stream, "color:#%03x;\n", sdata[1]); |
|---|
| 1788 | websWrite(stream, |
|---|
| 1789 | "border-color:#%03x #%03x #%03x #%03x;\n}\n#menuSubList li a {\n", |
|---|
| 1790 | sdata[2], sdata[3], sdata[4], sdata[5]); |
|---|
| 1791 | websWrite(stream, "background:#%03x;\n", sdata[6]); |
|---|
| 1792 | websWrite(stream, "color:#%03x;\n", sdata[7]); |
|---|
| 1793 | websWrite(stream, |
|---|
| 1794 | "border-color:#%03x #%03x #%03x #%03x;\n}\n#menuSubList li a:hover {\n", |
|---|
| 1795 | sdata[8], sdata[9], sdata[10], sdata[11]); |
|---|
| 1796 | websWrite(stream, "background:#%03x;\n", sdata[12]); |
|---|
| 1797 | websWrite(stream, "color:#%03x;\n", sdata[13]); |
|---|
| 1798 | websWrite(stream, |
|---|
| 1799 | "border-color:#%03x #%03x #%03x #%03x;\n}\nfieldset legend {\n", |
|---|
| 1800 | sdata[14], sdata[15], sdata[16], sdata[17]); |
|---|
| 1801 | websWrite(stream, "color:#%03x;\n}\n#help a {\n", sdata[18]); |
|---|
| 1802 | websWrite(stream, "color:#%03x;\n}\n#help a:hover {\n", sdata[19]); |
|---|
| 1803 | websWrite(stream, "color:#%03x;\n}\n.meter .bar {\n", sdata[20]); |
|---|
| 1804 | websWrite(stream, "background-color: #%03x;\n}\n.meter .text {\n", |
|---|
| 1805 | sdata[21]); |
|---|
| 1806 | websWrite(stream, "color:#%03x;\n}\n.progressbar {\n", sdata[22]); |
|---|
| 1807 | websWrite(stream, "background-color: #%03x;\n", sdata[23]); |
|---|
| 1808 | websWrite(stream, |
|---|
| 1809 | "border-color: #%03x;\nfont-size:.09em;\nborder-width:.09em;\n}\n.progressbarblock {\n", |
|---|
| 1810 | sdata[24]); |
|---|
| 1811 | websWrite(stream, |
|---|
| 1812 | "background-color: #%03x;\nfont-size:.09em;\n}\ninput.button {\n", |
|---|
| 1813 | sdata[25]); |
|---|
| 1814 | websWrite(stream, "background: #%03x;\n", sdata[26]); |
|---|
| 1815 | websWrite(stream, "color: #%03x;\n}\ninput.button:hover {\n", |
|---|
| 1816 | sdata[27]); |
|---|
| 1817 | websWrite(stream, "background: #%03x;\n", sdata[28]); |
|---|
| 1818 | websWrite(stream, "color: #%03x;\n}\n", sdata[29]); |
|---|
| 1819 | |
|---|
| 1820 | } |
|---|
| 1821 | |
|---|
| 1822 | static void do_stylecss_ie(struct mime_handler *handler, char *url, |
|---|
| 1823 | webs_t stream, char *query) |
|---|
| 1824 | { |
|---|
| 1825 | websWrite(stream, ".submitFooter input {\n" |
|---|
| 1826 | "padding:.362em .453em;\n" |
|---|
| 1827 | "}\n" |
|---|
| 1828 | "fieldset {\n" |
|---|
| 1829 | "padding-top:0;\n" |
|---|
| 1830 | "}\n" |
|---|
| 1831 | "fieldset legend {\n" |
|---|
| 1832 | "margin-left:-9px;\n" |
|---|
| 1833 | "margin-bottom:8px;\n" "padding:0 .09em;\n" "}\n"); |
|---|
| 1834 | } |
|---|
| 1835 | #endif |
|---|
| 1836 | #ifdef HAVE_REGISTER |
|---|
| 1837 | static void do_trial_logo(struct mime_handler *handler, char *url, |
|---|
| 1838 | webs_t stream, char *query) |
|---|
| 1839 | { |
|---|
| 1840 | #if defined(HAVE_TRIMAX) || defined(HAVE_MAKSAT) || defined(HAVE_VILIM) || defined(HAVE_TELCOM) || defined(HAVE_WIKINGS) || defined(HAVE_NEXTMEDIA) |
|---|
| 1841 | do_file(handler, url, stream, query); |
|---|
| 1842 | #else |
|---|
| 1843 | if (!isregistered_real()) { |
|---|
| 1844 | do_file(handler, "style/logo-trial.png", stream, query); |
|---|
| 1845 | } else { |
|---|
| 1846 | if (iscpe()) { |
|---|
| 1847 | do_file(handler, "style/logo-cpe.png", stream, query); |
|---|
| 1848 | } else { |
|---|
| 1849 | do_file(handler, url, stream, query); |
|---|
| 1850 | } |
|---|
| 1851 | } |
|---|
| 1852 | #endif |
|---|
| 1853 | } |
|---|
| 1854 | |
|---|
| 1855 | #endif |
|---|
| 1856 | /* |
|---|
| 1857 | * static void do_style (char *url, webs_t stream, char *query) { char *style |
|---|
| 1858 | * = nvram_get ("router_style"); if (style == NULL || strlen (style) == 0) |
|---|
| 1859 | * do_file ("kromo.css", stream, NULL); else do_file (style, stream, NULL); } |
|---|
| 1860 | */ |
|---|
| 1861 | |
|---|
| 1862 | static void do_mypage(struct mime_handler *handler, char *url, |
|---|
| 1863 | webs_t stream, char *query) |
|---|
| 1864 | { |
|---|
| 1865 | char *snamelist = nvram_safe_get("mypage_scripts"); |
|---|
| 1866 | char *next; |
|---|
| 1867 | char sname[128]; |
|---|
| 1868 | int qnum; |
|---|
| 1869 | int i = 1; |
|---|
| 1870 | |
|---|
| 1871 | if (query == NULL || strlen(query) == 0) |
|---|
| 1872 | qnum = 1; |
|---|
| 1873 | else |
|---|
| 1874 | qnum = atoi(query); |
|---|
| 1875 | |
|---|
| 1876 | foreach(sname, snamelist, next) { |
|---|
| 1877 | if (qnum == i) { |
|---|
| 1878 | strcat(sname, " > /tmp/mypage.tmp"); |
|---|
| 1879 | system2(sname); |
|---|
| 1880 | do_file_attach(handler, "/tmp/mypage.tmp", stream, NULL, |
|---|
| 1881 | "MyPage.asp"); |
|---|
| 1882 | unlink("/tmp/mypage.tmp"); |
|---|
| 1883 | } |
|---|
| 1884 | i++; |
|---|
| 1885 | } |
|---|
| 1886 | |
|---|
| 1887 | return; |
|---|
| 1888 | |
|---|
| 1889 | } |
|---|
| 1890 | |
|---|
| 1891 | static void do_fetchif(struct mime_handler *handler, char *url, |
|---|
| 1892 | webs_t stream, char *query) |
|---|
| 1893 | { |
|---|
| 1894 | char line[256]; |
|---|
| 1895 | int i, llen; |
|---|
| 1896 | char buffer[256]; |
|---|
| 1897 | char querybuffer[32]; |
|---|
| 1898 | |
|---|
| 1899 | if (query == NULL || strlen(query) == 0) |
|---|
| 1900 | return; |
|---|
| 1901 | |
|---|
| 1902 | strncpy(querybuffer, query, 30); |
|---|
| 1903 | strcat(querybuffer, ":"); |
|---|
| 1904 | |
|---|
| 1905 | int strbuffer = 0; |
|---|
| 1906 | time_t tm; |
|---|
| 1907 | struct tm tm_time; |
|---|
| 1908 | |
|---|
| 1909 | time(&tm); |
|---|
| 1910 | memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); |
|---|
| 1911 | char *date_fmt = "%a %b %e %H:%M:%S %Z %Y"; |
|---|
| 1912 | |
|---|
| 1913 | strftime(buffer, 200, date_fmt, &tm_time); |
|---|
| 1914 | strbuffer = strlen(buffer); |
|---|
| 1915 | buffer[strbuffer++] = '\n'; |
|---|
| 1916 | FILE *in = fopen("/proc/net/dev", "rb"); |
|---|
| 1917 | |
|---|
| 1918 | if (in == NULL) |
|---|
| 1919 | return; |
|---|
| 1920 | |
|---|
| 1921 | /* eat first two lines */ |
|---|
| 1922 | fgets(line, sizeof(line), in); |
|---|
| 1923 | fgets(line, sizeof(line), in); |
|---|
| 1924 | |
|---|
| 1925 | while (fgets(line, sizeof(line), in) != NULL) { |
|---|
| 1926 | if (strstr(line, querybuffer)) { |
|---|
| 1927 | llen = strlen(line); |
|---|
| 1928 | for (i = 0; i < llen; i++) { |
|---|
| 1929 | buffer[strbuffer++] = line[i]; |
|---|
| 1930 | } |
|---|
| 1931 | break; |
|---|
| 1932 | } |
|---|
| 1933 | } |
|---|
| 1934 | fclose(in); |
|---|
| 1935 | |
|---|
| 1936 | buffer[strbuffer] = 0; |
|---|
| 1937 | websWrite(stream, "%s", buffer); |
|---|
| 1938 | } |
|---|
| 1939 | |
|---|
| 1940 | static char *getLanguageName() |
|---|
| 1941 | { |
|---|
| 1942 | char *lang = nvram_get("language"); |
|---|
| 1943 | |
|---|
| 1944 | cprintf("get language %s\n", lang); |
|---|
| 1945 | char *l = safe_malloc(60); |
|---|
| 1946 | |
|---|
| 1947 | if (lang == NULL) { |
|---|
| 1948 | cprintf("return default\n"); |
|---|
| 1949 | sprintf(l, "lang_pack/english.js"); |
|---|
| 1950 | return l; |
|---|
| 1951 | } |
|---|
| 1952 | sprintf(l, "lang_pack/%s.js", lang); |
|---|
| 1953 | cprintf("return %s\n", l); |
|---|
| 1954 | return l; |
|---|
| 1955 | } |
|---|
| 1956 | |
|---|
| 1957 | char *live_translate(char *tran) |
|---|
| 1958 | { |
|---|
| 1959 | |
|---|
| 1960 | FILE *fp; |
|---|
| 1961 | static char temp[256], temp1[256]; |
|---|
| 1962 | char *temp2; |
|---|
| 1963 | if (tran == NULL || !strlen(tran)) |
|---|
| 1964 | return ""; |
|---|
| 1965 | char *lang = getLanguageName(); |
|---|
| 1966 | char buf[64]; |
|---|
| 1967 | int start, filelen, pos; |
|---|
| 1968 | |
|---|
| 1969 | memset(temp, 0, sizeof(temp)); |
|---|
| 1970 | memset(temp1, 0, sizeof(temp)); |
|---|
| 1971 | |
|---|
| 1972 | sprintf(buf, "%s", lang); |
|---|
| 1973 | free(lang); |
|---|
| 1974 | |
|---|
| 1975 | strcpy(temp1, tran); |
|---|
| 1976 | strcat(temp1, "=\""); |
|---|
| 1977 | |
|---|
| 1978 | int len = strlen(temp1); |
|---|
| 1979 | |
|---|
| 1980 | fp = getWebsFile(buf); |
|---|
| 1981 | if (fp) { |
|---|
| 1982 | start = ftell(fp); |
|---|
| 1983 | filelen = getWebsFileLen(buf); |
|---|
| 1984 | |
|---|
| 1985 | while (fgets(temp, 256, fp) != NULL) { |
|---|
| 1986 | pos = ftell(fp); |
|---|
| 1987 | |
|---|
| 1988 | if ((pos - start) > filelen) |
|---|
| 1989 | break; |
|---|
| 1990 | if ((memcmp(temp, temp1, len)) == 0) { |
|---|
| 1991 | temp2 = strtok(temp, "\""); |
|---|
| 1992 | temp2 = strtok(NULL, "\""); |
|---|
| 1993 | |
|---|
| 1994 | fclose(fp); |
|---|
| 1995 | return temp2; |
|---|
| 1996 | } |
|---|
| 1997 | } |
|---|
| 1998 | fclose(fp); |
|---|
| 1999 | } |
|---|
| 2000 | |
|---|
| 2001 | strcpy(buf, "lang_pack/english.js"); // if string not found, try english |
|---|
| 2002 | fp = getWebsFile(buf); |
|---|
| 2003 | |
|---|
| 2004 | if (fp == NULL) |
|---|
| 2005 | return "Error"; |
|---|
| 2006 | start = ftell(fp); |
|---|
| 2007 | filelen = getWebsFileLen(buf); |
|---|
| 2008 | |
|---|
| 2009 | while (fgets(temp, 256, fp) != NULL) { |
|---|
| 2010 | pos = ftell(fp); |
|---|
| 2011 | |
|---|
| 2012 | if ((pos - start) > filelen) |
|---|
| 2013 | break; |
|---|
| 2014 | if ((memcmp(temp, temp1, len)) == 0) { |
|---|
| 2015 | temp2 = strtok(temp, "\""); |
|---|
| 2016 | temp2 = strtok(NULL, "\""); |
|---|
| 2017 | |
|---|
| 2018 | fclose(fp); |
|---|
| 2019 | return temp2; |
|---|
| 2020 | } |
|---|
| 2021 | } |
|---|
| 2022 | fclose(fp); |
|---|
| 2023 | |
|---|
| 2024 | return "Error"; // not found |
|---|
| 2025 | |
|---|
| 2026 | } |
|---|
| 2027 | |
|---|
| 2028 | static void do_ttgraph(struct mime_handler *handler, char *url, |
|---|
| 2029 | webs_t stream, char *query) |
|---|
| 2030 | { |
|---|
| 2031 | #define COL_WIDTH 16 /* single column width */ |
|---|
| 2032 | |
|---|
| 2033 | char *next; |
|---|
| 2034 | char var[80]; |
|---|
| 2035 | |
|---|
| 2036 | unsigned int days; |
|---|
| 2037 | unsigned int month; |
|---|
| 2038 | unsigned int year; |
|---|
| 2039 | int wd; |
|---|
| 2040 | int i = 0; |
|---|
| 2041 | char months[12][12] = { |
|---|
| 2042 | "share.jan", "share.feb", "share.mar", "share.apr", "share.may", |
|---|
| 2043 | "share.jun", |
|---|
| 2044 | "share.jul", "share.aug", "share.sep", "share.oct", |
|---|
| 2045 | "share.nov", "share.dec" |
|---|
| 2046 | }; |
|---|
| 2047 | unsigned long rcvd[31] = { |
|---|
| 2048 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 2049 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
|---|
| 2050 | }; |
|---|
| 2051 | unsigned long sent[31] = { |
|---|
| 2052 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|---|
| 2053 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
|---|
| 2054 | }; |
|---|
| 2055 | unsigned long max = 5, smax = 5, f = 1; |
|---|
| 2056 | unsigned long totin = 0; |
|---|
| 2057 | unsigned long totout = 0; |
|---|
| 2058 | |
|---|
| 2059 | if (sscanf(query, "%u-%u", &month, &year) != 2) |
|---|
| 2060 | return; |
|---|
| 2061 | if (month < 1 || month > 12) |
|---|
| 2062 | return; |
|---|
| 2063 | |
|---|
| 2064 | days = daysformonth(month, year); |
|---|
| 2065 | wd = weekday(month, 1, year); // first day in month (mon=0, tue=1, |
|---|
| 2066 | // ..., sun=6) |
|---|
| 2067 | |
|---|
| 2068 | char tq[32]; |
|---|
| 2069 | |
|---|
| 2070 | sprintf(tq, "traff-%02u-%u", month, year); |
|---|
| 2071 | char *tdata = nvram_safe_get(tq); |
|---|
| 2072 | |
|---|
| 2073 | if (tdata != NULL && strlen(tdata)) { |
|---|
| 2074 | foreach(var, tdata, next) { |
|---|
| 2075 | if (i == days) |
|---|
| 2076 | break; //skip monthly total |
|---|
| 2077 | int ret = sscanf(var, "%lu:%lu", &rcvd[i], &sent[i]); |
|---|
| 2078 | if (ret != 2) |
|---|
| 2079 | break; |
|---|
| 2080 | totin += rcvd[i]; |
|---|
| 2081 | totout += sent[i]; |
|---|
| 2082 | if (rcvd[i] > max) |
|---|
| 2083 | max = rcvd[i]; |
|---|
| 2084 | if (sent[i] > max) |
|---|
| 2085 | max = sent[i]; |
|---|
| 2086 | i++; |
|---|
| 2087 | } |
|---|
| 2088 | } |
|---|
| 2089 | |
|---|
| 2090 | while (max > smax) { |
|---|
| 2091 | if (max > (f * 5)) |
|---|
| 2092 | smax = f * 10; |
|---|
| 2093 | if (max > (f * 10)) |
|---|
| 2094 | smax = f * 25; |
|---|
| 2095 | if (max > (f * 25)) |
|---|
| 2096 | smax = f * 50; |
|---|
| 2097 | f = f * 10; |
|---|
| 2098 | } |
|---|
| 2099 | |
|---|
| 2100 | char incom[32]; |
|---|
| 2101 | |
|---|
| 2102 | snprintf(incom, 32, "%s", live_translate("status_inet.traffin")); |
|---|
| 2103 | char outcom[32]; |
|---|
| 2104 | |
|---|
| 2105 | snprintf(outcom, 32, "%s", live_translate("status_inet.traffout")); |
|---|
| 2106 | char monthname[32]; |
|---|
| 2107 | |
|---|
| 2108 | snprintf(monthname, 32, "%s", live_translate(months[month - 1])); |
|---|
| 2109 | |
|---|
| 2110 | websWrite(stream, |
|---|
| 2111 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" |
|---|
| 2112 | "<html>\n" |
|---|
| 2113 | "<head>\n" |
|---|
| 2114 | "<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=%s\" />\n", |
|---|
| 2115 | live_translate("lang_charset.set")); |
|---|
| 2116 | |
|---|
| 2117 | websWrite(stream, "<title>dd-wrt traffic graph</title>\n" |
|---|
| 2118 | "<script type=\"text/javascript\">\n" |
|---|
| 2119 | "//<![CDATA[\n" |
|---|
| 2120 | "function Show(label) {\n" |
|---|
| 2121 | "document.getElementById(\"label\").innerHTML = label;\n" |
|---|
| 2122 | "}\n" |
|---|
| 2123 | "//]]>\n" |
|---|
| 2124 | "</script>\n" |
|---|
| 2125 | "<style type=\"text/css\">\n\n" |
|---|
| 2126 | "#t-graph {position: relative; width: %upx; height: 300px;\n", |
|---|
| 2127 | days * COL_WIDTH); |
|---|
| 2128 | websWrite(stream, " margin: 1.1em 0 3.5em; padding: 0;\n" |
|---|
| 2129 | " border: 1px solid gray; list-style: none;\n" |
|---|
| 2130 | " font: 9px Tahoma, Arial, sans-serif;}\n" |
|---|
| 2131 | "#t-graph ul {margin: 0; padding: 0; list-style: none;}\n" |
|---|
| 2132 | "#t-graph li {position: absolute; bottom: 0; width: %dpx; z-index: 2;\n", |
|---|
| 2133 | COL_WIDTH); |
|---|
| 2134 | websWrite(stream, " margin: 0; padding: 0;\n" |
|---|
| 2135 | " text-align: center; list-style: none;}\n" |
|---|
| 2136 | "#t-graph li.day {height: 298px; padding-top: 2px; border-right: 1px dotted #C4C4C4; color: #AAA;}\n" |
|---|
| 2137 | "#t-graph li.day_sun {height: 298px; padding-top: 2px; border-right: 1px dotted #C4C4C4; color: #E00;}\n" |
|---|
| 2138 | "#t-graph li.bar {width: 4px; border: 1px solid; border-bottom: none; color: #000;}\n" |
|---|
| 2139 | "#t-graph li.bar p {margin: 5px 0 0; padding: 0;}\n" |
|---|
| 2140 | "#t-graph li.rcvd {left: 3px; background: #228B22;}\n" |
|---|
| 2141 | "#t-graph li.sent {left: 8px; background: #CD0000;}\n"); |
|---|
| 2142 | |
|---|
| 2143 | for (i = 0; i < days - 1; i++) { |
|---|
| 2144 | websWrite(stream, "#t-graph #d%d {left: %dpx;}\n", i + 1, |
|---|
| 2145 | i * COL_WIDTH); |
|---|
| 2146 | } |
|---|
| 2147 | websWrite(stream, "#t-graph #d%u {left: %upx; border-right: none;}\n", |
|---|
| 2148 | days, (days - 1) * COL_WIDTH); |
|---|
| 2149 | |
|---|
| 2150 | websWrite(stream, |
|---|
| 2151 | "#t-graph #ticks {width: %upx; height: 300px; z-index: 1;}\n", |
|---|
| 2152 | days * COL_WIDTH); |
|---|
| 2153 | websWrite(stream, |
|---|
| 2154 | "#t-graph #ticks .tick {position: relative; border-bottom: 1px solid #BBB; width: %upx;}\n", |
|---|
| 2155 | days * COL_WIDTH); |
|---|
| 2156 | websWrite(stream, |
|---|
| 2157 | "#t-graph #ticks .tick p {position: absolute; left: 100%%; top: -0.67em; margin: 0 0 0 0.5em;}\n" |
|---|
| 2158 | "#t-graph #label {width: 500px; bottom: -20px; z-index: 1; font: 12px Tahoma, Arial, sans-serif; font-weight: bold;}\n" |
|---|
| 2159 | "</style>\n" |
|---|
| 2160 | "</head>\n\n" "<body>\n" "<ul id=\"t-graph\">\n"); |
|---|
| 2161 | |
|---|
| 2162 | for (i = 0; i < days; i++) { |
|---|
| 2163 | websWrite(stream, "<li class=\"day%s\" id=\"d%d\" ", |
|---|
| 2164 | (wd % 7) == 6 ? "_sun" : "", i + 1); |
|---|
| 2165 | wd++; |
|---|
| 2166 | websWrite(stream, |
|---|
| 2167 | "onmouseover=\"Show(\'%s %d, %d (%s: %lu MB / %s: %lu MB)\')\" ", |
|---|
| 2168 | monthname, i + 1, year, incom, rcvd[i], outcom, |
|---|
| 2169 | sent[i]); |
|---|
| 2170 | websWrite(stream, |
|---|
| 2171 | "onmouseout=\"Show(\'%s %d (%s: %lu MB / %s: %lu MB)\')\"", |
|---|
| 2172 | monthname, year, incom, totin, outcom, totout); |
|---|
| 2173 | websWrite(stream, ">%d\n", i + 1); |
|---|
| 2174 | websWrite(stream, "<ul>\n"); |
|---|
| 2175 | websWrite(stream, |
|---|
| 2176 | "<li class=\"rcvd bar\" style=\"height: %lupx;\"><p></p></li>\n", |
|---|
| 2177 | rcvd[i] * 300 / smax); |
|---|
| 2178 | websWrite(stream, |
|---|
| 2179 | "<li class=\"sent bar\" style=\"height: %lupx;\"><p></p></li>\n", |
|---|
| 2180 | sent[i] * 300 / smax); |
|---|
| 2181 | websWrite(stream, "</ul>\n"); |
|---|
| 2182 | websWrite(stream, "</li>\n"); |
|---|
| 2183 | } |
|---|
| 2184 | |
|---|
| 2185 | websWrite(stream, "<li id=\"ticks\">\n"); |
|---|
| 2186 | for (i = 5; i; i--) // scale |
|---|
| 2187 | { |
|---|
| 2188 | websWrite(stream, |
|---|
| 2189 | "<div class=\"tick\" style=\"height: 59px;\"><p>%d%sMB</p></div>\n", |
|---|
| 2190 | smax * i / 5, (smax > 10000) ? " " : " "); |
|---|
| 2191 | } |
|---|
| 2192 | websWrite(stream, "</li>\n\n"); |
|---|
| 2193 | |
|---|
| 2194 | websWrite(stream, "<li id=\"label\">\n"); |
|---|
| 2195 | websWrite(stream, "%s %d (%s: %lu MB / %s: %lu MB)\n", monthname, year, |
|---|
| 2196 | incom, totin, outcom, totout); |
|---|
| 2197 | websWrite(stream, "</li>\n" "</ul>\n\n" "</body>\n" "</html>\n"); |
|---|
| 2198 | |
|---|
| 2199 | } |
|---|
| 2200 | |
|---|
| 2201 | static void ttraff_backup(struct mime_handler *handler, char *url, |
|---|
| 2202 | webs_t stream, char *query) |
|---|
| 2203 | { |
|---|
| 2204 | system2("echo TRAFF-DATA > /tmp/traffdata.bak"); |
|---|
| 2205 | system2("nvram show | grep traff- >> /tmp/traffdata.bak"); |
|---|
| 2206 | do_file_attach(handler, "/tmp/traffdata.bak", stream, NULL, |
|---|
| 2207 | "traffdata.bak"); |
|---|
| 2208 | unlink("/tmp/traffdata.bak"); |
|---|
| 2209 | } static void do_apply_cgi(struct mime_handler *handler, char *url, |
|---|
| 2210 | webs_t stream, char *q) |
|---|
| 2211 | { |
|---|
| 2212 | char *path, *query; |
|---|
| 2213 | |
|---|
| 2214 | if (post == 1) { |
|---|
| 2215 | query = post_buf; |
|---|
| 2216 | path = url; |
|---|
| 2217 | } else { |
|---|
| 2218 | query = url; |
|---|
| 2219 | path = strsep(&query, "?") ? : url; |
|---|
| 2220 | init_cgi(query); |
|---|
| 2221 | } |
|---|
| 2222 | |
|---|
| 2223 | if (!query) |
|---|
| 2224 | return; |
|---|
| 2225 | |
|---|
| 2226 | apply_cgi(stream, NULL, NULL, 0, url, path, query); |
|---|
| 2227 | init_cgi(NULL); |
|---|
| 2228 | } |
|---|
| 2229 | |
|---|
| 2230 | #ifdef HAVE_MADWIFI |
|---|
| 2231 | extern int getdevicecount(void); |
|---|
| 2232 | #endif |
|---|
| 2233 | |
|---|
| 2234 | #ifdef HAVE_LANGUAGE |
|---|
| 2235 | static void do_language(struct mime_handler *handler, char *path, webs_t stream, char *query) // jimmy, |
|---|
| 2236 | // https, |
|---|
| 2237 | // 8/4/2003 |
|---|
| 2238 | { |
|---|
| 2239 | char *lang = getLanguageName(); |
|---|
| 2240 | |
|---|
| 2241 | do_file(handler, lang, stream, NULL); |
|---|
| 2242 | free(lang); |
|---|
| 2243 | return; |
|---|
| 2244 | } |
|---|
| 2245 | #endif |
|---|
| 2246 | extern int issuperchannel(void); |
|---|
| 2247 | |
|---|
| 2248 | static char no_cache[] = |
|---|
| 2249 | "Cache-Control: no-cache\r\n" "Pragma: no-cache\r\n" "Expires: 0"; |
|---|
| 2250 | |
|---|
| 2251 | struct mime_handler mime_handlers[] = { |
|---|
| 2252 | // { "ezconfig.asp", "text/html", ezc_version, do_apply_ezconfig_post, |
|---|
| 2253 | // do_ezconfig_asp, do_auth }, |
|---|
| 2254 | #ifdef HAVE_SKYTRON |
|---|
| 2255 | {"setupindex*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2256 | #endif |
|---|
| 2257 | #ifdef HAVE_POKER |
|---|
| 2258 | {"PokerEdit.asp", "text/html", no_cache, NULL, do_ej, NULL, 1}, |
|---|
| 2259 | #endif |
|---|
| 2260 | #ifdef HAVE_DDLAN |
|---|
| 2261 | {"Upgrade*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2262 | {"Management*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2263 | {"Services*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2264 | {"Hotspot*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2265 | {"Wireless*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2266 | {"WL_*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2267 | {"WPA*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2268 | {"Log*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2269 | {"Alive*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2270 | {"Diagnostics*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2271 | {"Wol*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2272 | {"Factory_Defaults*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2273 | {"config*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2274 | #endif |
|---|
| 2275 | |
|---|
| 2276 | {"changepass.asp", "text/html", no_cache, NULL, do_ej, NULL, 1}, |
|---|
| 2277 | #ifdef HAVE_REGISTER |
|---|
| 2278 | {"register.asp", "text/html", no_cache, NULL, do_ej, do_auth_reg, 1}, |
|---|
| 2279 | #endif |
|---|
| 2280 | {"WL_FilterTable*", "text/html", no_cache, NULL, do_filtertable, |
|---|
| 2281 | do_auth, 1}, |
|---|
| 2282 | #ifdef HAVE_FREERADIUS |
|---|
| 2283 | {"FreeRadiusCert*", "text/html", no_cache, NULL, do_radiuscert, do_auth, |
|---|
| 2284 | 1}, |
|---|
| 2285 | {"freeradius-certs/*", "application/octet-stream", no_cache, NULL, |
|---|
| 2286 | cert_file_out, do_auth, 0}, |
|---|
| 2287 | #endif |
|---|
| 2288 | // #endif |
|---|
| 2289 | // #ifdef HAVE_MADWIFI |
|---|
| 2290 | {"Wireless_WDS*", "text/html", no_cache, NULL, do_wds, do_auth, 1}, |
|---|
| 2291 | {"WL_ActiveTable*", "text/html", no_cache, NULL, do_activetable, |
|---|
| 2292 | do_auth, 1}, |
|---|
| 2293 | {"Wireless_Advanced*", "text/html", no_cache, NULL, do_wireless_adv, |
|---|
| 2294 | do_auth, 1}, |
|---|
| 2295 | // #endif |
|---|
| 2296 | {"MyPage.asp*", "text/html", no_cache, NULL, do_mypage, do_auth, 1}, |
|---|
| 2297 | {"**.asp", "text/html", no_cache, NULL, do_ej, do_auth, 1}, |
|---|
| 2298 | {"**.JPG", "image/jpeg", no_cache, NULL, do_file, NULL, 0}, |
|---|
| 2299 | // {"style.css", "text/css", NULL, NULL, do_style, NULL}, |
|---|
| 2300 | {"common.js", "text/javascript", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2301 | #ifdef HAVE_LANGUAGE |
|---|
| 2302 | {"lang_pack/language.js", "text/javascript", NULL, NULL, do_language, |
|---|
| 2303 | NULL, 0}, |
|---|
| 2304 | #endif |
|---|
| 2305 | #ifdef HAVE_BUFFALO |
|---|
| 2306 | {"vsp.html", "text/plain", no_cache, NULL, do_vsp_page, NULL, 1}, |
|---|
| 2307 | #endif |
|---|
| 2308 | {"SysInfo.htm*", "text/plain", no_cache, NULL, do_ej, do_auth, 1}, |
|---|
| 2309 | #ifdef HAVE_SKYTRON |
|---|
| 2310 | {"Info.htm*", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2311 | {"Info.live.htm", "text/html", no_cache, NULL, do_ej, do_auth, 1}, |
|---|
| 2312 | {"**.htm", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2313 | {"**.html", "text/html", no_cache, NULL, do_ej, do_auth2, 1}, |
|---|
| 2314 | #else |
|---|
| 2315 | {"Info.htm*", "text/html", no_cache, NULL, do_ej, do_cauth, 1}, |
|---|
| 2316 | {"Info.live.htm", "text/html", no_cache, NULL, do_ej, do_cauth, 1}, |
|---|
| 2317 | {"**.htm", "text/html", no_cache, NULL, do_ej, NULL, 1}, |
|---|
| 2318 | {"**.html", "text/html", no_cache, NULL, do_ej, NULL, 1}, |
|---|
| 2319 | |
|---|
| 2320 | #endif |
|---|
| 2321 | #ifdef HAVE_ROUTERSTYLE |
|---|
| 2322 | {"style/blue/style.css", "text/css", NULL, NULL, do_stylecss, NULL, 1}, |
|---|
| 2323 | {"style/cyan/style.css", "text/css", NULL, NULL, do_stylecss, NULL, 1}, |
|---|
| 2324 | {"style/elegant/style.css", "text/css", NULL, NULL, do_stylecss, NULL, |
|---|
| 2325 | 1}, |
|---|
| 2326 | {"style/green/style.css", "text/css", NULL, NULL, do_stylecss, NULL, 1}, |
|---|
| 2327 | {"style/orange/style.css", "text/css", NULL, NULL, do_stylecss, NULL, |
|---|
| 2328 | 1}, |
|---|
| 2329 | {"style/red/style.css", "text/css", NULL, NULL, do_stylecss, NULL, 1}, |
|---|
| 2330 | {"style/yellow/style.css", "text/css", NULL, NULL, do_stylecss, NULL, |
|---|
| 2331 | 1}, |
|---|
| 2332 | {"style/blue/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, |
|---|
| 2333 | NULL, |
|---|
| 2334 | 1}, |
|---|
| 2335 | {"style/cyan/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, |
|---|
| 2336 | NULL, |
|---|
| 2337 | 1}, |
|---|
| 2338 | {"style/elegant/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, |
|---|
| 2339 | NULL, 1}, |
|---|
| 2340 | {"style/green/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, |
|---|
| 2341 | NULL, |
|---|
| 2342 | 1}, |
|---|
| 2343 | {"style/orange/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, |
|---|
| 2344 | NULL, 1}, |
|---|
| 2345 | {"style/red/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, NULL, |
|---|
| 2346 | 1}, |
|---|
| 2347 | {"style/yellow/style_ie.css", "text/css", NULL, NULL, do_stylecss_ie, |
|---|
| 2348 | NULL, 1}, |
|---|
| 2349 | #endif |
|---|
| 2350 | #ifdef HAVE_REGISTER |
|---|
| 2351 | {"style/logo.png", "image/png", NULL, NULL, do_trial_logo, NULL, 0}, |
|---|
| 2352 | #endif |
|---|
| 2353 | {"**.css", "text/css", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2354 | {"**.svg", "image/svg+xml", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2355 | {"**.gif", "image/gif", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2356 | {"**.png", "image/png", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2357 | {"**.jpg", "image/jpeg", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2358 | {"**.ico", "image/x-icon", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2359 | {"**.js", "text/javascript", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2360 | {"**.swf", "application/x-shockwave-flash", NULL, NULL, do_file, NULL, |
|---|
| 2361 | 0}, |
|---|
| 2362 | {"**.pdf", "application/pdf", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2363 | {"**.mp4", "video/mp4", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2364 | {"**.mp3", "audio/mpeg3", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2365 | {"**.mpg", "video/mpeg", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2366 | {"**.avi", "video/x-msvideo", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2367 | {"**.wma", "audio/x-ms-wma", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2368 | {"**.wmv", "video/x-ms-wmv", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2369 | {"**.flv", "video/x-flv", NULL, NULL, do_file, NULL, 0}, |
|---|
| 2370 | #ifdef HAVE_SKYTRON |
|---|
| 2371 | {"applyuser.cgi*", "text/html", no_cache, do_apply_post, do_apply_cgi, |
|---|
| 2372 | do_auth2, 1}, |
|---|
| 2373 | #elif HAVE_DDLAN |
|---|
| 2374 | {"applyuser.cgi*", "text/html", no_cache, do_apply_post, do_apply_cgi, |
|---|
| 2375 | NULL, 1}, |
|---|
| 2376 | #else |
|---|
| 2377 | {"applyuser.cgi*", "text/html", no_cache, do_apply_post, do_apply_cgi, |
|---|
| 2378 | do_auth, 1}, |
|---|
| 2379 | #endif |
|---|
| 2380 | {"fetchif.cgi*", "text/html", no_cache, NULL, do_fetchif, do_auth, 1}, |
|---|
| 2381 | #ifdef HAVE_DDLAN |
|---|
| 2382 | {"apply.cgi*", "text/html", no_cache, do_apply_post, do_apply_cgi, NULL, |
|---|
| 2383 | 1}, |
|---|
| 2384 | {"upgrade.cgi*", "text/html", no_cache, do_upgrade_post, do_upgrade_cgi, |
|---|
| 2385 | NULL, 1}, |
|---|
| 2386 | #else |
|---|
| 2387 | {"apply.cgi*", "text/html", no_cache, do_apply_post, do_apply_cgi, |
|---|
| 2388 | do_auth, 1}, |
|---|
| 2389 | {"upgrade.cgi*", "text/html", no_cache, do_upgrade_post, do_upgrade_cgi, |
|---|
| 2390 | do_auth, 1}, |
|---|
| 2391 | #endif |
|---|
| 2392 | #ifdef HAVE_BUFFALO |
|---|
| 2393 | {"olupgrade.cgi*", "text/html", no_cache, do_olupgrade_post, |
|---|
| 2394 | do_upgrade_cgi, |
|---|
| 2395 | do_auth, 1}, |
|---|
| 2396 | #endif |
|---|
| 2397 | // {"Gozila.cgi*", "text/html", no_cache, NULL, do_setup_wizard, |
|---|
| 2398 | // do_auth}, // for setup wizard |
|---|
| 2399 | /* |
|---|
| 2400 | * { "**.cfg", "application/octet-stream", no_cache, NULL, do_backup, |
|---|
| 2401 | * do_auth }, |
|---|
| 2402 | */ |
|---|
| 2403 | #ifdef HAVE_DDLAN |
|---|
| 2404 | {"restore.cgi**", "text/html", no_cache, do_upgrade_post, |
|---|
| 2405 | do_upgrade_cgi, |
|---|
| 2406 | NULL, 1}, |
|---|
| 2407 | #else |
|---|
| 2408 | {"restore.cgi**", "text/html", no_cache, do_upgrade_post, |
|---|
| 2409 | do_upgrade_cgi, |
|---|
| 2410 | do_auth, 1}, |
|---|
| 2411 | #endif |
|---|
| 2412 | {"test.bin**", "application/octet-stream", no_cache, NULL, do_file, |
|---|
| 2413 | do_auth, 0}, |
|---|
| 2414 | |
|---|
| 2415 | #ifdef HAVE_DDLAN |
|---|
| 2416 | {"nvrambak.bin*", "application/octet-stream", no_cache, NULL, |
|---|
| 2417 | nv_file_out, do_auth2, 0}, |
|---|
| 2418 | {"nvrambak**.bin*", "application/octet-stream", no_cache, NULL, |
|---|
| 2419 | nv_file_out, |
|---|
| 2420 | do_auth2, 0}, |
|---|
| 2421 | {"nvram.cgi*", "text/html", no_cache, nv_file_in, sr_config_cgi, NULL, |
|---|
| 2422 | 1}, |
|---|
| 2423 | #else |
|---|
| 2424 | {"nvrambak.bin*", "application/octet-stream", no_cache, NULL, |
|---|
| 2425 | nv_file_out, do_auth, 0}, |
|---|
| 2426 | {"nvrambak**.bin*", "application/octet-stream", no_cache, NULL, |
|---|
| 2427 | nv_file_out, |
|---|
| 2428 | do_auth, 0}, |
|---|
| 2429 | {"nvram.cgi*", "text/html", no_cache, nv_file_in, sr_config_cgi, |
|---|
| 2430 | do_auth, |
|---|
| 2431 | 1}, |
|---|
| 2432 | #endif |
|---|
| 2433 | #if !defined(HAVE_X86) && !defined(HAVE_MAGICBOX) |
|---|
| 2434 | {"backup/cfe.bin", "application/octet-stream", no_cache, NULL, |
|---|
| 2435 | do_cfebackup, |
|---|
| 2436 | do_auth, 0}, |
|---|
| 2437 | #endif |
|---|
| 2438 | {"ttgraph.cgi*", "text/html", no_cache, NULL, do_ttgraph, do_auth, 1}, |
|---|
| 2439 | {"traffdata.bak*", "text/html", no_cache, NULL, ttraff_backup, |
|---|
| 2440 | do_auth, 0}, |
|---|
| 2441 | {"tadmin.cgi*", "text/html", no_cache, td_file_in, td_config_cgi, |
|---|
| 2442 | NULL, 1}, |
|---|
| 2443 | {"*", "application/octet-stream", no_cache, NULL, do_file, do_auth, 1}, |
|---|
| 2444 | // for ddm |
|---|
| 2445 | {NULL, NULL, NULL, NULL, NULL, NULL, 0} |
|---|
| 2446 | }; |
|---|
| 2447 | |
|---|
| 2448 | /* |
|---|
| 2449 | * Format: type = SET : " " => " " , ":" => ";" type = GET : |
|---|
| 2450 | * " " => " " , ";" => ":" Example: name1 = test 123:abc |
|---|
| 2451 | * filter_name("name1", new_name, SET); new_name="test 123;abc" |
|---|
| 2452 | * name2 = test 123;abc filter_name("name2", new_name, GET); |
|---|
| 2453 | * new_name="test 123:abc" |
|---|
| 2454 | */ |
|---|
| 2455 | int httpd_filter_name(char *old_name, char *new_name, size_t size, int type) |
|---|
| 2456 | { |
|---|
| 2457 | int i, j, match; |
|---|
| 2458 | |
|---|
| 2459 | cprintf("httpd_filter_name\n"); |
|---|
| 2460 | |
|---|
| 2461 | struct pattern { |
|---|
| 2462 | char ch; |
|---|
| 2463 | char *string; |
|---|
| 2464 | }; |
|---|
| 2465 | |
|---|
| 2466 | struct pattern patterns[] = { |
|---|
| 2467 | {' ', " "}, |
|---|
| 2468 | {':', ";"}, |
|---|
| 2469 | {'<', "<"}, |
|---|
| 2470 | {'>', ">"}, |
|---|
| 2471 | }; |
|---|
| 2472 | |
|---|
| 2473 | struct pattern *v; |
|---|
| 2474 | |
|---|
| 2475 | strcpy(new_name, ""); |
|---|
| 2476 | |
|---|
| 2477 | switch (type) { |
|---|
| 2478 | case SET: |
|---|
| 2479 | for (i = 0; *(old_name + i); i++) { |
|---|
| 2480 | match = 0; |
|---|
| 2481 | for (v = patterns; v < &patterns[STRUCT_LEN(patterns)]; |
|---|
| 2482 | v++) { |
|---|
| 2483 | if (*(old_name + i) == v->ch) { |
|---|
| 2484 | if (strlen(new_name) + strlen(v->string) > size) { // avoid overflow |
|---|
| 2485 | cprintf("%s(): overflow\n", |
|---|
| 2486 | __FUNCTION__); |
|---|
| 2487 | new_name[strlen(new_name)] = |
|---|
| 2488 | '\0'; |
|---|
| 2489 | return 1; |
|---|
| 2490 | } |
|---|
| 2491 | sprintf(new_name + strlen(new_name), |
|---|
| 2492 | "%s", v->string); |
|---|
| 2493 | match = 1; |
|---|
| 2494 | break; |
|---|
| 2495 | } |
|---|
| 2496 | } |
|---|
| 2497 | if (!match) { |
|---|
| 2498 | if (strlen(new_name) + 1 > size) { |
|---|
| 2499 | cprintf("%s(): overflow\n", __FUNCTION__); // avoid |
|---|
| 2500 | // overflow |
|---|
| 2501 | new_name[strlen(new_name)] = '\0'; |
|---|
| 2502 | return 1; |
|---|
| 2503 | } |
|---|
| 2504 | sprintf(new_name + strlen(new_name), "%c", |
|---|
| 2505 | *(old_name + i)); |
|---|
| 2506 | } |
|---|
| 2507 | } |
|---|
| 2508 | |
|---|
| 2509 | break; |
|---|
| 2510 | case GET: |
|---|
| 2511 | for (i = 0, j = 0; *(old_name + j); j++) { |
|---|
| 2512 | match = 0; |
|---|
| 2513 | for (v = patterns; v < &patterns[STRUCT_LEN(patterns)]; |
|---|
| 2514 | v++) { |
|---|
| 2515 | if (!memcmp |
|---|
| 2516 | (old_name + j, v->string, |
|---|
| 2517 | strlen(v->string))) { |
|---|
| 2518 | *(new_name + i) = v->ch; |
|---|
| 2519 | j = j + strlen(v->string) - 1; |
|---|
| 2520 | match = 1; |
|---|
| 2521 | break; |
|---|
| 2522 | } |
|---|
| 2523 | } |
|---|
| 2524 | if (!match) |
|---|
| 2525 | *(new_name + i) = *(old_name + j); |
|---|
| 2526 | |
|---|
| 2527 | i++; |
|---|
| 2528 | } |
|---|
| 2529 | *(new_name + i) = '\0'; |
|---|
| 2530 | break; |
|---|
| 2531 | default: |
|---|
| 2532 | cprintf("%s():Invalid type!\n", __FUNCTION__); |
|---|
| 2533 | break; |
|---|
| 2534 | } |
|---|
| 2535 | // cprintf("%s():new_name=[%s]\n", __FUNCTION__, new_name); |
|---|
| 2536 | |
|---|
| 2537 | return 1; |
|---|
| 2538 | } |
|---|
| 2539 | |
|---|
| 2540 | #ifdef HAVE_BUFFALO |
|---|
| 2541 | void do_vsp_page(struct mime_handler *handler, char *url, |
|---|
| 2542 | webs_t stream, char *query) |
|---|
| 2543 | { |
|---|
| 2544 | /* |
|---|
| 2545 | #ifdef HAVE_MADWIFI |
|---|
| 2546 | char *ifname = "ath0"; |
|---|
| 2547 | #else |
|---|
| 2548 | char *ifname = "wl0"; |
|---|
| 2549 | #endif |
|---|
| 2550 | |
|---|
| 2551 | char *authmode = nvram_nget("%s_security_mode", ifname); |
|---|
| 2552 | char *encrypt = nvram_nget("%s_crypto", ifname); |
|---|
| 2553 | char *wpakey = nvram_nget("%s_wpa_psk ", ifname); |
|---|
| 2554 | |
|---|
| 2555 | if (!strcmp(encrypt, "tkip")) { |
|---|
| 2556 | encrypt = "TKIP"; |
|---|
| 2557 | } else if (!strcmp(authmode, "aes")) { |
|---|
| 2558 | encrypt = "AES"; |
|---|
| 2559 | } else if (!strcmp(authmode, "tkip+aes")) { |
|---|
| 2560 | encrypt = "TKIP-AES-MIX"; |
|---|
| 2561 | } else { |
|---|
| 2562 | encrypt = ""; |
|---|
| 2563 | } |
|---|
| 2564 | |
|---|
| 2565 | if (!strcmp(authmode, "disabled")) { |
|---|
| 2566 | authmode = "NONE"; |
|---|
| 2567 | encrypt = ""; |
|---|
| 2568 | wpakey = ""; |
|---|
| 2569 | } else if (!strcmp(authmode, "wep")) { |
|---|
| 2570 | authmode = "WEP"; |
|---|
| 2571 | encrypt = ""; |
|---|
| 2572 | wpakey = ""; |
|---|
| 2573 | } else if (!strcmp(authmode, "radius") |
|---|
| 2574 | || !strcmp(authmode, "wpa") |
|---|
| 2575 | || !strcmp(authmode, "wpa2") |
|---|
| 2576 | || !strcmp(authmode, "wpa wpa2")) { |
|---|
| 2577 | authmode = "RADIUS"; |
|---|
| 2578 | encrypt = ""; |
|---|
| 2579 | wpakey = ""; |
|---|
| 2580 | } else if (!strcmp(authmode, "8021X")) { |
|---|
| 2581 | authmode = "802.1X"; |
|---|
| 2582 | encrypt = ""; |
|---|
| 2583 | wpakey = ""; |
|---|
| 2584 | } else if (!strcmp(authmode, "psk")) { |
|---|
| 2585 | authmode = "WPA"; |
|---|
| 2586 | } else if (!strcmp(authmode, "psk2")) { |
|---|
| 2587 | authmode = "WPA2"; |
|---|
| 2588 | } else if (!strcmp(authmode, "psk psk2")) { |
|---|
| 2589 | authmode = "WPA-WPA2-MIX"; |
|---|
| 2590 | } else { |
|---|
| 2591 | authmode = "UNKNOWN"; |
|---|
| 2592 | encrypt = ""; |
|---|
| 2593 | wpakey = ""; |
|---|
| 2594 | } |
|---|
| 2595 | */ |
|---|
| 2596 | websWrite(stream, "<html>\n"); |
|---|
| 2597 | websWrite(stream, "<head>\n"); |
|---|
| 2598 | websWrite(stream, "<title>VSP</title>\n"); |
|---|
| 2599 | websWrite(stream, "</head>\n"); |
|---|
| 2600 | websWrite(stream, "<body>\n"); |
|---|
| 2601 | websWrite(stream, "<pre>\n"); |
|---|
| 2602 | |
|---|
| 2603 | websWrite(stream, "DEVICE_VSP_VERSION=0.1\n"); |
|---|
| 2604 | websWrite(stream, "DEVICE_VENDOR=BUFFALO INC.\n"); |
|---|
| 2605 | websWrite(stream, "DEVICE_MODEL=%s DDWRT\n", |
|---|
| 2606 | nvram_safe_get("DD_BOARD")); |
|---|
| 2607 | websWrite(stream, "DEVICE_FIRMWARE_VERSION=1.00\n"); |
|---|
| 2608 | char *reg = getUEnv("region"); |
|---|
| 2609 | if (!reg) |
|---|
| 2610 | reg = "US"; |
|---|
| 2611 | websWrite(stream, "DEVICE_REGION=%s\n", reg); |
|---|
| 2612 | websWrite(stream, "WIRELESS_DEVICE_NUMBER=1\n"); |
|---|
| 2613 | // websWrite(stream, "WIRELESS_1_PRESET_AUTHMODE=%s\n", authmode); |
|---|
| 2614 | // websWrite(stream, "WIRELESS_1_PRESET_ENCRYPT=%s\n", encrypt); |
|---|
| 2615 | // websWrite(stream, "WIRELESS_1_PRESET_ENCRYPT_KEY=%s\n", wpakey); |
|---|
| 2616 | websWrite(stream, "DEVICE_URL_GET=/vsp.html\n"); |
|---|
| 2617 | websWrite(stream, "DEVICE_URL_SET=/vsp.html\n"); |
|---|
| 2618 | |
|---|
| 2619 | websWrite(stream, "</pre>\n"); |
|---|
| 2620 | websWrite(stream, "</body>\n"); |
|---|
| 2621 | websWrite(stream, "</html>\n"); |
|---|
| 2622 | } |
|---|
| 2623 | #endif |
|---|