int launch_wan_modem_ras(int unit) { char node_name[16] = {0}; char call_file[16]; char call_path[32]; snprintf(call_file, sizeof(call_file), "modem.wan%d", unit); snprintf(call_path, sizeof(call_path), "%s/%s", PPP_PEERS_DIR, call_file); mkdir_if_none(PPP_PEERS_DIR); unlink(call_path); if (get_modem_node_ras(node_name, NULL)) { if (write_pppd_ras_conf(call_path, node_name, unit)) { logmessage(LOGNAME, "select RAS modem interface %s to pppd", node_name); return eval("/usr/sbin/pppd", "call", call_file); } } logmessage(LOGNAME, "unable to open RAS modem script!"); return 1; }
int start_openvpn_server(void) { int i_mode_tun; char vpns_cfg[64], vpns_scr[64]; char *server_conf = "server.conf"; char *openvpn_argv[] = { OPENVPN_EXE, "--daemon", "openvpn-srv", "--cd", SERVER_ROOT_DIR, "--config", server_conf, NULL }; snprintf(vpns_cfg, sizeof(vpns_cfg), "%s/%s", SERVER_ROOT_DIR, server_conf); snprintf(vpns_scr, sizeof(vpns_scr), "%s/%s", SERVER_ROOT_DIR, SCRIPT_OVPN_SERVER); mkdir_if_none(SERVER_ROOT_DIR, "755"); mkdir_if_none(COMMON_TEMP_DIR, "777"); i_mode_tun = (nvram_get_int("vpns_ov_mode") == 1) ? 1 : 0; /* create conf file */ if (openvpn_create_server_conf(vpns_cfg, i_mode_tun)) return 1; /* create tun or tap device (and add tap to bridge) */ if (i_mode_tun) openvpn_tunif_start(IFNAME_SERVER_TUN); else openvpn_tapif_start(IFNAME_SERVER_TAP, 1); /* create script symlink */ symlink("/sbin/rc", vpns_scr); logmessage(LOGNAME, "starting %s...", SERVER_LOG_NAME); return _eval(openvpn_argv, NULL, 0, NULL); }
int mdev_wdm_main(int argc, char **argv) { FILE *fp; int isLock; char node_fname[64]; const char *device_name, *action; if(argc != 3){ printf("Usage: %s [device_name] [action]\n", argv[0]); return 0; } device_name = argv[1]; action = argv[2]; usb_dbg("(%s): action=%s.\n", device_name, action); if(!isWDMNode(device_name)) return 0; sprintf(node_fname, "%s/%s", MODEM_NODE_DIR, device_name); // Check Lock. if((isLock = file_lock((char *)device_name)) == -1) return 0; unlink(QMI_CLIENT_ID); // If remove the device? if(!check_hotplug_action(action)){ unlink(node_fname); goto out_unlock; } // Write node file. mkdir_if_none(MODEM_NODE_DIR); fp = fopen(node_fname, "w+"); if (fp) { fprintf(fp, "pref=%d\n", 1); fprintf(fp, "devnum=%d\n", 0); // todo fclose(fp); } usb_dbg("(%s): Success!\n", device_name); out_unlock: file_unlock(isLock); return 1; }
int create_mp_link(char *search_dir, char *link_path, int force_first_valid) { FILE *procpt; char line[256], devname[32], mpname[128], system_type[16], mount_mode[160], target_path[256]; int dummy1, dummy2, link_created; link_created = 0; procpt = fopen("/proc/mounts", "r"); if (procpt) { while (fgets(line, sizeof(line), procpt)) { if (sscanf(line, "%s %s %s %s %d %d", devname, mpname, system_type, mount_mode, &dummy1, &dummy2) != 6) continue; #if 0 if (only_ext_xfs) { if (strcmp(system_type, "xfs") && strcmp(system_type, "exfat") && strncmp(system_type, "ext", 3)) continue; } #endif if (strncmp(devname, "/dev/sd", 7) == 0 && strncmp(mpname, "/media/", 7) == 0) { sprintf(target_path, "%s/%s", mpname, search_dir); if (!force_first_valid) { if (check_if_dir_exist(target_path)) { if (symlink(target_path, link_path) == 0) { link_created = 1; break; } } } else { if (mkdir_if_none(target_path)) { if (symlink(target_path, link_path) == 0) { link_created = 1; break; } } } } } fclose(procpt); } return link_created; }
void run_samba(void) { int sh_num, has_nmbd, i; char tmpuser[40], tmp2[40]; char cmd[256]; if (nvram_match("enable_samba", "0") || nvram_match("st_samba_mode", "0")) return; mkdir_if_none("/etc/samba", "777"); has_nmbd = pids("nmbd"); if (!has_nmbd) { doSystem("rm -f %s", "/etc/samba/*"); clean_smbd_trash(); } recreate_passwd_unix(0); write_smb_conf(); sh_num = nvram_safe_get_int("acc_num", 0, 0, MAX_ACCOUNT_NUM); for (i = 0; i < sh_num; i++) { snprintf(tmpuser, sizeof(tmpuser), "acc_username%d", i); snprintf(tmp2, sizeof(tmp2), "acc_password%d", i); snprintf(cmd, sizeof(cmd), "smbpasswd %s %s", nvram_safe_get(tmpuser), nvram_safe_get(tmp2)); system(cmd); } if (has_nmbd) doSystem("killall %s %s", "-SIGHUP", "nmbd"); else eval("/sbin/nmbd", "-D", "-s", "/etc/smb.conf"); eval("/sbin/smbd", "-D", "-s", "/etc/smb.conf"); if (pids("smbd") && pids("nmbd")) logmessage("Samba Server", "daemon is started"); }
int mdev_tty_main(int argc, char **argv) { FILE *fp; int isLock, devnum, has_int_pipe; char usb_port_id[64], usb_interface_id[64], node_fname[64]; const char *device_name, *action; if(argc != 3){ printf("Usage: %s [device_name] [action]\n", argv[0]); return 0; } device_name = argv[1]; action = argv[2]; usb_dbg("(%s): action=%s.\n", device_name, action); if (!isSerialNode(device_name) && !isACMNode(device_name)) return 0; sprintf(node_fname, "%s/%s", MODEM_NODE_DIR, device_name); // Check Lock. if((isLock = file_lock((char *)device_name)) == -1) return 0; // If remove the device? if(!check_hotplug_action(action)){ unlink(node_fname); if (get_usb_modem_wan(0)) notify_rc("on_unplug_usb_modem"); usb_dbg("(%s): Remove the modem node\n", device_name); goto out_unlock; } // Get DevNum devnum = 0; has_int_pipe = 0; usb_port_id[0] = 0; if (get_interface_by_device(device_name, usb_interface_id, sizeof(usb_interface_id))) { has_int_pipe = get_interface_Int_endpoint(usb_interface_id); if (get_usb_port_by_interface_string(usb_interface_id, usb_port_id, sizeof(usb_port_id))) devnum = get_usb_devnum(usb_port_id); } // Write node file. mkdir_if_none(MODEM_NODE_DIR); fp = fopen(node_fname, "w+"); if (fp) { fprintf(fp, "pref=%d\n", (has_int_pipe) ? 1 : 0); fprintf(fp, "devnum=%d\n", devnum); fprintf(fp, "portid=%s\n", usb_port_id); fclose(fp); } if (nvram_invmatch("modem_arun", "0") && nvram_match("modem_rule", "1") && nvram_invmatch("modem_type", "3")) notify_rc("on_hotplug_usb_modem"); usb_dbg("(%s): Success!\n", device_name); out_unlock: file_unlock(isLock); return 1; }
int start_timemachine() { int ret = 0; char cnid_path[80]; char backup_path[80]; //char token_path[80]; char test_log[100]; char *mount_point_name; char prefix[] = "usb_pathXXXXXXXXXXXXXXXXX_", tmp[100]; char usb1_vid[8], usb1_pid[8], usb1_serial[64]; char usb2_vid[8], usb2_pid[8], usb2_serial[64]; snprintf(prefix, sizeof(prefix), "usb_path%s", "1"); memset(usb1_vid, 0, 8); strncpy(usb1_vid, nvram_safe_get(strcat_r(prefix, "_vid", tmp)), 8); memset(usb1_pid, 0, 8); strncpy(usb1_pid, nvram_safe_get(strcat_r(prefix, "_pid", tmp)), 8); memset(usb1_serial, 0, 64); strncpy(usb1_serial, nvram_safe_get(strcat_r(prefix, "_serial", tmp)), 8); snprintf(prefix, sizeof(prefix), "usb_path%s", "2"); memset(usb2_vid, 0, 8); strncpy(usb2_vid, nvram_safe_get(strcat_r(prefix, "_vid", tmp)), 8); memset(usb2_pid, 0, 8); strncpy(usb2_pid, nvram_safe_get(strcat_r(prefix, "_pid", tmp)), 8); memset(usb2_serial, 0, 64); strncpy(usb2_serial, nvram_safe_get(strcat_r(prefix, "_serial", tmp)), 8); //clear_timemachine_tokeninfo(); //find_tokenfile_partition(); if(!nvram_match("timemachine_enable", "1")) return -1; if(nvram_safe_get("tm_device_name") == NULL) { _dprintf("Timemachine: no device name to backup\n"); logmessage("Timemachine", "no device name to backup"); return -1; } #if 1 if(nvram_match("tm_ui_setting", "1")){ logmessage("Timemachine", "User select disk start TimeMachine"); mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name")); nvram_set("tm_ui_setting", "0"); }else{ //check mountpoint exchange or not if(!nvram_match("tm_usb_path_vid", "") && (nvram_match("tm_usb_path_vid",usb1_vid)) && (nvram_match("tm_usb_path_pid",usb1_pid)) && (nvram_match("tm_usb_path_serial",usb1_serial))) { sprintf(test_log, "Time Machine interface1 change %s -> %s", nvram_safe_get("tm_device_name"),nvram_safe_get("tm_partition_num")); mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name")); logmessage("Timemachine", test_log); } else if(!nvram_match("tm_usb_path_vid", "") && (nvram_match("tm_usb_path_vid",usb2_vid)) && (nvram_match("tm_usb_path_pid",usb2_pid)) && (nvram_match("tm_usb_path_serial",usb2_serial))) { sprintf(test_log, "tm_device_name interface2 change %s -> %s", nvram_safe_get("tm_device_name"),nvram_safe_get("tm_partition_num")); mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name")); logmessage("Timemachine", test_log); }else{ logmessage("Timemachine", "No disk to auto start TimeMachine"); mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name")); } } #endif if(mount_point_name == NULL) { _dprintf("Timemachine: can not find the correct mount point name\n"); logmessage("Timemachine", "can not find the correct mount point name"); return -1; } if(!check_if_dir_exist(mount_point_name)) { _dprintf("Timemachine: mount point name doesn't exist\n"); logmessage("Timemachine", "mount point name doesn't exist"); return -1; } // Create directory for use by afpd daemon and configuration file //if(!check_if_dir_exist(AFP_LOCK_PATH)) mkdir(AFP_LOCK_PATH, 0777); //if(!check_if_dir_exist(AFP_CONFIG_PATH)) mkdir(AFP_CONFIG_PATH, 0777); mkdir_if_none(AFP_LOCK_PATH); mkdir_if_none(AFP_CONFIG_PATH); // Create directory for use by avahi daemon and configuration file //if(!check_if_dir_exist(AVAHI_CONFIG_PATH)) mkdir(AVAHI_CONFIG_PATH, 0777); //if(!check_if_dir_exist(AVAHI_SERVICES_PATH)) mkdir(AVAHI_SERVICES_PATH, 0777); mkdir_if_none(AVAHI_CONFIG_PATH); mkdir_if_none(AVAHI_SERVICES_PATH); // Create directory for use by cnid_metad and cnid_dbd daemon sprintf(cnid_path, "%s/%s", mount_point_name, CNID_DIR_NAME); sprintf(backup_path, "%s", mount_point_name); //Create token file //sprintf(token_path, "%s/%s", mount_point_name, TIMEMACHINE_TOKEN_FILE); //if(!check_if_file_exist(token_path)) // ret = generate_timemachine_token_file(token_path); //if(!check_if_dir_exist(cnid_path)) mkdir(cnid_path, 0777); //if(!check_if_dir_exist(backup_path)) mkdir(backup_path, 0777); mkdir_if_none(cnid_path); //mkdir_if_none(backup_path); ret = generate_afp_config(mount_point_name); start_afpd(); start_cnid_metad(); restart_mdns(); logmessage("Timemachine", "daemon is started"); return ret; }
/* type : as define function TM_WRS_MAIL, TRAFFIC_CONTROL_MAIL, etc. path : attachment file or some information in file, if no file, path will be NULL */ static void am_send_mail(int type, char *path) { FILE *fp; char title[64], smtp_auth_pass[256]; char date[30]; time_t now; int status = 0; memset(title, 0, sizeof(title)); memset(date, 0, sizeof(date)); memset(smtp_auth_pass, 0, sizeof(smtp_auth_pass)); // get current date time(&now); StampToDate(now, date); // email server conf setting mkdir_if_none("/etc/email"); if((fp = fopen(MAIL_CONF, "w")) == NULL){ _dprintf("fail to open %s\n", MAIL_CONF); return; } #ifdef RTCONFIG_HTTPS strncpy(smtp_auth_pass,pwdec(nvram_get("PM_SMTP_AUTH_PASS")),256); #else strncpy(smtp_auth_pass,nvram_get("PM_SMTP_AUTH_PASS"),256); #endif fprintf(fp,"SMTP_SERVER = '%s'\n", nvram_safe_get("PM_SMTP_SERVER")); fprintf(fp,"SMTP_PORT = '%s'\n", nvram_safe_get("PM_SMTP_PORT")); fprintf(fp,"MY_NAME = 'Administrator'\n"); fprintf(fp,"MY_EMAIL = '%s'\n", nvram_safe_get("PM_MY_EMAIL")); fprintf(fp,"USE_TLS = 'true'\n"); fprintf(fp,"SMTP_AUTH = 'LOGIN'\n"); fprintf(fp,"SMTP_AUTH_USER = '******'\n", nvram_safe_get("PM_SMTP_AUTH_USER")); fprintf(fp,"SMTP_AUTH_PASS = '******'\n", smtp_auth_pass); fclose(fp); // mail title #ifdef RTCONFIG_BWDPI if(type == TM_WRS_MAIL) sprintf(title, "AiProtection alert! %s", date); #endif #ifdef RTCONFIG_TRAFFIC_CONTROL if(type == TRAFFIC_CONTROL_MAIL) sprintf(title, "Traffic control alert! %s", date); #endif // create command (attachment or not) char cmd[512]; memset(cmd, 0, sizeof(cmd)); if (path != NULL){ sprintf(cmd, "email -V -s \"%s\" %s -a \"%s\"", title, nvram_safe_get("PM_MY_EMAIL"), path); } else{ sprintf(cmd, "email -V -s \"%s\" %s", title, nvram_safe_get("PM_MY_EMAIL")); } // create popen if((fp = popen(cmd, "w")) == NULL){ _dprintf("%s : popen() error\n", __FUNCTION__); return; } // email content use popen (pipe open) ... // write mail content #ifdef RTCONFIG_BWDPI if(type == TM_WRS_MAIL) { // extract mail log into seperated event information extract_data(path, fp); fprintf(fp, "Suggest action: Your client devices has been detected suspicious networking behavior and blocked connection with destination server to protect your sensitive information.\nBased on our recommendation, you can\n"); fprintf(fp, "1. Remove app that access this site and don't visit this website to prevent any personal information leak.\n"); fprintf(fp, "2. Check your router security setting.\n"); fprintf(fp, "3. Update security patch for your client or new firmware for your router.\n"); fprintf(fp, "Please refer to attached log file for detail information. You also can link to trend micro website to download security trial software for your client device protection.\n"); fprintf(fp, "\n"); fprintf(fp, "http://www.trendmicro.com/\n"); logmessage("alert mail", "AiProtection send mail"); } #endif #ifdef RTCONFIG_TRAFFIC_CONTROL if(type == TRAFFIC_CONTROL_MAIL) { int count = nvram_get_int("traffic_control_count"); fprintf(fp, "Dear user,\n\n"); fprintf(fp, "Traffic Control configuration as below:\n\n"); if((count & 1) == 1){ fprintf(fp, "\t<Primary WAN>\n"); fprintf(fp, "\tRouter Current Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_realtime_0"))); fprintf(fp, "\tAlert Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_alert_max"))); fprintf(fp, "\tMAX Traffic: %.2f GB\n\n", atof(nvram_safe_get("traffic_control_limit_max"))); } if((count & 2) == 2){ fprintf(fp, "\t<Secondary WAN>\n"); fprintf(fp, "\tRouter Current Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_realtime_1"))); fprintf(fp, "\tAlert Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_alert_max"))); fprintf(fp, "\tMAX Traffic: %.2f GB\n\n", atof(nvram_safe_get("traffic_control_limit_max"))); } fprintf(fp, "Your internet traffic usage have reached the alert vlaue. If you are in limited traffic usage, please get more attention.\n\n"); fprintf(fp, "Thanks,\n"); fprintf(fp, "ASUSTeK Computer Inc.\n"); logmessage("alert mail", "Traffic control send mail"); } #endif status = pclose(fp); if(status == -1) _dprintf("%s : errno %d (%s)\n", __FUNCTION__, errno, strerror(errno)); }