Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GnuPG.html « Tools « Admin « html « share - github.com/bestpractical/rt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc501e8e1fa36d3ffaef7dd6e08e6d802fdf3cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
%# BEGIN BPS TAGGED BLOCK {{{
%#
%# COPYRIGHT:
%#
%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
%#                                          <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
%#
%#
%# LICENSE:
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
%#
%#
%# CONTRIBUTION SUBMISSION POLICY:
%#
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%#
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
<& /Admin/Elements/Header, Title => $title &>
<& /Elements/Tabs &>

<& /Elements/ListActions &>


<form action="<% RT->Config->Get('WebPath')%>/Admin/Tools/GnuPG.html" name="ImportKeys" method="POST" enctype="multipart/form-data" class="mx-auto max-width-lg">
<&|/Widgets/TitleBox, title => loc('Import Keys'), content_class => 'mx-auto width-md' &>
% my %options = RT->Config->Get('GnuPGOptions');
% if ( $options{'keyserver'} ) {
  <&| /Elements/LabeledValue, Label => '' &>
  <div class="input-group">
      <input name="Query" class="form-control" value="<% $ARGS{Query} // '' %>" size="40" />
      <input name="Search" type="submit" class="button btn btn-primary" value="<&|/l&>Search</&>" />
  </&>
% if ( @search_results ) {
  <&| /Elements/LabeledValue, Label => '' &>
      <div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input checkbox" id="KeyAll" name="KeyAll" value="1" onclick="setCheckbox(this, 'Key')" />
        <label class="custom-control-label" for="KeyAll"><&|/l&>Check All</&></label>
      </div>
  </&>
% for my $item ( @search_results ) {
  <&| /Elements/LabeledValue, Label => loc("Key") &>
      <div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input checkbox" id="Key-<% $item->{Key} %>" name="Key" value="<% $item->{Key} %>" />
        <label class="custom-control-label" for="Key-<% $item->{Key} %>"><% $item->{Summary} %></label>
      </div>
  </&>
% }
% }

% }

  <&| /Elements/LabeledValue, Label => loc("Content") &>
      <textarea class="form-control" name="Content" rows="8"><% $ARGS{Content} // '' %></textarea>
  </&>
  <div class="form-row">
    <div class="col-12">
      <& /Elements/Submit, Name => 'Import', Label => loc('Import') &>
    </div>
  </div>
</&>
</form>

<&|/Widgets/TitleBox, title => loc('GnuPG Public Keys') &>

% if ( $public{info} && @{$public{info}} ) {
<form action="<% RT->Config->Get('WebPath')%>/Admin/Tools/GnuPG.html" name="PublicKeys" method="POST" enctype="multipart/form-data">
    <table class="table collection-as-table">
        <tr>
            <th>
              <div class="custom-control custom-checkbox">
                <input type="checkbox" name="PublicKeyAll" value="1" id="PublicKeyAll" class="checkbox custom-control-input" onclick="setCheckbox(this, 'PublicKey')" />
                <label class="custom-control-label" for="PublicKeyAll"></label>
              </div>
            </th>
            <th><% loc('Summary') %></th>
            <th><% loc('Trust Level') %></th>
        </tr>
% for my $item ( @{$public{info}} ) {
        <tr>
            <td>
              <div class="custom-control custom-checkbox">
                <input type="checkbox" name="PublicKey" id="PublicKey-<% $item->{Fingerprint} %>" value="<% $item->{Fingerprint} %>" class="checkbox custom-control-input" <% $delete{$item->{Fingerprint}} ? 'checked="checked"' : '' |n %> />
                <label class="custom-control-label" for="PublicKey-<% $item->{Fingerprint} %>"></label>
              </div>
            </td>
            <td><% $item->{Formatted} %></td>
            <td><% $owner_trust_level{$item->{OwnerTrustChar}} || loc('Not set') %></td>
        </tr>
% }
    </table>
    <hr />

    <div class="form-row">
      <div class="label col-3">
        <% loc('Trust Level' ) %>:
      </div>
      <div class="input-group col-6">
        <select name="OwnerTrustLevel" class="form-control selectpicker">
            <option value=""  <% $OwnerTrustLevel eq '' ? 'selected="selected"' : '' |n %> >-</option>
            <option value="1" <% $OwnerTrustLevel eq 1 ? 'selected="selected"' : '' |n %> ><% $owner_trust_level{1} %></option>
            <option value="2" <% $OwnerTrustLevel eq 2 ? 'selected="selected"' : '' |n %> ><% $owner_trust_level{2} %></option>
            <option value="3" <% $OwnerTrustLevel eq 3 ? 'selected="selected"' : '' |n %> ><% $owner_trust_level{3} %></option>
            <option value="4" <% $OwnerTrustLevel eq 4 ? 'selected="selected"' : '' |n %> ><% $owner_trust_level{4} %></option>
            <option value="5" <% $OwnerTrustLevel eq 5 ? 'selected="selected"' : '' |n %> ><% $owner_trust_level{5} %></option>
        </select>
      </div>
    </div>

    <div class="form-row">
      <div class="col-12">
        <& /Elements/Submit, Label => loc('Delete'), Name => 'DeletePublic', CheckboxNameRegex => '/^PublicKey(All)?$/', CheckAll => 1, ClearAll => 1 &>
        <& /Elements/Submit, Label => loc('Save Changes'), Name => 'TrustPublic' &>
      </div>
    </div>
</form>
% } else {
<p class="mt-3 mb-1 ml-3"><&|/l&>No public keys found.</&></p>
% }

</&>

<&|/Widgets/TitleBox, title => loc('GnuPG Private Keys') &>

% if ( $private{info} && @{$private{info}} ) {
<form action="<% RT->Config->Get('WebPath')%>/Admin/Tools/GnuPG.html" name="PrivateKeys" method="POST" enctype="multipart/form-data">
    <table class="table collection-as-table">
        <tr>
            <th>
              <div class="custom-control custom-checkbox">
                <input type="checkbox" name="PrivateKeyAll" value="1" id="PrivateKeyAll" class="checkbox custom-control-input" onclick="setCheckbox(this, 'PrivateKey')" />
                <label class="custom-control-label" for="PrivateKeyAll"></label>
              </div>
            <th><% loc('Summary') %></th>
        </tr>
% for my $item ( @{$private{info}} ) {
        <tr>
            <td>
              <div class="custom-control custom-checkbox">
                <input type="checkbox" name="PrivateKey" id="PrivateKey-<% $item->{Fingerprint} %>" value="<% $item->{Fingerprint} %>" class="checkbox custom-control-input" <% $delete{$item->{Fingerprint}} ? 'checked="checked"' : '' |n %> />
                <label class="custom-control-label" for="PrivateKey-<% $item->{Fingerprint} %>"></label>
              </div>
            </td>
            <td><% $item->{Formatted} %></td>
        </tr>
% }
    </table>
    <hr />
    <div class="form-row">
      <div class="col-12">
        <& /Elements/Submit, Label => loc('Delete'), Name => 'DeletePrivate', CheckboxNameRegex => '/^PrivateKey(All)?$/', CheckAll => 1, ClearAll => 1 &>
      </div>
    </div>
</form>
% } else {
<p class="mt-3 mb-1 ml-3"><&|/l&>No private keys found.</&></p>
% }

</&>
<%INIT>

my $title = loc('Manage GnuPG Keys');
unless ( $session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'SuperUser' ) ) {
    Abort( loc('This feature is only available to system administrators.') );
}

my @results;
my %delete;

my %owner_trust_level = (
    1 => loc("I don't know or won't say"),
    2 => loc("I do NOT trust"),
    3 => loc("I trust marginally"),
    4 => loc("I trust fully"),
    5 => loc("I trust ultimately"),

    q => loc("I don't know or won't say"),
    n => loc("I do NOT trust"),
    m => loc("I trust marginally"),
    f => loc("I trust fully"),
    u => loc("I trust ultimately"),
);

require RT::Crypt::GnuPG;

my @search_results;
if ( $ARGS{Search} ) {
    if ( $ARGS{Query} ) {
        my %ret = RT::Crypt::GnuPG->SearchKey( $ARGS{Query} );
        @search_results = @{$ret{results}};
        push @results, split /\n+/, $ret{logger} unless @search_results;
    }
}
elsif ( $ARGS{Import} ) {

    # show admin detailed imported messages
    if ( $ARGS{Key} ) {
        for my $key ( ref $ARGS{Key} ? @{ $ARGS{Key} } : $ARGS{Key} ) {
            my %ret = RT::Crypt::GnuPG->ReceiveKey( $key );
            push @results, split /\n+/, $ret{logger};
        }
    }

    if ( $ARGS{Content} ) {
        my %ret = RT::Crypt::GnuPG->ImportKey( $ARGS{Content} );
        push @results, split /\n+/, $ret{logger};
    }
}
elsif ( $ARGS{TrustPublic} ) {
    if ( length $ARGS{OwnerTrustLevel} && $ARGS{PublicKey} ) {
        for my $key ( ref $ARGS{PublicKey} ? @{ $ARGS{PublicKey} } : $ARGS{PublicKey} ) {
            my %ret = RT::Crypt::GnuPG->TrustKey( $key, $ARGS{OwnerTrustLevel} );
            if ( $ret{exit_code} == 0 ) {
                if ( $ret{logger} ) {

                    # success messages are like "changing ownertrust
                    # from 6 to 4", which is useless and misleading to
                    # end users, so we hide them here.

                    RT->Logger->debug( $ret{logger} );
                    push @results, loc( "Key [_1] trust level is updated", substr( $key, -8 ) );
                }
            }
            elsif ( $ret{logger} ) {
                push @results, split /\n+/, $ret{logger};
            }
        }
    }
}
else {
    for my $type (qw/Public Private/) {
        next unless $ARGS{"Delete$type"};
        my $value = $ARGS{"${type}Key"};
        for my $key ( ref $value ? @$value : $value ) {
            $delete{$key} ||= 1;
            my %ret = RT::Crypt::GnuPG->DeleteKey($key);

            if ( $ret{exit_code} == 0 ) {
                # delete is silent, no extra debug messages
                push @results, loc( "Key [_1] is deleted", substr( $key, -8 ) );
            }
            elsif ( $ret{logger} ) {
                push @results, split /\n+/, $ret{logger};
            }
        }
    }
}

MaybeRedirectForResults(
    Actions => \@results,
    Path    => '/Admin/Tools/GnuPG.html',
);

my %public = RT::Crypt::GnuPG->GetKeysInfo( Force => 1 );
my %private = RT::Crypt::GnuPG->GetKeysInfo( Force => 1, Type => 'private' );

</%INIT>

<%ARGS>
$OwnerTrustLevel => ''
</%ARGS>