home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / skeptic / bibliography / admin / edit-info.cgi < prev    next >
Text File  |  2009-08-26  |  2KB  |  90 lines

  1. #!/usr/bin/perl
  2.  
  3. %filename =
  4.   (
  5.    "about.html", 1,
  6.    "list.html", 1,
  7.    "skeptic_faq.html", 1,
  8.    "admin/addresses", 1,
  9.   );
  10.  
  11.  
  12. unshift(@INC, "lib");
  13.  
  14. require 'config.pl';
  15. require 'web.pl';
  16. require 'cgi-lib.pl';
  17.  
  18. $temp = "$db::dir/temp$$";
  19.  
  20. &ReadParse; # Read the script input
  21. print "Content-type: text/html\n";
  22.  
  23. # Determine if we are running as an administrator
  24. &error("Cannot run this CGI except from the admin subdir!")
  25.   unless $ENV{SCRIPT_NAME} =~ m!/admin/!;
  26.  
  27. if ($in{filename})
  28. {
  29.     &error("Not a valid filename: $in{filename}")
  30.       unless $filename{ $in{filename} };
  31.  
  32.     $filename = "$bib::base_dir/$in{filename}";
  33. }
  34.  
  35. # If they selected a filename, display it for editing
  36. if ($filename)
  37. {
  38.     # If they're submitting this form, write and exit
  39.     &write_file_and_exit() if $in{data};
  40.  
  41.     open(FILE, $filename)
  42.       || &error("Cannot read file $filename: $!");
  43.  
  44.     undef $/; # read whole file at once
  45.  
  46.     $file_data = <FILE>;
  47.  
  48.     close(FILE);
  49.     $data = &bib::template("edit-info2.html",
  50.                            "FILENAME", $in{filename},
  51.                            "DATA", &untaint($file_data));
  52. }
  53. else
  54. {
  55.     # If they haven't selected anything, display the initial form
  56.     foreach (sort keys %filename)
  57.     {
  58.         $filenames .= "<OPTION>$_";
  59.     }
  60.  
  61.     $data = &bib::template("edit-info.html",
  62.                            "FILENAMES", $filenames);
  63. }
  64.  
  65. print "\n", &bib::template("basic.html",
  66.                            "TITLE", "Edit Info File",
  67.                            "DATA", $data);
  68.  
  69. exit 0;
  70.  
  71.  
  72. sub write_file_and_exit
  73. {
  74.     open(TMP, ">$temp") || &error("Cannot write temp file $temp: $!");
  75.     print TMP $in{data};
  76.     close TMP;
  77.  
  78.     unless (rename($temp, $filename))
  79.     {
  80.         unlink $temp;
  81.         &error("Cannot rename temp file '$temp' to '$filename': $!");
  82.     }
  83.  
  84.     chmod 0664, $filename;
  85.  
  86.     &success("Successfully updated file " .
  87.              "<A HREF=\"$bib::base/$in{filename}\">$in{filename}</A><P>\n" .
  88.              "<A HREF=$bib::admin_cgi/edit-info.cgi>Edit other files</A>");
  89. }
  90.