Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Perl script modification needed for multiple users to the site

Posted on 2004-11-28
6
Medium Priority
?
182 Views
Last Modified: 2010-03-05
Afternoon all,


I am in need of modification to the following script and page so that I can have multiple users with username and passwords all being directed to different home page on my site.

The script I am using has this code :



#!c:/Perl/bin/perl.exe
require ("cgi-lib.pl");
&ReadParse(*form);
$user = $form{'user'};
$pass = $form{'pass'};

####################################################################
#Start here to edit the 5 variables that may need to be changed    #
####################################################################

# Edit Variable #1 of 5
#Set #!/usr/bin/perl at the top line 1 to point to your Perl interpretor
#Usually #!/usr/bin/perl or #!/usr/local/bin/perl

# Edit Variable #2 of 5
#Replace "california" on next line with your own username  
$myusername = "s";

# Edit Variable #3 of 5
#Replace "raisins" on next line with your own password  
$mypassword = "m";

# Edit Variable #4 of 5
#Replace "granted.txt" on next line with your own file to be displayed when user/pass is correct
$protectedfile = "granted.txt";

# Edit Variable #5 of 5
#Replace "denied.txt" on next line with your own file to be displayed when user/pass is incorrect      
$accessdeniedfile = "denied.txt";

#That's it for this file Install Step #2. Now go to Install Step #3 on the readme.txt file.




















####################################################################
#End of variable selection DO NOT edit below this line             #
####################################################################
print "Content-type: text/html\n\n";
if ($mypassword eq $pass && $myusername eq $user)
{
open (granted, "$protectedfile");
@granted=<granted>;
print "@granted";
close (granted);
}
else
{
open (denied, "$accessdeniedfile");
@denied=<denied>;
print "@denied";
close (denied);
}
####################################################################
#This script created by Steve Baker (www.supernovacomputers.com) July 07, 2000#
####################################################################



Which is directed to this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>
Access Granted
</title>
<meta http-equiv="refresh" CONTENT="5;URL=http://123.456.678.90/S/new/index.htm">
</head>
<body>
Connecting....
<br>
</body>
</html>


Which is then directed to the private home page of my site.



What I want to do though, is to have another site linked from that password protected main page going to other 'home' pages.

Please ask for clarification if you don't understand.

Summary:


Login >>>> Connecting page >>>> Home Page


I want to add different login users so they go to different static Home Page files. Please advise how to change either the Login script page or the Connecting page HTML.



Many thanks.




Leon
0
Comment
Question by:Leon5178
3 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 12691348
So you want each user to go to their own individual home page?
Do you have to do it via a redirect?  Could you not just use web server user authentication for each user?

BTW, the script above is very poorly written.  
0
 

Author Comment

by:Leon5178
ID: 12694150
Tintin,


To be honest with you, I am not a Perl developer so I do not know how good that script is. It just seems to do the job and I am looking to create parallel sites for various members of my family.

I could use web server authentication but I am using the Apache Web server that comes with Oracle Application Server so I have little scope for flexibility.

I don't have to do a redirect but this was a free script that seemed to do the job so I kept it. I am open to suggestions as long as it doesn't take too much effort to implement.

Let me know what your thoughts are on this.



Leon



0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 12898430
A trivial generalization of the above script could be:


use strict;
use warnings;
use CGI;

my $q=new CGI;
my %form = $q->Vars;
my $user = $form{'user'};
my $pass = $form{'pass'};

my %users=(
's'     => ['m','granted.txt'],
'user2' => ['password2','granted2.txt'],
'user3' => ['password3','granted3.txt'],
);
my $accessdeniedfile = 'denied.txt';

####################################################################
print "Content-type: text/html\n\n";
if( $users{$user} && $users{$user}->[0] eq $pass ){
    open GRANTED, "<$users{$user}->[1]" or die "can't open GRANTED $!";
    print <GRANTED>;
    close GRANTED;
}else{
    open DENIED, "<$accessdeniedfile" or die "can't open DENIED $!";
    print <DENIED>;
    close DENIED;
}



Although it still does nothing to prevent an intruder from directly accessing http://123.456.678.90/S/new/index.htm
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question