📄 mailsend.c
字号:
/* Mail send application. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/time.h>#include <time.h>#include "parse.h"#define SENDMAIL "/usr/lib/sendmail"#define ALLOW "/export/home/00/ht1/htdocs/.allow"main(int argc, char *argv[]) {/* Local loop and argument counters. */ register int i,k=0;/* Indices of input arguments of interest. */ int dest,name,msg,ret,subj;/* Store length of data block. */ int len;/* File pointer for examining allow file. */ FILE *fp;/* Mail Pipe Name*/ char mail_pname[128];/* Pointer for mail pipe. */ FILE *mp;/* Array for form input arguments. */ Pair inputs[10];/* Strings used to store entries from allowed file. */ char allowed[16],allowed_addr[256];/* Date generation variables. */ char date[64]; time_t clock_sent; struct tm *time_sent;/* Generate content type message for server. */ printf("Content-type: text/html%c%c",10,10);/* Start response document. */ printf("<HTML>%c<HEAD>%c",10,10);/* Make sure a post type request was made; otherwise, generate an error. */ if(strcmp(getenv("REQUEST_METHOD"),"POST")) { printf("<TITLE>%s Error Screen</TITLE>%c</HEAD>%c<BODY>%c", *argv,10,10,10); printf("This script should be referenced with a METHOD of POST.\n"); printf("</BODY>%c</HTML>%c",10,10); exit(1); }/* Make sure that the input data is of the correct type. */ if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { printf("<TITLE>%s Error Screen</TITLE>%c</HEAD>%c<BODY>%c", *argv,10,10,10); printf("This script can only be used to decode form results.\n"); printf("</BODY>%c</HTML>%c",10,10); exit(2); }/* Get the length of the input block from the environment. */ len = atoi(getenv("CONTENT_LENGTH"));/* Retrieve and decode the input data from the data block. */ for(i=0; len && (!feof(stdin));i++) { inputs[i].attrib = build(256,'=',&len); inputs[i].value = build(1024,'&',&len); } k=i;/* Find the indices of the input data of interest. */ for(i=0;i<k;i++){ if(!strcmp("destination",inputs[i].attrib)) dest=i; if(!strcmp("name",inputs[i].attrib)) name=i; if(!strcmp("message",inputs[i].attrib)) msg=i; if(!strcmp("address",inputs[i].attrib)) ret=i; if(!strcmp("subject",inputs[i].attrib)) subj=i; }/* Open the allow file to determine if a valid destination was selected. */ if((fp=fopen(ALLOW,"r"))==(FILE *)NULL){ printf("This script could not open the list of available e-mail addresses.\n"); printf("Contact the web administrator for further information.%c",10); printf("%s file.",ALLOW); printf("</BODY>%c</HTML>%c",10,10); exit(3); }/* Find if the logical address specified maps to an actual email address. */ while(fscanf(fp,"%s %[^\n]",allowed,allowed_addr) != EOF) if(!strcmp(inputs[dest].value,allowed)) break; if(feof(fp)){ fclose(fp); printf("<TITLE>%s Error Screen</TITLE>%c</HEAD>%c<BODY>%c",*argv,10,10,10); printf("<STRONG>Destination not Allowed.</STRONG>%c",10); printf("<P>Contact the web administrator for further information.%c",10); printf("</BODY>%c</HTML>%c",10,10); exit(4); } fclose(fp);/* Generate pipe command and open pipe. */ sprintf(mail_pname,"%s %s",SENDMAIL,allowed_addr); if((mp=popen(mail_pname,"w")) == (FILE *)NULL){ printf("<TITLE>%s Error Screen</TITLE>%c</HEAD>%c<BODY>%c",*argv,10,10,10); printf("<STRONG>Could not open temporary mail file.</STRONG>%c",10); printf("</BODY>%c</HTML>%c",10,10); exit(5); }/* Send mail information to pipe. */ fprintf(mp,"Reply-To: %s (%s)%c",inputs[ret].value,inputs[name].value,10); fprintf(mp,"From: %s (%s)%c",inputs[ret].value,inputs[name].value,10); fprintf(mp,"To: %s%c",allowed_addr,10); fprintf(mp,"Subject: %s%c%c",inputs[subj].value,10,10); fprintf(mp,"\tMessage Sent via Web Mail Access from "); fprintf(mp,"Server: %s\n",getenv("SERVER_NAME")); fprintf(mp,"Mail sent from user at SITE %s (%s).\n\n",getenv("REMOTE_HOST"), getenv("REMOTE_ADDR")); fprintf(mp,"Sender's Message:\n%s\n",inputs[msg].value); pclose(mp);/* Generate local date. */ clock_sent = time(0); time_sent = localtime(&clock_sent); strftime(date,64,"%B %e, %Y",time_sent);/* Generate HTML 3.0 response page. */ printf("<TITLE>Mail Response Page</TITLE>%c",10); printf("<LINK REV=\"destination\" HREF=\"mailto:%s\">%c",allowed_addr,10); printf("</HEAD>%c<BODY>%c<HR>%c",10,10,10); printf("<H1 ALIGN=\"center\">Mail Response Page</H1>%c<HR SIZE=5>%c",10,10);/* Present message. */ printf("To: %s<BR>%c",inputs[dest].value,10); printf("From: %s (%s)<BR>%c",inputs[name].value,inputs[ret].value,10); printf("Subject: %s<BR>%c",inputs[subj].value,10); printf("<HR>%c<PRE>%s</PRE>%c",10,inputs[msg].value,10);/* Generate Signature. */ printf("<HR>%c<H5>Message Sent by Server on %s.<H5>%c",10,date,10); printf("</BODY>%c</HTML>%c",10,10); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -