maintenance.c
资源名称:cgi-web.rar [点击查看]
上传用户:sxdewei
上传日期:2014-06-02
资源大小:67k
文件大小:5k
源码类别:
嵌入式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"
- #include "fifo.h"
- #define DEBUG 0
- #define ID_LOC_ADMNM 21
- #define ID_LOC_ADMPD 22
- #define ID_LOC_USRNM 23
- #define ID_LOC_USRPD 24
- static config_item ** items;
- //static int config_list[] = {21,22,23,24};
- //static char *config_name[] = {"LOC_ADMNM", "LOC_ADMPD", "LOC_USRNM", "LOC_USRPD"};
- void maintenance(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 data_string[MAX_LINE_LENGTH];
- char java[]=
- "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">rn
- <HTML><HEAD><TITLE>Maintenance</TITLE>
- <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>";
- 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)
- {
- //RESTART DEFAULT_CFG FIMAGEii
- for (i=0; postvars[i]; i+= 2)
- {
- if(!strcmp(postvars[i], "RESTART"))
- {
- memset(data_string, 0, MAX_LINE_LENGTH);
- strcpy(data_string, "reboot");
- if(system(data_string)<0)
- {
- ;
- }
- }
- if(!strcmp(postvars[i], "DEFAULT_CFG"))
- {
- w_fd = open_write_fifo();
- send_cmd(w_fd, SET_DEFAULT_CFG);
- close_write_fifo(w_fd);
- }
- }
- }
- //GetConfValues(config_list, items, config_num);
- printf("<BODY class=bodyBg bgColor=white leftMargin=30 topMargin=24 rightMargin=30><P class=style1>系统维护</P>n");
- printf("<TABLE width="100%"><TBODY><TR><TD height=319><TABLE style="BORDER-COLLAPSE: collapse" borderColor=#dae3eb cellSpacing=0 cellPadding=0 width="100%" border=1><TBODY>n");
- printf("<TR bgColor=#cccccc><TD class=topTitle vAlign=top noWrap colSpan=2><STRONG>系统维护</STRONG></TD></TR>n");
- printf("<FORM name=RestartForm action="/maintenance.cgi" method=post target=msgFrame>n");
- printf("<INPUT type=hidden value=1 name=RESTART>n");
- printf("<TR><TD colSpan=2 height=35><INPUT type=submit value=重新启动 width=75> 重启ipcam。</TD></TR></FORM>n");
- printf("<FORM name=DefaultForm action="/cgi-bin/maintenance.cgi" method=post target=msgFrame>n");
- printf("<INPUT type=hidden value=1 name=DEFAULT_CFG>n");
- printf("<TR><TD colSpan=2 height=35><INPUT type=submit value=恢复设置 width=75> 恢复出厂设置。</TD></TR></FORM>n");
- printf("<FORM name=UpgradeForm action="/cgi-bin/maintenance.cgi" method=post target=msgFrame encType=multipart/form-data>n");
- printf("<INPUT type=hidden value=1 name=UPDATEFIRMWARE>n");
- printf("<TR bgColor=#cccccc> <TD class=subTitle noWrap colSpan=2><DIV align=left>系统升级</DIV></TD></TR>n");
- printf("<TR><TD noWrap colSpan=2>用最新的固件升级ipcam</TD></TR>n");
- printf("<TR><TD noWrap width="56%" height=35>指定升级文件: <INPUT type=file name=FIMAGE> 然后点击</TD>n");
- printf("<TD class=button noWrap align=left width="44%" height=35><INPUT class=btnNormal type=button value=执行升级 name=Upgrade width="75"></TD></TR>n");
- printf("<TR><TD colSpan=2><B>注意:</B>在升级过程中,请勿切断ipcam的电源。ipcam将在升级完成后自动重启 (正常过程约需3分钟) 。</TD></TR></FORM>n");
- printf("</TBODY></TABLE></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
- maintenance(postvars, form_method);
- //htmlFooter();
- cleanUp(form_method, getvars, postvars);
- fflush(stdout);
- exit(0);
- } // end of main