Eddy DK Programmer Guide
125
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]);
listPutf(list, "
n_mask
", buff);
}
else
listPutf(list, "
n_mask
", buff);
if (cgiFormStringNoNewlines("
N_GW
", buff, 16) == cgiFormNotFound)
{
sprintf(buff, "%d.%d.%d.%d", cfg.system.gateway[0], cfg.system.gateway[1],
cfg.system.gateway[2],cfg.system.gateway[3]);
listPutf(list, "
n_gw
", buff);
}
else
listPutf(list, "
n_gw
", buff);
if (cgiFormStringNoNewlines("
N_DNS
", buff, 16) == cgiFormNotFound)
{
sprintf(buff, "%d.%d.%d.%d",cfg.system.dns[0], cfg.system.dns[1],
cfg.system.dns[2],cfg.system.dns[3]);
listPutf(list, "
n_dns
", buff);
}
else
listPutf(list, "
n_dns
", buff);