home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
pub
/
public_html
/
samples
/
survey.txt
Wrap
Text File
|
2020-01-01
|
4KB
|
151 lines
#!/www/cgi/kermit/wermit +
#
# How to write a CGI script in the Kermit language.
# This production example collects responses to the survey at:
# http://www.columbia.edu/kermit/k95survey.html
#
# Requires C-Kermit 8.0.212 Dev.25 or later:
# http://www.columbia.edu/kermit/ckdaily.html
#
# F. da Cruz, Columbia University, December 2006
# Last update: Fri Dec 15 09:14:32 2006
# set flag on # debug
set flag off # no debug
.datafile = /www/cgi-upload/kermit/survey.dat
# Macro to decode a "URL encoded" variable in which
# '+' represents a space and %xx is a hexadecimal-encoded byte.
#
def decode {
.\%9 := \freplace(\m(\%1),+,\32)
.\%8 := \freplace(\fcont(\%9),%,\92x)
_asg \%1 \%8
}
# Check Kermit version for INPUT /COUNT:
.havecount = 0
if > \v(version) 800212 {
.havecount = 1
} else if == \v(version) 800212 {
if def \v(test) {
if lgt \v(test) Dev.24 .havecount = 1
}
}
# Emit the the HTML header for the response page.
#
echo Content-type: text/html
echo
echo <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
echo <html lang="\m(lang)"><head><title>Survey received - Thank you</title>
echo <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
echo <META http-equiv="Content-Style-Type" content="text/css">
echo </head>
echo <body margin:48 style="font-size:14pt">
# For debugging only
#
if flag {
echo <p>
pwd
echo <br>
echo \v(herald)<br>
echo Length: \$(CONTENT_LENGTH)<br>
echo Referred by: \$(HTTP_REFERER)<br>
echo Host: \$(REMOTE_HOST)<br>
echo Address: \$(REMOTE_ADDR)<br>
echo <p>
}
# Read the form contents. If the environment variable CONTENT_LENGTH
# is defined and has a numeric value, this is the length of the form data
# string. Otherwise (because of the definition of the form itself),
# the data is terminated by "END_OF_MESSAGE".
clear input
set input echo off
if ( numeric \$(CONTENT_LENGTH) && defined havecount ) {
input /count:\$(CONTENT_LENGTH) 10
if flag echo INPUT STATUS=\v(status)
.line := \v(input)
if flag echo INPUT /COUNT:\$(CONTENT_LENGTH)
if flag echo INPUT=[\v(input)]=\flen(\v(input))
} else {
input 10 END_OF_MESSAGE
.line := \freplace(\m(input),END_OF_MESSAGE,)
if flag echo INPUT END_OF_MESSAGE
}
# Make sure we got some data
#
if not def line {
echo "Empty message received<br>"
forward end
}
# The form data string is a series of 'name=value' pairs separated by
# ampersands or semicolons. Kermit's split() function separates them
# into an array, \&a[], one name=value pair in each array element:
#
.\%n := \fsplit(\m(line),&a,&;)
if not \%n {
echo "Name-value string not received<br>"
forward end
}
if flag { # (Debugging)
echo <pre>
show array a
echo </pre>
}
# Open the response log and write the decoded name-value pairs into it:
#
fopen /append \%o \m(datafile)
if fail {
echo "ERROR: \v(errstring)"
forward end
}
fwrite /line \%o "--- \v(timestamp) ---"
fwrite /line \%o "# Host = \$(REMOTE_HOST)"
fwrite /line \%o "# Addr = \$(REMOTE_ADDR)"
fwrite /line \%o "# User = \$(REMOTE_USER)"
# The keywordval() function parses a name-value pair, assigning the
# value to a macro of the given name. Then we decode the value.
# Then we write the decoded 'name=value' line into the mail program.
# \v(keywordvalue) contains the name of the variable (macro).
# \m(\v(keywordvalue)) gives its value (definition).
for \%i 1 \%n 1 {
void \fkeywordval(\&a[\%i])
if equ "\v(lastkeywordvalue)" "END_OF_MESSAGE" continue
decode \v(lastkeywordvalue)
if \flen(\m(\v(lastkeywordvalue))) {
fwrite /line \%o \v(lastkeywordvalue)=\m(\v(lastkeywordvalue))
}
}
# Close the response log file.
#
fclose \%o
chmod 664 \m(datafile)
# Here we print a thank-you note for the user who filled out the form.
# This is done simply by echoing HTML statements and text to our own
# standard output:
echo <h2>Thank you</h2>
echo Your response will help in our efforts to gain approval for creating
echo a new Kermit 95 release.
echo <p>
echo Thanks again!
echo <p>
echo Frank da Cruz<br>
echo <a href="mailto:fdc@columbia.edu">fdc@columbia.edu</a><br>
echo \v(timestamp)
echo <hr>
:end
# Emit the HTML footer
#
echo "</body>"
echo "</html>"
exit 0