mail.c
资源名称:cgi-web.rar [点击查看]
上传用户:sxdewei
上传日期:2014-06-02
资源大小:67k
文件大小:6k
源码类别:
嵌入式Linux
开发平台:
Unix_Linux
- #include <string.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <getopt.h>
- #include <errno.h>
- #include <sys/ioctl.h>
- #include <linux/config.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <stdio.h>
- #include "cgivars.h"
- #include "htmllib.h"
- #include "config_phase.h"
- #include "sysconf.h"
- #define DEBUG 0
- #define ID_SMTPSERADD 40
- #define ID_MALSENDADD 41
- #define ID_SMTPCHECKFLG 42
- #define ID_SMTPCHECKUSR 43
- #define ID_SMTPCHECKPWD 44
- static config_item ** items;
- static int config_list[] = {40,41,42,43,44};
- static char *config_name[] = {"SMTPSERADD","MALSENDADD","SMTPCHECKFLG","SMTPCHECKUSR","SMTPCHECKPWD"};
- char java[] =
- "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <HTML><HEAD>
- <META http-equiv=Expires content="Tue, 1 Jan 1980 2:00:00 GMT">
- <META http-equiv=Pragma content=no-cache>
- <META http-equiv=Cache-Control content="no-cache,must revalidate">
- <META http-equiv=Content-Type content="text/html; charset=gb2312">
- <STYLE type=text/css>BODY {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- TD {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- FORM {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- OPTION {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- TEXTAREA {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- P {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- OL {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- INPUT {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- SELECT {
- FONT-SIZE: 10pt; FONT-FAMILY: Arial
- }
- .style1 {
- FONT-WEIGHT: bold; FONT-SIZE: 14pt
- }
- </STYLE>
- <META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>";
- void mail(char **postvars, int form_method)
- {
- int config_num = sizeof(config_list)/sizeof(int);
- int i;
- int r_fd, w_fd;
- int temp_int;
- char *temp_string;
- //r_fd = open_read_fifo();
- items = init_config_item(items, config_num, config_list);
- printf("%sn", java);
- // If we got post, write it into flash
- if(form_method == POST)
- {
- GetConfValues(config_list, items, config_num);
- item_update(ID_SMTPCHECKFLG , items,config_num, "0");
- if(SaveConfig(postvars, items, config_list, config_name, config_num))
- {/*
- w_fd = open_write_fifo();
- notify_config(w_fd);
- close_write_fifo(w_fd);
- read_fifo(r_fd);
- */
- }
- }
- GetConfValues(config_list, items, config_num);
- printf("<BODY leftMargin=30 topMargin=24 rightMargin=30><P class=style1>电子邮件</P><TABLE width="100%">n");
- printf("<TBODY><TR> <TD><FORM name=mail action="/mail.cgi" method=post target=msgFrame>n");
- printf("<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#dae3eb cellSpacing=0 cellPadding=0 width="100%" border=1>n");
- printf("<TBODY><TR bgColor=#cccccc><TD colSpan=3><STRONG>SMTP设置</STRONG></TD></TR>n");
- //SMTPSERADD
- printf(" <TD class=oddItem noWrap width="38%">电子邮件服务器(SMTP):</TD><TD class=oddItem width="28%">n");
- if(temp_string = getdata(ID_SMTPSERADD, items, config_num))
- printf("<INPUT class=fieldNetAddr name=SMTPSERADD size=20 value=%s></TD><TD class=oddItem noWrap width="34%">(主机名或IP地址)</TD></TR>n", temp_string);
- else
- printf("<INPUT class=fieldNetAddr name=SMTPSERADD size=20></TD><TD class=oddItem noWrap width="34%">(主机名或IP地址)</TD></TR>n");
- //MALSENDADD
- printf("<TR><TD class=oddItem noWrap>发件人电子邮件地址:</TD><TD class=oddItem>n");
- if(temp_string = getdata(ID_MALSENDADD, items, config_num))
- printf("<INPUT class=fieldNetAddr name=MALSENDADD size=20 value=%s></TD><TD class=oddItem></TD></TR>n", temp_string);
- else
- printf("<INPUT class=fieldNetAddr name=MALSENDADD size=20></TD><TD class=oddItem></TD></TR>n");
- //SMTPCHECKFLG
- if(temp_string = getdata(ID_SMTPCHECKFLG, items, config_num))
- {
- temp_int = atoi(temp_string);
- if(1 == temp_int)
- printf("<TR><TD class=oddItem noWrap>电子邮件需要验证<INPUT id=Mail_Auth_alian type=checkbox CHECKED value="1" name=SMTPCHECKFLG></TD>n");
- else
- printf("<TR><TD class=oddItem noWrap>电子邮件需要验证<INPUT id=Mail_Auth_alian type=checkbox value="1" name=SMTPCHECKFLG></TD>n");
- }
- printf("<TD class=oddItem></TD><TD class=oddItem></TD></TR>n");
- //SMTPCHECKUSR
- printf("<TR><TD class=oddItem noWrap>发件人电子邮件用户名称:</TD>n");
- if(temp_string = getdata(ID_SMTPCHECKUSR, items, config_num))
- printf("<TD class=oddItem><INPUT name=SMTPCHECKUSR value=%s> </TD><TD class=oddItem></TD></TR>n", temp_string);
- else
- printf("<TD class=oddItem><INPUT name=SMTPCHECKUSR> </TD><TD class=oddItem></TD></TR>n");
- //ID_SMTPCHECKPWD
- printf("<TR><TD class=oddItem noWrap>发件人电子邮件验证密码:</TD>n");
- if(temp_string = getdata(ID_SMTPCHECKPWD, items, config_num))
- printf("<TD class=oddItem><INPUT type=password name=SMTPCHECKPWD value=%s> </TD><TD class=oddItem></TD></TR>n", temp_string);
- else
- printf("<TD class=oddItem><INPUT type=password name=SMTPCHECKPWD> </TD><TD class=oddItem></TD></TR>n");
- printf("</TBODY></TABLE>n");
- printf("<P align=left><INPUT type=submit value=应用><INPUT type=reset value=清除></P></FORM></TD></TR>n");
- printf("<TR><TD></TD></TR></TBODY></TABLE>n");
- free_config_item(items, config_num);
- //close_read_fifo();
- }
- ////////////////////////////////////////////////////////////////////////////
- // Function: main
- ////////////////////////////////////////////////////////////////////////////
- int main(void)
- {
- char **postvars = NULL; // POST request data repository
- char **getvars = NULL; // GET request data repository
- int form_method; // POST = 1, GET = 0
- // CGI part start here
- adminCheck();
- form_method = getRequestMethod();
- if(form_method == POST)
- {
- // getvars = getGETvars();
- postvars = getPOSTvars();
- }
- else if(form_method == GET)
- {
- getvars = getGETvars();
- }
- // CGI start here, set COM port
- mail(postvars, form_method);
- //htmlFooter();
- cleanUp(form_method, getvars, postvars);
- fflush(stdout);
- exit(0);
- } // end of main