CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl - 46.7% –C - 12.5% –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.

Slides:



Advertisements
Similar presentations
CGI Scripting and Vulnerabilities COEN 351: E-commerce Security  Thomas Schwarz, S.J
Advertisements

Common Gateway Interface Mechanism using Perl & Python NOTE: Some of slides are extracted from the course notes of USC CS571 and Deitel & Associates. These.
PART 6 Application Layer
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Exercise session week 2 Introduction to CGI and EiffelWeb.
How does the server format the information it gives to the appln program? As environment variables and in standard input.
Configuring Apache Server and Perl for CGI T.A. Maisa Khudair Dr. Qusai Abu Ein.
Web Services Nov 26, 2002 Topics HTTP Serving static content Serving dynamic content class27.ppt “The course that gives CMU its Zip!”
PZ15A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ15A - The Internet Programming Language Design and.
Lecture 9, : The Internet, Summer : The Internet Lecture 9: Web Services II David O’Hallaron School of Computer Science and Department.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
What is CGI? The Common Gateway Interface (CGI) is a mechanism that allows Web clients to execute programs on a Web server and to receive their output.
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.
CGI Scripts. 2 GET n Form data forms query string and is appended to the URL of the script –Can be accessed by using the environment variable QUERY_STRING.
Internet Services II April 27, 2000 Topics dynamic content Tiny Web server tour class28.ppt.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
1 Web Servers Web Protocols and Practice Chapter 4.
Sockets and Web services April 23, 2002 Topics Client-server model Sockets Interface HTTP Serving static content Serving dynamic content Reading 12.7,
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
Emlékeztető December 1.-én pótoljuk az elmaradt előadást (nov. 24-ről) az A/1 228-as teremben ig December 8.-án tartjuk a pótZH-t a sikertelen ZH-t.
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.
Ch27 - Common Gateway Interface (CGI) and Perl
Web Forms with PHP COEN 351. Displaying and processing a simple form if( array_key_exists(‘my name’,$_POST)){ print “Hello, “.$_POST[‘my_name’]; } else.
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.
CIS 706 Translators I The WIG Project Matthew Dwyer 324E Nichols Hall
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
CGI Scripting and Vulnerabilities COEN 351: E-commerce Security  Thomas Schwarz, S.J
Nic Shulver, Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.
Networking Programming --Web Server(I) 1. Outline Web History Web Servers –HTTP Protocol –Web Content –CGI Suggested Reading: –
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
CSCE Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013.
CGI programming Peter Verhás January What this tutorial is about Introduction to CGI programming Using ScriptBasic –Simple to program –Simple to.
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
ELECTRONIC COMMERCE- Framework, Technologies and Applications © Tata McGraw-Hill 1 Electronic Commerce: Information Publishing Technology.
Approaches for creating dynamic web pages Server-side processing: Server receives a request, performs all processing necessary to create a dynamic web.
Perl: Lecture 2 Advanced RE & CGI. Regular Expressions 2.
Perl CGI What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. Perl have a *very* nice interface to create CGI.
CGI Scripting and Vulnerabilities COEN 351: E-commerce Security.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Form Data Encoding GET – URL encoded POST – URL encoded
Internet and Intranet Fundamentals
Netprog 2002 CGI Programming1 CGI Programming CLIENT HTTP SERVER CGI Program http request http response setenv(), dup(), fork(), exec(),...
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Web Services November 30, 2004 Topics HTTP Serving static content Serving dynamic content “The course that gives CMU its Zip!” class26.ppt.
Krerk Piromsopa. 1 Department of Computer Engineering. Chulalongkorn University. Web Application Generic Issues.
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.
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.
WEB1P webarch1 Web architecture Dr Jim Briggs. WEB1P webarch2 What is the web? Distributed system Client-server system Characteristics of clients and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 04/03/12.
Web Server Design Week 15 Old Dominion University Department of Computer Science CS 495/595 Spring 2009 Michael L. Nelson 4/20/09.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
1 The Internet Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Web & Web applications DBW 2017.
Web Protocols and Practice
Web Server Design Assignment #5: Unsafe Methods & CGI
CSCE Systems Programming
The HTTP Protocol COSC 2206 Internet Tools The HTTP Protocol
Environment Variables
An Example of a TCP/IP Application: the World Wide Web
Web Server Design Week 16 Old Dominion University
MSc Internet Computing
Presentation transcript:

CGI

XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl % –C % –Shell Scripts - 8.1% –Tcl - Tool Commercial Language –Visual Basic –Java –C++ –AppleScript

XML3 Example Shell Script #!/bin/sh #Filename: hello.sh.cgi echo "Content-type: text/html" echo echo " Hello! " echo " Hello World! "

XML4 Hello World! in Perl #!/usr/bin/perl print "Content-type: text/html\n\n"; print " Hello! \n"; print " Hello, World! \n";

XML5 Hello World! in C #include #include main( ) { printf("Content-type: text/html\n\n"); printf("<html><head><title>Hello!</title></head>\n"); printf(" Hello, World! \n"); }

XML6 Environment Variables Using a Shell Script #!/bin/sh echo Content-type: text/plain echo echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE echo REQUEST_METHOD = $REQUEST_METHOD echo SCRIPT_NAME = $SCRIPT_NAME echo QUERY_STRING = $QUERY_STRING echo SERVER_SOFTWARE = $SERVER_SOFTWARE echo SERVER_NAME = $SERVER_NAME echo SERVER_PROTOCOL = $SERVER_PROTOCOL echo SERVER_PORT = $SERVER_PORT echo HTTP_USER_AGENT = $HTTP_USER_AGENT echo HTTP_ACCEPT = $HTTP_ACCEPT

XML7 Environment Variables Using a Shell Script echo PATH_INFO = $PATH_INFO echo PATH_TRANSLATED = $PATH_TRANSLATED echo REMOTE_HOST = $REMOTE_HOST echo REMOTE_ADDR = $REMOTE_ADDR echo REMOTE_USER = $REMOTE_USER echo REMOTE_IDENT = $REMOTE_IDENT echo AUTH_TYPE = $AUTH_TYPE echo CONTENT_TYPE = $CONTENT_TYPE echo CONTENT_LENGTH = $CONTENT_LENGTH

XML8 Environment Variables in Perl #!/usr/bin/perl print "Content-type: text/plain\n\n" print "GATEWAY_INTERFACE = $ENV{'GATEWAY_INTERFACE'}\n" print "REQUEST_METHOD = $ENV{'REQUEST_METHOD'}\n" print "SCRIPT_NAME = $ENV{'SCRIPT_NAME'}\n" print "QUERY_STRING = $ENV{'QUERY_STRING'}\n" print "SERVER_SOFTWARE = $ENV{'SERVER_SOFTWARE'}\n" print "SERVER_NAME = $ENV{'SERVER_NAME'}\n" print "SERVER_PROTOCOL = $ENV{'SERVER_PROTOCOL'}\n"

XML9 Environment Variables in Perl print "SERVER_PORT = $ENV{'SERVER_PORT'}\n" print "HTTP_USER_AGENT = $ENV{'HTTP_USER_AGENT'}\n" print "HTTP_ACCEPT = $ENV{'HTTP_ACCEPT'}\n" print "PATH_INFO = $ENV{'PATH_INFO'}\n" print "PATH_TRANSLATED = $ENV{'PATH_TRANSLATED'}\n" print "REMOTE_HOST = $ENV{'REMOTE_HOST'}\n" print "REMOTE_ADDR = $ENV{'REMOTE_ADDR'}\n" print "REMOTE_USER = $ENV{'REMOTE_USER'}\n" print "REMOTE_IDENT = $ENV{'REMOTE_IDENT'}\n"

XML10 Environment Variables in Perl print "AUTH_TYPE = $ENV{'AUTH_TYPE'}\n" print "CONTENT_TYPE = $ENV{'CONTENT_TYPE'}\n" print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n"

XML11 Environment Variables in C #include #include char *cp; char *empty = "[empty]" main( ) { printf ("Content-type: text/plain\n\n"); #define safenv(a) ((cp = getenv(a)) ? cp : empty) printf("GATEWAY_INTERFACE = %s\n", safenv("GATEWAY_INTERFACE"));

XML12 Environment Variables in C printf("REQUEST_METHOD = %s\n", safenv("REQUEST_METHOD")); printf("SCRIPT_NAME = %s\n", safenv("SCRIPT_NAME")); printf("QUERY_STRING = %s\n", safenv("QUERY_STRING")); printf("SERVER_SOFTWARE = %s\n" safenv("SERVER_SOFTWARE")); printf("SERVER_NAME = %s\n", safenv("SERVER_NAME")); printf("SERVER_PROTOCOL = %s\n", safenv("SERVER_PROTOCOL")); printf("SERVER_PORT = %s\n", safenv("SERVER_PORT")); printf("HTTP_USER_AGENT = %s\n", safenv("HTTP_USER_AGENT"));

XML13 Environment Variables in C printf("HTTP_ACCEPT = %s\n", safenv("HTTP_ACCEPT")); printf("PATH_INFO = %s\n", safenv("PATH_INFO")); printf("PATH_TRANSLATED = %s\n", safenv("PATH_TRANSLATED")); printf("REMOTE_HOST = %s\n", safenv("REMOTE_HOST")); printf("REMOTE_ADDR = %s\n", safenv("REMOTE_ADDR")); printf("REMOTE_USER = %s\n", safenv("REMOTE_USER"));

XML14 Environment Variables in C printf("REMOTE_IDENT = %s\n", safenv("REMOTE_IDENT")); printf("AUTH_TYPE = %s\n", safenv("AUTH_TYPE")); printf("CONTENT_TYPE = %s\n", safenv("CONTENT_TYPE")); printf("CONTENT_LENGTH = %s\n", safenv("CONTENT_LENGTH")); }

XML15 Standard CGI Variables n User information –HTTP_USER_AGENT n Name and version of user's browser n name/version library/version n Contains information about any proxy gateway –Used when firewalls exist

XML16 Standard CGI Variables n User information –HTTP_USER_AGENT n Examples –Mozilla/2.0b1J (Windows; I; 32 bit) –Mozilla/1.22 (Windows; I; 16 bit) –Lynx/2.3.7 BETA libwww/2.14 –Microsoft Internet Explorer/ (Windows 95)

XML17 Standard CGI Variables n User information –HTTP_ACCEPT n Gives MIME formats that the browser can accept –REMOTE_HOST n IP address of user n Always given –REMOTE_ADDR n Text-equivalent host name of user IP address n Not always given

XML18 Standard CGI Variables n Server information –SERVER_SOFTWARE n Name and version of server software n name/version –Apache/0.6.4b –SERVER_NAME n Server’s host name or IP address – –GATEWAY_INTERFACE n CGI revision –CGI/revision –CGI/1.1

XML19 Standard CGI Variables n Request-specific information –QUERY_STRING n Very important n Most common method of passing information to server n Suppose URL is submitted –All characters after the ? will be put into QUERY_STRING

XML20 Standard CGI Variables n Request-specific information –SCRIPT_NAME n File name of the CGI program –SERVER_PROTOCOL n Name and revision of the protocol that request came in from n protocol/revision –HTTP/1.0

XML21 Standard CGI Variables n Request-specific information –SERVER_PORT n Port on which request came in n Usually 80 –PATH_INFO n One can pass another file path to the CGI program by appending it to the URL n code.cgi/a/b/c –PATH_INFO will contain the extra path /a/b/c

XML22 Standard CGI Variables n Request-specific information –PATH_TRANSLATED n Contains PATH_INFO appended to the document root path of the server –/x/y/z/a/b/c –CONTENT_TYPE n Used for queries that have attached information, such as POST requests n MIME content-type of data n type/subtype –application/x-www-form-urlencoded

XML23 Standard CGI Variables n Request-specific information –CONTENT_LENGTH n Number of bytes of data –AUTH_TYPE n Contains authentication method used to validate user –REQUEST_METHOD n Method used for request –Usually either post or get