Gossamer Forum
Home : Products : DBMan : Installation :

Cleanup the Password file..

Quote Reply
Cleanup the Password file..
I wonder if there are some people, who want to automaticly cleanup their pw file. If so, there must be added a field in the pw file, whitch contains the login-date. This is what I want: Automaticly, when a user logs in, write the date in the pw file. Than, with an admin link, once or twice a week, run a login-refresh-script. (or with a cron automaticly). The users, from who the login are gone be deleted, will receive first an email, lets say, two days before the data will be deleted. This is how far I can go, HELP.
THANKS.
----------
Mart.
Quote Reply
Re: Cleanup the Password file.. In reply to
First you'll need to add a field to the password file. That sounds like a pretty easy thing, but there are a lot of places that the password file is accessed and you will have to account for that extra field every time. I found out what a pain it is when I wrote the "password lookup" mod.

Once you account for the additional field everywhere in the script, you'll need to add a routine to auth.pl to not only read the file but also to write to it, with the new date. That shouldn't be too hard.

Then you'll need to set up your subroutine to go through the password file, check the date and either send an email or delete the record. If you don't use cron, you'll probably want to add still another field to the password file for the date the emails that had been sent, in case you didn't run it for a day or two. This is the only way to be sure everyone gets notice before their password is deleted.

To make cron do it automatically, you would probably need to set your delete routine up as a separate script from db.cgi. There is a great explanation of how to set up cron in the FAQ for Links here on Gossamer Threads.
Your separate script would have to include several of the subroutines from db.cgi, probably at least part of sub query, sub date_to_unix and maybe some others.

This is a major modification.

------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
What do you mean by 'major modification', that this is specialy for me?? Don't you think there be more users who appreciate such a mod??

I was hoping you'll start with it...
Anyway, thanks.
Greetings,
-------
Mart.
Quote Reply
Re: Cleanup the Password file.. In reply to
It's a major modification in that it will take a lot of work to accomplish. I don't know if other users will want it or not.

I don't have any experience at all with writing separate files to be run by cron, so if I were to do it, it would require you to have a link or, at best, would work like your autodelete whenever someone logs in. Which, in order to be on the safe side would require two extra fields in the password file.

At any rate, this isn't something I can whip out in a few minutes online at the forum. That's what I mean by a "major modification."


------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Hi,
Quick answere. I really hope, you find the time for it. The part with a link is good for me, or paste it in the autodelete mod, if possible. If you're interested, I've a script on my server, what is powered by a cron. It makes each day a backup of my important files, saved in seven different dir's (days).So I've always 7 different backups. Very good. I don't think you've any trouble to read it. It might be useful.
Thanks again.

Greetings,
----------
Mart.
Quote Reply
Re: Cleanup the Password file.. In reply to
I'll get back to you if I come up with something. I am in the midst of some other things, though.


------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Ok,

Meanwhile, there may be more people interested in this mod. If they show that here, maybe you see then, that it's not only for me. I think its a very usefull mod.

I'll hear from you.

Gr.
--
Mart.
Quote Reply
Re: Cleanup the Password file.. In reply to
I think that we need to be a little more appreciative of JPDeni's time here. Mart I'm sure that there are many perl programmers who would do your mod for you on a fee for service basis. JP just thought I would say again how much I appreciate all your help.

Mike
Quote Reply
Re: Cleanup the Password file.. In reply to
Thanks Mike. Smile


------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Mart,

Quit pestering JPDeni. She's gone way above and beyond the call of duty to help us out. Contact her via email and offer to pay her is one thing, but you need to relax a bit.

Quote:
I was hoping you'll start with it..
I really hope, you find the time for it..
I think its a very usefull mod..
I'll hear from you

Sheesh! Go buy yourself a Perl book.
Quote Reply
Re: Cleanup the Password file.. In reply to
I thought there would be a bit more positive reaction on this. Let me tell you this: If anyone appreciate the help of JPD, I think its me. I'm not gonna defend myself for the words of Katana Man. I think its quit easy, to push someone in the back.
When I saw the reactions, I thought that there are at least two more people interested in this thing. Really frustrated, when I saw, that we're not on that same line.
Anyway, thanks for the reaction.

At least of all, excuse me for my language. not English.
-------
Mart.
Quote Reply
Re: Cleanup the Password file.. In reply to
I'm going to need to look at your db.cgi file and your auth.pl file so I will know what changes you have already made to the script. I don't want to be writing something that will conflict with your current modifications. If you could make those files available in .txt form on your website, I'll take a look at them and see if I can give you what you want.


------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Great!! Smile
The files you asked for are on http://www.autorandstad.nl/db_cgi.txt and /auth_pl.txt,

Thank you!!
----------
Mart.
Quote Reply
Re: Cleanup the Password file.. In reply to
Also, you said in private mail to me that you had something else in mind that would be even more complicated. You might as well tell me now. So many things are interrelated that it's less work to do things all at once than to do it piecemeal.

One of these days I'll get back to working on my own site. Smile


------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Well, I'll give it a try:
I will setup a fourth database in my site, where users can give their wishes for something they are been looking for. This has everything to do with cars. For example they look for a Mercedes, type C 200, year 1995. The purpose is, to create a modification, that will search in two other databases for lets say one month for matching records. The programm must send an email to the car searchers, the first time with all the maching records (with a max. of 10), and then lets say once a day (cron) if there are any new added matching records. If yes, send an email with the new record(s). This mean, that the earlier sended records must be saved in an extra field in the searchers db. I probbebly also have to work it out a little bit more.
This is, I think a very complicated, and also individual modification, but will you let me know, what you think of it??

[This message has been edited by mart (edited June 27, 1999).]
Quote Reply
Re: Cleanup the Password file.. In reply to
It's probably best that you told me what you were planning. That will take a very long "think" time. Smile

I think I have your mod ready.

First, you will need to add fields to your password file. Add the following to every line:

:27-Jun-1999:

so the format looks like

admin:admin:1:1:1:1:1:foo@bar.com:27-Jun-1999:

Use the current date -- the date that you will actually be making the change.

Add a couple of lines to your .cfg file:

Code:
# Number of days of inactivity before a warning message is sent
$inactive_days = 30;

# Number of days between the time the warning message is sent and the password file is deleted
$warning_days = 7;

I am assuming that you have $mailprog and $admin_email already defined in your .cfg file.

In auth.pl, replace sub auth_check_password with the following:

[code deleted. Look a couple more messages down for the edited code][/code]
Of course, I haven't tested this, but I have checked it for syntax errors.

I put in lots of comments for the lines I added, so you can see the changes. There are some other changes too, though, so if you want to figure out what I was doing, you'll need to compare it to your existing file.

I would suggest that you make several "dummy" entries in your password file that have old dates. Make a few with the date above to be expiring -- 25-May-1999 would work. I would be sure to have the email addresses connected with those records be either your own or that of a friend, so you don't send email to someone who isn't expecting it. Smile

Also make a few that would be expired today, in the form of

admin:admin:1:1:1:1:1:foo@bar.com:25-May-1999:19-Jun-1999

Then log in and see what happens. After you log in, download your password file and take a look to be sure that it works as you expect it to. I would keep a copy of the old password file to compare to the one you download after you log in.

If I may make a suggestion -- I think it would be better for you to have the call to &auto_delete in your auth.pl file. The way you have it, every time anybody does anything, it has to go through your entire database. That will slow things down a lot if your database is of any size at all.

If you move the line

&auto_delete; #Activeert het autodeleten van records ouder dan ..dagen

to just after

elsif ($in{'login'}) { # The user is trying to login.

in the auth.pl file, sub auth_check_password, you'll have it checked whenever anyone logs in, which should be plenty.


------------------
JPD







[This message has been edited by JPDeni (edited June 29, 1999).]
Quote Reply
Re: Cleanup the Password file.. In reply to
Well, more than great,
Thank you for the very quick help.
But I couldn't get it work good, it will messup my PW file. I deleted the ' ' between the '| |', but thats not the point. I don't know, whether to place one or two date's behind the email adress in the pwfile. It also delete the maked line in the top of my pwfile and I think, the writing of the today date works not, I only see a ':' appear in the pwfile, but thats maybe because I don't know if it has to be one or two date's in the pwfile.
Quote Reply
Re: Cleanup the Password file.. In reply to
Then I guess it isn't great. Smile

I'll have to look at it later. I have some appointments today and I don't have time right now to go into to much detail.



------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
I know I suggested putting two dates in for testing purposes, but forget that. Just add

:28-Jun-1999:

to the end of all your password lines.

If you want to keep the comment line at the beginning of your password file, change

Code:
PASS: foreach $pass (@passwds) { # Go through each pass and see if we match..
next PASS if ($pass =~ /^$/); # Skip blank lines.
next PASS if ($pass =~ /^#/); # Skip Comment lines.

to

Code:
PASS: foreach $pass (@passwds) { # Go through each pass and see if we match..
if ($pass =~ /^$/)
$output .= $pass;
next PASS;
}
if ($pass =~ /^#/)
$output .= $pass;
next PASS;
}

That will keep all of your lines intact.

When you log in, there should be only one date at the end of the line with your password and there should be a : at the end.




------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
This is what happens:
When a user logs in, the message will be sent to all other users, but the date in the pwfile is change to the today date. (29-Jun-1999), also by the other lines, the double dot ( Smile is gone, except by the inlogger, there it is at the end of the line. No lines are deleted, only the message is sent. I'll try now, with an older date, if the line will be deleted.
Quote Reply
Re: Cleanup the Password file.. In reply to
With the line with an older date, whitch must be deleted happens this:
The whole line is put behind the line, that before logging in, stands under the deleted line, so there stands two pwlines in one line.
Quote Reply
Re: Cleanup the Password file.. In reply to
I'm going to need to see your password file -- the one that you have used with the mod. I'm going to make a big exception here and suggest that you send me the password file as an email attachment. I understand that you probably would rather not have everyone able to look at it.

Send it to deni@jpdeni.com


------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Thank you, Mart, for sending me the password files. It really helped.

Here's the edited subroutine (just a few typos and using > instead of < made all the difference.) Smile

Code:
sub auth_check_password {
# --------------------------------------------------------
# This routine checks to see if the password and userid found
# in %in (must be 'pw' and 'userid') match a valid password and
# userid in the password file.
# It returns a status message and a userid which is built by a
# "user name" + "random number"
# which get's stored in the query string.

my ($pass, @passwd, $userid, $pw, @permissions, $file, $uid, $email, $last_login, $warning_sent);
my ($server_auth) = $ENV{'REMOTE_USER'} or $ENV{'AUTH_USER'};

if ($auth_no_authentication or (($db_uid eq 'default') && $auth_allow_default)) {
return ('ok', 'default', @auth_default_permissions);
}
elsif ($server_auth) { # The user has logged in via server authentication.
return ('ok', $server_auth, &auth_check_permissions($server_auth));
}
elsif ($in{'login'}) { # The user is trying to login.
open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>; # Let's get the user id and passwords..
close PASSWD;
my ($view, $add, $mod, $del, $admin, @data);
my ($found) = 0;
my ($output) = '';
PASS: foreach $pass (@passwds) { # Go through each pass and see if we match..
if ($pass =~ /^$/) {
$output .= $pass;
next PASS;
}
if ($pass =~ /^#/) {
$output .= $pass;
next PASS;
}
chomp ($pass);
(@data) = split (/:/, $pass);
if (($in{'userid'} eq $data[0]) && ($in{'pw'} eq $data[1])) {
$found = 1;
srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
$db_uid = "$data[0]." . time() . (int(rand(100000)) + 1);# Build User Id
$view=$data[2];
$add=$data[3];
$del=$data[4];
$mod=$data[5];
$admin=$data[6];
# save the date of the login
$data[8]=&get_date;
# reset the "warning" date
$data[9]='';
$output .= join (":",@data) . "\n";
open(AUTH, ">$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
print AUTH "$uid: $ENV{'REMOTE_HOST'}\n";
close AUTH;
}
# if a warning has been sent previously
elsif ($data[9]) {
# if the warning time has not elapsed
unless ((&date_to_unix($data[9]) + (86400 * $warning_days)) <= (time)) {
# keep the login information
$output .= $pass . "\n";
}
else {
# otherwise save the deleted account info to the log
&auth_logging('deleted user', $pass) if ($auth_logging);
}
}
# if the account has been inactive
elsif ((&date_to_unix($data[8]) + (86400 * $inactive_days)) <= (time)) {
# send an email to warn them
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");
print MAIL "To: $data[7]\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $db_name Account Expiring\n\n";
print MAIL "-" x 60 . "\n\n";
print MAIL "You have not logged in to the $db_name database at [insert the URL of your database here]\n";
print MAIL "for at least $inactive_days days.\n";
print MAIL "If you would like to maintain your account at $db_name, please visit the site again and log in.\n";
print MAIL "If you do not visit the database within $warning_days days, your account will be deleted.\n";
print MAIL "Your username is $data[0]\n";
print MAIL "Your password is $data[1]\n\n";
print MAIL "Sincerely, [insert your signature here]";
close (MAIL);
# save the date the warning was sent
$data[9] = &get_date;
# add the new information back into the password file
$output .= join (":",@data) . "\n";
}
else {
# everything is fine with this person's account
$output .= $pass . "\n";
}
}
# write the information back to the password file
open (PASSWD, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASSWD, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
print PASSWD $output;
close PASSWD;
if ($found) {
foreach (0 .. 3) { $permissions[$_] = int($permissions[$_]); }
&auth_logging('logged on', $userid) if ($auth_logging);
return ('ok', $db_uid, $view, $add, $del, $mod, $admin);
}
else {
return ("invalid username/password");
}
}
elsif ($db_uid) { # The user already has a user id given by the program.
(-e "$auth_dir/$db_uid") ?
return ('ok', $db_uid, &auth_check_permissions($db_uid)) :
return ('invalid/expired user session');
}
else { # User has not logged on yet.
return 'no login';
}
}

Also, you should make some other changes in db.cgi

In sub signup in db.cgi change

print PASS "$in{'userid'}:$in{'pw'}:$permissions:$in{'email'}\n";

to

$sign_date=&get_date;
print PASS "$in{'userid'}:$in{'pw'}:$permissions:$in{'email'}:$sign_date:\n";

In sub admin_display in db.cgi change

print PASS print PASS "$in{'new_username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:
$in{'per_mod'}:$in{'per_admin'}:$in{'email'}\n";

to

$sign_date=&get_date;
print PASS print PASS "$in{'new_username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:
$in{'per_mod'}:$in{'per_admin'}:$in{'email'}:$sign_date:\n";

Let me know if you still have problems.


------------------
JPD







[This message has been edited by JPDeni (edited June 29, 1999).]
Quote Reply
Re: Cleanup the Password file.. In reply to
I don't know how you can have some users kept in the password file without their logging in. It may be possible, but I would have to start over from the beginning on the mod and I'm just not up to it. Smile

I'm glad I could help. You are very welcome. Smile

------------------
JPD





Quote Reply
Re: Cleanup the Password file.. In reply to
Hi JPD,
Well, everything works fine now.
Hope this not bother you, but is it possible, to held one or two users permently in the pwfile, without logging in??, if not, no problem, I'm more dan satisfied with this.
I wish I knew more words to thank you.
Perfect.

Greetings,
----------
Mart.