Hi all,

I'm fairly new to Perl I am confused ? I will try to explain it. What i am trying to do is we have 26 branches and our central office generates data files like for income files (003.inc010105,003.inc020105,) /sales(003.sal010105) and many more reports on dialy basis in text format which is 08 kb to 15 kb. I mean to say when 003 logs in and wants income files all files pretaning to his branch 003+inc(income file)+date(s) will be availabe to him for download or view which is stored in a particular folder, and in the same order for sales or other reports. And in same manner for other branches 004,005 or others. Using a perl script for login.
We are sending sensitive/secret information via https.
May some one please show me some way.
Thanks in advance

I'll be honest, I only vaguely understand what you need done. I can assist you in building a perl program that logs someone in, etc, etc, but I'm a little lost on your whole file structure with dates and stuff. I don't have enough information to help you with your problem, but if you could elaborate, I'd be glad to see what I can do.

Hi Comatose,
Thanks for your speedy reply.
I have text files something like this 003inc010205.txt / 003inc020205.txt (here 003 means branch code + (inc) file name + date)
These files are generated on daily basis only the last part of date is changed. And similarly for sales we have 003sal010205.txt and in the same fashion for other reports (branch code + file name + date)
The starting of the file denotes the code of branch 003 is xxx branch / 004 is yyy branch / 005 is zzz branch and so on.
Now when 003 logs in with a login Id as 003 and wants inc files all the files pertaining to 003inc+dates will be available to him for download. And in the same manner for other reports.
When 004 logs in and wants his inc files all files for 004inc+dates will be available for him.
These files are located in particular directory sub-folder.
It’s like finding files in directory sub-folder. ?branch code=xxxfilename&directory=AAA.
I apologise if I'm asking a lot but I can't see how to do this?
Your help is greatly appreciated!
Thanks!

Ok, I understand the file naming convention, but now I need to know a few number of things.
A) This will be all web-based right?
B) A list of all the possible filenames (inc, sal, etc, etc)
C) A List of the directory structure (/ourfiles/001/sal) or whatever
D) Is There A Username and Password Needed, If So, Where Will the password file be stored? Is It A Unix Encrypted Password? Is It using PAM? Will it be just a plain text password file?

Hi,
Answers to your previous reply.
A)Its a dial-up server.
B)Yes
C)Yes
D)Yes, a username & password is a must because the username will be set to numeric like 003,004 or 005....
The password file is in /cgi-bin/pswd/password.txt
Its just a plain text password file.

Ok, What do you mean dial-up server? I'm saying this perl program is supposed to be a CGI (all web based) right?

B and C are not yes and no questions. I'm saying that I will need a list of all possible names: inc, sal, and whatever else there is.... I'll also need the directory tree where all these .txt files are stored at.

The Password File, How is it delimited: username:password, by comma's or by tabs? You say plain text, so I'm guessing the password is NOT encrypted also.... having it stored in the CGI bin, is generally a bad idea. If you plan to do that, a good idea is to rename it to password.pl, so that the server thinks it's a program, and if someone tries to surf to it, they will get an error message.

Also, Are you saying that the username is assigned which branch based on their name? If so, is this in the password file? Say: branch:username:password?

Hi,
This perl program is definitely to be a CGI (all web based) Yes.
B) list of all possible names: inc, sal, inw, out, drecs, crecs, drtrf, crtrf, drnat, crnat.
C) Individual folder for inc, sal, inw... in /var/www/bank/reports)
The password file is delimited by tabs and password is NOT encrypted.
I will surely work on your advice and rename it as password.pl thanks for your kind advice to me.
No only username&password is there.

Ok, Now, Each One of those has a folder under /var/www/bank/reports, so
/var/www/bank/reports/inc/*.* is all the inc files. So, all the inc files are clumped together (003incdate, 004incdate, 005incdate) in the same folder right?

So far so good, we need to find a way now, however, to be able to store the branch with the username, or find a way to associate the two of them. Is The password file already made and already setup? Would it hurt to modify that password file? Otherwise, we can create another file (say branch.txt.pl) that will link the two together. Say, line one of the password file is: jsmith <TAB> Password
then in the branch.txt.pl file, make line 1 003 (or whatever branch jsmith is). Do you understand so far?

Hi,
Yes, all the inc files are clumped together (003incdate, 004incdate, 005incdate) in the same folder. /var/www/bank/reports/inc/*.*
The password file is only made, no setup is done. We can modify the password file.

Too Cool. The password file will need minor modification, so that we can associate everyone by their branch. So, I'm thinking that 1 line of the password file should look like this:

username <TAB> password <TAB> branch number

IE:

jsmith     mykidsname     003

I'll assume that the password file will look like this (and will build one for testing purpose on my server), and I'll start building some code for it. I'm only going to do very plain HTML within the Perl Script, but I'll comment it all, and make it very easy to know where you will need to modify in order to make it look .... well, like the rest of the site :) I'll start working on that tonight.

Hi,
Thanks a lot.

Hi Comatose

I'll start building some code............
I'll start working on that tonight.........

Desperately waiting!!

Fareen

Fareen,

The code is almost done, actually. There are 2 issues, left however, that I am working on resolving. One of those is setting a session cookie, which shouldn't be any kind of problem, but I still need to code that peice. The other, is having the links to the files work to download them. I can fix that issue also, but I'll need a little bit more time. Also, have you modified the password file to contain the business code at the end of the passfile?

Also, the page is very very plain, that will require your HTML touches to make it work for you and your company, but right now this is what I have:

http://www.aftermath.net/~coma/cgi-bin/business.pl

Username, Password: test test

Hi,
That Works GREAT.
I don't have words to express.
Thanking you in advance.

alright, it's done. I'm attaching the perl source code. There is 1 spot that you need to focus some attention to... I have my aliases set up to default over-write anything that I try to copy. So, if I try to copy a file to say /home/coma, and the same filename already exists there, my linux setup will automatically over-write the one that's already there. You need to setup your box's alias for whomever the account is that will be running this script to automatically over-write should the file exist. Anyway, I've attached the mock passfile, and the perl file in a .zip file. Let me know how it goes.

Hi Comatose,

I get this error:

[Thu May 12 03:20:21 2005] [error] [client 127.0.0.1] Prototype mismatch: sub main::head vs ($) at /var/www/bank/cgi-bin/business.pl line 5
[Thu May 12 03:20:21 2005] [error] [client 127.0.0.1] Died at /var/www/bank/cgi-bin/business.pl line 319.
[Thu May 12 03:20:23 2005] [error] [client 127.0.0.1] Prototype mismatch: sub main::head vs ($) at /var/www/bank/cgi-bin/business.pl line 5, referer: http://www.mysite.com/cgi-bin/business.pl
[Thu May 12 03:20:25 2005] [error] [client 127.0.0.1] Prototype mismatch: sub main::head vs ($) at /var/www/bank/cgi-bin/business.pl line 5, referer: http://www.mysite.com/cgi-bin/business.pl
[Thu May 12 03:20:25 2005] [error] [client 127.0.0.1] sh: line 1: ffile: Permission denied, referer: http://www.mysite.com/cgi-bin/business.pl
[Thu May 12 03:20:25 2005] [error] [client 127.0.0.1] I suck at /var/www/bank/cgi-bin/business.pl line 260., referer: http://www.mysite.com/cgi-bin/business.pl
[Thu May 12 03:20:25 2005] [error] [client 127.0.0.1] Premature end of script headers: business.pl, referer: http://www.mysite.com/cgi-bin/business.pl

I installed the
perl -MCPAN -e'install LWP::Simple'
but still i get above error. Please help.
fareen

I'm willing to bet that the protocol mismatch is because you are supposed to be using https, and you are using http, I could be mistaken, so give it a shot and let me know.

Also, you don't need LWP, and if you don't want to have it installed (thought it is extremely handy) you can remove that from your server, along with the line of: use LWP, because it's not required. In fact, make sure that you take out the use LWP::Simple, because not only is not needed, I think it's causing problems on your system.

Also, did you make sure to change all the variables at the top of the script, so that they point to your folders, and https paths? Make those changes, and if there is still problems, attach the .pl file in an e-mail to me.

Hi Comatose,
I beg your pardon.
I have realised my mistake and your script is perfect. Its PERFECT
One more ?
When (text) files are open in the browser and clicked the data is displayed in the browser , but when right clicked to Save Link Target As it does not download and save the file. Please this is very important. When the branches wants to download the particular file they will just right click and save the file on their machine.
I will be highly thankfull for this.
Hoping for a favourable reply.
Thanking you in advance.

*Yikes*

I'll see what I can do.... let me give you the breakdown of WHY it is this way. The decision then will be yours to make regarding the use of such. The files that the people of the branches want to download (those are in some other folder... like: /var/www/bank/reports/*) Those paths, as far as I know, are NOT accessible to someone surfing the web. In order to make those files accessible, the program copies the file from it's original location, and saves it onto the root of the webserver, but it only does so, AFTER they click the link (the actual HREF of the link, points to the CGI, with the filename as a parameter). When the CGI see's this, (the person clicked a filename) it copies the file to the web server directories, and then redirects the browser to the newly copied file. This was made to aid in security and privacy of those files. However, It is entirely too possible for me to copy all the files to the webserver folders when the links are created, and simply HREF those.... that choice is yours...

Hi,
I am glad & highly thankfull to you for showing me your willingness to see into the subject.
Thanks a lot for the explanation. You are great.

Umn, Thank You.

Here is the updated version of the .pl file, so that they can right click on the link and save as... let me know how this works for you, k? :)

Hi Comatose,
Thank you very much. It works perfect. You have done it.
Thank a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.