User authentication for some Perl CGI scripts


 
Thread Tools Search this Thread
Top Forums Web Development User authentication for some Perl CGI scripts
# 1  
Old 11-13-2008
User authentication for some Perl CGI scripts

Hi,

I am trying to create a web interface with Perl CGI with 2 pages. The content of these pages is dependent on the user accessing it. Thus, I need some kind of authentication to identify WHO is logging in but I DO NOT WANT to be restricting the pages to a few.

What is the best way to prompt for a username/password from within the Perl CGI code (without building one more form) ? Also, once authenticated, how can I make sure the username/password box is not prompted on moving to the other page.

Appreciate any help in this regard. I can explain in more detail if required Smilie

Regards,
garric
# 2  
Old 11-14-2008
See if HTTP authorization is what you want. Your browser will show a standard popup requesting for username and password. You can set up HTTP authorization in Apache. From what I found, it's not possible to do so with Perl CGI (for mod_perl would be ok). It seems like the entered password will not be passed via the CGI mechanism.

For the Apache-based configuration, say if you apply the authorization on the URL /somedir then everything inside this path will be protected. You will only be prompted for authentication the first time you enter. Once you are in, browsing pages inside require no further authentication. That does not require any Perl code changes.

Basic access authentication - Wikipedia, the free encyclopedia
core - Apache HTTP Server
# 3  
Old 11-14-2008
thanks for this info. But I have one problem with this method which I am not sure how I can address. I do not want to restrict the page to a few. Will this method not require me to explicitly add usernames of who can access?

I want users to be authenticated so that I can track who is logging in and what they run.

Regards,
garric
# 4  
Old 11-14-2008
I'm not exactly sure what you meant by "I do not want to restrict the page to a few. Will this method not require me to explicitly add usernames of who can access". Well, there must be a list of users defined with password (password store) with any kind of authentication system. However, you can choose a format that allows you to more easily update who can have access (i.e. update the access list). You can also choose between an allow-by-default policy or a deny-by-default policy. That is if you don't want to have everybody authenticate, you can use an allow-by-default policy to define those explicitly require authentication, while the unstated ones can enter without authentication. This is all possible with easy Apache config.

The default password store is a text file. But Apache contains additional modules that allows you to put the authentication info in SQL database or DBM files that you can choose from. You can modify data stored in them from Perl.

I suggest you build yourself a simple test environment and see if that fits your use case because I'm not exactly sure what you meant.
# 5  
Old 11-14-2008
Sorry, my bad. I have to authenticate the user using LDAP and once I get a username/password, I can do that. But my problem is, in the configurations, I do not want to put a list of users like this

require user <user1> <user2> ...

Any user who tries logging in will be authenticated with LDAP. Once validated, the web tool will be displayed in a way dependent on the user. I hope I was clearer this time Smilie
# 6  
Old 11-14-2008
Hey! Apache allows you to authenticate with an LDAP backend.

mod_authnz_ldap - Apache HTTP Server

And you don't need an explicit user specified at all. If you need to, "Require valid-user" will match any users defined in the configuration. Also check that page for information about this and some examples. It seems to me a rather flexible one that the module does not mandate a specific LDAP schema.

If you insist you need to do it the Perl way, or you think you can't live with this method, you'll be required to deploy your Web application on mod_perl instead of Perl CGI because someone at other sites said Apache would not pass the password to the CGI process. I haven't verified this claim so I can't confirm. Upon HTTP authentication, the username+password will always be available in the HTTP header (that's why it works for Apache), but Apache may filter some of them before making them available to the CGI process (as HTTP_* envvars). But it seems that Apache *will* pass the username, that your CGI process can use that retrieved via an envvar to implement your business logic.

Or you deploy it on your own perl-based Web server daemon without Apache. Of course, I don't think it is too practical although theoretically you can do that. It's just the same line of thought as you can write a new OS from scratch but no one will casually do that.
# 7  
Old 11-14-2008
Cool, I guess the first option here will do. The ' require valid-user' is probably what I was looking for. But what should I put into the config file to be able to enable this?

Directory -> "/abc/def"
Module : mod_authnz_ldap
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash scripts - CGI and ssh

Hi Everyone, I started looking at the possibility of making some of our bash scripts available through a web server using CGI and the simple ones works just fine. Now I need to execute remote commands using ssh but can't really get it to work. I got private keys all sorted. Must be ssh... (1 Reply)
Discussion started by: arizah
1 Replies

2. Shell Programming and Scripting

CGI Perl : while loop in CGI perl

Hi Team, I am trying to connect to database(succeeded ) and print the records on the browser using while loop. But the elements of array are not displayed instead while loop is displayed directly. Instead of the below I can embed html statements in print but I am looking for the below style as I... (1 Reply)
Discussion started by: scriptscript
1 Replies

3. Shell Programming and Scripting

Perl CGI : unable to download the excel sheet from perl cgi page

Hi All, I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet. I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet. print "<center><table... (2 Replies)
Discussion started by: scriptscript
2 Replies

4. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

5. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

6. Shell Programming and Scripting

Perl LWP user authentication

Hello all.. i am new to perl scripting.. i wanted to parse a text file, encode the parsed text and attach in url.. please point me to right resources if you know any..This is my major problem. Now i try to get a url running and save it in a text file using LWP module in perl, I used following... (0 Replies)
Discussion started by: empyrean
0 Replies

7. Shell Programming and Scripting

isset() PHP function in cgi bash scripts

Hi! Some minutes ago I've posted a question related with sed regexps because I need to catch information sended with forms with GET action. This is the post: https://www.unix.com/shell-programming-scripting/127800-regular-expression-sed.html But now I have a new question. Does cgi scripts have... (0 Replies)
Discussion started by: GagleKas
0 Replies

8. UNIX for Dummies Questions & Answers

How to share CGI Scripts across UNIX web server?

Hi, is it possible to create a CGI folder somewhere on the server and allow all domains on that server be able to access the scripts? I tried a ScriptAlias addition in httpd.conf but still no luck. Would greatly appreciate any tips! Thanks. Linux version 2.4.20-021stab028.3.777-enterprise Plesk... (5 Replies)
Discussion started by: karlsworld
5 Replies

9. Programming

Perl CGI Scripts

I need to create a webserver to run Perl CGI Scripts. Anyone have any ideas or good links? Yes I know there are lovely programs out there, but I need to build one in C. Thanks! (1 Reply)
Discussion started by: cb.mark
1 Replies

10. UNIX for Dummies Questions & Answers

Help With CGI Scripts and .htaccess

Hi everyone, I need help with writing a script that does the following: a client/user goes onto my website, hits a link, it would pop up either 1. user name and password 2. password and directory name and then after they enter the required info, it would take them to their own folder. So... (6 Replies)
Discussion started by: crazycelicagts
6 Replies
Login or Register to Ask a Question