Ejemplo n.º 1
0
static void QoSSetup(webs_t wp, char_t *path, char_t *query)
{
	char *submitUrl;

	char_t *QoS_type = websGetVar(wp, T("QoSSelect"), T("0"));
	if (QoS_type == NULL)
		QoS_type = "0";

	char_t *simpleqos = websGetVar(wp, T("simple_qos"), T("0"));
	if (strcmp(simpleqos, "on") != 0)
		simpleqos = "off";
	simpleqos = (strcmp(simpleqos, "on") == 0) ? "1" : "0";

	nvram_init(RT2860_NVRAM);
	nvram_bufset(RT2860_NVRAM, "QoSEnable", QoS_type);
	nvram_bufset(RT2860_NVRAM, "simple_qos", simpleqos);

	if (CHK_IF_DIGIT(QoS_type, 2))
		setupParameters(wp, QoS_args, 0);

	nvram_close(RT2860_NVRAM);
	doSystem("service shaper restart && service iptables restart && service kext restart");

	submitUrl = websGetVar(wp, T("submit-url"), T(""));   // hidden page
#ifdef PRINT_DEBUG
	if (!submitUrl || !submitUrl[0])
		websDone(wp, 200);
	else
#endif
		websRedirect(wp, submitUrl);
}
Ejemplo n.º 2
0
/* goform/StorageEditUser */
static void StorageEditUser(webs_t wp, char_t *path, char_t *query)
{
	char_t *index, *password; 
	char_t *user_ftp_enable, *user_smb_enable;
	char feild[20];

	feild[0] = '\0';
	// fetch from web input
	index = websGetVar(wp, T("hiddenIndex"), T(""));
	password = websGetVar(wp, T("edituser_pw"), T(""));
	user_ftp_enable = websGetVar(wp, T("edituser_ftp"), T(""));
	user_smb_enable = websGetVar(wp, T("edituser_smb"), T(""));
	/*
	DEBUG(index);
	DEBUG(password);
	DEBUG(user_ftp_enable);
	DEBUG(user_smb_enable);
	*/

	// set to nvram
	sprintf(feild, "User%sPasswd", index);
	nvram_bufset(RT2860_NVRAM, feild, password);
	sprintf(feild, "FtpUser%s", index);
	// DEBUG(feild);
	nvram_bufset(RT2860_NVRAM, feild, user_ftp_enable);
	sprintf(feild, "SmbUser%s", index);
	// DEBUG(feild);
	nvram_bufset(RT2860_NVRAM, feild, user_smb_enable);
	nvram_commit(RT2860_NVRAM);
	doSystem("storage.sh admin");
		
	websRedirect(wp, "usb/STORAGEuser_admin.asp");
}
Ejemplo n.º 3
0
/* goform/webcamra */
static void webcamra(webs_t wp, char_t *path, char_t *query)
{
	char_t *enable, *resolution, *fps, *port;

	// fetch from web input
	enable = websGetVar(wp, T("enabled"), T(""));
	resolution = websGetVar(wp, T("resolution"), T(""));
	fps = websGetVar(wp, T("fps"), T(""));
	port = websGetVar(wp, T("port"), T(""));

	// set to nvram
	nvram_bufset(RT2860_NVRAM, "WebCamEnabled", enable);
	nvram_bufset(RT2860_NVRAM, "WebCamResolution", resolution);
	nvram_bufset(RT2860_NVRAM, "WebCamFPS", fps);
	nvram_bufset(RT2860_NVRAM, "WebCamPort", port);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("killall uvc_stream");
	if (0 == strcmp(enable, "1"))
	{
		doSystem("uvc_stream -r %s -f %s -p %s -b", 
				  resolution, fps, port);
	}

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>Web Camera Settings</h2><br>\n"));
	websWrite(wp, T("enabled: %s<br>\n"), enable);
	websWrite(wp, T("resolution: %s<br>\n"), resolution);
	websWrite(wp, T("fps: %s<br>\n"), fps);
	websWrite(wp, T("port: %s<br>\n"), port);
	websFooter(wp);
	websDone(wp, 200);
}
Ejemplo n.º 4
0
/* goform/storageAdm */
static void storageAdm(webs_t wp, char_t *path, char_t *query)
{
	char_t *submit;

	submit = websGetVar(wp, T("hiddenButton"), T(""));

	if (0 == strcmp(submit, "delete"))
	{
		char_t *user_select;
		char feild[20];

		feild[0] = '\0';
		user_select = websGetVar(wp, T("storage_user_select"), T(""));
		sprintf(feild, "User%s", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		doSystem("rm -rf \"%s/home/%s\"", first_part, nvram_bufget(RT2860_NVRAM, feild));
		sprintf(feild, "User%sPasswd", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		sprintf(feild, "FtpUser%s", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		sprintf(feild, "SmbUser%s", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		nvram_commit(RT2860_NVRAM);
		doSystem("storage.sh admin");
	}
	else if (0 == strcmp(submit, "apply"))
	{
		initUSB();
	}
	websRedirect(wp, "usb/STORAGEuser_admin.asp");
}
Ejemplo n.º 5
0
int gen_config(int mode)
{
	FILE *fp;
	int  i, ssid_num = 1;
	char tx_rate[16], wmm_enable[16];

	nvram_init(mode);

	/*
	nvram_bufset(mode, "SystemName", "RalinkAP");
	nvram_bufset(mode, "ModuleName", "RT2860");
	nvram_commit(mode);
	*/
	if (mode == RT2860_NVRAM) {
		unsigned char temp[2], buf[4];
		flash_read_NicConf(buf);
		sprintf(temp, "%x", buf[1]);
		nvram_bufset(mode, "RFICType", temp);
		sprintf(temp, "%x", buf[0]&0xf0>>4);
		if (atoi(temp) < atoi(nvram_bufget(mode, "HT_TxStream")))
			nvram_bufset(mode, "HT_TxStream", temp);
		nvram_bufset(mode, "TXPath", temp);
		sprintf(temp, "%x", buf[0]&0x0f);
		if (atoi(temp) < atoi(nvram_bufget(mode, "HT_RxStream")))
			nvram_bufset(mode, "HT_RxStream", temp);
		nvram_bufset(mode, "RXPath", temp);
		nvram_commit(mode);
	}
Ejemplo n.º 6
0
static void iTunesSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *enable, *dir_path, *name;

	// fetch from web input
	enable = websGetVar(wp, T("enabled"), T("0"));
	dir_path = websGetVar(wp, T("dir_path"), T(""));
	name = websGetVar(wp, T("srv_name"), T(""));
	// set to nvram
	nvram_bufset(RT2860_NVRAM, "iTunesEnable", enable);
	nvram_bufset(RT2860_NVRAM, "iTunesDir", dir_path);
	nvram_bufset(RT2860_NVRAM, "iTunesSrvName", name);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("killall mt-daapd; killall mDNSResponder");
	if (strcmp(enable, "1") == 0)
		doSystem("config-iTunes.sh \"%s\" \"%s\" \"%s\"", 
				 name,
				 nvram_bufget(RT2860_NVRAM, "Password"),
				 dir_path);

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>iTunes Server Settings</h2><br>\n"));
	websWrite(wp, T("capability: %s<br>\n"), enable);
	websWrite(wp, T("srv_name: %s<br>\n"), name);
	websWrite(wp, T("media library: %s<br>\n"), dir_path);
	websFooter(wp);
	websDone(wp, 200);
}
Ejemplo n.º 7
0
/* goform/storageSmbSrv */
static void storageSmbSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *submit;

	submit =  websGetVar(wp, T("hiddenButton"), T(""));

	if (0 == strcmp(submit, "delete"))
	{
		int index;
		FILE *fp;
		char smb_config_file[25];

		// strcpy(smb_config_file, "/var/.smb_config");
		sprintf(smb_config_file, "%s/.smb_config", first_part);
		fp = fopen(smb_config_file, "w");

		if (NULL == fp) {
			perror(__FUNCTION__);
			return;
		}

		index = atoi(websGetVar(wp, T("selectIndex"), T("")));
		// fprintf(stderr, "before set bitmap: %x%x%x\n", smb_conf.bitmap[2], smb_conf.bitmap[1], smb_conf.bitmap[0]);
		smb_conf.bitmap[index/32] &= ~(1<<(index%32));
		// fprintf(stderr, "after set bitmap: %x%x%x\n", smb_conf.bitmap[2], smb_conf.bitmap[1], smb_conf.bitmap[0]);
		smb_conf.count--;
		// fprintf(stderr, "smb dir count: %d\n", smb_conf.count);
		fwrite(&smb_conf, sizeof(struct smb_dir_config), 1, fp);
		fclose(fp);
		websRedirect(wp, "usb/SAMBAsmbsrv.asp");
	} 
	else if (0 == strcmp(submit, "apply"))
	{
		char_t *smb_enable, *wg, *netbios;
		
		// fetch from web input
		smb_enable = websGetVar(wp, T("smb_enabled"), T(""));
		wg = websGetVar(wp, T("smb_workgroup"), T(""));
		netbios = websGetVar(wp, T("smb_netbios"), T(""));

		// set to nvram
		nvram_bufset(RT2860_NVRAM, "SmbEnabled", smb_enable);
		nvram_bufset(RT2860_NVRAM, "HostName", wg);
		nvram_bufset(RT2860_NVRAM, "SmbNetBIOS", netbios);
		nvram_commit(RT2860_NVRAM);

		// setup device
		SetSambaSrv();

		// debug print
		websHeader(wp);
		websWrite(wp, T("<h2>smb_enabled: %s</h2><br>\n"), smb_enable);
		websWrite(wp, T("smb_workgroup: %s<br>\n"), wg);
		websWrite(wp, T("smb_netbios: %s<br>\n"), netbios);
		websFooter(wp);
		websDone(wp, 200);
	}
}
Ejemplo n.º 8
0
static void storageMediaSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *submit;

	submit =  websGetVar(wp, T("hiddenButton"), T(""));

	if (0 == strcmp(submit, "delete"))
	{
		int index;
		FILE *fp;
		char media_config_file[25];

		// strcpy(smb_config, "/var/.smb_config");
		sprintf(media_config_file, "%s/.media_config", first_part);
		fp = fopen(media_config_file, "w");

		if (NULL == fp) {
			perror(__FUNCTION__);
			return;
		}

		index = atoi(websGetVar(wp, T("media_dir"), T("")));
		memset(&media_conf[index].path, 0, sizeof(media_conf[index].path));	
		fwrite(media_conf, sizeof(media_conf), 1, fp);
		fclose(fp);
		websRedirect(wp, "usb/USHAREmediasrv.asp");
	} 
	else if (0 == strcmp(submit, "apply"))
	{
		char_t *media_enabled, *media_name;
		int i;
		
		// fetch from web input
		media_enabled = websGetVar(wp, T("media_enabled"), T(""));
		media_name = websGetVar(wp, T("media_name"), T(""));

		// set to nvram
		nvram_bufset(RT2860_NVRAM, "mediaSrvEnabled", media_enabled);
		nvram_bufset(RT2860_NVRAM, "mediaSrvName", media_name);
		nvram_commit(RT2860_NVRAM);

		// setup device
		if (0 == strcmp(media_enabled, "0"))
			memset(media_conf, 0, sizeof(media_conf));
		RunMediaSrv();

		// debug print
		websHeader(wp);
		websWrite(wp, T("<h2>Media Server Settings</h2><br>\n"));
		websWrite(wp, T("media_enabled: %s<br>\n"), media_enabled);
		websWrite(wp, T("media_name: %s<br>\n"), media_name);
		for(i=0;i<4;i++)
			websWrite(wp, T("media dir%d path: %s<br>\n"), i, media_conf[i].path);
		websFooter(wp);
		websDone(wp, 200);
	}
}
Ejemplo n.º 9
0
/* goform/StorageAddUser */
static void StorageAddUser(webs_t wp, char_t *path, char_t *query)
{
	char_t *name, *password;
	char_t *user_ftp_enable, *user_smb_enable;
	char mode[6], feild[20];
	int index; 

	mode[0] = '\0';
	feild[0] = '\0';

	// fetch from web input
	name = websGetVar(wp, T("adduser_name"), T(""));
	password = websGetVar(wp, T("adduser_pw"), T(""));
	user_ftp_enable = websGetVar(wp, T("adduser_ftp"), T(""));
	user_smb_enable = websGetVar(wp, T("adduser_smb"), T(""));
	/*
	DEBUG(name);
	DEBUG(password);
	DEBUG(user_ftp_enable);
	DEBUG(user_smb_enable);
	*/
	// get null user feild form nvram
	index = GetNthFree("User");
	// fprintf(stderr, "index: %d\n", index);

	// set to nvram
	if (0 != index) {
		sprintf(feild, "User%d", index);
		nvram_bufset(RT2860_NVRAM, feild, name);
		sprintf(feild, "User%dPasswd", index);
		nvram_bufset(RT2860_NVRAM, feild, password);
		sprintf(feild, "FtpUser%d", index);
		nvram_bufset(RT2860_NVRAM, feild, user_ftp_enable);
		sprintf(feild, "SmbUser%d", index);
		nvram_bufset(RT2860_NVRAM, feild, user_smb_enable);
		nvram_commit(RT2860_NVRAM);
		doSystem("storage.sh admin");

		websRedirect(wp, "usb/STORAGEuser_admin.asp");
	} else {
		websHeader(wp);
		websWrite(wp, T("<h2>User Quota is Full!</h2><br>\n"));
		websFooter(wp);
		websDone(wp, 200);
	}
}
Ejemplo n.º 10
0
int nvram_set(int index, char *name, char *value)
{
    //LIBNV_PRINT("--> nvram_set\n");

    if (-1 == nvram_bufset(index, name, value))

        return -1;
    return nvram_commit(index);
}
Ejemplo n.º 11
0
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);
}
Ejemplo n.º 12
0
static void QoSLoadDefaultProfile(webs_t wp, char_t *path, char_t *query)
{
    int i;
    for(i=0; i<QOS_PROFILE_ENTRYS_MAX ; i++) {
        if(QOS_PROFILE[i].name) {
            nvram_bufset(RT2860_NVRAM, QOS_PROFILE[i].name, QOS_PROFILE[i].value);
        } else {
            break;
        }
    }
    nvram_commit(RT2860_NVRAM);
    QoSRestart();

    websHeader(wp);
    websWrite(wp, T("Load default profile successfully.\n"));
    websFooter(wp);
    websDone(wp, 200);
}
Ejemplo n.º 13
0
static void goaSigHandler(int signum)
{
#ifdef CONFIG_RT2860V2_STA_WSC
	const char *opmode = nvram_bufget(RT2860_NVRAM, "OperationMode");
	const char *ethCon = nvram_bufget(RT2860_NVRAM, "ethConvert");
#endif

	if (signum != SIGUSR1)
		return;

#ifdef CONFIG_RT2860V2_STA_WSC
	if(!strcmp(opmode, "2") || (!strcmp(opmode, "0") &&   !strcmp(ethCon, "1") ) ) {		// wireless isp mode
		nvram_bufset(RT2860_NVRAM, "staWPSMode", "0");
		nvram_commit(RT2860_NVRAM);
		WPSSTAPBCStartEnr();	// STA WPS default is "Enrollee mode".
	}
	else
#endif
		WPSAPPBCStartAll();
}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
0
   static void linkbackup_action(webs_t wp, char_t *path, char_t *query)
  {
  	char linkbackup_para[1024];
	char *link_backup_status;
	char*link_backup_backtomain;
	char link_backup_first[10];
	char link_backup_second[10];
	char *link_backup_checkcount;


	char*linkbackup_cellural_priority_sel;
	char*linkbackup_wan_priority_sel;
	char*wan_port;

	
	char *link_backup_ping;
	char *link_backup_wan2_ping;
	
	char* link_backup_host;
	char* link_backup_wan2_host;



	
	int run_sign=0;
	
	
		link_backup_status=websGetVar(wp,T("link_backup_status") , T(""));
			
             if(strstr(link_backup_status,"on"))  {
			 
                            run_sign=1;
		}else{
                             run_sign=0;
		}
		nvram_bufset(RT2860_NVRAM, "link_backup_status",link_backup_status);


              link_backup_backtomain=websGetVar(wp,T("link_backup_backtomain"), T(""));
		nvram_bufset(RT2860_NVRAM, "link_backup_backtomain",link_backup_backtomain);


		linkbackup_cellural_priority_sel= websGetVar(wp, T("linkbackup_cellural_priority_sel"), T(""));
		if(strstr(linkbackup_cellural_priority_sel,"0"))  strcpy(link_backup_first,"3G");  
		else  strcpy(link_backup_second,"3G");
		
		linkbackup_wan_priority_sel= websGetVar(wp, T("linkbackup_wan_priority_sel"), T(""));
		wan_port= websGetVar(wp, T("linkbackup_wan_sel"), T(""));
		if(strstr(linkbackup_wan_priority_sel,"0"))  strcpy(link_backup_first,wan_port);  
		else  strcpy(link_backup_second,wan_port);
		
		nvram_bufset(RT2860_NVRAM, "link_backup_first",link_backup_first);
		nvram_bufset(RT2860_NVRAM, "link_backup_second",link_backup_second);

		link_backup_checkcount= websGetVar(wp, T("link_backup_checkcount"), T(""));											
		nvram_bufset(RT2860_NVRAM, "link_backup_checkcount",link_backup_checkcount);




		link_backup_ping= websGetVar(wp, T("wan1_ping_sel"), T(""));	
		nvram_bufset(RT2860_NVRAM, "link_backup_ping",link_backup_ping);
		
		link_backup_host= websGetVar(wp, T("link_backup_wan1_host"), T(""));	
		nvram_bufset(RT2860_NVRAM, "link_backup_host",link_backup_host);


		link_backup_wan2_ping= websGetVar(wp, T("wan2_ping_sel"), T(""));	
		nvram_bufset(RT2860_NVRAM, "link_backup_wan2_ping",link_backup_wan2_ping);
		
		link_backup_wan2_host= websGetVar(wp, T("link_backup_wan2_host"), T(""));	
		nvram_bufset(RT2860_NVRAM, "link_backup_wan2_host",link_backup_wan2_host);



			memset(linkbackup_para,0,sizeof(linkbackup_para));
			sprintf(linkbackup_para,"%s,%s,%s,%s,%s,%s,%s,%s,%s",
					link_backup_status,link_backup_backtomain,link_backup_first,link_backup_second, link_backup_checkcount,link_backup_ping,
                                   link_backup_host,link_backup_wan2_ping,link_backup_wan2_host
			);







	//printf("rulesbuf:%s\n", rulesbuf);
	nvram_set(RT2860_NVRAM,nvram_linkbackup_para, linkbackup_para);
	nvram_commit(RT2860_NVRAM);


//	load_fail_over_para_to_buf();

	/* 完成转到ipsec 配置页面*/
	websRedirect(wp, "internet/linkbackup.asp");



//ipsec_run(); 
	link_backup_run(run_sign);



	return;

		
}
Ejemplo n.º 16
0
static void QoSSetup(webs_t wp, char_t *path, char_t *query)
{
    char_t *qos_enable, *qos_model, *upload_bandwidth, *download_bandwidth, *upload_bandwidth_custom, *download_bandwidth_custom;
    char_t *highest_upload_queue_rate, *highest_upload_queue_ceil, *high_upload_queue_rate, *high_upload_queue_ceil, *default_upload_queue_rate, *default_upload_queue_ceil, *low_upload_queue_rate, *low_upload_queue_ceil;
    char_t *highest_download_queue_rate, *highest_download_queue_ceil, *high_download_queue_rate, *high_download_queue_ceil, *default_download_queue_rate, *default_download_queue_ceil, *low_download_queue_rate, *low_download_queue_ceil;
    char_t *reserve_bandwidth;
    qos_enable = websGetVar(wp, T("QoSSelect"), T(""));
    qos_model = websGetVar(wp, T("Model"), T(""));
    upload_bandwidth = websGetVar(wp, T("UploadBandwidth"), T(""));
    download_bandwidth = websGetVar(wp, T("DownloadBandwidth"), T(""));
    upload_bandwidth_custom = websGetVar(wp, T("UploadBandwidth_Custom"), T(""));
    download_bandwidth_custom = websGetVar(wp, T("DownloadBandwidth_Custom"), T(""));

    reserve_bandwidth = websGetVar(wp, T("ReserveBandwidth"), T(""));

    highest_upload_queue_rate  = websGetVar(wp, T("highest_upload_queue_rate"), T(""));
    high_upload_queue_rate  = websGetVar(wp, T("high_upload_queue_rate"), T(""));
    default_upload_queue_rate  = websGetVar(wp, T("default_upload_queue_rate"), T(""));
    low_upload_queue_rate  = websGetVar(wp, T("low_upload_queue_rate"), T(""));

    highest_upload_queue_ceil  = websGetVar(wp, T("highest_upload_queue_ceil"), T(""));
    high_upload_queue_ceil  = websGetVar(wp, T("high_upload_queue_ceil"), T(""));
    default_upload_queue_ceil  = websGetVar(wp, T("default_upload_queue_ceil"), T(""));
    low_upload_queue_ceil  = websGetVar(wp, T("low_upload_queue_ceil"), T(""));

    highest_download_queue_rate  = websGetVar(wp, T("highest_download_queue_rate"), T(""));
    high_download_queue_rate  = websGetVar(wp, T("high_download_queue_rate"), T(""));
    default_download_queue_rate  = websGetVar(wp, T("default_download_queue_rate"), T(""));
    low_download_queue_rate  = websGetVar(wp, T("low_download_queue_rate"), T(""));

    highest_download_queue_ceil  = websGetVar(wp, T("highest_download_queue_ceil"), T(""));
    high_download_queue_ceil  = websGetVar(wp, T("high_download_queue_ceil"), T(""));
    default_download_queue_ceil  = websGetVar(wp, T("default_download_queue_ceil"), T(""));
    low_download_queue_ceil  = websGetVar(wp, T("low_download_queue_ceil"), T(""));

    if(!qos_enable || !strlen(qos_enable))
        return;

    if(!strcmp(upload_bandwidth, "custom"))
        if(!upload_bandwidth_custom)
            return;
    if(!strcmp(download_bandwidth, "custom"))
        if(!download_bandwidth_custom)
            return;

    if(!strcmp(qos_enable, "1") /* bi-dir */ || !strcmp(qos_enable, "2") /* upload */ || !strcmp(qos_enable, "3") /* download */ || !strcmp(qos_enable, "4") /* port based */) {
        if(!strlen(upload_bandwidth))
            return;
        if(!strlen(download_bandwidth))
            return;
    }
    nvram_bufset(RT2860_NVRAM, "QoSEnable", qos_enable);

    if(!strcmp(qos_enable, "1") /* bi-dir */ || !strcmp(qos_enable, "2")/* upload */ || !strcmp(qos_enable, "3") /* download */ || !strcmp(qos_enable, "4") /* port based */) {
        char postfix[16];
        strncpy(postfix, upload_bandwidth_custom, sizeof(postfix));
        if(!strchr(postfix, 'k') && !strchr(postfix, 'K')  && !strchr(postfix, 'm') && !strchr(postfix, 'M') )
            strncat(postfix, "k", sizeof(postfix));
        nvram_bufset(RT2860_NVRAM, "QoSUploadBandwidth_custom", postfix);
        strncpy(postfix, download_bandwidth_custom, sizeof(postfix));
        if(!strchr(postfix, 'k') && !strchr(postfix, 'K')  && !strchr(postfix, 'm') && !strchr(postfix, 'M') )
            strncat(postfix, "k", sizeof(postfix));

        nvram_bufset(RT2860_NVRAM, "QoSDownloadBandwidth_custom", postfix);
        nvram_bufset(RT2860_NVRAM, "QoSUploadBandwidth", upload_bandwidth);
        nvram_bufset(RT2860_NVRAM, "QoSDownloadBandwidth", download_bandwidth);

        nvram_bufset(RT2860_NVRAM, "QoSReserveBandwidth", reserve_bandwidth);

        nvram_bufset(RT2860_NVRAM, "QoSModel", qos_model);

        if(highest_upload_queue_rate && strlen(highest_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF5ULRate", highest_upload_queue_rate);
        if(high_upload_queue_rate && strlen(high_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF2ULRate", high_upload_queue_rate);
        if(default_upload_queue_rate && strlen(default_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF6ULRate", default_upload_queue_rate);
        if(low_upload_queue_rate && strlen(low_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF1ULRate", low_upload_queue_rate);

        if(highest_upload_queue_ceil && strlen(highest_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF5ULCeil", highest_upload_queue_ceil);
        if(high_upload_queue_ceil && strlen(high_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF2ULCeil", high_upload_queue_ceil);
        if(default_upload_queue_ceil && strlen(default_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF6ULCeil", default_upload_queue_ceil);
        if(low_upload_queue_ceil && strlen(low_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF1ULCeil", low_upload_queue_ceil);

        if(highest_download_queue_rate && strlen(highest_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF5DLRate", highest_download_queue_rate);
        if(high_download_queue_rate && strlen(high_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF2DLRate", high_download_queue_rate);
        if(default_download_queue_rate && strlen(default_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF6DLRate", default_download_queue_rate);
        if(low_download_queue_rate && strlen(low_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF1DLRate", low_download_queue_rate);

        if(highest_download_queue_ceil && strlen(highest_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF5DLCeil", highest_download_queue_ceil);
        if(high_download_queue_ceil && strlen(high_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF2DLCeil", high_download_queue_ceil);
        if(default_download_queue_ceil && strlen(default_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF6DLCeil", default_download_queue_ceil);
        if(low_download_queue_ceil && strlen(low_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF1DLCeil", low_download_queue_ceil);

    }

    //
    nvram_commit(RT2860_NVRAM);

    QoSRestart();

    websHeader(wp);

    websWrite(wp, T("qos_enable: %s<br>\n"), qos_enable);
    websWrite(wp, T("upload bandwidth: %s<br>\n"), upload_bandwidth);
    websWrite(wp, T("download bandwidth: %s<br>\n"), download_bandwidth);
    websFooter(wp);
    websDone(wp, 200);
}
Ejemplo n.º 17
0
static void qosClassifier(webs_t wp, char_t *path, char_t *query)
{
    char rule[8192];
    const char *old_rule;
    char tmp[8];

    char_t *dir, *af_index, *dp_index, *comment, *mac_address, *dip_address, *sip_address, *pktlenfrom, *pktlento,
           *protocol, *dprf, *dprt, *sprf, *sprt, *layer7, *dscp, *ingress_if, *remark ;
    int af_index_i, dp_index_i, sprf_int, dprf_int, sprt_int, dprt_int;

    dir = websGetVar(wp, T("dir"), T(""));
    af_index = websGetVar(wp, T("af_index"), T(""));
    dp_index = websGetVar(wp, T("dp_index"), T(""));
    comment = websGetVar(wp, T("comment"), T(""));
    mac_address = websGetVar(wp, T("mac_address"), T(""));
    dip_address = websGetVar(wp, T("dip_address"), T(""));
    sip_address = websGetVar(wp, T("sip_address"), T(""));
    pktlenfrom = websGetVar(wp, T("pktlenfrom"), T(""));
    pktlento = websGetVar(wp, T("pktlento"), T(""));
    protocol = websGetVar(wp, T("protocol"), T(""));
    dprf = websGetVar(wp, T("dFromPort"), T(""));
    dprt = websGetVar(wp, T("dToPort"), T(""));
    sprf = websGetVar(wp, T("sFromPort"), T(""));
    sprt = websGetVar(wp, T("sToPort"), T(""));
    layer7 = websGetVar(wp, T("layer7"), T(""));
    dscp = websGetVar(wp, T("dscp"), T(""));
    ingress_if = "";
    remark =  websGetVar(wp, T("remark_dscp"), T(""));

    if(!dir || !af_index || !dp_index || !comment || !remark)
        return;

    if(!strlen(dir) || !strlen(af_index) || !strlen(dp_index) || strlen(comment) > 32)
        return;

    // i know you will try to break our box... ;)
    if(strchr(comment, ';') || strchr(comment, ','))
        return;

    af_index_i = atoi(af_index);
    dp_index_i = atoi(dp_index);
    /*
    	if(qosGetIndexByName(af_index_i, dp_index_i, comment) != -1){
    		// This name is not unique.
    		// return;
    	}
    */
    // pkt len from/to must be co-exist.
    if( (!strlen(pktlenfrom) && strlen(pktlento)) ||
            (strlen(pktlenfrom) && !strlen(pktlento)) )
        return;

    if(!strlen(protocol)) {
        if(	!strlen(mac_address) && !strlen(sip_address) && !strlen(dip_address) &&
                !strlen(dscp) /*&& !strlen(ingress_if)*/ && !strlen(pktlenfrom) )
            return;
        layer7 = "";
    } else if(!strcmp(protocol, "TCP") || !strcmp(protocol, "UDP")) {
        if(!strlen(dprf) && !strlen(sprf))
            return;
        layer7 = "";
    } else if(!strcmp(protocol, "Application")) {
        if(!strlen(layer7))
            return;
    } else if(!strcmp(protocol, "ICMP")) {
        layer7 = "";	// do nothing.
    } else
        return;

    // we dont trust user input.....
    if(strlen(mac_address)) {
        if(!isMacValid(mac_address))
            return;
    }

    if(strlen(sip_address)) {
        if(!isIpNetmaskValid(sip_address))
            return;
    }

    if(strlen(dip_address)) {
        if(!isIpNetmaskValid(dip_address))
            return;
    }


    if(!strlen(sprf)) {
        sprf_int = 0;
    } else {
        sprf_int = atoi(sprf);
        if(sprf_int == 0 || sprf_int > 65535)
            return;
    }
    if(!strlen(sprt)) {
        sprt_int = 0;
    } else {
        sprt_int = atoi(sprt);
        if(sprt_int ==0 || sprt_int > 65535)
            return;
    }
    if(!strlen(dprf)) {
        dprf_int = 0;
    } else {
        dprf_int = atoi(dprf);
        if(dprf_int == 0 || dprf_int > 65535)
            return;
    }
    if(!strlen(dprt)) {
        dprt_int = 0;
    } else {
        dprt_int = atoi(dprt);
        if(dprt_int == 0 || dprt_int > 65535)
            return;
    }

    if(!strcmp(remark, "Auto")) {
        if(af_index_i == 5 && dp_index_i == 1) {				/* EF class */
            remark = "EF";
        } else if(af_index_i == 6 && dp_index_i == 1) {		/* BE class */
            remark = "BE";
        } else {                                 /* AF classes */
            snprintf(tmp, sizeof(tmp), "AF%d%d", af_index_i, dp_index_i);
            remark = tmp;
        }
    }

    if(!strcmp(dir, "Download"))
        old_rule = nvram_bufget(RT2860_NVRAM, "QoSDLRules");
    else
        old_rule = nvram_bufget(RT2860_NVRAM, "QoSULRules");

    if(!old_rule || !strlen(old_rule))
        snprintf(rule, sizeof(rule), "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", comment, af_index, dp_index, mac_address, protocol, dip_address, sip_address, pktlenfrom, pktlento, dprf, dprt, sprf, sprt, layer7, dscp, ingress_if, remark);
    else
        snprintf(rule, sizeof(rule), "%s;%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", old_rule, comment, af_index, dp_index, mac_address, protocol, dip_address, sip_address, pktlenfrom, pktlento, dprf, dprt, sprf, sprt, layer7, dscp, ingress_if, remark);

    if(!strcmp(dir, "Download"))
        nvram_bufset(RT2860_NVRAM, "QoSDLRules", rule);
    else
        nvram_bufset(RT2860_NVRAM, "QoSULRules", rule);
    nvram_commit(RT2860_NVRAM);

    QoSRestart();

//	websHeader(wp);
    websWrite(wp, T("HTTP/1.0 200 OK\n"));
    websWrite(wp, T("Server: %s\r\n"), WEBS_NAME);
    websWrite(wp, T("Pragma: no-cache\n"));
    websWrite(wp, T("Cache-control: no-cache\n"));
    websWrite(wp, T("Content-Type: text/html\n"));
    websWrite(wp, T("\n"));
    websWrite(wp, T("<html>\n<head>\n"));
    websWrite(wp, T("<title>My Title</title>"));
    websWrite(wp, T("<link rel=\"stylesheet\" href=\"/style/normal_ws.css\" type=\"text/css\">"));
    websWrite(wp, T("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"));
    websWrite(wp, T("</head>\n<body onload=\"opener.location.reload();window.close();\">\n"));

    websWrite(wp, T("name: %s<br>\n"), comment);
    websWrite(wp, T("dir: %s<br>\n"), dir);
    websWrite(wp, T("mac: %s<br>\n"), mac_address);
    websWrite(wp, T("ingress interface: %s<br>\n"), ingress_if);
    websWrite(wp, T("sip_address: %s<br>\n"), sip_address);
    websWrite(wp, T("sFromPort: %s<br>\n"), sprf);
    websWrite(wp, T("sToPort: %s<br>\n"), sprt);
    websWrite(wp, T("dip_address: %s<br>\n"), dip_address);
    websWrite(wp, T("dFromPort: %s<br>\n"), dprf);
    websWrite(wp, T("dToPort: %s<br>\n"), dprt);
    websWrite(wp, T("protocol: %s<br>\n"), protocol);
    websWrite(wp, T("application: %s<br>\n"), layer7);
    websWrite(wp, T("dscp: %s<br>\n"), dscp);
    websWrite(wp, T("remark: %s<br>\n"), remark);

    websFooter(wp);
    websDone(wp, 200);
}
Ejemplo n.º 18
0
static int setbuf_one_para(char* para)
{		
	//FILE* fp;
//	char*p,*p1;
	int ret;
	char str_tmp[256];



	
	
	if(para==NULL) return false;

	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,0,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_status",str_tmp);


	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,1,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_backtomain",str_tmp);


	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,2,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_first",str_tmp);


	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,3,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_second",str_tmp);


	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,4,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_checkcount",str_tmp);


	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,5,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_ping",str_tmp);


      memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,6,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_host",str_tmp);

	memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,7,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_wan2_ping",str_tmp);


      memset(str_tmp,0,sizeof(str_tmp));	
	if((ret=locate_para(para,8,',',str_tmp))==false){
		return false;
	}
	nvram_bufset(RT2860_NVRAM, "link_backup_wan2_host",str_tmp);



   return true;

   }
Ejemplo n.º 19
0
/* goform/storageFtpSrv */
static void storageFtpSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *ftp, *name, *anonymous, *port, *max_sessions;
	char_t *adddir, *rename, *remove, *read, *write, *download, *upload;

	// fetch from web input
	ftp = websGetVar(wp, T("ftp_enabled"), T("0"));
	name = websGetVar(wp, T("ftp_name"), T("0"));
	anonymous = websGetVar(wp, T("ftp_anonymous"), T("0"));
	port = websGetVar(wp, T("ftp_port"), T(""));
	max_sessions = websGetVar(wp, T("ftp_max_sessions"), T(""));
	adddir = websGetVar(wp, T("ftp_adddir"), T("0"));
	rename = websGetVar(wp, T("ftp_rename"), T("0"));
	remove = websGetVar(wp, T("ftp_remove"), T("0"));
	read = websGetVar(wp, T("ftp_read"), T("0"));
	write = websGetVar(wp, T("ftp_write"), T("0"));
	download = websGetVar(wp, T("ftp_download"), T("0"));
	upload = websGetVar(wp, T("ftp_upload"), T("0"));

	// set to nvram
	nvram_bufset(RT2860_NVRAM, "FtpEnabled", ftp);
	nvram_bufset(RT2860_NVRAM, "FtpName", name);
	nvram_bufset(RT2860_NVRAM, "FtpAnonymous", anonymous);
	nvram_bufset(RT2860_NVRAM, "FtpPort", port);
	nvram_bufset(RT2860_NVRAM, "FtpMaxSessions", max_sessions);
	nvram_bufset(RT2860_NVRAM, "FtpAddDir", adddir);
	nvram_bufset(RT2860_NVRAM, "FtpRename", rename);
	nvram_bufset(RT2860_NVRAM, "FtpRemove", remove);
	nvram_bufset(RT2860_NVRAM, "FtpRead", read);
	nvram_bufset(RT2860_NVRAM, "FtpWrite", write);
	nvram_bufset(RT2860_NVRAM, "FtpDownload", download);
	nvram_bufset(RT2860_NVRAM, "FtpUpload", upload);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("storage.sh ftp");

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>ftp_enabled: %s</h2><br>\n"), ftp);
	websWrite(wp, T("ftp_anonymous: %s<br>\n"), anonymous);
	websWrite(wp, T("ftp_name: %s<br>\n"), name);
	websWrite(wp, T("ftp_port: %s<br>\n"), port);
	websWrite(wp, T("ftp_max_sessions: %s<br>\n"), max_sessions);
	websWrite(wp, T("ftp_adddir: %s<br>\n"), adddir);
	websWrite(wp, T("ftp_rename: %s<br>\n"), rename);
	websWrite(wp, T("ftp_remove: %s<br>\n"), remove);
	websWrite(wp, T("ftp_read: %s<br>\n"), read);
	websWrite(wp, T("ftp_write: %s<br>\n"), write);
	websWrite(wp, T("ftp_download: %s<br>\n"), download);
	websWrite(wp, T("ftp_upload: %s<br>\n"), upload);
	websFooter(wp);
	websDone(wp, 200);
}
Ejemplo n.º 20
0
int executeCommad(int fd)
{
	int ret =-1;
	msg *pmsg;
	pmsg = (msg*)malloc(sizeof(msg));
	moduleNvram mNvram;
	char nvramStr[1024];
	char ifname[16];
	const char* valueStr;
	int ndev;
	int num;
	struct timeval tv;
	tv.tv_sec =1;
	tv.tv_usec=0;
	ret = recvData(fd, pmsg, &tv);
	if(ret!=sizeof(msg)){
		printf("read data error\n");
		close(fd);
		return -1;			
	}
	switch(pmsg->dataType){
		case SET_NVRAM:
			deb_print("SET_NVRAM\n");
			memcpy(&mNvram, pmsg->dataBuf, sizeof(moduleNvram));
			if(!strcmp(mNvram.nvramDev, "rtdev"))
				ndev = RTDEV_NVRAM;
			else
				ndev = RT2860_NVRAM;
			nvram_bufset(ndev, mNvram.item, mNvram.value);
			
			strcpy(pmsg->dataBuf,"Success");
			pmsg->dataSize = strlen(pmsg->dataBuf)+1;
			write(fd, pmsg, sizeof(msg));
			break;

		case SET_NVRAM_COMMIT:
			deb_print("SET_NVRAM_COMMIT\n");
			memcpy(&mNvram, pmsg->dataBuf, sizeof(moduleNvram));
			if(!strcmp(mNvram.nvramDev, "rtdev"))
				ndev = RTDEV_NVRAM;
			else
				ndev = RT2860_NVRAM;
			nvram_commit(ndev);
			strcpy(pmsg->dataBuf,"Success");
			pmsg->dataSize = strlen(pmsg->dataBuf)+1;
			write(fd, pmsg, sizeof(msg));			
			break;

		case GET_NVRAM:
			deb_print("GET_NVRAM\n");
			memcpy(&mNvram, pmsg->dataBuf, sizeof(moduleNvram));
			if(!strcmp(mNvram.nvramDev, "rtdev"))
				ndev = RTDEV_NVRAM;
			else
				ndev = RT2860_NVRAM;
			valueStr = nvram_bufget( ndev, mNvram.item);
			if(valueStr==NULL)
				strcpy(pmsg->dataBuf,"NULL");
			else
				strcpy(pmsg->dataBuf, valueStr);
			pmsg->dataSize = strlen(pmsg->dataBuf)+1;
			deb_print("return: %s\n",pmsg->dataBuf);
			write(fd, pmsg, sizeof(msg));
			break;

		case INIT_INTERNET:
			initInternet();
			break;

		case GET_MACLIST:
			memcpy(ifname, pmsg->dataBuf, pmsg->dataSize);
			sendMacList(fd, ifname);
			break;

		case GET_MACNUM:
			memcpy(ifname, pmsg->dataBuf, pmsg->dataSize);
			num = getOnlineMacNum(ifname);
			memcpy(pmsg->dataBuf, num, sizeof(num));
			pmsg->dataSize=sizeof(num);
			write(fd, pmsg, sizeof(msg));			
			break;

		case SET_STALIMIT:
			setStaLimit( *(int*)(pmsg->dataBuf));
			break;
		
		case SYSTEM_CMD:
			system(pmsg->dataBuf);
			printf("pmsg->dataBuf:%s\n", pmsg->dataBuf);
			break;

		default:
			break;
	}

	return 0;
}
Ejemplo n.º 21
0
int renew_nvram(int mode, char *fname)
{
	FILE *fp;
#define BUFSZ 1024
	unsigned char buf[BUFSZ], *p;
	unsigned char wan_mac[32];
	int found = 0, need_commit = 0;

	if (NULL == (fp = fopen(fname, "ro"))) {
		perror("fopen");
		return -1;
	}

	//find "Default" first
	while (NULL != fgets(buf, BUFSZ, fp)) {
		if (buf[0] == '\n' || buf[0] == '#')
			continue;
		if (!strncmp(buf, "Default\n", 8)) {
			found = 1;
			break;
		}
	}
	if (!found) {
		printf("file format error!\n");
		fclose(fp);
		return -1;
	}

	nvram_init(mode);
	while (NULL != fgets(buf, BUFSZ, fp)) {
		if (buf[0] == '\n' || buf[0] == '#')
			continue;
		if (NULL == (p = strchr(buf, '='))) {
			if (need_commit)
				nvram_commit(mode);
			printf("%s file format error!\n", fname);
			fclose(fp);
			return -1;
		}
		buf[strlen(buf) - 1] = '\0'; //remove carriage return
		*p++ = '\0'; //seperate the string
		//printf("bufset %d '%s'='%s'\n", mode, buf, p);
		nvram_bufset(mode, buf, p);
		need_commit = 1;
	}

	//Get wan port mac address, please refer to eeprom format doc
	//0x30000=user configure, 0x32000=rt2860 parameters, 0x40000=RF parameter
	flash_read_mac(buf);
	sprintf(wan_mac,"%0X:%0X:%0X:%0X:%0X:%0X\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
	nvram_bufset(RT2860_NVRAM, "WAN_MAC_ADDR", wan_mac);

	need_commit = 1;

	if (need_commit)
		nvram_commit(mode);

	nvram_close(mode);
	fclose(fp);
	return 0;
}