コード例 #1
0
ファイル: auth.c プロジェクト: Liu1992/GasSub_LPC1788
/*
    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);
    }
}
コード例 #2
0
ファイル: qos.c プロジェクト: qwerty1023/wive-rtnl-firmware
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);
}
コード例 #3
0
ファイル: webmain.c プロジェクト: SayCV/rtems-missing_cpukit
static int websHomePageHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,
	int arg, char_t* url, char_t* path, char_t* query)
{
/*
 *	If the empty or "/" URL is invoked, redirect default URLs to the home page
 */
	if (*url == '\0' || gstrcmp(url, T("/")) == 0) {
#if 0
		websRedirect(wp, T("home.asp"));
#else
		websRedirect(wp, T("index.html"));
#endif
		return 1;
	}
	return 0;
}
コード例 #4
0
ファイル: usb.c プロジェクト: houzhenggang/MT
/* 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");
}
コード例 #5
0
ファイル: usb.c プロジェクト: houzhenggang/MT
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");
}
コード例 #6
0
ファイル: usb.c プロジェクト: houzhenggang/MT
/* 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");
}
コード例 #7
0
ファイル: usb.c プロジェクト: houzhenggang/MT
/* 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);
	}
}
コード例 #8
0
ファイル: usb.c プロジェクト: houzhenggang/MT
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);
	}
}
コード例 #9
0
ファイル: main.c プロジェクト: LIUSHILI/Graduationceremony
static int websHomePageHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,
	int arg, char_t *url, char_t *path, char_t *query)
{
/*
 *	If the empty or "/" URL is invoked, redirect default URLs to the home page
 */
	if (*url == '\0' || gstrcmp(url, T("/")) == 0) {
		websRedirect(wp, WEBS_DEFAULT_HOME);
		return 1;
	}
	return 0;
}
コード例 #10
0
static int websHomePageHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,
                               int arg, char_t *url, char_t *path, char_t *query)
{
    /*
     *	If the empty or "/" URL is invoked, redirect default URLs to the home page
     */
    if (*url == '\0' || gstrcmp(url, T("/")) == 0) {
        websRedirect(wp, T("/index.html"));
		//websRedirect(wp, T("cgi-bin/home.exe"));
        return 1;
    }
    return 0;
}
コード例 #11
0
ファイル: main.c プロジェクト: 18959263172/httpserver
static int websHomePageHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,
	int arg, char_t *url, char_t *path, char_t *query)
{
 //   fprintf(stderr, "prefix(%s),webDir(%s),url(%s), path(%s), query(%s)\n",
 //           urlPrefix,webDir,url,path,query);
 //   fprintf(stderr, "Default Home(%s)\n", WEBS_DEFAULT_HOME);
/*
 *	If the empty or "/" URL is invoked, redirect default URLs to the home page
 */
	if (*url == '\0' || gstrcmp(url, T("/")) == 0) {
		websRedirect(wp, WEBS_DEFAULT_HOME);
		return 1;
	}
	return 0;
}
コード例 #12
0
ファイル: usb.c プロジェクト: houzhenggang/MT
/* 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);
	}
}
コード例 #13
0
ファイル: default.c プロジェクト: morrisxd/PMC
int websDefaultHandler(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg,
						char_t *url, char_t *path, char_t *query)
{
	websStatType	sbuf;
	char_t			*lpath, *tmp, *date;
	int				bytes, flags, nchars, rc;

	a_assert(websValid(wp));
	a_assert(url && *url);
	a_assert(path);
	a_assert(query);

	flags = websGetRequestFlags(wp);
/*
 *	We do whitelist validation in addition to standard URL validation.
 *	The whitelist should really catch anything invalid first.
 *	If the whitelist check fails, rebuild the list and try again.
 *	Also validate if we are not on a secure connection, but the whitelist
 *	entry has the SSL flag set, do not serve the page.
 */
#ifdef WEBS_WHITELIST_SUPPORT
printf ("wp->url: (%s)\n", wp->url);
	if ((rc = websWhitelistCheck(wp->url)) < 0) {
		websBuildWhitelist();
		if ((rc = websWhitelistCheck(wp->url)) < 0) {
			websError(wp, 404, T("Cannot open URL: type 1"));
			return 1;
		}
	}
	if (!(flags & WEBS_SECURE) && (rc & WHITELIST_SSL)) {
		websError(wp, 500, T("HTTPS access required"));
		return 1;
	}
#endif /* WEBS_WHITELIST_SUPPORT */
/*
 *	Validate the URL and ensure that ".."s don't give access to unwanted files
 */
	if (websValidateUrl(wp, path) < 0) {
      /* 
       * preventing a cross-site scripting exploit -- you may restore the
       * following line of code to revert to the original behavior...
		websError(wp, 500, T("Invalid URL %s"), url);
       */
		websError(wp, 500, T("Invalid URL"));
		websBuildWhitelist();
		return 1;
	}
	lpath = websGetRequestLpath(wp);
	nchars = gstrlen(lpath) - 1;
	if (lpath[nchars] == '/' || lpath[nchars] == '\\') {
		lpath[nchars] = '\0';
	}

/*
 *	If the file is a directory, redirect using the nominated default page
 */
	if (websPageIsDirectory(lpath)) {
		nchars = gstrlen(path);
		if (path[nchars-1] == '/' || path[nchars-1] == '\\') {
			path[--nchars] = '\0';
		}
		nchars += gstrlen(websDefaultPage) + 2;
		fmtAlloc(&tmp, nchars, T("%s/%s"), path, websDefaultPage);
printf ("websDefaultHandler: tmp(%s)\n", tmp);
		websRedirect(wp, tmp);
		bfreeSafe(B_L, tmp);
		return 1;
	}

printf ("we now open the web pages\n");
printf ("lpath(%s), path(%s)\n", lpath, path);

/*
 *	Open the document. Stat for later use.
 */
	if (websPageOpen(wp, lpath, path, O_RDONLY | O_BINARY, 
		0666) < 0) 
   {
      /* 10 Dec 02 BgP -- according to 
       * <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>, 
       * the proper code to return here is NOT 400 (old code), which is used
       * to indicate a malformed request. Here, the request is good, but the
       * error we need to tell the client about is 404 (Not Found).
       */
      /* 
       * 17 Mar 03 BgP -- prevent a cross-site scripting exploit
		websError(wp, 404, T("Cannot open URL %s"), url);
       */
      
		websError(wp, 404, T("Cannot open URL, type 2"));
		websBuildWhitelist();
		return 1;
	} 

printf ("lpath(%s), path(%s)\n", lpath, path);
	if (websPageStat(wp, lpath, path, &sbuf) < 0) {
      /*
       * 17 Mar 03 BgP
       * prevent a cross-site scripting exploit
		websError(wp, 400, T("Cannot stat page for URL %s"), url);
       */
		websError(wp, 400, T("Cannot stat page for URL"));
		websBuildWhitelist();
		return 1;
	}

/*
 *	If the page has not been modified since the user last received it and it
 *	is not dynamically generated each time (ASP), then optimize request by
 *	sending a 304 Use local copy response
 */
	websStats.localHits++;
#ifdef WEBS_IF_MODIFIED_SUPPORT
	if (flags & WEBS_IF_MODIFIED && !(flags & WEBS_ASP)) {
		if (sbuf.mtime <= wp->since) {
			websWrite(wp, T("HTTP/1.0 304 Use local copy\r\n"));

/*
 *			by license terms the following line of code must
 *			not be modified.
 */
			websWrite(wp, T("Server: %s\r\n"), WEBS_NAME);

			if (flags & WEBS_KEEP_ALIVE) {
				websWrite(wp, T("Connection: keep-alive\r\n"));
			}
			websWrite(wp, T("\r\n"));
			websSetRequestFlags(wp, flags |= WEBS_HEADER_DONE);
			websDone(wp, 304);
			return 1;
		}
	}
#endif

/*
 *	Output the normal HTTP response header
 */
	if ((date = websGetDateString(NULL)) != NULL) {
		websWrite(wp, T("HTTP/1.0 200 OK\r\nDate: %s\r\n"), date);
/*
 *		The Server HTTP header below must not be modified unless
 *		explicitly allowed by licensing terms.
 */
#ifdef WEBS_SSL_SUPPORT
		websWrite(wp, T("Server: %s/%s %s/%s\r\n"), 
			WEBS_NAME, WEBS_VERSION, SSL_NAME, SSL_VERSION);
#else
		websWrite(wp, T("Server: %s/%s\r\n"), WEBS_NAME, WEBS_VERSION);
#endif
		bfree(B_L, date);
	}
	flags |= WEBS_HEADER_DONE;

/*
 *	If this is an ASP request, ensure the remote browser doesn't cache it.
 *	Send back both HTTP/1.0 and HTTP/1.1 cache control directives
 */
	if (flags & WEBS_ASP) {
		bytes = 0;
		websWrite(wp, T("Pragma: no-cache\r\nCache-Control: no-cache\r\n"));

	} else {
		if ((date = websGetDateString(&sbuf)) != NULL) {
			websWrite(wp, T("Last-modified: %s\r\n"), date);
			bfree(B_L, date);
		}
		bytes = sbuf.size;
	}

	if (bytes) {
		websWrite(wp, T("Content-length: %d\r\n"), bytes);
		websSetRequestBytes(wp, bytes);
	}
	websWrite(wp, T("Content-type: %s\r\n"), websGetRequestType(wp));

	if ((flags & WEBS_KEEP_ALIVE) && !(flags & WEBS_ASP)) {
		websWrite(wp, T("Connection: keep-alive\r\n"));
	}
	websWrite(wp, T("\r\n"));

/*
 *	All done if the browser did a HEAD request
 */
	if (flags & WEBS_HEAD_REQUEST) {
		websDone(wp, 200);
		return 1;
	}

/*
 *	Evaluate ASP requests
 */
	if (flags & WEBS_ASP) {
		if (websAspRequest(wp, lpath) < 0) {
			return 1;
		}
		websDone(wp, 200);
		return 1;
	}
/*
 *	Return the data via background write
 */
	websSetRequestSocketHandler(wp, SOCKET_WRITABLE, websDefaultWriteEvent);
	return 1;
}
コード例 #14
0
ファイル: file.c プロジェクト: blueskit/goahead
/*
    Serve static files
 */
static bool fileHandler(Webs *wp)
{
    WebsFileInfo    info;
    char            *tmp, *date;
    ssize           nchars;
    int             code;

    assert(websValid(wp));
    assert(wp->method);
    assert(wp->filename && wp->filename[0]);

#if !ME_ROM
    if (smatch(wp->method, "DELETE")) {
        if (unlink(wp->filename) < 0) {
            websError(wp, HTTP_CODE_NOT_FOUND, "Cannot delete the URI");
        } else {
            /* No content */
            websResponse(wp, 204, 0);
        }
    } else if (smatch(wp->method, "PUT")) {
        /* Code is already set for us by processContent() */
        websResponse(wp, wp->code, 0);

    } else 
#endif /* !ME_ROM */
    {
        /*
            If the file is a directory, redirect using the nominated default page
         */
        if (websPageIsDirectory(wp)) {
            nchars = strlen(wp->path);
            if (wp->path[nchars - 1] == '/' || wp->path[nchars - 1] == '\\') {
                wp->path[--nchars] = '\0';
            }
            tmp = sfmt("%s/%s", wp->path, websIndex);
            websRedirect(wp, tmp);
            wfree(tmp);
            return 1;
        }
        if (websPageOpen(wp, O_RDONLY | O_BINARY, 0666) < 0) {
#if ME_DEBUG
            if (wp->referrer) {
                trace(1, "From %s", wp->referrer);
            }
#endif
            websError(wp, HTTP_CODE_NOT_FOUND, "Cannot open document for: %s", wp->path);
            return 1;
        }
        if (websPageStat(wp, &info) < 0) {
            websError(wp, HTTP_CODE_NOT_FOUND, "Cannot stat page for URL");
            return 1;
        }
        code = 200;
        if (wp->since && info.mtime <= wp->since) {
            code = 304;
            info.size = 0;
        }
        websSetStatus(wp, code);
        websWriteHeaders(wp, info.size, 0);
        if ((date = websGetDateString(&info)) != NULL) {
            websWriteHeader(wp, "Last-Modified", "%s", date);
            wfree(date);
        }
        websWriteEndHeaders(wp);

        /*
            All done if the browser did a HEAD request
         */
        if (smatch(wp->method, "HEAD")) {
            websDone(wp);
            return 1;
        }
        if (info.size > 0) {
            websSetBackgroundWriter(wp, fileWriteEvent);
        } else {
            websDone(wp);
        }
    }
    return 1;
}
コード例 #15
0
ファイル: usb.c プロジェクト: houzhenggang/MT
static void storageDiskAdm(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 *dir_path = websGetVar(wp, T("dir_path"), T(""));

#if defined CONFIG_USER_SAMBA && (defined CONFIG_USB || defined CONFIG_MMC)
		FILE *fp = NULL; 
		char smb_config_file[25];
		int exist, index = 0;

		sprintf(smb_config_file, "%s/.smb_config", first_part);
		if (NULL == (fp = fopen(smb_config_file, "w")))
		{
			perror(__FUNCTION__);
			return;
		}
		while(96 > index)
		{
			exist = DIREXIST(smb_conf.bitmap, index);
			if ((exist) && 
				(0 == strcmp(dir_path, smb_conf.dir_list[index].path)))
			{
				// 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);
				break;
			}
			index++;
		}
		fwrite(&smb_conf, sizeof(struct smb_dir_config), 1, fp);
		fclose(fp);
#endif	
		doSystem("rm -rf \"%s\"", dir_path);
		websRedirect(wp, "usb/STORAGEdisk_admin.asp");
	}
	else if (0 == strcmp(submit, "add"))
	{
		char_t *dir_name, *disk_part;

		dir_name = websGetVar(wp, T("adddir_name"), T(""));
		disk_part = websGetVar(wp, T("disk_part"), T(""));
		// DEBUG(dir_name);
		// DEBUG(disk_part);
		doSystem("mkdir -p \"%s/%s\"", disk_part, dir_name);	
		doSystem("chmod 777 \"%s/%s\"", disk_part, dir_name);	
	}
	else if (0 == strcmp(submit, "format"))
	{
		char_t *disk_part = websGetVar(wp, T("disk_part"), T(""));
		char part[30] = "";
		FormatPart(part, disk_part);
		sleep(5);
		doSystem("storage.sh restart");
		sleep(5);

		websRedirect(wp, "usb/STORAGEdisk_admin.asp");
	}
	else if (0 == strcmp(submit, "remove"))
	{
		FILE *fp_mount = NULL;
		char part[30];
		
		if (NULL == (fp_mount = fopen("/proc/mounts", "r")))
		{
			perror(__FUNCTION__);
			return;
		}
		while(EOF != fscanf(fp_mount, "%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_mount);
		websRedirect(wp, "usb/STORAGEdisk_admin.asp");
	}
}
コード例 #16
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;

		
}
コード例 #17
0
ファイル: default.c プロジェクト: epicsdeb/rtems
int websDefaultHandler(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg,
						char_t *url, char_t *path, char_t *query)
{
	websStatType	sbuf;
	char_t			*lpath, *tmp, *date;
	int				bytes, flags, nchars;

	a_assert(websValid(wp));
	a_assert(url && *url);
	a_assert(path);
	a_assert(query);

/*
 *	Validate the URL and ensure that ".."s don't give access to unwanted files
 */
	flags = websGetRequestFlags(wp);

	if (websValidateUrl(wp, path) < 0) {
		websError(wp, 500, T("Invalid URL %s"), url);
		return 1;
	}
	lpath = websGetRequestLpath(wp);
	nchars = gstrlen(lpath) - 1;
	if (lpath[nchars] == '/' || lpath[nchars] == '\\') {
		lpath[nchars] = '\0';
	}

/*
 *	If the file is a directory, redirect using the nominated default page
 */
	if (websPageIsDirectory(lpath)) {
		nchars = gstrlen(path);
		if (path[nchars-1] == '/' || path[nchars-1] == '\\') {
			path[--nchars] = '\0';
		}
		nchars += gstrlen(websDefaultPage) + 2;
		fmtAlloc(&tmp, nchars, T("%s/%s"), path, websDefaultPage);
		websRedirect(wp, tmp);
		bfreeSafe(B_L, tmp);
		return 1;
	}

/*
 *	Open the document. Stat for later use.
 */
	if (websPageOpen(wp, lpath, path, SOCKET_RDONLY | SOCKET_BINARY,
		0666) < 0) {
		websError(wp, 400, T("Cannot open URL <b>%s</b>"), url);
		return 1;
	}

	if (websPageStat(wp, lpath, path, &sbuf) < 0) {
		websError(wp, 400, T("Cannot stat page for URL <b>%s</b>"), url);
		return 1;
	}

/*
 *	If the page has not been modified since the user last received it and it
 *	is not dynamically generated each time (ASP), then optimize request by
 *	sending a 304 Use local copy response
 */
	websStats.localHits++;
#ifdef WEBS_IF_MODIFIED_SUPPORT
	if (flags & WEBS_IF_MODIFIED && !(flags & WEBS_ASP)) {
		if (sbuf.mtime <= wp->since) {
			websWrite(wp, T("HTTP/1.0 304 Use local copy\r\n"));

/*
 *			by license terms the following line of code must
 *			not be modified.
 */
			websWrite(wp, T("Server: %s\r\n"), WEBS_NAME);

			if (flags & WEBS_KEEP_ALIVE) {
				websWrite(wp, T("Connection: keep-alive\r\n"));
			}
			websWrite(wp, T("\r\n"));
			websSetRequestFlags(wp, flags |= WEBS_HEADER_DONE);
			websDone(wp, 304);
			return 1;
		}
	}
#endif

/*
 *	Output the normal HTTP response header
 */
	if ((date = websGetDateString(NULL)) != NULL) {
		websWrite(wp, T("HTTP/1.0 200 OK\r\nDate: %s\r\n"), date);

/*
 *		By license terms the following line of code must not be modified.
 */
		websWrite(wp, T("Server: %s\r\n"), WEBS_NAME);
		bfree(B_L, date);
	}
	flags |= WEBS_HEADER_DONE;

/*
 *	If this is an ASP request, ensure the remote browser doesn't cache it.
 *	Send back both HTTP/1.0 and HTTP/1.1 cache control directives
 */
	if (flags & WEBS_ASP) {
		bytes = 0;
		websWrite(wp, T("Pragma: no-cache\r\nCache-Control: no-cache\r\n"));

	} else {
		if ((date = websGetDateString(&sbuf)) != NULL) {
			websWrite(wp, T("Last-modified: %s\r\n"), date);
			bfree(B_L, date);
		}
		bytes = sbuf.size;
	}

	if (bytes) {
		websWrite(wp, T("Content-length: %d\r\n"), bytes);
		websSetRequestBytes(wp, bytes);
	}
	websWrite(wp, T("Content-type: %s\r\n"), websGetRequestType(wp));

	if ((flags & WEBS_KEEP_ALIVE) && !(flags & WEBS_ASP)) {
		websWrite(wp, T("Connection: keep-alive\r\n"));
	}
	websWrite(wp, T("\r\n"));

/*
 *	All done if the browser did a HEAD request
 */
	if (flags & WEBS_HEAD_REQUEST) {
		websDone(wp, 200);
		return 1;
	}

/*
 *	Evaluate ASP requests
 */
	if (flags & WEBS_ASP) {
		if (websAspRequest(wp, lpath) < 0) {
			return 1;
		}
		websDone(wp, 200);
		return 1;
	}

#ifdef WEBS_SSL_SUPPORT
	if (wp->flags & WEBS_SECURE) {
		websDefaultWriteEvent(wp);
	} else {
		websSetRequestSocketHandler(wp, SOCKET_WRITABLE, websDefaultWriteEvent);
	}
#else
/*
 *	For normal web documents, return the data via background write
 */
	websSetRequestSocketHandler(wp, SOCKET_WRITABLE, websDefaultWriteEvent);
#endif
	return 1;
}
コード例 #18
0
ファイル: modbus.c プロジェクト: qiuuu/xml
void GoFormModbusConfig(webs_t wp, char_t *path, char_t *query)
{
//	int shmid;
//	char *shmptr;
       char *devName, *seriaName;

	char *saveBtn;
	char *getBtn;


	char *nid;
	char *nname;
	char *ntime, *nbaud, *nparity, *ndata, *nstop, *ninfo;
 	printf("HELLO!\n");
	xmlDocPtr pdoc = NULL;
	xmlNodePtr proot = NULL, pcur = NULL;
	xmlChar *xmlId, *xmlName, *xmlBaud,*xmlParity, *xmlStop, *xmlData, *xmlTimeout, *xmlInfo;

        devName = websGetVar(wp,T("name"),"");
        seriaName = websGetVar(wp,T("serialName"),""); 
        printf("%s \n",strcpy(modArg.id,devName));
        printf("seria is %s \n",strcpy(modArg.name,seriaName)); 
        getBtn = websGetVar(wp,T("getBtn"),T(""));
	saveBtn = websGetVar(wp,T("saveBtn"),T(""));
        printf("ready button \n");
        if(strlen(getBtn)!=0)
	{

	    pdoc = xmlReadFile("modbus.xml","UTF-8",XML_PARSE_RECOVER);
	    
	    proot = xmlDocGetRootElement(pdoc);
            printf("get the proot !!!\n");
	    pcur = proot->xmlChildrenNode;
	    while(pcur!=NULL)
	    {
	 	if(!xmlStrcmp(pcur->name, (const xmlChar*)"dev")){
	  		xmlId = xmlGetProp(pcur,(const xmlChar*)"ID");
			xmlName = xmlGetProp(pcur,(const xmlChar*)"Sname"); 
                        printf("the devNa is %s\n",devName); 
			if(!strcmp(xmlId,devName) && !strcmp(xmlName,seriaName))
			{
              		     xmlBaud = xmlGetProp(pcur,(const xmlChar*)"baud");
 		             xmlTimeout = xmlGetProp(pcur,(const xmlChar*)"timeout");
                             xmlParity = xmlGetProp(pcur,(const xmlChar*)"parity");
                             xmlStop = xmlGetProp(pcur,(const xmlChar*)"stop");
		       	     xmlData = xmlGetProp(pcur,(const xmlChar*)"data");
                             xmlInfo = xmlGetProp(pcur,(const xmlChar*)"info"); 



			     printf("get the id is : %s\n",strcpy(modArg.id,xmlId));
                             printf("get the serianame is : %s\n",strcpy(modArg.name,xmlName));
                             printf("get the baud is :!!%s\n",strcpy(modArg.baud,xmlBaud));
			     printf("get the parity is : %s\n",strcpy(modArg.parity,xmlParity));
			     printf("get the data is :!!%s\n",strcpy(modArg.data_bit,xmlData));	 	
			     printf("get the stop_bit is : %s\n",strcpy(modArg.stop_bit,xmlStop));
                             printf("get the timeout is : %s\n",strcpy(modArg.time_out,xmlTimeout));
                             printf("get the information is :!!%s\n",strcpy(modArg.info,xmlInfo));


                             xmlFree(xmlId);
			     xmlFree(xmlName);
                             xmlFree(xmlBaud);
			     xmlFree(xmlTimeout);    
                             xmlFree(xmlParity);
			     xmlFree(xmlStop); 
                             xmlFree(xmlData);
                             xmlFree(xmlInfo); 
                             break;
			} 		
		}
		pcur = pcur->next;
	    }
	
        	xmlFreeDoc(pdoc);
        }else if(strlen(saveBtn)!=0){
	    printf("enter the save area!!!\n");


            pdoc = xmlReadFile("modbus.xml","UTF-8",XML_PARSE_RECOVER);
            proot = xmlDocGetRootElement(pdoc);
            pcur = proot->xmlChildrenNode;
            printf("the pcur is %s\n",pcur->name); 
       	    while(pcur!=NULL)
            {
                 printf("the pcur in while is%s\n",pcur->name); 
                 xmlId = xmlGetProp(pcur,(const xmlChar*)"ID");
	         if(!xmlStrcmp(xmlId, (const xmlChar*)devName))
	         {			

                         
         	                     printf("the dev is %s\n",devName); 
  		                   
                                     nid = websGetVar(wp,T("name"),T(""));		 
                                     nname = websGetVar(wp,T("serialName"),T("")); 
				     nbaud = websGetVar(wp,T("opSelect1"),T(""));
                                     nparity = websGetVar(wp,T("opSelect2"),T(""));
                                     ndata = websGetVar(wp,T("opSelect3"),T(""));
                                     nstop = websGetVar(wp,T("opSelect4"),T(""));
                                     ntime = websGetVar(wp,T("time"),T(""));
                                     ninfo = websGetVar(wp,T("info"),T(""));
                                      




                                     xmlSetProp(pcur,(const xmlChar*)"ID",(const xmlChar*)nid);
				     xmlSetProp(pcur,(const xmlChar*)"Sname",(const xmlChar*)nname);
	 	
                                     xmlSetProp(pcur,(const xmlChar*)"baud",(const xmlChar*)nbaud);
                                     xmlSetProp(pcur,(const xmlChar*)"parity",(const xmlChar*)nparity);
                                     xmlSetProp(pcur,(const xmlChar*)"data",(const xmlChar*)ndata);
                                     xmlSetProp(pcur,(const xmlChar*)"stop",(const xmlChar*)nstop); 
                                     xmlSetProp(pcur,(const xmlChar*)"timeout",(const xmlChar*)ntime);
                                     xmlSetProp(pcur,(const xmlChar*)"info",(const xmlChar*)ninfo); 
                                     
				     

				     xmlBaud = xmlGetProp(pcur,(const xmlChar*)"baud");
				     xmlParity = xmlGetProp(pcur,(const xmlChar*)"parity"); 
				     xmlTimeout = xmlGetProp(pcur,(const xmlChar*)"timeout"); 
				     xmlStop = xmlGetProp(pcur,(const xmlChar*)"stop");
                                     xmlData = xmlGetProp(pcur,(const xmlChar*)"data");
      

                                     xmlInfo = xmlGetProp(pcur,(const xmlChar*)"info");  
       

                                     printf("sur info ssss %s\n",strcpy(modArg.info,xmlInfo));
                                     printf("sur baud ssss %s\n",strcpy(modArg.baud,(const char*)xmlBaud));
				     printf("show parity %s\n",strcpy(modArg.parity,xmlParity));
                                     printf("save the timeout After is %s\n",strcpy(modArg.time_out,(const char*)xmlTimeout));
 				     printf("show the stop_bit is %s\n",strcpy(modArg.stop_bit,xmlStop)); 

                                     printf("data_bit is %s\n",strcpy(modArg.data_bit,xmlData));
                                        


			             xmlSaveFormatFileEnc("modbus.xml",pdoc,"UTF-8",1); 
                                
				     
                                     xmlFree(xmlBaud);
                                     xmlFree(xmlParity);
                                     xmlFree(xmlStop);
				     xmlFree(xmlTimeout);
                                     xmlFree(xmlData);
                                     xmlFree(xmlInfo);
                         
                                      break;
                 }
		 pcur = pcur->next;
  		if(pcur==NULL)
		{
			printf("make a new dev\n");
			pcur = xmlNewNode(NULL,(const xmlChar*)"dev");
			xmlAddChild(proot,pcur);
			xmlNewProp(pcur,(const xmlChar*)"ID",(const xmlChar*)devName);
			xmlNewProp(pcur,(const xmlChar*)"Sname",(const xmlChar*)seriaName);
			xmlNewProp(pcur,(const xmlChar*)"baud",(const xmlChar*)"NULL");
			xmlNewProp(pcur,(const xmlChar*)"parity",(const xmlChar*)"NULL");
			xmlNewProp(pcur,(const xmlChar*)"data",(const xmlChar*)"NULL");
			xmlNewProp(pcur,(const xmlChar*)"stop",(const xmlChar*)"NULL");
			xmlNewProp(pcur,(const xmlChar*)"timeout",(const xmlChar*)"NULL");
			xmlNewProp(pcur,(const xmlChar*)"info",(const xmlChar*)"NULL");
			printf("successful new!%s\n",pcur->name);	
		}
	   }
     

           xmlFreeDoc(pdoc); 

	} 
/*
	if((shmid = shmget(MYKEY,BUF_SIZE,IPC_CREAT)) ==-1)     
        {     
           printf("shmget error!\n");     
           exit(1);     
        }

        if((shmptr = shmat(shmid,0,0)) == (void *)-1)     
        {     
 	   printf("shmat error!\n");     
           exit(1);     
        }     
        
	   printf("string:%s\n",shmptr);
	   sleep(3);

        fp = fopen("modbus.txt","w");
        
        fprintf(fp, "%s\n",shmptr);

        fclose(fp);
*/
        websRedirect(wp,T("modbus.asp")); 
	return ;	
}