CGI-AppBuilder-Security

 view release on metacpan or  search on metacpan

Security.pm  view on Meta::CPAN

                   );
our %EXPORT_TAGS = (
    access => [qw(access_ok)],
    all  => [@EXPORT_OK]
);

=head1 NAME

CGI::AppBuilder::Security - Security Procedures

=head1 SYNOPSIS

  use CGI::AppBuilder::Security;

  my $sec = CGI::AppBuilder::Security->new();
  my ($sta, $msg) = $sec->access_ok($ar); 

=head1 DESCRIPTION

This class provides methods for reading and parsing configuration
files. 

=cut

=head2 new (ifn => 'file.cfg', opt => 'hvS:')

This is a inherited method from CGI::AppBuilder. See the same method
in CGI::AppBuilder for more details.

=cut

sub new {
  my ($s, %args) = @_;
  return $s->SUPER::new(%args);
}

=head2 access_ok($ar)

Input variables:

  $ar  - array ref containing the following variables:
  task		: task name required ($t)
  sel_sn1	: select one (DB/server name)
  sel_sn2	: select two (Argument)
  allowed_ip	: allowed ip address for each task
  roles		: roles allowed to access a list of tasks
  svr_allowed	: server allowed for each task
  arg_required	: required argument for each task

Variables used or routines called:

  None

How to use:

First define the parameters in the initial file or define all the parameters
in a hash array reference as $ar->{$p} where $p are

  task     = task_name
  sel_sn1  = a_db_name_or_server_name
  app_user = logname_or_logid
  usr_role = {
    usr1 = [qw(dba owb)],
    usr2 = [qw(r1 r2)],
   }
  usr_task = {
    usr1 = [qw(task1 task2)],
    usr2 = [qw(task3 task4)],
    }
  rol_task = {
    dba => [qw(task1 task3 task5)],
    owb => [qw(task2 task4)],
    }
  allowed_ip = {
    all   => [10.0.0.127,10.0.0.185,10.0.1.125)],
    task1 => [192.168.1.1,192.168.1.2],
    task2 => [10.0.0.5],
    }
  arg_required = {
    task1 => 'input1:input2',
    task2 => 'p_dnm:p_prj:p_tab:p_own',
    }    
  svr_allowed = {
    task1 => {svr1=>1},
    task2 => {svr1=>1,svr2=>1,svr3=>1},
    }  
  # $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
  #   $sec : 0~59
  #   $min : 0~59
  #   $hour: 0~23
  #   $mday: 1~31
  #   $mon : 0~11
  #   $year: yyyy-1900
  #   ex   : [0,0,0,16,8,109] = 2009/09/16 00:00:00
  task_expired = {
    task1 => [0,0,0,25,0,109],   # 2009/01/25
    task1 => [0,0,0,17,8,119],   # 2019/09/17
    }

  my ($q, $ar, $ar_log) = $self->start_app($0, \@ARGV);
  or
  my $ar = $self->read_init_file('/tmp/my_init.cfg');
  my ($status, $err_msg) = $self->access_ok($ar);
  if ($status > 0) {
    print "OK\n";
  } else {
    print "Failed: $err_msg\n";
  }

  my ($ok, $msg) = $self->access_ok($task, $ar); 
  if ($ok) { 
      $self->exe_sql($q, $ar);
  } else {
      print $self->disp_form($q, $ar);
      print "<font color=red>$msg</font>\n" if $ar->{write_log}; 
      $self->echo_msg($msg,0);
  }

Return: ($status, $msg) where $status is 1 (ok) or 0 (not), and the msg
is the error message. 



( run in 2.053 seconds using v1.01-cache-2.11-cpan-5735350b133 )