home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.pdx.edu / 2014.03.ftp.cs.pdx.edu.tar / ftp.cs.pdx.edu / stash / CGI_WEB / my_list.cgi < prev    next >
Text File  |  1999-04-06  |  973b  |  43 lines

  1. #! /usr/bin/perl
  2. # CGI Script for displaying the contents of a file.
  3. # Version 1.0, 03/99
  4. # Author Matthias Lampe, lampe@cs.pdx.edu
  5. #
  6. # The scripts takes the name of the file as a parameter and simply
  7. # displays the content of the file.
  8. #
  9. # PARAMETERS:
  10. #    file
  11. #
  12. use CGI #qw(:standard);    # include CGI library
  13. $f = CGI->new;        # create new CGI instance
  14.  
  15. print $f->header("text/plain");    # print HTTP header
  16.  
  17. $file = $f->param("file");    # read parameter
  18. $file="list.cgi";
  19.  
  20. #--- just allow to read files in directory of script or
  21. #    subdirectories, i.e. '.' or '/' are not allowed as
  22. #    first characters in filename
  23.  
  24. if ($file =~ /^[.\/]/)
  25. {
  26.    print("Illegal filename $file.");
  27.    die("Illegal filename $file.\n");
  28. }
  29.  
  30. #--- open file or die if file not found
  31. open(FILE_HANDLE, $file) || (print("Error opening file $file: $!")
  32.             && die("Error opening file $file: $!\n"));
  33.  
  34. #--- read content of file
  35. while ($line = <FILE_HANDLE>)
  36. {
  37.    print $line;
  38. }
  39.  
  40. close(FILE_HANDLE);
  41.