#################### main pod documentation begin ################### =head1 NAME Zymonic::Form::KeyEntry; - Zymonic Workflow System Form 'KeyEntry' module =head1 SYNOPSIS This is a module to show the status of decryptor keys and allow entry of decryptor keys. =head1 DESCRIPTION This is a module to show the status of decryptor keys and allow entry of decryptor keys. =head1 USAGE This module should not be called directly. =head1 BUGS NONE =head1 SUPPORT As in the license, Zymonic is provided without warranty or support unless purchased separately, however... If you email zymonic-support@zednax.com your issue will be noted and may receive a response. For security issues, please contact zymonic-security@zednax.com and someone will respond within 8 working hours. =head1 AUTHOR Alex Masidlover et al. CPAN ID: MODAUTHOR Zednax Limited alex.masidlover@zednax.com http://www.zednax.com =head1 COPYRIGHT This program is free software licensed under the... Zymonic Public License 1.0 The full text of the license can be found in the LICENSE file included with this module. Other licenses may be acceptable if including parts of Zymonic in larger projects, please contact Zednax for details. =head1 SEE ALSO perl(1). =cut #################### main pod documentation end ################### package Zymonic::Form::KeyEntry; use strict; BEGIN { use Exporter (); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 'D1-r7186'; @ISA = qw(Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw(); @EXPORT_OK = qw(); %EXPORT_TAGS = (); } use base "Zymonic::Form"; use Zymonic::Decryptor::Client; use Zymonic; use Exception::Class ( 'Zymonic::Exception::Decryptor' => { isa => 'Zymonic::Exception', fields => ['decryptor'], description => 'Decryptor related exception', }, 'Zymonic::Exception::Decryptor::Form' => { isa => 'Zymonic::Exception::Decryptor', fields => ['decryptor'], description => 'Decryptor related exception', }, 'Zymonic::Exception::Decryptor::Form::KeyEntry' => { isa => 'Zymonic::Exception::Decryptor::Form', fields => [], description => 'Error from decryptor', }, 'Zymonic::Exception::Decryptor::Form::KeyEntry::DecryptorError' => { isa => 'Zymonic::Exception::Decryptor::Form::KeyEntry', fields => [], description => 'Decryptor status returned error', }, ); #################### subroutine header begin #################### =head2 init Usage : N/A Purpose : This is a stub for the init. Returns : nothing Argument : nothing Throws : see the 'See Also' Comment : nothing See Also : =cut #################### subroutine header end #################### sub init { my $self = shift; $self->{field_groups} = { structure => { content => {}, type => 'base' }, defns => {} }; $self->{ident} = ( $self->{ident} || '' ) . ( $self->{zname} || '' ) . '_'; $self->get_records; } #################### subroutine header begin #################### =head2 get_records Usage : TO DO Purpose : TO DO Returns : nothing Argument : nothing Throws : TODO Comment : See Also : =cut #################### subroutine header end #################### sub get_records { my $self = shift; # set single record $self->{records} = [ { id => 1, ident => $self->{ident} . "fake_rec", } ]; # set fields on the record map { $self->store_field_ref( $_->{zname}, { on_form => 'Y', xmldef => $_->{xmldef}, # set correct ident and record ident => $self->{records}->[0]->{ident}, record => $self->{records}->[0], db_value_record => $_->{db_value_record}, # send through flag to indicate can get user value from this field get_user_values => 'true', } ); } values %{ $self->my_fields() }; } #################### subroutine header begin #################### =head2 output_navigation Usage : $self->output_navigation; Purpose : This method returns the navigation ready for transformation to XML. Returns : a hashref containing navigation. Argument : nothing Throws : nothing Comment : This is a stub as the Login form has no navigation... See Also : =cut #################### subroutine header end #################### sub output_navigation { my $self = shift; return {}; } #################### subroutine header begin #################### =head2 save Usage : $form->save; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : stub as this form has no table associated with it there is nothign to save on it. See Also : =cut #################### subroutine header end #################### sub save { my $self = shift; } #################### subroutine header begin #################### =head2 pre_save Usage : $form->pre_save; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : stub as this form has no table associated with it there is nothign to save on it. See Also : =cut #################### subroutine header end #################### sub pre_save { my $self = shift; } #################### subroutine header begin #################### =head2 my_fields Usage : $form->my_fields; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : See Also : =cut #################### subroutine header end #################### sub my_fields { my $self = shift; # Get the decryptor key statuses. my $decryptor_status = $self->decryptor_client()->call_decryptor( { messagetype => 'Status' }, '', 'nokey' ); Zymonic::Exception::Decryptor::Form::KeyEntry::DecryptorError->throw( extras => $decryptor_status, ) if $decryptor_status->{error}; # Work out which key group the user is in. my $keygroup = $self->{DB}->run_query( { string => 'SELECT keygroup FROM zz_keyholders WHERE username = ? AND (deleted IS NULL OR deleted != \'Y\')', params => [ $self->{auth}->{user} ], } ); # create fields. my %status_fields = (); my $sequence = 1; # Set the key entry field(s) up if ( ref($keygroup) eq 'ARRAY' and scalar( @{$keygroup} ) > 0 ) { foreach my $key ( map { substr( $_, -1 ) } grep { ref( $decryptor_status->{$_} ) and $decryptor_status->{$_}->{present} eq 'Y' } keys( %{$decryptor_status} ) ) { my $zname = 'kpc_' . $key . '_' . $keygroup->[0]->{keygroup}; $status_fields{$zname} = { parent => $self, xmldef => { ZName => { content => $zname }, sequence => $sequence++, DisplayName => { content => 'Part ' . $keygroup->[0]->{keygroup} . ' of Key ' . $key }, FieldGroup => { ZName => { content => 'zz_keyentry' }, }, MaximumLength => { content => '500' }, DisplaySize => { content => '30' }, HiddenContent => { content => 'true' }, }, ident => $self->{ident}, zname => $zname, on_form => 'Y', type => 'Field', }; } } # Status Fields my @field_descs = ( map { { key => $_, zname => 'present_' . $_, displayname => 'Key ' . $_ . ' Present', yesno => 1, }, { key => $_, zname => 'decoded_' . $_, displayname => 'Key ' . $_ . ' Decoded', yesno => 1, }, { key => $_, zname => 'primary_key_' . $_, displayname => 'Key ' . $_ . ' is Primary', yesno => 1, }, { key => $_, zname => 'kek_part_1_last_sent_' . $_, displayname => 'Key ' . $_ . ' Encrypting Key Part 1 Last Sent', }, { key => $_, zname => 'kek_part_2_last_sent_' . $_, displayname => 'Key ' . $_ . ' Encrypting Key Part 2 Last Sent', }, } (qw(a b)) ); foreach (@field_descs) { $status_fields{ $_->{zname} } = { parent => $self, xmldef => { ZName => { content => $_->{zname} }, sequence => $sequence++, DisplayName => { content => $_->{displayname} }, FieldGroup => { ZName => { content => 'zz_keyentry_' . $_->{key} }, }, ReadOnly => { content => 'true' }, ( ( $_->{yesno} ) ? ( class => 'Choice', MaximumLength => { content => '1' }, DisplaySize => { content => '1' }, ClassOptions => { 'Option' => [ { 'Value' => { 'content' => 'Y' }, 'DisplayName' => { 'content' => 'Yes' } }, { 'Value' => { 'content' => 'N' }, 'DisplayName' => { 'content' => 'No' } } ], 'DisplayAs' => { 'content' => 'Buttons' } }, ) : ( MaximumLength => { content => '50' }, DisplaySize => { content => '50' }, ) ), }, ident => $self->{ident}, zname => $_->{zname}, on_form => 'Y', type => 'Field', }; } # Set the values foreach my $zname ( keys(%status_fields) ) { # Skip key entry fields. next if $zname =~ /^kpc/; # Set from decryptor status as db_value_record so value is set when field loaded my $key = substr( $zname, -1 ); my $name = substr( $zname, 0, -2 ); $status_fields{$zname}->{db_value_record} = { $zname => $decryptor_status->{ 'key_' . $key }->{$name} }; } return \%status_fields; } #################### subroutine header begin #################### =head2 decyptor_client Usage : $form->decryptor_client; Purpose : TODO Returns : nothing Argument : nothing Throws : TODO Comment : See Also : =cut #################### subroutine header end #################### sub decryptor_client { my $self = shift; $self->{decryptor_client} = Zymonic::Decryptor::Client->new( parent => $self, config => $self->{config}, db => $self->{DB} ) unless ( defined( $self->{decryptor_client} ) ); return $self->{decryptor_client}; } #################### subroutine header begin #################### =head2 output Usage : print XMLout($form->output); Purpose : This method generates the output for display/further use. Returns : a hashref suitable for conversion to XML. Argument : A flag indicating no display attributes to be sent. Throws : Zymonic::Exception::Form::Validate Comment : See Also : =cut #################### subroutine header end #################### sub output { my $self = shift; $self->get_records; return $self->SUPER::output(@_); } 1;