Exemplo n.º 1
0
int access_ornot(const char *destip) // 0 -> not 1 -> ok
{
	//192.168.1/255.255.255.0

	char ipinfo[16],maskinfo[16];
	char *p,*ip=ipinfo,*mask=maskinfo;
	char count=0;
	char *maskget=Getconfig("mask");
	const char *destipconst,*ipinfoconst,*maskinfoconst;
	if(maskget=="")
	{
		printf("ok:%s\n",maskget);
		return 1;
	}	
	p=maskget;

/* get ipinfo[] start */

	while(*p!='/')
	{
		if(*p=='.')
			++count;
		*ip++=*p++;
	}

	while(count<3)
	{
		*ip++='.';
		*ip++='0';
		++count;
	}
	*ip='\0';

/* get ipinfo[] end */

/* get maskinfo[] start */

	++p;
	while(*p!='\0')
	{
		if(*p=='.')
			++count;
		*mask++=*p++;
	}

	while(count<3)
	{
		*mask++='.';
		*mask++='0';
		++count;
	}
	*mask='\0';

/* get maskinfo[] end */
	destipconst=destip;
	ipinfoconst=ipinfo;
	maskinfoconst=maskinfo;
	return ipadd_to_longlong(ipinfoconst)==(ipadd_to_longlong(maskinfoconst)&ipadd_to_longlong(destipconst));

}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	int					listenfd, connfd, port, clientlen;
	pid_t				pid;
	struct sockaddr_in	clientaddr;
	char	isdaemon = 0, *portp = NULL, *logp = NULL, tmpcwd[MAXLINE];

	openlog(argv[0], LOG_NDELAY|LOG_PID, LOG_DAEMON);
	cwd = (char *)get_current_dir_name();
	strcpy(tmpcwd, cwd);
	strcat(tmpcwd, "/");

	parse_option(argc, argv, &isdaemon, &portp, &logp);

	printf("isdaemon = %d\n", isdaemon);
	printf("protp = %s\n", portp);
	printf("logp = %s\n", logp);
	//printf("cwd = %s\n", cwd);

	portp == NULL ? (port=atoi(Getconfig("http"))) : (port = atoi(portp));


	



	return 0;
}
Exemplo n.º 3
0
/* $begin parse_uri */
static int parse_uri(char *uri, char *filename, char *cgiargs) 
{
    char *ptr;
    char tmpcwd[MAXLINE];
    strcpy(tmpcwd,cwd);
    strcat(tmpcwd,"/");

    if (!strstr(uri, "cgi-bin")) 
    {  /* Static content */
	strcpy(cgiargs, "");
	strcpy(filename, strcat(tmpcwd,Getconfig("root")));
	strcat(filename, uri);
	if (uri[strlen(uri)-1] == '/')
	    strcat(filename, "home.html");
	return 1;
    }
    else 
    {  /* Dynamic content */
	ptr = index(uri, '?');
	if (ptr) 
	{
	    strcpy(cgiargs, ptr+1);
	    *ptr = '\0';
	}
	else 
	    strcpy(cgiargs, "");
	strcpy(filename, cwd);
	strcat(filename, uri);
	return 0;
    }
}
Exemplo n.º 4
0
static void ssl_init(void)
{
	static char crypto[]="RC4-MD5";
	certfile=Getconfig("ca");

	SSL_load_error_strings();
	SSLeay_add_ssl_algorithms();
	ssl_ctx = SSL_CTX_new( SSLv23_server_method() );

	if ( certfile[0] != '\0' )
		if ( SSL_CTX_use_certificate_file( ssl_ctx, certfile, SSL_FILETYPE_PEM ) == 0 || SSL_CTX_use_PrivateKey_file( ssl_ctx, certfile, SSL_FILETYPE_PEM ) == 0 || SSL_CTX_check_private_key( ssl_ctx ) == 0 )
		{
			ERR_print_errors_fp( stderr );
			exit( 1 );
		}
		if ( crypto != (char*) 0 )
		{

			if ( SSL_CTX_set_cipher_list( ssl_ctx, crypto ) == 0 )
			{
				ERR_print_errors_fp( stderr );
				exit( 1 );
			}
		}

}
Exemplo n.º 5
0
int main(int argc, char **argv) 
{
    int listenfd,connfd, port,clientlen;
    pid_t pid;
    struct sockaddr_in clientaddr;
    char isdaemon=0,*portp=NULL,*logp=NULL,tmpcwd[MAXLINE];

    #ifdef HTTPS 
    int sslport;
    char dossl=0,*sslportp=NULL;
    #endif

    openlog(argv[0],LOG_NDELAY|LOG_PID,LOG_DAEMON);	
    cwd=(char*)get_current_dir_name();	
    strcpy(tmpcwd,cwd);
    strcat(tmpcwd,"/");
    /* parse argv */

    #ifdef  HTTPS
    parse_option(argc,argv,&isdaemon,&portp,&logp,&sslportp,&dossl);
    sslportp==NULL ?(sslport=atoi(Getconfig("https"))) : (sslport=atoi(sslportp));

    if(dossl==1||strcmp(Getconfig("dossl"),"yes")==0)
    	dossl=1;
    #else
    parse_option(argc,argv,&isdaemon,&portp,&logp);
    #endif

    portp==NULL ?(port=atoi(Getconfig("http"))) : (port=atoi(portp));


    Signal(SIGCHLD,sigChldHandler);


    /* init log */
    if(logp==NULL) 
    	logp=Getconfig("log");
    initlog(strcat(tmpcwd,logp));

    /* whethe show dir */
    if(strcmp(Getconfig("dir"),"no")==0)
    	isShowdir=0;	
    	

    clientlen = sizeof(clientaddr);


    if(isdaemon==1||strcmp(Getconfig("daemon"),"yes")==0)
    	Daemon(1,1);

    writePid(1);

    /* $https start  */ 
    #ifdef HTTPS 
    if(dossl)
    {
    	if((pid=Fork())==0)
	{
		listenfd= Open_listenfd(sslport);
		ssl_init();

		while(1)
		{
			connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen);
			if(access_ornot(inet_ntoa(clientaddr.sin_addr))==0)
			{
				clienterror(connfd,"maybe this web server not open to you!" , "403", "Forbidden", "Tiny couldn't read the file");
				continue;
			}

			if((pid=Fork())>0)
			{
				Close(connfd);
				continue;
			}
			else if(pid==0)
			{
				ishttps=1;	
				doit(connfd);
				exit(1);
			}
		}
	}
    }
    #endif

    /* $end https */


    listenfd = Open_listenfd(port);
    while (1)
    {
	connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen);
	if(access_ornot(inet_ntoa(clientaddr.sin_addr))==0)
	{
	    clienterror(connfd,"maybe this web server not open to you!" , "403", "Forbidden", "Tiny couldn't read the file");
	    continue;
	}

	if((pid=Fork())>0)
	{
		Close(connfd);
		continue;
	}
	else if(pid==0)
	{
		doit(connfd);
		exit(1);
	}
    }
}