📄 asgxa.htm
字号:
<HTML>
<HEAD>
<TITLE>Apache Server Survival Guide asgxa.htm </TITLE>
<LINK REL="ToC" HREF="index.htm" tppabs="http://docs.rinet.ru:8080/Apachu/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://docs.rinet.ru:8080/Apachu/htindex.htm">
<LINK REL="Next" HREF="asgxb.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asgxb.htm">
<LINK REL="Previous" HREF="asgpt6.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asgpt6.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<!--#exec cmd="/www/docs/ssi-bin/restricted_search.ssi"-->
<!--#exec cmd="/www/docs/ssi-bin/inc.ssi"-->
<A NAME="I0"></A>
<H2>Apache Server Survival Guide asgxa.htm</H2>
<P ALIGN=LEFT>
<A HREF="asgpt6.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asgpt6.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm" tppabs="http://docs.rinet.ru:8080/Apachu/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="asgxb.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asgxb.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E175" >Introduction</A>
<LI>
<A HREF="#E68E176" >Installation</A>
<LI>
<A HREF="#E68E177" >Usage</A>
<UL>
<LI>
<A HREF="#E69E197" >Special Processing</A></UL>
<LI>
<A HREF="#E68E178" >Other Features</A>
<LI>
<A HREF="#E68E179" >Frequently Asked Questions</A>
<UL>
<LI>
<A HREF="#E69E198" >I Get an Error About sys_errlist When I Compile</A>
<LI>
<A HREF="#E69E199" >Where Do I Put Everything?</A>
<LI>
<A HREF="#E69E200" >Why Does Un-CGI Tell Me It Can't Run My Script?</A>
<LI>
<A HREF="#E69E201" >What Do I Do in My Forms?</A>
<LI>
<A HREF="#E69E202" >I Get an Error 403 when I Submit My Form</A>
<LI>
<A HREF="#E69E203" >I Get an Error Code 500 From the Server</A>
<LI>
<A HREF="#E69E204" >My Script Doesn't See the Form Variables</A>
<LI>
<A HREF="#E69E205" >The Browser Just Sits There When I Submit My Form</A>
<LI>
<A HREF="#E69E206" >How Do I Parse Check Box Results?</A>
<LI>
<A HREF="#E69E207" >Do I Need to Make a Directory Called uncgi?</A>
<LI>
<A HREF="#E69E208" >Does Un-CGI Strip Out Special Shell Characters that Might Cause Security Problems?</A></UL>
<LI>
<A HREF="#E68E180" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E17"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>A</B></FONT></CENTER></H1>
<BR>
<A NAME="E67E24"></A>
<H2 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>Un-CGI Version 1.7 Documentation</B></FONT></CENTER></H2>
<BR>
<P>The Un-CGI documentation was reprinted, with minor alterations, with kind permission from its author, Steven Grimm. The most recent version of this software and its documentation are available via the Web at <A HREF="javascript:if(confirm('http://www.hyperion.com/~koreth/uncig.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.hyperion.com/~koreth/uncig.html'" tppabs="http://www.hyperion.com/~koreth/uncig.html"> http://www.hyperion.com/~koreth/uncig.html</A>.
<BR>
<BR>
<A NAME="E68E175"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Introduction</B></FONT></CENTER></H3>
<BR>
<P>This is Un-CGI, a frontend for processing queries and forms from the Web on UNIX systems. You can get it via anonymous File Transfer Protocol (FTP) from ftp.hyperion.com or, depending on your browser, by following this link:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">http://www.hyperion.com/~koreth/uncgi.html.</FONT></PRE>
<P>If you wanted to process a form without this program, you would have to either write or dig up routines to translate the values of the form's fields from URL encoding to whichever your program required. This was a hassle in C and a real pain in the shell, and you had to do things differently for GET and POST queries.
<BR>
<P>This is where uncgi comes in. It decodes all the form fields and sticks them into environment variables for easy peruse by a shell script, a C program, a Perl script, or whatever you like. Then it executes whichever program you specify. (Actually, Un-CGI is something of a misnomer because the weird URL syntax is from the HTML forms specification, not from CGI itself.)
<BR>
<BR>
<A NAME="E68E176"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Installation</B></FONT></CENTER></H3>
<BR>
<P>Let's assume that you have at least a passing familiarity with compiling and installing programs from the Internet. You know how to unpack a compressed tarfile and use make, and are familiar with the operation of your HTTP server. If you don't, you're probably not the right person to install Un-CGI; ask your system administrator to set it up for you.
<BR>
<P>To install, edit the makefile. Change the following settings:
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CC
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The name of your system's C compiler—typically cc or gcc.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SCRIPT_DIR
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The directory where you want Un-CGI to look for your programs. This doesn't have to be the same as your server's CGI directory. Note that you cannot use a tilde (~) here to signify a home directory; you have to use the entire path, beginning with /.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
DESTDIR
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The directory where you want the Un-CGI executable to be installed. If your server has a cgi-bin directory, it is generally what you'll need to put here because the server needs to know to run Un-CGI as a CGI program. Often that can only happen for programs that are located in the server's cgi-bin directory.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><BR></FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Note that you cannot just make a directory called cgi-bin in your account and expect Un-CGI to be run from it. The HTTP server needs to be configured to know where to look for executable programs. If you don't manage the HTTP server on your system, you probably cannot install Un-CGI in the right place. (On some servers, you can put CGI programs anywhere if you give them a certain file extension; talk to your system administrator to find out if this is the case on your system. If so, see the next item.)
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
EXTENSION
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
If your server allows CGI programs to be run from anywhere as long as they have a particular filename extension (typically .cgi), you should set this to that extension, including the period (.). In that case, you can set DESTDIR to point into any directory that the server has access to (for example, your public_html directory).
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><BR></FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
You don't need to follow any particular naming rules for the programs you're going to ask Un-CGI to run. As long as they're in the SCRIPT_DIR directory, you can name them any way you see fit.</FONT>
</TABLE><P>Once you're done editing the makefile, run make install and your system will build and install Un-CGI into the directory you specified as DESTDIR. If you get an error message like make: Command not found or cc: Command not found, talk to your system administrator. There's no way of magically knowing where your system happens to put its compiler tools.
<BR>
<P>Make sure the file permissions on the Un-CGI binary (and the directory it's in) are set so that the HTTP server can execute it. On most systems the HTTP server runs as user nobody or www. You may want to make Un-CGI a setuid program if you want to manipulate private files with your back-end scripts because they will ordinarily be run under the same user ID as the HTTP server. Consult your system administrator to find out your site's policy on setuid programs; they are frowned upon in some places.
<BR>
<BR>
<A NAME="E68E177"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Usage</B></FONT></CENTER></H3>
<BR>
<P>An example is the easiest way to demonstrate Un-CGI's use. Suppose you have the following in an HTML file:
<BR>
<PRE>
<FONT COLOR="#000080"><form method=POST action="/cgi-bin/uncgi/myscript">
What's your name?
<input type=text size=30 name=name>
<p>
Type some comments.
<br>
<textarea name=_comments rows=10 cols=60></textarea>
What problem are you having? <select name=problem multiple>
<option> Sleeplessness
<option> Unruly goat
<option> Limousine overcrowding
</select>
<p>
<input type=submit value=" Send 'em in! ">
</form></FONT></PRE>
<P>When the user selects the Send 'em in! button, the HTTP server will run Un-CGI. Un-CGI will set three environment variables—WWW_name, WWW_comments, and WWW_problem—to the values of the name, comments, and problem fields in the form, respectively. Then it will execute myscript in the SCRIPT_DIR directory.
<BR>
<P>All the usual CGI environment variables (PATH_INFO, QUERY_STRING, and so on) are available to the script or program you tell Un-CGI to run. A couple of them (PATH_INFO and PATH_TRANSLATED) are tweaked by Un-CGI to the values they would have if your program were being executed directly by the server. PATH_INFO is, in case you haven't read up on CGI, set to all the path elements after the script name in your URL (if there is any). This is an easy way to specify additional parameters to your script without resorting to hidden fields.
<BR>
<P>myscript might be as simple as this:
<BR>
<PRE>
<FONT COLOR="#000080">#!/bin/sh
echo 'Content-type: text/html'
echo ''
mail webmaster << __EOF__
$WWW_name is having $WWW_problem problems and said:
$WWW_comments
__EOF__
cat /my/home/directory/htmlfiles/thanks.html</FONT></PRE>
<P>With Un-CGI, that's all you need to write a script to send your mail from a form and print a prewritten file as a response. It's the same whether you want to use GET or POST queries.
<BR>
<P>If you're using Perl, $ENV{"WWW_xyz"} will look up the value of the xyz form field.
<BR>
<P>If more than one problem is selected in the previous example, the values will all be placed in WWW_comments and separated by hash marks (#). You can use the library function strtok() to separate and replace the hash marks with newlines using tr. Type the following:
<BR>
<PRE>
<FONT COLOR="#000080">echo $WWW_problem | tr '#' \\012 | while read value; do
echo $value 'selected.'
done</FONT></PRE>
<P>A useful learning tool is to point your form at a script that just prints the contents of the environment. On most systems there is a program to do that, called either env or printenv. You can write a little script that runs it:
<BR>
<PRE>
<FONT COLOR="#000080">#!/bin/sh
echo 'Content-type: text/plain'
echo ''
env</FONT></PRE>
<P>This script will print all the CGI environment variables set by the server.
<BR>
<BR>
<A NAME="E69E197"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Special Processing</B></FONT></CENTER></H4>
<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -