Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 04/03/12.

Slides:



Advertisements
Similar presentations
HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
Advertisements

How does the server format the information it gives to the appln program? As environment variables and in standard input.
CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl % –C % –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.
Outcomes Know what are CGI Environment Variables Know how to use environment variables How to process A simple Query Form Able to use URL Encoding rules.
Common Gateway Interface
1 ‘Dynamic’ Web Pages So far, we have developed ‘static’ web-pages, e.g., cv.html, repair.html and order.html. There is often a requirement to produce.
Overview A plain HTML document is static A CGI program is executed in real-time, so that it can output dynamic information. CGI (Common Gateway Interface)
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
Web Server Design Week 5 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/10/10.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
CSCE Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013.
Web Programming Week 1 Old Dominion University Department of Computer Science CS 418/518 Fall 2010 Martin Klein 8/31/10.
Web Server Design Week 8 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 3/3/10.
Perl: Lecture 2 Advanced RE & CGI. Regular Expressions 2.
Web Server Design Week 4 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/03/10.
CGI Scripting and Vulnerabilities COEN 351: E-commerce Security.
Web Server Design Assignment #1: Basic Operations Due: 02/03/2010 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin.
Web Server Design Week 11 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 3/24/10.
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
Form Data Encoding GET – URL encoded POST – URL encoded
Internet and Intranet Fundamentals
Web Server Design Assignment #2: Conditionals & Persistence Due: 02/24/2010 Old Dominion University Department of Computer Science CS 495/595 Spring 2010.
Web Server Design Week 2 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 1/20/10.
Web Server Design Week 7 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/24/10.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/7/10.
Krerk Piromsopa. 1 Department of Computer Engineering. Chulalongkorn University. Web Application Generic Issues.
Web Server Design Week 6 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/17/10.
Web Server Design Assignment #5: Unsafe Methods & CGI Due: 05/05/2010 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin.
CS 330 Class 8 Homework A pattern that contains a word with an optional period A pattern that contains Fred with a space (not Freddy) See regexp.txt guest4.htm.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
Web Server Design Week 10 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 3/17/10.
Web Server Design Week 5 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 02/07/12.
Web Programming Week 1 Old Dominion University Department of Computer Science CS 418/518 Fall 2007 Michael L. Nelson 8/27/07.
Web Server Design Week 15 Old Dominion University Department of Computer Science CS 495/595 Spring 2009 Michael L. Nelson 4/20/09.
Web Server Design Week 3 Old Dominion University Department of Computer Science CS 495/595 Spring 2006 Michael L. Nelson 1/23/06.
Web Server Design Week 6 Old Dominion University Department of Computer Science CS 495/595 Spring 2006 Michael L. Nelson 2/13/06.
Web Server Design Week 10 Old Dominion University
Web Server Design Week 4 Old Dominion University
Web Server Design Assignment #5: Unsafe Methods & CGI
Web Server Design Assignment #2: Conditionals & Persistence
Web Server Design Week 8 Old Dominion University
Web Server Design Week 11 Old Dominion University
Web Server Design Week 7 Old Dominion University
CSCE Systems Programming
Web Server Design Assignment #5 Extra Credit
Web Server Design Week 4 Old Dominion University
Web Server Design Week 15 Old Dominion University
Web Server Design Week 5 Old Dominion University
Web Server Design Assignment #2: Conditionals & Persistence
Web Server Design Week 8 Old Dominion University
Web Server Design Week 8 Old Dominion University
Web Server Design Week 6 Old Dominion University
Web Server Design Week 10 Old Dominion University
Web Server Design Week 8 Old Dominion University
Web Server Design Week 11 Old Dominion University
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
Environment Variables
Web Server Design Week 5 Old Dominion University
Web Server Design Week 4 Old Dominion University
Web Server Design Week 16 Old Dominion University
Web Server Design Week 12 Old Dominion University
Web Server Design Week 14 Old Dominion University
Web Server Design Assignment #1: Basic Operations
Web Server Design Week 6 Old Dominion University
Web Server Design Assignment #5 Extra Credit
Web Server Design Week 7 Old Dominion University
Web Programming Week 1 Old Dominion University
Web Server Design Week 7 Old Dominion University
Presentation transcript:

Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 04/03/12

Common Gateway Interface A method for remotely invoking executable programs on a server –A long-time convention –finally defined in RFC 3875 client server GET /foo.cgi HTTP/1.1 foo.cgi 200 OK

CGI Invocation How Apache does it: – We’ll live slightly more dangerously: –any executable (non-directory) file can be invoked as CGI with: POST GET w/ query string –e.g. /a/b/c.cgi?var1=foo&var2=bar

CGI Operation The CGI program is responsible for returning (on STDOUT) some combination of its own headers: –Content-type –Location –Status –and other locally-defined headers Script-returned headers are: –collected by the server –processed; e.g.: “Location” -> HTTP/ Found Status -> HTTP response code line –combined with the server’s headers Resulting headers are returned to the client

Partial vs. Non-Parsed Headers The approach in the prior slide is what is known as "partial headers" (a combination of the headers from CGI script + the server) You can also have your script be responsible for all of the headers, in non-parsed-headers (nph) mode. –somewhat outdated, but possible –see:

Status % more status.cgi #!/usr/bin/perl print "Status: 678 This is not a real HTTP status code\n"; print "X-This-Header-Is-Madeup: foo=bar\n\n"; % telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s12/cgi/status.cgi HTTP/1.1 Host: HTTP/ This is not a real HTTP status code Date: Tue, 03 Apr :01:58 GMT Server: Apache/ (Unix) PHP/5.3.5 mod_ssl/ OpenSSL/0.9.8q X-This-Header-Is-Madeup: foo=bar Content-Length: 0 Content-Type: text/plain Connection closed by foreign host.

Status With an Entity % cat status-entity.cgi #!/usr/bin/perl print "Status: 678 This is not a real HTTP status code\n"; print "X-This-Header-Is-Madeup: foo=bar\n"; print "Content-type: text/html\n\n"; print "this is not a header, this is part of the entity...\n" % curl -i HTTP/ This is not a real HTTP status code Date: Tue, 03 Apr :11:57 GMT Server: Apache/ (Unix) PHP/5.3.5 mod_ssl/ OpenSSL/0.9.8q X-This-Header-Is-Madeup: foo=bar Content-Length: 52 Content-Type: text/html this is not a header, this is part of the entity...

Location % more location.cgi #!/usr/bin/perl print "Location: % telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/cgi/location.cgi HTTP/1.1 Host: HTTP/ Found Date: Mon, 24 Apr :40:31 GMT Server: Apache/2 Location: Content-Length: 277 Content-Type: text/html; charset=iso Found Found The document has moved here. Apache/2 Server at Port 80 note how the entity is automatically constructed

Location Fixes the Entity… % cat location-entity.cgi #!/usr/bin/perl print "Location: print "Content-type: text/plain\n\n"; print "this will never get printed..." % curl -i HTTP/ Found Date: Tue, 03 Apr :27:33 GMT Server: Apache/ (Unix) PHP/5.3.5 mod_ssl/ OpenSSL/0.9.8q Location: Content-Length: 329 Content-Type: text/html; charset=iso Found Found The document has moved here. Apache/ (Unix) PHP/5.3.5 mod_ssl/ OpenSSL/0.9.8q Server at Port 80

Content-type % more ls.cgi #!/usr/bin/perl print "Content-type: text/plain\n\n"; $ls = `ls -alR`; print "$ls\n"; % telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. HEAD /~mln/teaching/cs595-s07/cgi/ls.cgi HTTP/1.1 Connection: close Host: HTTP/ OK Date: Mon, 09 Apr :31:12 GMT Server: Apache/2.2.0 Connection: close Content-Type: text/plain Connection closed by foreign host. note how status 200 OK is automatically constructed

CGI Environment Section 4.1, RFC 3875 –AUTH_TYPE, CONTENT_LENGTH, CONTENT_TYPE, GATEWAY_INTERFACE, PATH_INFO, PATH_TRANSLATED, QUERY_STRING, REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, REMOTE_USER, REQUEST_METHOD, SCRIPT_NAME, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, SERVER_SOFTWARE In practice, slightly different: –

How to Customize the Environment? C: –fork() & execve() Perl: –set %ENV –fork() & exec() Python: –set %ENV –fork () & execve() Others??? –please share w/ the list

ENV & CGI Examples #!/usr/bin/perl print "Content-type: text/html\n\n"; foreach $key (keys (%ENV)) { print "$key = $ENV{$key} \n"; } while ( ) { print "$_ \n"; } {GET, POST} X {multipart/form-data, application/x-form-www-urlencoded}