43 changed files with 3039 additions and 754 deletions
-
11.travis.yml
-
1Dockerfile
-
88README.md
-
351acme.sh
-
163deploy/README.md
-
18deploy/cpanel_uapi.sh
-
34deploy/haproxy.sh
-
6deploy/keychain.sh
-
205deploy/ssh.sh
-
2deploy/strongswan.sh
-
57deploy/vault_cli.sh
-
189dnsapi/README.md
-
55dnsapi/dns_acmedns.sh
-
43dnsapi/dns_ali.sh
-
101dnsapi/dns_aws.sh
-
145dnsapi/dns_azure.sh
-
8dnsapi/dns_cf.sh
-
62dnsapi/dns_cloudns.sh
-
42dnsapi/dns_cx.sh
-
184dnsapi/dns_da.sh
-
30dnsapi/dns_dgon.sh
-
33dnsapi/dns_dnsimple.sh
-
82dnsapi/dns_dp.sh
-
97dnsapi/dns_dreamhost.sh
-
358dnsapi/dns_euserv.sh
-
132dnsapi/dns_freedns.sh
-
79dnsapi/dns_gd.sh
-
102dnsapi/dns_he.sh
-
50dnsapi/dns_inwx.sh
-
4dnsapi/dns_ispconfig.sh
-
107dnsapi/dns_kinghost.sh
-
227dnsapi/dns_loopia.sh
-
40dnsapi/dns_lua.sh
-
22dnsapi/dns_me.sh
-
73dnsapi/dns_namecom.sh
-
6dnsapi/dns_nsone.sh
-
7dnsapi/dns_nsupdate.sh
-
16dnsapi/dns_ovh.sh
-
68dnsapi/dns_pdns.sh
-
69dnsapi/dns_tele3.sh
-
16dnsapi/dns_yandex.sh
-
139dnsapi/dns_zilore.sh
-
85dnsapi/dns_zonomi.sh
@ -0,0 +1,205 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
# Script to deploy certificates to remote server by SSH |
|||
# Note that SSH must be able to login to remote host without a password... |
|||
# SSH Keys must have been exchanged with the remote host. Validate and |
|||
# test that you can login to USER@SERVER from the host running acme.sh before |
|||
# using this script. |
|||
# |
|||
# The following variables exported from environment will be used. |
|||
# If not set then values previously saved in domain.conf file are used. |
|||
# |
|||
# Only a username is required. All others are optional. |
|||
# |
|||
# The following examples are for QNAP NAS running QTS 4.2 |
|||
# export DEPLOY_SSH_CMD="" # defaults to ssh |
|||
# export DEPLOY_SSH_USER="admin" # required |
|||
# export DEPLOY_SSH_SERVER="qnap" # defaults to domain name |
|||
# export DEPLOY_SSH_KEYFILE="/etc/stunnel/stunnel.pem" |
|||
# export DEPLOY_SSH_CERTFILE="/etc/stunnel/stunnel.pem" |
|||
# export DEPLOY_SSH_CAFILE="/etc/stunnel/uca.pem" |
|||
# export DEPLOY_SSH_FULLCHAIN="" |
|||
# export DEPLOY_SSH_REMOTE_CMD="/etc/init.d/stunnel.sh restart" |
|||
# export DEPLOY_SSH_BACKUP="" # yes or no, default to yes |
|||
# |
|||
######## Public functions ##################### |
|||
|
|||
#domain keyfile certfile cafile fullchain |
|||
ssh_deploy() { |
|||
_cdomain="$1" |
|||
_ckey="$2" |
|||
_ccert="$3" |
|||
_cca="$4" |
|||
_cfullchain="$5" |
|||
_cmdstr="" |
|||
_homedir='~' |
|||
_backupprefix="$_homedir/.acme_ssh_deploy/$_cdomain-backup" |
|||
_backupdir="$_backupprefix-$(_utc_date | tr ' ' '-')" |
|||
|
|||
if [ -f "$DOMAIN_CONF" ]; then |
|||
# shellcheck disable=SC1090 |
|||
. "$DOMAIN_CONF" |
|||
fi |
|||
|
|||
_debug _cdomain "$_cdomain" |
|||
_debug _ckey "$_ckey" |
|||
_debug _ccert "$_ccert" |
|||
_debug _cca "$_cca" |
|||
_debug _cfullchain "$_cfullchain" |
|||
|
|||
# USER is required to login by SSH to remote host. |
|||
if [ -z "$DEPLOY_SSH_USER" ]; then |
|||
if [ -z "$Le_Deploy_ssh_user" ]; then |
|||
_err "DEPLOY_SSH_USER not defined." |
|||
return 1 |
|||
fi |
|||
else |
|||
Le_Deploy_ssh_user="$DEPLOY_SSH_USER" |
|||
_savedomainconf Le_Deploy_ssh_user "$Le_Deploy_ssh_user" |
|||
fi |
|||
|
|||
# SERVER is optional. If not provided then use _cdomain |
|||
if [ -n "$DEPLOY_SSH_SERVER" ]; then |
|||
Le_Deploy_ssh_server="$DEPLOY_SSH_SERVER" |
|||
_savedomainconf Le_Deploy_ssh_server "$Le_Deploy_ssh_server" |
|||
elif [ -z "$Le_Deploy_ssh_server" ]; then |
|||
Le_Deploy_ssh_server="$_cdomain" |
|||
fi |
|||
|
|||
# CMD is optional. If not provided then use ssh |
|||
if [ -n "$DEPLOY_SSH_CMD" ]; then |
|||
Le_Deploy_ssh_cmd="$DEPLOY_SSH_CMD" |
|||
_savedomainconf Le_Deploy_ssh_cmd "$Le_Deploy_ssh_cmd" |
|||
elif [ -z "$Le_Deploy_ssh_cmd" ]; then |
|||
Le_Deploy_ssh_cmd="ssh" |
|||
fi |
|||
|
|||
# BACKUP is optional. If not provided then default to yes |
|||
if [ "$DEPLOY_SSH_BACKUP" = "no" ]; then |
|||
Le_Deploy_ssh_backup="no" |
|||
elif [ -z "$Le_Deploy_ssh_backup" ]; then |
|||
Le_Deploy_ssh_backup="yes" |
|||
fi |
|||
_savedomainconf Le_Deploy_ssh_backup "$Le_Deploy_ssh_backup" |
|||
|
|||
_info "Deploy certificates to remote server $Le_Deploy_ssh_user@$Le_Deploy_ssh_server" |
|||
|
|||
# KEYFILE is optional. |
|||
# If provided then private key will be copied to provided filename. |
|||
if [ -n "$DEPLOY_SSH_KEYFILE" ]; then |
|||
Le_Deploy_ssh_keyfile="$DEPLOY_SSH_KEYFILE" |
|||
_savedomainconf Le_Deploy_ssh_keyfile "$Le_Deploy_ssh_keyfile" |
|||
fi |
|||
if [ -n "$Le_Deploy_ssh_keyfile" ]; then |
|||
if [ "$Le_Deploy_ssh_backup" = "yes" ]; then |
|||
# backup file we are about to overwrite. |
|||
_cmdstr="$_cmdstr cp $Le_Deploy_ssh_keyfile $_backupdir >/dev/null;" |
|||
fi |
|||
# copy new certificate into file. |
|||
_cmdstr="$_cmdstr echo \"$(cat "$_ckey")\" > $Le_Deploy_ssh_keyfile;" |
|||
_info "will copy private key to remote file $Le_Deploy_ssh_keyfile" |
|||
fi |
|||
|
|||
# CERTFILE is optional. |
|||
# If provided then private key will be copied or appended to provided filename. |
|||
if [ -n "$DEPLOY_SSH_CERTFILE" ]; then |
|||
Le_Deploy_ssh_certfile="$DEPLOY_SSH_CERTFILE" |
|||
_savedomainconf Le_Deploy_ssh_certfile "$Le_Deploy_ssh_certfile" |
|||
fi |
|||
if [ -n "$Le_Deploy_ssh_certfile" ]; then |
|||
_pipe=">" |
|||
if [ "$Le_Deploy_ssh_certfile" = "$Le_Deploy_ssh_keyfile" ]; then |
|||
# if filename is same as previous file then append. |
|||
_pipe=">>" |
|||
elif [ "$Le_Deploy_ssh_backup" = "yes" ]; then |
|||
# backup file we are about to overwrite. |
|||
_cmdstr="$_cmdstr cp $Le_Deploy_ssh_certfile $_backupdir >/dev/null;" |
|||
fi |
|||
# copy new certificate into file. |
|||
_cmdstr="$_cmdstr echo \"$(cat "$_ccert")\" $_pipe $Le_Deploy_ssh_certfile;" |
|||
_info "will copy certificate to remote file $Le_Deploy_ssh_certfile" |
|||
fi |
|||
|
|||
# CAFILE is optional. |
|||
# If provided then CA intermediate certificate will be copied or appended to provided filename. |
|||
if [ -n "$DEPLOY_SSH_CAFILE" ]; then |
|||
Le_Deploy_ssh_cafile="$DEPLOY_SSH_CAFILE" |
|||
_savedomainconf Le_Deploy_ssh_cafile "$Le_Deploy_ssh_cafile" |
|||
fi |
|||
if [ -n "$Le_Deploy_ssh_cafile" ]; then |
|||
_pipe=">" |
|||
if [ "$Le_Deploy_ssh_cafile" = "$Le_Deploy_ssh_keyfile" ] \ |
|||
|| [ "$Le_Deploy_ssh_cafile" = "$Le_Deploy_ssh_certfile" ]; then |
|||
# if filename is same as previous file then append. |
|||
_pipe=">>" |
|||
elif [ "$Le_Deploy_ssh_backup" = "yes" ]; then |
|||
# backup file we are about to overwrite. |
|||
_cmdstr="$_cmdstr cp $Le_Deploy_ssh_cafile $_backupdir >/dev/null;" |
|||
fi |
|||
# copy new certificate into file. |
|||
_cmdstr="$_cmdstr echo \"$(cat "$_cca")\" $_pipe $Le_Deploy_ssh_cafile;" |
|||
_info "will copy CA file to remote file $Le_Deploy_ssh_cafile" |
|||
fi |
|||
|
|||
# FULLCHAIN is optional. |
|||
# If provided then fullchain certificate will be copied or appended to provided filename. |
|||
if [ -n "$DEPLOY_SSH_FULLCHAIN" ]; then |
|||
Le_Deploy_ssh_fullchain="$DEPLOY_SSH_FULLCHAIN" |
|||
_savedomainconf Le_Deploy_ssh_fullchain "$Le_Deploy_ssh_fullchain" |
|||
fi |
|||
if [ -n "$Le_Deploy_ssh_fullchain" ]; then |
|||
_pipe=">" |
|||
if [ "$Le_Deploy_ssh_fullchain" = "$Le_Deploy_ssh_keyfile" ] \ |
|||
|| [ "$Le_Deploy_ssh_fullchain" = "$Le_Deploy_ssh_certfile" ] \ |
|||
|| [ "$Le_Deploy_ssh_fullchain" = "$Le_Deploy_ssh_cafile" ]; then |
|||
# if filename is same as previous file then append. |
|||
_pipe=">>" |
|||
elif [ "$Le_Deploy_ssh_backup" = "yes" ]; then |
|||
# backup file we are about to overwrite. |
|||
_cmdstr="$_cmdstr cp $Le_Deploy_ssh_fullchain $_backupdir >/dev/null;" |
|||
fi |
|||
# copy new certificate into file. |
|||
_cmdstr="$_cmdstr echo \"$(cat "$_cfullchain")\" $_pipe $Le_Deploy_ssh_fullchain;" |
|||
_info "will copy fullchain to remote file $Le_Deploy_ssh_fullchain" |
|||
fi |
|||
|
|||
# REMOTE_CMD is optional. |
|||
# If provided then this command will be executed on remote host. |
|||
if [ -n "$DEPLOY_SSH_REMOTE_CMD" ]; then |
|||
Le_Deploy_ssh_remote_cmd="$DEPLOY_SSH_REMOTE_CMD" |
|||
_savedomainconf Le_Deploy_ssh_remote_cmd "$Le_Deploy_ssh_remote_cmd" |
|||
fi |
|||
if [ -n "$Le_Deploy_ssh_remote_cmd" ]; then |
|||
_cmdstr="$_cmdstr $Le_Deploy_ssh_remote_cmd;" |
|||
_info "Will execute remote command $Le_Deploy_ssh_remote_cmd" |
|||
fi |
|||
|
|||
if [ -z "$_cmdstr" ]; then |
|||
_err "No remote commands to excute. Failed to deploy certificates to remote server" |
|||
return 1 |
|||
elif [ "$Le_Deploy_ssh_backup" = "yes" ]; then |
|||
# run cleanup on the backup directory, erase all older |
|||
# than 180 days (15552000 seconds). |
|||
_cmdstr="{ now=\"\$(date -u +%s)\"; for fn in $_backupprefix*; \ |
|||
do if [ -d \"\$fn\" ] && [ \"\$(expr \$now - \$(date -ur \$fn +%s) )\" -ge \"15552000\" ]; \ |
|||
then rm -rf \"\$fn\"; echo \"Backup \$fn deleted as older than 180 days\"; fi; done; }; $_cmdstr" |
|||
# Alternate version of above... _cmdstr="find $_backupprefix* -type d -mtime +180 2>/dev/null | xargs rm -rf; $_cmdstr" |
|||
# Create our backup directory for overwritten cert files. |
|||
_cmdstr="mkdir -p $_backupdir; $_cmdstr" |
|||
_info "Backup of old certificate files will be placed in remote directory $_backupdir" |
|||
_info "Backup directories erased after 180 days." |
|||
fi |
|||
|
|||
_debug "Remote commands to execute: $_cmdstr" |
|||
_info "Submitting sequence of commands to remote server by ssh" |
|||
# quotations in bash cmd below intended. Squash travis spellcheck error |
|||
# shellcheck disable=SC2029 |
|||
$Le_Deploy_ssh_cmd -T "$Le_Deploy_ssh_user@$Le_Deploy_ssh_server" sh -c "'$_cmdstr'" |
|||
_ret="$?" |
|||
|
|||
if [ "$_ret" != "0" ]; then |
|||
_err "Error code $_ret returned from $Le_Deploy_ssh_cmd" |
|||
fi |
|||
|
|||
return $_ret |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
# Here is a script to deploy cert to hashicorp vault |
|||
# (https://www.vaultproject.io/) |
|||
# |
|||
# it requires the vault binary to be available in PATH, and the following |
|||
# environment variables: |
|||
# |
|||
# VAULT_PREFIX - this contains the prefix path in vault |
|||
# VAULT_ADDR - vault requires this to find your vault server |
|||
# |
|||
# additionally, you need to ensure that VAULT_TOKEN is avialable or |
|||
# `vault auth` has applied the appropriate authorization for the vault binary |
|||
# to access the vault server |
|||
|
|||
#returns 0 means success, otherwise error. |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#domain keyfile certfile cafile fullchain |
|||
vault_cli_deploy() { |
|||
|
|||
_cdomain="$1" |
|||
_ckey="$2" |
|||
_ccert="$3" |
|||
_cca="$4" |
|||
_cfullchain="$5" |
|||
|
|||
_debug _cdomain "$_cdomain" |
|||
_debug _ckey "$_ckey" |
|||
_debug _ccert "$_ccert" |
|||
_debug _cca "$_cca" |
|||
_debug _cfullchain "$_cfullchain" |
|||
|
|||
# validate required env vars |
|||
if [ -z "$VAULT_PREFIX" ]; then |
|||
_err "VAULT_PREFIX needs to be defined (contains prefix path in vault)" |
|||
return 1 |
|||
fi |
|||
|
|||
if [ -z "$VAULT_ADDR" ]; then |
|||
_err "VAULT_ADDR needs to be defined (contains vault connection address)" |
|||
return 1 |
|||
fi |
|||
|
|||
VAULT_CMD=$(which vault) |
|||
if [ ! $? ]; then |
|||
_err "cannot find vault binary!" |
|||
return 1 |
|||
fi |
|||
|
|||
$VAULT_CMD write "${VAULT_PREFIX}/${_cdomain}/cert.pem" value=@"$_ccert" || return 1 |
|||
$VAULT_CMD write "${VAULT_PREFIX}/${_cdomain}/cert.key" value=@"$_ckey" || return 1 |
|||
$VAULT_CMD write "${VAULT_PREFIX}/${_cdomain}/chain.pem" value=@"$_cca" || return 1 |
|||
$VAULT_CMD write "${VAULT_PREFIX}/${_cdomain}/fullchain.pem" value=@"$_cfullchain" || return 1 |
|||
|
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
#!/usr/bin/env sh |
|||
# |
|||
#Author: Wolfgang Ebner |
|||
#Report Bugs here: https://github.com/webner/acme.sh |
|||
# |
|||
######## Public functions ##################### |
|||
|
|||
#Usage: dns_acmedns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_acmedns_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
_info "Using acme-dns" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
ACMEDNS_UPDATE_URL="${ACMEDNS_UPDATE_URL:-$(_readaccountconf_mutable ACMEDNS_UPDATE_URL)}" |
|||
ACMEDNS_USERNAME="${ACMEDNS_USERNAME:-$(_readaccountconf_mutable ACMEDNS_USERNAME)}" |
|||
ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readaccountconf_mutable ACMEDNS_PASSWORD)}" |
|||
ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readaccountconf_mutable ACMEDNS_SUBDOMAIN)}" |
|||
|
|||
if [ "$ACMEDNS_UPDATE_URL" = "" ]; then |
|||
ACMEDNS_UPDATE_URL="https://auth.acme-dns.io/update" |
|||
fi |
|||
|
|||
_saveaccountconf_mutable ACMEDNS_UPDATE_URL "$ACMEDNS_UPDATE_URL" |
|||
_saveaccountconf_mutable ACMEDNS_USERNAME "$ACMEDNS_USERNAME" |
|||
_saveaccountconf_mutable ACMEDNS_PASSWORD "$ACMEDNS_PASSWORD" |
|||
_saveaccountconf_mutable ACMEDNS_SUBDOMAIN "$ACMEDNS_SUBDOMAIN" |
|||
|
|||
export _H1="X-Api-User: $ACMEDNS_USERNAME" |
|||
export _H2="X-Api-Key: $ACMEDNS_PASSWORD" |
|||
data="{\"subdomain\":\"$ACMEDNS_SUBDOMAIN\", \"txt\": \"$txtvalue\"}" |
|||
|
|||
_debug data "$data" |
|||
response="$(_post "$data" "$ACMEDNS_UPDATE_URL" "" "POST")" |
|||
_debug response "$response" |
|||
|
|||
if ! echo "$response" | grep "\"$txtvalue\"" >/dev/null; then |
|||
_err "invalid response of acme-dns" |
|||
return 1 |
|||
fi |
|||
|
|||
} |
|||
|
|||
#Usage: fulldomain txtvalue |
|||
#Remove the txt record after validation. |
|||
dns_acmedns_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
_info "Using acme-dns" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
@ -0,0 +1,184 @@ |
|||
#!/usr/bin/env sh |
|||
# -*- mode: sh; tab-width: 2; indent-tabs-mode: s; coding: utf-8 -*- |
|||
# vim: et ts=2 sw=2 |
|||
# |
|||
# DirectAdmin 1.41.0 API |
|||
# The DirectAdmin interface has it's own Let's encrypt functionality, but this |
|||
# script can be used to generate certificates for names which are not hosted on |
|||
# DirectAdmin |
|||
# |
|||
# User must provide login data and URL to DirectAdmin incl. port. |
|||
# You can create login key, by using the Login Keys function |
|||
# ( https://da.example.com:8443/CMD_LOGIN_KEYS ), which only has access to |
|||
# - CMD_API_DNS_CONTROL |
|||
# - CMD_API_SHOW_DOMAINS |
|||
# |
|||
# See also https://www.directadmin.com/api.php and |
|||
# https://www.directadmin.com/features.php?id=1298 |
|||
# |
|||
# Report bugs to https://github.com/TigerP/acme.sh/issues |
|||
# |
|||
# Values to export: |
|||
# export DA_Api="https://remoteUser:remotePassword@da.example.com:8443" |
|||
# export DA_Api_Insecure=1 |
|||
# |
|||
# Set DA_Api_Insecure to 1 for insecure and 0 for secure -> difference is |
|||
# whether ssl cert is checked for validity (0) or whether it is just accepted |
|||
# (1) |
|||
# |
|||
######## Public functions ##################### |
|||
|
|||
# Usage: dns_myapi_add _acme-challenge.www.example.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
# Used to add txt record |
|||
dns_da_add() { |
|||
fulldomain="${1}" |
|||
txtvalue="${2}" |
|||
_debug "Calling: dns_da_add() '${fulldomain}' '${txtvalue}'" |
|||
_DA_credentials && _DA_getDomainInfo && _DA_addTxt |
|||
} |
|||
|
|||
# Usage: dns_da_rm _acme-challenge.www.example.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
# Used to remove the txt record after validation |
|||
dns_da_rm() { |
|||
fulldomain="${1}" |
|||
txtvalue="${2}" |
|||
_debug "Calling: dns_da_rm() '${fulldomain}' '${txtvalue}'" |
|||
_DA_credentials && _DA_getDomainInfo && _DA_rmTxt |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
# Usage: _DA_credentials |
|||
# It will check if the needed settings are available |
|||
_DA_credentials() { |
|||
DA_Api="${DA_Api:-$(_readaccountconf_mutable DA_Api)}" |
|||
DA_Api_Insecure="${DA_Api_Insecure:-$(_readaccountconf_mutable DA_Api_Insecure)}" |
|||
if [ -z "${DA_Api}" ] || [ -z "${DA_Api_Insecure}" ]; then |
|||
DA_Api="" |
|||
DA_Api_Insecure="" |
|||
_err "You haven't specified the DirectAdmin Login data, URL and whether you want check the DirectAdmin SSL cert. Please try again." |
|||
return 1 |
|||
else |
|||
_saveaccountconf_mutable DA_Api "${DA_Api}" |
|||
_saveaccountconf_mutable DA_Api_Insecure "${DA_Api_Insecure}" |
|||
# Set whether curl should use secure or insecure mode |
|||
export HTTPS_INSECURE="${DA_Api_Insecure}" |
|||
fi |
|||
} |
|||
|
|||
# Usage: _get_root _acme-challenge.www.example.com |
|||
# Split the full domain to a domain and subdomain |
|||
#returns |
|||
# _sub_domain=_acme-challenge.www |
|||
# _domain=example.com |
|||
_get_root() { |
|||
domain=$1 |
|||
i=2 |
|||
p=1 |
|||
# Get a list of all the domains |
|||
# response will contain "list[]=example.com&list[]=example.org" |
|||
_da_api CMD_API_SHOW_DOMAINS "" "${domain}" |
|||
while true; do |
|||
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
|||
_debug h "$h" |
|||
if [ -z "$h" ]; then |
|||
# not valid |
|||
_debug "The given domain $h is not valid" |
|||
return 1 |
|||
fi |
|||
if _contains "$response" "$h" >/dev/null; then |
|||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
|||
_domain=$h |
|||
return 0 |
|||
fi |
|||
p=$i |
|||
i=$(_math "$i" + 1) |
|||
done |
|||
_debug "Stop on 100" |
|||
return 1 |
|||
} |
|||
|
|||
# Usage: _da_api CMD_API_* data example.com |
|||
# Use the DirectAdmin API and check the result |
|||
# returns |
|||
# response="error=0&text=Result text&details=" |
|||
_da_api() { |
|||
cmd=$1 |
|||
data=$2 |
|||
domain=$3 |
|||
_debug "$domain; $data" |
|||
response="$(_post "$data" "$DA_Api/$cmd" "" "POST")" |
|||
|
|||
if [ "$?" != "0" ]; then |
|||
_err "error $cmd" |
|||
return 1 |
|||
fi |
|||
_debug response "$response" |
|||
|
|||
case "${cmd}" in |
|||
CMD_API_DNS_CONTROL) |
|||
# Parse the result in general |
|||
# error=0&text=Records Deleted&details= |
|||
# error=1&text=Cannot View Dns Record&details=No domain provided |
|||
err_field="$(_getfield "$response" 1 '&')" |
|||
txt_field="$(_getfield "$response" 2 '&')" |
|||
details_field="$(_getfield "$response" 3 '&')" |
|||
error="$(_getfield "$err_field" 2 '=')" |
|||
text="$(_getfield "$txt_field" 2 '=')" |
|||
details="$(_getfield "$details_field" 2 '=')" |
|||
_debug "error: ${error}, text: ${text}, details: ${details}" |
|||
if [ "$error" != "0" ]; then |
|||
_err "error $response" |
|||
return 1 |
|||
fi |
|||
;; |
|||
CMD_API_SHOW_DOMAINS) ;; |
|||
esac |
|||
return 0 |
|||
} |
|||
|
|||
# Usage: _DA_getDomainInfo |
|||
# Get the root zone if possible |
|||
_DA_getDomainInfo() { |
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
else |
|||
_debug "The root domain: $_domain" |
|||
_debug "The sub domain: $_sub_domain" |
|||
fi |
|||
return 0 |
|||
} |
|||
|
|||
# Usage: _DA_addTxt |
|||
# Use the API to add a record |
|||
_DA_addTxt() { |
|||
curData="domain=${_domain}&action=add&type=TXT&name=${_sub_domain}&value=\"${txtvalue}\"" |
|||
_debug "Calling _DA_addTxt: '${curData}' '${DA_Api}/CMD_API_DNS_CONTROL'" |
|||
_da_api CMD_API_DNS_CONTROL "${curData}" "${_domain}" |
|||
_debug "Result of _DA_addTxt: '$response'" |
|||
if _contains "${response}" 'error=0'; then |
|||
_debug "Add TXT succeeded" |
|||
return 0 |
|||
fi |
|||
_debug "Add TXT failed" |
|||
return 1 |
|||
} |
|||
|
|||
# Usage: _DA_rmTxt |
|||
# Use the API to remove a record |
|||
_DA_rmTxt() { |
|||
curData="domain=${_domain}&action=select&txtrecs0=name=${_sub_domain}&value=\"${txtvalue}\"" |
|||
_debug "Calling _DA_rmTxt: '${curData}' '${DA_Api}/CMD_API_DNS_CONTROL'" |
|||
if _da_api CMD_API_DNS_CONTROL "${curData}" "${_domain}"; then |
|||
_debug "Result of _DA_rmTxt: '$response'" |
|||
else |
|||
_err "Result of _DA_rmTxt: '$response'" |
|||
fi |
|||
if _contains "${response}" 'error=0'; then |
|||
_debug "RM TXT succeeded" |
|||
return 0 |
|||
fi |
|||
_debug "RM TXT failed" |
|||
return 1 |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
#Author: RhinoLance |
|||
#Report Bugs here: https://github.com/RhinoLance/acme.sh |
|||
# |
|||
|
|||
#define the api endpoint |
|||
DH_API_ENDPOINT="https://api.dreamhost.com/" |
|||
querystring="" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_dreamhost_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
if ! validate "$fulldomain" "$txtvalue"; then |
|||
return 1 |
|||
fi |
|||
|
|||
querystring="key=$DH_API_KEY&cmd=dns-add_record&record=$fulldomain&type=TXT&value=$txtvalue" |
|||
if ! submit "$querystring"; then |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
#Usage: fulldomain txtvalue |
|||
#Remove the txt record after validation. |
|||
dns_dreamhost_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
if ! validate "$fulldomain" "$txtvalue"; then |
|||
return 1 |
|||
fi |
|||
|
|||
querystring="key=$DH_API_KEY&cmd=dns-remove_record&record=$fulldomain&type=TXT&value=$txtvalue" |
|||
if ! submit "$querystring"; then |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
#send the command to the api endpoint. |
|||
submit() { |
|||
querystring=$1 |
|||
|
|||
url="$DH_API_ENDPOINT?$querystring" |
|||
|
|||
_debug url "$url" |
|||
|
|||
if ! response="$(_get "$url")"; then |
|||
_err "Error <$1>" |
|||
return 1 |
|||
fi |
|||
|
|||
if [ -z "$2" ]; then |
|||
message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" |
|||
if [ -n "$message" ]; then |
|||
_err "$message" |
|||
return 1 |
|||
fi |
|||
fi |
|||
|
|||
_debug response "$response" |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
#check that we have a valid API Key |
|||
validate() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
_info "Using dreamhost" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
#retrieve the API key from the environment variable if it exists, otherwise look for a saved key. |
|||
DH_API_KEY="${DH_API_KEY:-$(_readaccountconf_mutable DH_API_KEY)}" |
|||
|
|||
if [ -z "$DH_API_KEY" ]; then |
|||
DH_API_KEY="" |
|||
_err "You didn't specify the DreamHost api key yet (export DH_API_KEY=\"<api key>\")" |
|||
_err "Please login to your control panel, create a key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the api key to the account conf file. |
|||
_saveaccountconf_mutable DH_API_KEY "$DH_API_KEY" |
|||
} |
|||
@ -0,0 +1,358 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
#This is the euserv.eu api wrapper for acme.sh |
|||
# |
|||
#Author: Michael Brueckner |
|||
#Report Bugs: https://www.github.com/initit/acme.sh or mbr@initit.de |
|||
|
|||
# |
|||
#EUSERV_Username="username" |
|||
# |
|||
#EUSERV_Password="password" |
|||
# |
|||
# Dependencies: |
|||
# ------------- |
|||
# - none - |
|||
|
|||
EUSERV_Api="https://api.euserv.net" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_euserv_add() { |
|||
fulldomain="$(echo "$1" | _lower_case)" |
|||
txtvalue=$2 |
|||
|
|||
EUSERV_Username="${EUSERV_Username:-$(_readaccountconf_mutable EUSERV_Username)}" |
|||
EUSERV_Password="${EUSERV_Password:-$(_readaccountconf_mutable EUSERV_Password)}" |
|||
if [ -z "$EUSERV_Username" ] || [ -z "$EUSERV_Password" ]; then |
|||
EUSERV_Username="" |
|||
EUSERV_Password="" |
|||
_err "You don't specify euserv user and password yet." |
|||
_err "Please create your key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the user and email to the account conf file. |
|||
_saveaccountconf_mutable EUSERV_Username "$EUSERV_Username" |
|||
_saveaccountconf_mutable EUSERV_Password "$EUSERV_Password" |
|||
|
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
_debug "_sub_domain" "$_sub_domain" |
|||
_debug "_domain" "$_domain" |
|||
_info "Adding record" |
|||
if ! _euserv_add_record "$_domain" "$_sub_domain" "$txtvalue"; then |
|||
return 1 |
|||
fi |
|||
|
|||
} |
|||
|
|||
#fulldomain txtvalue |
|||
dns_euserv_rm() { |
|||
|
|||
fulldomain="$(echo "$1" | _lower_case)" |
|||
txtvalue=$2 |
|||
|
|||
EUSERV_Username="${EUSERV_Username:-$(_readaccountconf_mutable EUSERV_Username)}" |
|||
EUSERV_Password="${EUSERV_Password:-$(_readaccountconf_mutable EUSERV_Password)}" |
|||
if [ -z "$EUSERV_Username" ] || [ -z "$EUSERV_Password" ]; then |
|||
EUSERV_Username="" |
|||
EUSERV_Password="" |
|||
_err "You don't specify euserv user and password yet." |
|||
_err "Please create your key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the user and email to the account conf file. |
|||
_saveaccountconf_mutable EUSERV_Username "$EUSERV_Username" |
|||
_saveaccountconf_mutable EUSERV_Password "$EUSERV_Password" |
|||
|
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
_debug "_sub_domain" "$_sub_domain" |
|||
_debug "_domain" "$_domain" |
|||
|
|||
_debug "Getting txt records" |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>domain.dns_get_active_records</methodName> |
|||
<params> |
|||
<param> |
|||
<value> |
|||
<struct> |
|||
<member> |
|||
<name>login</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>password</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>domain_id</name> |
|||
<value> |
|||
<int>%s</int> |
|||
</value> |
|||
</member> |
|||
</struct> |
|||
</value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$_euserv_domain_id") |
|||
|
|||
export _H1="Content-Type: text/xml" |
|||
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
|||
_err "Error could not get txt records" |
|||
_debug "xml_content" "$xml_content" |
|||
_debug "response" "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
if ! echo "$response" | grep '>dns_record_content<.*>'"$txtvalue"'<' >/dev/null; then |
|||
_info "Do not need to delete record" |
|||
else |
|||
# find XML block where txtvalue is in. The record_id is allways prior this line! |
|||
_endLine=$(echo "$response" | grep -n '>dns_record_content<.*>'"$txtvalue"'<' | cut -d ':' -f 1) |
|||
# record_id is the last <name> Tag with a number before the row _endLine, identified by </name><value><struct> |
|||
_record_id=$(echo "$response" | sed -n '1,'"$_endLine"'p' | grep '</name><value><struct>' | _tail_n 1 | sed 's/.*<name>\([0-9]*\)<\/name>.*/\1/') |
|||
_info "Deleting record" |
|||
_euserv_delete_record "$_record_id" |
|||
fi |
|||
|
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
_get_root() { |
|||
domain=$1 |
|||
_debug "get root" |
|||
|
|||
# Just to read the domain_orders once |
|||
|
|||
domain=$1 |
|||
i=2 |
|||
p=1 |
|||
|
|||
if ! _euserv_get_domain_orders; then |
|||
return 1 |
|||
fi |
|||
|
|||
# Get saved response with domain_orders |
|||
response="$_euserv_domain_orders" |
|||
|
|||
while true; do |
|||
h=$(echo "$domain" | cut -d . -f $i-100) |
|||
_debug h "$h" |
|||
if [ -z "$h" ]; then |
|||
#not valid |
|||
return 1 |
|||
fi |
|||
|
|||
if _contains "$response" "$h"; then |
|||
_sub_domain=$(echo "$domain" | cut -d . -f 1-$p) |
|||
_domain="$h" |
|||
if ! _euserv_get_domain_id "$_domain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
return 0 |
|||
fi |
|||
p=$i |
|||
i=$(_math "$i" + 1) |
|||
done |
|||
|
|||
return 1 |
|||
} |
|||
|
|||
_euserv_get_domain_orders() { |
|||
# returns: _euserv_domain_orders |
|||
|
|||
_debug "get domain_orders" |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>domain.get_domain_orders</methodName> |
|||
<params> |
|||
<param> |
|||
<value> |
|||
<struct> |
|||
<member> |
|||
<name>login</name> |
|||
<value><string>%s</string></value> |
|||
</member> |
|||
<member> |
|||
<name>password</name> |
|||
<value><string>%s</string></value> |
|||
</member> |
|||
</struct> |
|||
</value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' "$EUSERV_Username" "$EUSERV_Password") |
|||
|
|||
export _H1="Content-Type: text/xml" |
|||
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
|||
_err "Error could not get domain orders" |
|||
_debug "xml_content" "$xml_content" |
|||
_debug "response" "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
# save response to reduce API calls |
|||
_euserv_domain_orders="$response" |
|||
return 0 |
|||
} |
|||
|
|||
_euserv_get_domain_id() { |
|||
# returns: _euserv_domain_id |
|||
domain=$1 |
|||
_debug "get domain_id" |
|||
|
|||
# find line where the domain name is within the $response |
|||
_startLine=$(echo "$_euserv_domain_orders" | grep -n '>domain_name<.*>'"$domain"'<' | cut -d ':' -f 1) |
|||
# next occurency of domain_id after the domain_name is the correct one |
|||
_euserv_domain_id=$(echo "$_euserv_domain_orders" | sed -n "$_startLine"',$p' | grep '>domain_id<' | _head_n 1 | sed 's/.*<i4>\([0-9]*\)<\/i4>.*/\1/') |
|||
|
|||
if [ -z "$_euserv_domain_id" ]; then |
|||
_err "Could not find domain_id for domain $domain" |
|||
_debug "_euserv_domain_orders" "$_euserv_domain_orders" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
_euserv_delete_record() { |
|||
record_id=$1 |
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>domain.dns_delete_record</methodName> |
|||
<params> |
|||
<param> |
|||
<value> |
|||
<struct> |
|||
<member> |
|||
<name>login</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>password</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>dns_record_id</name> |
|||
<value> |
|||
<int>%s</int> |
|||
</value> |
|||
</member> |
|||
</struct> |
|||
</value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$record_id") |
|||
|
|||
export _H1="Content-Type: text/xml" |
|||
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
|||
_err "Error deleting record" |
|||
_debug "xml_content" "$xml_content" |
|||
_debug "response" "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
|
|||
} |
|||
|
|||
_euserv_add_record() { |
|||
domain=$1 |
|||
sub_domain=$2 |
|||
txtval=$3 |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>domain.dns_create_record</methodName> |
|||
<params> |
|||
<param> |
|||
<value> |
|||
<struct> |
|||
<member> |
|||
<name>login</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>password</name> |
|||
<value> |
|||
<string>%s</string></value> |
|||
</member> |
|||
<member> |
|||
<name>domain_id</name> |
|||
<value> |
|||
<int>%s</int> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>dns_record_subdomain</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>dns_record_type</name> |
|||
<value> |
|||
<string>TXT</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>dns_record_value</name> |
|||
<value> |
|||
<string>%s</string> |
|||
</value> |
|||
</member> |
|||
<member> |
|||
<name>dns_record_ttl</name> |
|||
<value> |
|||
<int>300</int> |
|||
</value> |
|||
</member> |
|||
</struct> |
|||
</value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$_euserv_domain_id" "$sub_domain" "$txtval") |
|||
|
|||
export _H1="Content-Type: text/xml" |
|||
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
|||
_err "Error could not create record" |
|||
_debug "xml_content" "$xml_content" |
|||
_debug "response" "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
@ -0,0 +1,107 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
############################################################ |
|||
# KingHost API support # |
|||
# http://api.kinghost.net/doc/ # |
|||
# # |
|||
# Author: Felipe Keller Braz <felipebraz@kinghost.com.br> # |
|||
# Report Bugs here: https://github.com/kinghost/acme.sh # |
|||
# # |
|||
# Values to export: # |
|||
# export KINGHOST_Username="email@provider.com" # |
|||
# export KINGHOST_Password="xxxxxxxxxx" # |
|||
############################################################ |
|||
|
|||
KING_Api="https://api.kinghost.net/acme" |
|||
|
|||
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
# Used to add txt record |
|||
dns_kinghost_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}" |
|||
KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}" |
|||
if [ -z "$KINGHOST_Username" ] || [ -z "$KINGHOST_Password" ]; then |
|||
KINGHOST_Username="" |
|||
KINGHOST_Password="" |
|||
_err "You don't specify KingHost api password and email yet." |
|||
_err "Please create you key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the credentials to the account conf file. |
|||
_saveaccountconf_mutable KINGHOST_Username "$KINGHOST_Username" |
|||
_saveaccountconf_mutable KINGHOST_Password "$KINGHOST_Password" |
|||
|
|||
_debug "Getting txt records" |
|||
_kinghost_rest GET "dns" "name=$fulldomain&content=$txtvalue" |
|||
|
|||
#This API call returns "status":"ok" if dns record does not exists |
|||
#We are creating a new txt record here, so we expect the "ok" status |
|||
if ! echo "$response" | grep '"status":"ok"' >/dev/null; then |
|||
_err "Error" |
|||
_err "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
_kinghost_rest POST "dns" "name=$fulldomain&content=$txtvalue" |
|||
if ! echo "$response" | grep '"status":"ok"' >/dev/null; then |
|||
_err "Error" |
|||
_err "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
# Usage: fulldomain txtvalue |
|||
# Used to remove the txt record after validation |
|||
dns_kinghost_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}" |
|||
KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}" |
|||
if [ -z "$KINGHOST_Password" ] || [ -z "$KINGHOST_Username" ]; then |
|||
KINGHOST_Password="" |
|||
KINGHOST_Username="" |
|||
_err "You don't specify KingHost api key and email yet." |
|||
_err "Please create you key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
_kinghost_rest DELETE "dns" "name=$fulldomain&content=$txtvalue" |
|||
if ! echo "$response" | grep '"status":"ok"' >/dev/null; then |
|||
_err "Error" |
|||
_err "$response" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
_kinghost_rest() { |
|||
method=$1 |
|||
uri="$2" |
|||
data="$3" |
|||
_debug "$uri" |
|||
|
|||
export _H1="X-Auth-Email: $KINGHOST_Username" |
|||
export _H2="X-Auth-Key: $KINGHOST_Password" |
|||
|
|||
if [ "$method" != "GET" ]; then |
|||
_debug data "$data" |
|||
response="$(_post "$data" "$KING_Api/$uri.json" "" "$method")" |
|||
else |
|||
response="$(_get "$KING_Api/$uri.json?$data")" |
|||
fi |
|||
|
|||
if [ "$?" != "0" ]; then |
|||
_err "error $uri" |
|||
return 1 |
|||
fi |
|||
_debug2 response "$response" |
|||
return 0 |
|||
} |
|||
@ -0,0 +1,227 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
# |
|||
#LOOPIA_User="username" |
|||
# |
|||
#LOOPIA_Password="password" |
|||
|
|||
LOOPIA_Api="https://api.loopia.se/RPCSERV" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_loopia_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
LOOPIA_User="${LOOPIA_User:-$(_readaccountconf_mutable LOOPIA_User)}" |
|||
LOOPIA_Password="${LOOPIA_Password:-$(_readaccountconf_mutable LOOPIA_Password)}" |
|||
if [ -z "$LOOPIA_User" ] || [ -z "$LOOPIA_Password" ]; then |
|||
LOOPIA_User="" |
|||
LOOPIA_Password="" |
|||
_err "You don't specify loopia user and password yet." |
|||
_err "Please create you key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the api key and email to the account conf file. |
|||
_saveaccountconf_mutable LOOPIA_User "$LOOPIA_User" |
|||
_saveaccountconf_mutable LOOPIA_Password "$LOOPIA_Password" |
|||
|
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
_debug _sub_domain "$_sub_domain" |
|||
_debug _domain "$_domain" |
|||
|
|||
_info "Adding record" |
|||
|
|||
_loopia_add_record "$_domain" "$_sub_domain" |
|||
_loopia_update_record "$_domain" "$_sub_domain" "$txtvalue" |
|||
|
|||
} |
|||
|
|||
dns_loopia_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
LOOPIA_User="${LOOPIA_User:-$(_readaccountconf_mutable LOOPIA_User)}" |
|||
LOOPIA_Password="${LOOPIA_Password:-$(_readaccountconf_mutable LOOPIA_Password)}" |
|||
if [ -z "$LOOPIA_User" ] || [ -z "$LOOPIA_Password" ]; then |
|||
LOOPIA_User="" |
|||
LOOPIA_Password="" |
|||
_err "You don't specify LOOPIA user and password yet." |
|||
_err "Please create you key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the api key and email to the account conf file. |
|||
_saveaccountconf_mutable LOOPIA_User "$LOOPIA_User" |
|||
_saveaccountconf_mutable LOOPIA_Password "$LOOPIA_Password" |
|||
|
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>removeSubdomain</methodName> |
|||
<params> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' $LOOPIA_User $LOOPIA_Password "$_domain" "$_sub_domain") |
|||
|
|||
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "OK"; then |
|||
_err "Error could not get txt records" |
|||
return 1 |
|||
fi |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
_get_root() { |
|||
domain=$1 |
|||
_debug "get root" |
|||
|
|||
domain=$1 |
|||
i=2 |
|||
p=1 |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>getDomains</methodName> |
|||
<params> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' $LOOPIA_User $LOOPIA_Password) |
|||
|
|||
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
|||
while true; do |
|||
h=$(echo "$domain" | cut -d . -f $i-100) |
|||
if [ -z "$h" ]; then |
|||
#not valid |
|||
return 1 |
|||
fi |
|||
|
|||
if _contains "$response" "$h"; then |
|||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
|||
_domain="$h" |
|||
return 0 |
|||
fi |
|||
p=$i |
|||
i=$(_math "$i" + 1) |
|||
done |
|||
return 1 |
|||
|
|||
} |
|||
|
|||
_loopia_update_record() { |
|||
domain=$1 |
|||
sub_domain=$2 |
|||
txtval=$3 |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>updateZoneRecord</methodName> |
|||
<params> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<struct> |
|||
<member> |
|||
<name>type</name> |
|||
<value><string>TXT</string></value> |
|||
</member> |
|||
<member> |
|||
<name>priority</name> |
|||
<value><int>0</int></value> |
|||
</member> |
|||
<member> |
|||
<name>ttl</name> |
|||
<value><int>60</int></value> |
|||
</member> |
|||
<member> |
|||
<name>rdata</name> |
|||
<value><string>%s</string></value> |
|||
</member> |
|||
<member> |
|||
<name>record_id</name> |
|||
<value><int>0</int></value> |
|||
</member> |
|||
</struct> |
|||
</param> |
|||
</params> |
|||
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain" "$txtval") |
|||
|
|||
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "OK"; then |
|||
_err "Error" |
|||
return 1 |
|||
fi |
|||
return 0 |
|||
} |
|||
|
|||
_loopia_add_record() { |
|||
domain=$1 |
|||
sub_domain=$2 |
|||
|
|||
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
|||
<methodCall> |
|||
<methodName>addSubdomain</methodName> |
|||
<params> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
<param> |
|||
<value><string>%s</string></value> |
|||
</param> |
|||
</params> |
|||
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain") |
|||
|
|||
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
|||
|
|||
if ! _contains "$response" "OK"; then |
|||
_err "Error" |
|||
return 1 |
|||
fi |
|||
return 0 |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
#!/usr/bin/env sh |
|||
# |
|||
# tele3.cz DNS API |
|||
# |
|||
# Author: Roman Blizik |
|||
# Report Bugs here: https://github.com/par-pa/acme.sh |
|||
# |
|||
# -- |
|||
# export TELE3_Key="MS2I4uPPaI..." |
|||
# export TELE3_Secret="kjhOIHGJKHg" |
|||
# -- |
|||
|
|||
TELE3_API="https://www.tele3.cz/acme/" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
dns_tele3_add() { |
|||
_info "Using TELE3 DNS" |
|||
data="\"ope\":\"add\", \"domain\":\"$1\", \"value\":\"$2\"" |
|||
if ! _tele3_call; then |
|||
_err "Publish zone failed" |
|||
return 1 |
|||
fi |
|||
|
|||
_info "Zone published" |
|||
} |
|||
|
|||
dns_tele3_rm() { |
|||
_info "Using TELE3 DNS" |
|||
data="\"ope\":\"rm\", \"domain\":\"$1\", \"value\":\"$2\"" |
|||
if ! _tele3_call; then |
|||
_err "delete TXT record failed" |
|||
return 1 |
|||
fi |
|||
|
|||
_info "TXT record successfully deleted" |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
_tele3_init() { |
|||
TELE3_Key="${TELE3_Key:-$(_readaccountconf_mutable TELE3_Key)}" |
|||
TELE3_Secret="${TELE3_Secret:-$(_readaccountconf_mutable TELE3_Secret)}" |
|||
if [ -z "$TELE3_Key" ] || [ -z "$TELE3_Secret" ]; then |
|||
TELE3_Key="" |
|||
TELE3_Secret="" |
|||
_err "You must export variables: TELE3_Key and TELE3_Secret" |
|||
return 1 |
|||
fi |
|||
|
|||
#save the config variables to the account conf file. |
|||
_saveaccountconf_mutable TELE3_Key "$TELE3_Key" |
|||
_saveaccountconf_mutable TELE3_Secret "$TELE3_Secret" |
|||
} |
|||
|
|||
_tele3_call() { |
|||
_tele3_init |
|||
data="{\"key\":\"$TELE3_Key\", \"secret\":\"$TELE3_Secret\", $data}" |
|||
|
|||
_debug data "$data" |
|||
|
|||
response="$(_post "$data" "$TELE3_API" "" "POST")" |
|||
_debug response "$response" |
|||
|
|||
if [ "$response" != "success" ]; then |
|||
_err "$response" |
|||
return 1 |
|||
fi |
|||
} |
|||
@ -0,0 +1,139 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
Zilore_API="https://api.zilore.com/dns/v1" |
|||
# Zilore_Key="YOUR-ZILORE-API-KEY" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
dns_zilore_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
_info "Using Zilore" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
Zilore_Key="${Zilore_Key:-$(_readaccountconf_mutable Zilore_Key)}" |
|||
if [ -z "$Zilore_Key" ]; then |
|||
Zilore_Key="" |
|||
_err "Please define Zilore API key" |
|||
return 1 |
|||
fi |
|||
_saveaccountconf_mutable Zilore_Key "$Zilore_Key" |
|||
|
|||
if ! _get_root "$fulldomain"; then |
|||
_err "Unable to determine root domain" |
|||
return 1 |
|||
else |
|||
_debug _domain "$_domain" |
|||
fi |
|||
|
|||
if _zilore_rest POST "domains/$_domain/records?record_type=TXT&record_ttl=600&record_name=$fulldomain&record_value=\"$txtvalue\""; then |
|||
if _contains "$response" '"added"' >/dev/null; then |
|||
_info "Added TXT record, waiting for validation" |
|||
return 0 |
|||
else |
|||
_debug response "$response" |
|||
_err "Error while adding DNS records" |
|||
return 1 |
|||
fi |
|||
fi |
|||
|
|||
return 1 |
|||
} |
|||
|
|||
dns_zilore_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
_info "Using Zilore" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
Zilore_Key="${Zilore_Key:-$(_readaccountconf_mutable Zilore_Key)}" |
|||
if [ -z "$Zilore_Key" ]; then |
|||
Zilore_Key="" |
|||
_err "Please define Zilore API key" |
|||
return 1 |
|||
fi |
|||
_saveaccountconf_mutable Zilore_Key "$Zilore_Key" |
|||
|
|||
if ! _get_root "$fulldomain"; then |
|||
_err "Unable to determine root domain" |
|||
return 1 |
|||
else |
|||
_debug _domain "$_domain" |
|||
fi |
|||
|
|||
_debug "Getting TXT records" |
|||
_zilore_rest GET "domains/${_domain}/records?search_text=$txtvalue&search_record_type=TXT" |
|||
_debug response "$response" |
|||
|
|||
if ! _contains "$response" '"ok"' >/dev/null; then |
|||
_err "Error while getting records list" |
|||
return 1 |
|||
else |
|||
_record_id=$(printf "%s\n" "$response" | _egrep_o "\"record_id\":\"[^\"]+\"" | cut -d : -f 2 | tr -d \" | _head_n 1) |
|||
if [ -z "$_record_id" ]; then |
|||
_err "Cannot determine _record_id" |
|||
return 1 |
|||
else |
|||
_debug _record_id "$_record_id" |
|||
fi |
|||
if ! _zilore_rest DELETE "domains/${_domain}/records?record_id=$_record_id"; then |
|||
_err "Error while deleting chosen record" |
|||
return 1 |
|||
fi |
|||
_contains "$response" '"ok"' |
|||
fi |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
_get_root() { |
|||
domain=$1 |
|||
i=2 |
|||
while true; do |
|||
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
|||
_debug h "$h" |
|||
if [ -z "$h" ]; then |
|||
#not valid |
|||
return 1 |
|||
fi |
|||
|
|||
if ! _zilore_rest GET "domains?search_text=$h"; then |
|||
return 1 |
|||
fi |
|||
|
|||
if _contains "$response" "\"$h\"" >/dev/null; then |
|||
_domain=$h |
|||
return 0 |
|||
else |
|||
_debug "$h not found" |
|||
fi |
|||
i=$(_math "$i" + 1) |
|||
done |
|||
return 1 |
|||
} |
|||
|
|||
_zilore_rest() { |
|||
method=$1 |
|||
param=$2 |
|||
data=$3 |
|||
|
|||
export _H1="X-Auth-Key: $Zilore_Key" |
|||
|
|||
if [ "$method" != "GET" ]; then |
|||
response="$(_post "$data" "$Zilore_API/$param" "" "$method")" |
|||
else |
|||
response="$(_get "$Zilore_API/$param")" |
|||
fi |
|||
|
|||
if [ "$?" != "0" ]; then |
|||
_err "error $param" |
|||
return 1 |
|||
fi |
|||
|
|||
_debug2 response "$response" |
|||
return 0 |
|||
} |
|||
@ -0,0 +1,85 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
# |
|||
#ZM_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|||
# |
|||
#https://zonomi.com dns api |
|||
|
|||
ZM_Api="https://zonomi.com/app/dns/dyndns.jsp" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_zonomi_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
ZM_Key="${ZM_Key:-$(_readaccountconf_mutable ZM_Key)}" |
|||
|
|||
if [ -z "$ZM_Key" ]; then |
|||
ZM_Key="" |
|||
_err "You don't specify zonomi api key yet." |
|||
_err "Please create your key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the api key to the account conf file. |
|||
_saveaccountconf_mutable ZM_Key "$ZM_Key" |
|||
|
|||
_info "Get existing txt records for $fulldomain" |
|||
if ! _zm_request "action=QUERY&name=$fulldomain"; then |
|||
_err "error" |
|||
return 1 |
|||
fi |
|||
|
|||
if _contains "$response" "<record"; then |
|||
_debug "get and update records" |
|||
_qstr="action[1]=SET&type[1]=TXT&name[1]=$fulldomain&value[1]=$txtvalue" |
|||
_qindex=2 |
|||
for t in $(echo "$response" | tr -d "\r\n" | _egrep_o '<action.*</action>' | tr "<" "\n" | grep record | grep 'type="TXT"' | cut -d '"' -f 6); do |
|||
_debug2 t "$t" |
|||
_qstr="$_qstr&action[$_qindex]=SET&type[$_qindex]=TXT&name[$_qindex]=$fulldomain&value[$_qindex]=$t" |
|||
_qindex="$(_math "$_qindex" + 1)" |
|||
done |
|||
_zm_request "$_qstr" |
|||
else |
|||
_debug "Just add record" |
|||
_zm_request "action=SET&type=TXT&name=$fulldomain&value=$txtvalue" |
|||
fi |
|||
|
|||
} |
|||
|
|||
#fulldomain txtvalue |
|||
dns_zonomi_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
ZM_Key="${ZM_Key:-$(_readaccountconf_mutable ZM_Key)}" |
|||
if [ -z "$ZM_Key" ]; then |
|||
ZM_Key="" |
|||
_err "You don't specify zonomi api key yet." |
|||
_err "Please create your key and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
_zm_request "action=DELETE&type=TXT&name=$fulldomain" |
|||
|
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
#qstr |
|||
_zm_request() { |
|||
qstr="$1" |
|||
|
|||
_debug2 "qstr" "$qstr" |
|||
|
|||
_zm_url="$ZM_Api?api_key=$ZM_Key&$qstr" |
|||
_debug2 "_zm_url" "$_zm_url" |
|||
response="$(_get "$_zm_url")" |
|||
|
|||
if [ "$?" != "0" ]; then |
|||
return 1 |
|||
fi |
|||
_debug2 response "$response" |
|||
_contains "$response" "<is_ok>OK:" |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue