Esempio n. 1
0
static void formDisplayUser(webs_t wp, char_t *path, char_t *query)
{
	char_t	*userid, *ok, *temp;
	bool_t	enabled;

	a_assert(wp);

	userid = websGetVar(wp, T("user"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websWrite(wp, T("<body>"));

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Display User Cancelled"));
	} else if (umUserExists(userid) == FALSE) {
		websWrite(wp, T("ERROR: User <b>%s</b> not found.\n"), userid);
	} else {
		websWrite(wp, T("<h2>User ID: <b>%s</b></h2>\n"), userid);
		temp = umGetUserGroup(userid);
		websWrite(wp, T("<h3>User Group: <b>%s</b></h3>\n"), temp);
		enabled = umGetUserEnabled(userid);
		websWrite(wp, T("<h3>Enabled: <b>%d</b></h3>\n"), enabled);
	}

	websWrite(wp, T("</body>\n"));
	websFooter(wp);
	websDone(wp, 200);
}
Esempio n. 2
0
static void formDeleteGroup(webs_t wp, char_t *path, char_t *query)
{
	char_t	*group, *ok;

	a_assert(wp);

	group = websGetVar(wp, T("group"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Delete Group Cancelled."));
	} else if ((group == NULL) || (*group == '\0')) {
		websWrite(wp, T("ERROR: No group was selected."));
	} else if (umGetGroupProtected(group)) {
		websWrite(wp, T("ERROR: Group, \"%s\" is delete-protected."), group);
	} else if (umGetGroupInUse(group)) {
		websWrite(wp, T("ERROR: Group, \"%s\" is being used."),	group);
	} else if (umDeleteGroup(group) != 0) {
		websWrite(wp, T("ERROR: Unable to delete group, \"%s\" "), group);
	} else {
		websWrite(wp, T("Group, \"%s\" was successfully deleted."), group);
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Esempio n. 3
0
static void storageDiskPart(webs_t wp, char_t *path, char_t *query)
{
	char_t *part1_vol, *part2_vol, *part3_vol;
	int max_part = atoi(websGetVar(wp, T("max_part"), T("")));
	FILE *fp = NULL;
	char part[30];

	if (NULL == (fp = fopen("/proc/mounts", "r")))
	{
		perror(__FUNCTION__);
		return;
	}
	while(EOF != fscanf(fp, "%s %*s %*s %*s %*s %*s\n", part))
	{
		if (NULL != strstr(part, "/dev/sd") || NULL != strstr(part, "/dev/mmc"))
			doSystem("umount -l %s", part);
	}
	fclose(fp);
	part1_vol = websGetVar(wp, T("part1_vol"), T(""));
	part2_vol = websGetVar(wp, T("part2_vol"), T(""));
	part3_vol = websGetVar(wp, T("part3_vol"), T(""));
	doSystem("storage.sh reparted %s %s %s %d", 
			  part1_vol, part2_vol, part3_vol, max_part);
	sleep(50);
	memset(part, 0, 30);
	do {
		sprintf(part, "/dev/sda%d", max_part+4);
		FormatPart(part, "");
		sleep(5);
	} while (max_part--);
	doSystem("storage.sh restart");
	sleep(5);
	websRedirect(wp, "usb/STORAGEdisk_admin.asp");
}
Esempio n. 4
0
static void formDeleteUser(webs_t wp, char_t *path, char_t *query)
{
	char_t	*userid, *ok;

	a_assert(wp);

	userid = websGetVar(wp, T("user"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Delete User Cancelled"));
	} else if (umUserExists(userid) == FALSE) {
		websWrite(wp, T("ERROR: User \"%s\" not found"), userid);
	} else if (umGetUserProtected(userid)) {
		websWrite(wp, T("ERROR: User, \"%s\" is delete-protected."), userid);
	} else if (umDeleteUser(userid) != 0) {
		websWrite(wp, T("ERROR: Unable to delete user, \"%s\" "), userid);
	} else {
		websWrite(wp, T("User, \"%s\" was successfully deleted."), userid);
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Esempio n. 5
0
PRIVATE int process_bus_config_sta_status_req(Webs *wp){
	char *seq, *status, *act;
	act = websGetVar(wp, "act", "");
	int ret = RET_OK;
	char sta_buff[2048];
	if(strcmp(act, "set") == 0){
		seq = websGetVar(wp, "seq", "");
		status = websGetVar(wp, "status", "");
		ret = set_bus_config_bus_driving_data(atoi(seq), atoi(status));
		if(ret == RET_OK){
			process_web_write_response(wp, HTTP_CODE_OK, "ok" , 0);
		}else{
			process_web_write_response(wp, HTTP_CODE_OK, "error" , 0);
		}
		
	}else if(strcmp(act, "get") == 0){
		
		memset(sta_buff, 0, sizeof(sta_buff));
		ret = get_bus_config_bus_driving_data(sta_buff, 2048);
		if( (strlen(sta_buff) < 2) || (ret !=RET_OK)){
			process_web_write_response(wp, HTTP_CODE_OK, "[]" , 0);
		}else{
			process_web_write_response(wp, HTTP_CODE_OK, sta_buff , 0);
		}
	}else{
		process_web_write_response(wp, HTTP_CODE_OK, "param error" , 0);
	}
}
Esempio n. 6
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");
}
Esempio n. 7
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);
}
Esempio n. 8
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");
}
Esempio n. 9
0
/*
    Internal login service routine for Form-based auth
 */
static void loginServiceProc(Webs *wp)
{
    WebsRoute   *route;

    assert(wp);
    route = wp->route;
    assert(route);
    
    if (websLoginUser(wp, websGetVar(wp, "username", ""), websGetVar(wp, "password", ""))) {
        /* If the application defines a referrer session var, redirect to that */
        char *referrer;
        if ((referrer = websGetSessionVar(wp, "referrer", 0)) != 0) {
            websRedirect(wp, referrer);
        } else {
            websRedirectByStatus(wp, HTTP_CODE_OK);
        }
        websSetSessionVar(wp, "loginStatus", "ok");
    } else {
        if (route->askLogin) {
            (route->askLogin)(wp);
        }
        websSetSessionVar(wp, "loginStatus", "failed");
        websRedirectByStatus(wp, HTTP_CODE_UNAUTHORIZED);
    }
}
Esempio n. 10
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);
}
Esempio n. 11
0
PRIVATE int process_bus_config_cur_line_req(Webs *wp){
	char *line_name,*line_direction,*act;
	act = websGetVar(wp, "act", "");
	int ret = RET_OK;
	if(strcmp(act, "set") == 0){
		line_name = websGetVar(wp, "line_name", "");
		line_direction = websGetVar(wp, "line_direction", "");
		ret = set_bus_config_bus_num(line_name);
		ret = set_bus_config_bus_derection( atoi(line_direction) );
		ret = update_bus_config_bus_cur_line_info();
		if(ret == RET_OK){
			process_web_write_response(wp, HTTP_CODE_OK, "ok" , 0);
		}else{
			process_web_write_response(wp, HTTP_CODE_OK, "error" , 0);
		}
		
	}else if(strcmp(act, "get") == 0){
		if(strlen(bus_cur_line_info) < 10){
			process_web_write_response(wp, HTTP_CODE_OK, "[]" , 0);
		}else{
			process_web_write_response(wp, HTTP_CODE_OK, bus_cur_line_info , 0);
		}
		
	}else{
		process_web_write_response(wp, HTTP_CODE_OK, "param error" , 0);
	}
}
Esempio n. 12
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);
}
Esempio n. 13
0
static void formDeleteAccessLimit(webs_t wp, char_t *path, char_t *query)
{
	char_t	*url, *ok;

	a_assert(wp);

	url = websGetVar(wp, T("url"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Delete Access Limit Cancelled"));
	} else if (umDeleteAccessLimit(url) != 0) {
		websWrite(wp, T("ERROR: Unable to delete Access Limit for [%s]"), 
			url);
	} else {
		websWrite(wp, T("Access Limit for [%s], was successfully deleted."), 
			url);
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Esempio n. 14
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);
	}
}
Esempio n. 15
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);
	}
}
Esempio n. 16
0
static void formTest( webs_t wp, char_t* path, char_t* query )
{
    char_t*	name, *address;
    name = websGetVar( wp, T( "name" ), T( "Joe Smith" ) );
    address = websGetVar( wp, T( "address" ), T( "1212 Milky Way Ave." ) );
    websHeader( wp );
    websWrite( wp, T( "<body><h2>Name: %s, Address: %s</h2>\n" ), name, address );
    websFooter( wp );
    websDone( wp, 200 );
}
Esempio n. 17
0
/*
    Implement /action/actionTest. Parse the form variables: name, address and echo back.
 */
static void actionTest(Webs *wp, char *path, char *query)
{
	char	*name, *address;

	name = websGetVar(wp, "name", NULL);
	address = websGetVar(wp, "address", NULL);
    websSetStatus(wp, 200);
    websWriteHeaders(wp, -1, 0);
    websWriteEndHeaders(wp);
	websWrite(wp, "<html><body><h2>name: %s, address: %s</h2></body></html>\n", name, address);
	websDone(wp);
}
Esempio n. 18
0
static void formAddAccessLimit(webs_t wp, char_t *path, char_t *query)
{
	char_t			*url, *method, *group, *secure, *ok;
	int				nCheck;
	accessMeth_t	am;
	short			nSecure;

	a_assert(wp);

	url = websGetVar(wp, T("url"), T("")); 
	group = websGetVar(wp, T("group"), T("")); 
	method = websGetVar(wp, T("method"), T("")); 
	secure = websGetVar(wp, T("secure"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Add Access Limit Cancelled."));
	} else if ((url == NULL) || (*url == 0)) {
		websWrite(wp, T("ERROR:  No URL was entered."));
	} else if (umAccessLimitExists(url)) {
		websWrite(wp, T("ERROR:  An Access Limit for [%s] already exists."),
			url);
	} else {
		if (method && *method) {
			am = (accessMeth_t) gatoi(method);
		} else {
			am = AM_FULL;
		}

		if (secure && *secure) {
			nSecure = (short) gatoi(secure);
		} else {
			nSecure = 0;
		}

		nCheck = umAddAccessLimit(url, am, nSecure, group);
		if (nCheck != 0) {
			websWrite(wp, T("Unable to add Access Limit for [%s]"),	url);
		} else {
			websWrite(wp, T("Access limit for [%s], was successfully added."),
				url);
		}
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Esempio n. 19
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);
}
Esempio n. 20
0
static void QoSDeleteRules(webs_t wp, char_t *path, char_t *query, char *which_rule)
{
    int i, j, rule_count;
    char_t name_buf[16];
    char_t *value;
    int *deleArray;

    char *new_rules;
    const char *rules = nvram_bufget(RT2860_NVRAM, which_rule);
    if(!rules || !strlen(rules) )
        return;

    rule_count = getRuleNums(rules);
    if(!rule_count)
        return;

    deleArray = (int *)malloc(rule_count * sizeof(int));
    if(!deleArray)
        return;

    new_rules = strdup(rules);
    if(!new_rules) {
        free(deleArray);
        return;
    }

    for(i=0, j=0; i< rule_count; i++) {
        snprintf(name_buf, 16, "del_qos_%d", i);
        value = websGetVar(wp, name_buf, NULL);
        if(value) {
            deleArray[j++] = i;
        }
    }
    if(!j) {
        free(deleArray);
        free(new_rules);
        websHeader(wp);
        websWrite(wp, T("You didn't select any rules to delete.<br>\n"));
        websFooter(wp);
        websDone(wp, 200);
        return;
    }

    deleteNthValueMulti(deleArray, j, new_rules, ';');

    nvram_set(RT2860_NVRAM, which_rule, new_rules);
    nvram_commit(RT2860_NVRAM);

    QoSRestart();

    websHeader(wp);
    websWrite(wp, T("Delete Rules:\n") );
    for(i=0; i<j; i++)
        websWrite(wp, "%d ", (deleArray[i] + 1) );

    websFooter(wp);
    websDone(wp, 200);
    free(deleArray);
    free(new_rules);
}
Esempio n. 21
0
static void formLoadUserManagement( webs_t wp, char_t* path, char_t* query )
{
    char_t*	ok;
    a_assert( wp );
    ok = websGetVar( wp, T( "ok" ), T( "" ) );
    websHeader( wp );
    websMsgStart( wp );

    if ( gstricmp( ok, T( "ok" ) ) != 0 )
    {
        websWrite( wp, T( "Load Cancelled." ) );
    }

    else if ( umRestore( NULL ) != 0 )
    {
        websWrite( wp, T( "ERROR: Unable to load user configuration." ) );
    }

    else
    {
        websWrite( wp, T( "User configuration was re-loaded successfully." ) );
    }

    websMsgEnd( wp );
    websFooter( wp );
    websDone( wp, 200 );
}
Esempio n. 22
0
File: music.c Progetto: aircross/ray
int
save_music(webs_t wp, char *value, struct variable *v, struct service *s)
{
    char buf[LONG_BUF_LEN], tmp[LONG_BUF_LEN];
    char *enable;
    int change = 0;
    int64_t map = 0;

    /* Enable */
    snprintf(tmp, sizeof(tmp), "music_enable");
    enable = websGetVar(wp, tmp, "");

    /* save music_rule */
    ezplib_get_rule("music_rule", 0, tmp, sizeof(tmp));
    snprintf(buf, sizeof(buf), "%s",
            enable);

    if (strcmp(buf, tmp)) {
        config_preaction(&map, v, s, "", ""); 
        ezplib_replace_rule("music_rule", 0, buf);
        ezplib_replace_rule("bw_enable", 0, buf);
        config_postaction(map, s, "", "");
        change = 1;
    }

    return change;
}
Esempio n. 23
0
char_t *websCalcDigest(webs_t wp)
{
#ifdef DIGEST_ACCESS_SUPPORT
	char_t	*digest, *a1, *a1prime, *a2, *a2prime, *preDigest, *method;

	a_assert(wp);
	digest = NULL;

/*
 *	Calculate first portion of digest H(A1)
 */
	a1 = NULL;
	fmtAlloc(&a1, 255, T("%s:%s:%s"), wp->userName, wp->realm, wp->password);
	a_assert(a1);
	a1prime = websMD5(a1);
	bfreeSafe(B_L, a1);
/*
 *	Calculate second portion of digest H(A2)
 */
	method = websGetVar(wp, T("REQUEST_METHOD"), NULL);
	a_assert(method);
	a2 = NULL;
	fmtAlloc(&a2, 255, T("%s:%s"), method, wp->uri);
	a_assert(a2);
	a2prime = websMD5(a2);
	bfreeSafe(B_L, a2);
/*
 *	Construct final digest KD(H(A1):nonce:H(A2))
 */
	a_assert(a1prime);
	a_assert(a2prime);
	a_assert(wp->nonce);

	preDigest = NULL;
	if (!wp->qop) {
		fmtAlloc(&preDigest, 255, T("%s:%s:%s"), a1prime, wp->nonce, a2prime);
	} else {
		fmtAlloc(&preDigest, 255, T("%s:%s:%s:%s:%s:%s"), 
			a1prime, 
			wp->nonce,
			wp->nc,
			wp->cnonce,
			wp->qop,
			a2prime);
	}

	a_assert(preDigest);
	digest = websMD5(preDigest);
/*
 *	Now clean up
 */
	bfreeSafe(B_L, a1prime);
	bfreeSafe(B_L, a2prime);
	bfreeSafe(B_L, preDigest);
	return digest;
#else
	return NULL;
#endif /* DIGEST_ACCESS_SUPPORT */
}
Esempio n. 24
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);
	}
}
Esempio n. 25
0
char_t *websCalcUrlDigest(webs_t wp)
{
	char_t	*digest, *a1, *a1prime, *a2, *a2prime, *preDigest, *method;

	a_assert(wp);
	digest = NULL;

/*
 *	Calculate first portion of digest H(A1)
 */
	a1 = NULL;
	fmtAlloc(&a1, 255, T("%s:%s:%s"), wp->userName, wp->realm, wp->password);
	a_assert(a1);
	a1prime = websMD5(a1);
	bfreeSafe(B_L, a1);
/*
 *	Calculate second portion of digest H(A2)
 */
	method = websGetVar(wp, T("REQUEST_METHOD"), NULL);
	a_assert(method);
	/* Fixes by Richard Laing, 2003/7/15 */
	a2 = balloc(B_L, (gstrlen(method) +2 + gstrlen(wp->url) ) * sizeof(char_t));
	a_assert(a2);
	gsprintf(a2, T("%s:%s"), method, wp->url);
	a2prime = websMD5(a2);
	bfreeSafe(B_L, a2);
/*
 *	Construct final digest KD(H(A1):nonce:H(A2))
 */
	a_assert(a1prime);
	a_assert(a2prime);
	a_assert(wp->nonce);

	preDigest = NULL;
	if (!wp->qop) {
		fmtAlloc(&preDigest, 255, T("%s:%s:%s"), a1prime, wp->nonce, a2prime);
	} else {
		fmtAlloc(&preDigest, 255, T("%s:%s:%s:%s:%s:%s"), 
			a1prime, 
			wp->nonce,
			wp->nc,
			wp->cnonce,
			wp->qop,
			a2prime);
	}

	a_assert(preDigest);
	digest = websMD5(preDigest);
/*
 *	Now clean up
 */
	bfreeSafe(B_L, a1prime);
	bfreeSafe(B_L, a2prime);
	bfreeSafe(B_L, preDigest);
	return digest;
}
Esempio n. 26
0
File: diag.c Progetto: aircross/ray
int
diag_ping_start(webs_t wp)
{
    int ret = 0;
    char *ip = websGetVar(wp, "ping_ip", NULL);
    char *times = websGetVar(wp, "ping_times", NULL);

    if (!ip || !times || !strcmp(ip, ""))
        return ret;

    if (strcmp(times, "0") && strcmp(times, "5") && strcmp(times, "10")) {
        return ret;
    }

    unlink(PING_TMP);
    nvram_set("ping_ip", ip);
    nvram_set("ping_times", times);

    return ret;
}
Esempio n. 27
0
File: diag.c Progetto: ebichu/dd-wrt
void ping_onload(webs_t wp, char *arg)
{
	int pid;
	char *type = websGetVar(wp, "submit_type", "");

	pid = find_pid_by_ps("ping");

	if (pid > 0 && strncmp(type, "stop", 4)) {	// pinging
		websWrite(wp, arg);
	}

}
Esempio n. 28
0
static void MediaDirAdd(webs_t wp, char_t *path, char_t *query)
{
	char_t *dir_path;
	FILE *fp;
	char media_config_file[25];
	int index = 0;

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

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

	// fetch from web input
	dir_path = websGetVar(wp, T("dir_path"), T(""));
	/*
	DEBUG(dir_path);
	*/
	while (4 > index)
	{
		if (0 == strcmp(dir_path, media_conf[index].path))
		{
			fprintf(stderr, "Existed Media Shared Dir: %s\n", dir_path);
			fwrite(media_conf, sizeof(media_conf), 1, fp);
			fclose(fp);
			return;
		}
		index++;
	}
	index = 0;
	while (4 > index)
	{
		if (0 == strlen(media_conf[index].path))
		{
			strcpy(media_conf[index].path, dir_path);
			break;
		}
		index++;
	}
	if (index == 5)
	{
		perror("Media Server Shared Dirs exceed 4");
		fclose(fp);
		return;
	}
	fwrite(media_conf, sizeof(media_conf), 1, fp);
	fclose(fp);
}
Esempio n. 29
0
File: diag.c Progetto: aircross/ray
int
diag_traceroute_start(webs_t wp)
{
    int ret = 0;
    char *ip = websGetVar(wp, "traceroute_ip", NULL);

    if (!ip || !strcmp(ip, ""))
        return ret;

    unlink(TRACEROUTE_TMP);
    nvram_set("traceroute_ip", ip);

    return ret;
}
Esempio n. 30
0
PUBLIC void action_bus_config_process(Webs *wp, char *path, char *query){
	char *rq_type;
	int ret = 0;
	rq_type = websGetVar(wp, "rq_type", "");
      
	if(strcmp(rq_type, BUS_CONFIG_CUR_LINE) == 0){
		ret = process_bus_config_cur_line_req(wp);
	}else if(strcmp(rq_type, BUS_CONFIG_STA_STATUS) == 0) {
		ret = process_bus_config_sta_status_req(wp);
	}else{
		process_web_write_response(wp, HTTP_CODE_OK, "no param" , 0);
	}
	
}