Commit e22c5ea8 authored by Martin Kammerlander's avatar Martin Kammerlander
Browse files

Merge with Neilpang dev repo.

parents 16bfb172 eb623878
#!/usr/bin/env sh
#Support SENDGRID.com api
#SENDGRID_API_KEY=""
#SENDGRID_TO="xxxx@xxx.com"
#SENDGRID_FROM="xxxx@cccc.com"
sendgrid_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode"
SENDGRID_API_KEY="${SENDGRID_API_KEY:-$(_readaccountconf_mutable SENDGRID_API_KEY)}"
if [ -z "$SENDGRID_API_KEY" ]; then
SENDGRID_API_KEY=""
_err "You didn't specify a sendgrid api key SENDGRID_API_KEY yet ."
_err "You can get yours from here https://sendgrid.com"
return 1
fi
_saveaccountconf_mutable SENDGRID_API_KEY "$SENDGRID_API_KEY"
SENDGRID_TO="${SENDGRID_TO:-$(_readaccountconf_mutable SENDGRID_TO)}"
if [ -z "$SENDGRID_TO" ]; then
SENDGRID_TO=""
_err "You didn't specify an email to SENDGRID_TO receive messages."
return 1
fi
_saveaccountconf_mutable SENDGRID_TO "$SENDGRID_TO"
SENDGRID_FROM="${SENDGRID_FROM:-$(_readaccountconf_mutable SENDGRID_FROM)}"
if [ -z "$SENDGRID_FROM" ]; then
SENDGRID_FROM=""
_err "You didn't specify an email to SENDGRID_FROM receive messages."
return 1
fi
_saveaccountconf_mutable SENDGRID_FROM "$SENDGRID_FROM"
export _H1="Authorization: Bearer $SENDGRID_API_KEY"
export _H2="Content-Type: application/json"
_content="$(echo "$_content" | _json_encode)"
_data="{\"personalizations\": [{\"to\": [{\"email\": \"$SENDGRID_TO\"}]}],\"from\": {\"email\": \"$SENDGRID_FROM\"},\"subject\": \"$_subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$_content\"}]}"
response="$(_post "$_data" "https://api.sendgrid.com/v3/mail/send")"
if [ "$?" = "0" ] && [ -z "$response" ]; then
_info "sendgrid send sccess."
return 0
fi
_err "sendgrid send error."
_err "$response"
return 1
}
#!/usr/bin/env sh
#Support Slack webhooks
#SLACK_WEBHOOK_URL=""
#SLACK_CHANNEL=""
#SLACK_USERNAME=""
slack_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode"
SLACK_WEBHOOK_URL="${SLACK_WEBHOOK_URL:-$(_readaccountconf_mutable SLACK_WEBHOOK_URL)}"
if [ -z "$SLACK_WEBHOOK_URL" ]; then
SLACK_WEBHOOK_URL=""
_err "You didn't specify a Slack webhook url SLACK_WEBHOOK_URL yet."
return 1
fi
_saveaccountconf_mutable SLACK_WEBHOOK_URL "$SLACK_WEBHOOK_URL"
SLACK_CHANNEL="${SLACK_CHANNEL:-$(_readaccountconf_mutable SLACK_CHANNEL)}"
if [ -n "$SLACK_CHANNEL" ]; then
_saveaccountconf_mutable SLACK_CHANNEL "$SLACK_CHANNEL"
fi
SLACK_USERNAME="${SLACK_USERNAME:-$(_readaccountconf_mutable SLACK_USERNAME)}"
if [ -n "$SLACK_USERNAME" ]; then
_saveaccountconf_mutable SLACK_USERNAME "$SLACK_USERNAME"
fi
export _H1="Content-Type: application/json"
_content="$(printf "*%s*\n%s" "$_subject" "$_content" | _json_encode)"
_data="{\"text\": \"$_content\", "
if [ -n "$SLACK_CHANNEL" ]; then
_data="$_data\"channel\": \"$SLACK_CHANNEL\", "
fi
if [ -n "$SLACK_USERNAME" ]; then
_data="$_data\"username\": \"$SLACK_USERNAME\", "
fi
_data="$_data\"mrkdwn\": \"true\"}"
if _post "$_data" "$SLACK_WEBHOOK_URL"; then
# shellcheck disable=SC2154
if [ "$response" = "ok" ]; then
_info "slack send success."
return 0
fi
fi
_err "slack send error."
_err "$response"
return 1
}
#!/usr/bin/env sh
# support smtp
smtp_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_subject" "$_subject"
_debug "_content" "$_content"
_debug "_statusCode" "$_statusCode"
_err "Not implemented yet."
return 1
}
#!/usr/bin/env sh
#Support xmpp via sendxmpp
#XMPP_BIN="/usr/bin/sendxmpp"
#XMPP_BIN_ARGS="-n -t --tls-ca-path=/etc/ssl/certs"
#XMPP_TO="zzzz@example.com"
xmpp_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_subject" "$_subject"
_debug "_content" "$_content"
_debug "_statusCode" "$_statusCode"
XMPP_BIN="${XMPP_BIN:-$(_readaccountconf_mutable XMPP_BIN)}"
if [ -n "$XMPP_BIN" ] && ! _exists "$XMPP_BIN"; then
_err "It seems that the command $XMPP_BIN is not in path."
return 1
fi
_XMPP_BIN=$(_xmpp_bin)
if [ -n "$XMPP_BIN" ]; then
_saveaccountconf_mutable XMPP_BIN "$XMPP_BIN"
else
_clearaccountconf "XMPP_BIN"
fi
XMPP_BIN_ARGS="${XMPP_BIN_ARGS:-$(_readaccountconf_mutable XMPP_BIN_ARGS)}"
if [ -n "$XMPP_BIN_ARGS" ]; then
_saveaccountconf_mutable XMPP_BIN_ARGS "$XMPP_BIN_ARGS"
else
_clearaccountconf "XMPP_BIN_ARGS"
fi
XMPP_TO="${XMPP_TO:-$(_readaccountconf_mutable XMPP_TO)}"
if [ -n "$XMPP_TO" ]; then
if ! _xmpp_valid "$XMPP_TO"; then
_err "It seems that the XMPP_TO=$XMPP_TO is not a valid xmpp address."
return 1
fi
_saveaccountconf_mutable XMPP_TO "$XMPP_TO"
fi
result=$({ _xmpp_message | eval "$(_xmpp_cmnd)"; } 2>&1)
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
_debug "xmpp send error."
_err "$result"
return 1
fi
_debug "xmpp send success."
return 0
}
_xmpp_bin() {
if [ -n "$XMPP_BIN" ]; then
_XMPP_BIN="$XMPP_BIN"
elif _exists "sendxmpp"; then
_XMPP_BIN="sendxmpp"
else
_err "Please install sendxmpp first."
return 1
fi
echo "$_XMPP_BIN"
}
_xmpp_cmnd() {
case $(basename "$_XMPP_BIN") in
sendxmpp)
echo "'$_XMPP_BIN' '$XMPP_TO' $XMPP_BIN_ARGS"
;;
*)
_err "Command $XMPP_BIN is not supported, use sendxmpp."
return 1
;;
esac
}
_xmpp_message() {
echo "$_subject"
}
_xmpp_valid() {
_contains "$1" "@"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment