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

Quote Reply
Re: add.cgi error In reply to
Have you had a look at the error log / ran it thru telnet?

Quote Reply
Re: add.cgi error In reply to
I can't see log server
Help me
Thanks in advance
Bye fFrom Italy
Fabio

Quote Reply
Re: add.cgi error In reply to
I tested your script (cercaziende.it) and it all works fine now.

(But all the results pages gets is Unkown Tag: citta, so you need to edit your add success template, but you probably know that Wink. I think that that spelling error is from the wrong site, as it's a links 2 flat-file error. If it is the wrong site, then try reuploading a fresh add.cgi, as ascii, with the correct path to the admin dir, and chmod it (all very blatant) and there's no reason why it shouldn't work, if your other user side scripts work. )
Quote Reply
Re: add.cgi error In reply to
It's wrong U have seen on www.cercaziende.it (it's OK)
But the really link is on www2.cercaziende.it
Help me
Bye from Italy
Fabio

Quote Reply
Re: add.cgi error In reply to
I think you've done nothing to your add.cgi. It may just be a simple permissions/ ascii / path problem. It's nothing serious as all your other scripts work. Try uploading a fresh copy and it'll probably work, hopefully


Quote Reply
Re: add.cgi error In reply to
I've uploaded a fresh copy permissions 755/ ascii but it's the same.
How I can Do?
Help Me
Thanks in advance
Bye From Italy
Fabio

Quote Reply
Re: add.cgi error In reply to
it's probably this line:
use lib '/home/cercaz/cercaziende.it/cgi-bin/admin';

Make sure it's right.

Quote Reply
Re: add.cgi error In reply to
I'm sorry but it's right !!
How Help me?
Thanks in advance
Bye From Italy
Fabio

Quote Reply
Re: add.cgi error In reply to
If you have been through all the right steps and you don't have an error log or telnet, then there's nothing else I can really say. Perhaps I'm missing something, beats me though.