timing.c
资源名称:cgi-web.rar [点击查看]
上传用户:sxdewei
上传日期:2014-06-02
资源大小:67k
文件大小:11k
源码类别:
嵌入式Linux
开发平台:
Unix_Linux
- #include <stdio.h>
- #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 "cgivars.h"
- #include "htmllib.h"
- #include "config_phase.h"
- #include "sysconf.h"
- #define DEBUG 0
- #define ID_FIXSET 136
- #define ID_FIXTM 137
- #define ID_FIXTY 138
- #define ID_SMTPSENDSEL 139
- #define ID_SMTPSENDADDR 140
- #define ID_FTPSENDSEL 142
- #define ID_FTPSENDDIR 143
- #define ID_FIXSVFLG 145
- #define ID_FIXSDTM 146
- static config_item ** items;
- static int config_list[] = {136,137,138,139,140,142,143,145,146};
- static char *config_name[] = {"FIXSET","FIXTM","FIXTY","SMTPSENDSEL","SMTPSENDADDR","FTPSENDSEL","FTPSENDDIR",
- "FIXSVFLG","FIXSDTM"};
- void timing(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;
- char t_start[10], t_end[10], t_set[20];
- char java[] ="
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">rn
- <HTML><HEAD>
- <META http-equiv=Pragma content=no-cache>
- <META http-equiv=Content-Type content="text/html; charset=gb2312">
- <SCRIPT language=JavaScript src="js/javascript.js"></SCRIPT>
- <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>";
- char jsp[] = "
- <script language=JavaScript>
- <!--
- function isTime(str)
- {
- var reg=/^(\d{2})\:(\d{2})$/
- if(arr=str.match(reg)){
- if(parseInt(arr[1])>23){return false;}
- if(parseInt(arr[2])>59){return false;}
- }else
- {
- return false;
- }
- return true;
- }
- function checkTime()
- {
- var element ;
- element = document.getElementById('T_START');
- if( isTime(element.value) == false){
- alert("定时操作时间格式不对! ");
- return false;
- }
- element = document.getElementById('T_END');
- if( isTime(element.value) == false){
- alert("定时操作时间格式不对! ");
- return false;
- }
- return true;
- }
- //-->
- </script> ";
- //r_fd = open_read_fifo();
- items = init_config_item(items, config_num, config_list);
- printf("%sn", java);
- printf("%sn",jsp);
- // If we got post, write it into flash
- if(form_method == POST)
- {
- GetConfValues(config_list, items, config_num);
- memset(t_set, 0, 20);
- for (i=0; postvars[i]; i+= 2)
- {
- if(!strcmp(postvars[i], "T_START"))
- {
- memcpy(t_set, postvars[i+1], 5);
- t_set[5] = '-';
- }
- if(!strcmp(postvars[i], "T_END"))
- {
- memcpy(t_set+6, postvars[i+1], 5);
- }
- }
- item_update(ID_FIXTM, items, config_num, t_set);
- 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>n");
- printf("<P><SPAN class=style1>定时操作</SPAN></P><TABLE width="100%"><TBODY>n");
- printf("<TR><TD noWrap><FORM name=timing action="/timing.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>定时操作</STRONG></TD></TR>n");
- //FIXSET
- printf(" <TR><TD noWrap width="15%"> <DIV align=left>启用定时操作</DIV></TD>n");
- printf("<TD colSpan=2><SELECT id=en_timerA onchange="check_disable('A',this.value);" size=1 name=FIXSET>n");
- if(temp_string = getdata(ID_FIXSET, items, config_num))
- {
- temp_int = atoi(temp_string);
- if( 1 == temp_int )
- {
- printf("<OPTION value="1" selected>是</OPTION>n");
- printf("<OPTION value="0">否</OPTION></SELECT></TD></TR>n");
- }
- else
- {
- printf("<OPTION value="1">是</OPTION>n");
- printf("<OPTION value="0" selected>否</OPTION></SELECT></TD></TR>n");
- }
- }
- //FIXTM
- printf("<TR><TD noWrap rowSpan=2>时间 (hh:mm)</TD><TD noWrap align=middle><DIV align=left>n");
- if(temp_string = getdata(ID_FIXTM, items, config_num))
- {
- memset(t_start, 0, 10);
- memset(t_end, 0, 10);
- memcpy(t_start, temp_string, 5);
- memcpy(t_end, temp_string+6, 5);
- printf("<INPUT maxLength=8 size=9 name=T_START value=%s> — n", t_start);
- printf("<INPUT maxLength=8 size=9 name=T_END value=%s></DIV></TD> n", t_end);
- printf("<TD noWrap align=middle width="36%"><DIV align=left>n");
- printf("<INPUT disabled maxLength=8 size=9 name=Schedule_Action_Start_2> — n");
- printf("<INPUT disabled maxLength=8 size=9 name=Schedule_Action_End_2> </DIV></TD></TR>n");
- printf("<TR><TD noWrap align=middle><DIV align=left>n");
- printf("<INPUT disabled maxLength=8 size=9 name=Schedule_Action_Start_3> — n");
- printf("<INPUT disabled maxLength=8 size=9 name=Schedule_Action_End_3> </DIV></TD>n");
- printf("<TD noWrap align=middle><DIV align=left>n");
- printf("<INPUT disabled maxLength=8 size=9 name=Schedule_Action_Start_4> — n");
- printf("<INPUT disabled maxLength=8 size=9 name=Schedule_Action_End_4> </DIV></TD></TR>n");
- }
- //FIXTY
- printf("<tr><TD noWrap width="15%"><DIV align=left>报警类型</DIV></TD>n");
- printf("<TD colSpan=2><SELECT id=en_timerA0 onchange="check_disable('A',this.value);" size=1 name=FIXTY>n");
- if(temp_string = getdata(ID_FIXTY, items, config_num))
- {
- temp_int = atoi(temp_string);
- if( 0 == temp_int )
- {
- printf("<OPTION value="0" selected>图片</OPTION> n");
- printf("<OPTION value="1">视频</OPTION></SELECT> </TD> </tr>n");
- }
- else
- {
- printf("<OPTION value="0">图片</OPTION> n");
- printf("<OPTION value="1" selected>视频</OPTION></SELECT> </TD> </tr>n");
- }
- }
- //FTPSENDSEL
- printf("<TR><TD noWrap>传送到FTP服务器 </TD> <TD noWrap align=left colspan=2> <DIV align=left>n");
- printf("<SELECT id=ftp_send_timerA size=1 name=FTPSENDSEL>n");
- if(temp_string = getdata(ID_FTPSENDSEL, items, config_num))
- {
- temp_int = atoi(temp_string);
- if( 0 == temp_int )
- {
- printf("<OPTION value="0" selected>否</OPTION> n");
- printf("<OPTION value="1">是</OPTION></SELECT> </DIV></TD><TD noWrap></TD><TD noWrap></TD></TR>n");
- }
- else
- {
- printf("<OPTION value="0">否</OPTION> n");
- printf("<OPTION value="1" selected>是</OPTION></SELECT> </DIV></TD><TD noWrap></TD><TD noWrap></TD></TR>n");
- }
- }
- //FTPSENDDIR
- printf(" <TR><TD noWrap>FTP目录: </TD> <TD align=left colspan=2>n");
- if(temp_string = getdata(ID_FTPSENDDIR, items, config_num))
- printf("<INPUT id=ftp_timer_A0 maxLength=40 name=FTPSENDDIR size=40 value=%s></TD> <TD noWrap></TD><TD noWrap></TD></TR>n", temp_string);
- else
- printf("<INPUT id=ftp_timer_A0 maxLength=40 name=FTPSENDDIR size=40></TD> <TD noWrap></TD><TD noWrap></TD></TR>n");
- //SMTPSENDSEL
- printf("<TR><TD noWrap>发送邮件</TD> <TD align=left colspan=2><DIV align=left>n");
- printf("<SELECT id=timer_mail_select_A name=SMTPSENDSEL size=1> n");
- if(temp_string = getdata(ID_SMTPSENDSEL, items, config_num))
- {
- temp_int = atoi(temp_string);
- if( 0 == temp_int )
- {
- printf("<OPTION value="0" selected>否</OPTION> n");
- printf("<OPTION value="1">是</OPTION></SELECT> </DIV></TD><TD noWrap></TD><TD noWrap></TD></TR>n");
- }
- else
- {
- printf("<OPTION value="0">否</OPTION> n");
- printf("<OPTION value="1" selected>是</OPTION></SELECT> </DIV></TD><TD noWrap></TD><TD noWrap></TD></TR>n");
- }
- }
- //SMTPSENDADDR
- printf("<TR><TD noWrap>邮件接收者1</TD> <TD noWrap colSpan=2>n");
- if(temp_string = getdata(ID_SMTPSENDADDR, items, config_num))
- printf("<INPUT id=Mail_Rcver1A maxLength=40 size=40 name=SMTPSENDADDR value=%s> </TD></TR>n", temp_string);
- else
- printf("<INPUT id=Mail_Rcver1A maxLength=40 size=40 name=SMTPSENDADDR> </TD></TR>n");
- // 2 no use
- printf("<TR><TD noWrap>邮件接收者2</TD> <TD noWrap colSpan=2>n");
- printf("<INPUT id=Mail_Rcver2A disabled maxLength=40 size=40 name=nouse_SMTPSENDADDR> </TD></TR>n");
- //FIXSVFLG
- printf("<TR><TD noWrap>存储到SD卡</TD> <TD align=left colspan=2><DIV align=left>n");
- printf("<SELECT id=timer_cf_storageA disabled size=1 name=FIXSVFLG>n");
- if(temp_string = getdata(ID_FIXSVFLG, items, config_num))
- {
- temp_int = atoi(temp_string);
- if( 0 == temp_int )
- {
- printf("<OPTION value="0" selected>否</OPTION> n");
- printf("<OPTION value="1">是</OPTION></SELECT> </DIV></TD><TD noWrap colSpan=2></TD></tr>n");
- }
- else
- {
- printf("<OPTION value="0">否</OPTION> n");
- printf("<OPTION value="1" selected>是</OPTION></SELECT> </DIV></TD><TD noWrap colSpan=2></TD></tr>n");
- }
- }
- //FIXSDTM
- printf("<TR><TD noWrap>SD卡存储间隔(秒):</TD> <TD noWrap colSpan=2>n");
- if(temp_string = getdata(ID_FIXSDTM, items, config_num))
- printf("<INPUT id=ftp_timer_A1 disabled name=FIXSDTM size=9 value=%s></TD> <TD noWrap></TD><TD noWrap></TD></tr>n", temp_string);
- else
- printf("<INPUT id=ftp_timer_A1 disabled name=FIXSDTM size=9></TD> <TD noWrap></TD><TD noWrap></TD></tr>n");
- printf("</TBODY></TABLE><P align=left><INPUT type=submit value=应用 onclick="return checkTime();"><INPUT type=reset value=清除></P>n");
- printf("</FORM></TD></TR></TBODY></TABLE></BODY></HTML>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
- timing(postvars, form_method);
- //htmlFooter();
- cleanUp(form_method, getvars, postvars);
- fflush(stdout);
- exit(0);
- } // end of main