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

📄 cgi_show.c

📁 VIA VT6524 8口网管交换机源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:    cgi_show.c
 *
 * Purpose:
 *
 * Author:  Jenda Jao
 *
 * Date:    Jan 08, 2002
 *
 * Functions:
 *
 * Revision History:
 *
 */


#include "version.h"
#include "weblib.h"
#include "str.h"
#if !defined(__BITOP_H__)
#include "bitop.h"
#endif
#include "cfgstr.h"
#include "allpages.h"
#include "piportmp.h"
#include "piport.h"
#include "swsys.h"
#include "pidef.h"
#include "pimsg.h"
#include <stdio.h> // for sprintf




/*---------------------  Static Definitions  ------------------------*/
#define s_apszStrTbl  ((char**)&WEBg_SCgiInfo)    // share memory buffer in order to save ram

/*---------------------  Static Types  ------------------------------*/

/*---------------------  Static Macros  -----------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/
static char* psz;
static DIRECT_MEMTYPE_CODE char s_szTrColor[] = " bgcolor=skyblue";

#ifdef __ASIC_VT6526
DIRECT_MEMTYPE_CODE char s_szPageList[] = "\
<STYLE type=\"text/css\">\n\
BODY {font-family:Arial}\n\
A:link,A:active,A:visited {text-decoration:none;color:blue}\n\
A:hover {text-decoration:underline;color:blue}\n\
</STYLE>\n\
<BASE target=main>\
<IMG src=logo.jpg>\
<P>\
<LI><A HREF=ShowPortSts>Port Status</A>\
<LI><A HREF=ShowPortCfg>Port Configuration</A>\
<LI><A HREF=ShowTrkCfg>Trunk Configuration</A>\
<LI><A HREF=ShowVlanCfg>VLAN Configuration</A>\
<LI><A HREF=ShowSnfCfg>Port Monitoring Configuration</A>\
<LI><A HREF=ShowQosCfg>QoS Configuration</A>\
<LI><A HREF=ShowRateCfg>Bandwidth Control</A>\
<LI><A HREF='javascript:show()' target=_self>Misc Operation</A>\
<UL id=sub style=\"display:none;font-size=80%\">\
<LI><A HREF=ShowMiscCfg>Advanced Switch Configuration</A>\
<LI><A HREF=ShowAdmCfg>Password Setting</A>\
<LI><A HREF=WriteDefault onclick=\"return confirm('All user configuration will be reset to default!\\nAnd the system will be reboot.')\">Restore System Default Setting</A>\
<LI><A HREF=Reboot onclick=\"return confirm('Sure?')\">Reboot System</A>\
<LI><A HREF=ShowSysInfo>System Information</A>\
<LI><A HREF=ShowIpCfg>IP Configuration</A>\
</UL>\
<LI><A HREF=Logout target=_top>Logout</A>\
<SCRIPT LANGUAGE=javascript>\n\
x=0\n\
function show()\n\
{\n\
x=!x\n\
obj=document.getElementById(\"sub\")\n\
if (x)\n\
obj.style.display=\"BLOCK\"\n\
else\n\
obj.style.display=\"NONE\"\n\
}\n\
</SCRIPT>";
#else   // for VT6524 heavychen
DIRECT_MEMTYPE_CODE char s_szPageList[] = "\
<STYLE type=\"text/css\">\n\
BODY {font-family:Arial}\n\
A:link,A:active,A:visited {text-decoration:none;color:blue}\n\
A:hover {text-decoration:underline;color:blue}\n\
</STYLE>\n\
<BASE target=main>\
<IMG src=logo.jpg>\
<P>\
<LI><A HREF=ShowPortSts>Port Status</A>\
<LI><A HREF=ShowPortCfg>Port Configuration</A>\
<LI><A HREF=ShowTrkCfg>Trunk Configuration</A>\
<LI><A HREF=ShowVlanCfg>VLAN Configuration</A>\
<LI><A HREF=ShowSnfCfg>Port Monitoring Configuration</A>\
<LI><A HREF=ShowQosCfg>QoS Configuration</A>\
<LI><A HREF='javascript:show()' target=_self>Misc Operation</A>\
<UL id=sub style=\"display:none;font-size=80%\">\
<LI><A HREF=ShowMiscCfg>Advanced Switch Configuration</A>\
<LI><A HREF=ShowAdmCfg>Password Setting</A>\
<LI><A HREF=WriteDefault onclick=\"return confirm('All user configuration will be reset to default!\\nAnd the system will be reboot.')\">Restore System Default Setting</A>\
<LI><A HREF=Reboot onclick=\"return confirm('Sure?')\">Reboot System</A>\
<LI><A HREF=ShowSysInfo>System Information</A>\
<LI><A HREF=ShowIpCfg>IP Configuration</A>\
</UL>\
<LI><A HREF=Logout target=_top>Logout</A>\
<SCRIPT LANGUAGE=javascript>\n\
x=0\n\
function show()\n\
{\n\
x=!x\n\
obj=document.getElementById(\"sub\")\n\
if (x)\n\
obj.style.display=\"BLOCK\"\n\
else\n\
obj.style.display=\"NONE\"\n\
}\n\
</SCRIPT>";
#endif


/*---------------------  Static Functions  --------------------------*/

/*---------------------  Export Variables  --------------------------*/




static BYTE s_byGenHtmlHeader(PSTR pszBuf, PSTR pszTitle)
{
    return sprintf(pszBuf, "%s<BODY><CENTER><H2>%s</H2>", g_szHtmlOkHeader, pszTitle);
}


static BYTE s_byAddFormTable(PSTR pszBuf, PSTR szAction, BOOL bBorder)
{
    return sprintf(pszBuf, "<FORM method=GET name=f action=%s><TABLE%s", szAction,
                   (bBorder) ? " border=1>" : "><TR><TD>");
}


static BYTE s_byAddFormTableEnd(PSTR pszBuf)
{
    return sprintf(pszBuf, "</TABLE><P><INPUT type=submit value=Apply></FORM>");

}


UINT16 CGI_wShowMain(void)
{
    return sprintf(HTTPg_abyOutBuf, "%s<TITLE>S1908D Web Smart</TITLE><FRAMESET cols=\"240,*\" frameborder=0><FRAME src=ShowList noresize marginwidth=0><FRAME src=ShowLogin name=main></FRAMESET>", g_szHtmlOkHeader);
}


UINT16 CGI_wShowList(void)
{
    return sprintf(HTTPg_abyOutBuf, "%s%s", g_szHtmlOkHeader, s_szPageList);
}

DIRECT_MEMTYPE_CODE char s_szLogin[] = "<FORM method=GET action=/Login><P>Username:<INPUT type=text name=U><P>Password:<INPUT type=password name=P><P><INPUT type=submit value=Login></FORM><SCRIPT language=javascript>if (top.frames.length!=0) top.location=self.location</SCRIPT>";
UINT16 CGI_wShowLogin(void)
{
    return sprintf(HTTPg_abyOutBuf, "%s<BODY><CENTER><H2><BR><BR>"STRING_LOGIN_TITLE"<BR><BR></H2>%s", g_szHtmlOkHeader,
                   (WEBg_bLoginEbl && (*WEBg_szLoginID == 0)) ? s_szLogin : "Welcome");
}


UINT16 CGI_wShowPortSts(void)
{
    UINT8   byPortId;

    // Get port status
    PIPORT_vGetPortStatus(WEBg_pSPortStatus);

    psz = HTTPg_abyOutBuf + s_byGenHtmlHeader(HTTPg_abyOutBuf, g_strPortStatus);
    psz += sprintf(psz, "<TABLE border=1><TR ALIGN=center><TH>Port<TH>Enable<TH>Link Status<TH>Spd/Dpx<TH>Flow Control</TR>");

    for (byPortId = 0; byPortId < SWITCH_PORT_NUM; byPortId++)
    {
        // Put begining of a table entry and port name
        psz += sprintf(psz, "<TR%s><TD>%s", ((byPortId & 0x01) ? "" : s_szTrColor), g_aszPortNameTable[byPortId]);

#ifndef __ASIC_VT6524
        // Put port enable status
        psz += sprintf(psz, "<TD>%s", g_aszEnDisCfg[WEBg_pSPortStatus->aSPortStatus[byPortId].f2Enable]);
        // Put port link status
        psz += sprintf(psz, "<TD>%s", g_aszPortLinkDownUp[WEBg_pSPortStatus->aSPortStatus[byPortId].f2LinkUp]);
        // Put speed & duplex status
        psz += sprintf(psz, "<TD>%s", g_aszSpdDpxCfg[WEBg_pSPortStatus->aSPortStatus[byPortId].f4SpdDpx]);
        // Put flow control status
        psz += sprintf(psz, "<TD>%s", g_aszOnOffCfg[WEBg_pSPortStatus->aSPortStatus[byPortId].f2FlowCtrl]);
#else
        // Put port enable status
        psz += sprintf(psz, "<TD>%s", g_aszEnDisCfg[WEBg_pSPortStatus->aSPortStatus[byPortId].f1Enable]);
        // Put port link status
        psz += sprintf(psz, "<TD>%s", g_aszPortLinkDownUp[WEBg_pSPortStatus->aSPortStatus[byPortId].f2LinkUp]);
        // Put speed & duplex status
        psz += sprintf(psz, "<TD>%s", g_aszSpdDpxCfg[WEBg_pSPortStatus->aSPortStatus[byPortId].f3SpdDpx]);
        // Put flow control status
        psz += sprintf(psz, "<TD>%s", g_aszOnOffCfg[WEBg_pSPortStatus->aSPortStatus[byPortId].f2FlowCtrl]);
#endif
    }

    psz += sprintf(psz, "</TABLE>");

    return psz-HTTPg_abyOutBuf;
}


DIRECT_MEMTYPE_CODE char s_szPortCfgJS[] = "\
en=new Array(\"Disable\",\"Enable\")\n\
spd=new Array(\"Auto\",\"100F\",\"100H\",\"10F\",\"10H\")\n\
onf=new Array(\"Off\",\"On\")\n\
txt=new Array(en,onf,spd,onf)\n\
function m(i,s){\n\
num=txt[i%4].length\n\
document.f.elements[i].length=num\n\
for(j=0;j<num;j++){\n\
with(document.f.elements[i].options[j]){\n\
text=txt[i%4][j]\n\
value=j\n\
selected=true\n\
}}\n\
document.f.elements[i].selectedIndex=s\n\
}\n\
for(i=0;i<p*4;i++)\n\
m(i,v[i])\n\
</SCRIPT>";

#ifndef __ASIC_VT6524

UINT16 CGI_wShowPortCfg(void)
{
    UINT8   byPortId, byGigaPortId, si;

    psz = HTTPg_abyOutBuf + s_byGenHtmlHeader(HTTPg_abyOutBuf, g_strPortCfg);
    psz += s_byAddFormTable(psz, "SetPortCfg", 1);
    psz += sprintf(psz, "<TR><TH>Port<TH>Enable<TH>Auto<TH>Spd/Dpx<TH>Flow<BR>Control</TR>");

    // Get port status
    PIPORT_vInitPage(WEBg_pSPortPage);

    for (byPortId = 0; byPortId < g_byLogIdNum; byPortId++)
    {
        // if mega or giga port
        byGigaPortId = (PIPORTMP_dwLogPtrToPhyMsk(byPortId) & 0x3000000) >> 24;
        if (byGigaPortId)   // for giga port
        {
            byGigaPortId--;     // one-based to zero-based

            // Put begining of a table entry and port name
            psz += sprintf(psz, "<TR%s><TD>%s", ((byPortId & 0x01) ? "" : s_szTrColor),
                                                g_aszModulePortName[WEBg_pSPortPage->abyGigaPortName[byGigaPortId]]);

            // Put port enable status
            psz += WEB_wAddSelectTag(psz, 'A', byPortId, g_aszEnDisCfg, 2, WEBg_pSPortPage->aSGigaPortCfg[byGigaPortId].f2Enable, TRUE, 0);

            // Put auto
            psz += WEB_wAddSelectTag(psz, 'B', byPortId, g_aszOnOffCfg,
                                     (WEBg_pSPortPage->aSStrTblMap[byGigaPortId][1].byListNum == 0) ? 1 : 2,
                                     WEBg_pSPortPage->aSGigaPortCfg[byGigaPortId].f2Auto, TRUE, 0);

            // Put speed & duplex status
            // deal with port ability string mapping array
            for (si=0; si<WEBg_pSPortPage->aSStrTblMap[byGigaPortId][2].byListNum; si++)
                s_apszStrTbl[si] = g_aszSpdDpxCfg[ WEBg_pSPortPage->aSStrTblMap[byGigaPortId][2].abyListIndex[si] ];
            psz += WEB_wAddSelectTag(psz, 'C', byPortId,
                                         s_apszStrTbl, si,
                                         WEBg_pSPortPage->aSGigaPortCfg[byGigaPortId].f4SpdDpx, TRUE, 0);

            psz += WEB_wAddSelectTag(psz, 'D', byPortId, g_aszOnOffCfg, 2, WEBg_pSPortPage->aSGigaPortCfg[byGigaPortId].f2FC, TRUE, 0);
        }
        else                // for mega port
        {
            // Put begining of a table entry and port name
            psz += sprintf(psz, "<TR%s><TD>%s", ((byPortId & 0x01) ? "" : s_szTrColor),
                                                g_aszPortNameTable[g_abyLogIdList[byPortId]]);

            psz += sprintf(psz, "<TD><SELECT name=A%bd></SELECT><TD><SELECT name=B%bd></SELECT><TD><SELECT name=C%bd></SELECT><TD><SELECT name=D%bd></SELECT>",
                                byPortId, byPortId, byPortId, byPortId);
        }
    } // end for
    psz += s_byAddFormTableEnd(psz);

    psz += sprintf(psz, "<SCRIPT language=javascript>\np=%bd\nv=new Array(", g_byMegaLogIdNum);
    for (byPortId = 0; byPortId < g_byMegaLogIdNum; byPortId++)
        psz += sprintf(psz, "%bd,%bd,%bd,%bd,",
                       WEBg_pSPortPage->aSMegaPortCfg[byPortId].f1Enable,
                       WEBg_pSPortPage->aSMegaPortCfg[byPortId].f1Auto,
                       WEBg_pSPortPage->aSMegaPortCfg[byPortId].f3SpdDpx,
                       WEBg_pSPortPage->aSMegaPortCfg[byPortId].f1FC);
    psz += sprintf(psz-1, ")\n%s", s_szPortCfgJS);

    return psz-HTTPg_abyOutBuf;
}

#else   // for VT6524

UINT16 CGI_wShowPortCfg(void)
{
    UINT8   byPortId;

    psz = HTTPg_abyOutBuf + s_byGenHtmlHeader(HTTPg_abyOutBuf, g_strPortCfg);
    psz += s_byAddFormTable(psz, "SetPortCfg", 1);
    psz += sprintf(psz, "<TR><TH>Port<TH>Enable<TH>Auto<TH>Spd/Dpx<TH>Flow<BR>Control</TR>");

    // Get port status
    PIPORT_vInitPage(WEBg_pSPortPage);

    for (byPortId = 0; byPortId < g_byLogIdNum; byPortId++)
    {
        // Put begining of a table entry and port name
        psz += sprintf(psz, "<TR%s><TD>%s", ((byPortId & 0x01) ? "" : s_szTrColor),
                                            g_aszPortNameTable[g_abyLogIdList[byPortId]]);

        psz += sprintf(psz, "<TD><SELECT name=A%bd></SELECT><TD><SELECT name=B%bd></SELECT><TD><SELECT name=C%bd></SELECT><TD><SELECT name=D%bd></SELECT>",
                            byPortId, byPortId, byPortId, byPortId);
    }
    psz += s_byAddFormTableEnd(psz);

    psz += sprintf(psz, "<SCRIPT language=javascript>\np=%bd\nv=new Array(", g_byLogIdNum);
    for (byPortId = 0; byPortId < g_byLogIdNum; byPortId++)
        psz += sprintf(psz, "%bd,%bd,%bd,%bd,",
                       WEBg_pSPortPage->aSPortCfg[byPortId].f1Enable,
                       WEBg_pSPortPage->aSPortCfg[byPortId].f1Auto,
                       WEBg_pSPortPage->aSPortCfg[byPortId].f3SpdDpx,
                       WEBg_pSPortPage->aSPortCfg[byPortId].f1FC);
    psz += sprintf(psz-1, ")\n%s", s_szPortCfgJS);

    return psz-HTTPg_abyOutBuf;
}

#endif


#ifdef __ASIC_VT6526
UINT16 CGI_wShowRateCfg(void)
{
    BYTE byPortId;

    psz = HTTPg_abyOutBuf + s_byGenHtmlHeader(HTTPg_abyOutBuf, g_strRateCfg);
    psz += s_byAddFormTable(psz, "SetRateCfg", 1);
    psz += sprintf(psz, "<TR><TH>Port<TH>InRate<TH>OutRate</TR>");

    PIRATE_vInitPage(WEBg_pSRatePage);

    for (byPortId=0; byPortId<g_byMegaLogIdNum; byPortId++)
    {
        // Put begining of a table entry and port name

⌨️ 快捷键说明

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