Web Server Example

WWWedgy - Web 1.0 (old school!) WWW-server CGI-BIN example

This program is a simple skeleton CGI-BIN program. The UNIX mode of operation of CGI-BIN program is that everything that the program prints out using normal C printf functions goes to something known as "stdout" or standard output. A WWW-Server usually grabs whatever the CGI-BIN program spits out to "stdout" and sends it to the client. WWW servers are usually UGLY when written in C if a lot of the HTML is encoded in C printf functions, largely because all the quotation marks
have to be written as
The program WWWedgy uses a tactic of copying the contents of files containing HTML, so that the programmer need not embedd all the HTML within C printf statements. The function WWWPrintFileData is used to copy the contents of the files weghead.txt and wegtail.txt, which are shown as comments in the program below.

In the case of CGI-BIN programming use WWWGetArgs rather than GetArgs. This sets up the proper processing of GET and POST forms requests from the client. A more detailed example is found in /ncbi/biostruc/mmdbsrv.c

Compile wwwedgy.c with make.wwwedgy

Start apache on CentOS with (as root)

        /sbin/service httpd start

Copy the excecutable and two txt files to /var/www/cgi-bin/

chmod 777 .* (for now this gives too much permission, but it works)
and (eeks! mimicking an old-school 1995 Unix machine with no security)
setenforce 0   (this shuts off ALL of SELinux - !)

Visit this url (which is your own web server)


Check the log file that is created in /var/www/cgi-bin/ for some web statistics !
If you are done, use
setenforce 1  to turn SELinux back on.
You can see the SELinux context file and directory settings for the /var/www/cgi-bin directory with the command
ls -alZ
You can figure out how to set up just the cgi-bin using the
chcon command and the appropriate SELinux context.

Christopher Hogue,
Nov 20, 2009, 2:13 AM