From c12d1b2bd8fa58f2dd4fffa17f31d71669d39605 Mon Sep 17 00:00:00 2001 From: Mirko Tietgen Date: Sun, 21 Oct 2012 21:26:44 +0200 Subject: [PATCH] Bug 8897 [ENH] Optional GnuPG encryption of outgoing emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enhancement allows GnuPG encryption of emails sent by Koha. Initial patch with some basic functionality. TODO: key management, attachments … --- C4/Letters.pm | 7 +++++++ C4/Message.pm | 5 +++++ installer/data/mysql/sysprefs.sql | 2 ++ installer/data/mysql/updatedatabase.pl | 8 ++++++++ .../prog/en/modules/admin/preferences/admin.pref | 8 ++++++++ 5 files changed, 30 insertions(+), 0 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index f646241..4333bad 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -33,6 +33,7 @@ use Date::Calc qw( Add_Delta_Days ); use Encode; use Unicode::Normalize; use Carp; +use C4::GnuPG; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -782,6 +783,12 @@ sub EnqueueLetter { ); } + # gnupg encrypt content if encryption enabled and key for patron present + my $useremail = $params->{'to_address'}; + if ( (C4::Context->preference("GnuPGPassphrase")) && (C4::Context->preference("GnuPGPassphrase") ne '') && (C4::GnuPG->does_exist($params->{'to_address'}) == 1) ) { + $params->{'letter'}->{'content'} = C4::GnuPG->encrypt($params->{'letter'}->{'content'}, $params->{'to_address'}); + } + my $dbh = C4::Context->dbh(); my $statement = << 'ENDSQL'; INSERT INTO message_queue diff --git a/C4/Message.pm b/C4/Message.pm index a63b3ca..5b3caff 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -25,6 +25,7 @@ use C4::Context; use C4::Letters; use YAML::Syck; use Carp; +use C4::GnuPG; =head1 NAME @@ -322,6 +323,10 @@ sub append { push @{$metadata->{body}}, $item; $self->metadata($metadata); my $new_content = $self->render_metadata($format); + # gnupg encrypt content if encryption enabled and key for patron present + if ( (C4::Context->preference("GnuPGPassphrase")) && (C4::Context->preference("GnuPGPassphrase") ne '') && (C4::GnuPG->does_exist($self->{'to_address'}) == 1) ) { + $new_content = C4::GnuPG->encrypt($new_content, $self->{'to_address'}) + } return $self->content($new_content); } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index a4fceea..a139fa0 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -386,3 +386,5 @@ INSERT INTO systempreferences (variable,value,explanation,type) VALUES('OPACdidy INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdidyoumean',NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'); INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo'); 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'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPath','/usr/bin/gpg','Path to GnuPG','','free'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPassphrase','','Passphrase for GnuPG','','free'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e67bf3e..73847c2 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6011,6 +6011,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = 'XXX'; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPath','/usr/bin/gpg','Path to GnuPG','','free');"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GnuPGPassphrase','','Passphrase for GnuPG','','free');"); + print "Upgrade to $DBversion done (Add GnuPGPath and GnuPGPassphrase sysprefs)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index 4e907e1..c4db4be 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -40,6 +40,14 @@ Administration: yes: Allow no: "Don't allow" - staff and patrons to create and view saved lists of books. + - + - 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. + - pref: GnuPGPassphrase + class: password + - + - Path to GnuPG + - pref: GnuPGPath + - class: textarea Login options: - - pref: insecure -- 1.7.2.5