Gossamer Forum
Home : Products : Links 2.0 : Customization :

Weird Problem with Delete.cgi

Quote Reply
Weird Problem with Delete.cgi
Bmxer,

Hi there. For some reason, my delete.cgi script does not work. I keep getting the following errors if a LINK is found in the links.db file:

Code:
* Title (Can not be left blank)
* URL (Can not be left blank)
* Category (Can not be left blank)
* Contact Email (Can not be left blank)
* ReceiveMail (Can not be left blank)

I know that this is a problem with the sub validate_record routine. I cannot figure out what the problem could be.

The only changes I've made to the delete.cgi script is changed the fields from Link ID, URL, and Contact Name to the following fields:

1) ID
2) Contact Name
3) Password

When I don't fill in any information, I get the typical error messages in the delete.cgi script when the link is not found or if the fields are not filled out.

You can see the script in action at:

vlib.anthrotech.com/bin/delete.cgi

Any thoughts?

Thank you.

Regards,

Eliot Lee

[This message has been edited by AnthroRules (edited April 03, 2000).]
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
How long has it done this? Ever since you installed the mod? Please post your sub validate_records

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell


Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Well, when I originally installed it back in January, the script was running fine. When I tested it last night, I released that it no longer works.

Here is my sub validate_record routine (taken from the db_utils.pl file):

Code:
sub validate_record {
# --------------------------------------------------------
# Verifies that the information passed through the form and stored
# in %in matches a valid record. It checks first to see that if
# we are adding, that a duplicate ID key does not exist. It then
# checks to see that fields specified as not null are indeed not null,
# finally it checks against the reg expression given in the database
# definition.
#
my ($col, @input_err, $errstr, $err, $line, @lines, @data);
my (%rec) = @_;

if ($rec{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
($data[$db_key_pos] eq $rec{$db_key}) and return "duplicate key error";
}
close DB;
}
foreach $col (@db_cols) {
if ($rec{$col} =~ /^\s*$/) { # entry is null or only whitespace
($db_not_null{$col}) and # entry is not allowed to be null.
push(@input_err, "$col (Can not be left blank)"); # so let's add it as an error
}
else { # else entry is not null.
($db_valid_types{$col} && !($rec{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)"); # but has failed validation.
(length($rec{$col}) > $db_lengths{$col}) and
push (@input_err, "$col (Too long. Max length: $db_lengths{$col})");
if ($db_sort{$col} eq "date") {
push (@input_err, "$col (Invalid date format)") unless &date_to_unix($rec{$col});
}
}
}
if ($#input_err+1 > 0) { # since there are errors, let's build
foreach $err (@input_err) { # a string listing the errors
$errstr .= "<li>$err"; # and return it.
}
return "<ul>$errstr</ul>";
}
else {
return "ok"; # no errors, return ok.
}
}

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
I have sent a mail to Bmxer two weeks ago inquiring about the same problem, unfortunately he hasn't replied yet...

Thomas
http://www.japanreference.com/
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Eliot,

could you possibly give me the code ?
I'm not really shure whether I can solve this problem Wink but I really would like to try !
You could mail the delete.cgi or post an URL.
cya,

nikolai
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
DigitalFusion,

I appreciate your enthusiasm and willingness to help. However, I would prefer to wait to hear from Bmxer before pursuing other options.

Thank you.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Heh Wink

ok...
just thought that it would be an interesting mod.
would be really nice if you can provide me with more information about it.
Like: where can i get it Smile
cya,

nikolai
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
This Mod, like most Mod, is located in the Resource Center!

Wink

You can download the codes at the following web page:


Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Uaaahhh,

sorry Eliot - didn't know.
But thanks for giving the link Smile
cya,

nikolai
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
I don't get the problem b/c the problem is the links.def and the fact that some fields are required and not in the page, but i set a field not on my page as required then entered everything in and it still got a success. So all i can do is post my delete.cgi and see if thats it.
sorry, i can't post it on hypermart b/c they execute anything w/ a shebang line as perl, even if its .txt
Code:
#!/usr/local/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: delete.cgi
# Description: Deletes a record marked unvalidated to the database and
# optionally emails someone.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Mod by: Lavon Russell
# Email: webmaster@lh.yi.org
# Web: http://www.gossamer-threads.com/
# Version: 2.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This mod is freeware, but Links isn't! Created under Gossamer Threads Inc. Links 2.0
# =====================================================================
#
# 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 "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/links2.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
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/(.+?)/?$,;
$is_valid{$1} ? &site_html_delete_form ($1) : &site_html_delete_form ();
}
else {
&site_html_delete_form ();
}
}
}

sub process_form {
# --------------------------------------------------------
my ($key, $status, @values, $found);
local (%original);

# Make sure we have an ID, URL, and Email address for the resource to delete.
# If any are missing, return an error message to the submitter.
((!$in{'URL'}) or
(!$in{'ID'}) or
(!$in{'Contact Email'})) and &site_html_delete_failure (qq|<ul>
<li>Missing the ID, URL, or Contact Email address of the resource to delete
</ul>|) and return;

# Let's check to make sure the link we want to update is actually in the
# database and that the link ID and Contact Email address match what is
# specified in the submission form.
open (DB, "<$db_file_name") or
&cgierr("Error in validate_records. Unable to open $db_file_name. Reason: $!");
$found = 0;
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
# Check for matching record ID, URL, and Contact Email address.
# If everything matches, get the record, stop searching.
if (($data[0] eq $in{'ID'}) and
($data[$db_url] eq $in{'URL'}) and
($data[$db_contact_email] eq $in{'Contact Email'})) {
$in{$db_key} = $data[0];
$found = 1;
%original = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
# If no matching record found, display error message to user
!$found and &site_html_delete_failure (qq|<ol>
<li>The requested Link URL was not found in the database.
<li>The requested Link URL does not match the database URL for the specified Link ID.
<li>The requested Link Contact Email address does not match the database Contact Email
address for the specified Link ID.
<li>The Link ID doesn't exist.
</ol>|) and return;

# Since we have a valid link, let's make sure the system fields are set to their
# proper values. We will simply copy over the original field values. This is to stop
# people from trying to modify system fields like number of hits, etc.
foreach $key (keys %add_system_fields) {
$in{$key} = $original{$key};
}


# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;

# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {

# First make sure the link isn't already in there.
open (DEL, "<$db_delete_name") or &cgierr ("error opening modified database: $db_delete_name. Reason: $!");
while (<DEL> ) {
chomp;
@values = split /\|/;
if ($values[0] eq $in{$db_key}) {
close DEL;
&site_html_delete_failure("A request to delete this record has already been received. Please try again later.");
return;
}
}
close DEL;
# Update the counter.
open (ID, ">$db_links_id_last_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_links_id_last_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 delete input to a "deletion database" where it is stored until
# the admin decides to delete it from the real database.
open (DEL, ">>$db_delete_name") or &cgierr("error in delete_record. unable to open validate file: $db_delete_name. Reason: $!");
flock(DEL, 2) unless (!$db_use_flock);
print DEL &join_encode(%in);
close DEL; # 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_delete_success;
}
else {
&site_html_delete_failure($status);
}

sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be deleted. 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 = "Deletion to Database: ID: $in{'ID'} on $in{$db_cols[$db_modified]}\n";
my $msg = qq|
The following link is awaiting Deletion:
ID: $in{'ID'}
URL: $in{'URL'}
Contact Email: $in{'Contact Email'}
Reason: $in{'Reason'}

Remote Host: $ENV{'REMOTE_HOST'}
Referer: $ENV{'HTTP_REFERER'}

To Delete, please go to:
$db_script_url

Sincerely,

Links Manager.
|;

# 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;
}
}

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell


Quote Reply
Re: Weird Problem with Delete.cgi In reply to
I did refer to your delete.cgi script.

The problem is that I do not want to un-require the fields in my links.def file. That would pose a problem with adding sites. (I suppose the other solution would be to copy the links.def file and name it something like delete.def file and then un-require all the fields. But that will be a pain in terms of managing the files in the long run.)

And again, the only changes I made to your script was changed URL and Contact Email to Contact Name and Password. I don't think this would cause a problem...but it seems to be since that is the only difference between your script and mine.

Hmm...Oh well...I guess I will take this script off my site until I have more time to look at it and fix the problem.

Thanks for looking into it.

Wink

Regards,


Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Hey Eliot,

I posted the same problem in another thread. Try the following:

Insert these files in delete.html template:

<input type="Hidden" name="Title" value="<%Title%>">
<input type="Hidden" name="URL" value="<%URL%>">
<input type="Hidden" name="Category" value="<%Category%>">
<input type="Hidden" name="Contact Email" value="<%Contact Email%>">
<input type="Hidden" name="ReceiveMail" value="<%ReceiveMail%>">

Well, I don't think all error messages will disappear but perhaps a few.

Phil.

Quote Reply
Re: Weird Problem with Delete.cgi In reply to
That is NOT the problem...Thanks for the suggestion...That is the second thing I tried....

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Ok, when the error page comes up, are the text fields filled in, or empty? If not do they say what was entered or Unknown?

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell


Quote Reply
Re: Weird Problem with Delete.cgi In reply to
 
Quote:
are the text fields filled in, or empty?

The fields are filled-in with values that the user submitted with the above posted error message.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
ok, then its nothing wrong with the scripts. Its just the variables that its using to check the db. I'll look more into it.

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell


Quote Reply
Re: Weird Problem with Delete.cgi In reply to
 
Quote:
ok, then its nothing wrong with the scripts.

I beg to differ...simply changing the fields to check before allowing the record to be added to the delete.db SHOULD NOT cause the problems I am experiencing.

Wink

But, I appreciate your assistance. Thanks.

Regards.

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
I didn't say the fields, I said the variables. Meaning it may be sub validate_records or links.def and the way delete.cgi works w/ it. This is why i said "I'll look into it"

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell


Quote Reply
Re: Weird Problem with Delete.cgi In reply to
 
Quote:
are the text fields filled in, or empty?

AND

Quote:
I didn't say the fields, I said the variables

Uh...You said fields!

Wink

Quote:
...Meaning it may be sub validate_records...

That was my very first thought.

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
  
Quote:
ok, then its nothing wrong with the scripts. Its just the variables that its using to check the db. I'll look more into it.
Uh...I said variables!
be more specific to which post your talking about.
Quote:
That was my very first thought.
well then go ahead and fix it. Its nothing wrong with "my" code.

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell




[This message has been edited by Bmxer (edited April 09, 2000).]
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Please refer me to the EXACT Reply (by date) where you stated variables. I don't see it...All you asked about was text fields....which is NOT variables.

It is NOT just me who is experiencing problems with your Mod...Guess you missed the following Thread.

http://www.gossamer-threads.com/...um3/HTML/005693.html

So, there does seem to be a bug with your codes/Mod.

Wink

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
six or seven posts up
posted April 07, 2000 03:39 PM PST
"variables".
I didn't miss that thread. And more people than you two installed my mod, and i only have to complaints. It is not only with my mod but with links.def and sub validate_records also.

------------------
LookHard Search
lookhard.hypermart.net
Lavon Russell


Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Sorry to interfere, but is there anything that can be done against that bug? Btw, I for my part have never complained, just pointed out a little flaw... Wink
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Sorry for raising the topic once again, but has finally someone come up with a solution for that bug ??
Quote Reply
Re: Weird Problem with Delete.cgi In reply to
Nope. I have entirely "deleted" this feature from my Directory.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.