View | Details | Raw Unified | Return to bug 8897
Collapse All | Expand All

(-)a/C4/GnuPG.pm (+72 lines)
Line 0 Link Here
1
package C4::GnuPG;
2
3
# Copyright 2012 Mirko Tietgen
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use C4::Context;
23
use Crypt::GPG;
24
25
=head1 C4::GnuPG
26
27
C4::GnuPG
28
29
=head1 Description
30
31
Provides methods to interact with GnuPG via Crypt::GPG for the purpose of encrypting emails to patrons
32
33
=cut
34
35
my $gpg = new Crypt::GPG;
36
$gpg->gpgbin(C4::Context->preference('GnuPGPPath'));
37
$gpg->secretkey(C4::Context->preference('KohaAdminEmailAddress'));
38
$gpg->passphrase(C4::Context->preference('GnuPGPassphrase'));
39
40
=head2 encrypt
41
42
Take email content and patron's email address, send back encrypted content. Call like
43
44
$content = C4::GnuPG->encrypt($content, $patronemail);
45
46
=cut
47
48
sub encrypt {
49
    my ($self, $content, $patronemail) = @_;
50
    $content = $gpg->encrypt($content, $patronemail);
51
    return $content;
52
}
53
54
=head2 does_exist
55
56
Check if there is a GnuPG key for the patron's email address. Call like
57
58
if ( C4::GnuPG->does_exist($useremail) = 1 ) {
59
    # … encrypt …
60
}
61
62
=cut
63
64
sub does_exist {
65
    my ($self, $patronemail) = @_;
66
    if ( $gpg->keydb($patronemail) ) {
67
        return 1;
68
    }
69
    else {
70
        return 0;
71
    }
72
}
(-)a/C4/Letters.pm (+7 lines)
Lines 33-38 use Date::Calc qw( Add_Delta_Days ); Link Here
33
use Encode;
33
use Encode;
34
use Unicode::Normalize;
34
use Unicode::Normalize;
35
use Carp;
35
use Carp;
36
use C4::GnuPG;
36
37
37
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38
39
Lines 782-787 sub EnqueueLetter { Link Here
782
        );
783
        );
783
    }
784
    }
784
785
786
    # gnupg encrypt content if encryption enabled and key for patron present
787
    my $useremail = $params->{'to_address'};
788
    if ( (C4::Context->preference("GnuPGPassphrase")) && (C4::Context->preference("GnuPGPassphrase") ne '') && (C4::GnuPG->does_exist($params->{'to_address'}) == 1) ) {
789
        $params->{'letter'}->{'content'} = C4::GnuPG->encrypt($params->{'letter'}->{'content'}, $params->{'to_address'});
790
    }
791
785
    my $dbh       = C4::Context->dbh();
792
    my $dbh       = C4::Context->dbh();
786
    my $statement = << 'ENDSQL';
793
    my $statement = << 'ENDSQL';
787
INSERT INTO message_queue
794
INSERT INTO message_queue
(-)a/C4/Message.pm (+5 lines)
Lines 25-30 use C4::Context; Link Here
25
use C4::Letters;
25
use C4::Letters;
26
use YAML::Syck;
26
use YAML::Syck;
27
use Carp;
27
use Carp;
28
use C4::GnuPG;
28
29
29
=head1 NAME
30
=head1 NAME
30
31
Lines 322-327 sub append { Link Here
322
    push @{$metadata->{body}}, $item;
323
    push @{$metadata->{body}}, $item;
323
    $self->metadata($metadata);
324
    $self->metadata($metadata);
324
    my $new_content = $self->render_metadata($format);
325
    my $new_content = $self->render_metadata($format);
326
    # gnupg encrypt content if encryption enabled and key for patron present
327
    if ( (C4::Context->preference("GnuPGPassphrase")) && (C4::Context->preference("GnuPGPassphrase") ne '') && (C4::GnuPG->does_exist($self->{'to_address'}) == 1) ) {
328
        $new_content = C4::GnuPG->encrypt($new_content, $self->{'to_address'})
329
    }
325
    return $self->content($new_content);
330
    return $self->content($new_content);
326
}
331
}
327
332
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 388-390 INSERT INTO systempreferences (variable, value, options, explanation, type) VALU Link Here
388
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer');
388
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer');
389
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('alphabet','A B C D E F G H I J K L M N O P Q R S T U V W X Y Z','Alphabet than can be expanded into browse links, e.g. on Home > Patrons',NULL,'free');
389
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('alphabet','A B C D E F G H I J K L M N O P Q R S T U V W X Y Z','Alphabet than can be expanded into browse links, e.g. on Home > Patrons',NULL,'free');
390
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RefundLostItemFeeOnReturn', '1', 'If enabled, the lost item fee charged to a borrower will be refunded when the lost item is returned.', NULL, 'YesNo');
390
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RefundLostItemFeeOnReturn', '1', 'If enabled, the lost item fee charged to a borrower will be refunded when the lost item is returned.', NULL, 'YesNo');
391
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPath','/usr/bin/gpg','Path to GnuPG','','free');
392
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPassphrase','','Passphrase for GnuPG','','free');
(-)a/installer/data/mysql/updatedatabase.pl (+8 lines)
Lines 6134-6139 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
6134
    SetVersion ($DBversion);
6134
    SetVersion ($DBversion);
6135
}
6135
}
6136
6136
6137
$DBversion = 'XXX';
6138
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
6139
   $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPath','/usr/bin/gpg','Path to GnuPG','','free');");
6140
   $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPassphrase','','Passphrase for GnuPG','','free');");
6141
   print "Upgrade to $DBversion done (Add GnuPGPath and GnuPGPassphrase sysprefs)\n";
6142
   SetVersion ($DBversion);
6143
}
6144
6137
=head1 FUNCTIONS
6145
=head1 FUNCTIONS
6138
6146
6139
=head2 TableExists($table)
6147
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (-1 / +8 lines)
Lines 40-45 Administration: Link Here
40
                  yes: Allow
40
                  yes: Allow
41
                  no: "Don't allow"
41
                  no: "Don't allow"
42
            - staff and patrons to create and view saved lists of books.
42
            - staff and patrons to create and view saved lists of books.
43
        -
44
            - GnuPG passphrase used to encrypt outgoing emails from KohaAdminEmailAddress. Leave blank to disable encryption. You must have GnuPG running and a keypair setup for KohaAdminEmailAddress to use this.
45
            - pref: GnuPGPassphrase
46
              class: password
47
        -
48
            - Path to GnuPG
49
            - pref: GnuPGPath
50
            - class: textarea
43
    Login options:
51
    Login options:
44
        -
52
        -
45
            - pref: insecure
53
            - pref: insecure
46
- 

Return to bug 8897