Download
internet engineering course n.
Skip this Video
Loading SlideShow in 5 Seconds..
Internet Engineering Course PowerPoint Presentation
Download Presentation
Internet Engineering Course

Internet Engineering Course

169 Views Download Presentation
Download Presentation

Internet Engineering Course

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Internet Engineering Course Web Application Development

  2. Introduction • Company needs to provide various web services • Hosting intranet applications • Company web site • Various internet applications • Therefore there is a need to develop applications • We should select web application model to use • Discuss on different types of applications

  3. Content • Application development models: • SSI • CGI with Perl • LAMP/WAMP • J2EE • .Net • Typical web applications in an organization • CMS/DMS • Groupware (Collaboration software) • WIKI • Workflow

  4. SSI • Server Side Includes • This is very simple model, not really an application development model suitable for middle to large size applications • Web server processes such instructions and generate dynamic content • Directives that are placed in HTML pages, and evaluated on the server while the pages are being served. • Let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.

  5. SSI • SSI directives have the following syntax: <!--#element attribute=value attribute=value ... --> • It is formatted like an HTML comment • so if you don't have SSI correctly enabled, the browser will ignore it

  6. SSI examples • Commonly used to obtain and display environment variables from the OS: <!--#echo var="DATE_LOCAL" --> • Modification date of the file This document last modified <!--#flastmod file="index.html" --> • Including the results of a CGI program: <!--#include virtual="/cgi-bin/counter.pl" --> • Including a standard footer: <!--#include virtual="/footer.html" -->

  7. SSI examples (cont.) • Executing commands: <pre> <!--#exec cmd="ls" --> </pre> • Conditional expressions: <!--#if expr="${Mac} && ${InternetExplorer}" --> Apologetic text goes here <!--#else --> Cool JavaScript code goes here <!--#endif -->

  8. SSI conclusion • Minimize code duplications • SSI for site management • Creates dynamic content • Can be a security problem

  9. CGI • Common Gateway Interface • Invented in 1993 by NCSA for HTTPd web server • Client requests program to be run on server-side • Web server passes parameters to program through UNIX shell environment variables • Program spawned as separate process via fork • Program's output => Results • Server passes back results (usually in form of HTML) • Good for interfacing external applications with information servers • it is language independent • CGI programs are most often written in PERL, C/C++, VB, Java, or UNIX shell scripts.

  10. CGI Request service Run CGI program … … … print $result HEADERS BODY

  11. CGI with Perl • Write a standard Perl Program • Program's output (to stdout) is sent back as HTTP Response • You must write out everything • Headers • Blank Space • Body

  12. CGI with Perl • Some CGI programs are in machine code, but Perl programs are usually kept in source form, so Perl must be run on them • A source file can be made to be “executable” by adding a line at their beginning that specifies that a language processing program be run on them first • For Perl programs, if the perl system is stored in /usr/local/bin/perl, as is often is in UNIX systems, this is: • #!/usr/local/bin/perl • The file extension .cgi is sometimes used for Perl CGI programs • An HTML document specifies a CGI program with the hypertext reference attribute, href, of an anchor tag, <a>, as in • <a href = “./cgi-bin/reply.cgi>" Click here to run the CGI program, reply.pl </a>

  13. Perl • Practical Extension and Reporting Language. • Originally developed as a utility language for UNIX. • Particularly well suited to manipulate patterns, especially text. • Popular because it is free, available for most operating systems, and relatively easy to learn • Exceedingly powerful, but noisy, and prone to errors.

  14. Perl – a simple example • “Hello World” in Perl #! /usr/bin/perl print "Content-type: text/html\n\n"; print "<html><body><h1>Hello World!"; print "</h1></body></html>\n"; • Simple concept -- the program executes, and the output is sent to the browser that called it.

  15. Perl – a simple counter #! /usr/bin/perl open (INPUT,”count.txt”); @inline= <INPUT>; $count = $inline[0] + 1; close INPUT; open (OUT,”>count.txt”); print OUT “$count\n”; close OUT; print "Content-type: text/html\n\n"; print "<html><body>”; print “<h1>Let’s Count! "</h1>"; print “This page accessed $count times<p>”; print “</body></html>\n";

  16. Perl – Basic syntax • Perl statements end in a semi-colon: • Comments start with a hash symbol and run to the end of the line • Whitespace is irrelevant:

  17. Perl – Basic syntax (cont.) • Variable types: • Scalars: • Arrays:

  18. Perl – Basic syntax (cont.) • Variable types: • Arrays:

  19. Perl – Basic syntax (cont.) • Variable types: • Hashes:

  20. Perl – Basic syntax (cont.) • Variable scoping: • Conditional constructs:

  21. Perl – Basic syntax (cont.) • Conditional constructs: • While:

  22. Perl – Basic syntax (cont.) • for: • foreach:

  23. Perl – Basic syntax (cont.) • Operators: • Arithmetic: • Numeric comparison:

  24. Perl – Basic syntax (cont.) • Operators: • String comparison: • Boolean logic:

  25. Perl – Basic syntax (cont.) • Files and IO:

  26. Perl – Basic syntax (cont.) • String matching:

  27. Perl – Basic syntax (cont.) • String matching:

  28. Perl – Basic syntax (cont.) • Subroutines:

  29. CGI environment variables (%ENV)

  30. CGI environment variables (%ENV) • example- Printing environment variables: #!/usr/bin/perl use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowserfatalsToBrowser); print header; print start_html("Environment"); foreach my $key (sort(keys(%ENV))) { print "$key = $ENV{$key}<br>\n"; } print end_html;

  31. CGI environment variables (%ENV) • Example- Referrer: #!/usr/bin/perl use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowserfatalsToBrowser); print header; print start_html("Referring Page"); print "Welcome, I see you've just come from $ENV{HTTP_REFERER}!<p>\n"; print end_html;

  32. CGI environment variables (%ENV) • Example- Browser detection: #!/usr/bin/perl use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowserfatalsToBrowser); print start_html("Browser Detect"); my($ua) = $ENV{HTTP_USER_AGENT}; print "User-agent: $ua<p>\n"; if (index($ua, "MSIE") > -1) { print "Your browser is Internet Explorer.<p>\n"; } elsif (index($ua, "Netscape") > -1) { print "Your browser is Netscape.<p>\n"; } elsif (index($ua, "Safari") > -1) { print "Your browser is Safari.<p>\n"; } elsif (index($ua, "Opera") > -1) { print "Your browser is Opera.<p>\n"; } elsif (index($ua, "Mozilla") > -1) { print "Your browser is probably Mozilla.<p>\n"; } else { print "I give up, I can't tell what browser you're using!<p>\n"; } print end_html;

  33. Form processing

  34. Form processing (cont.) #!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; print header; print start_html("Thank You"); print h2("Thank You"); my %form; foreach my $p (param()) { $form{$p} = param($p); print "$p = $form{$p}<br>\n"; } print end_html;

  35. Form processing (cont.) #!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; print header; print start_html("Results"); # Set the PATH environment variable to the same path # where sendmail is located: $ENV{PATH} = "/usr/sbin"; # open the pipe to sendmail open (MAIL, "|/usr/sbin/sendmail -oi -t") or &dienice("Can't fork for sendmail: $!\n"); # change this to your own e-mail address my $recipient = 'nullbox@cgi101.com';

  36. Form processing (cont.) # Start printing the mail headers # You must specify who it's to, or it won't be delivered: print MAIL "To: $recipient\n"; # From should probably be the webserver. print MAIL "From: nobody\@cgi101.com\n"; # print a subject line so you know it's from your form cgi. print MAIL "Subject: Form Data\n\n"; # Now print the body of your mail message. foreach my $p (param()) { print MAIL "$p = ", param($p), "\n"; } # Be sure to close the MAIL input stream so that the # message actually gets mailed. close(MAIL);

  37. Form processing (cont.) # Now print a thank-you page print <<EndHTML; <h2>Thank You</h2> <p>Thank you for writing!</p> <p>Return to our <a href="index.html">home page</a>.</p> EndHTML print end_html; # The dienice subroutine handles errors. sub dienice { my($errmsg) = @_; print "<h2>Error</h2>\n"; print "<p>$errmsg</p>\n"; print end_html; exit; }

  38. Setting cookies #!/usr/bin/perl use strict; my $cid = int(rand(1000000)); print "Set-Cookie: NAME=$cid\n"; print "Content-type: text/html\n\n"; print<<EndOfHTML; <html><head><title>Welcome</title></head><body><h2>Welcome!</h2>Your cookie is $cid.<p></body></html> EndOfHTML ;

  39. Reading cookies #!/usr/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; print header(); print start_html("Cookie"); print h2("Welcome!"); if (my $cookie = cookie('mycookie')) { print "Your cookie is $cookie.<br>"; } else { print "You don't have a cookie named `mycookie'.<br>"; } print end_html;

  40. References • http://httpd.apache.org/docs/1.3/howto/ssi.html • http://learn.perl.org/ • http://www.stanford.edu/class/cs193i/handoutsSum2004/21CGI.pdf • http://www.stanford.edu/class/cs193i/handoutsSum2004/22CGI2.pdf • http://www.stanford.edu/class/cs193i/handoutsSum2004/23CGI3.pdf

  41. LAMP

  42. What is LAMP? • LAMP refers to a set of tools: • Linux • Apache • MySQL • PHP • It allows for rapid deployment of software applications • It can be defined as Open Source platform • We have already discussed on Linux and Apache • We should talk more about PHP and MySQL

  43. PHP overview • Open Source server-side scripting language designed specifically for the web. • In-line scripting • Conceived in 1994, now used on +10 million web sites. Now in version 5.0 • Outputs not only HTML but can output XML, images (JPG & PNG), PDF files and even Flash movies (using libswf and Ming) all generated on the fly. Can write these files to the filesystem. • Supports a wide-range of databases (inherently or via ODBC). • PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, POP3, HTTP. • Supports OO programming • Perl- and C-like syntax. Relatively easy to learn. • Website @ http://www.php.net/

  44. Why use PHP • If you like free software or need a free solution • If you need a solution that’s portable across multiple platforms (e.g. Red Hat Linux to Windows 2000) • If you want to add dynamic content to your pages • If you want to make your pages easier to maintain • There are a lot of open source/free packages/libraries available in PHP. • Many mailing lists/sites are dedicated to it. • Examples of uses of PHP : • Small/Medium Portals • Small/Medium Web-Mails • Content Management

  45. What is in a php file • PHP files may contain text, HTML tags and scripts • PHP files are returned to the browser as plain HTML • PHP files have a file extension of ".php", ".php3", or “.phtml“ • Embedding PHP in HTML: <html> <body> <strong>Hello World!</strong><br /> <? echo ‘This is a PHP introductory course!’; ?> </body> </html>

  46. Include mechanism <?php include '../includes/header.html'; ?> <center> content of your web page </center> <?php include 'http://cs.ucy.ac.cy/php/footer.html'; ?> • Content can be included from a local or remote source via such protocols as HTTP, HTTPS, FTP, and FTPS

  47. Types • Scalar types • Boolean • Integer • Float • String • Compound types • Array • Object

  48. Variables • Variables all start with a $ • Case-sensitive • Must start with a letter or underscore, followed by any number of letters, numbers, or underscores • Variables are not explicitly typed • Type of value is inferred on operator application • Uninitialized variables have value undef • What undefmeans depends on context • Numeric context it is 0 • String context it is empty string “”

  49. Variables • To assign values to variables: • $foo = ‘bar’; Data Type: String • $foo = 1; Data Type: integer • $foo = 5.34; Data Type: float • $foo = array(“bar”,”united”); Data Type: Array • Data Types are automatically assigned though you can force a data type by type casting. For example: • $foo = ‘Hello’; • $bar = (int)$foo; • $bar now equals 0 • Almost all variables are local (page). Global variables include $_Session

  50. Example <html> <body> <p> <?php $temperature = 5; $conversionFactorC2K = 273; print("$temperature &deg;C"); echo " is "; print($temperature+$conversionFactorC2K."&deg;K"); ?> </p> </body> </html>