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

📄 web.c

📁 采用ajax技术
💻 C
📖 第 1 页 / 共 4 页
字号:
#include "web.h"
/*************************************************************************
* 名称:ProcessWeb
* 函数原型:uint8 ProcessWeb(uint8 *buf)
* 功能:处理WEB请求
* 入口参数:
            buf :  web请求数据
*
* 出口参数:执行结果
* 使用说明:
* 创建日期:
* 作者:Henry
**************************************************************************/
uint8 ProcessWeb(tcplist *tcpbuf)
{
	uint8  nKind = 100,i=0;
	uint8 tcpid = tcpbuf->id;	
	http httpList[10] ={0};
	uint8 listLen =0;
	
	memset((uint8*)httpList,0,10*sizeof(http));
	nKind = ParseHttp((uint8*)tcpbuf->buf,httpList,&listLen);
	
	if(!CheckSuperUserIp((uint8*)tcpbuf->ip,SuperUserIp))
	{
		if(CheckSuperUserIp((uint8*)tcpbuf->ip,OldSuperIp) && IsSuperUser >1)
		{
			if(IsSuperUser >1)
			{
				IsSuperUser--;
				memset(OldSuperIp,255,4);
			}
			
			web_login(tcpid);
			return TRUE;
		}
		
		if(ClientHost[0] != 255 && !CheckUserIp((uint8*)tcpbuf->ip) && listLen==0)
		{
			web_login(tcpid);
			return TRUE;
		}
		
		if(ClientHost[0] != 255 && nLogin	
			&& !CheckLoginUser((uint8*)tcpbuf->ip,tcpid,httpList))
			return FALSE;
			
		if(ClientHost[0] == 255 && nLogin &&
			!web_loginCheck((char *)httpList[0].value,(char *)httpList[1].value, tcpid))
		{
			web_login(tcpid);
			return TRUE;
		}
		
		if((ClientHost[0] == 255 && nLogin==0 && nDisplayHome==0) 
			|| (nDisplayHome==2 &&  nLogin==0 ) 
			|| (nDisplayHome==1 && nKind != 15))
			nKind = 100;


	}
	
	switch(nKind)
	{
		case 3:
			send( tcpid,(uint8*)httpImg ,strlen((char*)httpImg), 0 );
			send( tcpid,(uint8*) logo_gif,982,0);
			break;
		
		case 4://InitMenu.js
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) &InitMenu_js,tcpid);
			break;
		case 5://objTree.js
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) &objTree_js,tcpid);
			break;
		case 6://Tree.htm
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) &Tree_htm,tcpid);
			break;
		case 7://VersionShow
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) ver,tcpid);
			break;
		case 8://Default configuration
			if(listLen >0)
			{
				RestoreDef();
				WDTC = 0x0000001;
				nResetFlag = 0xAA;
			}
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) DefSet,tcpid);
			}
			break;
		case 9://Redir.js
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) Redir_js,tcpid);
			break;
		case 10://common.js
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) common_js,tcpid);
			break;
		case 11://snmp.js
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) snmp_js,tcpid);
			break;
		case 12://Comm.htm
			if(listLen >0)
				ParseWebRequest(4,httpList,tcpid);
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) Comm_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			break;
		case 13://Trap.htm
			if(listLen >0)
				ParseWebRequest(5,httpList,tcpid);
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) Trap_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			break;
		case 14://AddComm
			break;
		case 15: //Login
			if(web_loginCheck((char *)&httpList[0].value[0],(char *)&httpList[1].value[0], tcpid))
			{
				if(CheckSuperUser((uint8*)tcpbuf->ip,tcpid,httpList))
				{
					if(IsSuperUser==1)
					{
						memcpy(OldSuperIp,SuperUserIp,4);
					}
					
					IsSuperUser++;
					memcpy(SuperUserIp,(uint8*)tcpbuf->ip,4);
					
				}
				else
				{
					for(i=0;i<4;i++)
						ClientHost[i] = tcpbuf->ip[i];
						
					ClientHost[4] = 0;
				}
				
				nTimeout = OSTimeGet() ;
				nDisplayHome =2;
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) index,tcpid);
				nLogin = TRUE;
			}
			else
				web_loginErr(tcpid);
			break;
		case 16://Logout
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) Logout,tcpid);
			}
			else
			{
				if(CheckUserIp((uint8*)tcpbuf->ip))
				{
					memset(ClientHost,255,4);
					ClientHost[4]=0;
				}
				
				if(CheckSuperUserIp((uint8*)tcpbuf->ip,SuperUserIp))
				{
					IsSuperUser=0;
					memset(SuperUserIp,255,4);
				}
					
				if(IsSuperUser==0 && ClientHost[0]==255)
				{
					nLogin = FALSE;
					LogoutFlag = FALSE;
					nDisplayHome = FALSE;
					nTimeout = 0;
				}
			}
			break;
		case 17://PwCfgShow
			if(listLen >0)
				ParseWebRequest(1,httpList,tcpid);
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) userinfo,tcpid);
				nTimeout = OSTimeGet() ;
			}
			break;
		case 18://GetUserInfo
			ParseWebRequest(0,httpList,tcpid);
			break;
		case 19://NetCfgShow
			if(listLen >0)
				if(strcmp((char*)httpList[0].name,"temp")==0)
					ParseWebRequest(2,httpList,tcpid);
				else
					ParseWebRequest(3,httpList,tcpid);
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) netinfo,tcpid);
				nTimeout = OSTimeGet() ;
			}
			break;
		case 20://Misc.htm
			if(listLen >0)// && strcmp((char*)&httpList[0].name,"timeout")==0)
			{
				ParseWebRequest(6,httpList,tcpid);
			}
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) misc,tcpid);
				nTimeout = OSTimeGet() ;
			}
			break;
		case 21://Mac
			if(listLen >0)
				ParseWebRequest(15,httpList,tcpid);
			else
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) macinfo,tcpid);
				nTimeout = OSTimeGet() ;
			}
			break;
		case 23://upload.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) upload,tcpid);
			}
			else
			{
				#ifdef __DEBUG
					Uart0SendStr((uint8 *)&"\r\nUpdate Image file");
				#endif
				
				tcpbuf->flag=10;
				web_Upload(httpList);
			}
			break;
		case 24:	//box.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) box_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(7,httpList,tcpid);
				
			break;
		
		case 25:	//bandwidth.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(bandwidth_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(8,httpList,tcpid);
				
			break;
		case 26: //loopback.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(loopback_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(9,httpList,tcpid);
			break;
		case 27: //parameter.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(parameter_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(10,httpList,tcpid);
			break;
		
		case 28: //vlantable.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(vlantable_htm,tcpid);
				nTimeout = OSTimeGet() ;
				memset(VlanPos,0,2);
			}
			else
				ParseWebRequest(18,httpList,tcpid);
			break;
		case 29: //vlanconfig.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(vlanconfig_htm,tcpid);
				nTimeout = OSTimeGet() ;
				memset(VlanListPos,0,2);
			}
			else
				ParseWebRequest(19,httpList,tcpid);
			break;
		
		case 30: //vcg.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(vcg_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(11,httpList,tcpid);
			break;
		case 31: //gfp.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(gfp_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(12,httpList,tcpid);
			break;
		case 32: //clock.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(clock_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(13,httpList,tcpid);
			break;
		case 33: //error.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient(error_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
				ParseWebRequest(14,httpList,tcpid);
			break;
		case 34: //mode.htm
			SendToClient((uint8*)&"<p><h1>Reserved</h1></p>",tcpid);
			break;
		
		case 35: //reset.htm
		case 22://restart
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) reset_htm,tcpid);
			}
			else
			{
				ParseWebRequest(16,httpList,tcpid);
				DelayNS(2);
				restartsys(StrToInt(httpList[0].value));
			}
			break;
		case 36://parsexml.js
			send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
			SendToClient((uint8*) parsexml_js,tcpid);
			break;
		
		case 37://limit.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) limit_htm,tcpid);
				nTimeout = OSTimeGet() ;
			}
			else
			{
				if(strncmp((char*)httpList[0].name,"setting",7)==0
					&& httpList[0].value[0]=='1') 
				{
					SetLimitValue(httpList);
					strcpy(httpList[0].name,"query");
					httpList[0].value[0] ='0';
				}
				
				ParseWebRequest(7,httpList,tcpid);
			}
			
			break;
		case 38://mask.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) mask_htm,tcpid);
			}
			else
				ParseWebRequest(20,httpList,tcpid);
				
			break;
		case 39://capability.htm
			if(listLen ==0)
			{
				send( tcpid,(uint8*)httpHead ,strlen((char*)httpHead), 0 );
				SendToClient((uint8*) capability_htm,tcpid);
			}
			else
				ParseWebRequest(21,httpList,tcpid);
				
			break;
		
		default:
			web_login(tcpid);
	}

	return TRUE;
}
/*************************************************************************
* 名称:uint8 web_Upload(http *list)
* 函数原型:uint8 web_Upload(http *list)
* 功能:升级image
* 入口参数:
*
* 出口参数:
* 使用说明:
* 创建日期:
* 作者:Henry
**************************************************************************/
uint8 web_Upload(http *list)
{
	uint8 buf[8] ={0xAA,0xBB,0xCC,0xDD,0,0,0,0};
	
	if(strcmp((char*)list[0].name,"update")==0 
		&& list[0].value[0] == '1')
	{
		ISendStr(AT24C01,0x30, buf, 8);
		DelayNS(5);
		WDTC = 0x0000001;
		nResetFlag = 0xAA;
		return 1;
	}
	
	return 0;	
}
/*************************************************************************
* 名称:ParseWebRequest
* 函数原型:ParseWebRequest(uint8 type,http *list,uint8 tcpid)
* 功能:解析web请求
* 入口参数:
*
* 出口参数:
* 使用说明:
* 创建日期:
* 作者:Henry
**************************************************************************/
void ParseWebRequest(uint8 type,http *list,uint8 tcpid)
{
	uint8 buf[1000]={0},temp[10]={0};
	int i=0,pos=-1,page=1;
	memset(buf,0,1000);
	strcpy((char*)&buf,XMLHEAD);
	
	switch(type)
	{
		case 0://GetUserInfo
			GetResponse((char*)&buf,"kind","0");
			GetResponse((char*)&buf,"username",(char*)&mGlobalInf.pUserName);
			break;
		case 1:
			if(strcmp(list[1].value,(char*)&mGlobalInf.pUserPw) == 0)
			{
				GetResponse((char*)&buf,"kind","2");
				memset((char*)&mGlobalInf.pUserName,0,12);
				memset((char*)&mGlobalInf.pUserPw,0,12);
				strcpy((char*)&mGlobalInf.pUserName,(char*)list[0].value);
				strcpy((char*)&mGlobalInf.pUserPw,(char*)list[2].value);
				//ModifyParameter(1,0);
			}
			else
				GetResponse((char*)&buf,"kind","1");
			break;
		case 2://GetNetInfo
			GetResponse((char*)&buf,"kind","0");
			GetNetInfo(buf);
			break;
		case 3://SetNetInfo
			GetIp((uint8 *)mGloablCfg.pLocalIp,(uint8 *)&list[0].value[0]);
			GetIp((uint8 *)mGloablCfg.pLocalSubmark,(uint8 *)&list[1].value[0]);
			GetIp((uint8 *)mGloablCfg.pLocalGW,(uint8 *)&list[2].value[0]);
			
			if(web_NetSet())
				GetResponse((char*)&buf,"kind","2");
			else
				GetResponse((char*)&buf,"kind","1");
			break;
		case 4://Comm.htm	
			GetResponse((char*)&buf,"kind","0");
			if(strcmp((char*)list[0].value,"AddComm")==0)
			{
				web_CommAdd(&list[1]);
				
				//ModifyParameter(1,0);
			}
			else if(strcmp((char*)list[0].value,"DelComm")==0)
			{
				web_CommDel(&list[1]);
				//ModifyParameter(1,0);
			}
			
			GetCommInfo(buf);
			
			break;
		case 5://Trap.htm	
			GetResponse((char*)&buf,"kind","1");
			
			if(strcmp((char*)list[0].value,"AddTrap")==0)
			{
				web_TrapIpAdd(&list[1]);
				//ModifyParameter(1,0);
			}
			else if(strcmp((char*)list[0].value,"DelTrap")==0)
			{
				web_TrapIpDel(&list[1]);
				//ModifyParameter(1,0);
			}
			
			GetTrapInfo(buf);
			break;
		case 6://Misc
			if(strcmp((char*)list[0].name,"getop")==0)
				GetResponse((char*)&buf,"kind","1");
			else
			{
				GetResponse((char*)&buf,"kind","0");
				nLogout = StrToInt(list[0].value);
				memset(temp,0,10);
				temp[0]=0xAA;
				temp[1]=nLogout;
				ISendStr(AT24C01,0x20, temp, 8);
				DelayNS(5);
				
			}
			
			if(nLogout==0)
				GetResponse((char*)&buf,"op","The option is disable.");
			if(nLogout==50)
				GetResponse((char*)&buf,"op","The option is After 5 min logout.");
			if(nLogout==100)
				GetResponse((char*)&buf,"op","The option is After 10 min logout.");
			if(nLogout==200)
				GetResponse((char*)&buf,"op","The option is After 20 min logout.");
				
			break;
		case 7://box.htm
			if(strncmp((char*)list[0].name,"query",5)==0
				&& strncmp((char*)list[1].name,"local",5)==0) 

⌨️ 快捷键说明

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