|
CSE Home |
About Us |
Search |
Contact Info |
|
Executive SummarySupport for user CGI and PHP scripts is now provided on abstract.cs.washington.edu, a lab-supported Linux machine running Apache httpd 2.2. If you have a CSE account, you probably already have an account on abstract, and therefore the ability to create your own CGI scripts. Go to:
About CGI ScriptsCGI scripts are special programs that have been designed to be run by a web server. The acronym stands for "common gateway interface," meaning that the CGI mechanism is intended to be a gateway to other types of information beyond static files. While we call them scripts, there is no requirement that a CGI script be coded in a scripting language such as perl, shell, or python, though those are all common ways to do it. Compiled languages such as C can also be used. What makes a CGI script different from other programs is fairly minor. Most notably, it must emit a little bit of the HTTP header information as its first action. Secondly, the server sets up a number of enviroment variables that help the script understand the context in which it's being run. Here is a simple perl CGI program that illustrates both of these concepts:
The CGI/1.1 specifcation is here. Apache documentation for mod_cgi, the component of Apache that handles CGI scripts, is here. About Your Abstract Accountabstract.cs.washington.edu is a lab-supported Linux machine that runs the Apache web server, version 2.2 (local documentation is here). It has been configured to run CGI scripts for all account holders in a mode called suEXEC, which means that CGI scripts run under your own user identity. That means that you could write a CGI script that could take any action on the computer that you could, both a useful and a scary fact. You can mix your CGI scripts right in with your static content. By default, anything with a filename extension of .cgi, .cl, .lsp, .lisp, or .pl will be treated as a CGI script-- that is, the web server will try to run it as a CGI script instead of just passing the contents over to the browser. You can manipulate the list of such extensions-- or specify specific files to be treated as CGIs-- using Apache directives in a .htaccess file. (Details are left as an excercise for the reader.) Lab staff has created accounts for all grads, undergrads, faculty, and staff on abstract. To login, use your kerberos credentials. Your home directory on abstract is distinct from that on any other host, and is /www/homes/<user>/. Your web content is in /www/homes/<user>/www/. The corresponding URL is http://abstract.cs.washington.edu/~<user>/. abstract:/www/homes/ is exported to other CSE Unix hosts as /homes/abstract/, so your home directory is available on those hosts as /homes/abstract/<user>/. (Also, on research hosts, as /cse/abstract/<user>). About SecurityUnlike almost all other programs on a computer, CGI scripts can be run by arbitrary users on the public internet (this is also true of special purpose network service providers such as the ftp service, when it's enabled). Some of those users would enjoy the opportunity to subvert the intention of your program to their own creative ends. It's quite hard to write a CGI script that can't be subverted. Security alerts reporting exploits of common CGIs abound. That's why we don't enable user CGI execution on hosts like www.cs.washington.edu, which serve mission-critical department functions. Here's how we manage security risks on abstract:
Here are a few sugggestions for how to keep your CGI scripts from being turned against you:
The World Wide Web Security FAQ, hosted at W3, has a section on CGI scripts, written by Lincoln Stein. Tips on Writing CGI Scripts
PHPAbstract also supports PHP, a scripting language that allows you to embed statements in an HTML file. This is a concept much like (but historically preceeds) Microsoft's Active Server Pages, but without the language independence. As a language, PHP is sort of like perl. There is documentation for PHP. You might consider starting with the FAQ. PHP is configured at build-time to support any of a vast array of extensions. You can see how we built ours by visiting PHP Info for Abstract. Files on Abstract that have the filename extension .php will be parsed for PHP language constructs. Files named index.php will be processed as the directory index for the containing directory if no other directory index files (such as index.html) exist in the directory. At this writing, we run version PHP 5.2. NB: versions of PHP later than 4.2.0 have different a default setting for the "register globals" behavior than did all previous versions; that tends to break a lot of older code. Information on this issue can be found in Using Register Globals and in Working with Form Variables in PHP 4.2+. A quick workaround is to create a .htaccess file in the directory containing your code with this content: php_flag register_globals on(It's quick, but not recommended. Better is to live in and code for the present. Register Globals won't be back, but if it did return, we'd expect it to be riding an eyeless horse, smelling of sulphur, wearing a black cloak, and carrying a scythe.) (PHP used to stand for "Personal Home Page," but now they pretend it's for "Hypertext PreProcessor.") NB: your data is not secure when managed by PHP. PHP behaves a lot like CGI, but it doesn't run under the suEXEC mechanism. Your CGI scripts run as you. Your PHP scripts run as the web server user (apache). Your colleagues' PHP scripts also run as the web server user. Data managed by your PHP scripts is writable by the web server user, trashable by the web server user, and therefore trashable by your colleagues' PHP scripts. If you chose to use PHP to write to the file system, make sure that the data is not sensitive or valuable. Keep your own backups of the data. Consider using CGI instead of PHP to manage data. Server-Side-IncludesServer side includes, AKA "SSI," is a technique for adding dynamic content to HTML pages. This is done by crafting HTML comments with special syntax-- called "SSI directives"-- inline with your HTML content. The possibilities with SSI are much more limited than with PHP, but, on the upside, you don't need to learn an entire programming language to use it. You can set, test, and echo variables, include the output of programs or CGI scripts, include external files, and do a few other little tricks. Please read Apache Tutorial: Introduction to Server Side Includes in the Apache 1.3 documentation for details. To make SSI work on your content, you need to do two things:
About HTTPS/SSL on AbstractAbstract offers SSL (HTTPS) service. That means that pretty much anything that's offered under http://abstract.cs.washington.edu/ is also available under https://abstract.cs.washington.edu/. To make this work, staff created an "SSL certificate" that identifies the server and contains a key for encrypting the session. The SSL certificate on Abstract was signed by the "UW Services CA" (administered by C&C), not by a commercial certificate authority (how stingy is that?)-- they charge upwards of $150 to perform this service. What that penny-pinching move means is that most users who browse to https://abstract.cs.washington.edu/ (or anything that starts with it) will face down a mildly scary alert from their browser warning them that the certificate has a problem, and asking them if they want to accept it. Therefore, if you chose to advertise your Abstract resources at an HTTPS URL, you might warn your users that the certificate is locally-signed, or that they should expect the security dialog, or that they should install C&C's root CA certificate by browsing here. (We offer HTTPS services on most other CSE Apache web servers, too. www.cs.washington.edu and www4.cs.washington.edu do have commercially-signed certificates because we need to support external users there. Others don't.) Closing NotesBy now, you are thinking "This document sucks! I don't have to put up with this @#$#%!" Right you are: your comments and criticisms are welcomed. [Last modified: Monday, October 15, 2007, at 02:44PM PDT.] |
|
Department of Computer Science & Engineering University of Washington Box 352350 Seattle, WA 98195-2350 (206) 543-1695 voice, (206) 543-2969 FAX [comments to webmaster] | |