git » kxd » commit 3de6bbd

scripts: Add an example hook

author Alberto Bertogli
2017-09-17 21:14:03 UTC
committer Alberto Bertogli
2017-09-17 21:15:12 UTC
parent 6182dc8fea87e5005b6f2b837572ed997810645f

scripts: Add an example hook

This patch adds an example hook, which uses the system's sendmail to
send email notifications.

It uses most (if not all) variables, and is also useful when kxd's
internal email sending is not enough (e.g. there's a need for
authentication, or you don't have a MTA).

scripts/hook +30 -0

diff --git a/scripts/hook b/scripts/hook
new file mode 100755
index 0000000..e114470
--- /dev/null
+++ b/scripts/hook
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# Example kxd hook, which uses the system's sendmail to send a notification
+# via email.
+#
+# Note that if the script fails, kxd will NOT send the key.
+#
+
+echo "Date: $(date --rfc-2822)
+From: $MAIL_FROM
+To: $EMAIL_TO
+Subject: Access to key $KEY_PATH
+
+Key: $KEY_PATH
+Accessed by: $REMOTE_ADDR
+On: $(date)
+
+Client certificate:
+  Signature: ${CLIENT_CERT_SIGNATURE:0:40}...
+  Subject: $CLIENT_CERT_SUBJECT
+
+Authorizing chains:
+  $CHAIN_0
+  $CHAIN_1
+  $CHAIN_2
+
+" | sendmail -t
+
+exit $?
+