[Logcheck-users] Patch to add gpg support to logcheck.

Mike Mestnik cheako at mikemestnik.net
Sun Feb 10 05:19:15 UTC 2013


Enjoy,
  Based mostly of the man page for mime-construct.

# free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# 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
# if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

===================================================================
RCS file: /usr/sbin/logcheck,v
retrieving revision 1.1
diff -u -r1.1 /usr/sbin/logcheck
--- /usr/sbin/logcheck	2013/02/10 04:17:53	1.1
+++ /usr/sbin/logcheck	2013/02/10 05:11:26
@@ -83,6 +83,7 @@
 LOGCHECKDEBUG=0
 MAILOUT=0
 MAILASATTACH=0
+MAILASGPG=0
 NOCLEANUP=0
 REBOOT=0
 FQDN=0
@@ -174,7 +175,13 @@

 $(export)
 EOF
-	} | eval mime-construct $MIMECONSTRUCTARGS \
+	} | if [ "$MAILASGPG" -eq 1 ]; then
+	  debug "Sending error as gpg"
+	  mime-construct $MIMECONSTRUCTARGS --subpart \
+	  --file - | {
+	    gpg --encrypt --batch --quiet --armor -r "$SENDMAILTO" 2>&1; }
+	else cat; fi |
+	eval mime-construct $MIMECONSTRUCTARGS \
 	    --subject "'Logcheck: $HOSTNAME $DATE exiting due to errors'"
--encoding "7bit" \
         --file - --to "$SENDMAILTO"

@@ -300,12 +307,32 @@
 	debug "Sent report to STDOUT"
     else
 	debug "Sending report: '$subject' to $SENDMAILTO"
-        if [ "$MAILASATTACH" -eq 1 ]; then
-          debug "Sending report as attachment"
-          eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'"
--encoding "7bit" --string "'Report attached'" --to "$SENDMAILTO"
--attachment "logcheck_report" --encoding "7bit" --file "$TMPDIR/report"
-          return $?
-        fi
-        eval mime-construct $MIMECONSTRUCTARGS --subject "'$subject'"
--to "$SENDMAILTO" --encoding "7bit" --file "$TMPDIR/report"
+	if [ "$MAILASGPG" -eq 1 ]; then
+	  debug "Sending error as gpg"
+          if [ "$MAILASATTACH" -eq 1 ]; then
+            debug "Sending report as attachment"
+            mime-construct $MIMECONSTRUCTARGS --subpart --encoding
"7bit" --string "'Report attached'" --attachment "logcheck_report"
--encoding "7bit" --file "$TMPDIR/report"
+	  else
+            eval mime-construct $MIMECONSTRUCTARGS --subpart --encoding
"7bit" --file "$TMPDIR/report"
+          fi | {
+	    gpg --encrypt --batch --quiet --armor -r "$SENDMAILTO" 2>&1; } |
+            eval mime-construct --output \
+               --to "$SENDMAILTO" \
+	       --subject "'$subject'" \
+               --multipart "multipart/encrypted;
protocol=\"application/pgp-encrypted\"" \
+               --type "application/pgp-encrypted" \
+               --string "Version: 1
+" \
+               --type application/octet-stream \
+               --file -
+	else
+          if [ "$MAILASATTACH" -eq 1 ]; then
+            debug "Sending report as attachment"
+            eval mime-construct $MIMECONSTRUCTARGS --subject
"'$subject'" --encoding "7bit" --string "'Report attached'" --to
"$SENDMAILTO" --attachment "logcheck_report" --encoding "7bit" --file
"$TMPDIR/report"
+	  else
+            eval mime-construct $MIMECONSTRUCTARGS --subject
"'$subject'" --to "$SENDMAILTO" --encoding "7bit" --file "$TMPDIR/report"
+          fi
+	fi
     fi
 }

===================================================================
RCS file: /etc/logcheck/logcheck.conf,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /etc/logcheck/logcheck.conf	2012/07/23 03:10:37	1.3
+++ /etc/logcheck/logcheck.conf	2013/02/10 04:21:11	1.4
@@ -33,6 +33,12 @@

 MAILASATTACH=0

+# Send the results as gpg or not.
+# 0=not as gpg; 1=as gpg
+# Default is 0
+
+MAILASGPG=0
+
 # Should the hostname in the subject of generated mails be fully qualified?

 FQDN=1



More information about the Logcheck-users mailing list