beautypg.com

Example cgi code, 3 example cgi code – Solvline Eddy DKV2.1.0.3 User Manual

Page 104

background image

Chapter 8. Handling

HTML & CGI

104

DNS
N_DNS

" value="[v,

n_dns

]"

>


Telnet Service



Telnet Service


As shown above there are name and value parts for each record to link with CGI.
Name stores information modified by user in HTML, so that it can save modified value when a user
click on the submit button on the lower part of HTML page. Value reads value to getagent.c to
display on HTML page and let user to modify the value as needed.

8.3 Example CGI Code

Eddy-Serial DK has two CGI programs: getagent.cgi and setagent.cgi.
‚getagent.c‛ reads an environment configuration file on /etc/ folder to HTML document , and
‚setagent.c‛ saves user-modified information on the HTML document back the environment file on
/etc/folder and saves it to flash/, so the user-modified environment configuration is stored.

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

[Source Summary]
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]);