📄 sysinfo.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 <time.h>
#include "cgivars.h"
#include "htmllib.h"
#include "config_phase.h"
#include "sysconf.h"
#define DEBUG 0
#define ID_CAM_RESO 3
#define ID_CAM_IMGQ 4
#define ID_CAM_SDDIF 12
#define ID_CAM_DIVN 13
#define ID_CAM_DIVS 14
#define ID_CAM_HRDV 15
#define ID_CAM_SOFV 16
#define ID_FCAM_FUNCS 17
#define ID_SAF_MOD 25
#define ID_GAPFALG 26
#define ID_IP 27
#define ID_SUBMASK 28
#define ID_GAWADD 29
#define ID_DNSADD1 31
#define ID_DNSADD2 32
#define ID_PPOEFLAG 34
#define ID_SMTPSERADD 40
#define ID_FTPSERADD 45
#define ID_ALMINFFLAG 64
#define ID_ALMWIRDFLAG 74
#define ID_ALMWIRD2FLAG 84
#define ID_ALMWIRLFLAG 94
#define ID_ALMWIRL2FLAG 104
#define ID_ALMWIRL3FLAG 114
#define ID_ALMWIRL4FLAG 124
static config_item ** items;
static int config_list[] = {3,4,12,13,14,15,16,17,25,26,27,28,29,31,32,34,40,45,64,74,84,94,104,114,124};
static char *config_name[] = {"CAM_RESO","CAM_IMGQ","CAM_SDDIF","CAM_DIVN","CAM_DIVS","CAM_HRDV",
"CAM_SOFV","FCAM_FUNCS","SAF_MOD","GAPFALG","IP","SUBMASK","GAWADD",
"DNSADD1","DNSADD2", "PPOEFLAG","SMTPSERADD","FTPSERADD",
"ALMINFFLAG","ALMWIRDFLAG","ALMWIRD2FLAG","ALMWIRLFLAG","ALMWIRL2FLAG",
"ALMWIRL3FLAG","ALMWIRL4FLAG"};
void getPPPOEIP(char *ipadd){
char msgbuff[256];
int fd;
int count;
int len;
char *prt_start =NULL ,*prt_end =NULL;
memset(msgbuff ,'\0',256);
//memset(msbuff,0,16);
system("ifconfig ppp0 > /var/ifconfigpppoedata 2>&1");
fd = open("/var/ifconfigpppoedata" ,O_RDONLY);
if( fd == -1)
return ;
//printf("can not open /var/ifconfigdata");
count = read(fd ,msgbuff ,255);
close(fd);
unlink("/var/ifconfigpppoedata");
if(count < 1)
return ;
prt_start = strstr(msgbuff ,"inet addr:");
if(prt_start ==NULL)
return ;
prt_start+=10;
prt_end = strstr(prt_start," ");
if( prt_end == NULL)
return ;
len = prt_end - prt_start;
strncpy(ipadd,prt_start,len);
}
void sysinfo(char **postvars, int form_method)
{
int config_num = sizeof(config_list)/sizeof(int);
int i;
int r_fd, w_fd;
int temp_int, day, hour, min, sec;
char *temp_string;
time_t the_time;
struct tm *tm_ptr;
FILE *temp_fd;
char data_string[MAX_LINE_LENGTH];
char pppoeIP[16];
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>";
//r_fd = open_read_fifo();
items = init_config_item(items, config_num, config_list);
printf("%s\n", java);
// If we got post, write it into flash
#if 0
if(form_method == POST)
{
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);
}
}
#endif
GetConfValues(config_list, items, config_num);
printf("<BODY class=bodyBg bgColor=white leftMargin=30 topMargin=24 rightMargin=30>\n");
printf("<P class=style1>系统状态</P><TABLE width=\"100%\"><TBODY><TR><TD>");
printf("<TABLE borderColor=#dae3eb cellSpacing=0 cellPadding=2 width=\"100%\" border=1><TBODY>\n");
printf("<TR bgColor=#cccccc><TD class=topTitle vAlign=top noWrap colSpan=2><DIV align=left>\n");
printf("<STRONG>系统概况</STRONG></DIV></TD></TR>\n");
//CAM_DIVN
if(temp_string=getdata(ID_CAM_DIVN, items, config_num))
printf("<TR><TD width=\"24%\">产品名称</TD><TD width=\"76%\">%s</TD></TR>\n", temp_string);
else
printf("<TR><TD width=\"24%\">产品名称</TD><TD width=\"76%\">NULL</TD></TR>\n");
//CAM_DIVS
if(temp_string=getdata(ID_CAM_DIVS, items, config_num))
printf("<TR><TD>产品序列号</TD><TD>%s</TD></TR>\n", temp_string);
else
printf("<TR><TD>产品序列号</TD><TD>NULL</TD></TR>\n");
//CAM_HRDV
if(temp_string=getdata(ID_CAM_HRDV, items, config_num))
printf("<TR><TD>硬件版本</TD><TD>%s</TD></TR>\n", temp_string);
else
printf("<TR><TD>硬件版本</TD><TD>NULL</TD></TR>\n");
//CAM_SOFV
if(temp_string=getdata(ID_CAM_SOFV, items, config_num))
printf("<TR><TD>固件版本</TD><TD>%s</TD></TR>\n", temp_string);
else
printf("<TR><TD>固件版本</TD><TD>NULL</TD></TR>\n");
//FCAM_FUNCS
if(temp_string=getdata(ID_FCAM_FUNCS, items, config_num))
printf("<TR><TD>产品功能</TD><TD>%s</TD></TR>\n", temp_string);
else
printf("<TR><TD>产品功能</TD><TD>NULL</TD></TR>\n");
//SAF_MOD
if(temp_string=getdata(ID_SAF_MOD, items, config_num))
{
temp_int = atoi(temp_string);
if( 1 == temp_int)
printf("<TR><TD>安全模式</TD><TD>开启</TD></TR>\n");
else
printf("<TR><TD>安全模式</TD><TD>关闭</TD></TR>\n");
}
else
printf("<TR><TD>安全模式</TD><TD>NULL</TD></TR>\n");
//time
memset(data_string, 0, MAX_LINE_LENGTH);
time(&the_time);
tm_ptr = localtime(&the_time);
sprintf(data_string, "%04d-%02d-%02d %02d:%02d:%02d\n", tm_ptr->tm_year+1900, tm_ptr->tm_mon+1, tm_ptr->tm_mday,
tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
printf("<TR><TD>系统时间</TD><TD><DIV id=sys_time>%s</DIV></TD></TR>\n", data_string);
//uptime
memset(data_string, 0, MAX_LINE_LENGTH);
temp_fd = fopen("/proc/uptime", "rb");
if(temp_fd >= 0)
{
fgets(data_string, MAX_LINE_LENGTH, temp_fd);
temp_string = strtok(data_string, ".");
temp_int = atoi(temp_string);
day = temp_int/(3600*24);
temp_int = temp_int%(3600*24);
hour = temp_int/3600;
temp_int = temp_int%3600;
min = temp_int/60;
sec = temp_int%60;
memset(data_string, 0, MAX_LINE_LENGTH);
sprintf(data_string, "%d天%d小时%d分钟%d秒", day, hour, min, sec);
printf("<TR><TD>系统运行时间</TD><TD><DIV id=up_time>%s</DIV></TD></TR>\n", data_string);
}
//memery
//
//GAPFALG
printf("<TR bgColor=#cccccc><TD colSpan=2><STRONG>网络概况</STRONG></TD></TR>\n");
if(temp_string=getdata(ID_GAPFALG, items, config_num))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -