/* Legacy handler with old parameter sequence */ static int legacyTest(Webs *wp, char *prefix, char *dir, int flags) { websSetStatus(wp, 200); websWriteHeaders(wp, -1, 0); websWriteHeader(wp, "Content-Type", "text/plain"); websWriteEndHeaders(wp); websWrite(wp, "Hello Legacy World\n"); websDone(wp); return 1; }
static int aspTest(int eid, webs_t wp, int argc, char_t **argv) { char_t *name, *address; if (ejArgs(argc, argv, T("%s %s"), &name, &address) < 2) { websError(wp, 400, T("Insufficient args\n")); return -1; } return websWrite(wp, T("Name: %s, Address %s"), name, address); }
static void formTest( webs_t wp, char_t* path, char_t* query ) { char_t* name, *address; name = websGetVar( wp, T( "name" ), T( "Joe Smith" ) ); address = websGetVar( wp, T( "address" ), T( "1212 Milky Way Ave." ) ); websHeader( wp ); websWrite( wp, T( "<body><h2>Name: %s, Address: %s</h2>\n" ), name, address ); websFooter( wp ); websDone( wp, 200 ); }
void ej_exec_show_aliases(webs_t wp, int argc, char_t ** argv) { int i; char *count; int c = 0; count = nvram_safe_get("milkfish_ddaliasesnum"); if (count == NULL || strlen(count) == 0 || (c = atoi(count)) <= 0) { websWrite(wp, "<tr>\n<td colspan=\"4\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n</tr>\n"); } for (i = 0; i < c; i++) { websWrite(wp, "<tr><td>\n<input maxlength=\"30\" size=\"30\" name=\"user%d\" onblur=\"valid_name(this,'Name')\" value=\"", i); show_aliases_table(wp, "user", i); websWrite(wp, "\" /></td>\n<td>\n<input maxlength=\"50\" size=\"50\" name=\"pass%d\" onblur=\"valid_name(this,'Name')\" value=\"", i); show_aliases_table(wp, "pass", i); websWrite(wp, "\" /></td>\n</tr>\n"); } return; }
void ej_compile_date(webs_t wp, int argc, char_t ** argv) { char year[8], mon[4], day[4]; char string[20]; sscanf(__DATE__, "%s %s %s", mon, day, year); snprintf(string, sizeof(string), "%s. %s, %s", mon, day, year); websWrite(wp, "%s", string); }
/* Parse the form variables: name, address and echo back */ static int aspTest(int eid, Webs *wp, int argc, char **argv) { char *name, *address; if (jsArgs(argc, argv, "%s %s", &name, &address) < 2) { websError(wp, 400, "Insufficient args\n"); return -1; } return (int) websWrite(wp, "Name: %s, Address %s", name, address); }
void show_registrations_table(webs_t wp, char *type, int which) { static char word[256]; char *next, *wordlist; char *user, *contact, *agent; static char new_user[200], new_contact[200], new_agent[200]; int temp; wordlist = nvram_safe_get("milkfish_ddactive"); temp = which; foreach(word, wordlist, next) { if (which-- == 0) { contact = word; user = strsep(&contact, ":"); if (!user || !contact) continue; agent = contact; contact = strsep(&agent, ":"); if (!contact || !agent) continue; if (!strcmp(type, "user")) { httpd_filter_name(user, new_user, sizeof(new_user), GET); websWrite(wp, "%s", new_user); } else if (!strcmp(type, "contact")) { httpd_filter_name(contact, new_contact, sizeof(new_contact), GET); websWrite(wp, "%s", new_contact); } else if (!strcmp(type, "agent")) { httpd_filter_name(agent, new_agent, sizeof(new_agent), GET); websWrite(wp, "%s", new_agent); } return; } } }
/* * retreive and convert dsls values for specified dsl_unit * Example: * <% dsl_get_parameter(); %> for coping wan[n]_ to wan_ */ int ej_dsl_get_parameter(int eid, webs_t wp, int argc, char_t **argv) { int unit; unit = nvram_get_int("dsl_unit"); // handle generate cases first (void)copy_index_to_unindex("dsl_", unit, -1); return (websWrite(wp,"")); }
void ej_get_url(webs_t wp, int argc, char_t ** argv) { char *type; if (ejArgs(argc, argv, "%s", &type) < 1) { websError(wp, 400, "Insufficient args\n"); return; } websWrite(wp, "%s", "Invalid argument\n"); }
int ej_get_DSL_WAN_list(int eid, webs_t wp, int argc, char_t **argv){ char buf[MAX_LINE_SIZE]; char buf2[MAX_LINE_SIZE]; char prefix[]="dslXXXXXX_", tmp[100]; int unit; int j; int firstItem; char *display_items[] = {"dsl_enable", "dsl_vpi", "dsl_vci","dsl_proto", "dsl_encap", "dsl_svc_cat", "dsl_pcr","dsl_scr","dsl_mbs",NULL}; for ( unit = 0; unit<8; unit++ ) { snprintf(prefix, sizeof(prefix), "dsl%d_", unit); firstItem = 1; websWrite(wp, "["); for ( j = 0; display_items[j] != NULL; j++ ) { if(firstItem == 1) { firstItem = 0; } else { websWrite(wp, ", "); } strcpy(buf,nvram_safe_get(strcat_r(prefix, &display_items[j][4], tmp))); if (strcmp(buf,"")==0) { strcpy(buf2,"\"0\""); } else { sprintf(buf2,"\"%s\"",buf); } websWrite(wp, "%s", buf2); } if (unit != 7) { websWrite(wp, "], "); } else { websWrite(wp, "]"); } } return 0; }
static int ShowMediaDir(int eid, webs_t wp, int argc, char_t **argv) { int index; fetchMediaConfig(); media_dir_count = 0; for(index=0;index<4;index++) { if (0 != strlen(media_conf[index].path)) { websWrite(wp, T("<tr align=\"center\">")); websWrite(wp, T("<td><input type=\"radio\" name=\"media_dir\" value=\"%d\"></td>"), index); websWrite(wp, T("<td>%s</td>"), media_conf[index].path); websWrite(wp, T("</tr>")); media_dir_count++; } } return 0; }
void ping_onload(webs_t wp, char *arg) { int pid; char *type = websGetVar(wp, "submit_type", ""); pid = find_pid_by_ps("ping"); if (pid > 0 && strncmp(type, "stop", 4)) { // pinging websWrite(wp, arg); } }
static int aspGenerateAccessLimitList( int eid, webs_t wp, int argc, char_t** argv ) { char_t* url; int row, nBytesSent, nBytes; a_assert( wp ); row = nBytesSent = 0; url = umGetFirstAccessLimit(); nBytes = websWrite( wp, T( "<SELECT NAME=\"url\" SIZE=\"3\" TITLE=\"Select a URL\">" ) ); while ( url && ( nBytes > 0 ) ) { nBytes = websWrite( wp, T( "<OPTION VALUE=\"%s\">%s\n" ), url, url ); url = umGetNextAccessLimit( url ); nBytesSent += nBytes; } nBytesSent += websWrite( wp, T( "</SELECT>" ) ); return nBytesSent; }
/* Implement /action/actionTest. Parse the form variables: name, address and echo back. */ static void actionTest(Webs *wp, char *path, char *query) { char *name, *address; name = websGetVar(wp, "name", NULL); address = websGetVar(wp, "address", NULL); websSetStatus(wp, 200); websWriteHeaders(wp, -1, 0); websWriteEndHeaders(wp); websWrite(wp, "<html><body><h2>name: %s, address: %s</h2></body></html>\n", name, address); websDone(wp); }
int ej_vpns_leases(int eid, webs_t wp, int argc, char **argv) { FILE *fp; int ret = 0, i_clients = 0; char ifname[16], addr_l[32], addr_r[32], peer_name[64]; ret += websWrite(wp, "# IP Local IP Remote Login NetIf\n"); if (!(fp = fopen("/tmp/vpns.leases", "r"))) { return ret; } while (fscanf(fp, "%s %s %s %[^\n]\n", ifname, addr_l, addr_r, peer_name) == 4) { i_clients++; ret += websWrite(wp, "%-3u", i_clients); ret += websWrite(wp, "%-17s", addr_l); ret += websWrite(wp, "%-17s", addr_r); ret += websWrite(wp, "%-15s", peer_name); ret += websWrite(wp, "%s\n", ifname); } fclose(fp); return ret; }
static void formDeleteGroup(webs_t wp, char_t *path, char_t *query) { char_t *group, *ok; a_assert(wp); group = websGetVar(wp, T("group"), T("")); ok = websGetVar(wp, T("ok"), T("")); websHeader(wp); websMsgStart(wp); if (gstricmp(ok, T("ok")) != 0) { websWrite(wp, T("Delete Group Cancelled.")); } else if ((group == NULL) || (*group == '\0')) { websWrite(wp, T("ERROR: No group was selected.")); } else if (umGetGroupProtected(group)) { websWrite(wp, T("ERROR: Group, \"%s\" is delete-protected."), group); } else if (umGetGroupInUse(group)) { websWrite(wp, T("ERROR: Group, \"%s\" is being used."), group); } else if (umDeleteGroup(group) != 0) { websWrite(wp, T("ERROR: Unable to delete group, \"%s\" "), group); } else { websWrite(wp, T("Group, \"%s\" was successfully deleted."), group); } websMsgEnd(wp); websFooter(wp); websDone(wp, 200); }
static int __websLuciferHandler(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, char_t *url, char_t *path, char_t* query) { int method = 0; fprintf(stderr, "__websLuciferHandler: urlPrefix(%s),webDir(%s),arg(%d),url(%s), path(%s),query(%s)\r\n", urlPrefix,webDir,arg,url,path,query); fprintf(stderr, "flags(%08X)\r\n", wp->flags); if(wp->flags & WEBS_HEAD_REQUEST) { fprintf(stderr, "request(HEAD)\r\n"); } else if(wp->flags & WEBS_POST_REQUEST) { fprintf(stderr, "request(POST)\r\n"); websWrite(wp, T("{List:[ " "{\"Role\":\"A\",\"Msg\"Msg\":\"哈\":\"哈哈哈哈哈哈啊哈\",\"Date\":\"2012-12-24 15:32\"}," "{\"Role\":\"A\",哈哈哈哈哈啊哈\",\"Date\":\"2012-12-24 15:32\"}," "{\"Role\":\"A\",\"Msg\":\"哈哈哈哈哈哈啊哈\",\"Date\":\"2012-12-24 15:32\"}," "{\"Role\":\"B\",\"Msg\":\"哈哈哈哈哈哈啊哈\",\"Date\":\"2012-12-24 15:32\"}," "{\"Role\":\"A\",\"Msg\":\"哈哈哈哈哈哈啊哈\",\"Date\":\"2012-12-24 15:32\"}," "{\"Role\":\"B\",\"Msg\":\"哈哈哈哈哈哈啊哈\",\"Date\":\"2012-12-24 15:32\"}" "] }" )); } else { fprintf(stderr, "request(GET)\r\n"); websWrite(wp, T("{\"List\":[" "{\"No\":\"13696994500\",\"FName\":\"吴昕\",\"Date\":\"15:20\",\"Msg\":\"晚上去哪里吃饭\"}," "{\"No\":\"13696994501\",\"FName\":\"吴昕\",\"Date\":\"15:30\",\"Msg\":\"晚上去哪里吃饭\"}," "{\"No\":\"13696994502\",\"FName\":\"吴昕\",\"Date\":\"15:40\",\"Msg\":\"晚上去哪里吃饭\"}," "{\"No\":\"13696994503\",\"FName\":\"吴昕\",\"Date\":\"15:50\",\"Msg\":\"晚上去哪里吃饭\"} ]}" )); } websDone(wp, 200); return 1; }
int ej_get_upnp_array(int eid, webs_t wp, int argc, char_t **argv) { FILE *fp; char proto[4], eport[6], iaddr[sizeof("255.255.255.255")], iport[6], timestamp[15], desc[200], desc2[256]; int ret=0; char line[256]; ret += websWrite(wp, "var upnparray = ["); fp = fopen("/var/lib/misc/upnp.leases", "r"); if (fp == NULL) { ret += websWrite(wp, "[]];\n"); return ret; } while (fgets(line, sizeof(line), fp) != NULL) { if (sscanf(line, "%3[^:]:" "%5[^:]:" "%15[^:]:" "%5[^:]:" "%14[^:]:" "%200[^\n]", proto, eport, iaddr, iport, timestamp, desc) < 6) continue; if (str_escape_quotes(desc2, desc, sizeof(desc2)) == 0) strncpy(desc2, desc, sizeof(desc2)); ret += websWrite(wp, "[\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"],\n", proto, eport, iaddr, iport, timestamp, desc2); } fclose(fp); ret += websWrite(wp, "[]];\n"); return ret; }
static void show_chaps_table(webs_t wp, char *type, int which) { static char word[256]; char *next, *wordlist; char *user, *pass, *ip, *enable; static char new_user[200], new_pass[200]; int temp; wordlist = nvram_safe_get("pppoeserver_chaps"); temp = which; foreach(word, wordlist, next) { if (which-- == 0) { pass = word; user = strsep(&pass, ":"); if (!user || !pass) continue; ip = pass; pass = strsep(&ip, ":"); if (!pass || !ip) continue; enable = ip; ip = strsep(&enable, ":"); if (!ip || !enable) continue; if (!strcmp(type, "user")) { httpd_filter_name(user, new_user, sizeof(new_user), GET); websWrite(wp, "%s", new_user); } else if (!strcmp(type, "pass")) { httpd_filter_name(pass, new_pass, sizeof(new_pass), GET); websWrite(wp, "%s", new_pass); } else if (!strcmp(type, "ip")) websWrite(wp, "%s", ip); else if (!strcmp(type, "enable")) { if (!strcmp(enable, "on")) websWrite(wp, "checked=\"checked\""); else websWrite(wp, ""); } return; } } if (!strcmp(type, "ip")) websWrite(wp, "0.0.0.0"); else websWrite(wp, ""); }
static int aspGenerateUserList( int eid, webs_t wp, int argc, char_t** argv ) { char_t* userid; int row, nBytesSent, nBytes; a_assert( wp ); nBytes = websWrite( wp, T( "<SELECT NAME=\"user\" SIZE=\"3\" TITLE=\"Select a User\">" ) ); row = 0; userid = umGetFirstUser(); nBytesSent = 0; while ( userid && ( nBytes > 0 ) ) { nBytes = websWrite( wp, T( "<OPTION VALUE=\"%s\">%s\n" ), userid, userid ); userid = umGetNextUser( userid ); nBytesSent += nBytes; } nBytesSent += websWrite( wp, T( "</SELECT>" ) ); return nBytesSent; }
void ej_list_fbn(webs_t wp, int argc, char_t ** argv) { int i; system2("site_survey"); open_site_survey(); for (i = 0; i < SITE_SURVEY_NUM; i++) { if (site_survey_lists[i].SSID[0] == 0 || site_survey_lists[i].BSSID[0] == 0 || (site_survey_lists[i].channel & 0xff) == 0) break; if (startswith(site_survey_lists[i].SSID, "www.fbn-dd.de")) { websWrite(wp, "<option value=\""); tf_webWriteJS(wp, site_survey_lists[i].SSID); websWrite(wp, "\">"); tf_webWriteJS(wp, site_survey_lists[i].SSID); websWrite(wp, "</option>\n"); } } }
static void formDeleteUser( webs_t wp, char_t* path, char_t* query ) { char_t* userid, *ok; a_assert( wp ); userid = websGetVar( wp, T( "user" ), T( "" ) ); ok = websGetVar( wp, T( "ok" ), T( "" ) ); websHeader( wp ); websMsgStart( wp ); if ( gstricmp( ok, T( "ok" ) ) != 0 ) { websWrite( wp, T( "Delete User Cancelled" ) ); } else if ( umUserExists( userid ) == FALSE ) { websWrite( wp, T( "ERROR: User \"%s\" not found" ), userid ); } else if ( umGetUserProtected( userid ) ) { websWrite( wp, T( "ERROR: User, \"%s\" is delete-protected." ), userid ); } else if ( umDeleteUser( userid ) != 0 ) { websWrite( wp, T( "ERROR: Unable to delete user, \"%s\" " ), userid ); } else { websWrite( wp, T( "User, \"%s\" was successfully deleted." ), userid ); } websMsgEnd( wp ); websFooter( wp ); websDone( wp, 200 ); }
void ej_get_clone_mac(webs_t wp, int argc, char_t ** argv) { char *c; int mac, which; int dofree = 0; #ifdef FASTWEB ejArgs(argc, argv, "%d", &which); #else if (ejArgs(argc, argv, "%d", &which) < 1) { websError(wp, 400, "Insufficient args\n"); } #endif if (nvram_match("clone_wan_mac", "1")) c = nvram_safe_get("http_client_mac"); else { if (nvram_match("def_hwaddr", "00:00:00:00:00:00")) { if (nvram_match("port_swap", "1")) c = strdup(nvram_safe_get("et1macaddr")); else c = strdup(nvram_safe_get("et0macaddr")); if (c) { MAC_ADD(c); dofree = 1; } } else c = nvram_safe_get("def_hwaddr"); } if (c) { mac = get_single_mac(c, which); websWrite(wp, "%02X", mac); if (dofree) free(c); } else websWrite(wp, "00"); }
static void formSaveUserManagement(webs_t wp, char *path, char *query) { char *ok; a_assert(wp); ok = websGetVar(wp, T("ok"), T("")); websHeader(wp); websMsgStart(wp); if (gstricmp(ok, T("ok")) != 0) { websWrite(wp, T("Save Cancelled.")); } else if (umCommit(NULL) != 0) { websWrite(wp, T("ERROR: Unable to save user configuration.")); } else { websWrite(wp, T("User configuration was saved successfully.")); } websMsgEnd(wp); websFooter(wp); websDone(wp, 200); }
void ej_dump_wiviz_data(webs_t wp, int argc, char_t ** argv) // Eko, for // testing // only { FILE *f; char buf[256]; killall("autokill_wiviz", SIGTERM); eval("autokill_wiviz"); eval("run_wiviz"); if ((f = fopen("/tmp/wiviz2-dump", "r")) != NULL) { while (fgets(buf, sizeof(buf), f)) { websWrite(wp, "%s", buf); } fclose(f); } else // dummy data - to prevent first time js // error { websWrite(wp, "top.hosts = new Array();\nvar hnum = 0;\nvar h;\nvar wiviz_cfg = new Object();\n wiviz_cfg.channel = 6\ntop.wiviz_callback(top.hosts, wiviz_cfg);\nfunction wiviz_callback(one, two) {\nalert(\'This asp is intended to run inside Wi-Viz. You will now be redirected there.\');\nlocation.replace('Wiviz_Survey.asp');\n}\n"); } }
static void formLoadUserManagement(webs_t wp, char_t *path, char_t *query) { char_t *ok; a_assert(wp); ok = websGetVar(wp, T("ok"), T("")); websHeader(wp); websMsgStart(wp); if (gstricmp(ok, T("ok")) != 0) { websWrite(wp, T("Load Cancelled.")); } else if (umRestore(NULL) != 0) { websWrite(wp, T("ERROR: Unable to load user configuration.")); } else { websWrite(wp, T("User configuration was re-loaded successfully.")); } websMsgEnd(wp); websFooter(wp); websDone(wp, 200); }
static void QoSPortSetup(webs_t wp, char_t *path, char_t *query) { int i; char_t *portX[32]; char_t *portX_remark[32]; char tmp_str[512]; memset(portX, 0, sizeof(char *) * 32); memset(portX_remark, 0, sizeof(char *) * 32); for(i=0; i<5; i++) { sprintf(tmp_str, "port%d_group", i); portX[i] = websGetVar(wp, T(tmp_str), T("")); sprintf(tmp_str, "port%d_remarker", i); portX_remark[i] = websGetVar(wp, T(tmp_str), T("")); } for(i=1; i<9; i++) { sprintf(tmp_str, "ssid%d_group", i); portX[i+4] = websGetVar(wp, T(tmp_str), T("")); sprintf(tmp_str, "ssid%d_remarker", i); portX_remark[i+4] = websGetVar(wp, T(tmp_str), T("")); } tmp_str[0] = '\0'; for(i=0; i<13; i++) { if(portX[i]) strcat(tmp_str, portX[i]); strcat(tmp_str, ","); if(portX_remark[i]) strcat(tmp_str, portX_remark[i]); strcat(tmp_str, ","); } nvram_bufset(RT2860_NVRAM, "QoSPortBasedRules", tmp_str); nvram_commit(RT2860_NVRAM); QoSRestart(); websHeader(wp); for(i=0; i<13; i++) { sprintf(tmp_str, "port%d=%s,%s<br>", i, portX[i], portX_remark[i]); websWrite(wp, T(tmp_str)); } websFooter(wp); websDone(wp, 200); }
int traceroute_onload(webs_t wp, char *arg) { int ret = 0; int pid; char *type = websGetVar(wp, "submit_type", ""); pid = find_pid_by_ps("traceroute"); if (pid > 0 && strncmp(type, "stop", 4)) { // tracerouting ret += websWrite(wp, arg); } return ret; }
static void printersrv(webs_t wp, char_t *path, char_t *query) { char_t *enable; // fetch from web input enable = websGetVar(wp, T("enabled"), T("")); // set to nvram nvram_bufset(RT2860_NVRAM, "PrinterSrvEnabled", enable); nvram_commit(RT2860_NVRAM); // setup device doSystem("killall p910nd"); if (0 == strcmp(enable, "1")) { doSystem("p910nd -b -f /dev/lp0"); } // debug print websHeader(wp); websWrite(wp, T("<h2>Printer Server Settings</h2><br>\n")); websWrite(wp, T("enabled: %s<br>\n"), enable); websFooter(wp); websDone(wp, 200); }
int ej_get_leases_array(int eid, webs_t wp, int argc, char_t **argv) { char *leaselist = NULL, *leaselistptr; char hostname[16], duration[9], ip[40], mac[18]; int ret=0; killall("dnsmasq", SIGUSR2); sleep(1); leaselist = read_whole_file("/var/lib/misc/dnsmasq.leases"); if (!leaselist) return websWrite(wp, "leasearray = [];\n"); ret += websWrite(wp, "leasearray= ["); leaselistptr = leaselist; while ((leaselistptr < leaselist+strlen(leaselist)-2) && (sscanf(leaselistptr,"%8s %17s %15s %15s %*s", duration, mac, ip, hostname) == 4)) { ret += websWrite(wp, "[\"%s\", \"%s\", \"%s\", \"%s\"],\n", duration, mac, ip, hostname); leaselistptr = strstr(leaselistptr,"\n")+1; } ret += websWrite(wp, "[]];\n"); return ret; }