Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Duplicity in the addition of Resources

Quote Reply
Duplicity in the addition of Resources
Hi
I would like to know if some parameter does not exist to prevent duplicity in the addition of Resources. It sees the example: http://www.meujovem.com/s/more4.html

Thanks YOU
meujovem
Brazil

Last edited by:

meujovem: Jan 6, 2003, 3:59 PM
Quote Reply
Re: [meujovem] Duplicity in the addition of Resources In reply to
http://mir.spaceports.com/~glennu/repeat.html


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Duplicity in the addition of Resources In reply to
Thanks You Leonard
I go to edit the files You to do orientations..
meujovem
Brazil
Quote Reply
Re: [meujovem] Duplicity in the addition of Resources In reply to
Help me

Leonard

I would like to know me in the archive add.cgi the edition of script I start in
Sub main {

But I am not understanding I ém that line finishes the edition it script vc could assist me?


#################################################
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;

# We are processing the form.
if (keys %in != 0) {
&logger;
}
# 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_add_form ($1) : &site_html_add_form ();
}
else {
&site_html_add_form ();
}
}
}


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

################################################

#!/usr/local/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.01
#
# (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 "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";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n[/url]";
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_add_form ($1) : &site_html_add_form ();
}
else {
&site_html_add_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);
if ($status eq "ok") {

# 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_links_name") or &cgierr("error in add_record. unable to open validate file: $db_links_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 {
&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'}

To validate, please go to:
$db_script_url

Atenciosamente,

meujovem.com.
|;

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

Last edited by:

meujovem: Jan 13, 2003, 3:38 AM
Quote Reply
Re: [meujovem] Duplicity in the addition of Resources In reply to
I'm not sure what problem you're having... Did you use the mod linked from the earlier post? If so, be sure you did these things:
  • In the data directory, create an empty file named addsite.txt
  • Replace the sub main code in your add.cgi with the sub main and sub logger code as shown in the mod.
  • Add the code as shown to site_html_templates.pl. Put it just before this: sub site_html_add_success {
  • Create a new template called add_ip_error.html in the template directory, base it on an existing template. (Copy rate_error.html, and change the <%error%> to "Sorry you have already submitted a site recently." or similar...)


If you did all that, and it's still not working, let us know...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Duplicity in the addition of Resources In reply to
Leonard

This item I Dont Know to do.

Replace the sub main code in your add.cgi with the sub main and sub logger code as shown in the mod.

where line starts and where line finishes the edition of this code:
add.cgi
meujovem
Brazil
Quote Reply
Re: [meujovem] Duplicity in the addition of Resources In reply to
Put the mod's sub main in place of the original sub main (in add.cgi), the sub logger goes under that, before sub process_form. In other words, delete the original sub main, and add the two new subs from the mod code in its' place.


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Duplicity in the addition of Resources In reply to
Leonard
Here are the archives:
add.cgi - chmod 755 (-rwxr-xr-x)
site_html_templates.pl - chmod ???
addsite.txt - chmod 666 (-rw-rw-rw-)
add_ip_error.html - chmod ???

I edited all as its orientation but it continues not functioning. What it could astar giving wrong?
It sees the archives below atach:
meujovem
Brazil

Last edited by:

meujovem: Jan 14, 2003, 6:57 AM
Quote Reply
Re: [meujovem] Duplicity in the addition of Resources In reply to
Your code looks OK, what is not working? Do you get an error message? Or is just not doing it's job, but not stopping Links from working?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Duplicity in the addition of Resources In reply to
Leonard

It does not appear no message of error. But script is accepting one more than link to validate, or either the problem of duplicate of link continues. In the truth I would like that the user did not have permission to add link more than a time the same, but this continues happening. It looks at test here that I myself I made the afternoon today.

W3Schools

http://www.meujovem.com/New/14-Jan-2003.html


Another thing that I perceived is that in the archive addsite.txt no register was carried through. Therefore later that I made test I verified this archive in the server.
meujovem
Brazil