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; }
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; }