Hi,
I installed the mod auto submit block on to two different urls. I have the blockurl.txt mod working on both also.
The first domain works great. When I try to add a url from my blockurl.txt file, the proper message appears etc...
The second domain, works great for everything, except when I try to add a url from that domains blockurl.txt file, I get Internal server error.
I will show you the line from my error logs, and then place my code from my add.cgi file, (not called that anymore, changed the name a long time ago, I do not think that is an issue.) - a copy of site_html_templates.pl is below also.
error log:
malformed header from script. Bad Header=<html>: /usr/local/psa/home/vhosts/domainname.com/cgi-bin/links/diraddition.pl
Here is the contents of my add.cgi file:
#!/usr/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: add.cgi
# Description: Adds a record marked unvalidated to the database and
# optionally emails someone.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
#
# Setup Notes:
# Make sure the require statement below points to the config file.
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "/home/vhosts/domainname.com/cgi-bin/links/admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
require "$db_lib_path/blockurl.txt"
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;
# We are processing the form.
if (keys %in != 0) {
&process_form;
}
# Otherwise we are displaying the form (in site_html.pl).
else {
if ($db_single_category) {
my %is_valid = map { $_ => 1 } &category_list;
$ENV{'HTTP_REFERER'} =~ s,/[^/]+\.[^/]+$,,;
$ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,;
&rand_img;
&set_cookie($rand);
$is_valid{$1} ? &site_html_add_form ($1) : &site_html_add_form ();
}
else {
&rand_img;
&set_cookie($rand);
&site_html_add_form ();
}
}
}
sub rand_img {
my @dig = (0..9);
srand(time ^ $$);
for (my $i = 0; $i++ < 9;) {
$rand .= qq|$dig[rand(@dig)]|;
}
return $rand;
}
sub set_cookie {
my ($rand) = shift;
use CGI qw(:standard);
$cookie = cookie( -name => 'rand_pass',
-value => "$rand",
-expires => '+1d',
-domain => ''
);
print header( -cookie => $cookie );
open(TMP, ">$rand.txt") || &cgierr("Couldn't open tmp file : $!");
close(TMP);
}
sub logger {
# --------------------------------------------------------
# Log the IP
if (open (HIT, "<addsite.txt")) {
my $input = <HIT>; chomp $input;
($old_rating) = split /\s/, $input;
chomp ($old_time = <HIT>);
chomp (@IP = <HIT>);
(($time - $old_time) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
close HIT;
if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$rating = $rating;
open (HIT, ">addsite.txt") or &cgierr ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &cgierr ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$votes $rating\n$time\n@IP";
close HIT;
&process_form;
}
else {
&site_html_add_ip_error;
}
}
else {
open (HIT, ">addsite.txt") or &cgierr ("Can't increment counter file 'deadlink.txt'. Reason: $!");
print HIT "1 $rating\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
&process_form;
}
}
sub process_form {
# --------------------------------------------------------
my ($key, $status, $line, $output);
# Check the referer.
if (@db_referers and $ENV{'HTTP_REFERER'}) {
$found = 0;
foreach (@db_referers) {
$ENV{'HTTP_REFERER'} =~ /$_/i and $found++ and last;
}
if (!$found) {
&site_html_add_failure ("Auto submission is not allowed in this directory. Please visit the site to add your entry.");
return;
}
}
# This will set system fields like Validated to their proper values.
foreach $key (keys %add_system_fields) {
$in{$key} = $add_system_fields{$key};
}
# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;
open (ID, "<$db_links_id_file_name") or &cgierr("error in process_form. unable to open id file: $db_links_id_file_name. Reason: $!");
$in{$db_key} = <ID> + 1; # Get next ID number
close ID;
# Validate the form input..
$status = &validate_record(%in);
$domain = $in{'URL'};
foreach $url (@blockurl) {
if ($in{'URL'} =~ /$url/i) {
&site_html_add_failure (qq|Url <a href="$domain">$url</a> is restricted from addition|);
return;
}
}
if ($status eq "ok") {
$pass = $in{'rand'};
($ck) = cookie('rand_pass');
if (!$pass) {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("Incorrect Random Pass Code.") and return;
}
if ($ck !~ /^\d{9}$/) {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("Invalid Cookie.") and return;
}
if ($pass ne $ck) {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("Incorrect Random Pass Code.") and return;
}
unless (-e "$pass.txt") {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("You seem like a spammer to me.") and return;
}
# Update the counter.
open (ID, ">$db_links_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_links_id_file_name. Reason: $!");
flock(ID, 2) unless (!$db_use_flock);
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
# Print out the validate input to a "validation database" where it is stored until
# the admin decides to add it into the real database.
open (VAL, ">>$db_valid_name") or &cgierr("error in add_record. unable to open validate file: $db_valid_name. Reason: $!");
flock(VAL, 2) unless (!$db_use_flock);
print VAL &join_encode(%in);
close VAL; # automatically removes file lock
# Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_add_success;
}
else {
&rand_img;
&set_cookie($rand);
&site_html_add_failure($status);
}
}
sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be validated. No error checking as we don't
# want users to see the informative &cgierr output.
# Check to make sure that there is an admin email address defined.
$db_admin_email or &cgierr("Admin Email Address Not Defined in config file!");
my $to = $db_admin_email;
my $from = $in{$db_cols[$db_contact_email]};
my $subject = "addition to Database: $in{'Title'}\n";
my $msg = qq|
The following link is awaiting validation:
Title: $in{'Title'}
URL: $in{'URL'}
Category: $in{'Category'}
Description: $in{'Description'}
Contact Name: $in{'Contact Name'}
Contact Email: $in{'Contact Email'}
Remote Host: $ENV{'REMOTE_HOST'}
Referer: $ENV{'HTTP_REFERER'}
Remote Addr: $ENV{'REMOTE_ADDR'}
To validate, please go to:
$db_script_url
Sincerely,
Tammy
WebMaster Fraser Valley BC.
|;
# Then mail it away!
require "$db_lib_path/Mailer.pm";
my $mailer = new Mailer ( { smtp => $db_smtp_server,
sendmail => $db_mail_path,
from => $from,
subject => $subject,
to => $to,
msg => $msg,
log => $db_mailer_log
} ) or return;
$mailer->send or return;
}
# -------------
# Links
# -------------
# Links Manager
#
# File: site_html.pl
# Description: This library contains all the HTML that will be generated in
# the finished directory.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
# ----------------------------------------------------------------------
# The HTML in this file and the style sheet (links.css) have been authored
# by Chris Croome of webarchitects.
#
# Email: chris@atomism.demon.co.uk
# Web: http://www.webarchitects.co.uk/
# ----------------------------------------------------------------------
# You can put variables here that you would like to use in any
# of your templates.
%globals = (
site_header => &site_header,
site_footer => &site_footer,
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,
banner => \&insertadvert
);
sub insertadvert {
#---------------------------------------------------------
# Insert Banner Ad
my $ad = `/home/vhosts/domainname.com/cgi-bin/ad.cgi`;
$ad =~ s,Content-type:\stext/html,,;
return $ad;
}
sub site_header {
# -----------------------------------
# This is the header file to insert into your LINKS pages.
open (INC, "/home/vhosts/domainname.com/httpdocs/links_pages/header.html") or return "Can't find include file: header.txt";
return join ("", <INC> );
}
sub site_footer {
# -----------------------------------
# This is the footer file to insert into your LINKS pages.
open (INC, "/home/vhosts/domainname.com/httpdocs/links_pages/footer.txt") or return "Can't find include file: footer.txt";
return join ("", <INC> );
}
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.
my %rec = @_;
# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});
return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}
sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
%globals
});
}
sub site_html_new {
# --------------------------------------------------------
# This routine will build a what's new page.
return &load_template ('new.html', {
total => $total,
grand_total => $grand_total,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}
sub site_html_cool {
# --------------------------------------------------------
# This routine will build a what's new page.
return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}
sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.
return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}
sub site_html_ratings {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.
return &load_template ( 'rate_top.html', {
total => $total,
top_rated => $top_rated,
top_votes => $top_votes,
%globals
});
}
########################################################################################
# THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!#
########################################################################################
sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
my $category = shift;
$category ?
($category = qq~$category <input type=hidden name="Category" value="$category">~) :
($category = &build_select_field ("Category", "$in{'Category'}"));
print &load_template ('addsite.html', {
Category => $category,
rand_pass => $rand,
%globals
});
}
sub site_html_add_success {
# --------------------------------------------------------
# This routine determines how the add success page will look like.
&html_print_headers;
print &load_template ('add_success.html', {
%in,
%globals
});
}
sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.
my ($errormsg) = shift;
$in{'Category'} ?
($in{'Category'} = qq~<input type=hidden name="Category" value="$in{'Category'}">$in{'Category'}~) :
($in{'Category'} = &build_select_field ("Category"));
print &load_template ('add_error.html', {
error => $errormsg,
rand_pass => $rand,
%in,
%globals
});
}
sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.
my $category = &build_select_field ("Category", "$in{'Category'}");
&html_print_headers;
print &load_template ('modify.html', {
Category => $category,
%globals
});
}
sub site_html_modify_success {
# --------------------------------------------------------
# This routine determines how the modify success page will look like.
&html_print_headers;
print &load_template ('modify_success.html', {
%in,
%globals
});
}
sub site_html_modify_failure {
# --------------------------------------------------------
# This routine determines how the modify failure page will look like.
my $errormsg = shift;
$in{'Category'} = &build_select_field ("Category", $in{'Category'});
&html_print_headers;
print &load_template ('modify_error.html', {
error => $errormsg,
%in,
%globals
});
}
sub site_html_add_confirm {
# --------------------------------------------------------
# This routine determines how the add success page will look like.
&html_print_headers;
print &load_template ('add_confirm.html', {
%in,
%globals
});
}
sub site_html_search_results {
# --------------------------------------------------------
# This routine displays the search results.
#
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_results.html', {
term => $term,
link_results => $link_results,
category_results => $category_results,
next => $next,
cat_hits => $cat_hits,
link_hits => $link_hits,
%in,
%globals
});
}
sub site_html_search_failure {
# --------------------------------------------------------
# This routine displays a failed search page with error in $error.
#
my $error = shift;
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_error.html', {
term => $term,
error => $error,
%in,
%globals
});
}
sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.
&html_print_headers;
print &load_template ('search.html', {
term => $term,
error => $error,
%in,
%globals
});
}
sub site_html_mailing {
# --------------------------------------------------------
# This routine displays your mailing list subscribe/unsubscribe form.
#
my $action = shift;
my $message;
($action eq 'subscribe') and ($message = qq~You've been successfully subscribed to the mailing list!~);
($action eq 'unsubscribe') and ($message = qq~You've been successfully removed from the mailing list!~);
&html_print_headers;
print &load_template ('email.html', {
message => $message,
%in,
%globals
});
}
sub site_html_mailing_error {
# --------------------------------------------------------
# This routine is displayed if there was a problem subscribing.
#
my $error = shift;
&html_print_headers();
print &load_template ('email_error.html', {
error => $error,
%in,
%globals
});
}
sub site_html_rate_form {
# --------------------------------------------------------
# This routine determines how the rate form page will look like.
#
my %rec = @_;
&html_print_headers;
print &load_template ('rate.html', {
%rec,
%globals
});
}
sub site_html_rate_success {
# --------------------------------------------------------
# This routine determines how the rate success page will look like.
&html_print_headers;
print &load_template ('rate_success.html', {
%in,
%globals
});
}
sub site_html_rate_failure {
# --------------------------------------------------------
# This routine determines how the rate failure page will look like.
my ($errormsg) = shift;
&html_print_headers;
print &load_template ('rate_error.html', {
error => $errormsg,
%in,
%globals
});
}
sub site_html_add_ip_error {
# --------------------------------------------------------
# This routine determines how the add site IP error page will look like.
&html_print_headers();
print &load_template ('add_ip_error.html', {
%in,
%globals
});
}
########################################################################################
# THE FOLLOWING DETERMINES YOUR CATEGORY LISTING, IT'S NOT TEMPLATE BASED (YET)! #
########################################################################################
sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);
# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;
foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];
# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];
# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><FONT SIZE="2" FACE="Verdana, Arial" COLOR="000000"><a href="$url">$category_name</a> ($numlinks) |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd>$description </dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}
# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}
1;[/code]
Let me know if you need more info. I have tried all night, I have compared each of the files, and I cant seem to find it.
Thanks in advance, greatly appreciated!
Tammy
I installed the mod auto submit block on to two different urls. I have the blockurl.txt mod working on both also.
The first domain works great. When I try to add a url from my blockurl.txt file, the proper message appears etc...
The second domain, works great for everything, except when I try to add a url from that domains blockurl.txt file, I get Internal server error.
I will show you the line from my error logs, and then place my code from my add.cgi file, (not called that anymore, changed the name a long time ago, I do not think that is an issue.) - a copy of site_html_templates.pl is below also.
error log:
malformed header from script. Bad Header=<html>: /usr/local/psa/home/vhosts/domainname.com/cgi-bin/links/diraddition.pl
Here is the contents of my add.cgi file:
Code:
#!/usr/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: add.cgi
# Description: Adds a record marked unvalidated to the database and
# optionally emails someone.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
#
# Setup Notes:
# Make sure the require statement below points to the config file.
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "/home/vhosts/domainname.com/cgi-bin/links/admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
require "$db_lib_path/blockurl.txt"
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;
# We are processing the form.
if (keys %in != 0) {
&process_form;
}
# Otherwise we are displaying the form (in site_html.pl).
else {
if ($db_single_category) {
my %is_valid = map { $_ => 1 } &category_list;
$ENV{'HTTP_REFERER'} =~ s,/[^/]+\.[^/]+$,,;
$ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,;
&rand_img;
&set_cookie($rand);
$is_valid{$1} ? &site_html_add_form ($1) : &site_html_add_form ();
}
else {
&rand_img;
&set_cookie($rand);
&site_html_add_form ();
}
}
}
sub rand_img {
my @dig = (0..9);
srand(time ^ $$);
for (my $i = 0; $i++ < 9;) {
$rand .= qq|$dig[rand(@dig)]|;
}
return $rand;
}
sub set_cookie {
my ($rand) = shift;
use CGI qw(:standard);
$cookie = cookie( -name => 'rand_pass',
-value => "$rand",
-expires => '+1d',
-domain => ''
);
print header( -cookie => $cookie );
open(TMP, ">$rand.txt") || &cgierr("Couldn't open tmp file : $!");
close(TMP);
}
sub logger {
# --------------------------------------------------------
# Log the IP
if (open (HIT, "<addsite.txt")) {
my $input = <HIT>; chomp $input;
($old_rating) = split /\s/, $input;
chomp ($old_time = <HIT>);
chomp (@IP = <HIT>);
(($time - $old_time) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
close HIT;
if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$rating = $rating;
open (HIT, ">addsite.txt") or &cgierr ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &cgierr ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$votes $rating\n$time\n@IP";
close HIT;
&process_form;
}
else {
&site_html_add_ip_error;
}
}
else {
open (HIT, ">addsite.txt") or &cgierr ("Can't increment counter file 'deadlink.txt'. Reason: $!");
print HIT "1 $rating\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
&process_form;
}
}
sub process_form {
# --------------------------------------------------------
my ($key, $status, $line, $output);
# Check the referer.
if (@db_referers and $ENV{'HTTP_REFERER'}) {
$found = 0;
foreach (@db_referers) {
$ENV{'HTTP_REFERER'} =~ /$_/i and $found++ and last;
}
if (!$found) {
&site_html_add_failure ("Auto submission is not allowed in this directory. Please visit the site to add your entry.");
return;
}
}
# This will set system fields like Validated to their proper values.
foreach $key (keys %add_system_fields) {
$in{$key} = $add_system_fields{$key};
}
# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;
open (ID, "<$db_links_id_file_name") or &cgierr("error in process_form. unable to open id file: $db_links_id_file_name. Reason: $!");
$in{$db_key} = <ID> + 1; # Get next ID number
close ID;
# Validate the form input..
$status = &validate_record(%in);
$domain = $in{'URL'};
foreach $url (@blockurl) {
if ($in{'URL'} =~ /$url/i) {
&site_html_add_failure (qq|Url <a href="$domain">$url</a> is restricted from addition|);
return;
}
}
if ($status eq "ok") {
$pass = $in{'rand'};
($ck) = cookie('rand_pass');
if (!$pass) {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("Incorrect Random Pass Code.") and return;
}
if ($ck !~ /^\d{9}$/) {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("Invalid Cookie.") and return;
}
if ($pass ne $ck) {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("Incorrect Random Pass Code.") and return;
}
unless (-e "$pass.txt") {
&rand_img;
&set_cookie($rand);
&site_html_add_failure("You seem like a spammer to me.") and return;
}
# Update the counter.
open (ID, ">$db_links_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_links_id_file_name. Reason: $!");
flock(ID, 2) unless (!$db_use_flock);
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
# Print out the validate input to a "validation database" where it is stored until
# the admin decides to add it into the real database.
open (VAL, ">>$db_valid_name") or &cgierr("error in add_record. unable to open validate file: $db_valid_name. Reason: $!");
flock(VAL, 2) unless (!$db_use_flock);
print VAL &join_encode(%in);
close VAL; # automatically removes file lock
# Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_add_success;
}
else {
&rand_img;
&set_cookie($rand);
&site_html_add_failure($status);
}
}
sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be validated. No error checking as we don't
# want users to see the informative &cgierr output.
# Check to make sure that there is an admin email address defined.
$db_admin_email or &cgierr("Admin Email Address Not Defined in config file!");
my $to = $db_admin_email;
my $from = $in{$db_cols[$db_contact_email]};
my $subject = "addition to Database: $in{'Title'}\n";
my $msg = qq|
The following link is awaiting validation:
Title: $in{'Title'}
URL: $in{'URL'}
Category: $in{'Category'}
Description: $in{'Description'}
Contact Name: $in{'Contact Name'}
Contact Email: $in{'Contact Email'}
Remote Host: $ENV{'REMOTE_HOST'}
Referer: $ENV{'HTTP_REFERER'}
Remote Addr: $ENV{'REMOTE_ADDR'}
To validate, please go to:
$db_script_url
Sincerely,
Tammy
WebMaster Fraser Valley BC.
|;
# Then mail it away!
require "$db_lib_path/Mailer.pm";
my $mailer = new Mailer ( { smtp => $db_smtp_server,
sendmail => $db_mail_path,
from => $from,
subject => $subject,
to => $to,
msg => $msg,
log => $db_mailer_log
} ) or return;
$mailer->send or return;
}
# -------------
# Links
# -------------
# Links Manager
#
# File: site_html.pl
# Description: This library contains all the HTML that will be generated in
# the finished directory.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
# ----------------------------------------------------------------------
# The HTML in this file and the style sheet (links.css) have been authored
# by Chris Croome of webarchitects.
#
# Email: chris@atomism.demon.co.uk
# Web: http://www.webarchitects.co.uk/
# ----------------------------------------------------------------------
# You can put variables here that you would like to use in any
# of your templates.
%globals = (
site_header => &site_header,
site_footer => &site_footer,
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,
banner => \&insertadvert
);
sub insertadvert {
#---------------------------------------------------------
# Insert Banner Ad
my $ad = `/home/vhosts/domainname.com/cgi-bin/ad.cgi`;
$ad =~ s,Content-type:\stext/html,,;
return $ad;
}
sub site_header {
# -----------------------------------
# This is the header file to insert into your LINKS pages.
open (INC, "/home/vhosts/domainname.com/httpdocs/links_pages/header.html") or return "Can't find include file: header.txt";
return join ("", <INC> );
}
sub site_footer {
# -----------------------------------
# This is the footer file to insert into your LINKS pages.
open (INC, "/home/vhosts/domainname.com/httpdocs/links_pages/footer.txt") or return "Can't find include file: footer.txt";
return join ("", <INC> );
}
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.
my %rec = @_;
# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});
return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}
sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
%globals
});
}
sub site_html_new {
# --------------------------------------------------------
# This routine will build a what's new page.
return &load_template ('new.html', {
total => $total,
grand_total => $grand_total,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}
sub site_html_cool {
# --------------------------------------------------------
# This routine will build a what's new page.
return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}
sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
%rec,
%globals
} );
}
sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.
return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}
sub site_html_ratings {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.
return &load_template ( 'rate_top.html', {
total => $total,
top_rated => $top_rated,
top_votes => $top_votes,
%globals
});
}
########################################################################################
# THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!#
########################################################################################
sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
my $category = shift;
$category ?
($category = qq~$category <input type=hidden name="Category" value="$category">~) :
($category = &build_select_field ("Category", "$in{'Category'}"));
print &load_template ('addsite.html', {
Category => $category,
rand_pass => $rand,
%globals
});
}
sub site_html_add_success {
# --------------------------------------------------------
# This routine determines how the add success page will look like.
&html_print_headers;
print &load_template ('add_success.html', {
%in,
%globals
});
}
sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.
my ($errormsg) = shift;
$in{'Category'} ?
($in{'Category'} = qq~<input type=hidden name="Category" value="$in{'Category'}">$in{'Category'}~) :
($in{'Category'} = &build_select_field ("Category"));
print &load_template ('add_error.html', {
error => $errormsg,
rand_pass => $rand,
%in,
%globals
});
}
sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.
my $category = &build_select_field ("Category", "$in{'Category'}");
&html_print_headers;
print &load_template ('modify.html', {
Category => $category,
%globals
});
}
sub site_html_modify_success {
# --------------------------------------------------------
# This routine determines how the modify success page will look like.
&html_print_headers;
print &load_template ('modify_success.html', {
%in,
%globals
});
}
sub site_html_modify_failure {
# --------------------------------------------------------
# This routine determines how the modify failure page will look like.
my $errormsg = shift;
$in{'Category'} = &build_select_field ("Category", $in{'Category'});
&html_print_headers;
print &load_template ('modify_error.html', {
error => $errormsg,
%in,
%globals
});
}
sub site_html_add_confirm {
# --------------------------------------------------------
# This routine determines how the add success page will look like.
&html_print_headers;
print &load_template ('add_confirm.html', {
%in,
%globals
});
}
sub site_html_search_results {
# --------------------------------------------------------
# This routine displays the search results.
#
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_results.html', {
term => $term,
link_results => $link_results,
category_results => $category_results,
next => $next,
cat_hits => $cat_hits,
link_hits => $link_hits,
%in,
%globals
});
}
sub site_html_search_failure {
# --------------------------------------------------------
# This routine displays a failed search page with error in $error.
#
my $error = shift;
my $term = &urlencode ($in{'query'});
&html_print_headers;
print &load_template ('search_error.html', {
term => $term,
error => $error,
%in,
%globals
});
}
sub site_html_search_form {
# --------------------------------------------------------
# This routine displays the search form.
&html_print_headers;
print &load_template ('search.html', {
term => $term,
error => $error,
%in,
%globals
});
}
sub site_html_mailing {
# --------------------------------------------------------
# This routine displays your mailing list subscribe/unsubscribe form.
#
my $action = shift;
my $message;
($action eq 'subscribe') and ($message = qq~You've been successfully subscribed to the mailing list!~);
($action eq 'unsubscribe') and ($message = qq~You've been successfully removed from the mailing list!~);
&html_print_headers;
print &load_template ('email.html', {
message => $message,
%in,
%globals
});
}
sub site_html_mailing_error {
# --------------------------------------------------------
# This routine is displayed if there was a problem subscribing.
#
my $error = shift;
&html_print_headers();
print &load_template ('email_error.html', {
error => $error,
%in,
%globals
});
}
sub site_html_rate_form {
# --------------------------------------------------------
# This routine determines how the rate form page will look like.
#
my %rec = @_;
&html_print_headers;
print &load_template ('rate.html', {
%rec,
%globals
});
}
sub site_html_rate_success {
# --------------------------------------------------------
# This routine determines how the rate success page will look like.
&html_print_headers;
print &load_template ('rate_success.html', {
%in,
%globals
});
}
sub site_html_rate_failure {
# --------------------------------------------------------
# This routine determines how the rate failure page will look like.
my ($errormsg) = shift;
&html_print_headers;
print &load_template ('rate_error.html', {
error => $errormsg,
%in,
%globals
});
}
sub site_html_add_ip_error {
# --------------------------------------------------------
# This routine determines how the add site IP error page will look like.
&html_print_headers();
print &load_template ('add_ip_error.html', {
%in,
%globals
});
}
########################################################################################
# THE FOLLOWING DETERMINES YOUR CATEGORY LISTING, IT'S NOT TEMPLATE BASED (YET)! #
########################################################################################
sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#
my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);
# Print Header.
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;
foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];
# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];
# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><FONT SIZE="2" FACE="Verdana, Arial" COLOR="000000"><a href="$url">$category_name</a> ($numlinks) |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd>$description </dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}
# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}
1;[/code]
Let me know if you need more info. I have tried all night, I have compared each of the files, and I cant seem to find it.
Thanks in advance, greatly appreciated!
Tammy