Example #1
0
void NullForm()
{
  html_begin("Null Form Submitted");
  h1("Null Form Submitted");
  printf("You have sent an empty form.  Please go back and fill out\r\n");
  printf("the form properly, or email <i>%s</i>\r\n",WEBADMIN);
  printf("if you are having difficulty.\r\n");
  html_end();
}
Example #2
0
__externC cyg_bool cyg_httpd_send_html( FILE *client, char *filename,
                                        char *request, void *arg )
{
    html_begin( client );
    
    fwrite( arg, 1, strlen((char *)arg), client );

    html_end( client );

    return true;
}
Example #3
0
int main()
{
  llist entries;
  int status;

  html_header();
  html_begin("Query Results");
  status = read_cgi_input(&entries);
  printf("<h1>Status = %d</h1>\n",status);
  h1("Query results");
  print_entries(entries);
  html_end();
  list_clear(&entries);
  return 0;
}
Example #4
0
int main()
{
	char ip_range_start[50],ip_range_end[50],country[50];
	char *osinfo,*browserinfo;
	char *ip,*trueip;

  	html_header();
  	html_begin("cgi-lib 测试程序");

	ip = REMOTE_ADDR;
	trueip = HTTP_CLIENT_IP;

	if(trueip == NULL)
		trueip = HTTP_X_FORWARDED_FOR;
	if(trueip == NULL)
		trueip = ip;	
//	printf("-%s--%s-",ip,trueip);
		
	get_user_ipinfo(trueip,ip_range_start,ip_range_end,country);

	printf("访问者IP地址为: %s <br>\n",ip);
	printf("IP所属区域为:%s <br>\n",country);
	printf("IP所在范围为: %s - %s <br>\n",ip_range_start,ip_range_end);

	if(strstr(trueip,ip) == NULL)
	{
		get_user_ipinfo(ip,ip_range_start,ip_range_end,country);

		printf("访问者代理IP地址为: %s <br>\n",trueip);
		printf("代理IP所属区域为:%s <br>\n",country);
		printf("代理IP所在范围为: %s - %s <br>\n",ip_range_start,ip_range_end);
	
	}
	else
		if(HTTP_X_FORWARDED_FOR != NULL)
			printf("代理 IP 地址未知(没有使用代理、代理服务器 IP 显示被禁止)<br>\n");


	osinfo = get_user_osinfo();
	browserinfo = get_user_browserinfo();
	
	printf("操作系统为: %s <br>\n",osinfo);
	
	printf("浏览器为: %s <br>\n",browserinfo);
	
  	html_end();
  	return 0;
}
Example #5
0
int main()
{
  	float usetime;

	html_header();
	html_begin("Test CGI");
	printf("开始计时!\n<br>");
	timeuse_microsecond_begin();
	printf("输出1!\n<br>");
	printf("输出2\n<br>");
	timeuse_microsecond_end();
	printf("计时结束!\n<br>");
	usetime = timeuse_microsecond_result();
	printf("输出1和输出2共计用时:%f 秒\n<br>",usetime);
	html_end();
	
	return 0;
}
Example #6
0
int main()
{
  llist entries;
  int status;

  html_header();
  html_begin("Test CGI");
  h1("CGI Test Program");
  printf("<hr>\n");
  h2("CGI Environment Variables");
  print_cgi_env();
  status = read_cgi_input(&entries);
  printf("<h2>Status = %d</h2>\n",status);
  h2("CGI Entries");
  print_entries(entries);
  html_end();
  list_clear(&entries);
  return 0;
}
Example #7
0
void authenticate(char *dest)
{
  FILE *access;
  char s[80];
  short FOUND = 0;

  access = fopen(AUTH,"r");
  while ( (fgets(s,80,access)!=NULL) && (!FOUND) ) {
    s[strlen(s) - 1] = '\0';
    if (!strcmp(s,dest))
      FOUND = 1;
  }
  if (!FOUND) {
    /* not authenticated */
    html_begin("Unauthorized Destination");
    h1("Unauthorized Destination");

    html_end();
    exit(1);
  }
}
Example #8
0
int main()
{
	LIST_STRU entries;
  	LIST_STRU configs;
  	char *configname = "simple-webmail.conf";
  	FILE *mail;
  	char *dest,*name,*from,*subject,*content;
	char command[256];

  	html_header();

  	read_cgi_input(&entries);
  	read_configs(&configs,configname);

  	if( (is_field_empty(entries,"name")) && (is_field_empty(entries,"from")) &&
      		(is_field_empty(entries,"subject")) && (is_field_empty(entries,"content")) )
	{
	    printf("重新输入!");
  	}
  	else
  	{

    		if (is_field_empty(entries,"to"))
      			dest = strdup(TO);
    		else
      			dest = strdup(cgi_val(entries,"to"));
		
		if (!xstrcmp("*@*.*",dest))
		{
			printf("收件人 %s 不是标准的邮件格式 *@*.*\n",dest);
			exit(-1);
		}
    		name = strdup(cgi_val(entries,"name"));
    		from = strdup(cgi_val(entries,"from"));
    		subject = strdup(cgi_val(entries,"subject"));
		
    		if (dest[0] == '\0')
      			strcpy(dest,WEBADMIN);

		sprintf(command,"%s %s",SENDMAIL,dest);

    		mail = popen(command,"w");
    		if (mail == NULL) 
    		{
      			html_begin("系统出错!");
      			printf("系统出错!");
      			printf("请发信给 %s 。 \r\n",WEBADMIN);
      			printf("<hr>\r\n简单WEB邮件发送程序 v 0.1 . 作者: ");
      			printf("<i>%s</i>.\r\n",WEBADMIN);
      			exit(-1);
      			html_end();
    		}
    		else 
    		{
      			content = strdup(cgi_val(entries,"content"));
      			fprintf(mail,"From: %s (%s)\n",from,name);
      			fprintf(mail,"Subject: %s\n",subject);
      			fprintf(mail,"To: %s\n",dest);
      			fprintf(mail,"X-Sender: %s\n\n",WEBADMIN);
	  		if (REMOTE_ADDR != NULL)
				fprintf(mail,"发送者 IP 地址 %s\n",REMOTE_ADDR);
			// 增加 http 代理 相关环境变量,可判断是否有代理服务器,可显示出非匿名代理的源地址  2003.08.17
  			if (HTTP_X_FORWARDED_FOR != NULL)
				fprintf(mail,"经过代理前IP地址 %s\n",HTTP_X_FORWARDED_FOR);
  			if (HTTP_CLIENT_IP != NULL)
				fprintf(mail,"代理服务器地址 %s\n",HTTP_CLIENT_IP);
      			fprintf(mail,"%s\n\n",content);
      			pclose(mail);
      			html_begin("邮件发送成功");
      			printf("邮件发送成功");
      			printf("你发送了以下的信息:\r\n<pre>\r\n");
      			printf("收信人: %s \r\n",dest);
      			printf("发信人: %s (%s)\r\n",from,name);
      			printf("标 题: %s\r\n\r\n",subject);
      			printf("%s\r\n</pre>\r\n",content);
	  		if (REMOTE_ADDR != NULL)
				printf("发送者 IP 地址 %s<br>\n",REMOTE_ADDR);
			// 增加 http 代理 相关环境变量,可判断是否有代理服务器,可显示出非匿名代理的源地址  2003.08.17
  			if (HTTP_X_FORWARDED_FOR != NULL)
				printf("经过代理前IP地址 %s<br>\n",HTTP_X_FORWARDED_FOR);
  			if (HTTP_CLIENT_IP != NULL)
				printf("代理服务器地址 %s<br>\n",HTTP_CLIENT_IP);
      			printf("谢谢使用!<p>\r\n");
      			printf("<hr>\r\n简单WEB邮件发送程序 v 0.1 . 作者: ");
      			printf("<i>%s</i>.\r\n",WEBADMIN);
      			html_end();
    		}
	}

  	list_clear(&entries);
  	list_clear(&configs);
  	return 0;
}
Example #9
0
int main()
{
  llist entries;
  FILE *mail;
  char command[256] = "/usr/lib/sendmail ";
  char *dest,*name,*email,*subject,*content;

  html_header();
  read_cgi_input(&entries);
  if ( !strcmp("",cgi_val(entries,"name")) &&
      !strcmp("",cgi_val(entries,"email")) &&
      !strcmp("",cgi_val(entries,"subject")) &&
      !strcmp("",cgi_val(entries,"content")) )
    NullForm();
  else {
    if (is_field_empty(entries,"to"))
      dest = newstr(WEBADMIN);
    else
      dest = newstr(cgi_val(entries,"to"));
    name = newstr(cgi_val(entries,"name"));
    email = newstr(cgi_val(entries,"email"));
    subject = newstr(cgi_val(entries,"subject"));
    if (dest[0]=='\0')
      strcpy(dest,WEBADMIN);
    else
      authenticate(dest);
    /* no need to escape_input() on dest, since we assume there aren't
       insecure entries in the authentication file. */
    strcat(command,dest);
    mail = popen(command,"w");
    if (mail == NULL) {
      html_begin("System Error!");
      h1("System Error!");
      printf("Please mail %s and inform\r\n",WEBADMIN);
      printf("the web maintainers that the comments script is improperly\r\n");
      printf("configured. We apologize for the inconvenience<p>\r\n");
      printf("<hr>\r\nWeb page created on the fly by ");
      printf("<i>%s</i>.\r\n",WEBADMIN);
      html_end();
    }
    else {
      content = newstr(cgi_val(entries,"content"));
      fprintf(mail,"From: %s (%s)\n",email,name);
      fprintf(mail,"Subject: %s\n",subject);
      fprintf(mail,"To: %s\n",dest);
      fprintf(mail,"X-Sender: %s\n\n",WEBADMIN);
      fprintf(mail,"%s\n\n",content);
      pclose(mail);
      html_begin("Comment Submitted");
      h1("Comment Submitted");
      printf("You submitted the following comment:\r\n<pre>\r\n");
      printf("From: %s (%s)\r\n",email,name);
      printf("Subject: %s\r\n\r\n",subject);
      printf("%s\r\n</pre>\r\n",content);
      printf("Thanks again for your comments.<p>\r\n");
      printf("<hr>\r\nWeb page created on the fly by ");
      printf("<i>%s</i>.\r\n",WEBADMIN);
      html_end();
    }
  }
  list_clear(&entries);
  return 0;
}