⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system_ctl.c

📁 嵌入式linux的一个cgi网站
💻 C
字号:
#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_CAM_NTID                         18
#define ID_CAM_NTPD                        19
#define ID_CAM_NTSER                      20
#define ID_SAF_MOD                          25


static config_item ** items;
static int config_list[] = {18,19,20,25};         //for system_ctl

char java[]="
<!DOCTYPE HTML PUBLIC\"-//W3C//DTD HTML 4.0 Transitional//EN\">\r\n
<HTML><HEAD><TITLE>System Status</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\">
<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
}
.style3 {
	COLOR: #999999
}
</STYLE>

<META content=\"MSHTML 6.00.6000.16414\" name=GENERATOR></HEAD>";
	
void system_ctl(char **postvars, int form_method)
{
	int config_num = sizeof(config_list)/sizeof(int);
	int i;
	int temp_int;
	int r_fd, w_fd;
	
	char *CAM_NTPD;
	char *SAF_MOD;

	items = init_config_item(items, config_num, config_list);
	//r_fd = open_read_fifo();
	
	printf("%s\n", java);

	DEBUGMSG(0, ("form_method=%d: %s, %s\n", form_method, postvars[0], postvars[1]));

	if(form_method == POST)
	{
		DEBUGMSG(0, ("<body><center><BR><font style=\"font-size:12pt\" face=\"Arial\">"));
		GetConfValues(config_list, items, config_num);

		for (i=0; postvars[i]; i+= 2)
		{
			DEBUGMSG(0, ("DEBUG: [%s] = [%s]<br>", postvars[i], postvars[i+1]));

			if(!strcmp(postvars[i], "CAM_NTPD"))
				item_update(ID_CAM_NTPD, items, config_num, postvars[i+1]);

			if(!strcmp(postvars[i], "SAF_MOD"))
			{
				item_update(ID_SAF_MOD, items, config_num, postvars[i+1]);
			}
		}

		if(SaveTempConfig(config_num, items))
		{
		/*
			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 class=bodyBg bgColor=white leftMargin=30 topMargin=24 rightMargin=30>\n");
	printf("<P class=style1>系统设置</P>\n");
	//printf("<FORM name=system_ctl action=\"/system_ctl.cgi\" method=post target=msgFrame onsubmit=\"return CheckForm()\">\n");
	printf("<FORM name=system_ctl action=\"/system_ctl.cgi\" method=post target=msgFrame>\n");
	printf("<TABLE width=\"100%\"><TBODY>\n");
	printf("<TR><TD><TABLE borderColor=#dae3eb cellSpacing=0 cellPadding=2 width=\"100%\" border=1>\n");
	printf("<TBODY><TR bgColor=#cccccc><TD class=topTitle vAlign=top noWrap colSpan=2><DIV align=left>\n");
	printf("<STRONG>系统信息</STRONG></DIV></TD></TR>\n");

	//18 ID_CAM_NTID
	printf("<TR><TD width=\"24%\">入网ID</TD><TD width=\"76%\"> %s </TD></TR>\n", getdata(ID_CAM_NTID, items, config_num));

	//20 ID_CAM_NTSER
	printf("<TR><TD>入网服务器(注册服务器)地址</TD><TD>%s</TD></TR>\n", getdata(ID_CAM_NTSER, items, config_num));

	//19 ID_CAM_NTPD
	CAM_NTPD = getdata(19, items, config_num);
	printf(" <TR><TD>入网Password</td><td>\n");
	printf("<input type=password name=CAM_NTPD size=15 maxlength=15 value=%s></TD></TR>\n", CAM_NTPD);
	
	//25 ID_SAF_MOD
	printf("<TR><TD><P>安全模式</P></TD>\n");
	printf("<TD><SELECT  name=SAF_MOD>\n");

	if(SAF_MOD = getdata(ID_SAF_MOD, items, config_num))
	{
		//temp_int = atoi(SAF_MOD);
		if(!strcmp(SAF_MOD, "1"))
		{
			printf("<option  value=\"1\" selected>安全模式\n");
			printf("<option  value=\"0\">普通模式\n");
		}
		else
		{
			printf("<option  value=\"1\">安全模式\n");
			printf("<option  value=\"0\" selected>普通模式\n");
		}
	}
	printf("</select></td></tr></TBODY></TABLE>\n");
	printf("<P align=left>\n");
	//printf("<input type=submit onclick=\"return CheckForm();\" class=button value=\"应用\">\n");
	printf("<input type=submit class=button onclick=\"return CheckForm();\" value=\"应用\"  >\n");
	printf("<input type=reset class=button value=\"清除\"></p>\n");
	printf("</TD></TR></TBODY></TABLE></FORM></BODY></HTML>\n");

	// javascript layout
	{
		char jsp[]="
		<script language=JavaScript> 
		<!--  
		function CheckForm()
		{
			if(document.system_ctl.CAM_NTPD.value==\"\"||document.system_ctl.CAM_NTPD.value==null){
				alert(\"入网Password不能为空!\");
				document.system_ctl.CAM_NTPD.focus();
				return false;
			}
		}
		//--> 
		</script>";

		printf("%s\n", jsp);
	}
	
	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
    system_ctl(postvars, form_method);

    //htmlFooter();
    cleanUp(form_method, getvars, postvars);


    fflush(stdout);
    exit(0);

}  // end of main






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -