Golo has asked for the wisdom of the Perl Monks concerning the following question:
package Guestbook; use base 'CGI::Application'; use strict; # define all run modes here to allow different sets, # the actual access control should then be enforced using # multiple instance scripts, which in turn are placed in a # secure area and only enable the desired set(s) sub _RUN_MODES { DEFAULT => { view => 'view_entries', sign => 'sign_guestbook' }, RESTRICTED => { delete => 'delete_entry' } } sub enable_rm_set { my $self = shift; my %run_modes = _RUN_MODES; foreach (@_) { $self->run_modes( %{$run_modes{$_}} ); #ensure that info on loaded sets is avaible $self->param($_ => '1'); } } sub setup { my $self = shift; $self->enable_rm_set('DEFAULT'); $self->start_mode('view'); } sub view_entries { my $self = shift; my ($ip, $del_link); # are we in "admin mode"? if ($self->param('RESTRICTED')) { $ip = "with IP's"; $del_link = '<a href="?rm=delete">+ del option</a>'; } return "showing guesbook entries $ip"; } sub sign_guestbook { my $self = shift; return "sign guestbook"; } # restricted sub delete_entry { my $self = shift; # bail out if authentification did not happen # (of course this check should be during setup ;) return _no_auth() unless defined($ENV{UserName}); return "delete entry"; } sub _no_auth { return "oops, authentification did not happen"; } 1;
use Guestbook; my $gb = Guestbook->new(); # enable admin mode $gb->enable_rm_set('RESTRICTED'); $gb->run();
use Guestbook; my $gb = Guestbook->new(); $gb->run();
Updates:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Application with access control on certain functions/run modes
by tilly (Archbishop) on Mar 28, 2004 at 07:31 UTC | |
by Golo (Friar) on Mar 28, 2004 at 14:19 UTC | |
by dragonchild (Archbishop) on Mar 28, 2004 at 17:22 UTC | |
|
Re: CGI::Application with access control on certain functions/run modes
by simon.proctor (Vicar) on Mar 28, 2004 at 14:20 UTC | |
by Golo (Friar) on Mar 28, 2004 at 15:49 UTC |