Esempio n. 1
0
void
rstat(void)
{
	Xfile *f;
	Dir dir;

	chat("stat(fid=%d)...", req->fid);
	f=xfile(req->fid, Asis);
	setnames(&dir, fdata);
	(*f->xf->s->stat)(f, &dir);
	if(chatty)
		showdir(2, &dir);
	rep->nstat = convD2M(&dir, statbuf, sizeof statbuf);
	rep->stat = statbuf;
}
Esempio n. 2
0
int serveconnection(int sockfd)
{
	FILE *in;
	char tempdata[8192], *ptr, *ptr2, *host_ptr1, *host_ptr2;
	char tempstring[8192], mimetype[50];
	char filename[255];
	unsigned int loop=0, flag=0;
	int numbytes=0;
	struct sockaddr_in sa;
	int addrlen = sizeof(struct sockaddr_in);
	t_vhost *thehost;
	
	thehost = &defaulthost;

// tempdata is the full header, tempstring is just the command

	while(!strstr(tempdata, "\r\n\r\n") && !strstr(tempdata, "\n\n"))
	{	
		if((numbytes=recv(sockfd, tempdata+numbytes, 4096-numbytes, 0))==-1)
			return -1;
	}
	for(loop=0; loop<4096 && tempdata[loop]!='\n' && tempdata[loop]!='\r'; loop++)
		tempstring[loop] = tempdata[loop];
	
	tempstring[loop] = '\0';
	ptr = strtok(tempstring, " ");
	if(ptr == 0) return -1;
	if(strcmp(ptr, "GET")) 
	{
		strcpy(filename, SERVERROOT);
		strcat(filename, "/cmderror.html");
		goto sendpage;
	}
	ptr = strtok(NULL, " ");
	if(ptr == NULL)
	{
		strcpy(filename, SERVERROOT);
		strcat(filename, "/cmderror.html");
		goto sendpage;
	}

	host_ptr1 = strstr(tempdata, "Host:");
	if(host_ptr1)
	{
		host_ptr2 = strtok(host_ptr1+6, " \r\n\t");
		
		for(loop=0; loop<no_vhosts; loop++)
			if(!gstricmp(vhosts[loop].host, host_ptr2))
				thehost = &vhosts[loop];
	}	
	else
		thehost = &defaulthost;
	if(strstr(ptr, "/.."))
	{
		strcpy(filename, SERVERROOT);
		strcat(filename, "/404.html");
		goto sendpage;
	}

	getpeername(sockfd, (struct sockaddr *)&sa, &addrlen);
	Log("Connection from %s, request = \"GET %s\"", inet_ntoa(sa.sin_addr), ptr);

	if(!strncmp(ptr, thehost->CGIBINDIR, strlen(thehost->CGIBINDIR)))
	{/* Trying to execute a cgi-bin file ? lets check */
		ptr2 = strstr(ptr, "?");
		if(ptr2!=NULL) { ptr2[0] = '\0'; flag = 1; }

		strcpy(filename, thehost->CGIBINROOT);
		ptr += strlen(thehost->CGIBINDIR);
		strcat(filename, ptr);

		// Filename = program to execute
		// ptr = filename in cgi-bin dir
		// ptr2+1 = parameters

		if(does_file_exist(filename)==TRUE && isDirectory(filename)==FALSE)
		{
			if(send(sockfd, "HTTP/1.1 200 OK\n", 16, 0)==-1)
			{
				fclose(in);
				return -1;
			}
			if(send(sockfd, "Server: "SERVERNAME"\n", strlen("Server: "SERVERNAME"\n"), 0)==-1)
			{
				fclose(in);
				return -1;
			}
			
			// Is a CGI-program that needs executing
			if(0 != dup2(sockfd, 0) || 1 != dup2(sockfd, 1))
				return -1;

			setbuf(stdin, 0);
			setbuf(stdout, 0);
			if(flag==1) setenv("QUERY_STRING", ptr2+1, 1);
			
			chdir(thehost->CGIBINROOT);
			
			execl(filename, "");
		}
		strcpy(filename, SERVERROOT);
		strcat(filename, "/cgierror.html");
		goto sendpage;
	}	

	strcpy(filename, thehost->DOCUMENTROOT);
	strcat(filename, ptr);
	      
	if(does_file_exist(filename)==FALSE)
	{		
		if(filename[strlen(filename)-1] == '/')
			strcat(filename, thehost->DEFAULTPAGE);
		else
		{
			strcat(filename, "/");
			strcat(filename, thehost->DEFAULTPAGE);
		}
		if(does_file_exist(filename) == FALSE)
		{
			filename[strlen(filename)-strlen(thehost->DEFAULTPAGE)-1] = '\0'; // Get rid of the /index.. 
			if(isDirectory(filename) == TRUE) { showdir(filename, sockfd, thehost); return 0; }
	
			// File does not exist, so we need to display the 404 error page..
			strcpy(filename, SERVERROOT);
			strcat(filename, "/404.html");
		}	
	
	}
sendpage:
	if((in = fopen(filename, "rb"))==NULL)
		return -1;
	
	fseek(in, 0, SEEK_END);
	
	if(send(sockfd, "HTTP/1.1 200 OK\n", 16, 0)==-1)
	{
		fclose(in);
		return -1;
	}
	if(send(sockfd, "Server: "SERVERNAME"\n", strlen("Server: "SERVERNAME"\n"), 0)==-1)
	{
		fclose(in);
		return -1;
	}
	sprintf(tempstring, "Content-Length: %d\n", ftell(in));
	if(send(sockfd, tempstring, strlen(tempstring), 0)==-1)
	{
		fclose(in);
		return -1;
	}

	getmimetype(filename, mimetype);
	sprintf(tempstring, "Content-Type: %s\n\n", mimetype);
	if(send(sockfd, tempstring, strlen(tempstring), 0)==-1)
	{
		fclose(in);
		return -1;
	}
	
	fseek(in, 0, SEEK_SET);

	while(!feof(in))
	{
		numbytes = fread(tempdata, 1, 1024, in);
		if(send(sockfd, tempdata, numbytes, 0)==-1)
		{
			fclose(in);
			return -1;
		}
	}
	fclose(in);

	close(sockfd);	
	return 0;
}
Esempio n. 3
0
void main()
{
  char s[200],cdir[200]="/",tmp[200];
  int a,b,ID=alloc_console();
  FILE *fp;
  meminit();
  fileinit();

  printf("ChaOS shell ID=%x\n",ID);

  do {
    printf(">");
    gets(s);

    if (!strcmp(s,"exit")) break;

    if (s[0]=='t'&&s[1]=='y'&&s[2]=='p'&&s[3]=='e'&&s[4]==' '){
        fp=fopen(s+5,"rb");
        while((a=fread(tmp,1,199,fp))) for (b=0;b<a;b++) putch(tmp[b]);
        fclose(fp);
        continue;
    }

    if (!strcmp(s,"dir")){
        showdir(cdir);continue;
    }

    if (!strcmp(s,"cls")){
       clrscr();
       continue;
    }

    if (s[0]=='c'&&s[1]=='d'&&s[2]==' '){
      if (s[3]=='.'&&s[4]=='.'&&s[5]==0){
         if (strlen(cdir)<=1) continue;
         b=strlen(cdir);b--;
         cdir[b]=0;
         for(b--;b>=0;b--) if (cdir[b]=='/'){ cdir[b+1]=0;break;}
         continue;
      }

      if (s[3]=='/')
         strcpy(tmp,s+3);
      else
         { strcpy(tmp,cdir);strcat(tmp,s+3);}
      if (tmp[strlen(tmp)-1]!='/') strcat(tmp,"/");
      if (strlen(tmp)>1){
        tmp[strlen(tmp)-1]=0;
        if (findfirst(tmp,&sr,_FF_NORMAL)==0){
           strcpy(cdir,tmp);strcat(cdir,"/");
        } else printf("not found: %s\n",tmp);
      } else strcpy(cdir,tmp);
      continue;
    }

    if (!strcmp(s,"mem")){
      printf("free = %i\n",get_free_mem()<<12);
      continue;
    }

    // Execute
    if (s[0]==0) continue;
    if (s[0]!='/'){ strcpy(tmp,cdir);strcat(tmp,s);strcpy(s,tmp); }
    if ((a=system(s))!=0)
       printf("not found: %s (%x)\n",s,a);

  } while(1);

  free_console(ID);
}
Esempio n. 4
0
int main()
{
		char str[10];
		char strname[10];
		char c;

		printf("FormatDisk?<y/n>");
		scanf("%c",&c);
		fflush(stdin);
		if(c=='y')
		{
			if(!Format())
			{
				return -1;
			}
			printf("Finished!\n");
		}

		if(!Install())
		{
			return -1;
		}
		printf("login now\n");
		login();
		showhelp();
		printf("%s>",cmdhead);
		while(1)
		{
			scanf("%s",&str);
			if(strcmp(str,"shutdown")==0)
			{
				fclose(fd);
				return 0 ;
			}
			else	if(strcmp(str,"dir")==0)
					{
						showdir();
					}
			else if(strcmp(str,"bit")==0)
			{
					showbitmap();
			}

			else if(strcmp(str,"help")==0)
			{
					showhelp();
			}
			else if(strcmp(str,"logout")==0)
			{
				logout();
			}
			else	if(Iscmd(str))
			{
				scanf("%s",&strname);
				cmd_Up(str,strname);
			}

			else
			{
				printf("Error!!\n");
			}
			printf("%s>",cmdhead);
		}
return 0;
}
void main()
{
		char str[10];
		char strname[10];
		char c;

		printf("是否格式化?<y/n>");
		scanf("%c",&c);
		fgetc(stdin);
		if(c=='y')
		{
			if(!Format())
			{
				return;
			}
			printf("格式化完毕!\n");
		}

		if(!Install())
		{
			return;
		}
		printf("login.................\n");
		login();
		showhelp();
		printf("%s>",cmdhead);
		while(1)
		{
			scanf("%s",&str);
			if(strcmp(str,"exit")==0)
			{
				fclose(fd);
				return;
			}
			else	if(strcmp(str,"dir")==0)
					{
						showdir();
					}
			else if(strcmp(str,"bit")==0)
			{
					showbitmap();
			}
			else if(strcmp(str,"help")==0)
			{
					showhelp();
			}
			
			else	if(Iscmd(str))
			{
				scanf("%s",&strname);
				cmd_Up(str,strname);
			}

			else
			{
				printf("错误命令!\n");
			}
			printf("%s>",cmdhead);
		}

}