Upgrade to 4.0.8 with mod of ExternalAuth + absolute paths to ticket-menu.
[usit-rt.git] / share / html / Elements / GnuPG / SignEncryptWidget
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
5%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
13%# This work is made available to you under the terms of Version 2 of
14%# the GNU General Public License. A copy of that license should have
15%# been provided with this software, but in any event can be snarfed
16%# from www.gnu.org.
17%#
18%# This work is distributed in the hope that it will be useful, but
19%# WITHOUT ANY WARRANTY; without even the implied warranty of
20%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21%# General Public License for more details.
22%#
23%# You should have received a copy of the GNU General Public License
24%# along with this program; if not, write to the Free Software
25%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26%# 02110-1301 or visit their web page on the internet at
27%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
32%# (The following paragraph is not intended to limit the rights granted
33%# to you to modify and distribute this software under the terms of
34%# the GNU General Public License and is only of importance to you if
35%# you choose to contribute your changes and enhancements to the
36%# community by submitting them to Best Practical Solutions, LLC.)
37%#
38%# By intentionally submitting any modifications, corrections or
39%# derivatives to this work, or any other work intended for use with
40%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41%# you are the copyright holder for those contributions and you grant
42%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43%# royalty-free, perpetual, license to use, copy, create derivative
44%# works based on those contributions, and sublicense and distribute
45%# those contributions and any derivatives thereof.
46%#
47%# END BPS TAGGED BLOCK }}}
48<table><tr>
49% my $columnsplit = "</td><td>";
50<td><% loc( 'Sign[_1][_2] using [_3]',
51 $columnsplit,
52 $m->scomp('/Widgets/Form/Boolean:InputOnly',
53 Name => 'Sign', CurrentValue => $self->{'Sign'}
54 ),
55 $m->scomp('SelectKeyForSigning', User => $session{'CurrentUser'}->UserObj ),
56) |n %></td>
57
58<td><% loc('Encrypt')%></td>
59<td><& /Widgets/Form/Boolean:InputOnly, Name => 'Encrypt', CurrentValue => $self->{'Encrypt'} &></td>
60</tr></table>
61<%ARGS>
62$self => undef,
63</%ARGS>
64<%INIT>
65return unless $self;
66</%INIT>
67
68<%METHOD new>
69<%ARGS>
70$Arguments => {}
71</%ARGS>
72<%INIT>
73return undef unless RT->Config->Get('GnuPG')->{'Enable'};
74
75require RT::Crypt::GnuPG;
76return { %$Arguments };
77</%INIT>
78</%METHOD>
79
80<%METHOD ShowIssues>
81<%ARGS>
82$self => undef,
83</%ARGS>
84<%INIT>
85return unless $self;
86
87return $m->comp( '/Elements/GnuPG/KeyIssues',
88 Issues => $self->{'GnuPGRecipientsKeyIssues'} || [],
89 SignAddresses => $self->{'GnuPGCanNotSignAs'} || [],
90);
91</%INIT>
92</%METHOD>
93
94
95<%METHOD Process>
96<%ARGS>
97$self => undef
98$QueueObj => undef
99$TicketObj => undef
100</%ARGS>
101<%INIT>
102return unless $self;
103
104$QueueObj ||= $TicketObj->QueueObj if $TicketObj;
105
106foreach ( qw(Sign Encrypt) ) {
107 $self->{ $_ } = $m->comp( '/Widgets/Form/Boolean:Process',
108 Name => $_,
109 DefaultValue => $QueueObj->$_,
110 Arguments => $self,
111 );
112}
113</%INIT>
114</%METHOD>
115
116<%METHOD Check>
117<%ARGS>
118$self => undef
119$Operation => 'Update'
120$TicketObj => undef
121$QueueObj => undef
122</%ARGS>
123<%INIT>
124return 1 unless $self;
125
126my $checks_failure = 0;
127
128if ( $self->{'Sign'} ) {
129 $QueueObj ||= $TicketObj->QueueObj
130 if $TicketObj;
131
dab09ea8
MKG
132 my $private = $session{'CurrentUser'}->UserObj->PrivateKey || '';
133 my $queue = ($self->{'UpdateType'} && $self->{'UpdateType'} eq "private")
84fb5b46
MKG
134 ? ( $QueueObj->CommentAddress || RT->Config->Get('CommentAddress') )
135 : ( $QueueObj->CorrespondAddress || RT->Config->Get('CorrespondAddress') );
136
dab09ea8
MKG
137 my $address = $self->{'SignUsing'} || $queue;
138 if ($address ne $private and $address ne $queue) {
139 push @{ $self->{'GnuPGCanNotSignAs'} ||= [] }, $address;
140 $checks_failure = 1;
141 } elsif ( not RT::Crypt::GnuPG::DrySign( $address ) ) {
84fb5b46
MKG
142 push @{ $self->{'GnuPGCanNotSignAs'} ||= [] }, $address;
143 $checks_failure = 1;
144 } else {
145 RT::Crypt::GnuPG::UseKeyForSigning( $self->{'SignUsing'} )
146 if $self->{'SignUsing'};
147 }
148}
149
150if ( $self->{'Encrypt'} ) {
151
152 my @recipients;
153
154 if ( $Operation eq 'Update' ) {
155 @recipients = $TicketObj->DryRun(%$self)->Recipients;
156 }
157 elsif ( $Operation eq 'Create' ) {
158 $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
159 @recipients = $TicketObj->DryRunCreate(%$self)->Recipients;
160 }
161 else {
162 $RT::Logger->crit('Incorrect operation: '. $Operation );
163 }
164
165 my %seen;
166 @recipients = grep !$seen{ lc $_ }++, @recipients;
167
168 RT::Crypt::GnuPG::UseKeyForEncryption(
169 map { (/^UseKey-(.*)$/)[0] => $self->{ $_ } }
170 grep $self->{ $_ } && /^UseKey-/,
171 keys %$self
172 );
173
174 my ($status, @issues) = RT::Crypt::GnuPG::CheckRecipients( @recipients );
175 push @{ $self->{'GnuPGRecipientsKeyIssues'} ||= [] }, @issues;
176 $checks_failure = 1 unless $status;
177}
178
179return $checks_failure ? 0 : 1;
180</%INIT>
181</%METHOD>