Exemplo n.º 1
0
static int initWebs(void)
{
	struct in_addr	intaddr;
#ifdef GA_HOSTNAME_SUPPORT
	struct hostent	*hp;
	char			host[128];
#else
	//ROY: any ip addr
	const char			*lan_ip = "0.0.0.0";//nvram_bufget(RT2860_NVRAM, "lan_ipaddr");
#endif
	char			webdir[128];
	char			*cp;
	char_t			wbuf[128];

/*
 *	Initialize the socket subsystem
 */
	socketOpen();

#ifdef USER_MANAGEMENT_SUPPORT
/*
 *	Initialize the User Management database
 */
	char *admu = (char *) nvram_bufget(RT2860_NVRAM, "Login");
	char *admp = (char *) nvram_bufget(RT2860_NVRAM, "Password");
	umOpen();
	//umRestore(T("umconfig.txt"));
	//winfred: instead of using umconfig.txt, we create 'the one' adm defined in nvram
	umAddGroup(T("adm"), 0x07, AM_DIGEST, FALSE, FALSE);
	if (admu && strcmp(admu, "") && admp && strcmp(admp, "")) {
		umAddUser(admu, admp, T("adm"), FALSE, FALSE);
		umAddAccessLimit(T("/"), AM_DIGEST, FALSE, T("adm"));
	}
	else
		error(E_L, E_LOG, T("gohead.c: Warning: empty administrator account or password"));
#endif

#ifdef GA_HOSTNAME_SUPPORT
/*
 *	Define the local Ip address, host name, default home page and the 
 *	root web directory.
 */
	if (gethostname(host, sizeof(host)) < 0) {
		error(E_L, E_LOG, T("gohead.c: Can't get hostname"));
		return -1;
	}
	if ((hp = gethostbyname(host)) == NULL) {
		error(E_L, E_LOG, T("gohead.c: Can't get host address"));
		return -1;
	}
	memcpy((char *) &intaddr, (char *) hp->h_addr_list[0],
		(size_t) hp->h_length);
#else
/*
 * get ip address from nvram configuration (we executed initInternet)
 */
	if (NULL == lan_ip) {
		error(E_L, E_LOG, T("initWebs: cannot find lan_ip in NVRAM"));
		return -1;
	}
	intaddr.s_addr = inet_addr(lan_ip);
	if (intaddr.s_addr == INADDR_NONE) {
		error(E_L, E_LOG, T("initWebs: failed to convert %s to binary ip data"),
				lan_ip);
		intaddr.s_addr = 0;
		//return -1;
	}
#endif

/*
 *	Set rootWeb as the root web. Modify this to suit your needs
 */
	sprintf(webdir, "%s", rootWeb);

/*
 *	Configure the web server options before opening the web server
 */
	websSetDefaultDir(webdir);
	cp = inet_ntoa(intaddr);
	ascToUni(wbuf, cp, min(strlen(cp) + 1, sizeof(wbuf)));
	websSetIpaddr(wbuf);
#ifdef GA_HOSTNAME_SUPPORT
	ascToUni(wbuf, host, min(strlen(host) + 1, sizeof(wbuf)));
#else
	//use ip address (already in wbuf) as host
#endif
	websSetHost(wbuf);

/*
 *	Configure the web server options before opening the web server
 */
	websSetDefaultPage(T("default.asp"));
	websSetPassword(password);

/* 
 *	Open the web server on the given port. If that port is taken, try
 *	the next sequential port for up to "retries" attempts.
 */
	websOpenServer(port, retries);

/*
 * 	First create the URL handlers. Note: handlers are called in sorted order
 *	with the longest path handler examined first. Here we define the security 
 *	handler, forms handler and the default web page handler.
 */
	websUrlHandlerDefine(T(""), NULL, 0, websSecurityHandler, 
		WEBS_HANDLER_FIRST);
	websUrlHandlerDefine(T("/goform"), NULL, 0, websFormHandler, 0);
	websUrlHandlerDefine(T("/cgi-bin"), NULL, 0, websCgiHandler, 0);
	websUrlHandlerDefine(T(""), NULL, 0, websDefaultHandler, 
		WEBS_HANDLER_LAST); 

/*
 *	Define our functions
 */
	formDefineUtilities();
	formDefineInternet();
#if defined CONFIG_RALINKAPP_SWQOS
	formDefineQoS();
#endif
#if (defined CONFIG_USB) || (defined CONFIG_MMC)
	formDefineUSB();
#endif
#if defined CONFIG_RALINKAPP_MPLAYER
	formDefineMedia();
#endif
	formDefineWireless();
#if defined (RTDEV_SUPPORT)
	formDefineInic();
#elif defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
	formDefineLegacy();
#endif
#if defined CONFIG_RT2860V2_STA || defined CONFIG_RT2860V2_STA_MODULE
	formDefineStation();
#endif
	formDefineFirewall();
	formDefineManagement();

/*
 *	Create the Form handlers for the User Management pages
 */
#ifdef USER_MANAGEMENT_SUPPORT
	//formDefineUserMgmt();  winfred: we do it ourselves
#endif

/*
 *	Create a handler for the default home page
 */
	websUrlHandlerDefine(T("/"), NULL, 0, websHomePageHandler, 0); 
	return 0;
}
Exemplo n.º 2
0
static void formAddUser(webs_t wp, char_t *path, char_t *query)
{
	char_t	*userid, *pass1, *pass2, *group, *enabled, *ok;
	bool_t bDisable;
	int	nCheck;

	a_assert(wp);

	userid = websGetVar(wp, T("user"), T("")); 
	pass1 = websGetVar(wp, T("password"), T("")); 
	pass2 = websGetVar(wp, T("passconf"), T("")); 
	group = websGetVar(wp, T("group"), T("")); 
	enabled = websGetVar(wp, T("enabled"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Add User Cancelled"));
	} else if (gstrcmp(pass1, pass2) != 0) {
		websWrite(wp, T("Confirmation Password did not match."));
	} else {
		if (enabled && *enabled && (gstrcmp(enabled, T("on")) == 0)) {
			bDisable = FALSE;
		} else {
			bDisable = TRUE;
		}

		nCheck = umAddUser(userid, pass1, group, 0, bDisable);
		if (nCheck != 0) {
			char_t * strError;

			switch (nCheck) {
			case UM_ERR_DUPLICATE:
				strError = T("User already exists.");
				break;

			case UM_ERR_BAD_NAME:
				strError = T("Invalid user name.");
				break;

			case UM_ERR_BAD_PASSWORD:
				strError = T("Invalid password.");
				break;

			case UM_ERR_NOT_FOUND:
				strError = T("Invalid or unselected group.");
				break;

			default:
				strError = T("Error writing user record.");
				break;
			}

			websWrite(wp, T("Unable to add user, \"%s\".  %s"),
				userid, strError);
		} else {
			websWrite(wp, T("User, \"%s\" was successfully added."),
				userid);
		}
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Exemplo n.º 3
0
static int initWebs()
{
    struct hostent*	hp;
    struct in_addr	intaddr;
    char			host[128], dir[128], webdir[128];
    char*			cp;
    char_t			wbuf[128];
    char			admu[32];
    char			admp[32];
    /*
     *	Initialize the socket subsystem
     */
    socketOpen();
#ifdef USER_MANAGEMENT_SUPPORT
    /*
     *	Initialize the User Management database
     */
#if 0
    umOpen();
    umRestore( T( "umconfig.txt" ) );
#else
    memset( admu, 0x00, 32 );
    memset( admp, 0x00, 32 );
    sprintf( admu, "admin" );
    sprintf( admp, "admin" );
    umOpen();
    //umRestore(T("umconfig.txt"));
    //winfred: instead of using umconfig.txt, we create 'the one' adm defined in nvram
    umAddGroup( T( "adm" ), 0x07, AM_DIGEST, FALSE, FALSE );
    //if (admu && strcmp(admu, "") && admp && strcmp(admp, "")) {
    umAddUser( admu, admp, T( "adm" ), FALSE, FALSE );
    umAddUser( "admin0", "admin0", T( "adm" ), FALSE, FALSE );
    umAddUser( "admin1", "admin1", T( "adm" ), FALSE, FALSE );
    umAddAccessLimit( T( "/" ), AM_DIGEST, FALSE, T( "adm" ) );
    //}
#endif
#endif
    /*
     *	Define the local Ip address, host name, default home page and the
     *	root web directory.
     */
#if 0

    if ( gethostname( host, sizeof( host ) ) < 0 )
    {
        error( E_L, E_LOG, T( "Can't get hostname" ) );
        return -1;
    }

    if ( ( hp = gethostbyname( host ) ) == NULL )
    {
        error( E_L, E_LOG, T( "Can't get host address" ) );
        return -1;
    }

    memcpy( ( char* ) &intaddr, ( char* ) hp->h_addr_list[0],
            ( size_t ) hp->h_length );
#else
    intaddr.s_addr = inet_addr( "192.168.1.250" );
#endif
    /*
     *	Set ../web as the root web. Modify this to suit your needs
     */
    getcwd( dir, sizeof( dir ) );

    if ( ( cp = strrchr( dir, '/' ) ) )
    {
        *cp = '\0';
    }

    sprintf( webdir, "%s/%s", dir, rootWeb );
    /*
     *	Configure the web server options before opening the web server
     */
    websSetDefaultDir( webdir );
    cp = inet_ntoa( intaddr );
    ascToUni( wbuf, cp, min( strlen( cp ) + 1, sizeof( wbuf ) ) );
    websSetIpaddr( wbuf );
    ascToUni( wbuf, host, min( strlen( host ) + 1, sizeof( wbuf ) ) );
    websSetHost( wbuf );
    /*
     *	Configure the web server options before opening the web server
     */
    websSetDefaultPage( T( "index.htm" ) );
    websSetPassword( password );
    /*
     *	Open the web server on the given port. If that port is taken, try
     *	the next sequential port for up to "retries" attempts.
     */
    websOpenServer( port, retries );
    /*
     * 	First create the URL handlers. Note: handlers are called in sorted order
     *	with the longest path handler examined first. Here we define the security
     *	handler, forms handler and the default web page handler.
     */
    websUrlHandlerDefine( T( "" ), NULL, 0, websSecurityHandler, WEBS_HANDLER_FIRST );
    websUrlHandlerDefine( T( "/goform" ), NULL, 0, websFormHandler, 0 );
    websUrlHandlerDefine( T( "/cgi-bin" ), NULL, 0, websCgiHandler, 0 );
    websUrlHandlerDefine( T( "" ), NULL, 0, websDefaultHandler,
                          WEBS_HANDLER_LAST );
    /*
     *	Now define two test procedures. Replace these with your application
     *	relevant ASP script procedures and form functions.
     */
    websAspDefine( T( "aspTest" ), aspTest );
    websFormDefine( T( "formTest" ), formTest );
    /*
     *	Create the Form handlers for the User Management pages
     */
#ifdef USER_MANAGEMENT_SUPPORT
    formDefineUserMgmt();
#endif
    /*
     *	Create a handler for the default home page
     */
    websUrlHandlerDefine( T( "/" ), NULL, 0, websHomePageHandler, 0 );
    return 0;
}