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

📄 http_cgi.c

📁 web_based.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  T C P N E T
 *----------------------------------------------------------------------------
 *      Name:    HTTP_CGI.C
 *      Purpose: HTTP Server CGI Module
 *      Rev.:    V3.20
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *---------------------------------------------------------------------------*/

#include <Net_Config.h>
#include <stdio.h>
#include <string.h>
#include "GlobalVars.h"

/* ---------------------------------------------------------------------------
 *	    client to server programming vars 
 *
 *----------------------------------------------------------------------------*/ 
		 static U8  ucPcnt;               // case2 reapet count

		   U16 g_uiDataCnt;
		   U32 g_uiTotaldatacnt;
//    static U16 g_uiBufofset;
		   U16 g_uiXloop;		   
	static U16 g_uiWrreminder;		 // len % pagesize (512 )
//	static U8  g_ucReminderflag;     // flag for data remaining from last pcnt
		   U16  g_uiPagenumber;
	      // U8  READbuf[5];
	 	   U8 g_ucChksum;
		   U8 g_ucChksumFlag,g_ucSigFail,g_ucWebevent,g_ucNoFile;
/*----------------------------------------------------------------------------*/    
 extern int U0sendchar (char ch);
 extern U8 ChecksumCalc(U8*,U16,U8);
 extern INT8U CheckCMSSign(U8*); 
/* ---------------------------------------------------------------------------
 * The HTTP server provides a small scripting language.
 *
 * The script language is simple and works as follows. Each script line starts
 * with a command character, either "i", "t", "c", "#" or ".".
 *   "i" - command tells the script interpreter to "include" a file from the
 *         virtual file system and output it to the web browser.
 *   "t" - command should be followed by a line of text that is to be output
 *         to the browser.
 *   "c" - command is used to call one of the C functions from the this file.
 *         It may be followed by the line of text. This text is passed to
 *         'cgi_func()' as a pointer to environment variable.
 *   "#' - command is a comment line and is ignored (the "#" denotes a comment)
 *   "." - denotes the last script line.
 *
 * --------------------------------------------------------------------------*/

/* http_demo.c */
//extern U16 AD_in (U32 ch);

/* at_System.c */
extern  LOCALM localm[];
#define LocM   localm[NETIF_ETH]

/* Net_Config.c */
extern struct tcp_info tcp_socket[];
extern U8 const tcp_NumSocks;
extern U8 const http_EnAuth;
extern U8       http_auth_passw[20];

extern BOOL LEDrun;
extern void LED_out (U32 val);
//extern BOOL LCDupdate;
extern U8 lcd_text[2][16+1];
static U8 TempStr[20];
static U8 CardNo[10];
/* Local variables. */
//static U8 P2;
/*
static char const state[][11] = {
   "FREE",
   "CLOSED",
   "LISTEN",
   "SYN_REC",
   "SYN_SENT",
   "FINW1",
   "FINW2",
   "CLOSING",
   "LAST_ACK",
   "TWAIT",
   "CONNECT"};
*/

static U8 passw[12],retyped[12];
/* My structure of CGI status U32 variable. This variable is private for */
/* each HTTP Session and is not altered by HTTP Server. It is only set to  */
/* zero when the cgi_func() is called for the first time.                  */
typedef struct {
   U16 xcnt;
   U16 unused;
                } MY_BUF;
#define MYBUF(p)        ((MY_BUF *)p)
extern U8 lhost_name[16];

/*----------------------------------------------------------------------------
 * HTTP Server Common Gateway Interface Functions
 *---------------------------------------------------------------------------*/

/*--------------------------- cgi_process_var -------------------------------*/

void cgi_process_var (U8 *qs) {
   /* This function is called by HTTP server to process the Querry_String   */
   /* for the CGI Form GET method. It is called on SUBMIT from the browser. */
   /*.The Querry_String.is SPACE terminated.                                */
   U8 *var, stpassw,len;
   int s[4];
   U16 Cntr;
   INT8U *pucPtr;
	memset ( passw, 0, sizeof(passw) );
	memset ( retyped, 0, sizeof(retyped) );
    var = (U8 *)alloc_mem (40);

	stpassw = 0;
  do {
      /* Loop through all the parameters. */
      qs = http_get_var (qs, var, 40);
      /* Check the returned string, 'qs' now points to the next. */
      if (var[0] != 0) {
         /* Returned string is non 0-length. */
			/* Network Configuartion from the file network.cgi */
         if (str_scomp (var, "ip=") == __TRUE) {
            /* My IP address parameter. */
            sscanf ((const S8 *)&var[3], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
            NtwkCfg.wplocalm.IpAdr[0]   = s[0];
            NtwkCfg.wplocalm.IpAdr[1]   = s[1];
            NtwkCfg.wplocalm.IpAdr[2]   = s[2];
            NtwkCfg.wplocalm.IpAdr[3]   = s[3];
            LocM.IpAdr[0]   = s[0];
            LocM.IpAdr[1]   = s[1];
            LocM.IpAdr[2]   = s[2];
            LocM.IpAdr[3]   = s[3];
         }
         else if (str_scomp (var, "msk=") == __TRUE) {
            /* Net mask parameter. */
            sscanf ((const S8 *)&var[4], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
            NtwkCfg.wplocalm.NetMask[0] = s[0];
            NtwkCfg.wplocalm.NetMask[1] = s[1];
            NtwkCfg.wplocalm.NetMask[2] = s[2];
            NtwkCfg.wplocalm.NetMask[3] = s[3];
            LocM.NetMask[0]   = s[0];
            LocM.NetMask[1]   = s[1];
            LocM.NetMask[2]   = s[2];
            LocM.NetMask[3]   = s[3];
         }
         else if (str_scomp (var, "gw=") == __TRUE) {
            /* Default gateway parameter. */
            sscanf ((const S8 *)&var[3], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
            NtwkCfg.wplocalm.DefGW[0]   = s[0];
            NtwkCfg.wplocalm.DefGW[1]   = s[1];
            NtwkCfg.wplocalm.DefGW[2]   = s[2];
            NtwkCfg.wplocalm.DefGW[3]   = s[3];
            LocM.DefGW[0]   = s[0];
            LocM.DefGW[1]   = s[1];
            LocM.DefGW[2]   = s[2];
            LocM.DefGW[3]   = s[3];
         }
         else if (str_scomp (var, "pdns=") == __TRUE) {
            /* Primary DNS parameter. */
            sscanf ((const S8 *)&var[5], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
            NtwkCfg.wplocalm.PriDNS[0]  = s[0];
            NtwkCfg.wplocalm.PriDNS[1]  = s[1];
            NtwkCfg.wplocalm.PriDNS[2]  = s[2];
            NtwkCfg.wplocalm.PriDNS[3]  = s[3];
            LocM.PriDNS[0]   = s[0];
            LocM.PriDNS[1]   = s[1];
            LocM.PriDNS[2]   = s[2];
            LocM.PriDNS[3]   = s[3];
      	 }
         else if (str_scomp (var, "sdns=") == __TRUE) {
            /* Secondary DNS parameter. */
            sscanf ((const S8 *)&var[5], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
            NtwkCfg.wplocalm.SecDNS[0]  = s[0];
            NtwkCfg.wplocalm.SecDNS[1]  = s[1];
            NtwkCfg.wplocalm.SecDNS[2]  = s[2];
            NtwkCfg.wplocalm.SecDNS[3]  = s[3];
            LocM.SecDNS[0]   = s[0];
            LocM.SecDNS[1]   = s[1];
            LocM.SecDNS[2]   = s[2];
            LocM.SecDNS[3]   = s[3];
      	 }
         else if (str_scomp (var, "hname=") == __TRUE) {
           /* Host name parameter. */
          	sscanf ((const S8 *)&var[6], "%s", (INT8U *)NtwkCfg.hostname);
						str_copy ( (U8 *)lhost_name, (U8 *)NtwkCfg.hostname );
				 }
					/* Controller Operational configuration */
         else if (str_scomp (var, "pw=") == __TRUE) {
            			/* Password parameter. */
            			sscanf ((const S8 *)&var[3], "%s", (INT8U *)&passw);
						stpassw |= 1;
				 }
         else if (str_scomp (var, "pw2=") == __TRUE) {
            			/* Password parameter. */
            			sscanf ((const S8 *)&var[4], "%s", (INT8U *)&retyped);
						stpassw |= 2;
				 }
         else if (str_scomp (var, "tid=") == __TRUE) {
            			/* Terminal ID parameter. */
            			sscanf ((const S8 *)&var[4], "%d", &s[0]);
						NtwkCfg.uiTID = s[0];
				 }
	  			/* Reader Mode Configuration - CSNR or Employee Code */
					else if (str_scomp (var, "rdrtype=") == __TRUE) {
						/* Reader Type parameter */
						sscanf ((const S8 *)&var[8], "%s", (INT8U *)&TempStr);
						if (strcmp ( (const char *)&TempStr, "CSNR" ) == 0)
							NtwkCfg.ucReadEmpCodeFlag = 0;
						else
						{
							if( g_ucKeysLoaded == 1 )
								NtwkCfg.ucReadEmpCodeFlag = 1;
						}
					}
					else if (str_scomp (var, "display=") == __TRUE) {
						/* Display Mode parameter */
						sscanf ((const S8 *)&var[8], "%s", (INT8U *)&TempStr);
						if (strcmp ( (const char *)&TempStr, "DISPLAY" ) == 0)
							NtwkCfg.ucDisplayModeFlag = 1;
						else
							NtwkCfg.ucDisplayModeFlag = 0;
					}
				else if (str_scomp (var, "df=") == __TRUE) {
					/* Data Format in Bits parameter */
					sscanf ((const S8 *)&var[3], "%s", (INT8U *)&TempStr);
					if (strcmp ( (const char *)&TempStr, "YES" ) == 0)
					{
						NtwkCfg.ucReaderFormat = 35;
						g_ucaReaderDataLen_0 = WEIGAND_35_BIT;
						g_ucaReaderDataLen_1 = WEIGAND_35_BIT;
					}
					else if (strcmp ( (const char *)&TempStr, "NO" ) == 0)
					{
						NtwkCfg.ucReaderFormat = 0;
						pucPtr = g_ucaFlash_buf;
				  	// Write packet data into SPI Flash memory
						ReadConfig( READER_PAGE_NO, READER_PAGE_START, g_ucaFlash_buf, ( READER_LIST_SIZE * READER_RECORD_SIZE ) );
						g_ucaReaderDataLen_0 = ( ( Reader * )pucPtr )->ucDataFormat;
						pucPtr+= READER_RECORD_SIZE;
						g_ucaReaderDataLen_1 = ( ( Reader * )pucPtr )->ucDataFormat;
					}
				}
			/* User Configuration from the file usrcfg.cgi */
			else if (str_scomp (var, "fname=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[6], "%s", (U8 *)&TempStr);
				str_copy( (U8 *)&UserConfig.ucFname, (U8 *)&TempStr);
				UserConfig.ucStatus = 0;
			}
			else if (str_scomp (var, "mname=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[6], "%c", &UserConfig.ucMname);
			}
			else if (str_scomp (var, "lname=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[6], "%s", (U8 *)&TempStr);
				str_copy( (U8 *)&UserConfig.ucLname, (U8 *)&TempStr);
			}
			else if (str_scomp (var, "dept=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[5], "%s", (U8 *)&TempStr);
				str_copy( (U8 *)&UserConfig.ucDept, (U8 *)&TempStr);
			}
			else if (str_scomp (var, "cardno=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[7], "%x", &s[0]);
				UserConfig.ulCardNo = s[0];
			}
			else if (str_scomp (var, "tz1=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[4], "%d", &s[0]);
				UserConfig.ucTimezone1 = s[0];
			}
			else if (str_scomp (var, "tz2=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[4], "%d", &s[0]);
				UserConfig.ucTimezone2 = s[0];
			}
			else if (str_scomp (var, "expdt=") == __TRUE) {
				/* Timezone1 From Time Hours */
				sscanf ((const S8 *)&var[6], "%s", (INT8U *)&ucaTempDate);
				SetExpiryDate ( ucaTempDate, (INT8U *)&UserConfig.ucExpiryDate ); 
				/* Scan the User Profile Status Array to find a matching profile or free slot */
				if ( USERCOUNT < USER_LIST_SIZE )
				{
					for ( Cntr = 0; Cntr < USER_LIST_SIZE; Cntr++ )
					{
						if ( UserList[Cntr] == UserConfig.ulCardNo )		// Existing Profile
						{
							WriteConfig ( (PROFILE_START_PAGE + (Cntr/10)), ((Cntr%10) * sizeof(UserConfig)), (INT8U *)&UserConfig, sizeof(UserConfig) ); 
							UserList[Cntr] = UserConfig.ulCardNo;
							break;
						}
						else if ( UserList[Cntr] == 0 )		// New User Profile
						{
							WriteConfig ( (PROFILE_START_PAGE + (Cntr/10)), ((Cntr%10) * sizeof(UserConfig)), (INT8U *)&UserConfig, sizeof(UserConfig) ); 
							UserList[Cntr] = UserConfig.ulCardNo;
							USERCOUNT += 1;
							break;
						}
					}
				}
				else
					str_copy ( (U8 *)&ErrorMsg, "MAXIMUM NUMBER OF USER PROFILES EXCEEDED" );
			}
				else if (str_scomp (var, "mcardno=") == __TRUE) {
				/* Card Number to Modify */
				sscanf ((const S8 *)&var[8], "%x", &g_ulCardNo);
				for ( Cntr = 0; Cntr < USER_LIST_SIZE; Cntr++ )
				{
					if ( UserList[Cntr] == g_ulCardNo )
						break;
				}
				if ( Cntr < USER_LIST_SIZE )
				{
					ReadConfig ( (PROFILE_START_PAGE + (Cntr/10)), ((Cntr%10) * sizeof(UserConfig)), (INT8U *)&UserConfig, sizeof(UserConfig) ); 
					g_ucModifyProfile = 1;
				}
				else
					g_ucModifyProfile = 0;	
			}
			else if (str_scomp (var, "dcardno=") == __TRUE) {

⌨️ 快捷键说明

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