#!/usr/bin/perl use CGI ':cgi'; use Configs; use Extras; use CGI::Carp qw(fatalsToBrowser); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @monlist = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); if (length($year) > 2) { $year = $year + 1900; } elsif (length($year) < 2) { $year = "0$year"; } # Adjust Server Day (US TIME) $mday++; $shortyear = substr($year,(length($year)-2),2); $dateformat =~ s/dd/$mday/g; $dateformat =~ s/Mon/$monlist[$mon]/eg; $dateformat =~ s/mm/$mon/g; $dateformat =~ s/Year/$year/g; $dateformat =~ s/yyyy/$year/g; $dateformat =~ s/yy/$shortyear/eg; $action=param('action'); if($action eq "default") { &default; } elsif($action eq "post") { &post; } elsif($action eq "rate") { &rate; } elsif($action eq "clr") { &clr; } else { &default; } sub default { my $this_html = ""; my $post_html = ""; my $page_html = ""; my $post_cnt = ""; my $perpage = 25; my $page_cnt = 0; # my $page_cur = 0; my $cnt = 0; my $start = param('start'); if (-e "$scriptdir/templates/display/posts.html") { open(PAGE, "$scriptdir/templates/display/posts.html"); chomp(@postshtml=); close(PAGE); $post_html=join("\n", @postshtml); } else { $post_html="Error: Can't find Template"; } open (DAT, "$dbasedir/posts.txt"); chomp(@posts=); close(DAT); $post_cnt = @posts; if ($post_cnt > 0) { $page_cnt = $post_cnt / $perpage; } else { $page_cnt = 1; } if ($page_cnt > int(round($page_cnt))) { $page_cnt = int(round($page_cnt)) + 1; } else { $page_cnt = int(round($page_cnt)); } for ($x=0;$x<$start;$x++) { pop(@posts) } @posts = reverse(@posts); foreach $post (@posts) { my ($postid,$date,$name,$email,$title,$content,$ipaddressa)=split(/\|/,$post); open (DAT, "$dbasedir/rating.txt"); chomp(@rates=); close(DAT); my $rate_total = 0; my $rate_count = 0; my $rate_avg = 0; my $rate_html = ""; foreach $rate (@rates) { my ($rateid,$score,$ipaddressb)=split(/\|/,$rate); if ($rateid eq $postid) { $rate_total += $score; $rate_count++; } } if ($rate_total > 0) { $rate_avg = $rate_total / $rate_count; } $rate_avg = round($rate_avg,2); my $link = ""; if ($email =~ /.+?\@.+?\..+/i) { $link = qq~ $name ~; } else { $link = "$name"; } if ($title ne "") { $title = "

$title


"; $rate_html = qq~ Rating: $rate_avg
 1  2  3  4  5  
~; } $this_html .= $post_html; $this_html =~ s/%date%/$date/gi; $this_html =~ s/%link%/$link/gi; $this_html =~ s/%name%/$name/gi; $this_html =~ s/%email%/$email/gi; $this_html =~ s/%title%/$title/gi; $this_html =~ s/%content%/$content/gi; $this_html =~ s/%rating%/$rate_html/gi; $this_html =~ s/%scripturl%/$scripturl/gi; $this_html =~ s/%postid%/$postid/gi; if ($cnt >= $perpage) { last; } $cnt++; } my $x_start = 0; my $x_end = $perpage; for ($x=0;$x$x_start-$x_end] "; $x_start = $x_start + $perpage; $x_end = $x_end + $perpage; } if (-e "$scriptdir/templates/display/default.html") { open(PAGE, "$scriptdir/templates/display/default.html"); chomp(@page=); close(PAGE); $page_html=join("\n", @page); $page_html =~ s/%scripturl%/$scripturl/gi; $page_html =~ s/%content%/$this_html/gi; } else { $post_html="Error: Can't find Template"; } print "Content-type: text/html\n\n"; print "$page_html\n"; exit; } sub post { my $name = param('name'); my $email = param('email'); my $title = param('title'); my $content = param('content'); my $postid = time(); my $ipaddress = $ENV{'REMOTE_ADDR'}; if ($ENV{'HTTP_COOKIE'} =~ /ban/i) { $response = "Error"; $response1 = "Unspecified database error."; $cookie = "Set-Cookie: ban=fool;expires=".gmtime(time()+365*24*3600)." GMT;path=/;\n"; } if ($name eq "") { $response = "Error"; $response1 = "Please hit back and enter a Name."; # } elsif ($email eq "" || $email eq "you\@domain.com") { # $response = "Error"; # $response1 = "Please hit back and enter an Email Address."; } elsif ($content eq "") { $response = "Error"; $response1 = "Please hit back and enter the message contents."; } #Blacklist open (DAT, "$dbasedir/blacklist.txt"); chomp(@blacks=); close(DAT); foreach $black (@blacks) { if ($name =~ /$black/i) { $response = "Error"; $response1 = "Unspecified database error."; $cookie = "Set-Cookie: ban=fool;expires=".gmtime(time()+365*24*3600)." GMT;path=/;\n"; } elsif ($email =~ /$black/i) { $response = "Error"; $response1 = "Unspecified database error."; $cookie = "Set-Cookie: ban=fool;expires=".gmtime(time()+365*24*3600)." GMT;path=/;\n"; } } if ($response eq "") { $content =~ s/\n/
/gi; $content =~ s/\015//gi; $content =~ s/\012//gi; open (DAT, ">>$dbasedir/posts.txt"); print DAT "$postid|$dateformat|$name|$email|$title|$content|$ipaddress\n"; close(DAT); $response = "Success"; $response1 = "Your comments/story have been posted."; } system("chmod 0666 $dbasedir/posts.txt"); open(PAGE, "$scriptdir/templates/display/response.html"); chomp(@page=); close(PAGE); $page_html=join("\n", @page); $page_html =~ s/%scripturl%/$scripturl/gi; $page_html =~ s/%response%/$response/gi; $page_html =~ s/%response1%/$response1/gi; if ($cookie ne "") { print "$cookie"; } print "Content-type: text/html\n\n"; print "$page_html\n"; exit; } sub rate { my $postid = param('PostID'); my $score = param('Score'); my $ipaddress = $ENV{'REMOTE_ADDR'}; if ($ENV{'HTTP_COOKIE'} =~ /ban/i) { $response = "Error"; $response1 = "Unspecified database error."; $cookie = "Set-Cookie: ban=fool;expires=".gmtime(time()+365*24*3600)." GMT;path=/;\n"; } #Blacklist open (DAT, "$dbasedir/blacklist.txt"); chomp(@blacks=); close(DAT); foreach $black (@blacks) { if ($name =~ /$black/i) { $response = "Error"; $response1 = "Unspecified database error."; $cookie = "Set-Cookie: ban=fool;expires=".gmtime(time()+365*24*3600)." GMT;path=/;\n"; } elsif ($email =~ /$black/i) { $response = "Error"; $response1 = "Unspecified database error."; $cookie = "Set-Cookie: ban=fool;expires=".gmtime(time()+365*24*3600)." GMT;path=/;\n"; } } if ($response eq "") { open (DAT, ">>$dbasedir/rating.txt"); print DAT "$postid|$score|$ipaddress\n"; close(DAT); $response = "Success"; $response1 = "Your rating has been added."; } system("chmod 0666 $dbasedir/rating.txt"); open(PAGE, "$scriptdir/templates/display/response.html"); chomp(@page=); close(PAGE); $page_html=join("\n", @page); $page_html =~ s/%scripturl%/$scripturl/gi; $page_html =~ s/%response%/$response/gi; $page_html =~ s/%response1%/$response1/gi; if ($cookie ne "") { print "$cookie"; } print "Content-type: text/html\n\n"; print "$page_html\n"; exit; } sub clr { # $cookie = "Set-Cookie: no=false;Max-Age=-1;path=/;\n"; $cookie = "Set-Cookie: no=false;expires=".gmtime(time()-3600)." GMT;path=/;\n"; open(PAGE, "$scriptdir/templates/display/response.html"); chomp(@page=); close(PAGE); $page_html=join("\n", @page); $page_html =~ s/%scripturl%/$scripturl/gi; $page_html =~ s/%response%/$response/gi; $page_html =~ s/%response1%/$response1/gi; if ($cookie ne "") { print "$cookie"; } print "Content-type: text/html\n\n"; print "$page_html\n"; exit; }