Web Examples

 

To help users to master CGI programs, a demo web site is built under "/demo" directory of the device's web root. The CGI program cgidemo, together with demo html pages, demonstrate basic functions of CGI:

 

*          Demo 1 - Simple text output

*          Demo 2 - Output html file with text replacing

*          Demo 3 - Use textbox and listbox

*          Demo 4 - Send email

 

Login

 

Use URL http://x.x.x.x/demo to login. The demo directory is configured to have application level authentication. Set arbitrary user information:

 

 

 

Demo 1 - Simple Text Output

 

Web page

 

CGI code in cgidemo.c

int Demo1()

{   int i;

 

    // HTML header

    printf("%s",htmHead);

    // messages

    printf("This page is generated by demo1.<BR><BR>\r\n");

    // hello world

    for(i=1;i<=10;i++)

    {   printf("Hello World %d<BR>\r\n",i);

    }

    // Show user and password, if any.

s=getenv("REMOTE_USER");

    if(s) printf("User: %s<BR>\r\n",s);

    s=getenv("REMOTE_PASSWORD");

    if(s) printf("Password: %s<BR>\r\n",s);

    // HTML tail

    printf("%s",htmTail);

 

    return 1;

}

 

 

Demo 2 - Output HTML File with Text Replacing

 

Web page

 

CGI code in cgidemo.c

int Demo2()

{     

    // Read entire htm page into buffer for editing.

    if(!HttpReadFile("demo2.htm")) return 0;

    // replace tag with text

    ReplaceTag("%01","Hello World 1");         

    ReplaceTag("%02","Hello World 2");         

    // send out the htm page after editing.

    HttpSendResponse(SHOW_ALL);

 

    return 1;

}

 

 

 

Demo 3 - Use TextBox and ListBox

 

Web page

 

CGI code in cgidemo.c

int Demo3a()

{

    // Read and send htm page until the mark "//**" in JavaScript.

    if(!HttpReadFile("demo3.htm")) return 0;

    HttpSendResponse(SHOW_SCRIPT1);

    // Set the contents of Textbox and Listbox

    SetTextBox("ctTextBox","Hello World !");

    SetListBox("ctListBox","2");

    // end of script

    // Read and send htm page after the mark "//**" in JavaScript.

    HttpSendResponse(SHOW_SCRIPT2);

   

    return 1;

}

 

Web page

 

CGI code in cgidemo.c

int Demo3b()

{  

    if(!HttpReadFile("demo4.htm")) return 0;

    HttpSendResponse(SHOW_FORM1);

 

    printf("==== start ====<BR>\n");

    // Show text box contents

    if(CgiGetStr("ctTextBox",m_Str,100))

    {   printf("TextBox = \"%s\"<BR>\n",m_Str);

    }

    // Show list box contents

    if(CgiGetStr("ctListBox",m_Str,100))

    {   printf("ListBox = %s<BR>\n",m_Str);

    }

    // Additional message can be shown here

    printf("====  end  ====<BR>\n");

    // Send 2nd part of Html

    HttpSendResponse(SHOW_FORM2);

 

    return 1;

}

 

 

Demo 4 - Use email