Gossamer Forum
Home : Products : Links 2.0 : Customization :

Picking Either URL or Upload with the Phoenix Upload Mod

Quote Reply
Picking Either URL or Upload with the Phoenix Upload Mod
Hi, I am using the Phoenix Upload mod located at http://www.asan.com/users/phoenix/upload. I want to make it so that you can either upload a file or send a url, like the resource center here at Gossamer Threads.
The only problem is that I get an error saying
Code:
# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 0, '', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes']
);
Here is my added part to links.cfg
Code:
#
# Uploaded File Settings
# --------------------------------------------------------
# PATH and URL to directory where Attached Files will be stored.
# (make sure you create this directory on your server) No Trailing slash.
$build_attach_path = "$build_root_path/Attach";
$build_attach_url = "$build_root_url/Attach";

# Name of the field in your links.db where the URL of the uploaded
# file will be stored
$attach_file_field = "URL";

# Do you want this to be a required field? 1=Yes 0=No
$attach_field_required = 0;

# Maximum size for file attachments (in KB)
$attach_file_size = "2000";

# List of allowable file extensions. If the file does not have one of the extensions
# listed, it will not be saved to the server. The format for the setting is
# \.extension$
# If you want to allow more than one extension, separate the options by
# a | character. On a UNIX server, these are case sensitive.
$attach_ext = '\.zip$|\.ZIP$';
And here is my modified add.cgi
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 "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";
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) = &get_file_and_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") {

if ($attach_field_required) {
if (!$in{$attach_file_field}) {
if (!$in{'FILE_CONTENT'}) {
&site_html_add_failure ("You must either attach a file or enter data in the $attach_file_field field.");
return;
}
}
}

# Save any attachments
if ($in{'FILE_CONTENT'}) {
if ($in{$attach_file_field}) {
&site_html_add_failure("Please do not enter both a URL and a file. If you choose to upload a file, a URL will be automatically attached.");
return;
}
if (length($in{'FILE_CONTENT'}) > ($attach_file_size * 1000)) {
&site_html_add_failure("Maximum attachment size is $attach_file_size KB. Please reduce the size of your file or email it as an attachment to $db_admin_email.");
return;
}
my $filename = $in{'FILE_NAME'};
($filename =~ m,[/\\]([^/\\]+)$,) and ($filename = $1);
if ($filename !~ /^[\w\d\.\/\\]+$/) {
&site_html_add_failure ("Invalid characters in filename '$filename'. Please use letters, numbers and dashes only.");
return;
}
if ($filename =~ /\.\./) {
&site_html_add_failure ("Invalid characters in filename '$filename'. Please use letters, numbers and dashes only.");
return;
}
if ($filename !~ /$attach_ext/) {
$attach_ext =~ s/\\//g;
$attach_ext =~ s/\$//g;
@ext = split (/\Q|\E/o,$attach_ext);
$attach_ext = join(" or ",@ext);
&site_html_add_failure ("Only files with the following extension(s) are allowed: $attach_ext");
return;
}
open (FILE, ">$build_attach_path/$in{$db_key}-$filename") or &cgierr ("Can't save attach: $build_attach_path/$in{$db_key}-$filename. Reason: $!");
print FILE $in{'FILE_CONTENT'};
close FILE;
$in{$attach_file_field} = "$build_attach_url/$in{$db_key}-$filename";
}

# 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 {
&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

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

sub get_file_and_form {
# --------------------------------------------------------
# Code taken from WWWThreads 3.2 based off of work by Steve Hsueh
# and Rick Baker.
#
my ($i, $loc, $key, $val, $input, %ATTACH, $f,$header, $header_body, $len, $buf);

if( $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/ ) {
if ($ENV{'REQUEST_METHOD'} eq "GET") { $input = $ENV{'QUERY_STRING'}; }
elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
$len = 0; $input = '';
while( $len != $ENV{'CONTENT_LENGTH'} ) {
$buf = '';
$len += sysread(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
$input .= $buf;
}
}
my $boundary = '--'.$1;
my @list = split(/$boundary/, $input);

# For some reason there are always 2 extra, that are empty
my $size = @list -2 ;

for $x (1 .. $size) {
$header_body = $list[$x];
$header_body =~ /\r\n\r\n|\n\n/;
# Here we split the header and body
$header = $`;
my $body = $';
$body =~ s/\r\n$//;
# Now we try to get the file name
my $name = $header;
my $blah;
$name =~ /name=\"(.+)"/;
($name,$blah) = split(/"/,$1);
$ATTACH{'NAME'} = $name;
$ATTACH{'FILE_CONTENT'} = $body;
# If the form name is not attach, then we need to parse this like
# regular form data
if ($name ne "attach") {
$body =~ tr/+/ /;
$body =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$body =~ s/<!--(.|\n)*-->//g;
$body =~ s/\n/<br>/g;
$body =~ s/\r//g;
$ATTACH{$name} = $body;
# Otherwise it is an attachment and we need to finish it up
}
else {

$header =~ /filename=\"(.+)\"/;
$ATTACH{'FILE_NAME'} = $1;
$ATTACH{'FILE_NAME'} =~ s/\"//g;
$ATTACH{'FILE_NAME'} =~ s/\s//g;

for $i ($x .. $list[$i]) {
$list[$i] =~ s/^.+name=$//;
$list[$i] =~ /\"(\w+)\"/;
$ATTACH{$1} = $';
}
}
}
return %ATTACH;
}
else {
return &parse_form();
}
}

Please Help..


------------------
- YellowKard -



[This message has been edited by YellowKard (edited May 07, 2000).]
Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
My last email to Phoenix received no reply. This is just a small error but is keeping me from be able to use my project. Does links use site_html.pl at all if you are using templates?

------------------
- YellowKard -

Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
No...If you are using Templates, then you need to edit the sub-routines in the site_html_templates.pl file.

site_html.pl = NO TEMPLATES
site_html_templates.pl = TEMPLATES

Wink

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.


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
I would recommend contacting Phoenix via email to ask him about the Modification. I am not too familar with the Mod, and I don't know the logic that Phoenix is using and I do not have the time to de-bug the script for you.

Sorry.

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.


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
Yippee, I finally got everything working (took me around 24 hours total on this one small problem) anyways I was wondering how I could make it so that when I reject a link (file) it will delete it when rejected, instead of leaving the uploaded file on the server.

------------------
- YellowKard -

Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
I don't have a clue...I would have to look over the codes.

As a starting point, you could take a look at the discussions in the DBMAN forum about deleting associated images of records when they are deleted. While there are two totally different File Upload Mods for DBMAN, the logic behind deleting the images with associated records is the same.

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.


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
You're welcome.

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.


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
Ok thanks, do you know how to disable the notify (lets webmaster know somthing needs to be validated) feature when someone adds a resource. I searced for this for a while but im thinking just commenting that part out of add.cgi should do it.

------------------
- YellowKard -

Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
What you need to do is the following:

1) Add the following variable in your links.cfg file:

Code:
$db_validate_email = 0;

2) Then replace the following codes in your add.cgi file:

Code:
# Send the admin an email message notifying of new addition.
&send_email

with the following codes:

Code:
# Send the admin an email message notifying of new addition.
if ($db_validate_email) {
&send_email
}

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.


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
Thanks Eliot, it works great.

------------------
- YellowKard -

Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
Please STOP asking multiple questions in the same Topic...it is hard to follow!!!

Quote:
And, do you know where I could find a mod that blocks people from voting more than once for the same thing?

This has been discussed before in this forum. Search for Block voting.

About the verification error...I don't know what to tell you.

Best of luck!

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.


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
I just found out I have Cron and LWP isntalled on my server.

When I try using the link varification it says in the output:

Code:
Links Manager: Verifying Links
Verifying Links
Link checking started at: Sun May 14 08:47:17 2000
--------------------------------------------------------
Unable to load Parallel User Checker. System Error:
--
Can't locate HTTP/Request.pm in @INC (@INC contains: /usr/home/powweb6/www/vhosts/fullworm/cgi-bin/files-n-links/admin /usr/local/lib/perl5/5.00503/i386-freebsd /usr/local/lib/perl5/5.00503 /usr/local/lib/site_perl /usr/local/lib/site_perl .) at /usr/home/powweb6/www/vhosts/fullworm/cgi-bin/files-n-links/admin/Validator.pm line 23.
BEGIN failed--compilation aborted at /usr/home/powweb6/www/vhosts/fullworm/cgi-bin/files-n-links/admin/Validator.pm line 23.
--
Using IO::Socket method instead.

--------------------------------------------------------
Checked 39 - Success (200). Message: OK 200. URL: http://www.elitewormz.cjb.net
Checked 45 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/45-ProRules.zip
Checked 46 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/46-playboy.bmp
Checked 47 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/47-SchemeEd.zip
Checked 48 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/48-IWGRAVE3.bmp
Checked 40 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/40-matrixkungfu.zip
Checked 49 - Success (200). Message: OK 200. URL: http://worms.team17.com
Checked 41 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/41-EWFlag.bmp
Checked 42 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/42-plunger3.bmp
Checked 43 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/43-4Ts.bit
Checked 54 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/54-Acidsfunpractice.bit
Checked 55 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/55-TeamFortress.wsc
Checked 56 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/56-BnG.wsc
Checked 50 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/50-Flags.zip.zip
Checked 51 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/51-Fanfare.zip.zip
Checked 52 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/52-graves.zip.zip
Checked 53 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/53-KMsnewrace.bit
Checked 57 - Request Failed (404). Message: File Not found. URL: http://www.fullwormage.com/data/files-n-links/Uploads/57-EWFlagPack.zip

Took: 5 seconds to check 18 links.

Bad Link Summary
-----------------------------------------------
54 - http://www.fullwormage.com/data/files-n-links/Uploads/54-Acidsfunpractice.bit [modify|delete] : 404 - File Not found
43 - http://www.fullwormage.com/data/files-n-links/Uploads/43-4Ts.bit [modify|delete] : 404 - File Not found
52 - http://www.fullwormage.com/data/files-n-links/Uploads/52-graves.zip.zip [modify|delete] : 404 - File Not found
50 - http://www.fullwormage.com/data/files-n-links/Uploads/50-Flags.zip.zip [modify|delete] : 404 - File Not found
51 - http://www.fullwormage.com/data/files-n-links/Uploads/51-Fanfare.zip.zip [modify|delete] : 404 - File Not found
56 - http://www.fullwormage.com/data/files-n-links/Uploads/56-BnG.wsc [modify|delete] : 404 - File Not found
48 - http://www.fullwormage.com/data/files-n-links/Uploads/48-IWGRAVE3.bmp [modify|delete] : 404 - File Not found
57 - http://www.fullwormage.com/data/files-n-links/Uploads/57-EWFlagPack.zip [modify|delete] : 404 - File Not found
42 - http://www.fullwormage.com/data/files-n-links/Uploads/42-plunger3.bmp [modify|delete] : 404 - File Not found
55 - http://www.fullwormage.com/data/files-n-links/Uploads/55-TeamFortress.wsc [modify|delete] : 404 - File Not found
53 - http://www.fullwormage.com/data/files-n-links/Uploads/53-KMsnewrace.bit [modify|delete] : 404 - File Not found
45 - http://www.fullwormage.com/data/files-n-links/Uploads/45-ProRules.zip [modify|delete] : 404 - File Not found
41 - http://www.fullwormage.com/data/files-n-links/Uploads/41-EWFlag.bmp [modify|delete] : 404 - File Not found
40 - http://www.fullwormage.com/data/files-n-links/Uploads/40-matrixkungfu.zip [modify|delete] : 404 - File Not found
47 - http://www.fullwormage.com/data/files-n-links/Uploads/47-SchemeEd.zip [modify|delete] : 404 - File Not found

-----------------------------------------------

Good Links: 2
Bad Links : 16

Why is there that error? is it using LWP? Also every one of those urls are good links.

And, do you know where I could find a mod that blocks people from voting more than once for the same thing?

------------------
- YellowKard -




[This message has been edited by YellowKard (edited May 14, 2000).]
Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
I am having a verification problem...

When I varify links in the admin.cgi, It shows all links to files as bad links when in fact they're not, is there a way I can disable this?

------------------
- YellowKard -


Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
 
Code:
perl nph-verify.cgi > verify.log

The problem is either with your Validate.pm module or you are using too much CPU, which is not allowing you to get accurate results.

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.




[This message has been edited by AnthroRules (edited May 14, 2000).]
Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
Hi,

I have the same problem with the mod. While sending, it stores only a Word from the form as file.

I didn't understand what you have changed, please can you post that?

Thanks, Chris

Quote Reply
Re: Picking Either URL or Upload with the Phoenix Upload Mod In reply to
Hi!
would you PLEASE share your soultion with us, cause i have the same problem, and whole project is waitting for this error to fix

thanx in advance