int do_mon(void) { struct mon *v; checkupgrade(); checknas(); #ifndef HAVE_RT2880 softcontrol_wlan_led(); #endif for (v = mons; v < &mons[sizeof(mons) / sizeof(struct mon)]; v++) { if (v->name == NULL) break; if (v->nvvalue && v->nvmatch) { if (!nvram_match(v->nvvalue, v->nvmatch)) continue; // service not enabled. no need to check } printf("checking %s\n", v->name); if (v->type == M_WAN) if (!check_wan_link(0)) { printf("process is wan, but wan is not up\n"); continue; } if (!search_process(v->name, v->count)) { printf("Maybe %s had died, we need to re-exec it\n", v->name); sysprintf("stopservice %s", v->name); killall(v->name, SIGKILL); sysprintf("startservice_f %s", v->name); } printf("checking for %s done\n", v->name); } return 1; }
/* the real action: - increment the forced update times counter - detect current IP - connect to an HTTP server - parse the response for IP addr - for all the names that have to be maintained - get the current DYN DNS address from DYN DNS server - compare and update if neccessary */ RC_TYPE dyn_dns_update_ip(DYN_DNS_CLIENT *p_self) { RC_TYPE rc = RC_OK; if (p_self == NULL) { return RC_INVALID_POINTER; } do { if (nvram_match("ddns_wan_ip","1")) { char new_ip_str[32]; int wan_link = check_wan_link(0); char *wan_ipaddr = NULL; if (nvram_match("wan_proto", "pptp")) { wan_ipaddr = wan_link ? nvram_safe_get("pptp_get_ip") : nvram_safe_get("wan_ipaddr"); } else if (!strcmp(nvram_safe_get("wan_proto"), "pppoe")) { wan_ipaddr = wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; } else if (!strcmp(nvram_safe_get("wan_proto"), "3g")) { wan_ipaddr = wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; } else if (nvram_match("wan_proto", "l2tp")) { wan_ipaddr = wan_link ? nvram_safe_get("l2tp_get_ip") : nvram_safe_get("wan_ipaddr"); } else if (nvram_match("wan_proto", "disabled")) { wan_ipaddr = "0.0.0.0"; } else { wan_ipaddr = nvram_safe_get("wan_ipaddr"); } if (!strcmp(wan_ipaddr,"0.0.0.0")) { DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error: device has no WAN Address\n")); rc = RC_ERROR; break; } strcpy(new_ip_str,wan_ipaddr); p_self->info.my_ip_has_changed = (strcmp(new_ip_str, p_self->info.my_ip_address.name) != 0); strcpy(p_self->info.my_ip_address.name, new_ip_str); rc = RC_OK; }else{ /*ask IP server something so he will respond and give me my IP */ rc = do_ip_server_transaction(p_self); if (rc != RC_OK) { DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error '%s' (0x%x) when talking to IP server\n", errorcode_get_name(rc), rc)); break; } if (p_self->dbg.level > 1) { DBG_PRINTF((LOG_DEBUG,"DYNDNS: IP server response: %s\n", p_self->p_work_buffer)); } /*extract my IP, check if different than previous one*/ rc = do_parse_my_ip_address(p_self); if (rc != RC_OK) { break; } } if (p_self->dbg.level > 1) { DBG_PRINTF((LOG_WARNING,"W: DYNDNS: My IP address: %s\n", p_self->info.my_ip_address.name)); } /*step through aliases list, resolve them and check if they point to my IP*/ rc = do_check_alias_update_table(p_self); if (rc != RC_OK) { break; } /*update IPs marked as not identical with my IP*/ rc = do_update_alias_table(p_self); if (rc != RC_OK) { break; } } while(0); return rc; }
void ej_show_status(webs_t wp, int argc, char_t ** argv) { char *type; char *wan_proto = nvram_safe_get("wan_proto"); char *submit_type = websGetVar(wp, "submit_type", NULL); int wan_link = 0; char buf[254]; #ifdef HAVE_DSL_CPE_CONTROL if (argc > 0) { if (!strcmp(argv[0], "adsl")) { websWrite(wp, "{dsl_iface_status::%s}\n", nvram_get("dsl_iface_status")); websWrite(wp, "{dsl_datarate_ds::%11.2f}\n", atof(nvram_get("dsl_datarate_ds"))); websWrite(wp, "{dsl_datarate_us::%11.2f}\n", atof(nvram_get("dsl_datarate_us"))); websWrite(wp, "{dsl_snr_down::%d}\n", atoi(nvram_get("dsl_snr_down"))); websWrite(wp, "{dsl_snr_up::%d}\n", atoi(nvram_get("dsl_snr_up"))); } } #endif if (!strcmp(wan_proto, "pppoe") || !strcmp(wan_proto, "pptp") #ifdef HAVE_PPPOEDUAL || !strcmp(wan_proto, "pppoe_dual") #endif #ifdef HAVE_3G || !strcmp(wan_proto, "3g") #endif #ifdef HAVE_IPETH || !strcmp(wan_proto, "iphone") #endif #ifdef HAVE_PPPOATM || !strcmp(wan_proto, "pppoa") #endif #ifdef HAVE_L2TP || !strcmp(wan_proto, "l2tp") #endif || !strcmp(wan_proto, "heartbeat")) { /* * get type [ refresh | reload ] */ ejArgs(argc, argv, "%s", &type); /* * get ppp status , if /tmp/ppp/link exist, the connection is enabled */ wan_link = check_wan_link(0); if (!strcmp(type, "init")) { /* * press [ Connect | Disconnect ] button */ /* * set retry count */ if (nvram_match("gozila_action", "1")) retry_count = STATUS_RETRY_COUNT; // retry 3 times /* * set refresh time */ // submit_type old format is "Disconnect", new format is // "Disconnect_pppoe" or "Disconnect_pptp" or // "Disconnect_heartbeat" if (submit_type && !strncmp(submit_type, "Disconnect", 10)) // Disconnect // always // 60 // seconds // to // refresh retry_count = -1; refresh_time = (retry_count <= 0) ? STATUS_REFRESH_TIME2 : STATUS_REFRESH_TIME1; } else if (!strcmp(type, "refresh_time")) { websWrite(wp, "%d", refresh_time * 1000); } else if (!strcmp(type, "onload")) { if (retry_count == 0 || (!submit_type && !wan_link && nvram_match("gozila_action", "1"))) { // After refresh 2 times, if the status is // disconnect, show Alert message. websWrite(wp, "ShowAlert(\"TIMEOUT\");"); retry_count = -1; } else if (file_to_buf("/tmp/ppp/log", buf, sizeof(buf))) { websWrite(wp, "ShowAlert(\"%s\");", buf); retry_count = -1; unlink("/tmp/ppp/log"); } else { websWrite(wp, "Refresh();"); } if (retry_count != -1) retry_count--; } } return; }
void ej_nvram_status_get(webs_t wp, int argc, char_t ** argv) { char *type; char *wan_ipaddr, *wan_netmask, *wan_gateway; char *status1 = "", *status2 = "", *hidden1, *hidden2, *button1 = ""; char *wan_proto = nvram_safe_get("wan_proto"); struct dns_lists *dns_list = NULL; int wan_link = check_wan_link(0); int trans = 0; ejArgs(argc, argv, "%s %d", &type, &trans); if (!strcmp(wan_proto, "pptp")) { wan_ipaddr = wan_link ? nvram_safe_get("pptp_get_ip") : nvram_safe_get("wan_ipaddr"); wan_netmask = wan_link ? nvram_safe_get("wan_netmask") : nvram_safe_get("wan_netmask"); wan_gateway = wan_link ? nvram_safe_get("wan_gateway") : nvram_safe_get("pptp_server_ip"); } else if (!strcmp(wan_proto, "pppoe") #ifdef HAVE_PPPOEDUAL || !strcmp(wan_proto, "pppoe_dual") #endif #ifdef HAVE_PPPOATM || !strcmp(wan_proto, "pppoa") #endif #ifdef HAVE_3G || !strcmp(wan_proto, "3g") #endif #ifdef HAVE_IPETH || !strcmp(wan_proto, "iphone") #endif ) { wan_ipaddr = wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; wan_netmask = wan_link ? nvram_safe_get("wan_netmask") : "0.0.0.0"; wan_gateway = wan_link ? nvram_safe_get("wan_gateway") : "0.0.0.0"; } #ifdef HAVE_L2TP else if (!strcmp(wan_proto, "l2tp")) { wan_ipaddr = wan_link ? nvram_safe_get("l2tp_get_ip") : nvram_safe_get("wan_ipaddr"); wan_netmask = wan_link ? nvram_safe_get("wan_netmask") : nvram_safe_get("wan_netmask"); wan_gateway = wan_link ? nvram_safe_get("wan_gateway") : nvram_safe_get("wan_gateway"); } #endif else { wan_ipaddr = nvram_safe_get("wan_ipaddr"); wan_gateway = nvram_safe_get("wan_gateway"); wan_netmask = nvram_safe_get("wan_netmask"); } dns_list = get_dns_list(); if (!strcmp(wan_proto, "pppoe") || !strcmp(wan_proto, "pptp") #ifdef HAVE_PPPOEDUAL || !strcmp(wan_proto, "pppoe_dual") #endif #ifdef HAVE_3G || !strcmp(wan_proto, "3g") #endif #ifdef HAVE_IPETH || !strcmp(wan_proto, "iphone") #endif #ifdef HAVE_PPPOATM || !strcmp(wan_proto, "pppoa") #endif #ifdef HAVE_L2TP || !strcmp(wan_proto, "l2tp") #endif || !strcmp(wan_proto, "heartbeat")) { hidden1 = ""; hidden2 = ""; if (wan_link == 0) { // submit_button old format is "Connect", new format is // "Connect_pppoe" or "Connect_pptp" or "Connect_heartbeat" // if(submit_type && !strncmp(submit_type,"Connect",7) && // retry_count != -1){ if (retry_count != -1) { status1 = "share.statu"; status2 = "share.connecting"; if (trans) button1 = "share.disconnect"; else button1 = "Disconnect"; } else { status1 = "share.statu"; status2 = "share.disconnected"; if (trans) button1 = "share.connect"; else button1 = "Connect"; } } else { retry_count = -1; status1 = "share.statu"; status2 = "share.connected"; if (trans) button1 = "share.disconnect"; else button1 = "Disconnect"; } } else { status1 = "share.disable"; // only for nonbrand status2 = " "; hidden1 = "<!--"; hidden2 = "-->"; } if (!strcmp(type, "wan_ipaddr")) { if (getWET() || !strcmp(wan_proto, "disabled")) { websWrite(wp, "%s", live_translate("share.disabled")); } else websWrite(wp, "%s", wan_ipaddr); } else if (!strcmp(type, "wan_netmask")) websWrite(wp, "%s", wan_netmask); else if (!strcmp(type, "wan_gateway")) websWrite(wp, "%s", wan_gateway); else if (!strcmp(type, "wan_dns0")) { if (dns_list) websWrite(wp, "%s", dns_list->dns_server[0]); } else if (!strcmp(type, "wan_dns1")) { if (dns_list) websWrite(wp, "%s", dns_list->dns_server[1]); } else if (!strcmp(type, "wan_dns2")) { if (dns_list) websWrite(wp, "%s", dns_list->dns_server[2]); } else if (!strcmp(type, "status1")) websWrite(wp, "%s", live_translate(status1)); else if (!strcmp(type, "status2")) websWrite(wp, "%s", live_translate(status2)); else if (!strcmp(type, "button1")) { if (trans) websWrite(wp, "%s", live_translate(button1)); else websWrite(wp, "%s", button1); } else if (!strcmp(type, "hidden1")) websWrite(wp, "%s", hidden1); else if (!strcmp(type, "hidden2")) websWrite(wp, "%s", hidden2); else if (!strcmp(type, "wan_3g_signal")) websWrite(wp, "-40 DBm"); if (dns_list) free(dns_list); return; }