jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:
_____________________________________________________#!/usr/bin/perl -w use strict; use Fcntl ':flock'; # import LOCK_* constants use CGI qw/:standard/; #then why the OO stuff, right? use CGI::Carp qw/fatalsToBrowser /; use POSIX qw(strftime); my $q = CGI->new(); #declare some vars my $mail ='weezelflesh@weezelflesh.com'; my $path_to_text="/home/weezelflesh/www/news/body.txt"; my $path_to_header="/home/weezelflesh/www/news/header.html"; my ($time_words,$topic,$words,$pass,$name,$user); my $url = "http://www.weezelflesh.com/cgi-bin/newspage.cgi"; my $goodpass="********"; parse_form(); show_news(); get_time(); if ($pass ne $goodpass){ bad_hacker_no_cookie(); }else { post_new_news(); } mail_routine(); exit; sub parse_form { my %FORM = $q->Vars('topic','words','pass','name'); $name= $q->param('name')|| "Sludge Factor"; chomp($name); $name =~ s/\s/_/g; $words = $q->param('words'); $words =~ s/\r\n/<BR>/g; $topic= $q->param('topic'); chomp($topic); $user = $ENV{'REMOTE_ADDR'}; chomp($pass = $q->param('pass')); return [$topic,$words,$pass,$name,$user]; } sub get_time { my ($hour,$suffix); $hour= strftime ("%H", localtime ()); if ($hour >= 12) { $suffix="PM"; } else { $suffix = "AM"; } if ($hour > 12) { $hour -= 12; } $time_words= strftime (" at $hour:%M $suffix on %m\/%d\/%Y \n", lo +caltime ()); $time_words; } sub post_new_news { open (FH, "+< $path_to_text") or die "where's the damn file? : $!" +; flock (FH,LOCK_EX) or die "Couldn't flock: $!"; my @old_file = <FH>; seek FH, 0, 0; truncate (FH,0) or die "Can't truncate: $!"; print FH "<tr> <td> </td> <td><BR> <H3><font color= #008080> +$topic <br>"; print FH "posted by <a href=mailto:$name\@weezelflesh.com>$name</ +a>"; print FH "$time_words."; print FH "</H3> </font></td></TR>\n"; print FH "<TR><td> </td> <TD> $words <BR><BR> </TD> </TR>\n\ +n\n"; print FH @old_file; flock(FH,LOCK_UN); #unlock the file close FH or die "close damn you : $!"; print "Location: $url\n\n"; } sub bad_hacker_no_cookie { print "Content-type: text/html\n\n"; print "<HTML> \n"; print "<body bgcolor=000000 text=99CCCC> \n"; print "<CENTER><H1><font face=Arial>!Unauthorized Access!\n"; print "<BR>"; print "<font color = red>Hey bub, stop messin' with my News Page! +\n"; print "<BR>You are at IP address $user !"; print "</H1></CENTER></font></body>"; exit 0; } sub mail_routine { if ($pass ne $goodpass) { open MAIL,"|mail $mail" or die "mail problem : $!"; print MAIL "$user tried to get in using $pass for a password. +\n"; close MAIL; } else { open MAIL,"|mail $mail" or die "mail problem : $!"; print MAIL "$user changed the menu $words.\n"; close MAIL; } } sub show_news { #This sub produces the current news page if ($topic eq "" && $words eq "") { open (FTXT, "$path_to_text") or die "where's the text file? : +$!"; my @text_file = <FTXT>; open (FHTML, "$path_to_header") or die "where's the html file? + : $!"; my @html_file = <FHTML>; print "Content-type: text/html\n\n"; print @html_file; print @text_file; print "</table></div></body></html> \n"; exit; } else { return; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Critque my second script for me?
by Hero Zzyzzx (Curate) on Nov 17, 2001 at 19:59 UTC | |
|
Re: Critque my second script for me?
by chromatic (Archbishop) on Nov 17, 2001 at 23:52 UTC | |
|
Re: Critque my second script for me?
by Jazz (Curate) on Nov 18, 2001 at 00:50 UTC | |
|
My own idea of what I should do next:
by jerrygarciuh (Curate) on Nov 17, 2001 at 19:39 UTC |