Gossamer Forum
Home : Products : Gossamer Links : Discussions :

add.cgi error

Quote Reply
add.cgi error
Add.cgi make internal server error 500
this ih my add.cgi:
#!/usr/bin/perl
# ==================================================================
# Links SQL - enhanced directory management system
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# CVS Info : 087,069,084,089,084
# Revision : $Id: add.cgi,v 1.40 2001/05/24 01:22:27 alex Exp $
#
# Copyright (c) 2001 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

use strict;
use lib '/home/cercaz/cercaziende.it/cgi-bin/admin';
use Links qw/$DB $IN $USER $CFG/;
use Links::SiteHTML;
Links::reset_env( { load_user => 1 } ) if ($Links::PERSIST);

local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
# -------------------------------------------------------------------
# Display either an add form or process an add request.
#
if ($CFG->{user_required} and ! $USER) {
print $IN->redirect( Links::redirect_login_url ('add') );
return;
}

# We are processing an add request.
if ($IN->param('add')) {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'user_add_link', \&add_link, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('add_error', $results);
}
else {
print $IN->header();
print Links::SiteHTML::display ('add_success', $results);
}
}

# We are displaying an add form.
else {
my ($name, $category);
my $id = $IN->param('ID');

# If we don't have an id, and can't generate a list, let's send the user a message.
if (! $id and ! $CFG->{db_gen_category_list}) {
print $IN->header();
print Links::SiteHTML::display('error', { error => Links::language('ADD_SELCAT')});
return;
}
else {
# Otherwise display the add form.
my $category = _category_list();
if ($USER) {
$IN->param('Contact_Name') or ($IN->param('Contact_Name', $USER->{Name} || $USER->{Username}));
$IN->param('Contact_Email') or ($IN->param('Contact_Email', $USER->{Email}));
}
print $IN->header();
if (! $category) {
print Links::SiteHTML::display('error', { error => Links::language('ADD_INVALIDCAT', $IN->param('ID')) });
}
else {
print Links::SiteHTML::display('add', { Category => $category });
}
}
}
}

sub add_link {
# --------------------------------------------------------
# Add the link to the database.
#

# Get the category box for any errors.
my $category = _category_list();

# Check the referer.
if (@{$CFG->{db_referers}}) {
my $found = 0;
if ($ENV{'HTTP_REFERER'}) {
foreach (@{$CFG->{db_referers}}) { $ENV{'HTTP_REFERER'} =~ /\Q$_\E/i and $found++ and last; }
}
if (! $found) {
$category = _category_list();
return { error => Links::language('ADD_BADREFER', $ENV{'HTTP_REFERER'}), Category => $category };
}
}

# Get our form data.
my $input = $IN->get_hash;

# This will set system fields like Validated to their proper values.
foreach my $key (keys %{$CFG->{add_system_fields}}) {
$input->{$key} = $CFG->{add_system_fields}->{$key};
}

# Setup the language for GT::SQL.
local $GT::SQL::ERRORS->{ILLEGALVAL} = Links::language('ADD_ILLEGALVAL');
local $GT::SQL::ERRORS->{UNIQUE} = Links::language('ADD_UNIQUE');
local $GT::SQL::ERRORS->{NOT_NULL} = Links::language('ADD_NOTNULL');
local $Links::Link::ERRORS->{NOCATEGORY} = Links::language('ADD_NOCATEGORY');
$Links::Link::ERRORS ||= {}; # silence -w

# Validate the form input..
my $db = $DB->table ('Links');
my $cdb = $DB->table ('Category');
my $cat_links = $DB->table ('CatLinks');
my $name = $input->{'Contact_Name'} || $input->{'Contact Name'} || ($USER ? $USER->{Name} : '');
my $email = $input->{'Contact_Email'} || $input->{'Contact Email'} || ($USER ? $USER->{Email} : '');

# Set the LinkOwner.
$input->{LinkOwner} = $USER ? $USER->{Username} : 'admin';

# Set date variable to today's date.
Links::init_date();
my $today = GT::Date::date_get();
$input->{Add_Date} = $today;
$input->{Mod_Date} = $today;

# Backward compatibility..
$input->{Contact_Name} = $name;
$input->{Contact_Email} = $email;

# Auto validate this link:
$input->{isValidated} = 'No';
if ($CFG->{build_auto_validate}) {
if ((($CFG->{build_auto_validate} == 1) and $USER) or ($CFG->{build_auto_validate} == 2)) {
$input->{isValidated} = 'Yes';
}
}

# Check the category.
my @cids = $IN->param('CatLinks.CategoryID');
my @name;
if (@cids) {
foreach my $cid (@cids) {
next if (! $cid);
my $sth = $cdb->select ( { ID => $cid }, ['Full_Name'] );
$sth->rows or return { error => Links::language('ADD_INVALIDCAT', $cid), Category => $category };
push @name, $sth->fetchrow;
}
if (@name) {
$input->{'CatLinks.CategoryID'} = \@cids;
}
}

# Add the record.
my $id = $db->add ( $input );
$input->{ID} = $id;
if (! $id) {
my $error = "<ul><li>" . join ("<li>", $db->error) . "</ul>";
return { error => "<ul>$error</ul>", Category => $category };
}

# Add some special tags for formatting.
$input->{'Category'} = join "\n", @name;
$input->{Host} = $ENV{REMOTE_HOST} ? "$ENV{REMOTE_HOST} ($ENV{REMOTE_ADDR})" : $ENV{REMOTE_ADDR} ? $ENV{REMOTE_ADDR} : 'none';
$input->{Referer} = $ENV{HTTP_REFERER} ? $ENV{HTTP_REFERER} : 'none';

# Mail the email.
if ($CFG->{admin_email_add}) {
my $to = $CFG->{db_admin_email};
my $from = $input->{'Contact_Email'};
my $subject = "Addition to Database: $input->{'Title'}\n";
my $cfg = Links::Config::load_vars();
my $msg = GT::Template->parse ( 'email-val.txt', { %$input, %$cfg }, { compress => 0, root => $CFG->{admin_root_path} . '/templates/admin' } );

require GT::Mail;
$GT::Mail::error ||= ''; # Silence -w
GT::Mail->send (
smtp => $CFG->{db_smtp_server},
sendmail => $CFG->{db_mail_path},
from => $from,
subject => $subject,
to => $to,
msg => $msg,
debug => $Links::DEBUG
) or die "Unable to send mail: $GT::Mail::error";
}

# Send the visitor to the success page.
return $input;
}

sub _category_list {
# -------------------------------------------------------------------
# Return a list of all the categories.
#
my $category;
if ($CFG->{db_gen_category_list}) {
my $db = $DB->table('Links');
my $html = $DB->html($db, $IN);
my @ids = $IN->param('CatLinks.CategoryID') || $IN->param('ID');
$category = $html->get_all_categories(\@ids, 'CatLinks.CategoryID', 1);
}
else {
my $db = $DB->table('Category');
my $id = $IN->param('CatLinks.CategoryID') || $IN->param('ID');
my $sth = $db->select ( { ID => $id }, ['Full_Name'] );
my ($name) = $sth->fetchrow_array();
if ($name) {
$category = "$name <input type=hidden name='CatLinks.CategoryID' value='$id'>";
}
else {
return;
}
}
return $category;
}

-------------------------------------------
Thanks in advance
bye from Italy
Fabio

Subject Author Views Date
Thread add.cgi error fabio 3993 Jun 29, 2001, 9:29 AM
Thread Re: add.cgi error
account deleted 3820 Jun 29, 2001, 2:30 PM
Thread Re: add.cgi error
fabio 3814 Jun 29, 2001, 2:37 PM
Thread Re: add.cgi error
account deleted 3812 Jun 30, 2001, 12:46 AM
Thread Re: add.cgi error
fabio 3820 Jun 30, 2001, 6:56 AM
Thread Re: add.cgi error
account deleted 3804 Jun 30, 2001, 10:50 AM
Thread Re: add.cgi error
fabio 3799 Jun 30, 2001, 12:07 PM
Thread Re: add.cgi error
account deleted 3818 Jun 30, 2001, 4:45 PM
Thread Re: add.cgi error
fabio 3787 Jun 30, 2001, 8:29 PM
Post Re: add.cgi error
account deleted 3782 Jul 1, 2001, 1:07 AM