ID = 1; hotlink = ""; string pp_var(var) { tmp=tolower(var); tmp=explode(tmp); tmp[0] = toupper(tmp[0]); for (i=0; iup'; case "good": return 'good'; case "excelent": return 'excelent'; case "dialing": return 'dialing'; case "medium": return 'medium'; case "weak": return 'weak'; case "down": return 'down'; } return value; } void print_table(array fields) { nb_page_respond(page, '\n'); nb_page_respond(page, ''); for (i=0; i < length(fields); i++) { nb_page_respond(page, '\n'); nb_page_respond(page, '', sprintf("%s", pp_var(substr(fields[i], 9)))); nb_page_respond(page, sprintf("", pp(struct_get(wan, fields[i])))); nb_page_respond(page, '\n'); } nb_page_respond(page, '
'); nb_page_respond(page, left(fields[0], 8)); nb_page_respond(page, ''); if (struct_get(wan, "WAN_HOTLINK") != left(fields[0], 8) ) { nb_page_respond(page, '
'); nb_page_respond(page, sprintf("",left(fields[0], 8))); nb_page_respond(page, '
'); } nb_page_respond(page, '
%s%s
\n'); nb_page_respond(page, '
\n'); } /* register page */ page = nb_userpage_register(ID, "Wanlink", "Switch"); if (is_void(page)) { printf("unable to register page\n"); exit(1); } while (1) { printf("waiting for requests...\n"); /* wait for page request */ request = nb_page_request(page); if (!is_void(request)) { /* evaluate GET params */ GET = struct_get(request, "GET"); } for (k = 0; k < length(GET); k++) { key = struct_get(GET[k], "key"); if (key == "hotlink") { hotlink = struct_get(GET[k], "value"); } if (key == "action") { action = struct_get(GET[k], "value"); if (action == "reboot") nb_reboot(0); } } if (hotlink != "") { nb_wanlink_priorize(hotlink, 2); sleep(5); } fields = mkarray(); wan = nb_status("wan"); for (i=1; i <=9; i++) { wan_state = struct_get(wan, sprintf("WANLINK%d_STATE", i)); wan_idx = sprintf("WANLINK%d", i); if (strlen(wan_state) > 0) { // Attributes for WWAN link wan_array = mkarray(sprintf("%s_STATE", wan_idx), sprintf("%s_TYPE", wan_idx), sprintf("%s_SIGNAL_LEVEL", wan_idx), sprintf("%s_SIGNAL_QUALITY", wan_idx), sprintf("%s_SERVICE_TYPE", wan_idx), sprintf("%s_NETWORK", wan_idx) ); // Attributes for ETH/LAN link eth_array = mkarray(sprintf("%s_STATE", wan_idx), sprintf("%s_TYPE", wan_idx), sprintf("%s_ADDRESS", wan_idx), sprintf("%s_GATEWAY", wan_idx) ); type = struct_get(wan, sprintf("WANLINK%d_TYPE", i)); switch (type) { case "eth": tmp_array = eth_array; break; case "wwan": tmp_array = wan_array; break; } fields[i-1] = tmp_array; } } nb_page_respond(page, '\n'); nb_page_respond(page, '\n'); nb_page_respond(page, ''); nb_page_respond(page, sprintf("", struct_get(wan, "WAN_HOTLINK"))); nb_page_respond(page, '
Hotlink%s
\n'); nb_page_respond(page, '
\n'); nb_page_respond(page, '\n'); nb_page_respond(page,'\n'); nb_page_respond(page, '
Reebot
\n'); nb_page_respond(page, '
\n'); for (j=0; j