A crafty, nommy, occassionally geeky blog-thing.

Blosxom Plugin: Login (Hack)

In more productive news, we’ve finally gotten around to modifying Fletcher’s login plugin so that it performs its pattern matching against the filename rather than against the top level category name.


The original login plugin assumes that message categories will map neatly to desired access control lists. For instance, that I’d want one set of people to view all posts in category1, and another set of people to view all posts in category2. Further, it only performed its matching against the top category, so attempting to change restrictions on deeper level categories didn’t work.

I use categories to reflect the topic of a post. However, within any topic there can be posts of varying degrees of personal sensitivity or public interest. I therefore wanted a way to target specific posts, rather than just the overall topic.


The original code reads thus:

if ($localfile =~ /^$blosxom::datadir(\/)?$reqfile/) 

where $localfile is the absolute filesystem path of the post being checked, and $reqfile is the string pattern to be checked against.

I wanted to drop everything from $localfile that occurs up to and including the final ‘/’, and then check $reqfile against the remaining string (i.e., the filename without its context).

I’m not certain whether or not Perl already has a function which will do just that, however C looked up a couple of quick functions which would accomplish the same thing. Namely, ‘split’, which would take $localfile, and create an array of the elements taking ‘/’ as its delimiter, and ‘pop’, which then pops off the last element of the array (in this case, my filename) and pushes it into a variable.

So, I added the first two lines, and replaced the above with the final line:

@checkme = split('/',$localfile);
$localfile = pop(@checkme);
if ($localfile =~ /^$reqfile/) {

et voila! Its almost like knowing perl =P