Gossamer Forum
Home : General : Perl Programming :

Password Protection

Quote Reply
Password Protection
Hi to all. I'm using this script. A visitor can select a file to download but he must also type a requested password.
This password is send to the visitor by email.

This is my download.pl:

#!/usr/local/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: downloads.pl
# Description: Lets a visitor select a file to download
# 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 "c:/inetpub/wwwroot/cgi-bin/admin/download.conf";
require "c:/inetpub/wwwroot/cgi-bin/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;
}
# ========================================================================================================
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;}

if ($FORM{'source'} eq "Select One") {
print "Content-type:text/html\n\n";
print "You didn't choose from please select one...<p>\n";
}
if ($FORM{'pass'} eq $password) {
print "Content-type:text/html\n\n";
print "Correct password!<p>\n";
print "$send Password: $password - Formpass: $FORM{'pass'} - Source: $FORM{'source'} <p>\n"; #check strings
print "Location: $file\n\n"; #file automatically starts to download
exit;
}
else {
print "Content-type:text/html\n\n";
print "Invalid Password! Please hit back on on your browser and try again! $password";
}

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

This is my download.conf:

%file=( 'Download1' , 'http://195.66.30.215/pages/downloads/download1.zip',
'Download2' , 'http://195.66.30.215/pages/downloads/download2.zip',
'Download3' , 'http://195.66.30.215/pages/downloads/download3.zip' );

$password = "test";

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

and my download.html:


<form method="post" action="http://195.66.30.215/cgi-bin/download.pl">
<font size="2" face="Verdana,Arial,Helvetica" COLOR="#FF0000"><B>Please select the file to download:</b>
<INPUT type=hidden value="Select One"> <SELECT name="source"> <OPTION selected>Select
One<OPTION>Download1<OPTION>Download2<OPTION>Download3</OPTION></SELECT></p>

<font size="2" face="Verdana,Arial,Helvetica" COLOR="#FF0000"><B>Please type the requested password:</b>
<input type="password" name="pass" size="25"></p>
<input type="submit" value="Send"></br>
</form>

Thats All
Quote Reply
Re: Password Protection In reply to
Couple questions:

1) Do you have a User download database set-up?
2) If so, what fields do you have in this user download database?

Regards,

Eliot Lee
Quote Reply
Re: Password Protection In reply to
Thanks for responding and your help again. No I don't use a database. I want to keep it simple. See my download.conf for the password. I've modified my first posting...
Thanks

Quote Reply
Re: Password Protection In reply to
So, it is a generic password?

How do people get it?

Regards,

Eliot Lee
Quote Reply
Re: Password Protection In reply to
I send the password by email...

Quote Reply
Re: Password Protection In reply to
Well...what I would do is the following:

1) Put the following codes in its own sub:

Code:

sub process_form {
#-------------------------------------------------------
# Processes form and sends data

$send="";

foreach $item (keys(%file)){
if ($item eq $ARG{'source'}){
foreach $each (keys(%format)){
if ($ARG{'compress'} eq $each){
$send=$file{$item} . $format{$each};
}
}
foreach $each (keys(%dlurl)){
if ($ARG{'mode'} eq $each){
# Validate the form input..
my $url1 = "$dlurl{$each}$send\n";
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Headers;
$url = ($url1);
my ($ua,$req,$res);
$ua = LWP::UserAgent->new();
$ua->timeout(30);
$ua->agent("UrlScope");
$req = new HTTP::Request 'GET' => $url;
$res = $ua->request($req);
$mes = $ua->request($req);
$code = $res->code;
$message = $res->message;
if (($status ne "ok") && $res->is_error) {
&do_log;
&site_html_downloads_failure (qq|<ul><li> URL: $url - $code $message $status</ul>|);
exit;
}
print "Location: $dlurl{$each}$send\n\n";
}
}
if ($usecount == 1){
&countdl;
&do_log;
}
}
}
}


2) Then add a new sub called sub main before this:

Code:

sub main
#---------------------------------------------
# Main Sub

&form_data;

if ($in{'password'} eq $password) {
&process form;
}
else {
&site_html_download_failure (qq|<ul><li>You did not enter the correct password: $password. Please try accessing the form again. If you continue to have problems, contact the Site Administrator at <a href="mailto:$db_admin_email">$db_admin_email</a>|;)
}
}


3) Then I would change the password hash that you have in the .conf file to a variable, like the following:

Code:

$password = "pass_word";


4) I would create a login page with the following codes:

Code:

<form action="http://www.yourdomain.com/cgi-bin/download.pl" method="POST">
Enter Password: <input type="text" name="password" size="20">
</form>


That should do it.

Regards,

Eliot Lee
Quote Reply
Re: Password Protection In reply to
Thanks Eliot for your help. I've modified my first posting with the options you told me.
When I use the script with the correct password and without a password I get the error message:
"You did not enter the correct password"

I seems like the script don't reconize the password???.
I've tried it with $password=test; $password='test'; $password="test"; but nothing works.
When I remove the password field the script works correctly.
Could this be the problem?
&form_data;
if ($in{'password'} eq $password) {

You said:
") I would create a login page with the following codes:" but I want it in the same html page where the download options are....

Quote Reply
Re: Password Protection In reply to
nevermind
Quote Reply
Re: Password Protection In reply to
"nevermind" = new password maybe???

Eliot please your help again....



Quote Reply
Re: Password Protection In reply to
Try using $password = "test";.

And about having the login script on the same download page...Just simply email out the following URL:

Code:

http://www.yourdomain.com/cgi-bin/download.pl?password=test


Then your downloaders will be able to by-pass the login screen and go directly to the download page.

Wink

Regards,

Regards,

Eliot Lee
Quote Reply
Re: Password Protection In reply to
haha, this cat is a comedian

Quote Reply
Re: Password Protection In reply to
Hi Eliot and all the others... I've modified my first posting again with the new codes because it didn't work as I wanted. So forget the reply's for it. (sorry)...
Now, can someone help me the new codes to read my download.conf!!!

When I choose to download "download1" from download.html it will verify "download1" = http://195.etc/download1.zip in the download.conf and automatically starts downloading the file download1.zip

Thanks all for your help and your suggestions....

Quote Reply
Re: Password Protection In reply to
Isn't that what you want??? I am confused.

Regards,

Eliot Lee
Quote Reply
Re: Password Protection In reply to
You shouldn't be, designing is making changes... but can you help me again with this codes....

Lot of thanks again...

Quote Reply
Re: Password Protection In reply to
In Reply To:
You shouldn't be, designing is making changes... but can you help me again with this codes....
Welp...guess what...I am and if you choose not to be specific about what you need help with, then all I can say is Good luck!. Mad

Regards,

Eliot Lee
Quote Reply
Re: Password Protection In reply to
Sorry Eliot, I will try to be more specific but this is what I want:
New codes for download.pl to read my download.conf!!!

When I choose to download "download1" from download.html
then the script must read my download.conf and verify that "download1" = http://195.etc/download1.zip and automatically start downloading the file download1.zip
Thats all.

Thanks all for your help
Quote Reply
Re: Password Protection In reply to
Hi Eliot can or will you still help me with the new codes for download.pl to read my download.conf!!! (modified my first posting with new codes)...

The script download has to work as follows: When I choose to download "download1" from download.html
then the script must read my download.conf and verify that "download1" = http://195.etc/download1.zip and automatically start downloading the file download1.zip
Thats all.

Thanks all...

Quote Reply
Re: Password Protection In reply to
Eliot, your help again please!!!!!!!!!!!!
I know i'm a pain i-t-a- but forgive me...
See my two last postings....
Greetings....