#!/usr/bin/perl # set up # # this is intended for internal use only -- on a relatively safe intranet # # DON'T USE IT ON THE INTERNET!!! # # you should be able to rename the script file, and everything will work. # # whatever you name the script file, create a text file of the same name, # minus the extension, + "txt". Example: text_buf.pl -> text_buf.txt # # the script file needs to be executable by the web server # the text file needs to be read/write by the web server (not the world!) # # change the $MAX_LENGTH variable unless you like 100,000 as max # set max length of text buffer $MAX_LENGTH = 100000; # to minimize config, read a lot of environment variables $url = "http://$ENV{'HTTP_HOST'}$ENV{'REQUEST_URI'}"; # mindless regexp hacking to get scriptname.txt (minus any script ext) $textfile = $ENV{'SCRIPT_NAME'}; #$textfile = "/cgi-bin/ENV.pl"; $textfile =~ s|.*/||; if ($textfile =~ m|(.*)\.|) { $textfile = "$1"; } $textfile .= ".txt"; #print "tf: $textfile\n"; # html form $html_form = "

   

"; if ($ENV{'REQUEST_METHOD'} eq "POST") { # get value of form field "ta" and decode read(STDIN, $query, $ENV{'CONTENT_LENGTH'}); @vars = split(/&/, $query); foreach $var (@vars) { ($name, $value) = split('=', $var); if ($name eq 'ta') { $value =~ y/\+/ /; $value =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $ta = "$value"; last; } } # truncate to cover max length if (length($ta) > $MAX_LENGTH) { $ta = substr($ta, 0, $MAX_LENGTH); } # dumb regexps to replace > < & with character entities if ($ta) { $ta =~ s|\&|\&|sg; $ta =~ s|\>|\>|sg; $ta =~ s|\<|\<|sg; } # lock, write, release text file (works where os supports perl's lock) open(FH, ">$textfile") or die "can't open $textfile: $!"; flock(FH, 2) or die "can't flock $textfile: $!"; print FH $ta; close(FH) or die "can't close $textfile: $!"; # use regexed $ta in output area of form # (note: output doesn't reflect file, if there's a screw-up) $content=$ta; } else { # if GET, read text file open(FH, "<$textfile") or die "can't open $textfile: $!"; flock(FH, 1) or die "can't flock $textfile: $!"; undef $/; $content = ; close(FH); } # for get and post print "Content-type: text/html Text Buffer $html_form

$content
";