#!/usr/bin/perl -T
# notes.cgi
# Ted Fiedler
use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use warnings;
#use Data::Dumper;
$CGI::POST_MAX=1024 * 100; # max 100K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
# Clean up our UNIX environment
# for more infor read perldoc perlsec
$ENV{'PATH'} = '/home/tfiedler/stuff/scripts/web/cgi-bin';
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
# Flush the output buffer
$|++;
# define our vars
my $date = scalar(localtime);
my @text;
my $file="/home/tfiedler/stuff/scripts/web/cgi-bin/notes.tcf";
my $archive="/home/tfiedler/stuff/scripts/web/cgi-bin/archives.tcf";
my $project_name="webtop";
if (param('Archive'))
{
open (TFILE, "$file") or
die "unable to open $file for reading: $!\n";
#( -s "${file}_arc" ) ? open (TFILE2, ">>${file}_arc") or die($!)
# : open (TFILE2, ">${file}_arc") or die($!);
open (TFILE2, ">>$archive") or
die "Unable to open $archive\n";
print TFILE2 "$_" for (<TFILE>);
close(TFILE);
close(TFILE2);
unlink($file);
}
if ( param('delete') )
{
unlink($file);
}
if ( ! -e $file )
{
open (TOUCH, ">$file") or
die("Unable to create $file: $!\n");
close (TOUCH);
}
if ( defined (param('NOTES')) and param('NOTES') =~ m/\S/ )
{
@text=param('NOTES');
open (SERVER_NOTES, ">>$file") or
die("Unable to open $file: $!\n");
for $_(@text)
{
# remove HTML tags <> </>
s/<(?:[^>'"]*|(['"]).*?\1)*>//gs unless param('HTML');
# print the rest to file...
print SERVER_NOTES "[<font color=\"#ff0000\" size=\"-1\">$ENV{
+'REMOTE_ADDR'} - $date</font>]\n",
br, "<font size=\"-1\">$_</font>", br;
}
close (SERVER_NOTES);
}
## Start HTML ##
print header;
print start_html(-title=>"$project_name notes",
-BGCOLOR=>"#cccc99" ), "\n";
print "<tt><center>\n";
print h3("project $project_name notes"),"\n";
print "</center>\n";
print hr,"\n";
print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" wid
+th=\"70%\" align=\"center\">\n\n";
print "<tr align=\"center\" bgcolor=\"#999966\">\n
<th>notes</th>\n
</tr>\n";
print br,br;
print Delete_all() if ( param('delete') or param('Archive') or param('
+HTML') );
if ( -s $file )
{
print Delete_all();
open ( FH, $file ) or
die("unable to open notes: $!\n");
my @notes=<FH>;
print "<td>@notes</td>\n";
}
print "</table>\n";
print br,br,br;
print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" wid
+th=\"70%\" align=\"center\">\n\n";
print "<tr align=\"center\" bgcolor=\"#999966\">\n
<th>change $file </th>\n
</tr>\n";
print "</table>\n",br;
print start_form;
print "<center>\n";
print textarea('NOTES',"", 15, 80), "\n",br;
print checkbox(-name=> 'HTML', -value=> 'off'), " ",
checkbox(-name=> 'delete', -value=> 'off'), " ",
checkbox(-name=> 'Archive', -value=> 'off'), " ",
submit('Submit');
print "</center>\n",br;
if ( -s $archive )
{
print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\"
+ width=\"70%\" align=\"center\">\n\n";
print "<tr align=\"center\" bgcolor=\"#999966\">\n
<th>Archives</th>\n
</tr>\n";
open ( FH2, "$archive" ) or
die "Unable to open $archive: $!\n";
my @archives=<FH2>;
print "<td>@archives</td>\n";
print "</table>\n";
}
print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" hei
+ght=\"20\" width=\"70%\" align=\"center\">\n\n";
print "<tr align=\"center\" bgcolor=\"#999966\">\n
<td> </td>\n
</tr>\n";
print "</table>\n",br;
print end_html;
__END__
=head1 NAME
notes.cgi - Leave notes for other users, logs IP address & date
=head1 AUTHOR
Ted Fiedler<fiedlert@gmail.com>
|