58 changed files with 6125 additions and 1655 deletions
-
4Dockerfile
-
121README.md
-
751acme.sh
-
255deploy/README.md
-
18deploy/cpanel_uapi.sh
-
12deploy/fritzbox.sh
-
140deploy/gcore_cdn.sh
-
80deploy/gitlab.sh
-
36deploy/haproxy.sh
-
58deploy/mailcow.sh
-
59deploy/mydevil.sh
-
92deploy/qiniu.sh
-
6deploy/ssh.sh
-
12deploy/vault_cli.sh
-
899dnsapi/README.md
-
141dnsapi/dns_active24.sh
-
14dnsapi/dns_aws.sh
-
2dnsapi/dns_azure.sh
-
17dnsapi/dns_cf.sh
-
157dnsapi/dns_cn.sh
-
253dnsapi/dns_conoha.sh
-
4dnsapi/dns_cx.sh
-
204dnsapi/dns_desec.sh
-
155dnsapi/dns_dgon.sh
-
2dnsapi/dns_dnsimple.sh
-
59dnsapi/dns_doapi.sh
-
2dnsapi/dns_dp.sh
-
161dnsapi/dns_dpi.sh
-
26dnsapi/dns_dynu.sh
-
358dnsapi/dns_euserv.sh
-
168dnsapi/dns_exoscale.sh
-
62dnsapi/dns_gandi_livedns.sh
-
167dnsapi/dns_gcloud.sh
-
168dnsapi/dns_gdnsdk.sh
-
4dnsapi/dns_he.sh
-
162dnsapi/dns_hostingde.sh
-
3dnsapi/dns_inwx.sh
-
4dnsapi/dns_ispconfig.sh
-
55dnsapi/dns_lexicon.sh
-
185dnsapi/dns_linode_v4.sh
-
77dnsapi/dns_loopia.sh
-
97dnsapi/dns_mydevil.sh
-
210dnsapi/dns_mydnsjp.sh
-
407dnsapi/dns_namecheap.sh
-
19dnsapi/dns_namecom.sh
-
131dnsapi/dns_nederhost.sh
-
181dnsapi/dns_neodigit.sh
-
134dnsapi/dns_netcup.sh
-
4dnsapi/dns_nsone.sh
-
27dnsapi/dns_nsupdate.sh
-
211dnsapi/dns_nw.sh
-
217dnsapi/dns_online.sh
-
244dnsapi/dns_openprovider.sh
-
164dnsapi/dns_pointhq.sh
-
207dnsapi/dns_rackspace.sh
-
164dnsapi/dns_ultra.sh
-
61dnsapi/dns_unoeuro.sh
-
149dnsapi/dns_zone.sh
751
acme.sh
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,257 +1,6 @@ |
|||||
# Using deploy api |
# Using deploy api |
||||
|
|
||||
Before you can deploy your cert, you must [issue the cert first](https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert). |
|
||||
|
deploy hook usage: |
||||
|
|
||||
Here are the scripts to deploy the certs/key to the server/services. |
|
||||
|
https://github.com/Neilpang/acme.sh/wiki/deployhooks |
||||
|
|
||||
## 1. Deploy the certs to your cpanel host |
|
||||
|
|
||||
If you want to deploy using cpanel UAPI see 7. |
|
||||
|
|
||||
(cpanel deploy hook is not finished yet, this is just an example.) |
|
||||
|
|
||||
|
|
||||
|
|
||||
Then you can deploy now: |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_CPANEL_USER=myusername |
|
||||
export DEPLOY_CPANEL_PASSWORD=PASSWORD |
|
||||
acme.sh --deploy -d example.com --deploy-hook cpanel |
|
||||
``` |
|
||||
|
|
||||
## 2. Deploy ssl cert on kong proxy engine based on api |
|
||||
|
|
||||
Before you can deploy your cert, you must [issue the cert first](https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert). |
|
||||
Currently supports Kong-v0.10.x. |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook kong |
|
||||
``` |
|
||||
|
|
||||
## 3. Deploy the cert to remote server through SSH access |
|
||||
|
|
||||
The ssh deploy plugin allows you to deploy certificates to a remote host |
|
||||
using SSH command to connect to the remote server. The ssh plugin is invoked |
|
||||
with the following command... |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d example.com --deploy-hook ssh |
|
||||
``` |
|
||||
Prior to running this for the first time you must tell the plugin where |
|
||||
and how to deploy the certificates. This is done by exporting the following |
|
||||
environment variables. This is not required for subsequent runs as the |
|
||||
values are stored by acme.sh in the domain configuration files. |
|
||||
|
|
||||
Required... |
|
||||
``` |
|
||||
export DEPLOY_SSH_USER=username |
|
||||
``` |
|
||||
Optional... |
|
||||
``` |
|
||||
export DEPLOY_SSH_CMD=custom ssh command |
|
||||
export DEPLOY_SSH_SERVER=url or ip address of remote host |
|
||||
export DEPLOY_SSH_KEYFILE=filename for private key |
|
||||
export DEPLOY_SSH_CERTFILE=filename for certificate file |
|
||||
export DEPLOY_SSH_CAFILE=filename for intermediate CA file |
|
||||
export DEPLOY_SSH_FULLCHAIN=filename for fullchain file |
|
||||
export DEPLOY_SSH_REMOTE_CMD=command to execute on remote host |
|
||||
export DEPLOY_SSH_BACKUP=yes or no |
|
||||
``` |
|
||||
|
|
||||
**DEPLOY_SSH_USER** |
|
||||
Username at the remote host that SSH will login with. 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@URL from the host running acme.sh before using this script. |
|
||||
|
|
||||
The USER@URL at the remote server must also have has permissions to write to |
|
||||
the target location of the certificate files and to execute any commands |
|
||||
(e.g. to stop/start services). |
|
||||
|
|
||||
**DEPLOY_SSH_CMD** |
|
||||
You can customize the ssh command used to connect to the remote host. For example |
|
||||
if you need to connect to a specific port at the remote server you can set this |
|
||||
to, for example, "ssh -p 22" or to use `sshpass` to provide password inline |
|
||||
instead of exchanging ssh keys (this is not recommended, using keys is |
|
||||
more secure). |
|
||||
|
|
||||
**DEPLOY_SSH_SERVER** |
|
||||
URL or IP Address of the remote server. If not provided then the domain |
|
||||
name provided on the acme.sh --deploy command line is used. |
|
||||
|
|
||||
**DEPLOY_SSH_KEYFILE** |
|
||||
Target filename for the private key issued by LetsEncrypt. |
|
||||
|
|
||||
**DEPLOY_SSH_CERTFILE** |
|
||||
Target filename for the certificate issued by LetsEncrypt. |
|
||||
If this is the same as the previous filename (for keyfile) then it is |
|
||||
appended to the same file. |
|
||||
|
|
||||
**DEPLOY_SSH_CAFILE** |
|
||||
Target filename for the CA intermediate certificate issued by LetsEncrypt. |
|
||||
If this is the same as a previous filename (for keyfile or certfile) then |
|
||||
it is appended to the same file. |
|
||||
|
|
||||
**DEPLOY_SSH_FULLCHAIN** |
|
||||
Target filename for the fullchain certificate issued by LetsEncrypt. |
|
||||
If this is the same as a previous filename (for keyfile, certfile or |
|
||||
cafile) then it is appended to the same file. |
|
||||
|
|
||||
**DEPLOY_SSH_REMOTE_CMD** |
|
||||
Command to execute on the remote server after copying any certificates. This |
|
||||
could be any additional command required for example to stop and restart |
|
||||
the service. |
|
||||
|
|
||||
**DEPLOY_SSH_BACKUP** |
|
||||
Before writing a certificate file to the remote server the existing |
|
||||
certificate will be copied to a backup directory on the remote server. |
|
||||
These are placed in a hidden directory in the home directory of the SSH |
|
||||
user |
|
||||
```sh |
|
||||
~/.acme_ssh_deploy/[domain name]-backup-[timestamp] |
|
||||
``` |
|
||||
Any backups older than 180 days will be deleted when new certificates |
|
||||
are deployed. This defaults to "yes" set to "no" to disable backup. |
|
||||
|
|
||||
###Examples using SSH deploy |
|
||||
The following example illustrates deploying certificates to a QNAP NAS |
|
||||
(tested with QTS version 4.2.3) |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_SSH_USER="admin" |
|
||||
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_REMOTE_CMD="/etc/init.d/stunnel.sh restart" |
|
||||
|
|
||||
acme.sh --deploy -d qnap.example.com --deploy-hook ssh |
|
||||
``` |
|
||||
Note how in this example both the private key and certificate point to |
|
||||
the same file. This will result in the certificate being appended |
|
||||
to the same file as the private key... a common requirement of several |
|
||||
services. |
|
||||
|
|
||||
The next example illustrates deploying certificates to a Unifi |
|
||||
Controller (tested with version 5.4.11). |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_SSH_USER="root" |
|
||||
export DEPLOY_SSH_KEYFILE="/var/lib/unifi/unifi.example.com.key" |
|
||||
export DEPLOY_SSH_FULLCHAIN="/var/lib/unifi/unifi.example.com.cer" |
|
||||
export DEPLOY_SSH_REMOTE_CMD="openssl pkcs12 -export \ |
|
||||
-inkey /var/lib/unifi/unifi.example.com.key \ |
|
||||
-in /var/lib/unifi/unifi.example.com.cer \ |
|
||||
-out /var/lib/unifi/unifi.example.com.p12 \ |
|
||||
-name ubnt -password pass:temppass \ |
|
||||
&& keytool -importkeystore -deststorepass aircontrolenterprise \ |
|
||||
-destkeypass aircontrolenterprise \ |
|
||||
-destkeystore /var/lib/unifi/keystore \ |
|
||||
-srckeystore /var/lib/unifi/unifi.example.com.p12 \ |
|
||||
-srcstoretype PKCS12 -srcstorepass temppass -alias ubnt -noprompt \ |
|
||||
&& service unifi restart" |
|
||||
|
|
||||
acme.sh --deploy -d unifi.example.com --deploy-hook ssh |
|
||||
``` |
|
||||
In this example we execute several commands on the remote host |
|
||||
after the certificate files have been copied... to generate a pkcs12 file |
|
||||
compatible with Unifi, to import it into the Unifi keystore and then finally |
|
||||
to restart the service. |
|
||||
|
|
||||
Note also that once the certificate is imported |
|
||||
into the keystore the individual certificate files are no longer |
|
||||
required. We could if we desired delete those files immediately. If we |
|
||||
do that then we should disable backup at the remote host (as there are |
|
||||
no files to backup -- they were erased during deployment). For example... |
|
||||
```sh |
|
||||
export DEPLOY_SSH_BACKUP=no |
|
||||
# modify the end of the remote command... |
|
||||
&& rm /var/lib/unifi/unifi.example.com.key \ |
|
||||
/var/lib/unifi/unifi.example.com.cer \ |
|
||||
/var/lib/unifi/unifi.example.com.p12 \ |
|
||||
&& service unifi restart |
|
||||
``` |
|
||||
|
|
||||
## 4. Deploy the cert to local vsftpd server |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook vsftpd |
|
||||
``` |
|
||||
|
|
||||
The default vsftpd conf file is `/etc/vsftpd.conf`, if your vsftpd conf is not in the default location, you can specify one: |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_VSFTPD_CONF="/etc/vsftpd.conf" |
|
||||
|
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook vsftpd |
|
||||
``` |
|
||||
|
|
||||
The default command to restart vsftpd server is `service vsftpd restart`, if it doesn't work, you can specify one: |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_VSFTPD_RELOAD="/etc/init.d/vsftpd restart" |
|
||||
|
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook vsftpd |
|
||||
``` |
|
||||
|
|
||||
## 5. Deploy the cert to local exim4 server |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook exim4 |
|
||||
``` |
|
||||
|
|
||||
The default exim4 conf file is `/etc/exim/exim.conf`, if your exim4 conf is not in the default location, you can specify one: |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_EXIM4_CONF="/etc/exim4/exim4.conf.template" |
|
||||
|
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook exim4 |
|
||||
``` |
|
||||
|
|
||||
The default command to restart exim4 server is `service exim4 restart`, if it doesn't work, you can specify one: |
|
||||
|
|
||||
```sh |
|
||||
export DEPLOY_EXIM4_RELOAD="/etc/init.d/exim4 restart" |
|
||||
|
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook exim4 |
|
||||
``` |
|
||||
|
|
||||
## 6. Deploy the cert to OSX Keychain |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook keychain |
|
||||
``` |
|
||||
|
|
||||
## 7. Deploy to cpanel host using UAPI |
|
||||
|
|
||||
This hook is using UAPI and works in cPanel & WHM version 56 or newer. |
|
||||
``` |
|
||||
acme.sh --deploy -d example.com --deploy-hook cpanel_uapi |
|
||||
``` |
|
||||
DEPLOY_CPANEL_USER is required only if you run the script as root and it should contain cpanel username. |
|
||||
```sh |
|
||||
export DEPLOY_CPANEL_USER=username |
|
||||
acme.sh --deploy -d example.com --deploy-hook cpanel_uapi |
|
||||
``` |
|
||||
Please note, that the cpanel_uapi hook will deploy only the first domain when your certificate will automatically renew. Therefore you should issue a separate certificate for each domain. |
|
||||
|
|
||||
## 8. Deploy the cert to your FRITZ!Box router |
|
||||
|
|
||||
You must specify the credentials that have administrative privileges on the FRITZ!Box in order to deploy the certificate, plus the URL of your FRITZ!Box, through the following environment variables: |
|
||||
```sh |
|
||||
$ export DEPLOY_FRITZBOX_USERNAME=my_username |
|
||||
$ export DEPLOY_FRITZBOX_PASSWORD=the_password |
|
||||
$ export DEPLOY_FRITZBOX_URL=https://fritzbox.example.com |
|
||||
``` |
|
||||
|
|
||||
After the first deployment, these values will be stored in your $HOME/.acme.sh/account.conf. You may now deploy the certificate like this: |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d fritzbox.example.com --deploy-hook fritzbox |
|
||||
``` |
|
||||
|
|
||||
## 9. Deploy the cert to strongswan |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --deploy -d ftp.example.com --deploy-hook strongswan |
|
||||
``` |
|
||||
@ -0,0 +1,140 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Here is the script to deploy the cert to G-Core CDN service (https://gcorelabs.com/ru/) using the G-Core Labs API (https://docs.gcorelabs.com/cdn/). |
||||
|
# Uses command line curl for send requests and jq for parse responses. |
||||
|
# Returns 0 when success. |
||||
|
# |
||||
|
# Written by temoffey <temofffey@gmail.com> |
||||
|
# Public domain, 2019 |
||||
|
|
||||
|
#export DEPLOY_GCORE_CDN_USERNAME=myusername |
||||
|
#export DEPLOY_GCORE_CDN_PASSWORD=mypassword |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#domain keyfile certfile cafile fullchain |
||||
|
|
||||
|
gcore_cdn_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" |
||||
|
|
||||
|
_fullchain=$(tr '\n\r' '@#' <"$_cfullchain" | sed 's/@/\\n/g;s/#/\\r/g') |
||||
|
_key=$(tr '\n\r' '@#' <"$_ckey" | sed 's/@/\\n/g;s/#/\\r/g') |
||||
|
|
||||
|
_debug _fullchain "$_fullchain" |
||||
|
_debug _key "$_key" |
||||
|
|
||||
|
if [ -z "$DEPLOY_GCORE_CDN_USERNAME" ]; then |
||||
|
if [ -z "$Le_Deploy_gcore_cdn_username" ]; then |
||||
|
_err "Please define the target username: export DEPLOY_GCORE_CDN_USERNAME=username" |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gcore_cdn_username="$DEPLOY_GCORE_CDN_USERNAME" |
||||
|
_savedomainconf Le_Deploy_gcore_cdn_username "$Le_Deploy_gcore_cdn_username" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$DEPLOY_GCORE_CDN_PASSWORD" ]; then |
||||
|
if [ -z "$Le_Deploy_gcore_cdn_password" ]; then |
||||
|
_err "Please define the target password: export DEPLOY_GCORE_CDN_PASSWORD=password" |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gcore_cdn_password="$DEPLOY_GCORE_CDN_PASSWORD" |
||||
|
_savedomainconf Le_Deploy_gcore_cdn_password "$Le_Deploy_gcore_cdn_password" |
||||
|
fi |
||||
|
|
||||
|
_info "Get authorization token" |
||||
|
_request="{\"username\":\"$Le_Deploy_gcore_cdn_username\",\"password\":\"$Le_Deploy_gcore_cdn_password\"}" |
||||
|
_debug _request "$_request" |
||||
|
export _H1="Content-Type:application/json" |
||||
|
_response=$(_post "$_request" "https://api.gcdn.co/auth/signin") |
||||
|
_debug _response "$_response" |
||||
|
_regex=".*\"token\":\"\([-._0-9A-Za-z]*\)\".*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_token=$(echo "$_response" | sed -n "s/$_regex/\1/p") |
||||
|
_debug _token "$_token" |
||||
|
|
||||
|
if [ -z "$_token" ]; then |
||||
|
_err "Error G-Core Labs API authorization" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Find CDN resource with cname $_cdomain" |
||||
|
export _H2="Authorization:Token $_token" |
||||
|
_response=$(_get "https://api.gcdn.co/resources") |
||||
|
_debug _response "$_response" |
||||
|
_regex=".*(\"id\".*?\"cname\":\"$_cdomain\".*?})" |
||||
|
_regex="^.*\"cname\":\"$_cdomain\".*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_resource=$(echo "$_response" | sed 's/},{/},\n{/g' | _egrep_o "$_regex") |
||||
|
_debug _resource "$_resource" |
||||
|
_regex=".*\"id\":\([0-9]*\),.*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_resourceId=$(echo "$_resource" | sed -n "s/$_regex/\1/p") |
||||
|
_debug _resourceId "$_resourceId" |
||||
|
_regex=".*\"sslData\":\([0-9]*\)}.*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_sslDataOld=$(echo "$_resource" | sed -n "s/$_regex/\1/p") |
||||
|
_debug _sslDataOld "$_sslDataOld" |
||||
|
_regex=".*\"originGroup\":\([0-9]*\),.*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_originGroup=$(echo "$_resource" | sed -n "s/$_regex/\1/p") |
||||
|
_debug _originGroup "$_originGroup" |
||||
|
|
||||
|
if [ -z "$_resourceId" ] || [ -z "$_originGroup" ]; then |
||||
|
_err "Not found CDN resource with cname $_cdomain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Add new SSL certificate" |
||||
|
_date=$(date "+%d.%m.%Y %H:%M:%S") |
||||
|
_request="{\"name\":\"$_cdomain ($_date)\",\"sslCertificate\":\"$_fullchain\",\"sslPrivateKey\":\"$_key\"}" |
||||
|
_debug _request "$_request" |
||||
|
_response=$(_post "$_request" "https://api.gcdn.co/sslData") |
||||
|
_debug _response "$_response" |
||||
|
_regex=".*\"id\":\([0-9]*\),.*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_sslDataAdd=$(echo "$_response" | sed -n "s/$_regex/\1/p") |
||||
|
_debug _sslDataAdd "$_sslDataAdd" |
||||
|
|
||||
|
if [ -z "$_sslDataAdd" ]; then |
||||
|
_err "Error new SSL certificate add" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Update CDN resource" |
||||
|
_request="{\"originGroup\":$_originGroup,\"sslData\":$_sslDataAdd}" |
||||
|
_debug _request "$_request" |
||||
|
_response=$(_post "$_request" "https://api.gcdn.co/resources/$_resourceId" '' "PUT") |
||||
|
_debug _response "$_response" |
||||
|
_regex=".*\"sslData\":\([0-9]*\)}.*$" |
||||
|
_debug _regex "$_regex" |
||||
|
_sslDataNew=$(echo "$_response" | sed -n "s/$_regex/\1/p") |
||||
|
_debug _sslDataNew "$_sslDataNew" |
||||
|
|
||||
|
if [ "$_sslDataNew" != "$_sslDataAdd" ]; then |
||||
|
_err "Error CDN resource update" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$_sslDataOld" ] || [ "$_sslDataOld" = "null" ]; then |
||||
|
_info "Not found old SSL certificate" |
||||
|
else |
||||
|
_info "Delete old SSL certificate" |
||||
|
_response=$(_post '' "https://api.gcdn.co/sslData/$_sslDataOld" '' "DELETE") |
||||
|
_debug _response "$_response" |
||||
|
fi |
||||
|
|
||||
|
_info "Certificate successfully deployed" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Script to deploy certificate to a Gitlab hosted page |
||||
|
|
||||
|
# The following variables exported from environment will be used. |
||||
|
# If not set then values previously saved in domain.conf file are used. |
||||
|
|
||||
|
# All the variables are required |
||||
|
|
||||
|
# export GITLAB_TOKEN="xxxxxxx" |
||||
|
# export GITLAB_PROJECT_ID=012345 |
||||
|
# export GITLAB_DOMAIN="mydomain.com" |
||||
|
|
||||
|
gitlab_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" |
||||
|
|
||||
|
if [ -z "$GITLAB_TOKEN" ]; then |
||||
|
if [ -z "$Le_Deploy_gitlab_token" ]; then |
||||
|
_err "GITLAB_TOKEN not defined." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gitlab_token="$GITLAB_TOKEN" |
||||
|
_savedomainconf Le_Deploy_gitlab_token "$Le_Deploy_gitlab_token" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$GITLAB_PROJECT_ID" ]; then |
||||
|
if [ -z "$Le_Deploy_gitlab_project_id" ]; then |
||||
|
_err "GITLAB_PROJECT_ID not defined." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gitlab_project_id="$GITLAB_PROJECT_ID" |
||||
|
_savedomainconf Le_Deploy_gitlab_project_id "$Le_Deploy_gitlab_project_id" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$GITLAB_DOMAIN" ]; then |
||||
|
if [ -z "$Le_Deploy_gitlab_domain" ]; then |
||||
|
_err "GITLAB_DOMAIN not defined." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gitlab_domain="$GITLAB_DOMAIN" |
||||
|
_savedomainconf Le_Deploy_gitlab_domain "$Le_Deploy_gitlab_domain" |
||||
|
fi |
||||
|
|
||||
|
string_fullchain=$(_url_encode <"$_cfullchain") |
||||
|
string_key=$(_url_encode <"$_ckey") |
||||
|
|
||||
|
body="certificate=$string_fullchain&key=$string_key" |
||||
|
|
||||
|
export _H1="PRIVATE-TOKEN: $Le_Deploy_gitlab_token" |
||||
|
|
||||
|
gitlab_url="https://gitlab.com/api/v4/projects/$Le_Deploy_gitlab_project_id/pages/domains/$Le_Deploy_gitlab_domain" |
||||
|
|
||||
|
_response=$(_post "$body" "$gitlab_url" 0 PUT | _dbase64 "multiline") |
||||
|
|
||||
|
error_response="error" |
||||
|
|
||||
|
if test "${_response#*$error_response}" != "$_response"; then |
||||
|
_err "Error in deploying certificate:" |
||||
|
_err "$_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug response "$_response" |
||||
|
_info "Certificate successfully deployed" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Here is a script to deploy cert to mailcow. |
||||
|
|
||||
|
#returns 0 means success, otherwise error. |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#domain keyfile certfile cafile fullchain |
||||
|
mailcow_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" |
||||
|
|
||||
|
_mailcow_path="${DEPLOY_MAILCOW_PATH}" |
||||
|
|
||||
|
if [ -z "$_mailcow_path" ]; then |
||||
|
_err "Mailcow path is not found, please define DEPLOY_MAILCOW_PATH." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_ssl_path="${_mailcow_path}/data/assets/ssl/" |
||||
|
if [ ! -d "$_ssl_path" ]; then |
||||
|
_err "Cannot find mailcow ssl path: $_ssl_path" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Copying key and cert" |
||||
|
_real_key="$_ssl_path/key.pem" |
||||
|
if ! cat "$_ckey" >"$_real_key"; then |
||||
|
_err "Error: write key file to: $_real_key" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_real_fullchain="$_ssl_path/cert.pem" |
||||
|
if ! cat "$_cfullchain" >"$_real_fullchain"; then |
||||
|
_err "Error: write cert file to: $_real_fullchain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
DEFAULT_MAILCOW_RELOAD="cd ${_mailcow_path} && docker-compose restart postfix-mailcow dovecot-mailcow nginx-mailcow" |
||||
|
_reload="${DEPLOY_MAILCOW_RELOAD:-$DEFAULT_MAILCOW_RELOAD}" |
||||
|
|
||||
|
_info "Run reload: $_reload" |
||||
|
if eval "$_reload"; then |
||||
|
_info "Reload success!" |
||||
|
fi |
||||
|
return 0 |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,59 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# MyDevil.net API (2019-02-03) |
||||
|
# |
||||
|
# MyDevil.net already supports automatic Let's Encrypt certificates, |
||||
|
# except for wildcard domains. |
||||
|
# |
||||
|
# This script depends on `devil` command that MyDevil.net provides, |
||||
|
# which means that it works only on server side. |
||||
|
# |
||||
|
# Author: Marcin Konicki <https://ahwayakchih.neoni.net> |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: mydevil_deploy domain keyfile certfile cafile fullchain |
||||
|
mydevil_deploy() { |
||||
|
_cdomain="$1" |
||||
|
_ckey="$2" |
||||
|
_ccert="$3" |
||||
|
_cca="$4" |
||||
|
_cfullchain="$5" |
||||
|
ip="" |
||||
|
|
||||
|
_debug _cdomain "$_cdomain" |
||||
|
_debug _ckey "$_ckey" |
||||
|
_debug _ccert "$_ccert" |
||||
|
_debug _cca "$_cca" |
||||
|
_debug _cfullchain "$_cfullchain" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
ip=$(mydevil_get_ip "$_cdomain") |
||||
|
if [ -z "$ip" ]; then |
||||
|
_err "Could not find IP for domain $_cdomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Delete old certificate first |
||||
|
_info "Removing old certificate for $_cdomain at $ip" |
||||
|
devil ssl www del "$ip" "$_cdomain" |
||||
|
|
||||
|
# Add new certificate |
||||
|
_info "Adding new certificate for $_cdomain at $ip" |
||||
|
devil ssl www add "$ip" "$_cfullchain" "$_ckey" "$_cdomain" || return 1 |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Usage: ip=$(mydevil_get_ip domain.com) |
||||
|
# echo $ip |
||||
|
mydevil_get_ip() { |
||||
|
devil dns list "$1" | cut -w -s -f 3,7 | grep "^A$(printf '\t')" | cut -w -s -f 2 || return 1 |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Script to create certificate to qiniu.com |
||||
|
# |
||||
|
# This deployment required following variables |
||||
|
# export QINIU_AK="QINIUACCESSKEY" |
||||
|
# export QINIU_SK="QINIUSECRETKEY" |
||||
|
# export QINIU_CDN_DOMAIN="cdn.example.com" |
||||
|
|
||||
|
QINIU_API_BASE="https://api.qiniu.com" |
||||
|
|
||||
|
qiniu_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" |
||||
|
|
||||
|
if [ -z "$QINIU_AK" ]; then |
||||
|
_err "QINIU_AK is not defined." |
||||
|
return 1 |
||||
|
else |
||||
|
_savedomainconf QINIU_AK "$QINIU_AK" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$QINIU_SK" ]; then |
||||
|
_err "QINIU_SK is not defined." |
||||
|
return 1 |
||||
|
else |
||||
|
_savedomainconf QINIU_SK "$QINIU_SK" |
||||
|
fi |
||||
|
|
||||
|
if [ "$QINIU_CDN_DOMAIN" ]; then |
||||
|
_savedomainconf QINIU_CDN_DOMAIN "$QINIU_CDN_DOMAIN" |
||||
|
else |
||||
|
QINIU_CDN_DOMAIN="$_cdomain" |
||||
|
fi |
||||
|
|
||||
|
## upload certificate |
||||
|
string_fullchain=$(sed 's/$/\\n/' "$_cfullchain" | tr -d '\n') |
||||
|
string_key=$(sed 's/$/\\n/' "$_ckey" | tr -d '\n') |
||||
|
|
||||
|
sslcert_path="/sslcert" |
||||
|
sslcerl_body="{\"name\":\"$_cdomain\",\"common_name\":\"$QINIU_CDN_DOMAIN\",\"ca\":\"$string_fullchain\",\"pri\":\"$string_key\"}" |
||||
|
sslcert_access_token="$(_make_access_token "$sslcert_path")" |
||||
|
_debug sslcert_access_token "$sslcert_access_token" |
||||
|
export _H1="Authorization: QBox $sslcert_access_token" |
||||
|
sslcert_response=$(_post "$sslcerl_body" "$QINIU_API_BASE$sslcert_path" 0 "POST" "application/json" | _dbase64 "multiline") |
||||
|
|
||||
|
if ! _contains "$sslcert_response" "certID"; then |
||||
|
_err "Error in creating certificate:" |
||||
|
_err "$sslcert_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug sslcert_response "$sslcert_response" |
||||
|
_info "Certificate successfully uploaded, updating domain $_cdomain" |
||||
|
|
||||
|
## extract certId |
||||
|
_certId="$(printf "%s" "$sslcert_response" | _normalizeJson | _egrep_o "certID\": *\"[^\"]*\"" | cut -d : -f 2)" |
||||
|
_debug certId "$_certId" |
||||
|
|
||||
|
## update domain ssl config |
||||
|
update_path="/domain/$QINIU_CDN_DOMAIN/httpsconf" |
||||
|
update_body="{\"certid\":$_certId,\"forceHttps\":false}" |
||||
|
update_access_token="$(_make_access_token "$update_path")" |
||||
|
_debug update_access_token "$update_access_token" |
||||
|
export _H1="Authorization: QBox $update_access_token" |
||||
|
update_response=$(_post "$update_body" "$QINIU_API_BASE$update_path" 0 "PUT" "application/json" | _dbase64 "multiline") |
||||
|
|
||||
|
if _contains "$update_response" "error"; then |
||||
|
_err "Error in updating domain httpsconf:" |
||||
|
_err "$update_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug update_response "$update_response" |
||||
|
_info "Certificate successfully deployed" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_make_access_token() { |
||||
|
_token="$(printf "%s\n" "$1" | _hmac "sha1" "$(printf "%s" "$QINIU_SK" | _hex_dump | tr -d " ")" | _base64 | tr -- '+/' '-_')" |
||||
|
echo "$QINIU_AK:$_token" |
||||
|
} |
||||
@ -1,900 +1,5 @@ |
|||||
# How to use DNS API |
# How to use DNS API |
||||
|
DNS api usage: |
||||
|
|
||||
If your dns provider doesn't provide api access, you can use our dns alias mode: |
|
||||
|
https://github.com/Neilpang/acme.sh/wiki/dnsapi |
||||
|
|
||||
https://github.com/Neilpang/acme.sh/wiki/DNS-alias-mode |
|
||||
|
|
||||
## 1. Use CloudFlare domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your CloudFlare account to get your API key. |
|
||||
|
|
||||
``` |
|
||||
export CF_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
export CF_Email="xxxx@sss.com" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_cf -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `CF_Key` and `CF_Email` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 2. Use DNSPod.cn domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your DNSPod account to get your API Key and ID. |
|
||||
|
|
||||
``` |
|
||||
export DP_Id="1234" |
|
||||
export DP_Key="sADDsdasdgdsf" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_dp -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `DP_Id` and `DP_Key` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 3. Use CloudXNS.com domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your CloudXNS account to get your API Key and Secret. |
|
||||
|
|
||||
``` |
|
||||
export CX_Key="1234" |
|
||||
export CX_Secret="sADDsdasdgdsf" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_cx -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `CX_Key` and `CX_Secret` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 4. Use GoDaddy.com domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your GoDaddy account to get your API Key and Secret. |
|
||||
|
|
||||
https://developer.godaddy.com/keys/ |
|
||||
|
|
||||
Please create a Production key, instead of a Test key. |
|
||||
|
|
||||
``` |
|
||||
export GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
export GD_Secret="asdfsdafdsfdsfdsfdsfdsafd" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_gd -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `GD_Key` and `GD_Secret` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 5. Use PowerDNS embedded API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your PowerDNS account to enable the API and set your API-Token in the configuration. |
|
||||
|
|
||||
https://doc.powerdns.com/md/httpapi/README/ |
|
||||
|
|
||||
``` |
|
||||
export PDNS_Url="http://ns.example.com:8081" |
|
||||
export PDNS_ServerId="localhost" |
|
||||
export PDNS_Token="0123456789ABCDEF" |
|
||||
export PDNS_Ttl=60 |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_pdns -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `PDNS_Url`, `PDNS_ServerId`, `PDNS_Token` and `PDNS_Ttl` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 6. Use OVH/kimsufi/soyoustart/runabove API to automatically issue cert |
|
||||
|
|
||||
https://github.com/Neilpang/acme.sh/wiki/How-to-use-OVH-domain-api |
|
||||
|
|
||||
|
|
||||
## 7. Use nsupdate to automatically issue cert |
|
||||
|
|
||||
First, generate a key for updating the zone |
|
||||
``` |
|
||||
b=$(dnssec-keygen -a hmac-sha512 -b 512 -n USER -K /tmp foo) |
|
||||
cat > /etc/named/keys/update.key <<EOF |
|
||||
key "update" { |
|
||||
algorithm hmac-sha512; |
|
||||
secret "$(awk '/^Key/{print $2}' /tmp/$b.private)"; |
|
||||
}; |
|
||||
EOF |
|
||||
rm -f /tmp/$b.{private,key} |
|
||||
``` |
|
||||
|
|
||||
Include this key in your named configuration |
|
||||
``` |
|
||||
include "/etc/named/keys/update.key"; |
|
||||
``` |
|
||||
|
|
||||
Next, configure your zone to allow dynamic updates. |
|
||||
|
|
||||
Depending on your named version, use either |
|
||||
``` |
|
||||
zone "example.com" { |
|
||||
type master; |
|
||||
allow-update { key "update"; }; |
|
||||
}; |
|
||||
``` |
|
||||
or |
|
||||
``` |
|
||||
zone "example.com" { |
|
||||
type master; |
|
||||
update-policy { |
|
||||
grant update subdomain example.com.; |
|
||||
}; |
|
||||
} |
|
||||
``` |
|
||||
|
|
||||
Finally, make the DNS server and update Key available to `acme.sh` |
|
||||
|
|
||||
``` |
|
||||
export NSUPDATE_SERVER="dns.example.com" |
|
||||
export NSUPDATE_KEY="/path/to/your/nsupdate.key" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_nsupdate -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `NSUPDATE_SERVER` and `NSUPDATE_KEY` settings will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 8. Use LuaDNS domain API |
|
||||
|
|
||||
Get your API token at https://api.luadns.com/settings |
|
||||
|
|
||||
``` |
|
||||
export LUA_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
export LUA_Email="xxxx@sss.com" |
|
||||
``` |
|
||||
|
|
||||
To issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_lua -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `LUA_Key` and `LUA_Email` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 9. Use DNSMadeEasy domain API |
|
||||
|
|
||||
Get your API credentials at https://cp.dnsmadeeasy.com/account/info |
|
||||
|
|
||||
``` |
|
||||
export ME_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
export ME_Secret="qdfqsdfkjdskfj" |
|
||||
``` |
|
||||
|
|
||||
To issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_me -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `ME_Key` and `ME_Secret` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 10. Use Amazon Route53 domain API |
|
||||
|
|
||||
https://github.com/Neilpang/acme.sh/wiki/How-to-use-Amazon-Route53-API |
|
||||
|
|
||||
``` |
|
||||
export AWS_ACCESS_KEY_ID=XXXXXXXXXX |
|
||||
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXX |
|
||||
``` |
|
||||
|
|
||||
To issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_aws -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 11. Use Aliyun domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your Aliyun account to get your API key. |
|
||||
[https://ak-console.aliyun.com/#/accesskey](https://ak-console.aliyun.com/#/accesskey) |
|
||||
|
|
||||
``` |
|
||||
export Ali_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
export Ali_Secret="jlsdflanljkljlfdsaklkjflsa" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_ali -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `Ali_Key` and `Ali_Secret` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 12. Use ISPConfig 3.1 API |
|
||||
|
|
||||
This only works for ISPConfig 3.1 (and newer). |
|
||||
|
|
||||
Create a Remote User in the ISPConfig Control Panel. The Remote User must have access to at least `DNS zone functions` and `DNS txt functions`. |
|
||||
|
|
||||
``` |
|
||||
export ISPC_User="xxx" |
|
||||
export ISPC_Password="xxx" |
|
||||
export ISPC_Api="https://ispc.domain.tld:8080/remote/json.php" |
|
||||
export ISPC_Api_Insecure=1 |
|
||||
``` |
|
||||
If you have installed ISPConfig on a different port, then alter the 8080 accordingly. |
|
||||
Leaver ISPC_Api_Insecure set to 1 if you have not a valid ssl cert for your installation. Change it to 0 if you have a valid ssl cert. |
|
||||
|
|
||||
To issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_ispconfig -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `ISPC_User`, `ISPC_Password`, `ISPC_Api`and `ISPC_Api_Insecure` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 13. Use Alwaysdata domain API |
|
||||
|
|
||||
First you need to login to your Alwaysdata account to get your API Key. |
|
||||
|
|
||||
```sh |
|
||||
export AD_API_KEY="myalwaysdataapikey" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --issue --dns dns_ad -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `AD_API_KEY` will be saved in `~/.acme.sh/account.conf` and will be reused |
|
||||
when needed. |
|
||||
|
|
||||
## 14. Use Linode domain API |
|
||||
|
|
||||
First you need to login to your Linode account to get your API Key. |
|
||||
[https://manager.linode.com/profile/api](https://manager.linode.com/profile/api) |
|
||||
|
|
||||
Then add an API key with label *ACME* and copy the new key. |
|
||||
|
|
||||
```sh |
|
||||
export LINODE_API_KEY="..." |
|
||||
``` |
|
||||
|
|
||||
Due to the reload time of any changes in the DNS records, we have to use the `dnssleep` option to wait at least 15 minutes for the changes to take effect. |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --issue --dns dns_linode --dnssleep 900 -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `LINODE_API_KEY` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 15. Use FreeDNS |
|
||||
|
|
||||
FreeDNS (https://freedns.afraid.org/) does not provide an API to update DNS records (other than IPv4 and IPv6 |
|
||||
dynamic DNS addresses). The acme.sh plugin therefore retrieves and updates domain TXT records by logging |
|
||||
into the FreeDNS website to read the HTML and posting updates as HTTP. The plugin needs to know your |
|
||||
userid and password for the FreeDNS website. |
|
||||
|
|
||||
```sh |
|
||||
export FREEDNS_User="..." |
|
||||
export FREEDNS_Password="..." |
|
||||
``` |
|
||||
|
|
||||
You need only provide this the first time you run the acme.sh client with FreeDNS validation and then again |
|
||||
whenever you change your password at the FreeDNS site. The acme.sh FreeDNS plugin does not store your userid |
|
||||
or password but rather saves an authentication token returned by FreeDNS in `~/.acme.sh/account.conf` and |
|
||||
reuses that when needed. |
|
||||
|
|
||||
Now you can issue a certificate. |
|
||||
|
|
||||
```sh |
|
||||
acme.sh --issue --dns dns_freedns -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
Note that you cannot use acme.sh automatic DNS validation for FreeDNS public domains or for a subdomain that |
|
||||
you create under a FreeDNS public domain. You must own the top level domain in order to automatically |
|
||||
validate with acme.sh at FreeDNS. |
|
||||
|
|
||||
## 16. Use cyon.ch |
|
||||
|
|
||||
You only need to set your cyon.ch login credentials. |
|
||||
If you also have 2 Factor Authentication (OTP) enabled, you need to set your secret token too and have `oathtool` installed. |
|
||||
|
|
||||
``` |
|
||||
export CY_Username="your_cyon_username" |
|
||||
export CY_Password="your_cyon_password" |
|
||||
export CY_OTP_Secret="your_otp_secret" # Only required if using 2FA |
|
||||
``` |
|
||||
|
|
||||
To issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_cyon -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `CY_Username`, `CY_Password` and `CY_OTP_Secret` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 17. Use Domain-Offensive/Resellerinterface/Domainrobot API |
|
||||
|
|
||||
ATTENTION: You need to be a registered Reseller to be able to use the ResellerInterface. As a normal user you can not use this method. |
|
||||
|
|
||||
You will need your login credentials (Partner ID+Password) to the Resellerinterface, and export them before you run `acme.sh`: |
|
||||
``` |
|
||||
export DO_PID="KD-1234567" |
|
||||
export DO_PW="cdfkjl3n2" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_do -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
## 18. Use Gandi LiveDNS API |
|
||||
|
|
||||
You must enable the new Gandi LiveDNS API first and the create your api key, See: http://doc.livedns.gandi.net/ |
|
||||
|
|
||||
``` |
|
||||
export GANDI_LIVEDNS_KEY="fdmlfsdklmfdkmqsdfk" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_gandi_livedns -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
## 19. Use Knot (knsupdate) DNS API to automatically issue cert |
|
||||
|
|
||||
First, generate a TSIG key for updating the zone. |
|
||||
|
|
||||
``` |
|
||||
keymgr tsig generate -t acme_key hmac-sha512 > /etc/knot/acme.key |
|
||||
``` |
|
||||
|
|
||||
Include this key in your knot configuration file. |
|
||||
|
|
||||
``` |
|
||||
include: /etc/knot/acme.key |
|
||||
``` |
|
||||
|
|
||||
Next, configure your zone to allow dynamic updates. |
|
||||
|
|
||||
Dynamic updates for the zone are allowed via proper ACL rule with the `update` action. For in-depth instructions, please see [Knot DNS's documentation](https://www.knot-dns.cz/documentation/). |
|
||||
|
|
||||
``` |
|
||||
acl: |
|
||||
- id: acme_acl |
|
||||
address: 192.168.1.0/24 |
|
||||
key: acme_key |
|
||||
action: update |
|
||||
|
|
||||
zone: |
|
||||
- domain: example.com |
|
||||
file: example.com.zone |
|
||||
acl: acme_acl |
|
||||
``` |
|
||||
|
|
||||
Finally, make the DNS server and TSIG Key available to `acme.sh` |
|
||||
|
|
||||
``` |
|
||||
export KNOT_SERVER="dns.example.com" |
|
||||
export KNOT_KEY=`grep \# /etc/knot/acme.key | cut -d' ' -f2` |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_knot -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `KNOT_SERVER` and `KNOT_KEY` settings will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 20. Use DigitalOcean API (native) |
|
||||
|
|
||||
You need to obtain a read and write capable API key from your DigitalOcean account. See: https://www.digitalocean.com/help/api/ |
|
||||
|
|
||||
``` |
|
||||
export DO_API_KEY="75310dc4ca779ac39a19f6355db573b49ce92ae126553ebd61ac3a3ae34834cc" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_dgon -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
## 21. Use ClouDNS.net API |
|
||||
|
|
||||
You need to set the HTTP API user ID and password credentials. See: https://www.cloudns.net/wiki/article/42/. For security reasons, it's recommended to use a sub user ID that only has access to the necessary zones, as a regular API user has access to your entire account. |
|
||||
|
|
||||
``` |
|
||||
# Use this for a sub auth ID |
|
||||
export CLOUDNS_SUB_AUTH_ID=XXXXX |
|
||||
# Use this for a regular auth ID |
|
||||
#export CLOUDNS_AUTH_ID=XXXXX |
|
||||
export CLOUDNS_AUTH_PASSWORD="YYYYYYYYY" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_cloudns -d example.com -d www.example.com |
|
||||
``` |
|
||||
The `CLOUDNS_AUTH_ID` and `CLOUDNS_AUTH_PASSWORD` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 22. Use Infoblox API |
|
||||
|
|
||||
First you need to create/obtain API credentials on your Infoblox appliance. |
|
||||
|
|
||||
``` |
|
||||
export Infoblox_Creds="username:password" |
|
||||
export Infoblox_Server="ip or fqdn of infoblox appliance" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_infoblox -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
Note: This script will automatically create and delete the ephemeral txt record. |
|
||||
The `Infoblox_Creds` and `Infoblox_Server` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
|
|
||||
## 23. Use VSCALE API |
|
||||
|
|
||||
First you need to create/obtain API tokens on your [settings panel](https://vscale.io/panel/settings/tokens/). |
|
||||
|
|
||||
``` |
|
||||
VSCALE_API_KEY="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_vscale -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
## 24. Use Dynu API |
|
||||
|
|
||||
First you need to create/obtain API credentials from your Dynu account. See: https://www.dynu.com/resources/api/documentation |
|
||||
|
|
||||
``` |
|
||||
export Dynu_ClientId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" |
|
||||
export Dynu_Secret="yyyyyyyyyyyyyyyyyyyyyyyyy" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_dynu -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `Dynu_ClientId` and `Dynu_Secret` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 25. Use DNSimple API |
|
||||
|
|
||||
First you need to login to your DNSimple account and generate a new oauth token. |
|
||||
|
|
||||
https://dnsimple.com/a/{your account id}/account/access_tokens |
|
||||
|
|
||||
Note that this is an _account_ token and not a user token. The account token is |
|
||||
needed to infer the `account_id` used in requests. A user token will not be able |
|
||||
to determine the correct account to use. |
|
||||
|
|
||||
``` |
|
||||
export DNSimple_OAUTH_TOKEN="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
``` |
|
||||
|
|
||||
To issue the cert just specify the `dns_dnsimple` API. |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_dnsimple -d example.com |
|
||||
``` |
|
||||
|
|
||||
The `DNSimple_OAUTH_TOKEN` will be saved in `~/.acme.sh/account.conf` and will |
|
||||
be reused when needed. |
|
||||
|
|
||||
If you have any issues with this integration please report them to |
|
||||
https://github.com/pho3nixf1re/acme.sh/issues. |
|
||||
|
|
||||
## 26. Use NS1.com API |
|
||||
|
|
||||
``` |
|
||||
export NS1_Key="fdmlfsdklmfdkmqsdfk" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_nsone -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
## 27. Use DuckDNS.org API |
|
||||
|
|
||||
``` |
|
||||
export DuckDNS_Token="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" |
|
||||
``` |
|
||||
|
|
||||
Please note that since DuckDNS uses StartSSL as their cert provider, thus |
|
||||
--insecure may need to be used when issuing certs: |
|
||||
``` |
|
||||
acme.sh --insecure --issue --dns dns_duckdns -d mydomain.duckdns.org |
|
||||
``` |
|
||||
|
|
||||
For issues, please report to https://github.com/raidenii/acme.sh/issues. |
|
||||
|
|
||||
## 28. Use Name.com API |
|
||||
|
|
||||
Create your API token here: https://www.name.com/account/settings/api |
|
||||
|
|
||||
Note: `Namecom_Username` should be your Name.com username and not the token name. If you accidentally run the script with the token name as the username see `~/.acme.sh/account.conf` to fix the issue |
|
||||
|
|
||||
``` |
|
||||
export Namecom_Username="testuser" |
|
||||
export Namecom_Token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
|
||||
``` |
|
||||
|
|
||||
And now you can issue certs with: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_namecom -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
For issues, please report to https://github.com/raidenii/acme.sh/issues. |
|
||||
|
|
||||
## 29. Use Dyn Managed DNS API to automatically issue cert |
|
||||
|
|
||||
First, login to your Dyn Managed DNS account: https://portal.dynect.net/login/ |
|
||||
|
|
||||
It is recommended to add a new user specific for API access. |
|
||||
|
|
||||
The minimum "Zones & Records Permissions" required are: |
|
||||
``` |
|
||||
RecordAdd |
|
||||
RecordUpdate |
|
||||
RecordDelete |
|
||||
RecordGet |
|
||||
ZoneGet |
|
||||
ZoneAddNode |
|
||||
ZoneRemoveNode |
|
||||
ZonePublish |
|
||||
``` |
|
||||
|
|
||||
Pass the API user credentials to the environment: |
|
||||
``` |
|
||||
export DYN_Customer="customer" |
|
||||
export DYN_Username="apiuser" |
|
||||
export DYN_Password="secret" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_dyn -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `DYN_Customer`, `DYN_Username` and `DYN_Password` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 30. Use pdd.yandex.ru API |
|
||||
|
|
||||
``` |
|
||||
export PDD_Token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
|
||||
``` |
|
||||
|
|
||||
Follow these instructions to get the token for your domain https://tech.yandex.com/domain/doc/concepts/access-docpage/ |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_yandex -d mydomain.example.org |
|
||||
``` |
|
||||
|
|
||||
For issues, please report to https://github.com/non7top/acme.sh/issues. |
|
||||
|
|
||||
## 31. Use Hurricane Electric |
|
||||
|
|
||||
Hurricane Electric (https://dns.he.net/) doesn't have an API so just set your login credentials like so: |
|
||||
|
|
||||
``` |
|
||||
export HE_Username="yourusername" |
|
||||
export HE_Password="password" |
|
||||
``` |
|
||||
|
|
||||
Then you can issue your certificate: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_he -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `HE_Username` and `HE_Password` settings will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
Please report any issues to https://github.com/angel333/acme.sh or to <me@ondrejsimek.com>. |
|
||||
|
|
||||
## 32. Use UnoEuro API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your UnoEuro account to get your API key. |
|
||||
|
|
||||
``` |
|
||||
export UNO_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
export UNO_User="UExxxxxx" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_unoeuro -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `UNO_Key` and `UNO_User` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 33. Use INWX |
|
||||
|
|
||||
[INWX](https://www.inwx.de/) offers an [xmlrpc api](https://www.inwx.de/de/help/apidoc) with your standard login credentials, set them like so: |
|
||||
|
|
||||
``` |
|
||||
export INWX_User="yourusername" |
|
||||
export INWX_Password="password" |
|
||||
``` |
|
||||
|
|
||||
Then you can issue your certificates with: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_inwx -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `INWX_User` and `INWX_Password` settings will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
If your account is secured by mobile tan you have also defined the shared secret. |
|
||||
|
|
||||
``` |
|
||||
export INWX_Shared_Secret="shared secret" |
|
||||
``` |
|
||||
|
|
||||
You may need to re-enable the mobile tan to gain the shared secret. |
|
||||
|
|
||||
## 34. User Servercow API v1 |
|
||||
|
|
||||
Create a new user from the servercow control center. Don't forget to activate **DNS API** for this user. |
|
||||
|
|
||||
``` |
|
||||
export SERVERCOW_API_Username=username |
|
||||
export SERVERCOW_API_Password=password |
|
||||
``` |
|
||||
|
|
||||
Now you cann issue a cert: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_servercow -d example.com -d www.example.com |
|
||||
``` |
|
||||
Both, `SERVERCOW_API_Username` and `SERVERCOW_API_Password` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 35. Use Namesilo.com API |
|
||||
|
|
||||
You'll need to generate an API key at https://www.namesilo.com/account_api.php |
|
||||
Optionally you may restrict the access to an IP range there. |
|
||||
|
|
||||
``` |
|
||||
export Namesilo_Key="xxxxxxxxxxxxxxxxxxxxxxxx" |
|
||||
``` |
|
||||
|
|
||||
And now you can issue certs with: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_namesilo --dnssleep 900 -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
## 36. Use autoDNS (InternetX) |
|
||||
|
|
||||
[InternetX](https://www.internetx.com/) offers an [xml api](https://help.internetx.com/display/API/AutoDNS+XML-API) with your standard login credentials, set them like so: |
|
||||
|
|
||||
``` |
|
||||
export AUTODNS_USER="yourusername" |
|
||||
export AUTODNS_PASSWORD="password" |
|
||||
export AUTODNS_CONTEXT="context" |
|
||||
``` |
|
||||
|
|
||||
Then you can issue your certificates with: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_autodns -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `AUTODNS_USER`, `AUTODNS_PASSWORD` and `AUTODNS_CONTEXT` settings will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 37. Use Azure DNS |
|
||||
|
|
||||
You have to create a service principal first. See:[How to use Azure DNS](../../../wiki/How-to-use-Azure-DNS) |
|
||||
|
|
||||
``` |
|
||||
export AZUREDNS_SUBSCRIPTIONID="12345678-9abc-def0-1234-567890abcdef" |
|
||||
export AZUREDNS_TENANTID="11111111-2222-3333-4444-555555555555" |
|
||||
export AZUREDNS_APPID="3b5033b5-7a66-43a5-b3b9-a36b9e7c25ed" |
|
||||
export AZUREDNS_CLIENTSECRET="1b0224ef-34d4-5af9-110f-77f527d561bd" |
|
||||
``` |
|
||||
|
|
||||
Then you can issue your certificates with: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_azure -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
`AZUREDNS_SUBSCRIPTIONID`, `AZUREDNS_TENANTID`,`AZUREDNS_APPID` and `AZUREDNS_CLIENTSECRET` settings will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 38. Use selectel.com(selectel.ru) domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your account to get your API key from: https://my.selectel.ru/profile/apikeys. |
|
||||
|
|
||||
```sh |
|
||||
export SL_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
|
||||
|
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_selectel -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `SL_Key` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 39. Use zonomi.com domain API to automatically issue cert |
|
||||
|
|
||||
First you need to login to your account to find your API key from: http://zonomi.com/app/dns/dyndns.jsp |
|
||||
|
|
||||
Your will find your api key in the example urls: |
|
||||
|
|
||||
```sh |
|
||||
https://zonomi.com/app/dns/dyndns.jsp?host=example.com&api_key=1063364558943540954358668888888888 |
|
||||
``` |
|
||||
|
|
||||
```sh |
|
||||
export ZM_Key="1063364558943540954358668888888888" |
|
||||
|
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_zonomi -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `ZM_Key` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 40. Use DreamHost DNS API |
|
||||
|
|
||||
DNS API keys may be created at https://panel.dreamhost.com/?tree=home.api. |
|
||||
Ensure the created key has add and remove privelages. |
|
||||
|
|
||||
``` |
|
||||
export DH_API_KEY="<api key>" |
|
||||
acme.sh --issue --dns dns_dreamhost -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The 'DH_API_KEY' will be saved in `~/.acme.sh/account.conf` and will |
|
||||
be reused when needed. |
|
||||
|
|
||||
## 41. Use DirectAdmin 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 the DirectAdmin incl. port. |
|
||||
You can create an user which only has access to |
|
||||
|
|
||||
- CMD_API_DNS_CONTROL |
|
||||
- CMD_API_SHOW_DOMAINS |
|
||||
|
|
||||
By using the Login Keys function. |
|
||||
See also https://www.directadmin.com/api.php and https://www.directadmin.com/features.php?id=1298 |
|
||||
|
|
||||
``` |
|
||||
export DA_Api="https://remoteUser:remotePassword@da.domain.tld: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) |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_da -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
The `DA_Api` and `DA_Api_Insecure` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 42. Use KingHost DNS API |
|
||||
|
|
||||
API access must be enabled at https://painel.kinghost.com.br/painel.api.php |
|
||||
|
|
||||
``` |
|
||||
export KINGHOST_Username="yourusername" |
|
||||
export KINGHOST_Password="yourpassword" |
|
||||
acme.sh --issue --dns dns_kinghost -d example.com -d *.example.com |
|
||||
``` |
|
||||
|
|
||||
The `KINGHOST_username` and `KINGHOST_Password` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 43. Use Zilore DNS API |
|
||||
|
|
||||
First, get your API key at https://my.zilore.com/account/api |
|
||||
|
|
||||
``` |
|
||||
export Zilore_Key="5dcad3a2-36cb-50e8-cb92-000002f9" |
|
||||
``` |
|
||||
|
|
||||
Ok, let's issue a cert now: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_zilore -d example.com -d *.example.com |
|
||||
``` |
|
||||
|
|
||||
The `Zilore_Key` will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
|
|
||||
## 44. Use Loopia.se API |
|
||||
User must provide login credentials to the Loopia API. |
|
||||
The user needs the following permissions: |
|
||||
|
|
||||
- addSubdomain |
|
||||
- updateZoneRecord |
|
||||
- getDomains |
|
||||
- removeSubdomain |
|
||||
|
|
||||
Set the login credentials: |
|
||||
``` |
|
||||
export LOOPIA_User="user@loopiaapi" |
|
||||
export LOOPIA_Password="password" |
|
||||
``` |
|
||||
|
|
||||
And to issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_loopia -d example.com -d *.example.com |
|
||||
``` |
|
||||
|
|
||||
The username and password will be saved in `~/.acme.sh/account.conf` and will be reused when needed. |
|
||||
## 45. Use ACME DNS API |
|
||||
|
|
||||
ACME DNS is a limited DNS server with RESTful HTTP API to handle ACME DNS challenges easily and securely. |
|
||||
https://github.com/joohoi/acme-dns |
|
||||
|
|
||||
``` |
|
||||
export ACMEDNS_BASE_URL="https://auth.acme-dns.io" |
|
||||
``` |
|
||||
|
|
||||
And to issue a cert: |
|
||||
``` |
|
||||
acme.sh --issue --dns dns_acmedns -d example.com -d *.example.com |
|
||||
``` |
|
||||
The needed domain account is automatically created. The script will tell you the needed cname to create. |
|
||||
|
|
||||
The credentials will be saved in `~/.acme.sh/#DOMAIN/#DOMAIN.conf` and will |
|
||||
be reused when needed. |
|
||||
## 46. Use TELE3 API |
|
||||
|
|
||||
First you need to login to your TELE3 account to set your API-KEY. |
|
||||
https://www.tele3.cz/system-acme-api.html |
|
||||
|
|
||||
``` |
|
||||
export TELE3_Key="MS2I4uPPaI..." |
|
||||
export TELE3_Secret="kjhOIHGJKHg" |
|
||||
|
|
||||
acme.sh --issue --dns dns_tele3 -d example.com -d *.example.com |
|
||||
``` |
|
||||
|
|
||||
The TELE3_Key and TELE3_Secret will be saved in ~/.acme.sh/account.conf and will be reused when needed. |
|
||||
# Use custom API |
|
||||
|
|
||||
If your API is not supported yet, you can write your own DNS API. |
|
||||
|
|
||||
Let's assume you want to name it 'myapi': |
|
||||
|
|
||||
1. Create a bash script named `~/.acme.sh/dns_myapi.sh`, |
|
||||
2. In the script you must have a function named `dns_myapi_add()` which will be called by acme.sh to add the DNS records. |
|
||||
3. Then you can use your API to issue cert like this: |
|
||||
|
|
||||
``` |
|
||||
acme.sh --issue --dns dns_myapi -d example.com -d www.example.com |
|
||||
``` |
|
||||
|
|
||||
For more details, please check our sample script: [dns_myapi.sh](dns_myapi.sh) |
|
||||
|
|
||||
See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide |
|
||||
|
|
||||
# Use lexicon DNS API |
|
||||
|
|
||||
https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api |
|
||||
@ -0,0 +1,141 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#ACTIVE24_Token="sdfsdfsdfljlbjkljlkjsdfoiwje" |
||||
|
|
||||
|
ACTIVE24_Api="https://api.active24.com" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Used to add txt record |
||||
|
dns_active24_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_active24_init |
||||
|
|
||||
|
_info "Adding txt record" |
||||
|
if _active24_rest POST "dns/$_domain/txt/v1" "{\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":0}"; then |
||||
|
if _contains "$response" "errors"; then |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
else |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Usage: fulldomain txtvalue |
||||
|
# Used to remove the txt record after validation |
||||
|
dns_active24_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_active24_init |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_active24_rest GET "dns/$_domain/records/v1" |
||||
|
|
||||
|
if _contains "$response" "errors"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hash_ids=$(echo "$response" | _egrep_o "[^{]+${txtvalue}[^}]+" | _egrep_o "hashId\":\"[^\"]+" | cut -c10-) |
||||
|
|
||||
|
for hash_id in $hash_ids; do |
||||
|
_debug "Removing hash_id" "$hash_id" |
||||
|
if _active24_rest DELETE "dns/$_domain/$hash_id/v1" ""; then |
||||
|
if _contains "$response" "errors"; then |
||||
|
_err "Unable to remove txt record." |
||||
|
return 1 |
||||
|
else |
||||
|
_info "Removed txt record." |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
_err "No txt records found." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
|
||||
|
if ! _active24_rest GET "dns/domains/v1"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
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 |
||||
|
|
||||
|
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 |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_active24_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
export _H1="Authorization: Bearer $ACTIVE24_Token" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug "data" "$data" |
||||
|
response="$(_post "$data" "$ACTIVE24_Api/$ep" "" "$m" "application/json")" |
||||
|
else |
||||
|
response="$(_get "$ACTIVE24_Api/$ep")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_active24_init() { |
||||
|
ACTIVE24_Token="${ACTIVE24_Token:-$(_readaccountconf_mutable ACTIVE24_Token)}" |
||||
|
if [ -z "$ACTIVE24_Token" ]; then |
||||
|
ACTIVE24_Token="" |
||||
|
_err "You didn't specify a Active24 api token yet." |
||||
|
_err "Please create the token and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable ACTIVE24_Token "ACTIVE24_Token" |
||||
|
|
||||
|
_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" |
||||
|
} |
||||
@ -0,0 +1,157 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# DNS API for acme.sh for Core-Networks (https://beta.api.core-networks.de/doc/). |
||||
|
# created by 5ll and francis |
||||
|
|
||||
|
CN_API="https://beta.api.core-networks.de" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
dns_cn_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _cn_login; then |
||||
|
_err "login failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _cn_get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "_sub_domain $_sub_domain" |
||||
|
_debug "_domain $_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
curData="{\"name\":\"$_sub_domain\",\"ttl\":120,\"type\":\"TXT\",\"data\":\"$txtvalue\"}" |
||||
|
curResult="$(_post "${curData}" "${CN_API}/dnszones/${_domain}/records/")" |
||||
|
|
||||
|
_debug "curData $curData" |
||||
|
_debug "curResult $curResult" |
||||
|
|
||||
|
if _contains "$curResult" ""; then |
||||
|
_info "Added, OK" |
||||
|
|
||||
|
if ! _cn_commit; then |
||||
|
_err "commiting changes failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
|
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
_debug "curData is $curData" |
||||
|
_debug "curResult is $curResult" |
||||
|
_err "error adding text record, response was $curResult" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
dns_cn_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _cn_login; then |
||||
|
_err "login failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _cn_get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Deleting record" |
||||
|
curData="{\"name\":\"$_sub_domain\",\"data\":\"$txtvalue\"}" |
||||
|
curResult="$(_post "${curData}" "${CN_API}/dnszones/${_domain}/records/delete")" |
||||
|
_debug curData is "$curData" |
||||
|
|
||||
|
_info "commiting changes" |
||||
|
if ! _cn_commit; then |
||||
|
_err "commiting changes failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Deletet txt record" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
################### Private functions below ################################## |
||||
|
_cn_login() { |
||||
|
CN_User="${CN_User:-$(_readaccountconf_mutable CN_User)}" |
||||
|
CN_Password="${CN_Password:-$(_readaccountconf_mutable CN_Password)}" |
||||
|
if [ -z "$CN_User" ] || [ -z "$CN_Password" ]; then |
||||
|
CN_User="" |
||||
|
CN_Password="" |
||||
|
_err "You must export variables: CN_User and CN_Password" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the config variables to the account conf file. |
||||
|
_saveaccountconf_mutable CN_User "$CN_User" |
||||
|
_saveaccountconf_mutable CN_Password "$CN_Password" |
||||
|
|
||||
|
_info "Getting an AUTH-Token" |
||||
|
curData="{\"login\":\"${CN_User}\",\"password\":\"${CN_Password}\"}" |
||||
|
curResult="$(_post "${curData}" "${CN_API}/auth/token")" |
||||
|
_debug "Calling _CN_login: '${curData}' '${CN_API}/auth/token'" |
||||
|
|
||||
|
if _contains "${curResult}" '"token":"'; then |
||||
|
authToken=$(echo "${curResult}" | cut -d ":" -f2 | cut -d "," -f1 | sed 's/^.\(.*\).$/\1/') |
||||
|
export _H1="Authorization: Bearer $authToken" |
||||
|
_info "Successfully acquired AUTH-Token" |
||||
|
_debug "AUTH-Token: '${authToken}'" |
||||
|
_debug "_H1 '${_H1}'" |
||||
|
else |
||||
|
_err "Couldn't acquire an AUTH-Token" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Commit changes |
||||
|
_cn_commit() { |
||||
|
_info "Commiting changes" |
||||
|
_post "" "${CN_API}/dnszones/$h/records/commit" |
||||
|
} |
||||
|
|
||||
|
_cn_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
|
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
_debug _H1 "${_H1}" |
||||
|
|
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_cn_zonelist="$(_get ${CN_API}/dnszones/)" |
||||
|
_debug _cn_zonelist "${_cn_zonelist}" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "something went wrong while getting the zone list" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$_cn_zonelist" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "Zonelist does not contain domain - iterating " |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
|
||||
|
done |
||||
|
_err "Zonelist does not contain domain - exiting" |
||||
|
return 1 |
||||
|
} |
||||
@ -0,0 +1,253 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
CONOHA_DNS_EP_PREFIX_REGEXP="https://dns-service\." |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_conoha_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_conoha_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using conoha" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_debug "Check uesrname and password" |
||||
|
CONOHA_Username="${CONOHA_Username:-$(_readaccountconf_mutable CONOHA_Username)}" |
||||
|
CONOHA_Password="${CONOHA_Password:-$(_readaccountconf_mutable CONOHA_Password)}" |
||||
|
CONOHA_TenantId="${CONOHA_TenantId:-$(_readaccountconf_mutable CONOHA_TenantId)}" |
||||
|
CONOHA_IdentityServiceApi="${CONOHA_IdentityServiceApi:-$(_readaccountconf_mutable CONOHA_IdentityServiceApi)}" |
||||
|
if [ -z "$CONOHA_Username" ] || [ -z "$CONOHA_Password" ] || [ -z "$CONOHA_TenantId" ] || [ -z "$CONOHA_IdentityServiceApi" ]; then |
||||
|
CONOHA_Username="" |
||||
|
CONOHA_Password="" |
||||
|
CONOHA_TenantId="" |
||||
|
CONOHA_IdentityServiceApi="" |
||||
|
_err "You didn't specify a conoha api username and password yet." |
||||
|
_err "Please create the user and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable CONOHA_Username "$CONOHA_Username" |
||||
|
_saveaccountconf_mutable CONOHA_Password "$CONOHA_Password" |
||||
|
_saveaccountconf_mutable CONOHA_TenantId "$CONOHA_TenantId" |
||||
|
_saveaccountconf_mutable CONOHA_IdentityServiceApi "$CONOHA_IdentityServiceApi" |
||||
|
|
||||
|
if token="$(_conoha_get_accesstoken "$CONOHA_IdentityServiceApi/tokens" "$CONOHA_Username" "$CONOHA_Password" "$CONOHA_TenantId")"; then |
||||
|
accesstoken="$(printf "%s" "$token" | sed -n 1p)" |
||||
|
CONOHA_Api="$(printf "%s" "$token" | sed -n 2p)" |
||||
|
else |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain" "$CONOHA_Api" "$accesstoken"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
body="{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"data\":\"$txtvalue\",\"ttl\":60}" |
||||
|
if _conoha_rest POST "$CONOHA_Api/v1/domains/$_domain_id/records" "$body" "$accesstoken"; then |
||||
|
if _contains "$response" '"data":"'"$txtvalue"'"'; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_conoha_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using conoha" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_debug "Check uesrname and password" |
||||
|
CONOHA_Username="${CONOHA_Username:-$(_readaccountconf_mutable CONOHA_Username)}" |
||||
|
CONOHA_Password="${CONOHA_Password:-$(_readaccountconf_mutable CONOHA_Password)}" |
||||
|
CONOHA_TenantId="${CONOHA_TenantId:-$(_readaccountconf_mutable CONOHA_TenantId)}" |
||||
|
CONOHA_IdentityServiceApi="${CONOHA_IdentityServiceApi:-$(_readaccountconf_mutable CONOHA_IdentityServiceApi)}" |
||||
|
if [ -z "$CONOHA_Username" ] || [ -z "$CONOHA_Password" ] || [ -z "$CONOHA_TenantId" ] || [ -z "$CONOHA_IdentityServiceApi" ]; then |
||||
|
CONOHA_Username="" |
||||
|
CONOHA_Password="" |
||||
|
CONOHA_TenantId="" |
||||
|
CONOHA_IdentityServiceApi="" |
||||
|
_err "You didn't specify a conoha api username and password yet." |
||||
|
_err "Please create the user and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable CONOHA_Username "$CONOHA_Username" |
||||
|
_saveaccountconf_mutable CONOHA_Password "$CONOHA_Password" |
||||
|
_saveaccountconf_mutable CONOHA_TenantId "$CONOHA_TenantId" |
||||
|
_saveaccountconf_mutable CONOHA_IdentityServiceApi "$CONOHA_IdentityServiceApi" |
||||
|
|
||||
|
if token="$(_conoha_get_accesstoken "$CONOHA_IdentityServiceApi/tokens" "$CONOHA_Username" "$CONOHA_Password" "$CONOHA_TenantId")"; then |
||||
|
accesstoken="$(printf "%s" "$token" | sed -n 1p)" |
||||
|
CONOHA_Api="$(printf "%s" "$token" | sed -n 2p)" |
||||
|
else |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain" "$CONOHA_Api" "$accesstoken"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
if ! _conoha_rest GET "$CONOHA_Api/v1/domains/$_domain_id/records" "" "$accesstoken"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
record_id=$(printf "%s" "$response" | _egrep_o '{[^}]*}' \ |
||||
|
| grep '"type":"TXT"' | grep "\"data\":\"$txtvalue\"" | _egrep_o "\"id\":\"[^\"]*\"" \ |
||||
|
| _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug record_id "$record_id" |
||||
|
|
||||
|
_info "Removing the txt record" |
||||
|
if ! _conoha_rest DELETE "$CONOHA_Api/v1/domains/$_domain_id/records/$record_id" "" "$accesstoken"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_conoha_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
accesstoken="$4" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
if [ -n "$accesstoken" ]; then |
||||
|
export _H3="X-Auth-Token: $accesstoken" |
||||
|
fi |
||||
|
|
||||
|
_debug "$ep" |
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_secure_debug2 data "$data" |
||||
|
response="$(_post "$data" "$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$ep")" |
||||
|
fi |
||||
|
_ret="$?" |
||||
|
_secure_debug2 response "$response" |
||||
|
if [ "$_ret" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
response="$(printf "%s" "$response" | _normalizeJson)" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_conoha_get_accesstoken() { |
||||
|
ep="$1" |
||||
|
username="$2" |
||||
|
password="$3" |
||||
|
tenantId="$4" |
||||
|
|
||||
|
accesstoken="$(_readaccountconf_mutable conoha_accesstoken)" |
||||
|
expires="$(_readaccountconf_mutable conoha_tokenvalidto)" |
||||
|
CONOHA_Api="$(_readaccountconf_mutable conoha_dns_ep)" |
||||
|
|
||||
|
# can we reuse the access token? |
||||
|
if [ -n "$accesstoken" ] && [ -n "$expires" ] && [ -n "$CONOHA_Api" ]; then |
||||
|
utc_date="$(_utc_date | sed "s/ /T/")" |
||||
|
if expr "$utc_date" "<" "$expires" >/dev/null; then |
||||
|
# access token is still valid - reuse it |
||||
|
_debug "reusing access token" |
||||
|
printf "%s\n%s\n" "$accesstoken" "$CONOHA_Api" |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "access token expired" |
||||
|
fi |
||||
|
fi |
||||
|
_debug "getting new access token" |
||||
|
|
||||
|
body="$(printf '{"auth":{"passwordCredentials":{"username":"%s","password":"%s"},"tenantId":"%s"}}' "$username" "$password" "$tenantId")" |
||||
|
if ! _conoha_rest POST "$ep" "$body" ""; then |
||||
|
_err error "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
accesstoken=$(printf "%s" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
expires=$(printf "%s" "$response" | _egrep_o "\"expires\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2-4 | tr -d \" | tr -d Z) #expect UTC |
||||
|
if [ -z "$accesstoken" ] || [ -z "$expires" ]; then |
||||
|
_err "no acccess token received. Check your Conoha settings see $WIKI" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable conoha_accesstoken "$accesstoken" |
||||
|
_saveaccountconf_mutable conoha_tokenvalidto "$expires" |
||||
|
|
||||
|
CONOHA_Api=$(printf "%s" "$response" | _egrep_o 'publicURL":"'"$CONOHA_DNS_EP_PREFIX_REGEXP"'[^"]*"' | _head_n 1 | cut -d : -f 2-3 | tr -d \") |
||||
|
if [ -z "$CONOHA_Api" ]; then |
||||
|
_err "failed to get conoha dns endpoint url" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable conoha_dns_ep "$CONOHA_Api" |
||||
|
|
||||
|
printf "%s\n%s\n" "$accesstoken" "$CONOHA_Api" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain="$1" |
||||
|
ep="$2" |
||||
|
accesstoken="$3" |
||||
|
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 |
||||
|
|
||||
|
if ! _conoha_rest GET "$ep/v1/domains?name=$h" "" "$accesstoken"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | head -n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
@ -0,0 +1,204 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
# deSEC.io Domain API |
||||
|
# |
||||
|
# Author: Zheng Qian |
||||
|
# |
||||
|
# deSEC API doc |
||||
|
# https://desec.readthedocs.io/en/latest/ |
||||
|
|
||||
|
REST_API="https://desec.io/api/v1/domains" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_desec_add _acme-challenge.foobar.dedyn.io "d41d8cd98f00b204e9800998ecf8427e" |
||||
|
dns_desec_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using desec.io api" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
DEDYN_TOKEN="${DEDYN_TOKEN:-$(_readaccountconf_mutable DEDYN_TOKEN)}" |
||||
|
DEDYN_NAME="${DEDYN_NAME:-$(_readaccountconf_mutable DEDYN_NAME)}" |
||||
|
|
||||
|
if [ -z "$DEDYN_TOKEN" ] || [ -z "$DEDYN_NAME" ]; then |
||||
|
DEDYN_TOKEN="" |
||||
|
DEDYN_NAME="" |
||||
|
_err "You don't specify DEDYN_TOKEN and DEDYN_NAME yet." |
||||
|
_err "Please create you key and try again." |
||||
|
_err "e.g." |
||||
|
_err "export DEDYN_TOKEN=d41d8cd98f00b204e9800998ecf8427e" |
||||
|
_err "export DEDYN_NAME=foobar.dedyn.io" |
||||
|
return 1 |
||||
|
fi |
||||
|
#save the api token and name to the account conf file. |
||||
|
_saveaccountconf_mutable DEDYN_TOKEN "$DEDYN_TOKEN" |
||||
|
_saveaccountconf_mutable DEDYN_NAME "$DEDYN_NAME" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain" "$REST_API/"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
# Get existing TXT record |
||||
|
_debug "Getting txt records" |
||||
|
txtvalues="\"\\\"$txtvalue\\\"\"" |
||||
|
_desec_rest GET "$REST_API/$DEDYN_NAME/rrsets/$_sub_domain/TXT/" |
||||
|
|
||||
|
if [ "$_code" = "200" ]; then |
||||
|
oldtxtvalues="$(echo "$response" | _egrep_o "\"records\":\\[\"\\S*\"\\]" | cut -d : -f 2 | tr -d "[]\\\\\"" | sed "s/,/ /g")" |
||||
|
_debug "existing TXT found" |
||||
|
_debug oldtxtvalues "$oldtxtvalues" |
||||
|
if [ -n "$oldtxtvalues" ]; then |
||||
|
for oldtxtvalue in $oldtxtvalues; do |
||||
|
txtvalues="$txtvalues, \"\\\"$oldtxtvalue\\\"\"" |
||||
|
done |
||||
|
fi |
||||
|
fi |
||||
|
_debug txtvalues "$txtvalues" |
||||
|
_info "Adding record" |
||||
|
body="[{\"subname\":\"$_sub_domain\", \"type\":\"TXT\", \"records\":[$txtvalues], \"ttl\":60}]" |
||||
|
|
||||
|
if _desec_rest PUT "$REST_API/$DEDYN_NAME/rrsets/" "$body"; then |
||||
|
if _contains "$response" "$txtvalue"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_desec_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using desec.io api" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
DEDYN_TOKEN="${DEDYN_TOKEN:-$(_readaccountconf_mutable DEDYN_TOKEN)}" |
||||
|
DEDYN_NAME="${DEDYN_NAME:-$(_readaccountconf_mutable DEDYN_NAME)}" |
||||
|
|
||||
|
if [ -z "$DEDYN_TOKEN" ] || [ -z "$DEDYN_NAME" ]; then |
||||
|
DEDYN_TOKEN="" |
||||
|
DEDYN_NAME="" |
||||
|
_err "You don't specify DEDYN_TOKEN and DEDYN_NAME yet." |
||||
|
_err "Please create you key and try again." |
||||
|
_err "e.g." |
||||
|
_err "export DEDYN_TOKEN=d41d8cd98f00b204e9800998ecf8427e" |
||||
|
_err "export DEDYN_NAME=foobar.dedyn.io" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain" "$REST_API/"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
# Get existing TXT record |
||||
|
_debug "Getting txt records" |
||||
|
txtvalues="" |
||||
|
_desec_rest GET "$REST_API/$DEDYN_NAME/rrsets/$_sub_domain/TXT/" |
||||
|
|
||||
|
if [ "$_code" = "200" ]; then |
||||
|
oldtxtvalues="$(echo "$response" | _egrep_o "\"records\":\\[\"\\S*\"\\]" | cut -d : -f 2 | tr -d "[]\\\\\"" | sed "s/,/ /g")" |
||||
|
_debug "existing TXT found" |
||||
|
_debug oldtxtvalues "$oldtxtvalues" |
||||
|
if [ -n "$oldtxtvalues" ]; then |
||||
|
for oldtxtvalue in $oldtxtvalues; do |
||||
|
if [ "$txtvalue" != "$oldtxtvalue" ]; then |
||||
|
txtvalues="$txtvalues, \"\\\"$oldtxtvalue\\\"\"" |
||||
|
fi |
||||
|
done |
||||
|
fi |
||||
|
fi |
||||
|
txtvalues="$(echo "$txtvalues" | cut -c3-)" |
||||
|
_debug txtvalues "$txtvalues" |
||||
|
|
||||
|
_info "Deleting record" |
||||
|
body="[{\"subname\":\"$_sub_domain\", \"type\":\"TXT\", \"records\":[$txtvalues], \"ttl\":60}]" |
||||
|
_desec_rest PUT "$REST_API/$DEDYN_NAME/rrsets/" "$body" |
||||
|
if [ "$_code" = "200" ]; then |
||||
|
_info "Deleted, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
_err "Delete txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_desec_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
|
||||
|
export _H1="Authorization: Token $DEDYN_TOKEN" |
||||
|
export _H2="Accept: application/json" |
||||
|
export _H3="Content-Type: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_secure_debug2 data "$data" |
||||
|
response="$(_post "$data" "$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$ep")" |
||||
|
fi |
||||
|
_ret="$?" |
||||
|
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" |
||||
|
_debug "http response code $_code" |
||||
|
_secure_debug2 response "$response" |
||||
|
if [ "$_ret" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
response="$(printf "%s" "$response" | _normalizeJson)" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain="$1" |
||||
|
ep="$2" |
||||
|
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 |
||||
|
|
||||
|
if ! _desec_rest GET "$ep"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$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 |
||||
|
return 1 |
||||
|
} |
||||
@ -0,0 +1,59 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Official Let's Encrypt API for do.de / Domain-Offensive |
||||
|
# |
||||
|
# This is different from the dns_do adapter, because dns_do is only usable for enterprise customers |
||||
|
# This API is also available to private customers/individuals |
||||
|
# |
||||
|
# Provide the required LetsEncrypt token like this: |
||||
|
# DO_LETOKEN="FmD408PdqT1E269gUK57" |
||||
|
|
||||
|
DO_API="https://www.do.de/api/letsencrypt" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_doapi_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
DO_LETOKEN="${DO_LETOKEN:-$(_readaccountconf_mutable DO_LETOKEN)}" |
||||
|
if [ -z "$DO_LETOKEN" ]; then |
||||
|
DO_LETOKEN="" |
||||
|
_err "You didn't configure a do.de API token yet." |
||||
|
_err "Please set DO_LETOKEN and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable DO_LETOKEN "$DO_LETOKEN" |
||||
|
|
||||
|
_info "Adding TXT record to ${fulldomain}" |
||||
|
response="$(_get "$DO_API?token=$DO_LETOKEN&domain=${fulldomain}&value=${txtvalue}")" |
||||
|
if _contains "${response}" 'success'; then |
||||
|
return 0 |
||||
|
fi |
||||
|
_err "Could not create resource record, check logs" |
||||
|
_err "${response}" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
dns_doapi_rm() { |
||||
|
fulldomain=$1 |
||||
|
|
||||
|
DO_LETOKEN="${DO_LETOKEN:-$(_readaccountconf_mutable DO_LETOKEN)}" |
||||
|
if [ -z "$DO_LETOKEN" ]; then |
||||
|
DO_LETOKEN="" |
||||
|
_err "You didn't configure a do.de API token yet." |
||||
|
_err "Please set DO_LETOKEN and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable DO_LETOKEN "$DO_LETOKEN" |
||||
|
|
||||
|
_info "Deleting resource record $fulldomain" |
||||
|
response="$(_get "$DO_API?token=$DO_LETOKEN&domain=${fulldomain}&action=delete")" |
||||
|
if _contains "${response}" 'success'; then |
||||
|
return 0 |
||||
|
fi |
||||
|
_err "Could not delete resource record, check logs" |
||||
|
_err "${response}" |
||||
|
return 1 |
||||
|
} |
||||
@ -0,0 +1,161 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Dnspod.com Domain api |
||||
|
# |
||||
|
#DPI_Id="1234" |
||||
|
# |
||||
|
#DPI_Key="sADDsdasdgdsf" |
||||
|
|
||||
|
REST_API="https://api.dnspod.com" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_dpi_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
DPI_Id="${DPI_Id:-$(_readaccountconf_mutable DPI_Id)}" |
||||
|
DPI_Key="${DPI_Key:-$(_readaccountconf_mutable DPI_Key)}" |
||||
|
if [ -z "$DPI_Id" ] || [ -z "$DPI_Key" ]; then |
||||
|
DPI_Id="" |
||||
|
DPI_Key="" |
||||
|
_err "You don't specify dnspod api key and key id 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 DPI_Id "$DPI_Id" |
||||
|
_saveaccountconf_mutable DPI_Key "$DPI_Key" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
add_record "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_dpi_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
DPI_Id="${DPI_Id:-$(_readaccountconf_mutable DPI_Id)}" |
||||
|
DPI_Key="${DPI_Key:-$(_readaccountconf_mutable DPI_Key)}" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _rest POST "Record.List" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain"; then |
||||
|
_err "Record.Lis error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" 'No records'; then |
||||
|
_info "Don't need to remove." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
record_id=$(echo "$response" | _egrep_o '{[^{]*"value":"'"$txtvalue"'"' | cut -d , -f 1 | cut -d : -f 2 | tr -d \") |
||||
|
_debug record_id "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _rest POST "Record.Remove" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&record_id=$record_id"; then |
||||
|
_err "Record.Remove error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_contains "$response" "Action completed successful" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#add the txt record. |
||||
|
#usage: root sub txtvalue |
||||
|
add_record() { |
||||
|
root=$1 |
||||
|
sub=$2 |
||||
|
txtvalue=$3 |
||||
|
fulldomain="$sub.$root" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
|
||||
|
if ! _rest POST "Record.Create" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=default"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_contains "$response" "Action completed successful" || _contains "$response" "Domain record already exists" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _rest POST "Domain.Info" "user_token=$DPI_Id,$DPI_Key&format=json&domain=$h"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "Action completed successful"; then |
||||
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \") |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_domain="$h" |
||||
|
_debug _domain "$_domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p="$i" |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: method URI data |
||||
|
_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
url="$REST_API/$ep" |
||||
|
|
||||
|
_debug url "$url" |
||||
|
|
||||
|
if [ "$m" = "GET" ]; then |
||||
|
response="$(_get "$url" | tr -d '\r')" |
||||
|
else |
||||
|
_debug2 data "$data" |
||||
|
response="$(_post "$data" "$url" | tr -d '\r')" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -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,168 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
EXOSCALE_API=https://api.exoscale.com/dns/v1 |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Used to add txt record |
||||
|
dns_exoscale_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _checkAuth; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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 _exoscale_rest POST "domains/$_domain_id/records" "{\"record\":{\"name\":\"$_sub_domain\",\"record_type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":120}}" "$_domain_token"; then |
||||
|
if _contains "$response" "$txtvalue"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
|
||||
|
} |
||||
|
|
||||
|
# Usage: fulldomain txtvalue |
||||
|
# Used to remove the txt record after validation |
||||
|
dns_exoscale_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _checkAuth; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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" |
||||
|
_exoscale_rest GET "domains/${_domain_id}/records?type=TXT&name=$_sub_domain" "" "$_domain_token" |
||||
|
if _contains "$response" "\"name\":\"$_sub_domain\"" >/dev/null; then |
||||
|
_record_id=$(echo "$response" | tr '{' "\n" | grep "\"content\":\"$txtvalue\"" | _egrep_o "\"id\":[^,]+" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$_record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "Deleting record $_record_id" |
||||
|
|
||||
|
if ! _exoscale_rest DELETE "domains/$_domain_id/records/$_record_id" "" "$_domain_token"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_checkAuth() { |
||||
|
EXOSCALE_API_KEY="${EXOSCALE_API_KEY:-$(_readaccountconf_mutable EXOSCALE_API_KEY)}" |
||||
|
EXOSCALE_SECRET_KEY="${EXOSCALE_SECRET_KEY:-$(_readaccountconf_mutable EXOSCALE_SECRET_KEY)}" |
||||
|
|
||||
|
if [ -z "$EXOSCALE_API_KEY" ] || [ -z "$EXOSCALE_SECRET_KEY" ]; then |
||||
|
EXOSCALE_API_KEY="" |
||||
|
EXOSCALE_SECRET_KEY="" |
||||
|
_err "You don't specify Exoscale application key and application secret yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable EXOSCALE_API_KEY "$EXOSCALE_API_KEY" |
||||
|
_saveaccountconf_mutable EXOSCALE_SECRET_KEY "$EXOSCALE_SECRET_KEY" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
# _domain_token=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
|
||||
|
if ! _exoscale_rest GET "domains"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
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 |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain_id=$(echo "$response" | tr '{' "\n" | grep "\"name\":\"$h\"" | _egrep_o "\"id\":[^,]+" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
_domain_token=$(echo "$response" | tr '{' "\n" | grep "\"name\":\"$h\"" | _egrep_o "\"token\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ "$_domain_token" ] && [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# returns response |
||||
|
_exoscale_rest() { |
||||
|
method=$1 |
||||
|
path="$2" |
||||
|
data="$3" |
||||
|
token="$4" |
||||
|
request_url="$EXOSCALE_API/$path" |
||||
|
_debug "$path" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
|
||||
|
if [ "$token" ]; then |
||||
|
export _H2="X-DNS-Domain-Token: $token" |
||||
|
else |
||||
|
export _H2="X-DNS-Token: $EXOSCALE_API_KEY:$EXOSCALE_SECRET_KEY" |
||||
|
fi |
||||
|
|
||||
|
if [ "$data" ] || [ "$method" = "DELETE" ]; then |
||||
|
export _H3="Content-Type: application/json" |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$request_url" "" "$method")" |
||||
|
else |
||||
|
response="$(_get "$request_url" "" "" "$method")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $request_url" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,167 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Author: Janos Lenart <janos@lenart.io> |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: dns_gcloud_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_gcloud_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gcloud" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_dns_gcloud_find_zone || return $? |
||||
|
|
||||
|
# Add an extra RR |
||||
|
_dns_gcloud_start_tr || return $? |
||||
|
_dns_gcloud_get_rrdatas || return $? |
||||
|
echo "$rrdatas" | _dns_gcloud_remove_rrs || return $? |
||||
|
printf "%s\n%s\n" "$rrdatas" "\"$txtvalue\"" | grep -v '^$' | _dns_gcloud_add_rrs || return $? |
||||
|
_dns_gcloud_execute_tr || return $? |
||||
|
|
||||
|
_info "$fulldomain record added" |
||||
|
} |
||||
|
|
||||
|
# Usage: dns_gcloud_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Remove the txt record after validation. |
||||
|
dns_gcloud_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gcloud" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_dns_gcloud_find_zone || return $? |
||||
|
|
||||
|
# Remove one RR |
||||
|
_dns_gcloud_start_tr || return $? |
||||
|
_dns_gcloud_get_rrdatas || return $? |
||||
|
echo "$rrdatas" | _dns_gcloud_remove_rrs || return $? |
||||
|
echo "$rrdatas" | grep -F -v "\"$txtvalue\"" | _dns_gcloud_add_rrs || return $? |
||||
|
_dns_gcloud_execute_tr || return $? |
||||
|
|
||||
|
_info "$fulldomain record added" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_dns_gcloud_start_tr() { |
||||
|
if ! trd=$(mktemp -d); then |
||||
|
_err "_dns_gcloud_start_tr: failed to create temporary directory" |
||||
|
return 1 |
||||
|
fi |
||||
|
tr="$trd/tr.yaml" |
||||
|
_debug tr "$tr" |
||||
|
|
||||
|
if ! gcloud dns record-sets transaction start \ |
||||
|
--transaction-file="$tr" \ |
||||
|
--zone="$managedZone"; then |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_start_tr: failed to execute transaction" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_execute_tr() { |
||||
|
if ! gcloud dns record-sets transaction execute \ |
||||
|
--transaction-file="$tr" \ |
||||
|
--zone="$managedZone"; then |
||||
|
_debug tr "$(cat "$tr")" |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_execute_tr: failed to execute transaction" |
||||
|
return 1 |
||||
|
fi |
||||
|
rm -r "$trd" |
||||
|
|
||||
|
for i in $(seq 1 120); do |
||||
|
if gcloud dns record-sets changes list \ |
||||
|
--zone="$managedZone" \ |
||||
|
--filter='status != done' \ |
||||
|
| grep -q '^.*'; then |
||||
|
_info "_dns_gcloud_execute_tr: waiting for transaction to be comitted ($i/120)..." |
||||
|
sleep 5 |
||||
|
else |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
_err "_dns_gcloud_execute_tr: transaction is still pending after 10 minutes" |
||||
|
rm -r "$trd" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_remove_rrs() { |
||||
|
if ! xargs --no-run-if-empty gcloud dns record-sets transaction remove \ |
||||
|
--name="$fulldomain." \ |
||||
|
--ttl="$ttl" \ |
||||
|
--type=TXT \ |
||||
|
--zone="$managedZone" \ |
||||
|
--transaction-file="$tr"; then |
||||
|
_debug tr "$(cat "$tr")" |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_remove_rrs: failed to remove RRs" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_add_rrs() { |
||||
|
ttl=60 |
||||
|
if ! xargs --no-run-if-empty gcloud dns record-sets transaction add \ |
||||
|
--name="$fulldomain." \ |
||||
|
--ttl="$ttl" \ |
||||
|
--type=TXT \ |
||||
|
--zone="$managedZone" \ |
||||
|
--transaction-file="$tr"; then |
||||
|
_debug tr "$(cat "$tr")" |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_add_rrs: failed to add RRs" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_find_zone() { |
||||
|
# Prepare a filter that matches zones that are suiteable for this entry. |
||||
|
# For example, _acme-challenge.something.domain.com might need to go into something.domain.com or domain.com; |
||||
|
# this function finds the longest postfix that has a managed zone. |
||||
|
part="$fulldomain" |
||||
|
filter="dnsName=( " |
||||
|
while [ "$part" != "" ]; do |
||||
|
filter="$filter$part. " |
||||
|
part="$(echo "$part" | sed 's/[^.]*\.*//')" |
||||
|
done |
||||
|
filter="$filter)" |
||||
|
_debug filter "$filter" |
||||
|
|
||||
|
# List domains and find the longest match (in case of some levels of delegation) |
||||
|
if ! match=$(gcloud dns managed-zones list \ |
||||
|
--format="value(name, dnsName)" \ |
||||
|
--filter="$filter" \ |
||||
|
| while read -r dnsName name; do |
||||
|
printf "%s\t%s\t%s\n" "${#dnsName}" "$dnsName" "$name" |
||||
|
done \ |
||||
|
| sort -n -r | _head_n 1 | cut -f2,3 | grep '^.*'); then |
||||
|
_err "_dns_gcloud_find_zone: Can't find a matching managed zone! Perhaps wrong project or gcloud credentials?" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
dnsName=$(echo "$match" | cut -f2) |
||||
|
_debug dnsName "$dnsName" |
||||
|
managedZone=$(echo "$match" | cut -f1) |
||||
|
_debug managedZone "$managedZone" |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_get_rrdatas() { |
||||
|
if ! rrdatas=$(gcloud dns record-sets list \ |
||||
|
--zone="$managedZone" \ |
||||
|
--name="$fulldomain." \ |
||||
|
--type=TXT \ |
||||
|
--format="value(ttl,rrdatas)"); then |
||||
|
_err "_dns_gcloud_get_rrdatas: Failed to list record-sets" |
||||
|
rm -r "$trd" |
||||
|
return 1 |
||||
|
fi |
||||
|
ttl=$(echo "$rrdatas" | cut -f1) |
||||
|
rrdatas=$(echo "$rrdatas" | cut -f2 | sed 's/","/"\n"/g') |
||||
|
} |
||||
@ -0,0 +1,168 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
#Author: Herman Sletteng |
||||
|
#Report Bugs here: https://github.com/loial/acme.sh |
||||
|
# |
||||
|
# |
||||
|
# Note, gratisdns requires a login first, so the script needs to handle |
||||
|
# temporary cookies. Since acme.sh _get/_post currently don't directly support |
||||
|
# cookies, I've defined wrapper functions _myget/_mypost to set the headers |
||||
|
|
||||
|
GDNSDK_API="https://admin.gratisdns.com" |
||||
|
######## Public functions ##################### |
||||
|
#Usage: dns_gdnsdk_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_gdnsdk_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gratisdns.dk" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
if ! _gratisdns_login; then |
||||
|
_err "Login failed!" |
||||
|
return 1 |
||||
|
fi |
||||
|
#finding domain zone |
||||
|
if ! _get_domain; then |
||||
|
_err "No matching root domain for $fulldomain found" |
||||
|
return 1 |
||||
|
fi |
||||
|
# adding entry |
||||
|
_info "Adding the entry" |
||||
|
_mypost "action=dns_primary_record_added_txt&user_domain=$_domain&name=$fulldomain&txtdata=$txtvalue&ttl=1" |
||||
|
if _successful_update; then return 0; fi |
||||
|
_err "Couldn't create entry!" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_gdnsdk_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gratisdns.dk" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
if ! _gratisdns_login; then |
||||
|
_err "Login failed!" |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _get_domain; then |
||||
|
_err "No matching root domain for $fulldomain found" |
||||
|
return 1 |
||||
|
fi |
||||
|
_findentry "$fulldomain" "$txtvalue" |
||||
|
if [ -z "$_id" ]; then |
||||
|
_info "Entry doesn't exist, nothing to delete" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Deleting record..." |
||||
|
_mypost "action=dns_primary_delete_txt&user_domain=$_domain&id=$_id" |
||||
|
# removing entry |
||||
|
|
||||
|
if _successful_update; then return 0; fi |
||||
|
_err "Couldn't delete entry!" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_checkcredentials() { |
||||
|
GDNSDK_Username="${GDNSDK_Username:-$(_readaccountconf_mutable GDNSDK_Username)}" |
||||
|
GDNSDK_Password="${GDNSDK_Password:-$(_readaccountconf_mutable GDNSDK_Password)}" |
||||
|
|
||||
|
if [ -z "$GDNSDK_Username" ] || [ -z "$GDNSDK_Password" ]; then |
||||
|
GDNSDK_Username="" |
||||
|
GDNSDK_Password="" |
||||
|
_err "You haven't specified gratisdns.dk username and password yet." |
||||
|
_err "Please add credentials and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
#save the credentials to the account conf file. |
||||
|
_saveaccountconf_mutable GDNSDK_Username "$GDNSDK_Username" |
||||
|
_saveaccountconf_mutable GDNSDK_Password "$GDNSDK_Password" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_checkcookie() { |
||||
|
GDNSDK_Cookie="${GDNSDK_Cookie:-$(_readaccountconf_mutable GDNSDK_Cookie)}" |
||||
|
if [ -z "$GDNSDK_Cookie" ]; then |
||||
|
_debug "No cached cookie found" |
||||
|
return 1 |
||||
|
fi |
||||
|
_myget "action=" |
||||
|
if (echo "$_result" | grep -q "logmeout"); then |
||||
|
_debug "Cached cookie still valid" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Cached cookie no longer valid" |
||||
|
GDNSDK_Cookie="" |
||||
|
_saveaccountconf_mutable GDNSDK_Cookie "$GDNSDK_Cookie" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_gratisdns_login() { |
||||
|
if ! _checkcredentials; then return 1; fi |
||||
|
|
||||
|
if _checkcookie; then |
||||
|
_debug "Already logged in" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Logging into GratisDNS with user $GDNSDK_Username" |
||||
|
|
||||
|
if ! _mypost "login=$GDNSDK_Username&password=$GDNSDK_Password&action=logmein"; then |
||||
|
_err "GratisDNS login failed for user $GDNSDK_Username bad RC from _post" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
GDNSDK_Cookie="$(grep -A 15 '302 Found' "$HTTP_HEADER" | _egrep_o 'Cookie: [^;]*' | _head_n 1 | cut -d ' ' -f2)" |
||||
|
|
||||
|
if [ -z "$GDNSDK_Cookie" ]; then |
||||
|
_err "GratisDNS login failed for user $GDNSDK_Username. Check $HTTP_HEADER file" |
||||
|
return 1 |
||||
|
fi |
||||
|
export GDNSDK_Cookie |
||||
|
_saveaccountconf_mutable GDNSDK_Cookie "$GDNSDK_Cookie" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_myget() { |
||||
|
#Adds cookie to request |
||||
|
export _H1="Cookie: $GDNSDK_Cookie" |
||||
|
_result=$(_get "$GDNSDK_API?$1") |
||||
|
} |
||||
|
_mypost() { |
||||
|
#Adds cookie to request |
||||
|
export _H1="Cookie: $GDNSDK_Cookie" |
||||
|
_result=$(_post "$1" "$GDNSDK_API") |
||||
|
} |
||||
|
|
||||
|
_get_domain() { |
||||
|
_myget 'action=dns_primarydns' |
||||
|
_domains=$(echo "$_result" | _egrep_o ' domain="[[:alnum:]._-]+' | sed 's/^.*"//') |
||||
|
if [ -z "$_domains" ]; then |
||||
|
_err "Primary domain list not found!" |
||||
|
return 1 |
||||
|
fi |
||||
|
for _domain in $_domains; do |
||||
|
if (_endswith "$fulldomain" "$_domain"); then |
||||
|
_debug "Root domain: $_domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_successful_update() { |
||||
|
if (echo "$_result" | grep -q 'table-success'); then return 0; fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_findentry() { |
||||
|
#returns id of dns entry, if it exists |
||||
|
_myget "action=dns_primary_changeDNSsetup&user_domain=$_domain" |
||||
|
_id=$(echo "$_result" | _egrep_o "<td>$1</td>\s*<td>$2</td>[^?]*[^&]*&id=[^&]*" | sed 's/^.*=//') |
||||
|
if [ -n "$_id" ]; then |
||||
|
_debug "Entry found with _id=$_id" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
@ -0,0 +1,162 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# hosting.de API |
||||
|
|
||||
|
# Values to export: |
||||
|
# export HOSTINGDE_ENDPOINT='https://secure.hosting.de' |
||||
|
# export HOSTINGDE_APIKEY='xxxxx' |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
dns_hostingde_add() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
_debug "Calling: _hostingde_addRecord() '${fulldomain}' '${txtvalue}'" |
||||
|
_hostingde_apiKey && _hostingde_getZoneConfig && _hostingde_addRecord |
||||
|
return $? |
||||
|
} |
||||
|
|
||||
|
dns_hostingde_rm() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
_debug "Calling: _hostingde_removeRecord() '${fulldomain}' '${txtvalue}'" |
||||
|
_hostingde_apiKey && _hostingde_getZoneConfig && _hostingde_removeRecord |
||||
|
return $? |
||||
|
} |
||||
|
|
||||
|
#################### own Private functions below ################################## |
||||
|
|
||||
|
_hostingde_apiKey() { |
||||
|
HOSTINGDE_APIKEY="${HOSTINGDE_APIKEY:-$(_readaccountconf_mutable HOSTINGDE_APIKEY)}" |
||||
|
HOSTINGDE_ENDPOINT="${HOSTINGDE_ENDPOINT:-$(_readaccountconf_mutable HOSTINGDE_ENDPOINT)}" |
||||
|
if [ -z "$HOSTINGDE_APIKEY" ] || [ -z "$HOSTINGDE_ENDPOINT" ]; then |
||||
|
HOSTINGDE_APIKEY="" |
||||
|
HOSTINGDE_ENDPOINT="" |
||||
|
_err "You haven't specified hosting.de API key or endpoint yet." |
||||
|
_err "Please create your key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable HOSTINGDE_APIKEY "$HOSTINGDE_APIKEY" |
||||
|
_saveaccountconf_mutable HOSTINGDE_ENDPOINT "$HOSTINGDE_ENDPOINT" |
||||
|
} |
||||
|
|
||||
|
_hostingde_parse() { |
||||
|
find="${1}" |
||||
|
if [ "${2}" ]; then |
||||
|
notfind="${2}" |
||||
|
fi |
||||
|
if [ "${notfind}" ]; then |
||||
|
_egrep_o \""${find}\":.*" | grep -v "${notfind}" | cut -d ':' -f 2 | cut -d ',' -f 1 | tr -d ' ' |
||||
|
else |
||||
|
_egrep_o \""${find}\":.*" | cut -d ':' -f 2 | cut -d ',' -f 1 | tr -d ' ' |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_hostingde_getZoneConfig() { |
||||
|
_info "Getting ZoneConfig" |
||||
|
curZone="${fulldomain#*.}" |
||||
|
returnCode=1 |
||||
|
while _contains "${curZone}" "\\."; do |
||||
|
curData="{\"filter\":{\"field\":\"zoneName\",\"value\":\"${curZone}\"},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneConfigsFind")" |
||||
|
_debug "Calling zoneConfigsFind: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneConfigsFind'" |
||||
|
_debug "Result of zoneConfigsFind: '$curResult'" |
||||
|
if _contains "${curResult}" '"status": "error"'; then |
||||
|
if _contains "${curResult}" '"code": 10109'; then |
||||
|
_err "The API-Key is invalid or could not be found" |
||||
|
else |
||||
|
_err "UNKNOWN API ERROR" |
||||
|
fi |
||||
|
returnCode=1 |
||||
|
break |
||||
|
fi |
||||
|
if _contains "${curResult}" '"totalEntries": 1'; then |
||||
|
_info "Retrieved zone data." |
||||
|
_debug "Zone data: '${curResult}'" |
||||
|
zoneConfigId=$(echo "${curResult}" | _hostingde_parse "id") |
||||
|
zoneConfigName=$(echo "${curResult}" | _hostingde_parse "name") |
||||
|
zoneConfigType=$(echo "${curResult}" | _hostingde_parse "type" "FindZoneConfigsResult") |
||||
|
zoneConfigExpire=$(echo "${curResult}" | _hostingde_parse "expire") |
||||
|
zoneConfigNegativeTtl=$(echo "${curResult}" | _hostingde_parse "negativeTtl") |
||||
|
zoneConfigRefresh=$(echo "${curResult}" | _hostingde_parse "refresh") |
||||
|
zoneConfigRetry=$(echo "${curResult}" | _hostingde_parse "retry") |
||||
|
zoneConfigTtl=$(echo "${curResult}" | _hostingde_parse "ttl") |
||||
|
zoneConfigDnsServerGroupId=$(echo "${curResult}" | _hostingde_parse "dnsServerGroupId") |
||||
|
zoneConfigEmailAddress=$(echo "${curResult}" | _hostingde_parse "emailAddress") |
||||
|
zoneConfigDnsSecMode=$(echo "${curResult}" | _hostingde_parse "dnsSecMode") |
||||
|
if [ "${zoneConfigType}" != "\"NATIVE\"" ]; then |
||||
|
_err "Zone is not native" |
||||
|
returnCode=1 |
||||
|
break |
||||
|
fi |
||||
|
_debug "zoneConfigId '${zoneConfigId}'" |
||||
|
returnCode=0 |
||||
|
break |
||||
|
fi |
||||
|
curZone="${curZone#*.}" |
||||
|
done |
||||
|
if [ $returnCode -ne 0 ]; then |
||||
|
_info "ZoneEnd reached, Zone ${curZone} not found in hosting.de API" |
||||
|
fi |
||||
|
return $returnCode |
||||
|
} |
||||
|
|
||||
|
_hostingde_getZoneStatus() { |
||||
|
_debug "Checking Zone status" |
||||
|
curData="{\"filter\":{\"field\":\"zoneConfigId\",\"value\":${zoneConfigId}},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zonesFind")" |
||||
|
_debug "Calling zonesFind '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zonesFind'" |
||||
|
_debug "Result of zonesFind '$curResult'" |
||||
|
zoneStatus=$(echo "${curResult}" | _hostingde_parse "status" "success") |
||||
|
_debug "zoneStatus '${zoneStatus}'" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_hostingde_addRecord() { |
||||
|
_info "Adding record to zone" |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '${zoneStatus}'" |
||||
|
while [ "${zoneStatus}" != "\"active\"" ]; do |
||||
|
_sleep 5 |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '${zoneStatus}'" |
||||
|
done |
||||
|
curData="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":${zoneConfigId},\"name\":${zoneConfigName},\"type\":${zoneConfigType},\"dnsServerGroupId\":${zoneConfigDnsServerGroupId},\"dnsSecMode\":${zoneConfigDnsSecMode},\"emailAddress\":${zoneConfigEmailAddress},\"soaValues\":{\"expire\":${zoneConfigExpire},\"negativeTtl\":${zoneConfigNegativeTtl},\"refresh\":${zoneConfigRefresh},\"retry\":${zoneConfigRetry},\"ttl\":${zoneConfigTtl}}},\"recordsToAdd\":[{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"\\\"${txtvalue}\\\"\",\"ttl\":3600}]}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate")" |
||||
|
_debug "Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'" |
||||
|
_debug "Result of zoneUpdate: '$curResult'" |
||||
|
if _contains "${curResult}" '"status": "error"'; then |
||||
|
if _contains "${curResult}" '"code": 10109'; then |
||||
|
_err "The API-Key is invalid or could not be found" |
||||
|
else |
||||
|
_err "UNKNOWN API ERROR" |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_hostingde_removeRecord() { |
||||
|
_info "Removing record from zone" |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '$zoneStatus'" |
||||
|
while [ "$zoneStatus" != "\"active\"" ]; do |
||||
|
_sleep 5 |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '$zoneStatus'" |
||||
|
done |
||||
|
curData="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":${zoneConfigId},\"name\":${zoneConfigName},\"type\":${zoneConfigType},\"dnsServerGroupId\":${zoneConfigDnsServerGroupId},\"dnsSecMode\":${zoneConfigDnsSecMode},\"emailAddress\":${zoneConfigEmailAddress},\"soaValues\":{\"expire\":${zoneConfigExpire},\"negativeTtl\":${zoneConfigNegativeTtl},\"refresh\":${zoneConfigRefresh},\"retry\":${zoneConfigRetry},\"ttl\":${zoneConfigTtl}}},\"recordsToDelete\":[{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"\\\"${txtvalue}\\\"\"}]}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate")" |
||||
|
_debug "Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'" |
||||
|
_debug "Result of zoneUpdate: '$curResult'" |
||||
|
if _contains "${curResult}" '"status": "error"'; then |
||||
|
if _contains "${curResult}" '"code": 10109'; then |
||||
|
_err "The API-Key is invalid or could not be found" |
||||
|
else |
||||
|
_err "UNKNOWN API ERROR" |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,185 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Original Author: Philipp Grosswiler <philipp.grosswiler@swiss-design.net> |
||||
|
#v4 Update Author: Aaron W. Swenson <aaron@grandmasfridge.org> |
||||
|
|
||||
|
LINODE_V4_API_URL="https://api.linode.com/v4/domains" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_linode_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_linode_v4_add() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
if ! _Linode_API; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using Linode" |
||||
|
_debug "Calling: dns_linode_add() '${fulldomain}' '${txtvalue}'" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_payload="{ |
||||
|
\"type\": \"TXT\", |
||||
|
\"name\": \"$_sub_domain\", |
||||
|
\"target\": \"$txtvalue\" |
||||
|
}" |
||||
|
|
||||
|
if _rest POST "/$_domain_id/records" "$_payload" && [ -n "$response" ]; then |
||||
|
_resource_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\s*[0-9]+" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
_debug _resource_id "$_resource_id" |
||||
|
|
||||
|
if [ -z "$_resource_id" ]; then |
||||
|
_err "Error adding the domain resource." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Domain resource successfully added." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: dns_linode_rm _acme-challenge.www.domain.com |
||||
|
dns_linode_v4_rm() { |
||||
|
fulldomain="${1}" |
||||
|
|
||||
|
if ! _Linode_API; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using Linode" |
||||
|
_debug "Calling: dns_linode_rm() '${fulldomain}'" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
if _rest GET "/$_domain_id/records" && [ -n "$response" ]; then |
||||
|
response="$(echo "$response" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
|
||||
|
resource="$(echo "$response" | _egrep_o "{.*\"name\":\s*\"$_sub_domain\".*}")" |
||||
|
if [ "$resource" ]; then |
||||
|
_resource_id=$(printf "%s\n" "$resource" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "$_resource_id" ]; then |
||||
|
_debug _resource_id "$_resource_id" |
||||
|
|
||||
|
if _rest DELETE "/$_domain_id/records/$_resource_id" && [ -n "$response" ]; then |
||||
|
# On 200/OK, empty set is returned. Check for error, if any. |
||||
|
_error_response=$(printf "%s\n" "$response" | _egrep_o "\"errors\"" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
|
||||
|
if [ -n "$_error_response" ]; then |
||||
|
_err "Error deleting the domain resource: $_error_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Domain resource successfully deleted." |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_Linode_API() { |
||||
|
if [ -z "$LINODE_V4_API_KEY" ]; then |
||||
|
LINODE_V4_API_KEY="" |
||||
|
|
||||
|
_err "You didn't specify the Linode v4 API key yet." |
||||
|
_err "Please create your key and try again." |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf LINODE_V4_API_KEY "$LINODE_V4_API_KEY" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=12345 |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
if _rest GET; then |
||||
|
response="$(echo "$response" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hostedzone="$(echo "$response" | _egrep_o "{.*\"domain\":\s*\"$h\".*}")" |
||||
|
if [ "$hostedzone" ]; then |
||||
|
_domain_id=$(printf "%s\n" "$hostedzone" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#method method action data |
||||
|
_rest() { |
||||
|
mtd="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
|
||||
|
_debug mtd "$mtd" |
||||
|
_debug ep "$ep" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Authorization: Bearer $LINODE_V4_API_KEY" |
||||
|
|
||||
|
if [ "$mtd" != "GET" ]; then |
||||
|
# both POST and DELETE. |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$LINODE_V4_API_URL$ep" "" "$mtd")" |
||||
|
else |
||||
|
response="$(_get "$LINODE_V4_API_URL$ep$data")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# MyDevil.net API (2019-02-03) |
||||
|
# |
||||
|
# MyDevil.net already supports automatic Let's Encrypt certificates, |
||||
|
# except for wildcard domains. |
||||
|
# |
||||
|
# This script depends on `devil` command that MyDevil.net provides, |
||||
|
# which means that it works only on server side. |
||||
|
# |
||||
|
# Author: Marcin Konicki <https://ahwayakchih.neoni.net> |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_mydevil_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_mydevil_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using mydevil" |
||||
|
|
||||
|
domain=$(mydevil_get_domain "$fulldomain") |
||||
|
if [ -z "$domain" ]; then |
||||
|
_err "Invalid domain name: could not find root domain of $fulldomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# No need to check if record name exists, `devil` always adds new record. |
||||
|
# In worst case scenario, we end up with multiple identical records. |
||||
|
|
||||
|
_info "Adding $fulldomain record for domain $domain" |
||||
|
if devil dns add "$domain" "$fulldomain" TXT "$txtvalue"; then |
||||
|
_info "Successfully added TXT record, ready for validation." |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Unable to add DNS record." |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_mydevil_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using mydevil" |
||||
|
|
||||
|
domain=$(mydevil_get_domain "$fulldomain") |
||||
|
if [ -z "$domain" ]; then |
||||
|
_err "Invalid domain name: could not find root domain of $fulldomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# catch one or more numbers |
||||
|
num='[0-9][0-9]*' |
||||
|
# catch one or more whitespace |
||||
|
w=$(printf '[\t ][\t ]*') |
||||
|
# catch anything, except newline |
||||
|
any='.*' |
||||
|
# filter to make sure we do not delete other records |
||||
|
validRecords="^${num}${w}${fulldomain}${w}TXT${w}${any}${txtvalue}$" |
||||
|
for id in $(devil dns list "$domain" | tail -n+2 | grep "${validRecords}" | cut -w -s -f 1); do |
||||
|
_info "Removing record $id from domain $domain" |
||||
|
devil dns del "$domain" "$id" || _err "Could not remove DNS record." |
||||
|
done |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Usage: domain=$(mydevil_get_domain "_acme-challenge.www.domain.com" || _err "Invalid domain name") |
||||
|
# echo $domain |
||||
|
mydevil_get_domain() { |
||||
|
fulldomain=$1 |
||||
|
domain="" |
||||
|
|
||||
|
for domain in $(devil dns list | cut -w -s -f 1 | tail -n+2); do |
||||
|
if _endswith "$fulldomain" "$domain"; then |
||||
|
printf -- "%s" "$domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
@ -0,0 +1,210 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Here is a api script for MyDNS.JP. |
||||
|
#This file name is "dns_mydnsjp.sh" |
||||
|
#So, here must be a method dns_mydnsjp_add() |
||||
|
#Which will be called by acme.sh to add the txt record to your api system. |
||||
|
#returns 0 means success, otherwise error. |
||||
|
# |
||||
|
#Author: epgdatacapbon |
||||
|
#Report Bugs here: https://github.com/epgdatacapbon/acme.sh |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Export MyDNS.JP MasterID and Password in following variables... |
||||
|
# MYDNSJP_MasterID=MasterID |
||||
|
# MYDNSJP_Password=Password |
||||
|
|
||||
|
MYDNSJP_API="https://www.mydns.jp" |
||||
|
|
||||
|
#Usage: dns_mydnsjp_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_mydnsjp_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Using mydnsjp" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
# Load the credentials from the account conf file |
||||
|
MYDNSJP_MasterID="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}" |
||||
|
MYDNSJP_Password="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}" |
||||
|
if [ -z "$MYDNSJP_MasterID" ] || [ -z "$MYDNSJP_Password" ]; then |
||||
|
MYDNSJP_MasterID="" |
||||
|
MYDNSJP_Password="" |
||||
|
_err "You don't specify mydnsjp api MasterID and Password yet." |
||||
|
_err "Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Save the credentials to the account conf file |
||||
|
_saveaccountconf_mutable MYDNSJP_MasterID "$MYDNSJP_MasterID" |
||||
|
_saveaccountconf_mutable MYDNSJP_Password "$MYDNSJP_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" |
||||
|
|
||||
|
if _mydnsjp_api "REGIST" "$_domain" "$txtvalue"; then |
||||
|
if printf -- "%s" "$response" | grep "OK." >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_mydnsjp_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Removing TXT record" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
# Load the credentials from the account conf file |
||||
|
MYDNSJP_MasterID="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}" |
||||
|
MYDNSJP_Password="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}" |
||||
|
if [ -z "$MYDNSJP_MasterID" ] || [ -z "$MYDNSJP_Password" ]; then |
||||
|
MYDNSJP_MasterID="" |
||||
|
MYDNSJP_Password="" |
||||
|
_err "You don't specify mydnsjp api MasterID and Password yet." |
||||
|
_err "Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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" |
||||
|
|
||||
|
if _mydnsjp_api "DELETE" "$_domain" "$txtvalue"; then |
||||
|
if printf -- "%s" "$response" | grep "OK." >/dev/null; then |
||||
|
_info "Deleted, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Delete txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Delete txt record error." |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
# _acme-challenge.www.domain.com |
||||
|
# returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
fulldomain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
# Get the root domain |
||||
|
_mydnsjp_retrieve_domain |
||||
|
if [ "$?" != "0" ]; then |
||||
|
# not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
while true; do |
||||
|
_domain=$(printf "%s" "$fulldomain" | cut -d . -f $i-100) |
||||
|
|
||||
|
if [ -z "$_domain" ]; then |
||||
|
# not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ "$_domain" = "$_root_domain" ]; then |
||||
|
_sub_domain=$(printf "%s" "$fulldomain" | cut -d . -f 1-$p) |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Retrieve the root domain |
||||
|
# returns 0 success |
||||
|
_mydnsjp_retrieve_domain() { |
||||
|
_debug "Login to MyDNS.JP" |
||||
|
|
||||
|
response="$(_post "masterid=$MYDNSJP_MasterID&masterpwd=$MYDNSJP_Password" "$MYDNSJP_API/?MENU=100")" |
||||
|
cookie="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _head_n 1 | cut -d " " -f 2)" |
||||
|
|
||||
|
# If cookies is not empty then logon successful |
||||
|
if [ -z "$cookie" ]; then |
||||
|
_err "Fail to get a cookie." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "Retrieve DOMAIN INFO page" |
||||
|
|
||||
|
export _H1="Cookie:${cookie}" |
||||
|
|
||||
|
response="$(_get "$MYDNSJP_API/?MENU=300")" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "Fail to retrieve DOMAIN INFO." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_root_domain=$(echo "$response" | grep "DNSINFO\[domainname\]" | sed 's/^.*value="\([^"]*\)".*/\1/') |
||||
|
|
||||
|
# Logout |
||||
|
response="$(_get "$MYDNSJP_API/?MENU=090")" |
||||
|
|
||||
|
_debug _root_domain "$_root_domain" |
||||
|
|
||||
|
if [ -z "$_root_domain" ]; then |
||||
|
_err "Fail to get the root domain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_mydnsjp_api() { |
||||
|
cmd=$1 |
||||
|
domain=$2 |
||||
|
txtvalue=$3 |
||||
|
|
||||
|
# Base64 encode the credentials |
||||
|
credentials=$(printf "%s:%s" "$MYDNSJP_MasterID" "$MYDNSJP_Password" | _base64) |
||||
|
|
||||
|
# Construct the HTTP Authorization header |
||||
|
export _H1="Content-Type: application/x-www-form-urlencoded" |
||||
|
export _H2="Authorization: Basic ${credentials}" |
||||
|
|
||||
|
response="$(_post "CERTBOT_DOMAIN=$domain&CERTBOT_VALIDATION=$txtvalue&EDIT_CMD=$cmd" "$MYDNSJP_API/directedit.html")" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,407 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Namecheap API |
||||
|
# https://www.namecheap.com/support/api/intro.aspx |
||||
|
# |
||||
|
# Requires Namecheap API key set in |
||||
|
#NAMECHEAP_API_KEY, |
||||
|
#NAMECHEAP_USERNAME, |
||||
|
#NAMECHEAP_SOURCEIP |
||||
|
# Due to Namecheap's API limitation all the records of your domain will be read and re applied, make sure to have a backup of your records you could apply if any issue would arise. |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
NAMECHEAP_API="https://api.namecheap.com/xml.response" |
||||
|
|
||||
|
#Usage: dns_namecheap_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_namecheap_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _namecheap_check_config; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _namecheap_set_publicip; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_set_namecheap_TXT "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_namecheap_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _namecheap_set_publicip; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _namecheap_check_config; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_del_namecheap_TXT "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
fulldomain=$1 |
||||
|
|
||||
|
if ! _get_root_by_getList "$fulldomain"; then |
||||
|
_debug "Failed domain lookup via domains.getList api call. Trying domain lookup via domains.dns.getHosts api." |
||||
|
# The above "getList" api will only return hosts *owned* by the calling user. However, if the calling |
||||
|
# user is not the owner, but still has administrative rights, we must query the getHosts api directly. |
||||
|
# See this comment and the official namecheap response: http://disq.us/p/1q6v9x9 |
||||
|
if ! _get_root_by_getHosts "$fulldomain"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_get_root_by_getList() { |
||||
|
domain=$1 |
||||
|
|
||||
|
if ! _namecheap_post "namecheap.domains.getList"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
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 |
||||
|
if ! _contains "$h" "\\."; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _contains "$response" "$h"; then |
||||
|
_debug "$h not found" |
||||
|
else |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
return 0 |
||||
|
fi |
||||
|
p="$i" |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_get_root_by_getHosts() { |
||||
|
i=100 |
||||
|
p=99 |
||||
|
|
||||
|
while [ $p -ne 0 ]; do |
||||
|
|
||||
|
h=$(printf "%s" "$1" | cut -d . -f $i-100) |
||||
|
if [ -n "$h" ]; then |
||||
|
if _contains "$h" "\\."; then |
||||
|
_debug h "$h" |
||||
|
if _namecheap_set_tld_sld "$h"; then |
||||
|
_sub_domain=$(printf "%s" "$1" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "$h not found" |
||||
|
fi |
||||
|
fi |
||||
|
fi |
||||
|
i="$p" |
||||
|
p=$(_math "$p" - 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_namecheap_set_publicip() { |
||||
|
|
||||
|
if [ -z "$NAMECHEAP_SOURCEIP" ]; then |
||||
|
_err "No Source IP specified for Namecheap API." |
||||
|
_err "Use your public ip address or an url to retrieve it (e.g. https://ipconfig.co/ip) and export it as NAMECHEAP_SOURCEIP" |
||||
|
return 1 |
||||
|
else |
||||
|
_saveaccountconf NAMECHEAP_SOURCEIP "$NAMECHEAP_SOURCEIP" |
||||
|
_debug sourceip "$NAMECHEAP_SOURCEIP" |
||||
|
|
||||
|
ip=$(echo "$NAMECHEAP_SOURCEIP" | _egrep_o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') |
||||
|
addr=$(echo "$NAMECHEAP_SOURCEIP" | _egrep_o '(http|https)://.*') |
||||
|
|
||||
|
_debug2 ip "$ip" |
||||
|
_debug2 addr "$addr" |
||||
|
|
||||
|
if [ -n "$ip" ]; then |
||||
|
_publicip="$ip" |
||||
|
elif [ -n "$addr" ]; then |
||||
|
_publicip=$(_get "$addr") |
||||
|
else |
||||
|
_err "No Source IP specified for Namecheap API." |
||||
|
_err "Use your public ip address or an url to retrieve it (e.g. https://ipconfig.co/ip) and export it as NAMECHEAP_SOURCEIP" |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
_debug publicip "$_publicip" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_namecheap_post() { |
||||
|
command=$1 |
||||
|
data="ApiUser=${NAMECHEAP_USERNAME}&ApiKey=${NAMECHEAP_API_KEY}&ClientIp=${_publicip}&UserName=${NAMECHEAP_USERNAME}&Command=${command}" |
||||
|
_debug2 "_namecheap_post data" "$data" |
||||
|
response="$(_post "$data" "$NAMECHEAP_API" "" "POST")" |
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
if _contains "$response" "Status=\"ERROR\"" >/dev/null; then |
||||
|
error=$(echo "$response" | _egrep_o ">.*<\\/Error>" | cut -d '<' -f 1 | tr -d '>') |
||||
|
_err "error $error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_namecheap_parse_host() { |
||||
|
_host=$1 |
||||
|
_debug _host "$_host" |
||||
|
|
||||
|
_hostid=$(echo "$_host" | _egrep_o ' HostId="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostname=$(echo "$_host" | _egrep_o ' Name="[^"]*' | cut -d '"' -f 2) |
||||
|
_hosttype=$(echo "$_host" | _egrep_o ' Type="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostaddress=$(echo "$_host" | _egrep_o ' Address="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostmxpref=$(echo "$_host" | _egrep_o ' MXPref="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostttl=$(echo "$_host" | _egrep_o ' TTL="[^"]*' | cut -d '"' -f 2) |
||||
|
|
||||
|
_debug hostid "$_hostid" |
||||
|
_debug hostname "$_hostname" |
||||
|
_debug hosttype "$_hosttype" |
||||
|
_debug hostaddress "$_hostaddress" |
||||
|
_debug hostmxpref "$_hostmxpref" |
||||
|
_debug hostttl "$_hostttl" |
||||
|
} |
||||
|
|
||||
|
_namecheap_check_config() { |
||||
|
|
||||
|
if [ -z "$NAMECHEAP_API_KEY" ]; then |
||||
|
_err "No API key specified for Namecheap API." |
||||
|
_err "Create your key and export it as NAMECHEAP_API_KEY" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$NAMECHEAP_USERNAME" ]; then |
||||
|
_err "No username key specified for Namecheap API." |
||||
|
_err "Create your key and export it as NAMECHEAP_USERNAME" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf NAMECHEAP_API_KEY "$NAMECHEAP_API_KEY" |
||||
|
_saveaccountconf NAMECHEAP_USERNAME "$NAMECHEAP_USERNAME" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_set_namecheap_TXT() { |
||||
|
subdomain=$2 |
||||
|
txt=$3 |
||||
|
|
||||
|
if ! _namecheap_set_tld_sld "$1"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
request="namecheap.domains.dns.getHosts&SLD=${_sld}&TLD=${_tld}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hosts=$(echo "$response" | _egrep_o '<host[^>]*') |
||||
|
_debug hosts "$hosts" |
||||
|
|
||||
|
if [ -z "$hosts" ]; then |
||||
|
_error "Hosts not found" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_namecheap_reset_hostList |
||||
|
|
||||
|
while read -r host; do |
||||
|
if _contains "$host" "<host"; then |
||||
|
_namecheap_parse_host "$host" |
||||
|
_debug2 _hostname "_hostname" |
||||
|
_debug2 _hosttype "_hosttype" |
||||
|
_debug2 _hostaddress "_hostaddress" |
||||
|
_debug2 _hostmxpref "_hostmxpref" |
||||
|
_hostaddress="$(printf "%s" "$_hostaddress" | _url_encode)" |
||||
|
_debug2 "encoded _hostaddress" "_hostaddress" |
||||
|
_namecheap_add_host "$_hostname" "$_hosttype" "$_hostaddress" "$_hostmxpref" "$_hostttl" |
||||
|
fi |
||||
|
done <<EOT |
||||
|
echo "$hosts" |
||||
|
EOT |
||||
|
|
||||
|
_namecheap_add_host "$subdomain" "TXT" "$txt" 10 120 |
||||
|
|
||||
|
_debug hostrequestfinal "$_hostrequest" |
||||
|
|
||||
|
request="namecheap.domains.dns.setHosts&SLD=${_sld}&TLD=${_tld}${_hostrequest}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_del_namecheap_TXT() { |
||||
|
subdomain=$2 |
||||
|
txt=$3 |
||||
|
|
||||
|
if ! _namecheap_set_tld_sld "$1"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
request="namecheap.domains.dns.getHosts&SLD=${_sld}&TLD=${_tld}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hosts=$(echo "$response" | _egrep_o '<host[^>]*') |
||||
|
_debug hosts "$hosts" |
||||
|
|
||||
|
if [ -z "$hosts" ]; then |
||||
|
_error "Hosts not found" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_namecheap_reset_hostList |
||||
|
|
||||
|
found=0 |
||||
|
|
||||
|
while read -r host; do |
||||
|
if _contains "$host" "<host"; then |
||||
|
_namecheap_parse_host "$host" |
||||
|
if [ "$_hosttype" = "TXT" ] && [ "$_hostname" = "$subdomain" ] && [ "$_hostaddress" = "$txt" ]; then |
||||
|
_debug "TXT entry found" |
||||
|
found=1 |
||||
|
else |
||||
|
_hostaddress="$(printf "%s" "$_hostaddress" | _url_encode)" |
||||
|
_namecheap_add_host "$_hostname" "$_hosttype" "$_hostaddress" "$_hostmxpref" "$_hostttl" |
||||
|
fi |
||||
|
fi |
||||
|
done <<EOT |
||||
|
echo "$hosts" |
||||
|
EOT |
||||
|
|
||||
|
if [ $found -eq 0 ]; then |
||||
|
_debug "TXT entry not found" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
_debug hostrequestfinal "$_hostrequest" |
||||
|
|
||||
|
request="namecheap.domains.dns.setHosts&SLD=${_sld}&TLD=${_tld}${_hostrequest}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_namecheap_reset_hostList() { |
||||
|
_hostindex=0 |
||||
|
_hostrequest="" |
||||
|
} |
||||
|
|
||||
|
#Usage: _namecheap_add_host HostName RecordType Address MxPref TTL |
||||
|
_namecheap_add_host() { |
||||
|
_hostindex=$(_math "$_hostindex" + 1) |
||||
|
_hostrequest=$(printf '%s&HostName%d=%s&RecordType%d=%s&Address%d=%s&MXPref%d=%d&TTL%d=%d' "$_hostrequest" "$_hostindex" "$1" "$_hostindex" "$2" "$_hostindex" "$3" "$_hostindex" "$4" "$_hostindex" "$5") |
||||
|
} |
||||
|
|
||||
|
_namecheap_set_tld_sld() { |
||||
|
domain=$1 |
||||
|
_tld="" |
||||
|
_sld="" |
||||
|
|
||||
|
i=2 |
||||
|
|
||||
|
while true; do |
||||
|
|
||||
|
_tld=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug tld "$_tld" |
||||
|
|
||||
|
if [ -z "$_tld" ]; then |
||||
|
_debug "invalid tld" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
j=$(_math "$i" - 1) |
||||
|
|
||||
|
_sld=$(printf "%s" "$domain" | cut -d . -f 1-"$j") |
||||
|
_debug sld "$_sld" |
||||
|
|
||||
|
if [ -z "$_sld" ]; then |
||||
|
_debug "invalid sld" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
request="namecheap.domains.dns.getHosts&SLD=$_sld&TLD=$_tld" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_debug "sld($_sld)/tld($_tld) not found" |
||||
|
else |
||||
|
_debug "sld($_sld)/tld($_tld) found" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
i=$(_math "$i" + 1) |
||||
|
|
||||
|
done |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,131 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#NederHost_Key="sdfgikogfdfghjklkjhgfcdcfghjk" |
||||
|
|
||||
|
NederHost_Api="https://api.nederhost.nl/dns/v1" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_nederhost_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
NederHost_Key="${NederHost_Key:-$(_readaccountconf_mutable NederHost_Key)}" |
||||
|
if [ -z "$NederHost_Key" ]; then |
||||
|
NederHost_Key="" |
||||
|
_err "You didn't specify a NederHost api key." |
||||
|
_err "You can get yours from https://www.nederhost.nl/mijn_nederhost" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable NederHost_Key "$NederHost_Key" |
||||
|
|
||||
|
_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 _nederhost_rest PATCH "zones/$_domain/records/$fulldomain/TXT" "[{\"content\":\"$txtvalue\",\"ttl\":60}]"; then |
||||
|
if _contains "$response" "$fulldomain"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_nederhost_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
NederHost_Key="${NederHost_Key:-$(_readaccountconf_mutable NederHost_Key)}" |
||||
|
if [ -z "$NederHost_Key" ]; then |
||||
|
NederHost_Key="" |
||||
|
_err "You didn't specify a NederHost api key." |
||||
|
_err "You can get yours from https://www.nederhost.nl/mijn_nederhost" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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 "Removing txt record" |
||||
|
_nederhost_rest DELETE "zones/${_domain}/records/$fulldomain/TXT?content=$txtvalue" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
_domain=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_debug _domain "$_domain" |
||||
|
if [ -z "$_domain" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _nederhost_rest GET "zones/${_domain}"; then |
||||
|
if [ "${_code}" = "204" ]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
else |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_nederhost_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
export _H1="Authorization: Bearer $NederHost_Key" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$NederHost_Api/$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$NederHost_Api/$ep")" |
||||
|
fi |
||||
|
|
||||
|
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" |
||||
|
_debug "http response code $_code" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,181 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# |
||||
|
# NEODIGIT_API_TOKEN="jasdfhklsjadhflnhsausdfas" |
||||
|
|
||||
|
# This is Neodigit.net api wrapper for acme.sh |
||||
|
# |
||||
|
# Author: Adrian Almenar |
||||
|
# Report Bugs here: https://github.com/tecnocratica/acme.sh |
||||
|
# |
||||
|
NEODIGIT_API_URL="https://api.neodigit.net/v1" |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_neodigit_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
NEODIGIT_API_TOKEN="${NEODIGIT_API_TOKEN:-$(_readaccountconf_mutable NEODIGIT_API_TOKEN)}" |
||||
|
if [ -z "$NEODIGIT_API_TOKEN" ]; then |
||||
|
NEODIGIT_API_TOKEN="" |
||||
|
_err "You haven't specified a Token api key." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable NEODIGIT_API_TOKEN "$NEODIGIT_API_TOKEN" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_neo_rest GET "dns/zones/${_domain_id}/records?type=TXT&name=$fulldomain" |
||||
|
|
||||
|
_debug _code "$_code" |
||||
|
|
||||
|
if [ "$_code" != "200" ]; then |
||||
|
_err "error retrieving data!" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
if _neo_rest POST "dns/zones/$_domain_id/records" "{\"record\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":60}}"; then |
||||
|
if printf -- "%s" "$response" | grep "$_sub_domain" >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_neodigit_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
NEODIGIT_API_TOKEN="${NEODIGIT_API_TOKEN:-$(_readaccountconf_mutable NEODIGIT_API_TOKEN)}" |
||||
|
if [ -z "$NEODIGIT_API_TOKEN" ]; then |
||||
|
NEODIGIT_API_TOKEN="" |
||||
|
_err "You haven't specified a Token api key." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable NEODIGIT_API_TOKEN "$NEODIGIT_API_TOKEN" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_neo_rest GET "dns/zones/${_domain_id}/records?type=TXT&name=$fulldomain&content=$txtvalue" |
||||
|
|
||||
|
if [ "$_code" != "200" ]; then |
||||
|
_err "error retrieving data!" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
record_id=$(echo "$response" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d: -f2 | cut -d, -f1) |
||||
|
_debug "record_id" "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _neo_rest DELETE "dns/zones/$_domain_id/records/$record_id"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=dasfdsafsadg5ythd |
||||
|
_get_root() { |
||||
|
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 |
||||
|
|
||||
|
if ! _neo_rest GET "dns/zones?name=$h"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug p "$p" |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain_id=$(echo "$response" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d: -f2 | cut -d, -f1) |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_neo_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
export _H1="X-TCPanel-Token: $NEODIGIT_API_TOKEN" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$NEODIGIT_API_URL/$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$NEODIGIT_API_URL/$ep")" |
||||
|
fi |
||||
|
|
||||
|
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,134 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
#developed by linux-insideDE |
||||
|
|
||||
|
NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}" |
||||
|
NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}" |
||||
|
NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}" |
||||
|
end="https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON" |
||||
|
client="" |
||||
|
|
||||
|
dns_netcup_add() { |
||||
|
_debug NC_Apikey "$NC_Apikey" |
||||
|
login |
||||
|
if [ "$NC_Apikey" = "" ] || [ "$NC_Apipw" = "" ] || [ "$NC_CID" = "" ]; then |
||||
|
_err "No Credentials given" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable NC_Apikey "$NC_Apikey" |
||||
|
_saveaccountconf_mutable NC_Apipw "$NC_Apipw" |
||||
|
_saveaccountconf_mutable NC_CID "$NC_CID" |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c) |
||||
|
exit=$(_math "$exit" + 1) |
||||
|
i=$exit |
||||
|
|
||||
|
while |
||||
|
[ "$exit" -gt 0 ] |
||||
|
do |
||||
|
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit") |
||||
|
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then |
||||
|
domain="$tmp" |
||||
|
else |
||||
|
domain="$tmp.$domain" |
||||
|
fi |
||||
|
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then |
||||
|
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") |
||||
|
_debug "$msg" |
||||
|
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
else |
||||
|
break |
||||
|
fi |
||||
|
fi |
||||
|
fi |
||||
|
exit=$(_math "$exit" - 1) |
||||
|
done |
||||
|
logout |
||||
|
} |
||||
|
|
||||
|
dns_netcup_rm() { |
||||
|
login |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
domain="" |
||||
|
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c) |
||||
|
exit=$(_math "$exit" + 1) |
||||
|
i=$exit |
||||
|
rec="" |
||||
|
|
||||
|
while |
||||
|
[ "$exit" -gt 0 ] |
||||
|
do |
||||
|
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit") |
||||
|
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then |
||||
|
domain="$tmp" |
||||
|
else |
||||
|
domain="$tmp.$domain" |
||||
|
fi |
||||
|
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then |
||||
|
msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST") |
||||
|
rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g') |
||||
|
_debug "$msg" |
||||
|
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
else |
||||
|
break |
||||
|
fi |
||||
|
fi |
||||
|
fi |
||||
|
exit=$(_math "$exit" - 1) |
||||
|
done |
||||
|
|
||||
|
ida=0000 |
||||
|
idv=0001 |
||||
|
ids=0000000000 |
||||
|
i=1 |
||||
|
while |
||||
|
[ "$i" -ne 0 ] |
||||
|
do |
||||
|
specrec=$(_getfield "$rec" "$i" ";") |
||||
|
idv="$ida" |
||||
|
ida=$(_getfield "$specrec" "1" "," | sed 's/\"id\":\"//g' | sed 's/\"//g') |
||||
|
txtv=$(_getfield "$specrec" "5" "," | sed 's/\"destination\":\"//g' | sed 's/\"//g') |
||||
|
i=$(_math "$i" + 1) |
||||
|
if [ "$txtvalue" = "$txtv" ]; then |
||||
|
i=0 |
||||
|
ids="$ida" |
||||
|
fi |
||||
|
if [ "$ida" = "$idv" ]; then |
||||
|
i=0 |
||||
|
fi |
||||
|
done |
||||
|
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") |
||||
|
_debug "$msg" |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
fi |
||||
|
logout |
||||
|
} |
||||
|
|
||||
|
login() { |
||||
|
tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") |
||||
|
sid=$(_getfield "$tmp" "8" | sed s/\"responsedata\":\{\"apisessionid\":\"//g | sed 's/\"\}\}//g') |
||||
|
_debug "$tmp" |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
logout() { |
||||
|
tmp=$(_post "{\"action\": \"logout\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") |
||||
|
_debug "$tmp" |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
@ -0,0 +1,211 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
######################################################################## |
||||
|
# NocWorx script for acme.sh |
||||
|
# |
||||
|
# Handles DNS Updates for the Following vendors: |
||||
|
# - Nexcess.net |
||||
|
# - Thermo.io |
||||
|
# - Futurehosting.com |
||||
|
# |
||||
|
# Environment variables: |
||||
|
# |
||||
|
# - NW_API_TOKEN (Your API Token) |
||||
|
# - NW_API_ENDPOINT (One of the following listed below) |
||||
|
# |
||||
|
# Endpoints: |
||||
|
# - https://portal.nexcess.net (default) |
||||
|
# - https://core.thermo.io |
||||
|
# - https://my.futurehosting.com |
||||
|
# |
||||
|
# Note: If you do not have an API token, one can be generated at one |
||||
|
# of the following URLs: |
||||
|
# - https://portal.nexcess.net/api-token |
||||
|
# - https://core.thermo.io/api-token |
||||
|
# - https://my.futurehosting.com/api-token |
||||
|
# |
||||
|
# Author: Frank Laszlo <flaszlo@nexcess.net> |
||||
|
|
||||
|
NW_API_VERSION="0" |
||||
|
|
||||
|
# dns_nw_add() - Add TXT record |
||||
|
# Usage: dns_nw_add _acme-challenge.subdomain.domain.com "XyZ123..." |
||||
|
dns_nw_add() { |
||||
|
host="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
_debug host "${host}" |
||||
|
_debug txtvalue "${txtvalue}" |
||||
|
|
||||
|
if ! _check_nw_api_creds; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using NocWorx (${NW_API_ENDPOINT})" |
||||
|
_debug "Calling: dns_nw_add() '${host}' '${txtvalue}'" |
||||
|
|
||||
|
_debug "Detecting root zone" |
||||
|
if ! _get_root "${host}"; then |
||||
|
_err "Zone for domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _zone_id "${_zone_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
|
||||
|
_post_data="{\"zone_id\": \"${_zone_id}\", \"type\": \"TXT\", \"host\": \"${host}\", \"target\": \"${txtvalue}\", \"ttl\": \"300\"}" |
||||
|
|
||||
|
if _rest POST "dns-record" "${_post_data}" && [ -n "${response}" ]; then |
||||
|
_record_id=$(printf "%s\n" "${response}" | _egrep_o "\"record_id\": *[0-9]+" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
_debug _record_id "${_record_id}" |
||||
|
|
||||
|
if [ -z "$_record_id" ]; then |
||||
|
_err "Error adding the TXT record." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "TXT record successfully added." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# dns_nw_rm() - Remove TXT record |
||||
|
# Usage: dns_nw_rm _acme-challenge.subdomain.domain.com "XyZ123..." |
||||
|
dns_nw_rm() { |
||||
|
host="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
_debug host "${host}" |
||||
|
_debug txtvalue "${txtvalue}" |
||||
|
|
||||
|
if ! _check_nw_api_creds; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using NocWorx (${NW_API_ENDPOINT})" |
||||
|
_debug "Calling: dns_nw_rm() '${host}'" |
||||
|
|
||||
|
_debug "Detecting root zone" |
||||
|
if ! _get_root "${host}"; then |
||||
|
_err "Zone for domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _zone_id "${_zone_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
|
||||
|
_parameters="?zone_id=${_zone_id}" |
||||
|
|
||||
|
if _rest GET "dns-record" "${_parameters}" && [ -n "${response}" ]; then |
||||
|
response="$(echo "${response}" | tr -d "\n" | sed 's/^\[\(.*\)\]$/\1/' | sed -e 's/{"record_id":/|"record_id":/g' | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
_debug response "${response}" |
||||
|
|
||||
|
record="$(echo "${response}" | _egrep_o "{.*\"host\": *\"${_sub_domain}\", *\"target\": *\"${txtvalue}\".*}")" |
||||
|
_debug record "${record}" |
||||
|
|
||||
|
if [ "${record}" ]; then |
||||
|
_record_id=$(printf "%s\n" "${record}" | _egrep_o "\"record_id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "${_record_id}" ]; then |
||||
|
_debug _record_id "${_record_id}" |
||||
|
|
||||
|
_rest DELETE "dns-record/${_record_id}" |
||||
|
|
||||
|
_info "TXT record successfully deleted." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_check_nw_api_creds() { |
||||
|
NW_API_TOKEN="${NW_API_TOKEN:-$(_readaccountconf_mutable NW_API_TOKEN)}" |
||||
|
NW_API_ENDPOINT="${NW_API_ENDPOINT:-$(_readaccountconf_mutable NW_API_ENDPOINT)}" |
||||
|
|
||||
|
if [ -z "${NW_API_ENDPOINT}" ]; then |
||||
|
NW_API_ENDPOINT="https://portal.nexcess.net" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "${NW_API_TOKEN}" ]; then |
||||
|
_err "You have not defined your NW_API_TOKEN." |
||||
|
_err "Please create your token and try again." |
||||
|
_err "If you need to generate a new token, please visit one of the following URLs:" |
||||
|
_err " - https://portal.nexcess.net/api-token" |
||||
|
_err " - https://core.thermo.io/api-token" |
||||
|
_err " - https://my.futurehosting.com/api-token" |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable NW_API_TOKEN "${NW_API_TOKEN}" |
||||
|
_saveaccountconf_mutable NW_API_ENDPOINT "${NW_API_ENDPOINT}" |
||||
|
} |
||||
|
|
||||
|
_get_root() { |
||||
|
domain="${1}" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
if _rest GET "dns-zone"; then |
||||
|
response="$(echo "${response}" | tr -d "\n" | sed 's/^\[\(.*\)\]$/\1/' | sed -e 's/{"zone_id":/|"zone_id":/g' | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
|
||||
|
_debug response "${response}" |
||||
|
while true; do |
||||
|
h=$(printf "%s" "${domain}" | cut -d . -f $i-100) |
||||
|
_debug h "${h}" |
||||
|
if [ -z "${h}" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hostedzone="$(echo "${response}" | _egrep_o "{.*\"domain\": *\"${h}\".*}")" |
||||
|
if [ "${hostedzone}" ]; then |
||||
|
_zone_id=$(printf "%s\n" "${hostedzone}" | _egrep_o "\"zone_id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "${_zone_id}" ]; then |
||||
|
_sub_domain=$(printf "%s" "${domain}" | cut -d . -f 1-${p}) |
||||
|
_domain="${h}" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "${i}" + 1) |
||||
|
done |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_rest() { |
||||
|
method="${1}" |
||||
|
ep="/${2}" |
||||
|
data="${3}" |
||||
|
|
||||
|
_debug method "${method}" |
||||
|
_debug ep "${ep}" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Api-Version: ${NW_API_VERSION}" |
||||
|
export _H4="User-Agent: NW-ACME-CLIENT" |
||||
|
export _H5="Authorization: Bearer ${NW_API_TOKEN}" |
||||
|
|
||||
|
if [ "${method}" != "GET" ]; then |
||||
|
_debug data "${data}" |
||||
|
response="$(_post "${data}" "${NW_API_ENDPOINT}${ep}" "" "${method}")" |
||||
|
else |
||||
|
response="$(_get "${NW_API_ENDPOINT}${ep}${data}")" |
||||
|
fi |
||||
|
|
||||
|
if [ "${?}" != "0" ]; then |
||||
|
_err "error ${ep}" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "${response}" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,217 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Online API |
||||
|
# https://console.online.net/en/api/ |
||||
|
# |
||||
|
# Requires Online API key set in ONLINE_API_KEY |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
ONLINE_API="https://api.online.net/api/v1" |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_online_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _online_check_config; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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 _real_dns_version "$_real_dns_version" |
||||
|
|
||||
|
_info "Creating temporary zone version" |
||||
|
_online_create_temporary_zone_version |
||||
|
_info "Enabling temporary zone version" |
||||
|
_online_enable_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
_online_create_TXT_record "$_real_dns_version" "$_sub_domain" "$txtvalue" |
||||
|
_info "Disabling temporary version" |
||||
|
_online_enable_zone "$_real_dns_version" |
||||
|
_info "Destroying temporary version" |
||||
|
_online_destroy_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Record added." |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#fulldomain |
||||
|
dns_online_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _online_check_config; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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 _real_dns_version "$_real_dns_version" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
if ! _online_rest GET "domain/$_domain/version/active"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
rid=$(echo "$response" | _egrep_o "\"id\":[0-9]+,\"name\":\"$_sub_domain\",\"data\":\"\\\u0022$txtvalue\\\u0022\"" | cut -d ':' -f 2 | cut -d ',' -f 1) |
||||
|
_debug rid "$rid" |
||||
|
if [ -z "$rid" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Creating temporary zone version" |
||||
|
_online_create_temporary_zone_version |
||||
|
_info "Enabling temporary zone version" |
||||
|
_online_enable_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Removing DNS record" |
||||
|
_online_rest DELETE "domain/$_domain/version/$_real_dns_version/zone/$rid" |
||||
|
_info "Disabling temporary version" |
||||
|
_online_enable_zone "$_real_dns_version" |
||||
|
_info "Destroying temporary version" |
||||
|
_online_destroy_zone "$_temporary_dns_version" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_online_check_config() { |
||||
|
ONLINE_API_KEY="${ONLINE_API_KEY:-$(_readaccountconf_mutable ONLINE_API_KEY)}" |
||||
|
if [ -z "$ONLINE_API_KEY" ]; then |
||||
|
_err "No API key specified for Online API." |
||||
|
_err "Create your key and export it as ONLINE_API_KEY" |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _online_rest GET "domain/"; then |
||||
|
_err "Invalid API key specified for Online API." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable ONLINE_API_KEY "$ONLINE_API_KEY" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_online_rest GET "domain/$h/version/active" |
||||
|
|
||||
|
if ! _contains "$response" "Domain not found" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
_real_dns_version=$(echo "$response" | _egrep_o '"uuid_ref":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
_err "Unable to retrive DNS zone matching this domain" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# this function create a temporary zone version |
||||
|
# as online.net does not allow updating an active version |
||||
|
_online_create_temporary_zone_version() { |
||||
|
|
||||
|
_online_rest POST "domain/$_domain/version" "name=acme.sh" |
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_temporary_dns_version=$(echo "$response" | _egrep_o '"uuid_ref":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
|
||||
|
# Creating a dummy record in this temporary version, because online.net doesn't accept enabling an empty version |
||||
|
_online_create_TXT_record "$_temporary_dns_version" "dummy.acme.sh" "dummy" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_destroy_zone() { |
||||
|
version_id=$1 |
||||
|
_online_rest DELETE "domain/$_domain/version/$version_id" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_enable_zone() { |
||||
|
version_id=$1 |
||||
|
_online_rest PATCH "domain/$_domain/version/$version_id/enable" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_create_TXT_record() { |
||||
|
version=$1 |
||||
|
txt_name=$2 |
||||
|
txt_value=$3 |
||||
|
|
||||
|
_online_rest POST "domain/$_domain/version/$version/zone" "type=TXT&name=$txt_name&data=%22$txt_value%22&ttl=60&priority=0" |
||||
|
|
||||
|
# Note : the normal, expected response SHOULD be "Unknown method". |
||||
|
# this happens because the API HTTP response contains a Location: header, that redirect |
||||
|
# to an unknown online.net endpoint. |
||||
|
if [ "$?" != "0" ] || _contains "$response" "Unknown method" || _contains "$response" "\$ref"; then |
||||
|
return 0 |
||||
|
else |
||||
|
_err "error $response" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_online_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
_online_url="$ONLINE_API/$ep" |
||||
|
_debug2 _online_url "$_online_url" |
||||
|
export _H1="Authorization: Bearer $ONLINE_API_KEY" |
||||
|
export _H2="X-Pretty-JSON: 1" |
||||
|
if [ "$data" ] || [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$_online_url" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$_online_url")" |
||||
|
fi |
||||
|
if [ "$?" != "0" ] || _contains "$response" "invalid_grant" || _contains "$response" "Method not allowed"; then |
||||
|
_err "error $response" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,244 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# This is the OpenProvider API wrapper for acme.sh |
||||
|
# |
||||
|
# Author: Sylvia van Os |
||||
|
# Report Bugs here: https://github.com/Neilpang/acme.sh/issues/2104 |
||||
|
# |
||||
|
# export OPENPROVIDER_USER="username" |
||||
|
# export OPENPROVIDER_PASSWORDHASH="hashed_password" |
||||
|
# |
||||
|
# Usage: |
||||
|
# acme.sh --issue --dns dns_openprovider -d example.com |
||||
|
|
||||
|
OPENPROVIDER_API="https://api.openprovider.eu/" |
||||
|
#OPENPROVIDER_API="https://api.cte.openprovider.eu/" # Test API |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_openprovider_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_openprovider_add() { |
||||
|
fulldomain="$1" |
||||
|
txtvalue="$2" |
||||
|
|
||||
|
OPENPROVIDER_USER="${OPENPROVIDER_USER:-$(_readaccountconf_mutable OPENPROVIDER_USER)}" |
||||
|
OPENPROVIDER_PASSWORDHASH="${OPENPROVIDER_PASSWORDHASH:-$(_readaccountconf_mutable OPENPROVIDER_PASSWORDHASH)}" |
||||
|
|
||||
|
if [ -z "$OPENPROVIDER_USER" ] || [ -z "$OPENPROVIDER_PASSWORDHASH" ]; then |
||||
|
_err "You didn't specify the openprovider user and/or password hash." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# save the username and password to the account conf file. |
||||
|
_saveaccountconf_mutable OPENPROVIDER_USER "$OPENPROVIDER_USER" |
||||
|
_saveaccountconf_mutable OPENPROVIDER_PASSWORDHASH "$OPENPROVIDER_PASSWORDHASH" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _domain_name "$_domain_name" |
||||
|
_debug _domain_extension "$_domain_extension" |
||||
|
|
||||
|
_debug "Getting current records" |
||||
|
existing_items="" |
||||
|
results_retrieved=0 |
||||
|
while true; do |
||||
|
_openprovider_request "$(printf '<searchZoneRecordDnsRequest><name>%s.%s</name><offset>%s</offset></searchZoneRecordDnsRequest>' "$_domain_name" "$_domain_extension" "$results_retrieved")" |
||||
|
|
||||
|
items="$response" |
||||
|
while true; do |
||||
|
item="$(echo "$items" | _egrep_o '<openXML>.*<\/openXML>' | sed -n 's/.*\(<item>.*<\/item>\).*/\1/p')" |
||||
|
_debug existing_items "$existing_items" |
||||
|
_debug results_retrieved "$results_retrieved" |
||||
|
_debug item "$item" |
||||
|
|
||||
|
if [ -z "$item" ]; then |
||||
|
break |
||||
|
fi |
||||
|
|
||||
|
items="$(echo "$items" | sed "s|${item}||")" |
||||
|
|
||||
|
results_retrieved="$(_math "$results_retrieved" + 1)" |
||||
|
new_item="$(echo "$item" | sed -n 's/.*<item>.*\(<name>\(.*\)\.'"$_domain_name"'\.'"$_domain_extension"'<\/name>.*\(<type>.*<\/type>\).*\(<value>.*<\/value>\).*\(<prio>.*<\/prio>\).*\(<ttl>.*<\/ttl>\)\).*<\/item>.*/<item><name>\2<\/name>\3\4\5\6<\/item>/p')" |
||||
|
if [ -z "$new_item" ]; then |
||||
|
# Base record |
||||
|
new_item="$(echo "$item" | sed -n 's/.*<item>.*\(<name>\(.*\)'"$_domain_name"'\.'"$_domain_extension"'<\/name>.*\(<type>.*<\/type>\).*\(<value>.*<\/value>\).*\(<prio>.*<\/prio>\).*\(<ttl>.*<\/ttl>\)\).*<\/item>.*/<item><name>\2<\/name>\3\4\5\6<\/item>/p')" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$(echo "$new_item" | _egrep_o ".*<type>(A|AAAA|CNAME|MX|SPF|SRV|TXT|TLSA|SSHFP|CAA)<\/type>.*")" ]; then |
||||
|
_debug "not an allowed record type, skipping" "$new_item" |
||||
|
continue |
||||
|
fi |
||||
|
|
||||
|
existing_items="$existing_items$new_item" |
||||
|
done |
||||
|
|
||||
|
total="$(echo "$response" | _egrep_o '<total>.*?<\/total>' | sed -n 's/.*<total>\(.*\)<\/total>.*/\1/p')" |
||||
|
|
||||
|
_debug total "$total" |
||||
|
if [ "$results_retrieved" -eq "$total" ]; then |
||||
|
break |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
_debug "Creating acme record" |
||||
|
acme_record="$(echo "$fulldomain" | sed -e "s/.$_domain_name.$_domain_extension$//")" |
||||
|
_openprovider_request "$(printf '<modifyZoneDnsRequest><domain><name>%s</name><extension>%s</extension></domain><type>master</type><records><array>%s<item><name>%s</name><type>TXT</type><value>%s</value><ttl>86400</ttl></item></array></records></modifyZoneDnsRequest>' "$_domain_name" "$_domain_extension" "$existing_items" "$acme_record" "$txtvalue")" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_openprovider_rm() { |
||||
|
fulldomain="$1" |
||||
|
txtvalue="$2" |
||||
|
|
||||
|
OPENPROVIDER_USER="${OPENPROVIDER_USER:-$(_readaccountconf_mutable OPENPROVIDER_USER)}" |
||||
|
OPENPROVIDER_PASSWORDHASH="${OPENPROVIDER_PASSWORDHASH:-$(_readaccountconf_mutable OPENPROVIDER_PASSWORDHASH)}" |
||||
|
|
||||
|
if [ -z "$OPENPROVIDER_USER" ] || [ -z "$OPENPROVIDER_PASSWORDHASH" ]; then |
||||
|
_err "You didn't specify the openprovider user and/or password hash." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# save the username and password to the account conf file. |
||||
|
_saveaccountconf_mutable OPENPROVIDER_USER "$OPENPROVIDER_USER" |
||||
|
_saveaccountconf_mutable OPENPROVIDER_PASSWORDHASH "$OPENPROVIDER_PASSWORDHASH" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _domain_name "$_domain_name" |
||||
|
_debug _domain_extension "$_domain_extension" |
||||
|
|
||||
|
_debug "Getting current records" |
||||
|
existing_items="" |
||||
|
results_retrieved=0 |
||||
|
while true; do |
||||
|
_openprovider_request "$(printf '<searchZoneRecordDnsRequest><name>%s.%s</name><offset>%s</offset></searchZoneRecordDnsRequest>' "$_domain_name" "$_domain_extension" "$results_retrieved")" |
||||
|
|
||||
|
# Remove acme records from items |
||||
|
items="$response" |
||||
|
while true; do |
||||
|
item="$(echo "$items" | _egrep_o '<openXML>.*<\/openXML>' | sed -n 's/.*\(<item>.*<\/item>\).*/\1/p')" |
||||
|
_debug existing_items "$existing_items" |
||||
|
_debug results_retrieved "$results_retrieved" |
||||
|
_debug item "$item" |
||||
|
|
||||
|
if [ -z "$item" ]; then |
||||
|
break |
||||
|
fi |
||||
|
|
||||
|
items="$(echo "$items" | sed "s|${item}||")" |
||||
|
|
||||
|
results_retrieved="$(_math "$results_retrieved" + 1)" |
||||
|
if ! echo "$item" | grep -v "$fulldomain"; then |
||||
|
_debug "acme record, skipping" "$item" |
||||
|
continue |
||||
|
fi |
||||
|
|
||||
|
new_item="$(echo "$item" | sed -n 's/.*<item>.*\(<name>\(.*\)\.'"$_domain_name"'\.'"$_domain_extension"'<\/name>.*\(<type>.*<\/type>\).*\(<value>.*<\/value>\).*\(<prio>.*<\/prio>\).*\(<ttl>.*<\/ttl>\)\).*<\/item>.*/<item><name>\2<\/name>\3\4\5\6<\/item>/p')" |
||||
|
|
||||
|
if [ -z "$new_item" ]; then |
||||
|
# Base record |
||||
|
new_item="$(echo "$item" | sed -n 's/.*<item>.*\(<name>\(.*\)'"$_domain_name"'\.'"$_domain_extension"'<\/name>.*\(<type>.*<\/type>\).*\(<value>.*<\/value>\).*\(<prio>.*<\/prio>\).*\(<ttl>.*<\/ttl>\)\).*<\/item>.*/<item><name>\2<\/name>\3\4\5\6<\/item>/p')" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$(echo "$new_item" | _egrep_o ".*<type>(A|AAAA|CNAME|MX|SPF|SRV|TXT|TLSA|SSHFP|CAA)<\/type>.*")" ]; then |
||||
|
_debug "not an allowed record type, skipping" "$new_item" |
||||
|
continue |
||||
|
fi |
||||
|
|
||||
|
existing_items="$existing_items$new_item" |
||||
|
done |
||||
|
|
||||
|
total="$(echo "$response" | _egrep_o '<total>.*?<\/total>' | sed -n 's/.*<total>\(.*\)<\/total>.*/\1/p')" |
||||
|
|
||||
|
_debug total "$total" |
||||
|
|
||||
|
if [ "$results_retrieved" -eq "$total" ]; then |
||||
|
break |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
_debug "Removing acme record" |
||||
|
_openprovider_request "$(printf '<modifyZoneDnsRequest><domain><name>%s</name><extension>%s</extension></domain><type>master</type><records><array>%s</array></records></modifyZoneDnsRequest>' "$_domain_name" "$_domain_extension" "$existing_items")" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _domain_name=domain |
||||
|
# _domain_extension=com |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
|
||||
|
results_retrieved=0 |
||||
|
while true; do |
||||
|
h=$(echo "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_openprovider_request "$(printf '<searchDomainRequest><domainNamePattern>%s</domainNamePattern><offset>%s</offset></searchDomainRequest>' "$(echo "$h" | cut -d . -f 1)" "$results_retrieved")" |
||||
|
|
||||
|
items="$response" |
||||
|
while true; do |
||||
|
item="$(echo "$items" | _egrep_o '<openXML>.*<\/openXML>' | sed -n 's/.*\(<domain>.*<\/domain>\).*/\1/p')" |
||||
|
_debug existing_items "$existing_items" |
||||
|
_debug results_retrieved "$results_retrieved" |
||||
|
_debug item "$item" |
||||
|
|
||||
|
if [ -z "$item" ]; then |
||||
|
break |
||||
|
fi |
||||
|
|
||||
|
items="$(echo "$items" | sed "s|${item}||")" |
||||
|
|
||||
|
results_retrieved="$(_math "$results_retrieved" + 1)" |
||||
|
|
||||
|
_domain_name="$(echo "$item" | sed -n 's/.*<domain>.*<name>\(.*\)<\/name>.*<\/domain>.*/\1/p')" |
||||
|
_domain_extension="$(echo "$item" | sed -n 's/.*<domain>.*<extension>\(.*\)<\/extension>.*<\/domain>.*/\1/p')" |
||||
|
_debug _domain_name "$_domain_name" |
||||
|
_debug _domain_extension "$_domain_extension" |
||||
|
if [ "$_domain_name.$_domain_extension" = "$h" ]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
total="$(echo "$response" | _egrep_o '<total>.*?<\/total>' | sed -n 's/.*<total>\(.*\)<\/total>.*/\1/p')" |
||||
|
|
||||
|
_debug total "$total" |
||||
|
|
||||
|
if [ "$results_retrieved" -eq "$total" ]; then |
||||
|
results_retrieved=0 |
||||
|
i="$(_math "$i" + 1)" |
||||
|
fi |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_openprovider_request() { |
||||
|
request_xml=$1 |
||||
|
|
||||
|
xml_prefix='<?xml version="1.0" encoding="UTF-8"?>' |
||||
|
xml_content=$(printf '<openXML><credentials><username>%s</username><hash>%s</hash></credentials>%s</openXML>' "$OPENPROVIDER_USER" "$OPENPROVIDER_PASSWORDHASH" "$request_xml") |
||||
|
response="$(_post "$(echo "$xml_prefix$xml_content" | tr -d '\n')" "$OPENPROVIDER_API" "" "POST" "application/xml")" |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "<openXML><reply><code>0</code>.*</reply></openXML>"; then |
||||
|
_err "API request failed." |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
@ -0,0 +1,164 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# |
||||
|
#PointHQ_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
||||
|
# |
||||
|
#PointHQ_Email="xxxx@sss.com" |
||||
|
|
||||
|
PointHQ_Api="https://api.pointhq.com" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_pointhq_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
PointHQ_Key="${PointHQ_Key:-$(_readaccountconf_mutable PointHQ_Key)}" |
||||
|
PointHQ_Email="${PointHQ_Email:-$(_readaccountconf_mutable PointHQ_Email)}" |
||||
|
if [ -z "$PointHQ_Key" ] || [ -z "$PointHQ_Email" ]; then |
||||
|
PointHQ_Key="" |
||||
|
PointHQ_Email="" |
||||
|
_err "You didn't specify a PointHQ API key and email yet." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _contains "$PointHQ_Email" "@"; then |
||||
|
_err "It seems that the PointHQ_Email=$PointHQ_Email is not a valid email address." |
||||
|
_err "Please check and retry." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable PointHQ_Key "$PointHQ_Key" |
||||
|
_saveaccountconf_mutable PointHQ_Email "$PointHQ_Email" |
||||
|
|
||||
|
_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 _pointhq_rest POST "zones/$_domain/records" "{\"zone_record\": {\"name\":\"$_sub_domain\",\"record_type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":3600}}"; then |
||||
|
if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_pointhq_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
PointHQ_Key="${PointHQ_Key:-$(_readaccountconf_mutable PointHQ_Key)}" |
||||
|
PointHQ_Email="${PointHQ_Email:-$(_readaccountconf_mutable PointHQ_Email)}" |
||||
|
if [ -z "$PointHQ_Key" ] || [ -z "$PointHQ_Email" ]; then |
||||
|
PointHQ_Key="" |
||||
|
PointHQ_Email="" |
||||
|
_err "You didn't specify a PointHQ API key and email yet." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_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" |
||||
|
_pointhq_rest GET "zones/${_domain}/records?record_type=TXT&name=$_sub_domain" |
||||
|
|
||||
|
if ! printf "%s" "$response" | grep "^\[" >/dev/null; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ "$response" = "[]" ]; then |
||||
|
_info "No records to remove." |
||||
|
else |
||||
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":[^,]*" | cut -d : -f 2 | tr -d \" | head -n 1) |
||||
|
_debug "record_id" "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _pointhq_rest DELETE "zones/$_domain/records/$record_id"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
_contains "$response" '"status":"OK"' |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
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 |
||||
|
|
||||
|
if ! _pointhq_rest GET "zones"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$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 |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_pointhq_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
_pointhq_auth=$(printf "%s:%s" "$PointHQ_Email" "$PointHQ_Key" | _base64) |
||||
|
|
||||
|
export _H1="Authorization: Basic $_pointhq_auth" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Accept: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$PointHQ_Api/$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$PointHQ_Api/$ep")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -0,0 +1,207 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
# |
||||
|
#RACKSPACE_Username="" |
||||
|
# |
||||
|
#RACKSPACE_Apikey="" |
||||
|
|
||||
|
RACKSPACE_Endpoint="https://dns.api.rackspacecloud.com/v1.0" |
||||
|
|
||||
|
# 20190213 - The name & id fields swapped in the API response; fix sed |
||||
|
# 20190101 - Duplicating file for new pull request to dev branch |
||||
|
# Original - tcocca:rackspace_dnsapi https://github.com/Neilpang/acme.sh/pull/1297 |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_rackspace_add() { |
||||
|
fulldomain="$1" |
||||
|
_debug fulldomain="$fulldomain" |
||||
|
txtvalue="$2" |
||||
|
_debug txtvalue="$txtvalue" |
||||
|
_rackspace_check_auth || return 1 |
||||
|
_rackspace_check_rootzone || return 1 |
||||
|
_info "Creating TXT record." |
||||
|
if ! _rackspace_rest POST "$RACKSPACE_Tenant/domains/$_domain_id/records" "{\"records\":[{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":300}]}"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
if ! _contains "$response" "$txtvalue" >/dev/null; then |
||||
|
_err "Could not add TXT record." |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_rackspace_rm() { |
||||
|
fulldomain=$1 |
||||
|
_debug fulldomain="$fulldomain" |
||||
|
txtvalue=$2 |
||||
|
_debug txtvalue="$txtvalue" |
||||
|
_rackspace_check_auth || return 1 |
||||
|
_rackspace_check_rootzone || return 1 |
||||
|
_info "Checking for TXT record." |
||||
|
if ! _get_recordid "$_domain_id" "$fulldomain" "$txtvalue"; then |
||||
|
_err "Could not get TXT record id." |
||||
|
return 1 |
||||
|
fi |
||||
|
if [ "$_dns_record_id" = "" ]; then |
||||
|
_err "TXT record not found." |
||||
|
return 1 |
||||
|
fi |
||||
|
_info "Removing TXT record." |
||||
|
if ! _delete_txt_record "$_domain_id" "$_dns_record_id"; then |
||||
|
_err "Could not remove TXT record $_dns_record_id." |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root_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 |
||||
|
if ! _rackspace_rest GET "$RACKSPACE_Tenant/domains"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
# Response looks like: |
||||
|
# {"ttl":300,"accountId":12345,"id":1111111,"name":"example.com","emailAddress": ...<and so on> |
||||
|
_domain_id=$(echo "$response" | sed -n "s/^.*\"id\":\([^,]*\),\"name\":\"$h\",.*/\1/p") |
||||
|
_debug2 domain_id "$_domain_id" |
||||
|
if [ -n "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_get_recordid() { |
||||
|
domainid="$1" |
||||
|
fulldomain="$2" |
||||
|
txtvalue="$3" |
||||
|
if ! _rackspace_rest GET "$RACKSPACE_Tenant/domains/$domainid/records?name=$fulldomain&type=TXT"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "$txtvalue"; then |
||||
|
_dns_record_id=0 |
||||
|
return 0 |
||||
|
fi |
||||
|
_dns_record_id=$(echo "$response" | tr '{' "\n" | grep "\"data\":\"$txtvalue\"" | sed -n 's/^.*"id":"\([^"]*\)".*/\1/p') |
||||
|
_debug _dns_record_id "$_dns_record_id" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_delete_txt_record() { |
||||
|
domainid="$1" |
||||
|
_dns_record_id="$2" |
||||
|
if ! _rackspace_rest DELETE "$RACKSPACE_Tenant/domains/$domainid/records?id=$_dns_record_id"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "RUNNING"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug ep "$ep" |
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="X-Auth-Token: $RACKSPACE_Token" |
||||
|
export _H3="X-Project-Id: $RACKSPACE_Tenant" |
||||
|
export _H4="Content-Type: application/json" |
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$RACKSPACE_Endpoint/$ep" "" "$m")" |
||||
|
retcode=$? |
||||
|
else |
||||
|
_info "Getting $RACKSPACE_Endpoint/$ep" |
||||
|
response="$(_get "$RACKSPACE_Endpoint/$ep")" |
||||
|
retcode=$? |
||||
|
fi |
||||
|
|
||||
|
if [ "$retcode" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_authorization() { |
||||
|
export _H1="Content-Type: application/json" |
||||
|
data="{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\":{\"username\":\"$RACKSPACE_Username\",\"apiKey\":\"$RACKSPACE_Apikey\"}}}" |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "https://identity.api.rackspacecloud.com/v2.0/tokens" "" "POST")" |
||||
|
retcode=$? |
||||
|
_debug2 response "$response" |
||||
|
if [ "$retcode" != "0" ]; then |
||||
|
_err "Authentication failed." |
||||
|
return 1 |
||||
|
fi |
||||
|
if _contains "$response" "token"; then |
||||
|
RACKSPACE_Token="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token":{.*,"id":"\([^"]*\)",".*/\1/p')" |
||||
|
RACKSPACE_Tenant="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token":{.*,"id":"\([^"]*\)"}.*/\1/p')" |
||||
|
_debug RACKSPACE_Token "$RACKSPACE_Token" |
||||
|
_debug RACKSPACE_Tenant "$RACKSPACE_Tenant" |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_check_auth() { |
||||
|
# retrieve the rackspace creds |
||||
|
RACKSPACE_Username="${RACKSPACE_Username:-$(_readaccountconf_mutable RACKSPACE_Username)}" |
||||
|
RACKSPACE_Apikey="${RACKSPACE_Apikey:-$(_readaccountconf_mutable RACKSPACE_Apikey)}" |
||||
|
# check their vals for null |
||||
|
if [ -z "$RACKSPACE_Username" ] || [ -z "$RACKSPACE_Apikey" ]; then |
||||
|
RACKSPACE_Username="" |
||||
|
RACKSPACE_Apikey="" |
||||
|
_err "You didn't specify a Rackspace username and api key." |
||||
|
_err "Please set those values and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
# save the username and api key to the account conf file. |
||||
|
_saveaccountconf_mutable RACKSPACE_Username "$RACKSPACE_Username" |
||||
|
_saveaccountconf_mutable RACKSPACE_Apikey "$RACKSPACE_Apikey" |
||||
|
if [ -z "$RACKSPACE_Token" ]; then |
||||
|
_info "Getting authorization token." |
||||
|
if ! _rackspace_authorization; then |
||||
|
_err "Can not get token." |
||||
|
fi |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_rackspace_check_rootzone() { |
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root_zone "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
} |
||||
@ -0,0 +1,164 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# |
||||
|
# ULTRA_USR="your_user_goes_here" |
||||
|
# |
||||
|
# ULTRA_PWD="some_password_goes_here" |
||||
|
|
||||
|
ULTRA_API="https://restapi.ultradns.com/v2/" |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt" |
||||
|
dns_ultra_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
export txtvalue |
||||
|
ULTRA_USR="${ULTRA_USR:-$(_readaccountconf_mutable ULTRA_USR)}" |
||||
|
ULTRA_PWD="${ULTRA_PWD:-$(_readaccountconf_mutable ULTRA_PWD)}" |
||||
|
if [ -z "$ULTRA_USR" ] || [ -z "$ULTRA_PWD" ]; then |
||||
|
ULTRA_USR="" |
||||
|
ULTRA_PWD="" |
||||
|
_err "You didn't specify an UltraDNS username and password yet" |
||||
|
return 1 |
||||
|
fi |
||||
|
# save the username and password to the account conf file. |
||||
|
_saveaccountconf_mutable ULTRA_USR "$ULTRA_USR" |
||||
|
_saveaccountconf_mutable ULTRA_PWD "$ULTRA_PWD" |
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "${_domain_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
_debug "Getting txt records" |
||||
|
_ultra_rest GET "zones/${_domain_id}/rrsets/TXT?q=value:${fulldomain}" |
||||
|
if printf "%s" "$response" | grep \"totalCount\" >/dev/null; then |
||||
|
_err "Error, it would appear that this record already exists. Please review existing TXT records for this domain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Adding record" |
||||
|
if _ultra_rest POST "zones/$_domain_id/rrsets/TXT/${_sub_domain}" '{"ttl":300,"rdata":["'"${txtvalue}"'"]}'; then |
||||
|
if _contains "$response" "Successful"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
elif _contains "$response" "Resource Record of type 16 with these attributes already exists"; then |
||||
|
_info "Already exists, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
|
||||
|
} |
||||
|
|
||||
|
dns_ultra_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
export txtvalue |
||||
|
ULTRA_USR="${ULTRA_USR:-$(_readaccountconf_mutable ULTRA_USR)}" |
||||
|
ULTRA_PWD="${ULTRA_PWD:-$(_readaccountconf_mutable ULTRA_PWD)}" |
||||
|
if [ -z "$ULTRA_USR" ] || [ -z "$ULTRA_PWD" ]; then |
||||
|
ULTRA_USR="" |
||||
|
ULTRA_PWD="" |
||||
|
_err "You didn't specify an UltraDNS username and password yet" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "${_domain_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${domain}" |
||||
|
|
||||
|
_debug "Getting TXT records" |
||||
|
_ultra_rest GET "zones/${_domain_id}/rrsets?q=kind:RECORDS+owner:${_sub_domain}" |
||||
|
|
||||
|
if ! printf "%s" "$response" | grep \"resultInfo\" >/dev/null; then |
||||
|
_err "There was an error in obtaining the resource records for ${_domain_id}" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
count=$(echo "$response" | _egrep_o "\"returnedCount\":[^,]*" | cut -d: -f2 | cut -d'}' -f1) |
||||
|
_debug count "${count}" |
||||
|
if [ "${count}" = "" ]; then |
||||
|
_info "Text record is not present, will not delete anything." |
||||
|
else |
||||
|
if ! _ultra_rest DELETE "zones/$_domain_id/rrsets/TXT/${_sub_domain}" '{"ttl":300,"rdata":["'"${txtvalue}"'"]}'; then |
||||
|
_err "Deleting the record did not succeed, please verify/check." |
||||
|
return 1 |
||||
|
fi |
||||
|
_contains "$response" "" |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
_debug response "$response" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _ultra_rest GET "zones"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
if _contains "${response}" "${h}." >/dev/null; then |
||||
|
_domain_id=$(echo "$response" | _egrep_o "${h}") |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="${h}" |
||||
|
_debug sub_domain "${_sub_domain}" |
||||
|
_debug domain "${_domain}" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_ultra_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
_debug TOKEN "${AUTH_TOKEN}" |
||||
|
|
||||
|
_ultra_login |
||||
|
export _H1="Content-Type: application/json" |
||||
|
export _H2="Authorization: Bearer ${AUTH_TOKEN}" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "${data}" |
||||
|
response="$(_post "${data}" "${ULTRA_API}"/"${ep}" "" "${m}")" |
||||
|
else |
||||
|
response="$(_get "$ULTRA_API/$ep")" |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_ultra_login() { |
||||
|
export _H1="" |
||||
|
export _H2="" |
||||
|
AUTH_TOKEN=$(_post "grant_type=password&username=${ULTRA_USR}&password=${ULTRA_PWD}" "${ULTRA_API}authorization/token" | cut -d, -f3 | cut -d\" -f4) |
||||
|
export AUTH_TOKEN |
||||
|
} |
||||
@ -0,0 +1,149 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Zone.ee dns API |
||||
|
# https://help.zone.eu/kb/zoneid-api-v2/ |
||||
|
# required ZONE_Username and ZONE_Key |
||||
|
|
||||
|
ZONE_Api="https://api.zone.eu/v2" |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_zone_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_zone_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using zone.ee dns api" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
ZONE_Username="${ZONE_Username:-$(_readaccountconf_mutable ZONE_Username)}" |
||||
|
ZONE_Key="${ZONE_Key:-$(_readaccountconf_mutable ZONE_Key)}" |
||||
|
if [ -z "$ZONE_Username" ] || [ -z "$ZONE_Key" ]; then |
||||
|
ZONE_Username="" |
||||
|
ZONE_Key="" |
||||
|
_err "Zone api key and username must be present." |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable ZONE_Username "$ZONE_Username" |
||||
|
_saveaccountconf_mutable ZONE_Key "$ZONE_Key" |
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "Adding txt record" |
||||
|
|
||||
|
if _zone_rest POST "dns/${_domain}/txt" "{\"name\": \"$fulldomain\", \"destination\": \"$txtvalue\"}"; then |
||||
|
if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Adding txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
_err "Adding txt record error." |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_zone_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using zone.ee dns api" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
ZONE_Username="${ZONE_Username:-$(_readaccountconf_mutable ZONE_Username)}" |
||||
|
ZONE_Key="${ZONE_Key:-$(_readaccountconf_mutable ZONE_Key)}" |
||||
|
if [ -z "$ZONE_Username" ] || [ -z "$ZONE_Key" ]; then |
||||
|
ZONE_Username="" |
||||
|
ZONE_Key="" |
||||
|
_err "Zone api key and username must be present." |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable ZONE_Username "$ZONE_Username" |
||||
|
_saveaccountconf_mutable ZONE_Key "$ZONE_Key" |
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_zone_rest GET "dns/${_domain}/txt" |
||||
|
|
||||
|
if printf "%s" "$response" | grep \"error\" >/dev/null; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
count=$(printf "%s\n" "$response" | _egrep_o "\"name\":\"$fulldomain\"" | wc -l) |
||||
|
_debug count "$count" |
||||
|
if [ "$count" = "0" ]; then |
||||
|
_info "Nothing to remove." |
||||
|
else |
||||
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\",\"resource_url\":\"[^\"]*\",\"name\":\"$fulldomain\"," | cut -d : -f2 | cut -d , -f1 | tr -d \" | _head_n 1) |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "No id found to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _zone_rest DELETE "dns/${_domain}/txt/$record_id"; then |
||||
|
_err "Record deleting error." |
||||
|
return 1 |
||||
|
fi |
||||
|
_info "Record deleted" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_zone_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
realm="$(printf "%s" "$ZONE_Username:$ZONE_Key" | _base64)" |
||||
|
|
||||
|
export _H1="Authorization: Basic $realm" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$ZONE_Api/$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$ZONE_Api/$ep")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_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 |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _zone_rest GET "dns/$h/a"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 0 |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue