#!/usr/bin/perl use CGI; $query = new CGI; # Retrieve web argument values. $act = $query->param( 'act' ); $name = $query->param( 'name' ); if ( ( $act eq "Submit" ) || ( $act eq "Help" ) ) { print( "Content-type: text/html\n\n" ); print < Results

EndofHTML if ( $act eq "Submit" ) { # Remove leading and trailing spacing. $name =~ s/^\s*(\S*)\s*$/$1/; # For security, remove some Unix metacharacters. $name =~ s/;|>|>>|<|\*|\?|\&|\|//g; # For concurrency control, exclusively lock a dummy file. open ( fh, "> dummy.txt" ); flock ( fh, 2 ); system( "./CGIDemo '$name'" ); close ( fh ); } elsif ( $act eq "Help" ) { system( "/bin/cat Help.html" ); } else { print( "No such option: $act" ); } print <

EndofHTML } elsif ( $act eq "HTML source" ) { print ( "Content-type: text/plain\n\n" ); system( "cat /home/wenchen/public_html/course/351/week3/3p.html" ); } elsif ( $act eq "CGI Perl source" ) { print ( "Content-type: text/plain\n\n" ); system( "cat /home/wenchen/public_html/cgi-bin/351/week3/CGIDemo.pl" ); } else { print( "Content-type: text/plain\n\n" ); print( "No such option: $act" ); }