Gossamer Forum
Home : Products : DBMan : Customization :

expire permissions [permission dependant upon field record]?

Quote Reply
expire permissions [permission dependant upon field record]?
Forgive me if it's been asked before- I've spent quite some time searching the forum and faqs.

I am setting up a database for members and guests of a small club site. Members have their own permission level (add permission mod is already installed and works fine) but instead of having it static, I'd like for the permission to expire when the membership does. There is already a date field for expire.

Ideally, instead of burdening the script with running it each time someone logs on, I'd like to run it as a cron (since it will change things only once a month). So.... is there a straightforward mod that will look at that some field record and adjust that user's permissions accordingly? I can handle the coding of the date comparisons (I already did that when I realized I'd need a way to expire the member's permissions as well as their displayed data).

tia and regards,
wf
Quote Reply
Re: [testboy] expire permissions [permission dependant upon field record]? In reply to
So you are not using the expire field to delete the records when the membership expires?

There is one related thread regarding changing permissions, but you would have to modify this for your use.

In the FAQ the thread is called: Unique View/Modify Permissions (sub change_permissions)

=== original thread =====

Topic: Unique View/Modify Perm. Still having trouble...
taurus December 21, 1998
Thread: http://gossamer-threads.com/p/000288

Please note that the url might not work due to changes since 1998. but you could search on the topic.

You might also consider using the Archive mod to move the records out of the database after a set period of time?

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/
Quote Reply
Re: [LoisC] expire permissions [permission dependant upon field record]? In reply to
Lois,
I had seen that article earlier today but didn't really spend much time with it. The quote "Don't anybody use the modification I posted above!" kind of made me shySmile

No, I'm not going to expire/remove the field. Just the opposite, the field is going to force the expiry of the permission. We don't want to lose the person off the database (since they may well renew in a couple of days) or even a couple of years.

What I want to do is in the opposite order of that article. It had
sub change_permission {
OPEN THE PASSWORD FILE
FIND THE MATCHING USER
ASSIGN THE USERNAME & PASSWORD TO VARIABLES
DELETE THE USER
REWRITE USER FROM VARIABLES + NEW PERMISSIONS
CLOSE THE PASSWORD FILE
}
I'd like to instead
sub change_permission {
Open default.db
read default.db
for each user (i){
run the conditional on the expiry field
if (change) {
change member field (say, indiv. to no)

open default.ps
change $perm_mem to 0 for user i
close default.ps
}
open default.db
write new database
close default.db

}

I guess I'm having a problem conceptually of how to read each line of the database, find the user in the password file that corresponds and change that particular permission. And it's not just the permission for the current user (which again wouldn't be quite so difficult) but I need to iterate for all records.

btw, thanks for replying.
regards,
william
Quote Reply
Re: [testboy] expire permissions [permission dependant upon field record]? In reply to
I'm not a programmer so I can't help you find a solution, but I think these other threads may be of some help.

In the FAQ under the category "Files":

Delete Inactive Accounts</A> (Cleanup the Password file)

-----------
Topic: Cleanup the Password file..
mart June 23, 1999
Thread: http://gossamer-threads.com/p/001181

* if url sbove not active search by topic *
------------

In the FAQ under "Admin - Permissions:

"Conditional Display of Add Record"

perhaps using parts of both those threads might help you to come up with a solution. I don't think it's an easy task to do what you want. And I'm afraid not many of those who are good at programming have been visiting the forum regularly.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/
Quote Reply
Re: [LoisC] expire permissions [permission dependant upon field record]? In reply to
Lois,
thanks for sharing your ideas. I'll look at those which I think I missed before. I think you are probably right, I'll find inspiration in those articles. Again, thanks for taking the time to reply. I appreciate the work you've done on the FAQs.

regards,
william
Quote Reply
Re: [testboy] expire permissions [permission dependant upon field record]? In reply to
Thanks Lois,
The delete inactive file did suggest a different approach that is much easier to deal with- create a password field that contains the same info
(eg write the expiry date to both the .db and .ps file) same info that can be used for different purposes and makes operating on the password file so much easier (as a simple compare utility that will be a slimmed down version of db.cgi).
recalls the old adage of "There's always two ways to skin a cat(fish)"

Now to do the add permission mod (again...)
Smile
regards,
wf
wf
Quote Reply
Re: [testboy] expire permissions [permission dependant upon field record]? In reply to
If you do find a solution it would be very nice if you would share it with others.

Best of luck

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/
Quote Reply
Re: [LoisC] expire permissions [permission dependant upon field record]? In reply to
okay lois,
here it is...
first, let me explain that I made it harder than it needs to be. A simple date comparison of the expiry vs. today enables a switch in what's displayed. We really don't need to expire anyone statically (ie change a record)

further, the only person who's permissions need to change are he/she who is expired. again, we do a simple comparison when they log on and there you go. we determine if they are still current members

in auth.pl
sub auth_check_password
#### after ####
# &auth_logging('logged on', $userid) if ($auth_logging);
##### note that I've modded the permissions for extra ones###
# I had previously added an expiry date permission but we don't need
# that and I'm too lazy to go and clean it out.

## Let's begin our mod setting the membership permission by the expiry
## date in their record

open (DB, "<$db_file_name") or &cgierr("error in lookup. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
foreach $line (@lines) {
chomp $line;
@data = &split_decode($line);
if ($userid =~ /^$data[$auth_user_field]/) {
# let's get some more dates
$today = &get_date;
$expiregrace = &get_date(time() - 518400);
$expire = $data[$expire_field_number];
# lets convert them to unix-speak so we can compare them
$compareexp1= &date_to_unix($expire); # expiration date
$compareexp2 = &date_to_unix($expiregrace); #2 months after expiration
$compareexp3 = &date_to_unix($today); #today
# if either the expiry or grace period, depending upon the switch
# is greater than today's date, we give member permission
if ($usegrace eq 1) {if ($compareexp2 > $compareexp3) {$mem = 1;}
else {$mem = 0;}}
else {if ($compareexp1 > $compareexp3) {$mem = 1;}
else {$mem = 0;}}
last;
}

}

###


# let's rewrite the password file
open (REPASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(REPASS, 1); }
@relines = <REPASS>;
close REPASS;

open (REPASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(REPASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $reline (@relines) {
if ($reline =~ /^$in{'userid'}:/) {
print REPASS "$in{'userid'}:$pw:$view:$add:$del:$mod:$mem:$exp_mem:$admin\n";
$found = 1;
}
else {
print REPASS $reline;
}
}
return ('ok', $db_uid, $view, $add, $del, $mod, $mem, $exp_mem, $admin);

}

Seems to work. My syntax may not be the cleanest but then again, this isn't my day job
Smile

btw, most of this code is derived from jpdeni's mods. I just figured out a different use for them. My thanks to her.
Quote Reply
Re: [testboy] expire permissions [permission dependant upon field record]? In reply to
I'm so happy you came up with a solution for your permissions :)

Yes, I think many of us would be lost if it were not for JPDeni and all the coding she has provided over the years.

And when people like you post your solutions it also helps many others who may be looking to do similiar functions.

Thank you very much for sharing your solution.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/