/****************************************************************************** * * * void OptUninstall() * * * ******************************************************************************* * * Removes linice.o module * ******************************************************************************/ void OptUninstall() { int hIce; int status; // Only the root user may remove the module if( IsRootUser() ) { // Send the exit ioctl to the driver so it can decrement possibly // multiple usage count to only 1 (useful when loader crashes) hIce = open("/dev/"DEVICE_NAME, O_RDONLY); if( hIce>=0 ) { // Send the EXIT message to the Linice, so it can release its hooks status = ioctl(hIce, ICE_IOCTL_EXIT, 0); close(hIce); // If there are still any extension modules loaded, we cannot unload // since the modules are linked to us and wont let us unload cleanly. // Value of 1 for status is the special signal from Linice driver if( status != 1 ) { // Unload the linice.o device driver module status = system2("rmmod linice"); // rmmod must return 0 when uninstalling a module correctly if( status != 0 ) { // If we cannot unload linice because it crashed, use the // last resort and try to force unload it hIce = open("/dev/"DEVICE_NAME, O_RDONLY); if( hIce>=0 ) { VERBOSE1 printf("Forcing unload...\n"); status = ioctl(hIce, ICE_IOCTL_EXIT_FORCE, 0); close(hIce); // Theoretically, by now our bad module count is reset back to 0... // Unload the linice.o device driver module status = system2("rmmod linice"); } } printf("Linice uninstalled.\n"); } else fprintf(stderr, "One or more Linice extension modules are still loaded. Unload them first!\n"); } else fprintf(stderr, "Cannot communicate with the Linice module! Is Linice installed?\n"); } }
int sysprintf(const char *fmt, ...) { char varbuf[256]; va_list args; va_start(args, (char *)fmt); vsnprintf(varbuf, sizeof(varbuf), fmt, args); va_end(args); return system2(varbuf); }
/****************************************************************************** * * Returns a default SuSE System.map file path/name * ******************************************************************************/ char *MkSuSE(void) { static char sSystemMap[256] = { 0 }; // We will compose it into this buffer FILE *fp; // File that we just created system2("echo /boot/System.map-`uname -r` > /tmp/.linice.System.map"); fp = fopen("/tmp/.linice.System.map", "r"); if( fp ) { // Read the contents into our buffer fscanf(fp, "%s", sSystemMap); fclose(fp); } system2("rm -rf /tmp/.linice.System.map"); return( sSystemMap ); }
int main(int argc, char* argv[]) { char bash_path[1024] = {0}; FILE * fp = fopen("c:\\.bash-loc", "rb"); if (!fp) { fprintf(stderr, "Error: can't open `%s'\n", "c:\\.bash-loc"); exit(0); } fgets(bash_path, 1024, fp); chomp(bash_path); fprintf(stderr, "Bash is found at `%s'\n", bash_path); char shellHerlperSh[]= "~/bin/windows/shellHelper_vc6.sh"; int new_cmd_len = strlen(bash_path) + sizeof(shellHerlperSh) + 20; fprintf(stderr, "command line is %s\n", GetCommandLine()); for (int i=0; i<argc; i++) { new_cmd_len += strlen(argv[i])*2 +5; fprintf(stderr, "argv[%d] is '%s'\n", i, argv[i]); } char *new_cmd_str = (char *)calloc(new_cmd_len, sizeof(char)); char *next_pos = new_cmd_str + sprintf(new_cmd_str, "%s %s ", bash_path, shellHerlperSh); for (i=0; i<argc; i++) { next_pos = strdup_quote(next_pos, argv[i]); if (i<argc-1) { *next_pos++ = ' '; } } fprintf(stderr, "Will run `%s'\n", new_cmd_str); fflush(stderr); return system2(new_cmd_str); }
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"); } } }
void start_radvd(void) { int ret = 0; int c = 0; char *buf, *buf2; int i; FILE *fp; if (!nvram_match("radvd_enable", "1")) return; if (!nvram_match("ipv6_enable", "1")) return; buf = nvram_get("radvd_conf"); if (buf != NULL) writenvram("radvd_conf", "/tmp/radvd.conf"); system2("sync"); ret = eval("radvd", "-C", "/tmp/radvd.conf"); dd_syslog(LOG_INFO, "radvd : RADV daemon successfully started\n"); cprintf("done\n"); return; }
static inline int is_in_bridge(char *interface) { #define BUFFER_SIZE 256 FILE *fd = NULL;; char buffer[BUFFER_SIZE]; if (!interface) return 0; system2("/usr/sbin/brctl show > /tmp/bridges"); fd = fopen("/tmp/bridges", "r"); if (fd != NULL) { while (fgets(buffer, BUFFER_SIZE, fd) != NULL) { if (strstr(buffer, interface) != NULL) { fclose(fd); return 1; } } fclose(fd); } return 0; }
int svqos_iptables(void) { char *qos_pkts = nvram_safe_get("svqos_pkts"); char *qos_svcs = nvram_safe_get("svqos_svcs"); char name[32], type[32], data[32], level[32], pkt_filter[4]; char *wshaper_dev = nvram_get("wshaper_dev"); char *wan_dev = get_wanface(); char nullmask[24]; strcpy(nullmask, qos_nfmark(0)); insmod("ipt_mark"); insmod("xt_mark"); insmod("ipt_CONNMARK"); insmod("xt_CONNMARK"); insmod("ipt_mac"); insmod("xt_mac"); #if !(defined(ARCH_broadcom) && !defined(HAVE_BCMMODERN)) // if kernel version later then 2.4, overwrite all old tc filter sysprintf("tc filter del dev %s pref %d", wan_dev, 1); sysprintf("tc filter del dev %s pref %d", wan_dev, 3); sysprintf("tc filter del dev %s pref %d", wan_dev, 5); sysprintf("tc filter del dev %s pref %d", wan_dev, 8); sysprintf("tc filter del dev %s pref %d", wan_dev, 9); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(100), 100); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(10), 10); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(20), 20); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(30), 30); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(40), 40); sysprintf("tc filter del dev %s pref %d", "imq0", 1); sysprintf("tc filter del dev %s pref %d", "imq0", 3); sysprintf("tc filter del dev %s pref %d", "imq0", 5); sysprintf("tc filter del dev %s pref %d", "imq0", 8); sysprintf("tc filter del dev %s pref %d", "imq0", 9); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(100), 100); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(10), 10); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(20), 20); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(30), 30); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(40), 40); if (nvram_match("wshaper_dev", "LAN")) { sysprintf("tc filter del dev %s pref %d", "imq1", 1); sysprintf("tc filter del dev %s pref %d", "imq1", 3); sysprintf("tc filter del dev %s pref %d", "imq1", 5); sysprintf("tc filter del dev %s pref %d", "imq1", 8); sysprintf("tc filter del dev %s pref %d", "imq1", 9); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(100), 100); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(10), 10); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(20), 20); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(30), 30); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(40), 40); } #endif #ifdef HAVE_OPENDPI insmod("/lib/opendpi/xt_opendpi.ko"); #endif insmod("ipt_layer7"); insmod("xt_layer7"); // set-up mark/filter tables system2("iptables -t mangle -F SVQOS_SVCS"); system2("iptables -t mangle -X SVQOS_SVCS"); system2("iptables -t mangle -N SVQOS_SVCS"); system2("iptables -t mangle -F FILTER_OUT"); system2("iptables -t mangle -X FILTER_OUT"); system2("iptables -t mangle -N FILTER_OUT"); system2("iptables -t mangle -A FILTER_OUT -j CONNMARK --restore"); sysprintf("iptables -t mangle -A FILTER_OUT -m mark --mark %s -j SVQOS_SVCS", nullmask); system2("iptables -t mangle -F FILTER_IN"); system2("iptables -t mangle -X FILTER_IN"); system2("iptables -t mangle -N FILTER_IN"); system2("iptables -t mangle -A FILTER_IN -j CONNMARK --restore"); sysprintf("iptables -t mangle -A FILTER_IN -m mark --mark %s -j SVQOS_SVCS", nullmask); sysprintf("iptables -t mangle -D PREROUTING -j FILTER_IN"); sysprintf("iptables -t mangle -I PREROUTING -j FILTER_IN"); sysprintf("iptables -t mangle -D POSTROUTING -j FILTER_OUT"); sysprintf("iptables -t mangle -I POSTROUTING -j FILTER_OUT"); system2("iptables -t mangle -A POSTROUTING -m dscp --dscp ! 0 -j DSCP --set-dscp 0"); if (!strcmp(wshaper_dev, "WAN")) { sysprintf("iptables -t mangle -D INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -D FORWARD -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A FORWARD -i %s -j IMQ --todev 0", wan_dev); } if (!strcmp(wshaper_dev, "LAN")) { if (!client_bridged_enabled() && nvram_invmatch("wan_proto", "disabled")) { sysprintf("iptables -t mangle -D INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -D FORWARD -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A FORWARD -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -D INPUT -i ! %s -j IMQ --todev 1", wan_dev); sysprintf("iptables -t mangle -A INPUT -i ! %s -j IMQ --todev 1", wan_dev); sysprintf("iptables -t mangle -D FORWARD -i ! %s -o ! %s -j IMQ --todev 1", wan_dev, wan_dev); sysprintf("iptables -t mangle -A FORWARD -i ! %s -o ! %s -j IMQ --todev 1", wan_dev, wan_dev); } else { sysprintf("iptables -t mangle -D INPUT -j IMQ --todev 1"); sysprintf("iptables -t mangle -A INPUT -j IMQ --todev 1"); sysprintf("iptables -t mangle -D FORWARD -j IMQ --todev 1"); sysprintf("iptables -t mangle -A FORWARD -j IMQ --todev 1"); } } /* add openvpn filter rules */ #ifdef HAVE_AQOS #ifdef HAVE_OPENVPN if (nvram_invmatch("openvpn_enable", "0") || nvram_invmatch("openvpncl_enable", "0")) { char iflist[256]; static char word[256]; char *next; bool unbridged_tap = 0; insmod("xt_dscp"); insmod("xt_DSCP"); system2("iptables -t mangle -F VPN_IN"); system2("iptables -t mangle -X VPN_IN"); system2("iptables -t mangle -N VPN_IN"); system2("iptables -t mangle -A VPN_IN -j CONNMARK --save"); system2("iptables -t mangle -F VPN_OUT"); system2("iptables -t mangle -X VPN_OUT"); system2("iptables -t mangle -N VPN_OUT"); system2("iptables -t mangle -F VPN_DSCP"); system2("iptables -t mangle -X VPN_DSCP"); system2("iptables -t mangle -N VPN_DSCP"); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 10 -j MARK --set-mark %s", qos_nfmark(100)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 1 -j MARK --set-mark %s", qos_nfmark(10)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 2 -j MARK --set-mark %s", qos_nfmark(20)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 3 -j MARK --set-mark %s", qos_nfmark(30)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 4 -j MARK --set-mark %s", qos_nfmark(40)); system2("iptables -t mangle -A VPN_DSCP -m dscp --dscp ! 0 -j DSCP --set-dscp 0"); system2("iptables -t mangle -A VPN_DSCP -j RETURN"); // look for present tun-devices if (getifcount("tun")) { system2("iptables -t mangle -I PREROUTING 2 -i tun+ -j VPN_IN"); system2("iptables -t mangle -I INPUT 1 -i tun+ -j IMQ --todev 0"); system2("iptables -t mangle -I FORWARD 1 -i tun+ -j IMQ --todev 0"); system2("iptables -t mangle -I POSTROUTING 1 -o tun+ -j VPN_OUT"); } // look for present tap-devices if (getifcount("tap")) { writeproc("/proc/sys/net/bridge/bridge-nf-call-arptables", "1"); writeproc("/proc/sys/net/bridge/bridge-nf-call-ip6tables", "1"); writeproc("/proc/sys/net/bridge/bridge-nf-call-iptables", "1"); insmod("xt_physdev"); insmod("ebtables"); getIfList(iflist, "tap"); foreach(word, iflist, next) { if (is_in_bridge(word)) { sysprintf("iptables -t mangle -I PREROUTING 2 -m physdev --physdev-in %s -j VPN_IN", word); sysprintf("iptables -t mangle -I INPUT 1 -m physdev --physdev-in %s -j IMQ --todev 0", word); sysprintf("iptables -t mangle -I FORWARD 1 -m physdev --physdev-in %s -j IMQ --todev 0", word); sysprintf("iptables -t mangle -I POSTROUTING -m physdev --physdev-out %s -j VPN_OUT", word); } else unbridged_tap = 1; } if (unbridged_tap) { system2("iptables -t mangle -I PREROUTING 2 -i tap+ -j VPN_IN"); system2("iptables -t mangle -I INPUT 1 -i tap+ -j IMQ --todev 0"); system2("iptables -t mangle -I FORWARD 1 -i tap+ -j IMQ --todev 0"); system2("iptables -t mangle -I POSTROUTING 1 -o tap+ -j VPN_OUT"); } }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; unlink("/etc/nvram/.lock"); cprintf("sysinit() proc\n"); /* * /proc */ mount("proc", "/proc", "proc", MS_MGC_VAL, NULL); system2("/etc/convert"); mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL); cprintf("sysinit() tmp\n"); /* * /tmp */ mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL); mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL); eval("mount", "/etc/www.fs", "/www", "-t", "squashfs", "-o", "loop"); eval("mount", "/etc/modules.fs", "/lib/modules", "-t", "squashfs", "-o", "loop"); eval("mount", "/etc/usr.fs", "/usr", "-t", "squashfs", "-o", "loop"); mkdir("/tmp/www", 0700); eval("mount", "-o", "remount,rw", "/"); mkdir("/usr/local/nvram", 0777); unlink("/tmp/nvram/.lock"); mkdir("/tmp/nvram", 0700); eval("cp", "/etc/nvram/nvram.db", "/tmp/nvram"); // eval ("cp", "/etc/nvram/offsets.db", "/tmp/nvram"); cprintf("sysinit() var\n"); /* * /var */ mkdir("/tmp/var", 0777); mkdir("/var/lock", 0777); mkdir("/var/log", 0777); mkdir("/var/run", 0777); mkdir("/var/tmp", 0777); cprintf("sysinit() setup console\n"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); // enableAfterBurner (); insmod("md5"); insmod("aes"); insmod("blowfish"); insmod("deflate"); insmod("des"); insmod("michael_mic"); insmod("cast5"); insmod("crypto_null"); system2("/etc/kendin"); insmod("ixp400th"); insmod("ixp400"); system2("cat /usr/lib/firmware/IxNpeMicrocode.dat > /dev/IxNpe"); insmod("ixp400_eth"); insmod("ocf"); insmod("cryptodev"); insmod("ixp4xx", "init_crypto=0"); eval("ifconfig", "ixp0", "0.0.0.0", "up"); eval("vconfig", "add", "ixp0", "1"); eval("vconfig", "add", "ixp0", "2"); detect_wireless_devices(); // load_drivers(); //load madwifi drivers /* * Set a sane date */ stime(&tm); return; cprintf("done\n"); }
void start_sysinit(void) { time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ fprintf(stderr, "load ATH Ethernet Driver\n"); system("insmod ag71xx || insmod ag7240_mod"); FILE *fp = fopen("/dev/mtdblock/6", "rb"); if (fp) { // fseek(fp, 0xFF0000, SEEK_SET); fseek(fp, DDMACOFFSET, SEEK_SET); unsigned char buf[20]; fread(&buf[0], 6, 1, fp); char mac[20]; int i; unsigned int copy[20]; for (i = 0; i < 12; i++) copy[i] = buf[i] & 0xff; sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure ETH0 to %s\n", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); eval("ifconfig", "eth0", "hw", "ether", mac); fread(&buf[6], 6, 1, fp); for (i = 0; i < 12; i++) copy[i] = buf[i] & 0xff; sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[6], copy[7], copy[8], copy[9], copy[10], copy[11]); fprintf(stderr, "configure ETH1 to %s\n", mac); eval("ifconfig", "eth1", "hw", "ether", mac); fclose(fp); } // eval("ifconfig", "eth0", "up"); // eval("ifconfig", "eth1", "up"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_CONNECTED, LED_OFF); system2("echo 1 >/proc/sys/dev/wifi0/ledpin"); system2("echo 1 >/proc/sys/dev/wifi0/softled"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
int site_survey_main(int argc, char *argv[]) { char *name = nvram_safe_get("wl0_ifname"); unsigned char mac[20]; int i = 0; char *dev = name; unlink(SITE_SURVEY_DB); int ap = 0, oldap = 0; unsigned char buf[24 * 1024]; char ssid[31]; unsigned char *cp; int len; system2("airoscan-ng wifi0"); len = do80211priv("ath0", IEEE80211_IOCTL_SCAN_RESULTS, buf, sizeof(buf)); if (len == -1) fprintf(stderr, "unable to get scan results"); if (len < sizeof(struct ieee80211req_scan_result)) return; cp = buf; do { struct ieee80211req_scan_result *sr; unsigned char *vp; char ssid[14]; sr = (struct ieee80211req_scan_result *)cp; vp = (u_int8_t *)(sr + 1); memset(ssid, 0, sizeof(ssid)); strncpy(site_survey_lists[i].SSID, vp, sr->isr_ssid_len); strcpy(site_survey_lists[i].BSSID, ieee80211_ntoa(sr->isr_bssid)); site_survey_lists[i].channel = ieee80211_mhz2ieee(sr->isr_freq); site_survey_lists[i].frequency = sr->isr_freq; int noise = 256; noise -= (int)sr->isr_noise; site_survey_lists[i].phy_noise = -noise; site_survey_lists[i].RSSI = (int)site_survey_lists[i].phy_noise + (int)sr->isr_rssi; site_survey_lists[i].capability = sr->isr_capinfo; site_survey_lists[i].rate_count = sr->isr_nrates; cp += sr->isr_len, len -= sr->isr_len; i++; } while (len >= sizeof(struct ieee80211req_scan_result)); write_site_survey(); open_site_survey(); for (i = 0; i < SITE_SURVEY_NUM && site_survey_lists[i].BSSID[0] && site_survey_lists[i].channel != 0; i++) { fprintf(stderr, "[%2d] SSID[%20s] BSSID[%s] channel[%2d] frequency[%4d] rssi[%d] noise[%d] beacon[%d] cap[%x] dtim[%d] rate[%d]\n", i, site_survey_lists[i].SSID, site_survey_lists[i].BSSID, site_survey_lists[i].channel, site_survey_lists[i].frequency, site_survey_lists[i].RSSI, site_survey_lists[i].phy_noise, site_survey_lists[i].beacon_period, site_survey_lists[i].capability, site_survey_lists[i].dtim_period, site_survey_lists[i].rate_count); } return 0; }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/gpio",S_IFCHR|0644,makedev(127,0)); mkdir("/usr/local",0700); mkdir("/usr/local/nvram",0700); install_sdcard(); cprintf("sysinit() setup console\n"); eval("insmod", "ks8695_wdt", "wdt_time=30"); // load watchdog module with 30 seconds timeout if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); /* * network drivers */ eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); eval("ifconfig", "eth2", "up"); eval("ifconfig", "eth3", "up"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); system2("echo 1 >/proc/sys/dev/wifi0/softled"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); //disable led's return; cprintf("done\n"); }
int main(int argc,char** argv) { system2(argv[1]); return 0; }
void ej_dump_site_survey(webs_t wp, int argc, char_t ** argv) { int i; char buf[10] = { 0 }; char *rates = NULL; char *name; name = websGetVar(wp, "hidden_scan", NULL); if (name == NULL || strlen(name) == 0) system2("site_survey"); else { sysprintf("site_survey \"%s\"", name); } open_site_survey(); for (i = 0; i < SITE_SURVEY_NUM; i++) { if (site_survey_lists[i].BSSID[0] == 0 || (site_survey_lists[i].channel & 0xff) == 0) break; // fix for " in SSID char *tssid = (site_survey_lists[i].SSID[0] == 0) ? "hidden" : &site_survey_lists[i].SSID[0]; int pos = 0; int tpos; int ssidlen = strlen(tssid); while (pos < ssidlen) { if (tssid[pos] == '\"') { for (tpos = ssidlen; tpos > pos - 1; tpos--) tssid[tpos + 1] = tssid[tpos]; tssid[pos] = '\\'; pos++; ssidlen++; } pos++; } // end fix for " in SSID char strbuf[64]; if (site_survey_lists[i].channel & 0x1000) { int cbw = site_survey_lists[i].channel & 0x100; //0x000 = 80 mhz //0x100 = 8080 mhz //0x200 = 160 mhz int speed = site_survey_lists[i].rate_count; switch (cbw) { case 0: if (speed == 150) speed = 433; else if (speed == 300) speed = 867; else if (speed == 450) speed = 1300; case 0x100: case 0x200: if (speed == 150) speed = 867; else if (speed == 300) speed = 1733; else if (speed == 450) speed = 2600; } rates = strbuf; if ((site_survey_lists[i].channel & 0xff) < 15) { sprintf(rates, "%d(b/g/n/ac)", speed); } else { sprintf(rates, "%d(a/n/ac)", speed); } } else { if ((site_survey_lists[i].channel & 0xff) < 15) { if (site_survey_lists[i].rate_count == 4) rates = "11(b)"; else if (site_survey_lists[i].rate_count == 12) rates = "54(b/g)"; else if (site_survey_lists[i].rate_count == 13) rates = "108(b/g)"; else if (site_survey_lists[i].rate_count == 300) rates = "300(b/g/n)"; else if (site_survey_lists[i].rate_count == 450) rates = "450(b/g/n)"; else if (site_survey_lists[i].rate_count == 150) rates = "150(b/g/n)"; else { rates = buf; snprintf(rates, 9, "%d", site_survey_lists[i].rate_count); } } else { if (site_survey_lists[i].rate_count == 4) rates = "11(b)"; //bogus, never shown. but if, its definitly b with weired channel setting else if (site_survey_lists[i].rate_count == 12) rates = "54(a)"; else if (site_survey_lists[i].rate_count == 13) rates = "108(a)"; else if (site_survey_lists[i].rate_count == 300) rates = "300(a/n)"; else if (site_survey_lists[i].rate_count == 450) rates = "450(a/n)"; else if (site_survey_lists[i].rate_count == 150) rates = "150(a/n)"; else { rates = buf; snprintf(rates, 9, "%d", site_survey_lists[i].rate_count); } } } /* * #define DOT11_CAP_ESS 0x0001 #define DOT11_CAP_IBSS 0x0002 #define * DOT11_CAP_POLLABLE 0x0004 #define DOT11_CAP_POLL_RQ 0x0008 #define * DOT11_CAP_PRIVACY 0x0010 #define DOT11_CAP_SHORT 0x0020 #define * DOT11_CAP_PBCC 0x0040 #define DOT11_CAP_AGILITY 0x0080 #define * DOT11_CAP_SPECTRUM 0x0100 #define DOT11_CAP_SHORTSLOT 0x0400 * #define DOT11_CAP_CCK_OFDM 0x2000 */ char open[32]; strncpy(open, (site_survey_lists[i].capability & DOT11_CAP_PRIVACY) ? live_translate("share.no") : live_translate("share.yes"), 31); char *netmode; int netmodecap = site_survey_lists[i].capability; netmodecap &= (DOT11_CAP_ESS | DOT11_CAP_IBSS); if (netmodecap == DOT11_CAP_ESS) netmode = "AP"; else if (netmodecap == DOT11_CAP_IBSS) netmode = "AdHoc"; else netmode = live_translate("share.unknown"); char net[32]; strcpy(net, netmode); websWrite(wp, "%c\"", i ? ',' : ' '); tf_webWriteJS(wp, tssid); websWrite(wp, "\",\"%s\",\"%s\",\"%d (%d MHz)\",\"%d\",\"%d\",\"%d\",\"%s\",\"%s\",\"%d\",\"%s\"\n", net, site_survey_lists[i].BSSID, site_survey_lists[i].channel & 0xff, site_survey_lists[i].frequency, site_survey_lists[i].RSSI, site_survey_lists[i].phy_noise, site_survey_lists[i].beacon_period, open, site_survey_lists[i].ENCINFO, site_survey_lists[i].dtim_period, rates); } return; }
void start_sysinit(void) { struct stat tmp_stat; time_t tm = 0; eval("mknod", "/dev/gpio", "c", "127", "0"); eval("mknod", "/dev/rtc", "c", "254", "0"); eval("mknod", "/dev/crypto", "c", "10", "70"); eval("mount", "-o", "remount,rw", "/"); if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); // system watchdog cprintf("sysinit() setup console\n"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); nvram_set("intel_eth", "0"); #if 1 insmod("ixp400th"); insmod("ixp400"); system2("cat /usr/lib/firmware/IxNpeMicrocode.dat > /dev/IxNpe"); insmod("ixp400_eth"); eval("ifconfig", "ixp0", "0.0.0.0", "up"); eval("ifconfig", "ixp1", "0.0.0.0", "up"); insmod("ocf"); insmod("cryptodev"); // insmod("ixp4xx", "init_crypto=0"); #else // eval ("mknod", "/dev/IxNpe","c","10","184"); system2("cat /usr/lib/firmware/NPE-B > /dev/misc/ixp4xx_ucode"); system2("cat /usr/lib/firmware/NPE-C > /dev/misc/ixp4xx_ucode"); #endif detect_wireless_devices(); /* * Configure mac addresses by reading data from eeprom */ // char *filename = // "/sys/devices/platform/IXP4XX-I2C.0/i2c-0/0-0051/eeprom"; /* // bank2=0x100 */ char *filename = "/dev/mtdblock/0"; /* bank2=0x100 */ FILE *file = fopen(filename, "r"); if (file) { unsigned char buf[20]; fseek(file, 0x5ffa0, SEEK_SET); // point of mac address fread(&buf[0], 6, 1, file); char mac[20]; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); fprintf(stderr, "configure primary mac %s\n", mac); eval("ifconfig", "ixp0", "hw", "ether", mac); eval("ifconfig", "wifi0", "hw", "ether", mac); nvram_set("et0macaddr", mac); MAC_ADD(mac); fprintf(stderr, "configure secondary mac %s\n", mac); eval("ifconfig", "ixp1", "hw", "ether", mac); fclose(file); } eval("ifconfig", "ixp0", "0.0.0.0", "up"); eval("ifconfig", "ixp1", "0.0.0.0", "up"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); nvram_set("use_crypto", "0"); cprintf("done\n"); return; }
/****************************************************************************** * * * BOOL OptInstall(char *pSystemMap) * * * ******************************************************************************* * * Loads linice.o module. Feeds it the init file so it can configure itself. * Looks for the System.map file and read all necessary symbols that linice * cannot obtain as a kernel module and needs for proper operation. * * Where: * pSystemMap is the user-add path/name of the System.map file * * Returns: * TRUE - module loaded and initialized * FALSE - a problem happened, we need to exit * ******************************************************************************/ BOOL OptInstall(char *pSystemMap) { int hIce; FILE *fp; int status; char sLine[256], *pStr; char sKey[16], sValue[256]; TINITPACKET Init; int nLine, i; // Only the root user may install the module if( !IsRootUser() ) return( FALSE ); // Initialization: zero out the init packet memset(&Init, 0, sizeof(TINITPACKET)); Init.nSize = sizeof(TINITPACKET); //==================================================================== // Installation check - If Linice module already installed, return //==================================================================== hIce = open("/dev/"DEVICE_NAME, O_RDONLY); if( hIce>=0 ) { fprintf(stderr, "Linice module already installed, or /dev/%s exists.\n", DEVICE_NAME); return( TRUE ); } // When looking for the System.map file, user command line argument // has precedence over linice.dat file specification and lastly, default // It makes sense to display error and exit if the user-specified map // file can't be opened since he probably mistyped it if( pSystemMap ) { if( OpenSystemMap(pSystemMap)==FALSE ) { fprintf(stderr, "Unable to open specified map file: %s\n", pSystemMap); return( FALSE ); } } //==================================================================== // Look for the linice config file and read its assignments //==================================================================== fp = fopen("linice.dat", "r"); if( fp==NULL ) { VERBOSE1 printf("Looking for linice.dat in /etc"); // Look in the /etc directory fp = fopen("/etc/linice.dat", "r"); if( fp==NULL ) { // Failed to open the config file - load default settings fprintf(stderr, "Failed to open linice.dat file - loading default settings.\n"); // Set up default values: strcpy(Init.keyFn[ 0], "h;"); // F1 strcpy(Init.keyFn[ 1], "^wr;"); // F2 strcpy(Init.keyFn[ 2], "^src;"); // F3 strcpy(Init.keyFn[ 3], "^rs;"); // F4 strcpy(Init.keyFn[ 4], "^x;"); // F5 strcpy(Init.keyFn[ 5], "^ec;"); // F6 strcpy(Init.keyFn[ 6], "^here;"); // F7 strcpy(Init.keyFn[ 7], "^t;"); // F8 strcpy(Init.keyFn[ 8], "^bpx;"); // F9 strcpy(Init.keyFn[ 9], "^p;"); // F10 strcpy(Init.keyFn[10], "^G @SS:ESP;"); // F11 strcpy(Init.keyFn[11], "^p ret;"); // F12 strcpy(Init.keyFn[12], "^format;"); // SF1 strcpy(Init.keyFn[24], "^wr;"); // AF1 strcpy(Init.keyFn[25], "^wd;"); // AF2 strcpy(Init.keyFn[26], "^wc;"); // AF3 strcpy(Init.keyFn[27], "^ww;"); // AF4 strcpy(Init.keyFn[28], "CLS;"); // AF5 strcpy(Init.keyFn[34], "^dd dataaddr->0;"); // AF11 strcpy(Init.keyFn[35], "^dd dataaddr->4;"); // AF12 strcpy(Init.keyFn[36], "altscr off; lines 60; wc 32; wd 8;"); // CF1 strcpy(Init.keyFn[37], "^wr;^wd;^wc;"); // CF2 Init.fLowercase = 1; // Use lowercase disassembly } } // Set default values - these we do in any case before parsing the linice.dat file Init.nHistorySize = 16; // 16 Kb Init.nSymbolSize = 128; // 128 Kb Init.nMacros = 32; // 32 macro entries Init.nVars = 32; // 32 user variables nLine = 0; // Read config file line by line and build the config packet while( fp && !feof(fp) ) { nLine++; fgets(sLine, sizeof(sLine), fp); // Cut off end of line characters if( strchr(sLine, '\n') ) *(char *)strchr(sLine, '\n') = 0; if( strchr(sLine, '\r') ) *(char *)strchr(sLine, '\r') = 0; // Change all TABs into spaces while( strchr(sLine, '\t') ) { *(char *)strchr(sLine, '\t') = ' '; } // Get to the first meaningful character in a line pStr = sLine; while( *pStr==' ' ) pStr++; // Skip comment line and empty lines if((*pStr==';')||(*pStr=='#')||(*pStr==0)) continue; // Get the assignment in the form KEY=VALUE or KEY="value" sscanf(pStr, "%[a-zA-Z0-9.]s", sKey); pStr = strchr(pStr,'=') + 1; // Decipher the key and load the appropriate value (number, boolean or string) if(stricmp(sKey, "lowercase")==0) { sscanf(pStr, "%s", sValue); if(stricmp(sValue,"on")==0) Init.fLowercase = 1; } else if(stricmp(sKey, "sym")==0) sscanf(pStr, "%d", &Init.nSymbolSize); else if(stricmp(sKey, "drawsize")==0) sscanf(pStr, "%d", &Init.nDrawSize); else if(stricmp(sKey, "hst")==0) sscanf(pStr, "%d", &Init.nHistorySize); else if(stricmp(sKey, "macros")==0) sscanf(pStr, "%d", &Init.nMacros); else if(stricmp(sKey, "vars")==0) sscanf(pStr, "%d", &Init.nVars); else if(stricmp(sKey, "init")==0) GetString(Init.sInit, pStr); else if(stricmp(sKey, "layout" )==0) { // If we return TRUE, Init.Layout has been updated if( ReadKbdMapping(Init.Layout, pStr)==TRUE ) { VERBOSE2 printf("Keyboard layout: %s\n", pStr); } else { fprintf(stderr, "Invalid keyboard layout %s!\n", pStr); // We probably dont want to continue if the keyboard layout is bad return( FALSE ); } }else if(stricmp(sKey, "f1" )==0) GetString(Init.keyFn[ 0], pStr); else if(stricmp(sKey, "f2" )==0) GetString(Init.keyFn[ 1], pStr); else if(stricmp(sKey, "f3" )==0) GetString(Init.keyFn[ 2], pStr); else if(stricmp(sKey, "f4" )==0) GetString(Init.keyFn[ 3], pStr); else if(stricmp(sKey, "f5" )==0) GetString(Init.keyFn[ 4], pStr); else if(stricmp(sKey, "f6" )==0) GetString(Init.keyFn[ 5], pStr); else if(stricmp(sKey, "f7" )==0) GetString(Init.keyFn[ 6], pStr); else if(stricmp(sKey, "f8" )==0) GetString(Init.keyFn[ 7], pStr); else if(stricmp(sKey, "f9" )==0) GetString(Init.keyFn[ 8], pStr); else if(stricmp(sKey, "f10" )==0) GetString(Init.keyFn[ 9], pStr); else if(stricmp(sKey, "f11" )==0) GetString(Init.keyFn[10], pStr); else if(stricmp(sKey, "f12" )==0) GetString(Init.keyFn[11], pStr); else if(stricmp(sKey, "sf1" )==0) GetString(Init.keyFn[12], pStr); else if(stricmp(sKey, "sf2" )==0) GetString(Init.keyFn[13], pStr); else if(stricmp(sKey, "sf3" )==0) GetString(Init.keyFn[14], pStr); else if(stricmp(sKey, "sf4" )==0) GetString(Init.keyFn[15], pStr); else if(stricmp(sKey, "sf5" )==0) GetString(Init.keyFn[16], pStr); else if(stricmp(sKey, "sf6" )==0) GetString(Init.keyFn[17], pStr); else if(stricmp(sKey, "sf7" )==0) GetString(Init.keyFn[18], pStr); else if(stricmp(sKey, "sf8" )==0) GetString(Init.keyFn[19], pStr); else if(stricmp(sKey, "sf9" )==0) GetString(Init.keyFn[20], pStr); else if(stricmp(sKey, "sf10")==0) GetString(Init.keyFn[21], pStr); else if(stricmp(sKey, "sf11")==0) GetString(Init.keyFn[22], pStr); else if(stricmp(sKey, "sf12")==0) GetString(Init.keyFn[23], pStr); else if(stricmp(sKey, "af1" )==0) GetString(Init.keyFn[24], pStr); else if(stricmp(sKey, "af2" )==0) GetString(Init.keyFn[25], pStr); else if(stricmp(sKey, "af3" )==0) GetString(Init.keyFn[26], pStr); else if(stricmp(sKey, "af4" )==0) GetString(Init.keyFn[27], pStr); else if(stricmp(sKey, "af5" )==0) GetString(Init.keyFn[28], pStr); else if(stricmp(sKey, "af6" )==0) GetString(Init.keyFn[29], pStr); else if(stricmp(sKey, "af7" )==0) GetString(Init.keyFn[30], pStr); else if(stricmp(sKey, "af8" )==0) GetString(Init.keyFn[31], pStr); else if(stricmp(sKey, "af9" )==0) GetString(Init.keyFn[32], pStr); else if(stricmp(sKey, "af10")==0) GetString(Init.keyFn[33], pStr); else if(stricmp(sKey, "af11")==0) GetString(Init.keyFn[34], pStr); else if(stricmp(sKey, "af12")==0) GetString(Init.keyFn[35], pStr); else if(stricmp(sKey, "cf1" )==0) GetString(Init.keyFn[36], pStr); else if(stricmp(sKey, "cf2" )==0) GetString(Init.keyFn[37], pStr); else if(stricmp(sKey, "cf3" )==0) GetString(Init.keyFn[38], pStr); else if(stricmp(sKey, "cf4" )==0) GetString(Init.keyFn[39], pStr); else if(stricmp(sKey, "cf5" )==0) GetString(Init.keyFn[40], pStr); else if(stricmp(sKey, "cf6" )==0) GetString(Init.keyFn[41], pStr); else if(stricmp(sKey, "cf7" )==0) GetString(Init.keyFn[42], pStr); else if(stricmp(sKey, "cf8" )==0) GetString(Init.keyFn[43], pStr); else if(stricmp(sKey, "cf9" )==0) GetString(Init.keyFn[44], pStr); else if(stricmp(sKey, "cf10")==0) GetString(Init.keyFn[45], pStr); else if(stricmp(sKey, "cf11")==0) GetString(Init.keyFn[46], pStr); else if(stricmp(sKey, "cf12")==0) GetString(Init.keyFn[47], pStr); else // Try to open the system map file... // TODO: This is not documented if(stricmp(sKey, "System.map")==0) OpenSystemMap(pStr); else { VERBOSE2 printf("Line %d skipped: %s\n", nLine, sLine); } } // Close the linice.dat file if( fp ) fclose(fp); // Modify function key assignments to substitute the trailing semicolon // with the newline character for( i=0; i<48; i++) { if( strlen(Init.keyFn[i]) > 0 ) { pStr = Init.keyFn[i] + strlen(Init.keyFn[i]) - 1; if( *pStr==';' ) *pStr = '\n'; } } Init.nSymbolSize *= 1024; // Make these values kilobytes Init.nDrawSize *= 1024; Init.nHistorySize *= 1024; // Lastly, try several more default locations for System.map file OpenSystemMap("/boot/System.map"); // Default for RedHat OpenSystemMap(MkSuSE()); // Make default for SuSE linux OpenSystemMap("./System.map"); // Current directory OpenSystemMap("/System.map"); // File system root // Scan system map file for some symbols that we need to send to linice if( GetSymbolExports() ) { // In order to do "insmod" with the module name, we need to know where to // find it (user might called linsym from any directory). Environment variable // LINICE should be set to the 'bin' of the linice built module IF the linsym // is not being executed from the default place (bin). // Load the linice.o device driver module: // -x do not export externs // -f force load even if kernel version does not match sprintf(sLine, "insmod -f linice_`uname -r`/linice.o ice_debug_level=1 kbd=%d scan=%d pmodule=%d sys=%d switchto=%d start_sym=%d stop_sym=%d start_sym_gpl=%d stop_sym_gpl=%d", handle_kbd_event, handle_scancode, module_list, sys_call_table, switch_to, start_symtab, stop_symtab, start_symtab_gpl, stop_symtab_gpl); VERBOSE2 printf("%s\n", sLine); status = system2(sLine); // Execute the module load... // If failed on a first try, change the directory to the environment LINICE and retry if( status && getenv("LINICE") ) { VERBOSE2 printf("Using environment variable LINICE = %s\n", getenv("LINICE")); chdir(getenv("LINICE")); // Change directory to it status = system2(sLine); // Try the module load again... } // insmod must return 0 to load module correctly if( status==0 ) { //==================================================================== // Send the init packet down to the module //==================================================================== hIce = open("/dev/"DEVICE_NAME, O_RDONLY); if( hIce>=0 ) { status = ioctl(hIce, ICE_IOCTL_INIT, &Init); close(hIce); printf("Linice installed.\n"); // Return success return( TRUE ); } fprintf(stderr, "Error opening /dev/%s device!\n", DEVICE_NAME); // Unload linice module system2("rmmod linice"); } else { // We could not load linice module! fprintf(stderr, "Error loading linice module!\n\n"); } VERBOSE2 printf("system(insmod()) returns %d\n", status); fprintf(stderr, "Possible causes are:\n"); fprintf(stderr, " * /dev/ice exists (delete it)\n"); fprintf(stderr, " * Not calling Linsym from the default Linice directory (its 'bin') -\n"); fprintf(stderr, " Set the environment variable LINICE with the path to that directory:\n"); fprintf(stderr, " Example: export LINICE=/usr/src/linice/bin\n"); fprintf(stderr, " * Linice did not compile correctly so the module does not exist\n"); fprintf(stderr, " * Your Symbol.map file is not correct (use option -m <map>)\n"); fprintf(stderr, " * Unsupported kernel version 2.6.9 and above\n"); fprintf(stderr, "\n"); } else { // We did not find System.map - this file needs to be used since we // really can't hook without it.. fprintf(stderr, "Failed to open System.map file!\n"); fprintf(stderr, "Please use option --map <System.map> to specify its path and name.\n"); fprintf(stderr, "\n"); } // Return failure return( FALSE ); }
void hotspotsys_config(void) { FILE *fp; char *next; char var[64]; char *dnslist; int i; md5_ctx_t MD; if (strlen(nvram_safe_get("hotss_remotekey")) != 12) { unsigned char hash[32]; char *et0 = nvram_safe_get("et0macaddr"); md5_begin(&MD); md5_hash(et0, 17, &MD); md5_end((unsigned char *)hash, &MD); char idkey[16]; int i; for (i = 0; i < 6; i++) sprintf(&idkey[2 * i], "%02d", (hash[i] + hash[i + 1]) % 100); idkey[12] = '\0'; nvram_set("hotss_remotekey", idkey); nvram_commit(); char sendid[256]; sprintf(sendid, "/usr/bin/wget http://tech.hotspotsystem.com/up.php?mac=`nvram get wl0_hwaddr|sed s/:/-/g`\\&operator=%s\\&location=%s\\&remotekey=%s", nvram_get("hotss_operatorid"), nvram_get("hotss_locationid"), nvram_get("hotss_remotekey")); system2(sendid); } if (!(fp = fopen("/tmp/chilli/hotss.conf", "w"))) { perror("/tmp/chilli/hotss.conf"); return; } fprintf(fp, "ipup /tmp/chilli/ip-up.sh\n"); fprintf(fp, "ipdown /tmp/chilli/ip-down.sh\n"); fprintf(fp, "radiusserver1 radius.hotspotsystem.com\n"); fprintf(fp, "radiusserver2 radius2.hotspotsystem.com\n"); fprintf(fp, "radiussecret hotsys123\n"); fprintf(fp, "dhcpif %s\n", nvram_safe_get("hotss_interface")); if (nvram_invmatch("hotss_net", "")) fprintf(fp, "net %s\n", nvram_get("hotss_net")); char *uamdomain = "customer.hotspotsystem.com"; if (!nvram_match("hotss_customuam", "")) { uamdomain = nvram_safe_get("hotss_customuam"); } fprintf(fp, "uamserver %s://%s/customer/hotspotlogin.php\n", nvram_default_get("hotss_customuamproto", "https"), uamdomain); if (nvram_invmatch("wan_get_dns", "0.0.0.0") && nvram_invmatch("wan_get_dns", "")) { dnslist = nvram_safe_get("wan_get_dns"); i = 1; foreach(var, dnslist, next) { if (i > 2) break; fprintf(fp, "dns%d %s\n", i, var); i++; } } else if (nvram_invmatch("wan_dns", "0.0.0.0")
void // do_upgrade_post(char *url, FILE *stream, int len, char *boundary) do_upgrade_post(char *url, webs_t stream, int len, char *boundary) // jimmy, // https, // 8/6/2003 { killall("udhcpc", SIGKILL); #ifndef ANTI_FLASH char buf[1024]; int type = 0; upgrade_ret = EINVAL; // Let below files loaded to memory // To avoid the successful screen is blank after web upgrade. // system2 ("cat /www/Success_u_s.asp > /dev/null"); // system2 ("cat /www/Fail_u_s.asp > /dev/null"); /* * Look for our part */ while (len > 0) { if (!wfgets(buf, MIN(len + 1, sizeof(buf)), stream)) return; len -= strlen(buf); if (!strncasecmp(buf, "Content-Disposition:", 20)) { if (strstr(buf, "name=\"erase\"")) { while (len > 0 && strcmp(buf, "\n") && strcmp(buf, "\r\n")) { if (!wfgets(buf, MIN(len + 1, sizeof(buf)), stream)) return; len -= strlen(buf); } if (!wfgets(buf, MIN(len + 1, sizeof(buf)), stream)) return; len -= strlen(buf); buf[1] = '\0'; // we only want the 1st digit nvram_set("sv_restore_defaults", buf); nvram_commit(); } else if (strstr(buf, "name=\"file\"")) // upgrade image { type = 0; break; } } } /* * Skip boundary and headers */ while (len > 0) { if (!wfgets(buf, MIN(len + 1, sizeof(buf)), stream)) return; len -= strlen(buf); if (!strcmp(buf, "\n") || !strcmp(buf, "\r\n")) break; } upgrade_ret = sys_upgrade(NULL, stream, &len, type); fprintf(stderr, "core upgrade done() %d\n", len); /* * Restore factory original settings if told to. This will also cause a * restore defaults on reboot of a Sveasoft firmware. */ if (nvram_match("sv_restore_defaults", "1")) { system2("rm -f /usr/local/nvram/nvram.bin"); } /* * Slurp anything remaining in the request */ while (len--) { #ifdef HAVE_HTTPS if (do_ssl) { wfgets(buf, 1, stream); } else { (void)fgetc(stream); } #else (void)fgetc(stream); #endif } #endif fprintf(stderr, "upgrade done()\n"); }