CSCE Systems Programming

Slides:



Advertisements
Similar presentations
How does the server format the information it gives to the appln program? As environment variables and in standard input.
Advertisements

Configuring Apache Server and Perl for CGI T.A. Maisa Khudair Dr. Qusai Abu Ein.
CGI. XML2 Common Gateway Interface n Georgia Tech 1995 Web Usage Survey –Perl % –C % –Shell Scripts - 8.1% –Tcl - Tool Commercial Language.
CS 898N – Advanced World Wide Web Technologies Lecture 6: PERL and CGI Chin-Chih Chang
Definitions, Definitions, Definitions Lead to Understanding.
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 Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
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
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
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.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CIS 706 Translators I The WIG Project Matthew Dwyer 324E Nichols Hall
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,
How Web Servers and the Internet Work by by: Marshall Brainby: Marshall Brain
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
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.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
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.
Chapter 6 Server-side Programming: Java Servlets
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Application Block Diagram III. SOFTWARE PLATFORM Figure above shows a network protocol stack for a computer that connects to an Ethernet network and.
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.
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
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
Krerk Piromsopa. 1 Department of Computer Engineering. Chulalongkorn University. Web Application Generic Issues.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
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)
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
CS 372 COMPUTER COMMUNICATION AND NETWORKS
CS 330 Class 7 Comments on Exam Programming plan for today:
Web & Web applications DBW 2017.
Web Protocols and Practice
WWW and HTTP King Fahd University of Petroleum & Minerals
CGI I: Basics Web Programming.
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Web Server Design Assignment #5: Unsafe Methods & CGI
Introduction to Programming the WWW I
HTML: Basic Tags & Form Tags
CGI Programming Part II UNIX Security
Client side & Server side scripting
Chapter 2 Interacting with the Customer
World Wide Web Uniform Resource Locator hostname [:port]/path
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
CGI I: Basics Web Programming.
HTML: Basic Tags & Form Tags
Presentation transcript:

CSCE 510 - Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013

Overview Last Time Last times slides 22-36 Stream Server skeleton Web server Assignment Software as a Service (SaaS) Email ?? Today Tools Survey Web Servers again Web Server Skeleton – Pop Quiz Git CGI Common Gateway Interface

How Web Servers Work HowStuffWorks – http://www.howstuffworks.com/web-server1.htm by Marshall Brain - CSCE 510 2013 - http://computer.howstuffworks.com/web-server1.htm

Saas Book Figure 2.1 (Last Time slide 18 repeat) - CSCE 510 2013 - Engineering Long-Lasting Software: An Agile Approach Using SaaS and Cloud Computing (Beta Edition)

Behind the Scenes – Browser Initiates Decompose URL/URI The protocol ("http") The server name ("www.howstuffworks.com") optional :port The path name ("web-server.htm") Name to IP address translation gethostbyname – now obsolete; use getaddrinfo(3) and getnameinfo(3) int getaddrinfo(const char *node  www.howstuffworks.com Ref Saas Book - CSCE 510 2013 -

Domain Name Service (DNS) man –k dns host(1) … no section 3 entries except for pm Name servers - CSCE 510 2013 -

vim /etc/resolv.conf nameserver 129.252.11.15 nameserver 129.252.21.12 nameserver 129.252.21.13 domain cse.sc.edu search cse.sc.edu Command Anyone Know???? - CSCE 510 2013 -

DNS: nslookup(1) ares> nslookup howstuffworks.com Server: 129.252.11.15 Address: 129.252.11.15#53 Non-authoritative answer: Name: howstuffworks.com Address: 107.21.49.125 host(1) gives similar results - CSCE 510 2013 -

How does nslookup does its thing? Or how does getaddrinfo do its thing? DNS packets header question answer Authority look up in local table if not found send DNS (UDP) packet to nameserver At each nameserver: if it does not know knows somebody else to ask - CSCE 510 2013 - http://computer.howstuffworks.com/web-server1.htm

Get request + cookies sometimes Static Pages – just return HTML in file get means – give me the file Stateless connect to sever Send “Get page.html” Server: return page.html in HTML packet Server close connection session info / logins etc how does the server remember? It doesn’t it send a cookie to the browser the browser returns it with later requests - CSCE 510 2013 -

Domain Names .com, .org, .net, .edu top of the food chain for nameservers - CSCE 510 2013 -

Dynamic Pages Web 2.0 ? Dynamic pages – html pages generated on server and then sent to the browser Access Database process form … java servlets cgi - CSCE 510 2013 -

CGI – Common Gateway Interface chroot for static pages “webroot” cgi-bin – place for executables cgi scripts typically perl or C or …. - CSCE 510 2013 -

A simple CGI script cgi program to generate #include <stdio.h>   int main() { printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<body>\n"); printf("<h1>Hello there!</h1>\n"); printf("</body>\n"); printf("</html>\n"); return 0; } A simple HTMl page <html> <body> <h1>Hello there!</h1> </body> </html> compile with gcc simplest.c -o simplest.cgi - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

Perl version #! /usr/bin/perl print "Content-type: text/html\n\n"; print "<html><body><h1>Hello World!"; print "</h1></body></html>\n"; - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

Counter fscanf(f, "%d", &i); i++; fseek(f,0,SEEK_SET); fprintf(f, "%d", i); fclose(f); return i; }   int main() { printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<body>\n"); printf("<h1>The current count is: ") printf("%d</h1>\n", incrementcount()); printf("</body>\n"); printf("</html>\n"); return 0; Counter #include <stdio.h>   int incrementcount() { FILE *f; int i; f=fopen("count.txt", "r+"); if (!f) sleep(1); return -1; } - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

Forms: Sending Input lycos search: http://www.lycos.com/cgi-bin/pursuit?matchmode=and &cat=lycos&query=test&x=10&y=9 - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

HTML form <html> <body> <h1>A super-simple form<h1> <FORM METHOD=GET ACTION="http://www.howstuffworks.com/ cgi-bin/simpleform.cgi"> Enter Your Name: <input name="Name" size=20 maxlength=50> <P> <INPUT TYPE=submit value="Submit"> <INPUT TYPE=reset value="Reset"> </FORM> </body> </html> - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

Process Query String #include <stdio.h> #include <stdlib.h> int main() { printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<body>\n"); printf("<h1>The value entered was: ") printf("%s</h1>\n", getenv("QUERY_STRING")); printf("</body>\n"); printf("</html>\n"); return 0; } - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

Environment passed to scripts AUTH_TYPE CONTENT_LENGTH CONTENT_TYPE GATEWAY_INTERFACE HTTP_ACCEPT HTTP_USER_AGENT 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 - CSCE 510 2013 - http://computer.howstuffworks.com/cgi.htm

A real Form <html> <body> <h1>HSW Survey Form<h1> <FORM METHOD=POST ACTION="http: //www.howstuffworks.com/cgi- bin/survey.cgi"> Enter Your Name: <input name="Name" size=20 maxlength=50> <P>Enter your sex: <input type=radio CHECKED name=sex value=MALE>Male <input type=radio name=sex value=FEMALE>Female <P>Select your age<br> </SELECT> <SELECT size=2 NAME=age> <OPTION> 1-10 <OPTION> 11-20 <OPTION> 21-30 <OPTION> 31-40 <OPTION> 41-50 <OPTION> 51-60 <OPTION> 61 and up </SELECT> <P>Enter Your Comment: <input name="Name" size=40 maxlength=100> - CSCE 510 2013 -