RSS

LuxCal Forum

The place for questions, suggestions and news about the LuxCal Event Calendar

User:   Password:   Remember Me?   
LuxCal Forum / LuxCal / Comments and Suggestions / Notification Email Encryption with PHP / GNU Privacy Guard (GPG) during CronJob
Posted:  02 Nov 2015 00:16
How would I redirect the output of the event notification emails produced during a cron job to a php script that would use GNU Privacy Guard (GPG) encryption to encrypt the message before it is mailed out? I would like to load the encryption key in a subdirectory in the LuxCal directory.
Posted:  02 Nov 2015 03:10   Last Edited By: Roel B.
I found some code that appears to be applicable to modify the notify.php script with to incorporate notification encryption. The code is from an online version of the PHP Cookbook snippet at http://docstore.mik.ua/orelly/webprog/pcook/ch14_12.htm

$msgText = escapeshellarg($msgText);
$gpg_path     = '/usr/local/bin/gpg';
$sender       = 'web@example.com';
$recipient    = 'notificationcecipient@example.com';
$home_dir     = '/home/web';
$user_env     = 'web';

$cmd = "echo $msgText | HOME=$home_dir USER=$user_env $gpg_path " .
       '--quiet --no-secmem-warning --encrypt --sign --armor ' .
       "--recipient $recipient --local-user $sender";

$msgText = `$cmd`;

mail($recipient,'Web Site Order',$msgText);

Not being a programmer myself I am not sure how to make the modifications to the notify script to build in this code snippet.  Anybody done this already?

Thanks in advance,
Mark L Saginaw, Michigan
Posted:  02 Nov 2015 04:15   Last Edited By: Roel B.
Is this excerpt from notify.php the correct place to insert the GPG code?

//send notification
$sender = $set['notifSender'] ? $evt['uid'] : 0;

?? Can that GPG code snippet be worked in at this point before sendmail is used to launch the notification ??

$sent = sendMail($subject, $msgText, $evt['rml'], $sender);
$sentTo = $sent ? "{$sent} - {$ax['cro_subject']}: {$subject}" : "Sending mail failed. See logs/luxcal.log for details";
return $sentTo;

Is the following the correct modification of the notify.php script?

..
..
..

//send notification
$sender = $set['notifSender'] ? $evt['uid'] : 0;

// Insert GPG Snippet -START

$msgText = escapeshellarg($msgText);
$gpg_path     = '/usr/bin/gpg';
$sender       = $sender // was  'luxcaladmin@example.com';
$recipient    = $evt['rml']  // was 'notificationrecipient@example.com';
$home_dir     = '../gpg/sender/';  // location of secring.gpg key private key belonging to $sender
$user_env     = '../gpg/recipient/';  // location of public key belonging to $recipient

$cmd = "echo $msgText | HOME=$home_dir USER=$user_env $gpg_path " .
       '--quiet --no-secmem-warning --encrypt --sign --armor ' .
       "--recipient $recipient --local-user $sender";

$msgText = `$cmd`;

// Insert GPG Snippet -END
//
// Resume notify.php code

$sent = sendMail($subject, $msgText, $evt['rml'], $sender);
$sentTo = $sent ? "{$sent} - {$ax['cro_subject']}: {$subject}" : "Sending mail failed. See logs/luxcal.log for details";
return $sentTo;

...
...
...
Posted:  02 Nov 2015 07:59   Last Edited By: Roel B.
I hacked away at notify.php and came up with a working script modification. The notification email that is sent has
Subject line: Notification -Privacy

While the body of the message is encrypted:

-----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.10 (GNU/Linux)
...
...
hQIOAwjkEYFMHg3SEAf+PO07Q3n4AESMOsE9X8sMl8fmoJI6nX/GanTj9W+YxZux
....
...
...
-----END PGP MESSAGE-----

notify.php script mod as follows:

...
...
...
//send notification
$sender = $set['notifSender'] ? $evt['uid'] : 0;

// Insert GPG Snippet -START

$msgText = escapeshellarg($msgText);
$gpg_path     = '/usr/bin/gpg';
$gpg_sender   = 'admin@example.net';
$recipient    = $evt['rml'];
$home_dir     = '/kunden/homepages/14/d9/htdocs/';
$user_env     = '/kunden/homepages/14/d9/htdocs/';

$cmd = "echo $msgText | HOME=$home_dir USER=$user_env $gpg_path " .
       '--quiet --no-secmem-warning --encrypt --sign --armor ' .
       "--recipient $recipient --local-user $gpg_sender";

$msgText = `$cmd`;

// Insert GPG Snippet -END
//
// Resume with modified notify.php code

    $sent = sendMail("Notification -Privacy", $msgText, $evt['rml'], $sender);

// Resume original notify.php code

    $sentTo = $sent ? "{$sent} - {$ax['cro_subject']}: {$subject}" : "Sending mail failed. See logs/luxcal.log for details";
    return $sentTo;

...
...
...

Mark L Saginaw Michigan