commit
0accdb9e34
@ -1,4 +1,6 @@
|
||||
# How to use DNS API
|
||||
DNS api usage:
|
||||
|
||||
https://github.com/Neilpang/acme.sh/wiki/dnsapi
|
||||
|
||||
https://github.com/Neilpang/acme.sh/wiki/dnsapi
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#Nsd_ZoneFile="/etc/nsd/zones/example.com.zone"
|
||||
#Nsd_Command="sudo nsd-control reload"
|
||||
|
||||
# args: fulldomain txtvalue
|
||||
dns_nsd_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
ttlvalue=300
|
||||
|
||||
Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
|
||||
Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
|
||||
|
||||
# Arg checks
|
||||
if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then
|
||||
Nsd_ZoneFile=""
|
||||
Nsd_Command=""
|
||||
_err "Specify ENV vars Nsd_ZoneFile and Nsd_Command"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$Nsd_ZoneFile" ]; then
|
||||
Nsd_ZoneFile=""
|
||||
Nsd_Command=""
|
||||
_err "No such file: $Nsd_ZoneFile"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile"
|
||||
_savedomainconf Nsd_Command "$Nsd_Command"
|
||||
|
||||
echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile"
|
||||
_info "Added TXT record for $fulldomain"
|
||||
_debug "Running $Nsd_Command"
|
||||
if eval "$Nsd_Command"; then
|
||||
_info "Successfully updated the zone"
|
||||
return 0
|
||||
else
|
||||
_err "Problem updating the zone"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# args: fulldomain txtvalue
|
||||
dns_nsd_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
ttlvalue=300
|
||||
|
||||
Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
|
||||
Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
|
||||
|
||||
sed -i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile"
|
||||
_info "Removed TXT record for $fulldomain"
|
||||
_debug "Running $Nsd_Command"
|
||||
if eval "$Nsd_Command"; then
|
||||
_info "Successfully reloaded NSD "
|
||||
return 0
|
||||
else
|
||||
_err "Problem reloading NSD"
|
||||
return 1
|
||||
fi
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env sh
|
||||
# -*- mode: sh; tab-width: 2; indent-tabs-mode: s; coding: utf-8 -*-
|
||||
|
||||
# one.com ui wrapper for acme.sh
|
||||
# Author: github: @diseq
|
||||
# Created: 2019-02-17
|
||||
#
|
||||
# export ONECOM_User="username"
|
||||
# export ONECOM_Password="password"
|
||||
#
|
||||
# Usage:
|
||||
# acme.sh --issue --dns dns_one -d example.com
|
||||
#
|
||||
# only single domain supported atm
|
||||
|
||||
dns_one_add() {
|
||||
mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev)
|
||||
mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev)
|
||||
txtvalue=$2
|
||||
|
||||
# get credentials
|
||||
ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
|
||||
ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
|
||||
if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then
|
||||
ONECOM_User=""
|
||||
ONECOM_Password=""
|
||||
_err "You didn't specify a one.com username and password yet."
|
||||
_err "Please create the key and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
#save the api key and email to the account conf file.
|
||||
_saveaccountconf_mutable ONECOM_User "$ONECOM_User"
|
||||
_saveaccountconf_mutable ONECOM_Password "$ONECOM_Password"
|
||||
|
||||
# Login with user and password
|
||||
postdata="loginDomain=true"
|
||||
postdata="$postdata&displayUsername=$ONECOM_User"
|
||||
postdata="$postdata&username=$ONECOM_User"
|
||||
postdata="$postdata&targetDomain=$mydomain"
|
||||
postdata="$postdata&password1=$ONECOM_Password"
|
||||
postdata="$postdata&loginTarget="
|
||||
#_debug postdata "$postdata"
|
||||
|
||||
response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")"
|
||||
#_debug response "$response"
|
||||
|
||||
JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')"
|
||||
_debug jsessionid "$JSESSIONID"
|
||||
|
||||
export _H1="Cookie: ${JSESSIONID}"
|
||||
|
||||
# get entries
|
||||
response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")"
|
||||
_debug response "$response"
|
||||
|
||||
CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')"
|
||||
export _H2="Cookie: ${CSRF_G_TOKEN}"
|
||||
|
||||
# Update the IP address for domain entry
|
||||
postdata="{\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\"TXT\",\"prefix\":\"$mysubdomain\",\"content\":\"$txtvalue\"}}"
|
||||
_debug postdata "$postdata"
|
||||
response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records" "" "POST" "application/json")"
|
||||
response="$(echo "$response" | _normalizeJson)"
|
||||
_debug response "$response"
|
||||
|
||||
id=$(echo "$response" | sed -n "s/{\"result\":{\"data\":{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}}},\"metadata\":null}/\1/p")
|
||||
|
||||
if [ -z "$id" ]; then
|
||||
_err "Add txt record error."
|
||||
return 1
|
||||
else
|
||||
_info "Added, OK ($id)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
dns_one_rm() {
|
||||
mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev)
|
||||
mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev)
|
||||
txtvalue=$2
|
||||
|
||||
# get credentials
|
||||
ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
|
||||
ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
|
||||
if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then
|
||||
ONECOM_User=""
|
||||
ONECOM_Password=""
|
||||
_err "You didn't specify a one.com username and password yet."
|
||||
_err "Please create the key and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Login with user and password
|
||||
postdata="loginDomain=true"
|
||||
postdata="$postdata&displayUsername=$ONECOM_User"
|
||||
postdata="$postdata&username=$ONECOM_User"
|
||||
postdata="$postdata&targetDomain=$mydomain"
|
||||
postdata="$postdata&password1=$ONECOM_Password"
|
||||
postdata="$postdata&loginTarget="
|
||||
|
||||
response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")"
|
||||
#_debug response "$response"
|
||||
|
||||
JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')"
|
||||
_debug jsessionid "$JSESSIONID"
|
||||
|
||||
export _H1="Cookie: ${JSESSIONID}"
|
||||
|
||||
# get entries
|
||||
response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")"
|
||||
response="$(echo "$response" | _normalizeJson)"
|
||||
_debug response "$response"
|
||||
|
||||
CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')"
|
||||
export _H2="Cookie: ${CSRF_G_TOKEN}"
|
||||
|
||||
id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}.*/\1/p")
|
||||
|
||||
if [ -z "$id" ]; then
|
||||
_err "Txt record not found."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# delete entry
|
||||
response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records/$id" "" "DELETE" "application/json")"
|
||||
response="$(echo "$response" | _normalizeJson)"
|
||||
_debug response "$response"
|
||||
|
||||
if [ "$response" = '{"result":null,"metadata":null}' ]; then
|
||||
_info "Removed, OK"
|
||||
return 0
|
||||
else
|
||||
_err "Removing txt record error."
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
@ -0,0 +1,261 @@
|
||||
#!/usr/bin/env sh
|
||||
# -*- mode: sh; tab-width: 2; indent-tabs-mode: s; coding: utf-8 -*-
|
||||
|
||||
# Schlundtech DNS API
|
||||
# Author: mod242
|
||||
# Created: 2019-40-29
|
||||
# Completly based on the autoDNS xml api wrapper by auerswald@gmail.com
|
||||
#
|
||||
# export SCHLUNDTECH_USER="username"
|
||||
# export SCHLUNDTECH_PASSWORD="password"
|
||||
#
|
||||
# Usage:
|
||||
# acme.sh --issue --dns dns_schlundtech -d example.com
|
||||
|
||||
SCHLUNDTECH_API="https://gateway.schlundtech.de"
|
||||
|
||||
# Arguments:
|
||||
# txtdomain
|
||||
# txt
|
||||
dns_schlundtech_add() {
|
||||
fulldomain="$1"
|
||||
txtvalue="$2"
|
||||
|
||||
SCHLUNDTECH_USER="${SCHLUNDTECH_USER:-$(_readaccountconf_mutable SCHLUNDTECH_USER)}"
|
||||
SCHLUNDTECH_PASSWORD="${SCHLUNDTECH_PASSWORD:-$(_readaccountconf_mutable SCHLUNDTECH_PASSWORD)}"
|
||||
|
||||
if [ -z "$SCHLUNDTECH_USER" ] || [ -z "$SCHLUNDTECH_PASSWORD" ]; then
|
||||
_err "You didn't specify schlundtech user and password."
|
||||
return 1
|
||||
fi
|
||||
|
||||
_saveaccountconf_mutable SCHLUNDTECH_USER "$SCHLUNDTECH_USER"
|
||||
_saveaccountconf_mutable SCHLUNDTECH_PASSWORD "$SCHLUNDTECH_PASSWORD"
|
||||
|
||||
_debug "First detect the root zone"
|
||||
|
||||
if ! _get_autodns_zone "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _zone "$_zone"
|
||||
_debug _system_ns "$_system_ns"
|
||||
|
||||
_info "Adding TXT record"
|
||||
|
||||
autodns_response="$(_autodns_zone_update "$_zone" "$_sub_domain" "$txtvalue" "$_system_ns")"
|
||||
|
||||
if [ "$?" -eq "0" ]; then
|
||||
_info "Added, OK"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# txtdomain
|
||||
# txt
|
||||
dns_schlundtech_rm() {
|
||||
fulldomain="$1"
|
||||
txtvalue="$2"
|
||||
|
||||
SCHLUNDTECH_USER="${SCHLUNDTECH_USER:-$(_readaccountconf_mutable SCHLUNDTECH_USER)}"
|
||||
SCHLUNDTECH_PASSWORD="${SCHLUNDTECH_PASSWORD:-$(_readaccountconf_mutable SCHLUNDTECH_PASSWORD)}"
|
||||
|
||||
if [ -z "$SCHLUNDTECH_USER" ] || [ -z "$SCHLUNDTECH_PASSWORD" ]; then
|
||||
_err "You didn't specify schlundtech user and password."
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "First detect the root zone"
|
||||
|
||||
if ! _get_autodns_zone "$fulldomain"; then
|
||||
_err "zone not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _zone "$_zone"
|
||||
_debug _system_ns "$_system_ns"
|
||||
|
||||
_info "Delete TXT record"
|
||||
|
||||
autodns_response="$(_autodns_zone_cleanup "$_zone" "$_sub_domain" "$txtvalue" "$_system_ns")"
|
||||
|
||||
if [ "$?" -eq "0" ]; then
|
||||
_info "Deleted, OK"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
|
||||
# Arguments:
|
||||
# fulldomain
|
||||
# Returns:
|
||||
# _sub_domain=_acme-challenge.www
|
||||
# _zone=domain.com
|
||||
# _system_ns
|
||||
_get_autodns_zone() {
|
||||
domain="$1"
|
||||
|
||||
i=2
|
||||
p=1
|
||||
|
||||
while true; do
|
||||
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||
_debug h "$h"
|
||||
|
||||
if [ -z "$h" ]; then
|
||||
# not valid
|
||||
return 1
|
||||
fi
|
||||
|
||||
autodns_response="$(_autodns_zone_inquire "$h")"
|
||||
|
||||
if [ "$?" -ne "0" ]; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if _contains "$autodns_response" "<summary>1</summary>" >/dev/null; then
|
||||
_zone="$(echo "$autodns_response" | _egrep_o '<name>[^<]*</name>' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||
_system_ns="$(echo "$autodns_response" | _egrep_o '<system_ns>[^<]*</system_ns>' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||
return 0
|
||||
fi
|
||||
|
||||
p=$i
|
||||
i=$(_math "$i" + 1)
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
_build_request_auth_xml() {
|
||||
printf "<auth>
|
||||
<user>%s</user>
|
||||
<password>%s</password>
|
||||
<context>10</context>
|
||||
</auth>" "$SCHLUNDTECH_USER" "$SCHLUNDTECH_PASSWORD"
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# zone
|
||||
_build_zone_inquire_xml() {
|
||||
printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<request>
|
||||
%s
|
||||
<task>
|
||||
<code>0205</code>
|
||||
<view>
|
||||
<children>1</children>
|
||||
<limit>1</limit>
|
||||
</view>
|
||||
<where>
|
||||
<key>name</key>
|
||||
<operator>eq</operator>
|
||||
<value>%s</value>
|
||||
</where>
|
||||
</task>
|
||||
</request>" "$(_build_request_auth_xml)" "$1"
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# zone
|
||||
# subdomain
|
||||
# txtvalue
|
||||
# system_ns
|
||||
_build_zone_update_xml() {
|
||||
printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<request>
|
||||
%s
|
||||
<task>
|
||||
<code>0202001</code>
|
||||
<default>
|
||||
<rr_add>
|
||||
<name>%s</name>
|
||||
<ttl>600</ttl>
|
||||
<type>TXT</type>
|
||||
<value>%s</value>
|
||||
</rr_add>
|
||||
</default>
|
||||
<zone>
|
||||
<name>%s</name>
|
||||
<system_ns>%s</system_ns>
|
||||
</zone>
|
||||
</task>
|
||||
</request>" "$(_build_request_auth_xml)" "$2" "$3" "$1" "$4"
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# zone
|
||||
_autodns_zone_inquire() {
|
||||
request_data="$(_build_zone_inquire_xml "$1")"
|
||||
autodns_response="$(_autodns_api_call "$request_data")"
|
||||
ret="$?"
|
||||
|
||||
printf "%s" "$autodns_response"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# zone
|
||||
# subdomain
|
||||
# txtvalue
|
||||
# system_ns
|
||||
_autodns_zone_update() {
|
||||
request_data="$(_build_zone_update_xml "$1" "$2" "$3" "$4")"
|
||||
autodns_response="$(_autodns_api_call "$request_data")"
|
||||
ret="$?"
|
||||
|
||||
printf "%s" "$autodns_response"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# zone
|
||||
# subdomain
|
||||
# txtvalue
|
||||
# system_ns
|
||||
_autodns_zone_cleanup() {
|
||||
request_data="$(_build_zone_update_xml "$1" "$2" "$3" "$4")"
|
||||
# replace 'rr_add>' with 'rr_rem>' in request_data
|
||||
request_data="$(printf -- "%s" "$request_data" | sed 's/rr_add>/rr_rem>/g')"
|
||||
autodns_response="$(_autodns_api_call "$request_data")"
|
||||
ret="$?"
|
||||
|
||||
printf "%s" "$autodns_response"
|
||||
return "$ret"
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# request_data
|
||||
_autodns_api_call() {
|
||||
request_data="$1"
|
||||
|
||||
_debug request_data "$request_data"
|
||||
|
||||
autodns_response="$(_post "$request_data" "$SCHLUNDTECH_API")"
|
||||
ret="$?"
|
||||
|
||||
_debug autodns_response "$autodns_response"
|
||||
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
_err "error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if _contains "$autodns_response" "<type>success</type>" >/dev/null; then
|
||||
_info "success"
|
||||
printf "%s" "$autodns_response"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# support local mail app
|
||||
|
||||
mail_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
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#Support mailgun.com api
|
||||
|
||||
#MAILGUN_API_KEY="xxxx"
|
||||
#MAILGUN_TO="yyyy@gmail.com"
|
||||
|
||||
#MAILGUN_REGION="us|eu" #optional, use "us" as default
|
||||
#MAILGUN_API_DOMAIN="xxxxxx.com" #optional, use the default sandbox domain
|
||||
#MAILGUN_FROM="xxx@xxxxx.com" #optional, use the default sendbox account
|
||||
|
||||
_MAILGUN_BASE="https://api.mailgun.net/v3"
|
||||
|
||||
# subject content statusCode
|
||||
mailgun_send() {
|
||||
_subject="$1"
|
||||
_content="$2"
|
||||
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
|
||||
_debug "_statusCode" "$_statusCode"
|
||||
|
||||
MAILGUN_API_KEY="${MAILGUN_API_KEY:-$(_readaccountconf_mutable MAILGUN_API_KEY)}"
|
||||
if [ -z "$MAILGUN_API_KEY" ]; then
|
||||
MAILGUN_API_KEY=""
|
||||
_err "You didn't specify a mailgun api key MAILGUN_API_KEY yet ."
|
||||
_err "You can get yours from here https://mailgun.com"
|
||||
return 1
|
||||
fi
|
||||
_saveaccountconf_mutable MAILGUN_API_KEY "$MAILGUN_API_KEY"
|
||||
|
||||
MAILGUN_REGION="${MAILGUN_REGION:-$(_readaccountconf_mutable MAILGUN_REGION)}"
|
||||
if [ -z "$MAILGUN_REGION" ]; then
|
||||
MAILGUN_REGION=""
|
||||
_debug "The MAILGUN_REGION is not set, so use the default us region."
|
||||
_MAILGUN_BASE="https://api.mailgun.net/v3"
|
||||
else
|
||||
_saveaccountconf_mutable MAILGUN_REGION "$MAILGUN_REGION"
|
||||
_MAILGUN_BASE="https://api.eu.mailgun.net/v3"
|
||||
fi
|
||||
|
||||
MAILGUN_TO="${MAILGUN_TO:-$(_readaccountconf_mutable MAILGUN_TO)}"
|
||||
if [ -z "$MAILGUN_TO" ]; then
|
||||
MAILGUN_TO=""
|
||||
_err "You didn't specify an email to MAILGUN_TO receive messages."
|
||||
return 1
|
||||
fi
|
||||
_saveaccountconf_mutable MAILGUN_TO "$MAILGUN_TO"
|
||||
|
||||
MAILGUN_API_DOMAIN="${MAILGUN_API_DOMAIN:-$(_readaccountconf_mutable MAILGUN_API_DOMAIN)}"
|
||||
if [ -z "$MAILGUN_API_DOMAIN" ]; then
|
||||
_info "The MAILGUN_API_DOMAIN is not set, try to get the default sending sandbox domain for you."
|
||||
if ! _mailgun_rest GET "/domains"; then
|
||||
_err "Can not get sandbox domain."
|
||||
return 1
|
||||
fi
|
||||
_sendboxDomain="$(echo "$response" | _egrep_o '"name": *"sandbox.*.mailgun.org"' | cut -d : -f 2 | tr -d '" ')"
|
||||
_debug _sendboxDomain "$_sendboxDomain"
|
||||
MAILGUN_API_DOMAIN="$_sendboxDomain"
|
||||
if [ -z "$MAILGUN_API_DOMAIN" ]; then
|
||||
_err "Can not get sandbox domain for MAILGUN_API_DOMAIN"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_info "$(__green "When using sandbox domain, you must verify your email first.")"
|
||||
#todo: add recepient
|
||||
fi
|
||||
if [ -z "$MAILGUN_API_DOMAIN" ]; then
|
||||
_err "Can not get MAILGUN_API_DOMAIN"
|
||||
return 1
|
||||
fi
|
||||
_saveaccountconf_mutable MAILGUN_API_DOMAIN "$MAILGUN_API_DOMAIN"
|
||||
|
||||
MAILGUN_FROM="${MAILGUN_FROM:-$(_readaccountconf_mutable MAILGUN_FROM)}"
|
||||
if [ -z "$MAILGUN_FROM" ]; then
|
||||
MAILGUN_FROM="$PROJECT_NAME@$MAILGUN_API_DOMAIN"
|
||||
_info "The MAILGUN_FROM is not set, so use the default value: $MAILGUN_FROM"
|
||||
else
|
||||
_debug MAILGUN_FROM "$MAILGUN_FROM"
|
||||
_saveaccountconf_mutable MAILGUN_FROM "$MAILGUN_FROM"
|
||||
fi
|
||||
|
||||
#send from url
|
||||
_msg="/$MAILGUN_API_DOMAIN/messages?from=$(printf "%s" "$MAILGUN_FROM" | _url_encode)&to=$(printf "%s" "$MAILGUN_TO" | _url_encode)&subject=$(printf "%s" "$_subject" | _url_encode)&text=$(printf "%s" "$_content" | _url_encode)"
|
||||
_debug "_msg" "$_msg"
|
||||
_mailgun_rest POST "$_msg"
|
||||
if _contains "$response" "Queued. Thank you."; then
|
||||
_debug "mailgun send success."
|
||||
return 0
|
||||
else
|
||||
_err "mailgun send error"
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# method uri data
|
||||
_mailgun_rest() {
|
||||
_method="$1"
|
||||
_mguri="$2"
|
||||
_mgdata="$3"
|
||||
_debug _mguri "$_mguri"
|
||||
_mgurl="$_MAILGUN_BASE$_mguri"
|
||||
_debug _mgurl "$_mgurl"
|
||||
|
||||
_auth="$(printf "%s" "api:$MAILGUN_API_KEY" | _base64)"
|
||||
export _H1="Authorization: Basic $_auth"
|
||||
export _H2="Content-Type: application/json"
|
||||
|
||||
if [ "$_method" = "GET" ]; then
|
||||
response="$(_get "$_mgurl")"
|
||||
else
|
||||
_debug _mgdata "$_mgdata"
|
||||
response="$(_post "$_mgdata" "$_mgurl" "" "$_method")"
|
||||
fi
|
||||
if [ "$?" != "0" ]; then
|
||||
_err "Error: $_mguri"
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
return 0
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# support pop
|
||||
|
||||
pop_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
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
#!/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="" #just make shellcheck happy
|
||||
if _post "$_data" "https://api.sendgrid.com/v3/mail/send"; then
|
||||
if [ -z "$response" ]; then
|
||||
_info "sendgrid send sccess."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
_err "sendgrid send error."
|
||||
_err "$response"
|
||||
return 1
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#!/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
|
||||
}
|
Loading…
Reference in New Issue