## OpenCA - CA Command
## (c) 2001 by Michael Bell and OpenCA Group
##
##   File Name: show_roles
##       Brief: list roles
## Description: show all actual roles - entry to rolemanagement
##  Parameters: none

sub cmdShow_roles {

## load OpenSSL-dir
my $roledir = getRequired ('RBAC_DIR')."/".
              getRequired ('ROLES_DIR');

## load all lines
opendir DIR, $roledir or
  configError (i18nGettext("Cannot open the directory which contains the roles (__DIR__)!", "__DIR__", $roledir));
my @list = readdir DIR;
closedir DIR;

## sort them
my @hvalues;
foreach my $item (@list) {
        if ( $item !~ /^(\.\.|\.)$/ ) {
                push @hvalues, decodeName ($item);
        }
}
@list = sort @hvalues;

## Get required parameters ( return only the value string )
my $sheet    = getRequired( 'ShowRolesSheet' );
my $uptime   = $tools->getDate();

my @cols;
my $page;

## Get the base Page ( got in $page variable )
if( not $page = $query->getFile( "$sheet" ) ) {
	configError ( i18nGettext ("File not Found : __SHEET__", "__SHEET__", $sheet) );
};

my $table .= $query->startTable( 	COLS=>[ gettext ("Roles") ],
				WIDTH=>"100%",
				TITLE_BGCOLOR=>"#DDCCFF" );

my $value;
foreach $value (@list) {
  my $role = $value;
  $role =~ s/ /%20/g;
  $table .= $query->addTableLine( DATA => [ $value ]);
}
## for requests from users without a certificate
$table .= $query->addTableLine( DATA => [ gettext ("&lt;empty role - for new users&gt;") ]);

## Close the Table
$table .= $query->endTable();
$table .= getCopyRight();

## Substitute the Variables in the $page
$page = $query->subVar( $page, '$uptime', $uptime );
$page = $query->subVar( $page, '$table', $table );

print "$page";

}

1;

