www.pudn.com > cgi-web.rar > sysinfo.c, change:2007-08-31,size:14977b


#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)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD height=\"24\">IP»ñȡģʽ</TD><TD height=\"24\">¾²Ì¬É趨 </TD></TR>\n"); 
		else 
			printf("<TR><TD height=\"24\">IP»ñȡģʽ</TD><TD height=\"24\">DHCP </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD height=\"24\">IP»ñȡģʽ</TD><TD height=\"24\">δָ¶¨ </TD></TR>\n"); 
 
	//IP 
	if(temp_string=getdata(ID_IP, items, config_num)) 
		printf("<TR><TD>IP µØÖ·</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>IP µØÖ·</TD><TD>NULL</TD></TR>\n"); 
 
	//SUBMASK 
	if(temp_string=getdata(ID_SUBMASK, items, config_num)) 
		printf("<TR><TD>×ÓÍøÑÚÂë</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>×ÓÍøÑÚÂë</TD><TD>NULL</TD></TR>\n"); 
 
	//GAWADD 
	if(temp_string=getdata(ID_GAWADD, items, config_num)) 
		printf("<TR><TD>Íø¹ØIPµØÖ·</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>Íø¹ØIPµØÖ·</TD><TD>NULL</TD></TR>\n"); 
 
	//DNSADD1 
	if(temp_string=getdata(ID_DNSADD1, items, config_num)) 
		printf("<TR><TD>DNS·þÎñÆ÷IP-1</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>DNS·þÎñÆ÷IP-1</TD><TD>NULL</TD></TR>\n"); 
	 
	//DNSADD2 
	if(temp_string=getdata(ID_DNSADD2, items, config_num)) 
		printf("<TR><TD>DNS·þÎñÆ÷IP-2</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>DNS·þÎñÆ÷IP-2</TD><TD>NULL</TD></TR>\n"); 
 
	//PPOEFLAG 
	if(temp_string=getdata(ID_PPOEFLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD height=\"24\">PPPoE״̬</TD><TD height=\"24\">ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD height=\"24\">PPPoE״̬</TD><TD height=\"24\">δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD height=\"24\">PPPoE״̬</TD><TD height=\"24\">δÆôÓà </TD></TR>\n"); 
 
	//PPOE IP: to do: phase the config files 
	if(temp_int == 1){ 
      memset(pppoeIP ,0, 16); 
	 getPPPOEIP(pppoeIP); 
	} 
  
	printf("<TR><TD>PPPoE IP</TD><TD>%s</TD></TR>\n",pppoeIP) ; 
	 
	//SMTPSERADD 
	if(temp_string=getdata(ID_SMTPSERADD, items, config_num)) 
		printf("<TR><TD>E-mail·þÎñÆ÷µØÖ·</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>E-mail·þÎñÆ÷µØÖ·</TD><TD>NULL</TD></TR>\n"); 
 
	 
	//FTPSERADD 
	if(temp_string=getdata(ID_FTPSERADD, items, config_num)) 
		printf("<TR><TD>FTP·þÎñÆ÷µØÖ·</TD><TD>%s</TD></TR>\n", temp_string); 
	else 
		printf("<TR><TD>FTP·þÎñÆ÷µØÖ·</TD><TD>NULL</TD></TR>\n"); 
 
	printf("<TR bgColor=#cccccc><TD colSpan=2><STRONG>ÊÓÆµ¸Å¿ö</STRONG></TD></TR>\n"); 
 
	//CAM_RESO 
	if(temp_string=getdata(ID_CAM_RESO, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>µ±Ç°Í¼Ïñ´óС</TD><TD>704x576</TD></TR>\n"); 
		else if( 2== temp_int) 
			printf("<TR><TD>µ±Ç°Í¼Ïñ´óС</TD><TD>352x288</TD></TR>\n"); 
		else 
			printf("<TR><TD>µ±Ç°Í¼Ïñ´óС</TD><TD>176x144</TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>µ±Ç°Í¼Ïñ´óС</TD><TD>δÉ趨 </TD></TR>\n"); 
 
	//CAM_IMGQ 
	if(temp_string=getdata(ID_CAM_IMGQ, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int || 2==temp_int) 
			printf("<TR><TD>µ±Ç°Í¼ÏñÖÊÁ¿</TD><TD>µÍ</TD></TR>\n"); 
		else if( 3== 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>δÉ趨 </TD></TR>\n"); 
	 
 
	//ALMINFFLAG   
	printf("<TR bgColor=#cccccc><TD colSpan=2><STRONG>±¨¾¯ÉèÖøſö</STRONG></TD></TR>\n"); 
 
	if(temp_string=getdata(ID_ALMINFFLAG, 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>δÆôÓà </TD></TR>\n"); 
           
	//ALMWIRDFLAG 
	if(temp_string=getdata(ID_ALMWIRDFLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>ÓÐÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD>ÓÐÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>ÓÐÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
 
	//ALMWIRD2FLAG 
	if(temp_string=getdata(ID_ALMWIRD2FLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>ÓÐÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD>ÓÐÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>ÓÐÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
 
	//ALMWIRLFLAG 
	if(temp_string=getdata(ID_ALMWIRLFLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë1 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
 
	//ALMWIRL2FLAG 
	if(temp_string=getdata(ID_ALMWIRL2FLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë2 ״̬</TD><TD>ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë2 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë2 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
 
	//ALMWIRL3FLAG 
	if(temp_string=getdata(ID_ALMWIRL3FLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë3 ״̬</TD><TD>ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë3 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë3 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
 
	//ALMWIRL4FLAG 
	if(temp_string=getdata(ID_ALMWIRL4FLAG, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if( 1 == temp_int) 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë4 ״̬</TD><TD>ÒÑÆôÓÃ</TD></TR>\n"); 
		else 
			printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë4 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
	} 
	else 
		printf("<TR><TD>ÎÞÏß±¨¾¯ÊäÈë4 ״̬</TD><TD>δÆôÓà </TD></TR>\n"); 
 
	printf("<TR bgColor=#cccccc><TD colSpan=2><STRONG>SD¿¨¸Å¿ö</STRONG></TD></TR>\n"); 
	 
	//CAM_SDDIF 
	//to do: add the code 
    printf("<TR><TD>×ÜÈÝÁ¿</TD><TD>ÐèÌí¼Ó´úÂë </TD></TR>\n");    
	printf("<TR><TD>ÒÑÓÃ</TD><TD>ÐèÌí¼Ó´úÂë </TD></TR>\n");  
	printf("<TR><TD>Ê£Óà</TD><TD>ÐèÌí¼Ó´úÂë </TD></TR>\n");  
 
	printf("</TBODY></TABLE></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 
    char *user = NULL; 
	 
    // CGI part start here 
    adminCheck(); 
    form_method = getRequestMethod(); 
 
    if(form_method == POST) 
    { 
       // getvars = getGETvars(); 
        postvars = getPOSTvars(); 
    } 
    else if(form_method == GET) 
    { 
        getvars = getGETvars(); 
    } 
 
   if( user = getenv("REMOTE_USER")) 
   	 trace(user); 
    // CGI start here, set COM port 
    sysinfo(postvars, form_method); 
 
    //htmlFooter(); 
    cleanUp(form_method, getvars, postvars); 
 
 
    fflush(stdout); 
    exit(0); 
 
}  // end of main