3 example cgi code, 3 example cgi code -2 – Solvline Eddy DK Ver 2.20 User Manual

Page 64

Advertising
background image

Chapter 8. Handling HTML & CGI

8-2

<td class="content"><input type="text" size="16" maxlength="16" name="

N_DNS

" value="[v,

n_dns

]" >


<tr bgcolor="#FFFFFF">
<td class="content">Telnet Service</td>
<td class="content"><select name="

N_TELNET

">

<option [v,

n_telnet_di

] value="0">Disable</option>

<option [v,

n_telnet_en

] value="1">Enable</option>

</select>

<tr bgcolor="#FFFFFF">
<td class="content">Telnet Service</td>
<td class="content"><select name="

N_WEB

">

<option [v,

n_web_di

] value="0">Disable</option>

<option [v

, n_web_en

] value="1">Enable</option>

</select>

As shown above there are name and value part for each record to link with CGI.
Name stores information modified by user in HTHM so that it can save modified value when the user click

on submit button at the lower part of HTML page. Value reads value to getagent.c to display on HTML page
and lets user to modify the value she or he wants.


8.3 Example CGI Code

Eddy-Serial DK has two CGI programs: getagent.cgi and setagent.cgi.

“getagent.c” reads /etc/sb_config file to HTML document to display configuration information, and “setagent.c”

saves user-modified information from HTML document back to /etc/sb_config file and ultimately saves to

flash/sb_config so the user-modified environment configuration information is stored even if Eddy is reset.

The following example shows processing part of getagent.c to display configuration value HTML page of example

above.

[Source abstract]

if

(cgiFormStringNoNewlines("

N_IP

", buff, 16) == cgiFormNotFound)

{

sprintf(buff,

"%d.%d.%d.%d",cfg.system.ip[0],

cfg.system.ip[1],cfg.system.ip[2],cfg.system.ip[3]);

listPutf(list, "

n_ip

", buff);

}

else

listPutf(list,

"

n_ip

", buff);

if

(cgiFormStringNoNewlines("

N_MASK

", buff, 16) == cgiFormNotFound)

{

sprintf(buff, "%d.%d.%d.%d",cfg.system.mask[0], cfg.system.mask[1],

cfg.system.mask[2],cfg.system.mask[3]);

listPutf(list,

"

n_mask

", buff);

Advertising