Example #1
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);
}
Example #2
0
void
// do_upgrade_cgi(char *url, FILE *stream)
do_upgrade_cgi(struct mime_handler *handler, char *url, webs_t streamm, char *query)	// jimmy,
								// https,
								// 8/6/2003
{
#ifndef ANTI_FLASH
	fprintf(stderr, "do post\n");
	if (upgrade_ret)
		do_ej(handler, "Fail_u_s.asp", stream, NULL);
	else
		do_ej(handler, "Success_u_s.asp", stream, NULL);
	fprintf(stderr, "websdone\n");

	websDone(stream, 200);
	fprintf(stderr, "reboot\n");

	/*
	 * Reboot if successful 
	 */
	if (upgrade_ret == 0) {
		sleep(5);
		sys_reboot();
	}
#else
	do_ej(handler, "Fail_u_s.asp", stream, NULL);
	websDone(stream, 200);
#endif
}
Example #3
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);
}
Example #4
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);
}
Example #5
0
/*
    Do output back to the browser in the background. This is a socket write handler.
    This bypasses the output buffer and writes directly to the socket.
 */
static void fileWriteEvent(Webs *wp)
{
    char    *buf;
    ssize   len, wrote;

    assert(wp);
    assert(websValid(wp));

    /*
        Note: websWriteSocket may return less than we wanted. It will return -1 on a socket error.
     */
    if ((buf = walloc(ME_GOAHEAD_LIMIT_BUFFER)) == NULL) {
        websError(wp, HTTP_CODE_INTERNAL_SERVER_ERROR, "Cannot get memory");
        return;
    }
    /*
        OPT - we could potentially save this buffer so that on short-writes, it does not need to be re-read.
     */
    while ((len = websPageReadData(wp, buf, ME_GOAHEAD_LIMIT_BUFFER)) > 0) {
        if ((wrote = websWriteSocket(wp, buf, len)) < 0) {
            break;
        }
        if (wrote != len) {
            websPageSeek(wp, - (len - wrote), SEEK_CUR);
            break;
        }
    }
    wfree(buf);
    if (len <= 0) {
        websDone(wp);
    }
}
Example #6
0
/*
    Dump the file upload details. Don't actually do anything with the uploaded file.
 */
static void uploadTest(Webs *wp, char *path, char *query)
{
    WebsKey         *s;
    WebsUpload  *up;
    char            *upfile;

    websSetStatus(wp, 200);
    websWriteHeaders(wp, -1, 0);
    websWriteHeader(wp, "Content-Type", "text/plain");
    websWriteEndHeaders(wp);
    if (scaselessmatch(wp->method, "POST")) {
        for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
            up = s->content.value.symbol;
            websWrite(wp, "FILE: %s\r\n", s->name.value.string);
            websWrite(wp, "FILENAME=%s\r\n", up->filename);
            websWrite(wp, "CLIENT=%s\r\n", up->clientFilename);
            websWrite(wp, "TYPE=%s\r\n", up->contentType);
            websWrite(wp, "SIZE=%d\r\n", up->size);
            upfile = sfmt("%s/tmp/%s", websGetDocuments(), up->clientFilename);
            rename(up->filename, upfile);
            wfree(upfile);
        }
        websWrite(wp, "\r\nVARS:\r\n");
        for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) {
            websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string);
        }
    }
    websDone(wp);
}
Example #7
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 );
}
Example #8
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);
}
Example #9
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);
}
Example #10
0
static void storageGetFirmwarePath(webs_t wp, char_t *path, char_t *query)
{
	websWrite(wp, T("HTTP/1.1 200 OK\nContent-type: text/plain\nPragma: no-cache\nCache-Control: no-cache\n\n"));

	websWrite(wp, "%s", firmware_path);
	websDone(wp, 200);
}
Example #11
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);
}
Example #12
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);
}
Example #13
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);
}
Example #14
0
// for test
void show_default_info(webs_t wp)
{
	// int ret=0;

	websDone(wp, 200);	// Let header in first packet, and bellow
	// information in second packet.

	websWrite(wp, "Vendor:%s\n", VENDOR);
	websWrite(wp, "ModelName:%s\n", MODEL_NAME);

	websWrite(wp, "Firmware Version:%s%s , %s\n", CYBERTAN_VERSION, MINOR_VERSION, __DATE__);
	websWrite(wp, "#:%s\n", SERIAL_NUMBER);
	websWrite(wp, "Boot Version:%s\n", nvram_safe_get("boot_ver"));
	/*
	 * begin Svbeasoft modifications 
	 */
	// ret = websWrite(wp, "CodePattern:%s\n", CODE_PATTERN);
	// #if LOCALE == EUROPE
	// ret = websWrite(wp, "Country:Europe\n");
	// #elif LOCALE == JAPAN
	// ret = websWrite(wp, "Country:Japan\n");
	// #else
	// ret = websWrite(wp, "Country:US\n");
	// #endif
	// ret = websWrite(wp, "\n");

	websWrite(wp, "RF Status:%s\n", (nvram_match("wl0_hwaddr", "")
					 || nvram_match("wl_gmode", "-1")) ? "disabled" : "enabled");

	websWrite(wp, "RF Firmware Version:%s%s\n", CYBERTAN_VERSION, MINOR_VERSION);
	// #if LOCALE == EUROPE
	// ret = websWrite(wp, "RF Domain:ETSI (channel 1~%s)\n",
	// WL_MAX_CHANNEL);
	// #elif LOCALE == JAPAN
	// ret = websWrite(wp, "RF Domain:JPN (channel 1~%s)\n", WL_MAX_CHANNEL);
	// #else
	// ret = websWrite(wp, "RF Domain:US (channel 1~%s)\n", WL_MAX_CHANNEL);
	// #endif

	websWrite(wp, "RF Domain:Worldwide (channel 1~%s)\n", WL_MAX_CHANNEL);
	websWrite(wp, "RF Channel:%s\n", nvram_safe_get("wl0_channel"));
	websWrite(wp, "RF SSID:%s\n", nvram_safe_get("wl0_ssid"));

	websWrite(wp, "\n-----Dynamic Information\n");

	websWrite(wp, "RF Mac Address:%s\n", nvram_safe_get("wl0_hwaddr"));
	websWrite(wp, "LAN Mac Address:%s\n", nvram_safe_get("lan_hwaddr"));
	websWrite(wp, "WAN Mac Address:%s\n", nvram_safe_get("wan_hwaddr"));
	if (check_hw_type() == BCM4702_CHIP)
		websWrite(wp, "Hardware Version:1.x\n");
	else
		websWrite(wp, "Hardware Version:2.0\n");

	websWrite(wp, "Device Serial No.:%s\n", nvram_safe_get("get_sn"));

	websWrite(wp, "\n");	// The last char must be '\n'

	return;
}
Example #15
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);
	}
}
Example #16
0
PUBLIC int process_web_write_response(Webs *wp, int code, char *buf, int size){
	/* need route the code num in the future */
	websSetStatus(wp, code);
	websWriteHeaders(wp, -1, 0);
	websWriteEndHeaders(wp);
	/* need check the size  */
	websWrite(wp, buf);
	websDone(wp);
}
Example #17
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);
	}
}
Example #18
0
/*
    Any entry in the cgiList need to be checked to see if it has completed, and if so, process its output and clean up.
    Return time till next poll.
 */
WebsTime websCgiPoll()
{
    Webs    *wp;
    Cgi     *cgip;
    char    **ep;
    int     cid, nTries;

    for (cid = 0; cid < cgiMax; cid++) {
        if ((cgip = cgiList[cid]) != NULL) {
            wp = cgip->wp;
            websCgiGatherOutput(cgip);
            if (checkCgi(cgip->handle) == 0) {
                /*
                    We get here if the CGI process has terminated. Clean up.
                 */
                for (nTries = 0; (cgip->fplacemark == 0) && (nTries < 100); nTries++) {
                    websCgiGatherOutput(cgip);
                    /*                  
                         There are some cases when we detect app exit before the file is ready. 
                     */
                    if (cgip->fplacemark == 0) {
#if WINDOWS
                        Sleep(10);
#endif
                    }
                }
                if (cgip->fplacemark == 0) {
                    websError(wp, HTTP_CODE_INTERNAL_SERVER_ERROR, "CGI generated no output");
                } else {
                    trace(5, "cgi: Request complete - calling websDone");
                    websDone(wp);
                }
                /*
                    Remove the temporary re-direction files
                 */
                unlink(cgip->stdIn);
                unlink(cgip->stdOut);
                /*
                    Free all the memory buffers pointed to by cgip. The stdin file name (wp->cgiStdin) gets freed as
                    part of websFree().
                 */
                cgiMax = wfreeHandle(&cgiList, cid);
                for (ep = cgip->envp; ep != NULL && *ep != NULL; ep++) {
                    wfree(*ep);
                }
                wfree(cgip->cgiPath);
                wfree(cgip->argp);
                wfree(cgip->envp);
                wfree(cgip->stdOut);
                wfree(cgip);
                websPump(wp);
            }
        }
    }
    return cgiMax ? 10 : MAXINT;
}
Example #19
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 );
}
Example #20
0
/*
    Legacy handler with old parameter sequence
 */
static int legacyTest(Webs *wp, char *prefix, char *dir, int flags)
{
    websSetStatus(wp, 200);
    websWriteHeaders(wp, -1, 0);
    websWriteHeader(wp, "Content-Type", "text/plain");
    websWriteEndHeaders(wp);
    websWrite(wp, "Hello Legacy World\n");
    websDone(wp);
    return 1;
}
Example #21
0
static void websDefaultWriteEvent(webs_t wp)
{
	int		len, wrote, flags, bytes, written;
	char	*buf;

	a_assert(websValid(wp));

	flags = websGetRequestFlags(wp);

	websSetTimeMark(wp);

	wrote = bytes = 0;
	written = websGetRequestWritten(wp);

/*
 *	We only do this for non-ASP documents
 */
	if ( !(flags & WEBS_ASP)) {
		bytes = websGetRequestBytes(wp);
/*
 *		Note: websWriteDataNonBlock may return less than we wanted. It will
 *		return -1 on a socket error
 */
		if ((buf = balloc(B_L, PAGE_READ_BUFSIZE)) == NULL) {
			websError(wp, 200, T("Can't get memory"));
		} else {
			while ((len = websPageReadData(wp, buf, PAGE_READ_BUFSIZE)) > 0) {
				if ((wrote = websWriteDataNonBlock(wp, buf, len)) < 0) {
					break;
				}
				written += wrote;
				if (wrote != len) {
					websPageSeek(wp, - (len - wrote));
					break;
				}
			}
/*
 *			Safety. If we are at EOF, we must be done
 */
			if (len == 0) {
				a_assert(written >= bytes);
				written = bytes;
			}
			bfree(B_L, buf);
		}
	}

/*
 *	We're done if an error, or all bytes output
 */
	websSetRequestWritten(wp, written);
	if (wrote < 0 || written >= bytes) {
		websDone(wp, 200);
	}
}
Example #22
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);
}
Example #23
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);
}
Example #24
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);
}
Example #25
0
static void showTest(Webs *wp, char *path, char *query)
{
    WebsKey     *s;

    websSetStatus(wp, 200);
    websWriteHeaders(wp, -1, 0);
    websWriteEndHeaders(wp);
    websWrite(wp, "<html><body><pre>\n");
    for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) {
        websWrite(wp, "%s=%s\n", s->name.value.string, s->content.value.string);
    }
    websWrite(wp, "</pre></body></html>\n");
    websDone(wp);
}
Example #26
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);
}
Example #27
0
/*
    Generate a large response
 */
static int bigTest(int eid, Webs *wp, int argc, char **argv)
{
    int     i;

    websSetStatus(wp, 200);
    websWriteHeaders(wp, -1, 0);
    websWriteEndHeaders(wp);
    websWrite(wp, "<html>\n");
    for (i = 0; i < 800; i++) {
        websWrite(wp, " Line: %05d %s", i, "aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccccddddddd<br/>\r\n");
    }
    websWrite(wp, "</html>\n");
    websDone(wp);
    return 0;
}
Example #28
0
static void sessionTest(Webs *wp, char *path, char *query)
{
	char	*number;

    if (scaselessmatch(wp->method, "POST")) {
        number = websGetVar(wp, "number", 0);
        websSetSessionVar(wp, "number", number);
    } else {
        number = websGetSessionVar(wp, "number", 0);
    }
    websSetStatus(wp, 200);
    websWriteHeaders(wp, -1, 0);
    websWriteEndHeaders(wp);
    websWrite(wp, "<html><body><p>Number %s</p></body></html>\n", number);
    websDone(wp);
}
Example #29
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);
	}
}
Example #30
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);
}