mirror of
https://github.com/plantroon/acme.sh.git
synced 2024-12-22 13:11:41 +00:00
merge with upstream
This commit is contained in:
commit
ce38ecb966
25
.github/ISSUE_TEMPLATE.md
vendored
Normal file
25
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<!--
|
||||||
|
|
||||||
|
If it is a bug report:
|
||||||
|
- make sure you are able to repro it on the latest released version.
|
||||||
|
You can install the latest version by: `acme.sh --upgrade`
|
||||||
|
|
||||||
|
- Search the existing issues.
|
||||||
|
- Refer to the [WIKI](https://wiki.acme.sh).
|
||||||
|
- Debug info [Debug](https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh).
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
Steps to reproduce
|
||||||
|
------------------
|
||||||
|
|
||||||
|
|
||||||
|
Debug log
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
```
|
||||||
|
acme.sh --issue ..... --debug 2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
24
.travis.yml
Normal file
24
.travis.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
language: shell
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- SHFMT_URL=https://github.com/mvdan/sh/releases/download/v0.4.0/shfmt_v0.4.0_linux_amd64
|
||||||
|
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- debian-sid # Grab shellcheck from the Debian repo (o_O)
|
||||||
|
packages:
|
||||||
|
- shellcheck
|
||||||
|
|
||||||
|
script:
|
||||||
|
- curl -sSL $SHFMT_URL -o ~/shfmt
|
||||||
|
- chmod +x ~/shfmt
|
||||||
|
- shellcheck -V
|
||||||
|
- shellcheck -e SC2021,SC2126,SC2034 **/*.sh && echo "shellcheck OK"
|
||||||
|
- ~/shfmt -l -w -i 2 . && echo "shfmt OK" || git diff --exit-code || (echo "Run shfmt to fix the formatting issues" && false)
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
fast_finish: true
|
||||||
|
|
||||||
|
|
28
README.md
28
README.md
@ -1,4 +1,4 @@
|
|||||||
# An ACME Shell script: acme.sh
|
# An ACME Shell script: acme.sh [![Build Status](https://travis-ci.org/Neilpang/acme.sh.svg?branch=master)](https://travis-ci.org/Neilpang/acme.sh)
|
||||||
- An ACME protocol client written purely in Shell (Unix shell) language.
|
- An ACME protocol client written purely in Shell (Unix shell) language.
|
||||||
- Fully ACME protocol implementation.
|
- Fully ACME protocol implementation.
|
||||||
- Simple, powerful and very easy to use. You only need 3 minutes to learn.
|
- Simple, powerful and very easy to use. You only need 3 minutes to learn.
|
||||||
@ -36,6 +36,7 @@ Wiki: https://github.com/Neilpang/acme.sh/wiki
|
|||||||
|16|[![](https://cdn.rawgit.com/Neilpang/acmetest/master/status/mageia.svg)](https://github.com/Neilpang/letest#here-are-the-latest-status)|Mageia
|
|16|[![](https://cdn.rawgit.com/Neilpang/acmetest/master/status/mageia.svg)](https://github.com/Neilpang/letest#here-are-the-latest-status)|Mageia
|
||||||
|17|-----| OpenWRT: Tested and working. See [wiki page](https://github.com/Neilpang/acme.sh/wiki/How-to-run-on-OpenWRT)
|
|17|-----| OpenWRT: Tested and working. See [wiki page](https://github.com/Neilpang/acme.sh/wiki/How-to-run-on-OpenWRT)
|
||||||
|18|[![](https://cdn.rawgit.com/Neilpang/acmetest/master/status/solaris.svg)](https://github.com/Neilpang/letest#here-are-the-latest-status)|SunOS/Solaris
|
|18|[![](https://cdn.rawgit.com/Neilpang/acmetest/master/status/solaris.svg)](https://github.com/Neilpang/letest#here-are-the-latest-status)|SunOS/Solaris
|
||||||
|
|19|[![](https://cdn.rawgit.com/Neilpang/acmetest/master/status/gentoo-stage3-amd64.svg)](https://github.com/Neilpang/letest#here-are-the-latest-status)|Gentoo Linux
|
||||||
|
|
||||||
For all build statuses, check our [daily build project](https://github.com/Neilpang/acmetest):
|
For all build statuses, check our [daily build project](https://github.com/Neilpang/acmetest):
|
||||||
|
|
||||||
@ -137,15 +138,24 @@ More examples: https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert
|
|||||||
|
|
||||||
# 3. Install the issued cert to apache/nginx etc.
|
# 3. Install the issued cert to apache/nginx etc.
|
||||||
|
|
||||||
After you issue a cert, you probably want to install/copy the cert to your nginx/apache or other servers you may be using.
|
After you issue a cert, you probably want to install/copy the cert to your nginx/apache or other servers.
|
||||||
|
You **MUST** use this command to copy the certs to the target files, **Do NOT** use the certs files in **.acme.sh/** folder, they are for internal use only, the folder structure may change in future.
|
||||||
|
|
||||||
|
**nginx** example
|
||||||
```bash
|
```bash
|
||||||
acme.sh --installcert -d example.com \
|
acme.sh --installcert -d example.com \
|
||||||
--certpath /path/to/certfile/in/apache/nginx \
|
--keypath /path/to/keyfile/in/nginx/key.pem \
|
||||||
--keypath /path/to/keyfile/in/apache/nginx \
|
--fullchainpath path/to/fullchain/nginx/cert.pem \
|
||||||
--capath /path/to/ca/certfile/apache/nginx \
|
--reloadcmd "service nginx restart"
|
||||||
--fullchainpath path/to/fullchain/certfile/apache/nginx \
|
```
|
||||||
--reloadcmd "service apache2|nginx reload"
|
|
||||||
|
**apache** example
|
||||||
|
```bash
|
||||||
|
acme.sh --installcert -d example.com \
|
||||||
|
--certpath /path/to/certfile/in/apache/cert.pem \
|
||||||
|
--keypath /path/to/keyfile/in/apache/key.pem \
|
||||||
|
--fullchainpath path/to/fullchain/certfile/apache/fullchain.pem \
|
||||||
|
--reloadcmd "service apache2 restart"
|
||||||
```
|
```
|
||||||
|
|
||||||
Only the domain is required, all the other parameters are optional.
|
Only the domain is required, all the other parameters are optional.
|
||||||
@ -244,7 +254,9 @@ You don't have do anything manually!
|
|||||||
7. PowerDNS API
|
7. PowerDNS API
|
||||||
8. lexicon dns api: https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api
|
8. lexicon dns api: https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api
|
||||||
(DigitalOcean, DNSimple, DnsMadeEasy, DNSPark, EasyDNS, Namesilo, NS1, PointHQ, Rage4 and Vultr etc.)
|
(DigitalOcean, DNSimple, DnsMadeEasy, DNSPark, EasyDNS, Namesilo, NS1, PointHQ, Rage4 and Vultr etc.)
|
||||||
9. nsupdate
|
9. LuaDNS.com API
|
||||||
|
10. DNSMadeEasy.com API
|
||||||
|
11. nsupdate
|
||||||
|
|
||||||
##### More APIs are coming soon...
|
##### More APIs are coming soon...
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
#Which will be called by acme.sh to deploy the cert
|
#Which will be called by acme.sh to deploy the cert
|
||||||
#returns 0 means success, otherwise error.
|
#returns 0 means success, otherwise error.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
#domain keyfile certfile cafile fullchain
|
#domain keyfile certfile cafile fullchain
|
||||||
@ -17,17 +15,14 @@ myapi_deploy() {
|
|||||||
_ccert="$3"
|
_ccert="$3"
|
||||||
_cca="$4"
|
_cca="$4"
|
||||||
_cfullchain="$5"
|
_cfullchain="$5"
|
||||||
|
|
||||||
_debug _cdomain "$_cdomain"
|
_debug _cdomain "$_cdomain"
|
||||||
_debug _ckey "$_ckey"
|
_debug _ckey "$_ckey"
|
||||||
_debug _ccert "$_ccert"
|
_debug _ccert "$_ccert"
|
||||||
_debug _cca "$_cca"
|
_debug _cca "$_cca"
|
||||||
_debug _cfullchain "$_cfullchain"
|
_debug _cfullchain "$_cfullchain"
|
||||||
|
|
||||||
|
|
||||||
_err "Not implemented yet"
|
_err "Not implemented yet"
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,4 +186,41 @@ For more details, please check our sample script: [dns_myapi.sh](dns_myapi.sh)
|
|||||||
|
|
||||||
https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api
|
https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api
|
||||||
|
|
||||||
|
## 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 --dnssleep 3 -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.
|
||||||
|
|
||||||
|
## 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 --dnssleep 3 -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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,54 +1,54 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#CF_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
#CF_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
||||||
#
|
#
|
||||||
#CF_Email="xxxx@sss.com"
|
#CF_Email="xxxx@sss.com"
|
||||||
|
|
||||||
|
|
||||||
CF_Api="https://api.cloudflare.com/client/v4"
|
CF_Api="https://api.cloudflare.com/client/v4"
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
dns_cf_add(){
|
dns_cf_add() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
if [ -z "$CF_Key" ] || [ -z "$CF_Email" ] ; then
|
if [ -z "$CF_Key" ] || [ -z "$CF_Email" ]; then
|
||||||
|
CF_Key=""
|
||||||
|
CF_Email=""
|
||||||
_err "You don't specify cloudflare api key and email yet."
|
_err "You don't specify cloudflare api key and email yet."
|
||||||
_err "Please create you key and try again."
|
_err "Please create you key and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#save the api key and email to the account conf file.
|
#save the api key and email to the account conf file.
|
||||||
_saveaccountconf CF_Key "$CF_Key"
|
_saveaccountconf CF_Key "$CF_Key"
|
||||||
_saveaccountconf CF_Email "$CF_Email"
|
_saveaccountconf CF_Email "$CF_Email"
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root $fulldomain ; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug _domain_id "$_domain_id"
|
_debug _domain_id "$_domain_id"
|
||||||
_debug _sub_domain "$_sub_domain"
|
_debug _sub_domain "$_sub_domain"
|
||||||
_debug _domain "$_domain"
|
_debug _domain "$_domain"
|
||||||
|
|
||||||
_debug "Getting txt records"
|
_debug "Getting txt records"
|
||||||
_cf_rest GET "zones/${_domain_id}/dns_records?type=TXT&name=$fulldomain"
|
_cf_rest GET "zones/${_domain_id}/dns_records?type=TXT&name=$fulldomain"
|
||||||
|
|
||||||
if ! printf "$response" | grep \"success\":true > /dev/null ; then
|
if ! printf "%s" "$response" | grep \"success\":true >/dev/null; then
|
||||||
_err "Error"
|
_err "Error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
count=$(printf "%s\n" "$response" | _egrep_o \"count\":[^,]* | cut -d : -f 2)
|
count=$(printf "%s\n" "$response" | _egrep_o "\"count\":[^,]*" | cut -d : -f 2)
|
||||||
_debug count "$count"
|
_debug count "$count"
|
||||||
if [ "$count" = "0" ] ; then
|
if [ "$count" = "0" ]; then
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
if _cf_rest POST "zones/$_domain_id/dns_records" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
|
if _cf_rest POST "zones/$_domain_id/dns_records" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
|
||||||
if printf -- "%s" "$response" | grep $fulldomain > /dev/null ; then
|
if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then
|
||||||
_info "Added, sleeping 10 seconds"
|
_info "Added, sleeping 10 seconds"
|
||||||
sleep 10
|
sleep 10
|
||||||
#todo: check if the record takes effect
|
#todo: check if the record takes effect
|
||||||
@ -61,22 +61,21 @@ dns_cf_add(){
|
|||||||
_err "Add txt record error."
|
_err "Add txt record error."
|
||||||
else
|
else
|
||||||
_info "Updating record"
|
_info "Updating record"
|
||||||
record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \"| head -n 1)
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | head -n 1)
|
||||||
_debug "record_id" $record_id
|
_debug "record_id" "$record_id"
|
||||||
|
|
||||||
_cf_rest PUT "zones/$_domain_id/dns_records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}"
|
_cf_rest PUT "zones/$_domain_id/dns_records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}"
|
||||||
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
||||||
_info "Updated, sleeping 10 seconds"
|
_info "Updated, sleeping 10 seconds"
|
||||||
sleep 10
|
sleep 10
|
||||||
#todo: check if the record takes effect
|
#todo: check if the record takes effect
|
||||||
return 0;
|
return 0
|
||||||
fi
|
fi
|
||||||
_err "Update error"
|
_err "Update error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_cf_rm() {
|
dns_cf_rm() {
|
||||||
@ -84,7 +83,6 @@ dns_cf_rm() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#################### Private functions bellow ##################################
|
#################### Private functions bellow ##################################
|
||||||
#_acme-challenge.www.domain.com
|
#_acme-challenge.www.domain.com
|
||||||
#returns
|
#returns
|
||||||
@ -95,28 +93,28 @@ _get_root() {
|
|||||||
domain=$1
|
domain=$1
|
||||||
i=2
|
i=2
|
||||||
p=1
|
p=1
|
||||||
while [ '1' ] ; do
|
while true; do
|
||||||
h=$(printf $domain | cut -d . -f $i-100)
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
if [ -z "$h" ] ; then
|
if [ -z "$h" ]; then
|
||||||
#not valid
|
#not valid
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! _cf_rest GET "zones?name=$h" ; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf $response | grep \"name\":\"$h\" >/dev/null ; then
|
if ! _cf_rest GET "zones?name=$h"; then
|
||||||
_domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | head -n 1 | cut -d : -f 2 | tr -d \")
|
return 1
|
||||||
if [ "$_domain_id" ] ; then
|
fi
|
||||||
_sub_domain=$(printf $domain | cut -d . -f 1-$p)
|
|
||||||
|
if printf "%s" "$response" | grep "\"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
|
_domain=$h
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
p=$i
|
p=$i
|
||||||
i=$(expr $i + 1)
|
i=$(_math "$i" + 1)
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -125,25 +123,23 @@ _cf_rest() {
|
|||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
data="$3"
|
data="$3"
|
||||||
_debug $ep
|
_debug "$ep"
|
||||||
|
|
||||||
_H1="X-Auth-Email: $CF_Email"
|
_H1="X-Auth-Email: $CF_Email"
|
||||||
_H2="X-Auth-Key: $CF_Key"
|
_H2="X-Auth-Key: $CF_Key"
|
||||||
_H3="Content-Type: application/json"
|
_H3="Content-Type: application/json"
|
||||||
|
|
||||||
if [ "$data" ] ; then
|
if [ "$data" ]; then
|
||||||
_debug data "$data"
|
_debug data "$data"
|
||||||
response="$(_post "$data" "$CF_Api/$ep" "" $m)"
|
response="$(_post "$data" "$CF_Api/$ep" "" "$m")"
|
||||||
else
|
else
|
||||||
response="$(_get "$CF_Api/$ep")"
|
response="$(_get "$CF_Api/$ep")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
134
dnsapi/dns_cx.sh
134
dnsapi/dns_cx.sh
@ -6,10 +6,8 @@
|
|||||||
#
|
#
|
||||||
#CX_Secret="sADDsdasdgdsf"
|
#CX_Secret="sADDsdasdgdsf"
|
||||||
|
|
||||||
|
|
||||||
CX_Api="https://www.cloudxns.net/api2"
|
CX_Api="https://www.cloudxns.net/api2"
|
||||||
|
|
||||||
|
|
||||||
#REST_API
|
#REST_API
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
@ -17,54 +15,52 @@ CX_Api="https://www.cloudxns.net/api2"
|
|||||||
dns_cx_add() {
|
dns_cx_add() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
if [ -z "$CX_Key" ] || [ -z "$CX_Secret" ] ; then
|
if [ -z "$CX_Key" ] || [ -z "$CX_Secret" ]; then
|
||||||
|
CX_Key=""
|
||||||
|
CX_Secret=""
|
||||||
_err "You don't specify cloudxns.com api key or secret yet."
|
_err "You don't specify cloudxns.com api key or secret yet."
|
||||||
_err "Please create you key and try again."
|
_err "Please create you key and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
REST_API=$CX_Api
|
REST_API="$CX_Api"
|
||||||
|
|
||||||
#save the api key and email to the account conf file.
|
#save the api key and email to the account conf file.
|
||||||
_saveaccountconf CX_Key "$CX_Key"
|
_saveaccountconf CX_Key "$CX_Key"
|
||||||
_saveaccountconf CX_Secret "$CX_Secret"
|
_saveaccountconf CX_Secret "$CX_Secret"
|
||||||
|
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root $fulldomain ; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
existing_records $_domain $_sub_domain
|
existing_records "$_domain" "$_sub_domain"
|
||||||
_debug count "$count"
|
_debug count "$count"
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "Error get existing records."
|
_err "Error get existing records."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$count" = "0" ] ; then
|
if [ "$count" = "0" ]; then
|
||||||
add_record $_domain $_sub_domain $txtvalue
|
add_record "$_domain" "$_sub_domain" "$txtvalue"
|
||||||
else
|
else
|
||||||
update_record $_domain $_sub_domain $txtvalue
|
update_record "$_domain" "$_sub_domain" "$txtvalue"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" = "0" ] ; then
|
if [ "$?" = "0" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_cx_rm() {
|
dns_cx_rm() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#usage: root sub
|
#usage: root sub
|
||||||
#return if the sub record already exists.
|
#return if the sub record already exists.
|
||||||
#echos the existing records count.
|
#echos the existing records count.
|
||||||
@ -73,24 +69,24 @@ existing_records() {
|
|||||||
_debug "Getting txt records"
|
_debug "Getting txt records"
|
||||||
root=$1
|
root=$1
|
||||||
sub=$2
|
sub=$2
|
||||||
|
|
||||||
if ! _rest GET "record/$_domain_id?:domain_id?host_id=0&offset=0&row_num=100" ; then
|
if ! _rest GET "record/$_domain_id?:domain_id?host_id=0&offset=0&row_num=100"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
count=0
|
count=0
|
||||||
seg=$(printf "%s\n" "$response" | _egrep_o "{[^\{]*host\":\"$_sub_domain\"[^\}]*\}")
|
seg=$(printf "%s\n" "$response" | _egrep_o "{[^\{]*host\":\"$_sub_domain\"[^\}]*\}")
|
||||||
_debug seg "$seg"
|
_debug seg "$seg"
|
||||||
if [ -z "$seg" ] ; then
|
if [ -z "$seg" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep '"type":"TXT"' > /dev/null ; then
|
if printf "%s" "$response" | grep '"type":"TXT"' >/dev/null; then
|
||||||
count=1
|
count=1
|
||||||
record_id=$(printf "%s\n" "$seg" | _egrep_o \"record_id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
|
record_id=$(printf "%s\n" "$seg" | _egrep_o "\"record_id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")
|
||||||
_debug record_id "$record_id"
|
_debug record_id "$record_id"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#add the txt record.
|
#add the txt record.
|
||||||
@ -99,14 +95,14 @@ add_record() {
|
|||||||
root=$1
|
root=$1
|
||||||
sub=$2
|
sub=$2
|
||||||
txtvalue=$3
|
txtvalue=$3
|
||||||
fulldomain=$sub.$root
|
fulldomain="$sub.$root"
|
||||||
|
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
|
|
||||||
if ! _rest POST "record" "{\"domain_id\": $_domain_id, \"host\":\"$_sub_domain\", \"value\":\"$txtvalue\", \"type\":\"TXT\",\"ttl\":600, \"line_id\":1}"; then
|
if ! _rest POST "record" "{\"domain_id\": $_domain_id, \"host\":\"$_sub_domain\", \"value\":\"$txtvalue\", \"type\":\"TXT\",\"ttl\":600, \"line_id\":1}"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,20 +112,17 @@ update_record() {
|
|||||||
root=$1
|
root=$1
|
||||||
sub=$2
|
sub=$2
|
||||||
txtvalue=$3
|
txtvalue=$3
|
||||||
fulldomain=$sub.$root
|
fulldomain="$sub.$root"
|
||||||
|
|
||||||
_info "Updating record"
|
_info "Updating record"
|
||||||
|
|
||||||
if _rest PUT "record/$record_id" "{\"domain_id\": $_domain_id, \"host\":\"$_sub_domain\", \"value\":\"$txtvalue\", \"type\":\"TXT\",\"ttl\":600, \"line_id\":1}" ; then
|
if _rest PUT "record/$record_id" "{\"domain_id\": $_domain_id, \"host\":\"$_sub_domain\", \"value\":\"$txtvalue\", \"type\":\"TXT\",\"ttl\":600, \"line_id\":1}"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################### Private functions bellow ##################################
|
#################### Private functions bellow ##################################
|
||||||
#_acme-challenge.www.domain.com
|
#_acme-challenge.www.domain.com
|
||||||
#returns
|
#returns
|
||||||
@ -140,79 +133,76 @@ _get_root() {
|
|||||||
domain=$1
|
domain=$1
|
||||||
i=2
|
i=2
|
||||||
p=1
|
p=1
|
||||||
|
|
||||||
if ! _rest GET "domain" ; then
|
if ! _rest GET "domain"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ '1' ] ; do
|
while true; do
|
||||||
h=$(printf $domain | cut -d . -f $i-100)
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
_debug h "$h"
|
_debug h "$h"
|
||||||
if [ -z "$h" ] ; then
|
if [ -z "$h" ]; then
|
||||||
#not valid
|
#not valid
|
||||||
return 1;
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep "$h." >/dev/null ; then
|
if _contains "$response" "$h."; then
|
||||||
seg=$(printf "%s" "$response" | _egrep_o "\{[^\{]*\"$h\.\"[^\}]*\}" )
|
seg=$(printf "%s" "$response" | _egrep_o "\{[^\{]*\"$h\.\"[^\}]*\}")
|
||||||
_debug seg "$seg"
|
_debug seg "$seg"
|
||||||
_domain_id=$(printf "%s" "$seg" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
|
_domain_id=$(printf "%s" "$seg" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")
|
||||||
_debug _domain_id "$_domain_id"
|
_debug _domain_id "$_domain_id"
|
||||||
if [ "$_domain_id" ] ; then
|
if [ "$_domain_id" ]; then
|
||||||
_sub_domain=$(printf $domain | cut -d . -f 1-$p)
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||||
_debug _sub_domain $_sub_domain
|
_debug _sub_domain "$_sub_domain"
|
||||||
_domain=$h
|
_domain="$h"
|
||||||
_debug _domain $_domain
|
_debug _domain "$_domain"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
p=$i
|
p="$i"
|
||||||
i=$(expr $i + 1)
|
i=$(_math "$i" + 1)
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#Usage: method URI data
|
#Usage: method URI data
|
||||||
_rest() {
|
_rest() {
|
||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
_debug $ep
|
_debug "$ep"
|
||||||
url="$REST_API/$ep"
|
url="$REST_API/$ep"
|
||||||
_debug url "$url"
|
_debug url "$url"
|
||||||
|
|
||||||
cdate=$(date -u "+%Y-%m-%d %H:%M:%S UTC")
|
cdate=$(date -u "+%Y-%m-%d %H:%M:%S UTC")
|
||||||
_debug cdate "$cdate"
|
_debug cdate "$cdate"
|
||||||
|
|
||||||
data="$3"
|
data="$3"
|
||||||
_debug data "$data"
|
_debug data "$data"
|
||||||
|
|
||||||
sec="$CX_Key$url$data$cdate$CX_Secret"
|
sec="$CX_Key$url$data$cdate$CX_Secret"
|
||||||
_debug sec "$sec"
|
_debug sec "$sec"
|
||||||
hmac=$(printf "$sec"| openssl md5 |cut -d " " -f 2)
|
hmac=$(printf "%s" "$sec" | _digest md5 hex)
|
||||||
_debug hmac "$hmac"
|
_debug hmac "$hmac"
|
||||||
|
|
||||||
_H1="API-KEY: $CX_Key"
|
_H1="API-KEY: $CX_Key"
|
||||||
_H2="API-REQUEST-DATE: $cdate"
|
_H2="API-REQUEST-DATE: $cdate"
|
||||||
_H3="API-HMAC: $hmac"
|
_H3="API-HMAC: $hmac"
|
||||||
_H4="Content-Type: application/json"
|
_H4="Content-Type: application/json"
|
||||||
|
|
||||||
if [ "$data" ] ; then
|
if [ "$data" ]; then
|
||||||
response="$(_post "$data" "$url" "" $m)"
|
response="$(_post "$data" "$url" "" "$m")"
|
||||||
else
|
else
|
||||||
response="$(_get "$url")"
|
response="$(_get "$url")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
if ! printf "$response" | grep '"message":"success"' > /dev/null ; then
|
if ! _contains "$response" '"message":"success"'; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
138
dnsapi/dns_dp.sh
138
dnsapi/dns_dp.sh
@ -6,10 +6,8 @@
|
|||||||
#
|
#
|
||||||
#DP_Key="sADDsdasdgdsf"
|
#DP_Key="sADDsdasdgdsf"
|
||||||
|
|
||||||
|
|
||||||
DP_Api="https://dnsapi.cn"
|
DP_Api="https://dnsapi.cn"
|
||||||
|
|
||||||
|
|
||||||
#REST_API
|
#REST_API
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
@ -17,49 +15,47 @@ DP_Api="https://dnsapi.cn"
|
|||||||
dns_dp_add() {
|
dns_dp_add() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
if [ -z "$DP_Id" ] || [ -z "$DP_Key" ] ; then
|
if [ -z "$DP_Id" ] || [ -z "$DP_Key" ]; then
|
||||||
|
DP_Id=""
|
||||||
|
DP_Key=""
|
||||||
_err "You don't specify dnspod api key and key id yet."
|
_err "You don't specify dnspod api key and key id yet."
|
||||||
_err "Please create you key and try again."
|
_err "Please create you key and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
REST_API=$DP_Api
|
REST_API="$DP_Api"
|
||||||
|
|
||||||
#save the api key and email to the account conf file.
|
#save the api key and email to the account conf file.
|
||||||
_saveaccountconf DP_Id "$DP_Id"
|
_saveaccountconf DP_Id "$DP_Id"
|
||||||
_saveaccountconf DP_Key "$DP_Key"
|
_saveaccountconf DP_Key "$DP_Key"
|
||||||
|
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root $fulldomain ; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
existing_records $_domain $_sub_domain
|
existing_records "$_domain" "$_sub_domain"
|
||||||
_debug count "$count"
|
_debug count "$count"
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "Error get existing records."
|
_err "Error get existing records."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$count" = "0" ] ; then
|
if [ "$count" = "0" ]; then
|
||||||
add_record $_domain $_sub_domain $txtvalue
|
add_record "$_domain" "$_sub_domain" "$txtvalue"
|
||||||
else
|
else
|
||||||
update_record $_domain $_sub_domain $txtvalue
|
update_record "$_domain" "$_sub_domain" "$txtvalue"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_dp_rm() {
|
dns_dp_rm() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#usage: root sub
|
#usage: root sub
|
||||||
#return if the sub record already exists.
|
#return if the sub record already exists.
|
||||||
#echos the existing records count.
|
#echos the existing records count.
|
||||||
@ -68,26 +64,25 @@ existing_records() {
|
|||||||
_debug "Getting txt records"
|
_debug "Getting txt records"
|
||||||
root=$1
|
root=$1
|
||||||
sub=$2
|
sub=$2
|
||||||
|
|
||||||
if ! _rest POST "Record.List" "login_token=$DP_Id,$DP_Key&domain_id=$_domain_id&sub_domain=$_sub_domain"; then
|
if ! _rest POST "Record.List" "login_token=$DP_Id,$DP_Key&domain_id=$_domain_id&sub_domain=$_sub_domain"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep 'No records' ; then
|
if _contains "$response" 'No records'; then
|
||||||
count=0;
|
count=0
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep "Action completed successful" >/dev/null ; then
|
if _contains "$response" "Action completed successful"; then
|
||||||
count=$(printf "$response" | grep '<type>TXT</type>' | wc -l)
|
count=$(printf "%s" "$response" | grep '<type>TXT</type>' | wc -l)
|
||||||
record_id=$(printf "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)
|
record_id=$(printf "%s" "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_err "get existing records error."
|
_err "get existing records error."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
count=0
|
count=0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,20 +92,19 @@ add_record() {
|
|||||||
root=$1
|
root=$1
|
||||||
sub=$2
|
sub=$2
|
||||||
txtvalue=$3
|
txtvalue=$3
|
||||||
fulldomain=$sub.$root
|
fulldomain="$sub.$root"
|
||||||
|
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
|
|
||||||
if ! _rest POST "Record.Create" "login_token=$DP_Id,$DP_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=默认"; then
|
if ! _rest POST "Record.Create" "login_token=$DP_Id,$DP_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=默认"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep "Action completed successful" ; then
|
if _contains "$response" "Action completed successful"; then
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
return 1 #error
|
return 1 #error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,25 +114,22 @@ update_record() {
|
|||||||
root=$1
|
root=$1
|
||||||
sub=$2
|
sub=$2
|
||||||
txtvalue=$3
|
txtvalue=$3
|
||||||
fulldomain=$sub.$root
|
fulldomain="$sub.$root"
|
||||||
|
|
||||||
_info "Updating record"
|
_info "Updating record"
|
||||||
|
|
||||||
if ! _rest POST "Record.Modify" "login_token=$DP_Id,$DP_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=默认&record_id=$record_id"; then
|
if ! _rest POST "Record.Modify" "login_token=$DP_Id,$DP_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=默认&record_id=$record_id"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep "Action completed successful" ; then
|
if _contains "$response" "Action completed successful"; then
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1 #error
|
return 1 #error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################### Private functions bellow ##################################
|
#################### Private functions bellow ##################################
|
||||||
#_acme-challenge.www.domain.com
|
#_acme-challenge.www.domain.com
|
||||||
#returns
|
#returns
|
||||||
@ -149,59 +140,56 @@ _get_root() {
|
|||||||
domain=$1
|
domain=$1
|
||||||
i=2
|
i=2
|
||||||
p=1
|
p=1
|
||||||
while [ '1' ] ; do
|
while true; do
|
||||||
h=$(printf $domain | cut -d . -f $i-100)
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
if [ -z "$h" ] ; then
|
if [ -z "$h" ]; then
|
||||||
#not valid
|
#not valid
|
||||||
return 1;
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! _rest POST "Domain.Info" "login_token=$DP_Id,$DP_Key&format=json&domain=$h"; then
|
if ! _rest POST "Domain.Info" "login_token=$DP_Id,$DP_Key&format=json&domain=$h"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep "Action completed successful" >/dev/null ; then
|
if _contains "$response" "Action completed successful"; then
|
||||||
_domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")
|
||||||
_debug _domain_id "$_domain_id"
|
_debug _domain_id "$_domain_id"
|
||||||
if [ "$_domain_id" ] ; then
|
if [ "$_domain_id" ]; then
|
||||||
_sub_domain=$(printf $domain | cut -d . -f 1-$p)
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||||
_debug _sub_domain $_sub_domain
|
_debug _sub_domain "$_sub_domain"
|
||||||
_domain=$h
|
_domain="$h"
|
||||||
_debug _domain $_domain
|
_debug _domain "$_domain"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
p=$i
|
p="$i"
|
||||||
i=$(expr $i + 1)
|
i=$(_math "$i" + 1)
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#Usage: method URI data
|
#Usage: method URI data
|
||||||
_rest() {
|
_rest() {
|
||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
data="$3"
|
data="$3"
|
||||||
_debug $ep
|
_debug "$ep"
|
||||||
url="$REST_API/$ep"
|
url="$REST_API/$ep"
|
||||||
|
|
||||||
_debug url "$url"
|
_debug url "$url"
|
||||||
|
|
||||||
if [ "$data" ] ; then
|
if [ "$data" ]; then
|
||||||
_debug2 data "$data"
|
_debug2 data "$data"
|
||||||
response="$(_post $data "$url")"
|
response="$(_post "$data" "$url")"
|
||||||
else
|
else
|
||||||
response="$(_get "$url")"
|
response="$(_get "$url")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,39 +6,39 @@
|
|||||||
#
|
#
|
||||||
#GD_Secret="asdfsdfsfsdfsdfdfsdf"
|
#GD_Secret="asdfsdfsfsdfsdfdfsdf"
|
||||||
|
|
||||||
|
|
||||||
GD_Api="https://api.godaddy.com/v1"
|
GD_Api="https://api.godaddy.com/v1"
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
dns_gd_add(){
|
dns_gd_add() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
if [ -z "$GD_Key" ] || [ -z "$GD_Secret" ] ; then
|
if [ -z "$GD_Key" ] || [ -z "$GD_Secret" ]; then
|
||||||
|
GD_Key=""
|
||||||
|
GD_Secret=""
|
||||||
_err "You don't specify godaddy api key and secret yet."
|
_err "You don't specify godaddy api key and secret yet."
|
||||||
_err "Please create you key and try again."
|
_err "Please create you key and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#save the api key and email to the account conf file.
|
#save the api key and email to the account conf file.
|
||||||
_saveaccountconf GD_Key "$GD_Key"
|
_saveaccountconf GD_Key "$GD_Key"
|
||||||
_saveaccountconf GD_Secret "$GD_Secret"
|
_saveaccountconf GD_Secret "$GD_Secret"
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root $fulldomain ; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug _domain_id "$_domain_id"
|
|
||||||
_debug _sub_domain "$_sub_domain"
|
_debug _sub_domain "$_sub_domain"
|
||||||
_debug _domain "$_domain"
|
_debug _domain "$_domain"
|
||||||
|
|
||||||
|
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
if _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[{\"data\":\"$txtvalue\"}]"; then
|
if _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[{\"data\":\"$txtvalue\"}]"; then
|
||||||
if [ "$response" = "{}" ] ; then
|
if [ "$response" = "{}" ]; then
|
||||||
_info "Added, sleeping 10 seconds"
|
_info "Added, sleeping 10 seconds"
|
||||||
sleep 10
|
sleep 10
|
||||||
#todo: check if the record takes effect
|
#todo: check if the record takes effect
|
||||||
@ -50,50 +50,44 @@ dns_gd_add(){
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
_err "Add txt record error."
|
_err "Add txt record error."
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_gd_rm() {
|
dns_gd_rm() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################### Private functions bellow ##################################
|
#################### Private functions bellow ##################################
|
||||||
#_acme-challenge.www.domain.com
|
#_acme-challenge.www.domain.com
|
||||||
#returns
|
#returns
|
||||||
# _sub_domain=_acme-challenge.www
|
# _sub_domain=_acme-challenge.www
|
||||||
# _domain=domain.com
|
# _domain=domain.com
|
||||||
# _domain_id=sdjkglgdfewsdfg
|
|
||||||
_get_root() {
|
_get_root() {
|
||||||
domain=$1
|
domain=$1
|
||||||
i=2
|
i=2
|
||||||
p=1
|
p=1
|
||||||
while [ '1' ] ; do
|
while true; do
|
||||||
h=$(printf $domain | cut -d . -f $i-100)
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
if [ -z "$h" ] ; then
|
if [ -z "$h" ]; then
|
||||||
#not valid
|
#not valid
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! _gd_rest GET "domains/$h" ; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$response" | grep '"code":"NOT_FOUND"' >/dev/null ; then
|
if ! _gd_rest GET "domains/$h"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if _contains "$response" '"code":"NOT_FOUND"'; then
|
||||||
_debug "$h not found"
|
_debug "$h not found"
|
||||||
else
|
else
|
||||||
_sub_domain=$(printf $domain | cut -d . -f 1-$p)
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||||
_domain=$h
|
_domain="$h"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
p=$i
|
p="$i"
|
||||||
i=$(expr $i + 1)
|
i=$(_math "$i" + 1)
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -102,24 +96,22 @@ _gd_rest() {
|
|||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
data="$3"
|
data="$3"
|
||||||
_debug $ep
|
_debug "$ep"
|
||||||
|
|
||||||
_H1="Authorization: sso-key $GD_Key:$GD_Secret"
|
_H1="Authorization: sso-key $GD_Key:$GD_Secret"
|
||||||
_H2="Content-Type: application/json"
|
_H2="Content-Type: application/json"
|
||||||
|
|
||||||
if [ "$data" ] ; then
|
if [ "$data" ]; then
|
||||||
_debug data "$data"
|
_debug data "$data"
|
||||||
response="$(_post "$data" "$GD_Api/$ep" "" $m)"
|
response="$(_post "$data" "$GD_Api/$ep" "" "$m")"
|
||||||
else
|
else
|
||||||
response="$(_get "$GD_Api/$ep")"
|
response="$(_get "$GD_Api/$ep")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,15 +13,16 @@ wiki="https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api"
|
|||||||
dns_lexicon_add() {
|
dns_lexicon_add() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
domain=$(printf "$fulldomain" | cut -d . -f 2-999)
|
domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
|
||||||
|
|
||||||
if ! _exists $lexicon_cmd ; then
|
if ! _exists "$lexicon_cmd"; then
|
||||||
_err "Please install $lexicon_cmd first: $wiki"
|
_err "Please install $lexicon_cmd first: $wiki"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PROVIDER" ] ; then
|
if [ -z "$PROVIDER" ]; then
|
||||||
|
PROVIDER=""
|
||||||
_err "Please define env PROVIDER first: $wiki"
|
_err "Please define env PROVIDER first: $wiki"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -29,50 +30,44 @@ dns_lexicon_add() {
|
|||||||
_savedomainconf PROVIDER "$PROVIDER"
|
_savedomainconf PROVIDER "$PROVIDER"
|
||||||
export PROVIDER
|
export PROVIDER
|
||||||
|
|
||||||
Lx_name=$(echo LEXICON_${PROVIDER}_USERNAME | tr [a-z] [A-Z])
|
Lx_name=$(echo LEXICON_"${PROVIDER}"_USERNAME | tr '[a-z]' '[A-Z]')
|
||||||
eval Lx_name_v="\$$Lx_name"
|
Lx_name_v=$(eval echo \$"$Lx_name")
|
||||||
_debug "$Lx_name" "$Lx_name_v"
|
_debug "$Lx_name" "$Lx_name_v"
|
||||||
if [ "$Lx_name_v" ] ; then
|
if [ "$Lx_name_v" ]; then
|
||||||
_saveaccountconf $Lx_name "$Lx_name_v"
|
_saveaccountconf "$Lx_name" "$Lx_name_v"
|
||||||
export "$Lx_name"
|
eval export "$Lx_name"
|
||||||
fi
|
|
||||||
|
|
||||||
Lx_token=$(echo LEXICON_${PROVIDER}_TOKEN | tr [a-z] [A-Z])
|
|
||||||
eval Lx_token_v="\$$Lx_token"
|
|
||||||
_debug "$Lx_token" "$Lx_token_v"
|
|
||||||
if [ "$Lx_token_v" ] ; then
|
|
||||||
_saveaccountconf $Lx_token "$Lx_token_v"
|
|
||||||
export "$Lx_token"
|
|
||||||
fi
|
|
||||||
|
|
||||||
Lx_password=$(echo LEXICON_${PROVIDER}_PASSWORD | tr [a-z] [A-Z])
|
|
||||||
eval Lx_password_v="\$$Lx_password"
|
|
||||||
_debug "$Lx_password" "$Lx_password_v"
|
|
||||||
if [ "$Lx_password_v" ] ; then
|
|
||||||
_saveaccountconf $Lx_password "$Lx_password_v"
|
|
||||||
export "$Lx_password"
|
|
||||||
fi
|
|
||||||
|
|
||||||
Lx_domaintoken=$(echo LEXICON_${PROVIDER}_DOMAINTOKEN | tr [a-z] [A-Z])
|
|
||||||
eval Lx_domaintoken_v="\$$Lx_domaintoken"
|
|
||||||
_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
|
|
||||||
if [ "$Lx_domaintoken_v" ] ; then
|
|
||||||
export "$Lx_domaintoken"
|
|
||||||
_saveaccountconf $Lx_domaintoken "$Lx_domaintoken_v"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$lexicon_cmd "$PROVIDER" create ${domain} TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
|
Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr '[a-z]' '[A-Z]')
|
||||||
|
Lx_token_v=$(eval echo \$"$Lx_token")
|
||||||
|
_debug "$Lx_token" "$Lx_token_v"
|
||||||
|
if [ "$Lx_token_v" ]; then
|
||||||
|
_saveaccountconf "$Lx_token" "$Lx_token_v"
|
||||||
|
eval export "$Lx_token"
|
||||||
|
fi
|
||||||
|
|
||||||
|
Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr '[a-z]' '[A-Z]')
|
||||||
|
Lx_password_v=$(eval echo \$"$Lx_password")
|
||||||
|
_debug "$Lx_password" "$Lx_password_v"
|
||||||
|
if [ "$Lx_password_v" ]; then
|
||||||
|
_saveaccountconf "$Lx_password" "$Lx_password_v"
|
||||||
|
eval export "$Lx_password"
|
||||||
|
fi
|
||||||
|
|
||||||
|
Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr '[a-z]' '[A-Z]')
|
||||||
|
Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken")
|
||||||
|
_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
|
||||||
|
if [ "$Lx_domaintoken_v" ]; then
|
||||||
|
eval export "$Lx_domaintoken"
|
||||||
|
_saveaccountconf "$Lx_domaintoken" "$Lx_domaintoken_v"
|
||||||
|
fi
|
||||||
|
|
||||||
|
$lexicon_cmd "$PROVIDER" create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_lexicon_rm() {
|
dns_lexicon_rm() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
143
dnsapi/dns_lua.sh
Executable file
143
dnsapi/dns_lua.sh
Executable file
@ -0,0 +1,143 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# bug reports to dev@1e.ca
|
||||||
|
|
||||||
|
#
|
||||||
|
#LUA_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
||||||
|
#
|
||||||
|
#LUA_Email="user@luadns.net"
|
||||||
|
|
||||||
|
LUA_Api="https://api.luadns.com/v1"
|
||||||
|
LUA_auth=$(printf "%s" "$LUA_Email:$LUA_Key" | _base64)
|
||||||
|
|
||||||
|
######## Public functions #####################
|
||||||
|
|
||||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
|
dns_lua_add() {
|
||||||
|
fulldomain=$1
|
||||||
|
txtvalue=$2
|
||||||
|
|
||||||
|
if [ -z "$LUA_Key" ] || [ -z "$LUA_Email" ]; then
|
||||||
|
LUA_Key=""
|
||||||
|
LUA_Email=""
|
||||||
|
_err "You don't specify luadns api key and email yet."
|
||||||
|
_err "Please create you key and try again."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#save the api key and email to the account conf file.
|
||||||
|
_saveaccountconf LUA_Key "$LUA_Key"
|
||||||
|
_saveaccountconf LUA_Email "$LUA_Email"
|
||||||
|
|
||||||
|
_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"
|
||||||
|
_LUA_rest GET "zones/${_domain_id}/records"
|
||||||
|
|
||||||
|
if ! _contains "$response" "\"id\":"; 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 "Adding record"
|
||||||
|
if _LUA_rest POST "zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
|
||||||
|
if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then
|
||||||
|
_info "Added"
|
||||||
|
#todo: check if the record takes effect
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
_err "Add txt record error."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
_err "Add txt record error."
|
||||||
|
else
|
||||||
|
_info "Updating record"
|
||||||
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":[^,]*,\"name\":\"$fulldomain.\",\"type\":\"TXT\"" | cut -d: -f2 | cut -d, -f1)
|
||||||
|
_debug "record_id" "$record_id"
|
||||||
|
|
||||||
|
_LUA_rest PUT "zones/$_domain_id/records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"ttl\":120}"
|
||||||
|
if [ "$?" = "0" ]; then
|
||||||
|
_info "Updated!"
|
||||||
|
#todo: check if the record takes effect
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
_err "Update error"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#fulldomain
|
||||||
|
dns_lua_rm() {
|
||||||
|
fulldomain=$1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#################### Private functions bellow ##################################
|
||||||
|
#_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
|
||||||
|
if ! _LUA_rest GET "zones"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
while true; do
|
||||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
|
if [ -z "$h" ]; then
|
||||||
|
#not valid
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if _contains "$response" "\"name\":\"$h\""; then
|
||||||
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":[^,]*,\"name\":\"$h\"" | cut -d : -f 2 | cut -d , -f 1)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
_LUA_rest() {
|
||||||
|
m=$1
|
||||||
|
ep="$2"
|
||||||
|
data="$3"
|
||||||
|
_debug "$ep"
|
||||||
|
|
||||||
|
_H1="Accept: application/json"
|
||||||
|
_H2="Authorization: Basic $LUA_auth"
|
||||||
|
if [ "$data" ]; then
|
||||||
|
_debug data "$data"
|
||||||
|
response="$(_post "$data" "$LUA_Api/$ep" "" "$m")"
|
||||||
|
else
|
||||||
|
response="$(_get "$LUA_Api/$ep")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
_err "error $ep"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
_debug2 response "$response"
|
||||||
|
return 0
|
||||||
|
}
|
146
dnsapi/dns_me.sh
Executable file
146
dnsapi/dns_me.sh
Executable file
@ -0,0 +1,146 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# bug reports to dev@1e.ca
|
||||||
|
|
||||||
|
# ME_Key=qmlkdjflmkqdjf
|
||||||
|
# ME_Secret=qmsdlkqmlksdvnnpae
|
||||||
|
|
||||||
|
ME_Api=https://api.dnsmadeeasy.com/V2.0/dns/managed
|
||||||
|
|
||||||
|
######## Public functions #####################
|
||||||
|
|
||||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
|
dns_me_add() {
|
||||||
|
fulldomain=$1
|
||||||
|
txtvalue=$2
|
||||||
|
|
||||||
|
if [ -z "$ME_Key" ] || [ -z "$ME_Secret" ]; then
|
||||||
|
ME_Key=""
|
||||||
|
ME_Secret=""
|
||||||
|
_err "You didn't specify DNSMadeEasy api key and secret yet."
|
||||||
|
_err "Please create you key and try again."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#save the api key and email to the account conf file.
|
||||||
|
_saveaccountconf ME_Key "$ME_Key"
|
||||||
|
_saveaccountconf ME_Secret "$ME_Secret"
|
||||||
|
|
||||||
|
_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"
|
||||||
|
_me_rest GET "${_domain_id}/records?recordName=$_sub_domain&type=TXT"
|
||||||
|
|
||||||
|
if ! _contains "$response" "\"totalRecords\":"; then
|
||||||
|
_err "Error"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
count=$(printf "%s\n" "$response" | _egrep_o "\"totalRecords\":[^,]*" | cut -d : -f 2)
|
||||||
|
_debug count "$count"
|
||||||
|
if [ "$count" = "0" ]; then
|
||||||
|
_info "Adding record"
|
||||||
|
if _me_rest POST "$_domain_id/records/" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\",\"gtdLocation\":\"DEFAULT\",\"ttl\":120}"; then
|
||||||
|
if printf -- "%s" "$response" | grep \"id\": >/dev/null; then
|
||||||
|
_info "Added"
|
||||||
|
#todo: check if the record takes effect
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
_err "Add txt record error."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
_err "Add txt record error."
|
||||||
|
else
|
||||||
|
_info "Updating record"
|
||||||
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":[^,]*" | cut -d : -f 2 | head -n 1)
|
||||||
|
_debug "record_id" "$record_id"
|
||||||
|
|
||||||
|
_me_rest PUT "$_domain_id/records/$record_id/" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\",\"gtdLocation\":\"DEFAULT\",\"ttl\":120}"
|
||||||
|
if [ "$?" = "0" ]; then
|
||||||
|
_info "Updated"
|
||||||
|
#todo: check if the record takes effect
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
_err "Update error"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#fulldomain
|
||||||
|
dns_me_rm() {
|
||||||
|
fulldomain=$1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#################### Private functions bellow ##################################
|
||||||
|
#_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 ! _me_rest GET "name?domainname=$h"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if _contains "$response" "\"name\":\"$h\""; then
|
||||||
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":[^,]*" | head -n 1 | cut -d : -f 2)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
_me_rest() {
|
||||||
|
m=$1
|
||||||
|
ep="$2"
|
||||||
|
data="$3"
|
||||||
|
_debug "$ep"
|
||||||
|
|
||||||
|
cdate=$(date -u +"%a, %d %b %Y %T %Z")
|
||||||
|
hmac=$(printf "%s" "$cdate" | _hmac sha1 "$ME_Secret" 1)
|
||||||
|
|
||||||
|
_H1="x-dnsme-apiKey: $ME_Key"
|
||||||
|
_H2="x-dnsme-requestDate: $cdate"
|
||||||
|
_H3="x-dnsme-hmac: $hmac"
|
||||||
|
|
||||||
|
if [ "$data" ]; then
|
||||||
|
_debug data "$data"
|
||||||
|
response="$(_post "$data" "$ME_Api/$ep" "" "$m")"
|
||||||
|
else
|
||||||
|
response="$(_get "$ME_Api/$ep")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
_err "error $ep"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
_debug2 response "$response"
|
||||||
|
return 0
|
||||||
|
}
|
@ -6,8 +6,6 @@
|
|||||||
#Which will be called by acme.sh to add the txt record to your api system.
|
#Which will be called by acme.sh to add the txt record to your api system.
|
||||||
#returns 0 means success, otherwise error.
|
#returns 0 means success, otherwise error.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
@ -15,21 +13,18 @@ dns_myapi_add() {
|
|||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
_err "Not implemented!"
|
_err "Not implemented!"
|
||||||
return 1;
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_myapi_rm() {
|
dns_myapi_rm() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#################### Private functions bellow ##################################
|
#################### Private functions bellow ##################################
|
||||||
_info() {
|
_info() {
|
||||||
if [ -z "$2" ] ; then
|
if [ -z "$2" ]; then
|
||||||
echo "[$(date)] $1"
|
echo "[$(date)] $1"
|
||||||
else
|
else
|
||||||
echo "[$(date)] $1='$2'"
|
echo "[$(date)] $1='$2'"
|
||||||
@ -42,7 +37,7 @@ _err() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_debug() {
|
_debug() {
|
||||||
if [ -z "$DEBUG" ] ; then
|
if [ -z "$DEBUG" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
_err "$@"
|
_err "$@"
|
||||||
@ -50,8 +45,8 @@ _debug() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_debug2() {
|
_debug2() {
|
||||||
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ] ; then
|
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then
|
||||||
_debug "$@"
|
_debug "$@"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
|
||||||
#Applcation Key
|
#Applcation Key
|
||||||
#OVH_AK="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
#OVH_AK="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
||||||
#
|
#
|
||||||
@ -10,10 +9,8 @@
|
|||||||
#Consumer Key
|
#Consumer Key
|
||||||
#OVH_CK="sdfsdfsdfsdfsdfdsf"
|
#OVH_CK="sdfsdfsdfsdfsdfdsf"
|
||||||
|
|
||||||
|
|
||||||
#OVH_END_POINT=ovh-eu
|
#OVH_END_POINT=ovh-eu
|
||||||
|
|
||||||
|
|
||||||
#'ovh-eu'
|
#'ovh-eu'
|
||||||
OVH_EU='https://eu.api.ovh.com/1.0'
|
OVH_EU='https://eu.api.ovh.com/1.0'
|
||||||
|
|
||||||
@ -35,121 +32,118 @@ SYS_CA='https://ca.api.soyoustart.com/1.0'
|
|||||||
#'runabove-ca'
|
#'runabove-ca'
|
||||||
RAV_CA='https://api.runabove.com/1.0'
|
RAV_CA='https://api.runabove.com/1.0'
|
||||||
|
|
||||||
|
|
||||||
wiki="https://github.com/Neilpang/acme.sh/wiki/How-to-use-OVH-domain-api"
|
wiki="https://github.com/Neilpang/acme.sh/wiki/How-to-use-OVH-domain-api"
|
||||||
|
|
||||||
ovh_success="https://github.com/Neilpang/acme.sh/wiki/OVH-Success"
|
ovh_success="https://github.com/Neilpang/acme.sh/wiki/OVH-Success"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_ovh_get_api() {
|
_ovh_get_api() {
|
||||||
_ogaep="$1"
|
_ogaep="$1"
|
||||||
|
|
||||||
case "${_ogaep}" in
|
case "${_ogaep}" in
|
||||||
|
|
||||||
ovh-eu|ovheu)
|
ovh-eu | ovheu)
|
||||||
printf "%s" $OVH_EU
|
printf "%s" $OVH_EU
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
ovh-ca|ovhca)
|
ovh-ca | ovhca)
|
||||||
printf "%s" $OVH_CA
|
printf "%s" $OVH_CA
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
kimsufi-eu|kimsufieu)
|
kimsufi-eu | kimsufieu)
|
||||||
printf "%s" $KSF_EU
|
printf "%s" $KSF_EU
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
kimsufi-ca|kimsufica)
|
kimsufi-ca | kimsufica)
|
||||||
printf "%s" $KSF_CA
|
printf "%s" $KSF_CA
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
soyoustart-eu|soyoustarteu)
|
soyoustart-eu | soyoustarteu)
|
||||||
printf "%s" $SYS_EU
|
printf "%s" $SYS_EU
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
soyoustart-ca|soyoustartca)
|
soyoustart-ca | soyoustartca)
|
||||||
printf "%s" $SYS_CA
|
printf "%s" $SYS_CA
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
runabove-ca|runaboveca)
|
runabove-ca | runaboveca)
|
||||||
printf "%s" $RAV_CA
|
printf "%s" $RAV_CA
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
*)
|
*)
|
||||||
_err "Unknown parameter : $1"
|
|
||||||
return 1
|
_err "Unknown parameter : $1"
|
||||||
;;
|
return 1
|
||||||
esac
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
dns_ovh_add(){
|
dns_ovh_add() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
if [ -z "$OVH_AK" ] || [ -z "$OVH_AS" ] ; then
|
if [ -z "$OVH_AK" ] || [ -z "$OVH_AS" ]; then
|
||||||
|
OVH_AK=""
|
||||||
|
OVH_AS=""
|
||||||
_err "You don't specify OVH application key and application secret yet."
|
_err "You don't specify OVH application key and application secret yet."
|
||||||
_err "Please create you key and try again."
|
_err "Please create you key and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#save the api key and email to the account conf file.
|
#save the api key and email to the account conf file.
|
||||||
_saveaccountconf OVH_AK "$OVH_AK"
|
_saveaccountconf OVH_AK "$OVH_AK"
|
||||||
_saveaccountconf OVH_AS "$OVH_AS"
|
_saveaccountconf OVH_AS "$OVH_AS"
|
||||||
|
|
||||||
|
if [ -z "$OVH_END_POINT" ]; then
|
||||||
if [ -z "$OVH_END_POINT" ] ; then
|
|
||||||
OVH_END_POINT="ovh-eu"
|
OVH_END_POINT="ovh-eu"
|
||||||
fi
|
fi
|
||||||
_info "Using OVH endpoint: $OVH_END_POINT"
|
_info "Using OVH endpoint: $OVH_END_POINT"
|
||||||
if [ "$OVH_END_POINT" != "ovh-eu" ] ; then
|
if [ "$OVH_END_POINT" != "ovh-eu" ]; then
|
||||||
_saveaccountconf OVH_END_POINT "$OVH_END_POINT"
|
_saveaccountconf OVH_END_POINT "$OVH_END_POINT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OVH_API="$(_ovh_get_api $OVH_END_POINT )"
|
OVH_API="$(_ovh_get_api $OVH_END_POINT)"
|
||||||
_debug OVH_API "$OVH_API"
|
_debug OVH_API "$OVH_API"
|
||||||
|
|
||||||
if [ -z "$OVH_CK" ] ; then
|
if [ -z "$OVH_CK" ]; then
|
||||||
_info "OVH consumer key is empty, Let's get one:"
|
_info "OVH consumer key is empty, Let's get one:"
|
||||||
if ! _ovh_authentication ; then
|
if ! _ovh_authentication; then
|
||||||
_err "Can not get consumer key."
|
_err "Can not get consumer key."
|
||||||
fi
|
fi
|
||||||
#return and wait for retry.
|
#return and wait for retry.
|
||||||
return 1;
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
_info "Checking authentication"
|
_info "Checking authentication"
|
||||||
|
|
||||||
response="$(_ovh_rest GET "domain/")"
|
response="$(_ovh_rest GET "domain/")"
|
||||||
if _contains "$response" "INVALID_CREDENTIAL" ; then
|
if _contains "$response" "INVALID_CREDENTIAL"; then
|
||||||
_err "The consumer key is invalid: $OVH_CK"
|
_err "The consumer key is invalid: $OVH_CK"
|
||||||
_err "Please retry to create a new one."
|
_err "Please retry to create a new one."
|
||||||
_clearaccountconf OVH_CK
|
_clearaccountconf OVH_CK
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_info "Consumer key is ok."
|
_info "Consumer key is ok."
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root $fulldomain ; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug _domain_id "$_domain_id"
|
|
||||||
_debug _sub_domain "$_sub_domain"
|
_debug _sub_domain "$_sub_domain"
|
||||||
_debug _domain "$_domain"
|
_debug _domain "$_domain"
|
||||||
|
|
||||||
_debug "Getting txt records"
|
_debug "Getting txt records"
|
||||||
_ovh_rest GET "domain/zone/$_domain/record?fieldType=TXT&subDomain=$_sub_domain"
|
_ovh_rest GET "domain/zone/$_domain/record?fieldType=TXT&subDomain=$_sub_domain"
|
||||||
|
|
||||||
if _contains "$response" '\[\]' || _contains "$response" "This service does not exist" ; then
|
if _contains "$response" '\[\]' || _contains "$response" "This service does not exist"; then
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
if _ovh_rest POST "domain/zone/$_domain/record" "{\"fieldType\":\"TXT\",\"subDomain\":\"$_sub_domain\",\"target\":\"$txtvalue\",\"ttl\":60}"; then
|
if _ovh_rest POST "domain/zone/$_domain/record" "{\"fieldType\":\"TXT\",\"subDomain\":\"$_sub_domain\",\"target\":\"$txtvalue\",\"ttl\":60}"; then
|
||||||
if _contains "$response" "$txtvalue" ; then
|
if _contains "$response" "$txtvalue"; then
|
||||||
_ovh_rest POST "domain/zone/$_domain/refresh"
|
_ovh_rest POST "domain/zone/$_domain/refresh"
|
||||||
_debug "Refresh:$response"
|
_debug "Refresh:$response"
|
||||||
_info "Added, sleeping 10 seconds"
|
_info "Added, sleeping 10 seconds"
|
||||||
@ -161,27 +155,26 @@ dns_ovh_add(){
|
|||||||
else
|
else
|
||||||
_info "Updating record"
|
_info "Updating record"
|
||||||
record_id=$(printf "%s" "$response" | tr -d "[]" | cut -d , -f 1)
|
record_id=$(printf "%s" "$response" | tr -d "[]" | cut -d , -f 1)
|
||||||
if [ -z "$record_id" ] ; then
|
if [ -z "$record_id" ]; then
|
||||||
_err "Can not get record id."
|
_err "Can not get record id."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug "record_id" $record_id
|
_debug "record_id" "$record_id"
|
||||||
|
|
||||||
if _ovh_rest PUT "domain/zone/$_domain/record/$record_id" "{\"target\":\"$txtvalue\",\"subDomain\":\"$_sub_domain\",\"ttl\":60}" ; then
|
if _ovh_rest PUT "domain/zone/$_domain/record/$record_id" "{\"target\":\"$txtvalue\",\"subDomain\":\"$_sub_domain\",\"ttl\":60}"; then
|
||||||
if _contains "$response" "null" ; then
|
if _contains "$response" "null"; then
|
||||||
_ovh_rest POST "domain/zone/$_domain/refresh"
|
_ovh_rest POST "domain/zone/$_domain/refresh"
|
||||||
_debug "Refresh:$response"
|
_debug "Refresh:$response"
|
||||||
_info "Updated, sleeping 10 seconds"
|
_info "Updated, sleeping 10 seconds"
|
||||||
sleep 10
|
sleep 10
|
||||||
return 0;
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
_err "Update error"
|
_err "Update error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_ovh_rm() {
|
dns_ovh_rm() {
|
||||||
@ -189,72 +182,69 @@ dns_ovh_rm() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#################### Private functions bellow ##################################
|
#################### Private functions bellow ##################################
|
||||||
|
|
||||||
_ovh_authentication() {
|
_ovh_authentication() {
|
||||||
|
|
||||||
_H1="X-Ovh-Application: $OVH_AK"
|
_H1="X-Ovh-Application: $OVH_AK"
|
||||||
_H2="Content-type: application/json"
|
_H2="Content-type: application/json"
|
||||||
_H3=""
|
_H3=""
|
||||||
_H4=""
|
_H4=""
|
||||||
|
|
||||||
_ovhdata='{"accessRules": [{"method": "GET","path": "/*"},{"method": "POST","path": "/*"},{"method": "PUT","path": "/*"},{"method": "DELETE","path": "/*"}],"redirection":"'$ovh_success'"}'
|
_ovhdata='{"accessRules": [{"method": "GET","path": "/*"},{"method": "POST","path": "/*"},{"method": "PUT","path": "/*"},{"method": "DELETE","path": "/*"}],"redirection":"'$ovh_success'"}'
|
||||||
|
|
||||||
response="$(_post "$_ovhdata" "$OVH_API/auth/credential")"
|
response="$(_post "$_ovhdata" "$OVH_API/auth/credential")"
|
||||||
_debug3 response "$response"
|
_debug3 response "$response"
|
||||||
validationUrl="$(echo "$response" | _egrep_o "validationUrl\":\"[^\"]*\"" | _egrep_o "http.*\"" | tr -d '"')"
|
validationUrl="$(echo "$response" | _egrep_o "validationUrl\":\"[^\"]*\"" | _egrep_o "http.*\"" | tr -d '"')"
|
||||||
if [ -z "$validationUrl" ] ; then
|
if [ -z "$validationUrl" ]; then
|
||||||
_err "Unable to get validationUrl"
|
_err "Unable to get validationUrl"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug validationUrl "$validationUrl"
|
_debug validationUrl "$validationUrl"
|
||||||
|
|
||||||
consumerKey="$(echo "$response" | _egrep_o "consumerKey\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
|
consumerKey="$(echo "$response" | _egrep_o "consumerKey\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
|
||||||
if [ -z "$consumerKey" ] ; then
|
if [ -z "$consumerKey" ]; then
|
||||||
_err "Unable to get consumerKey"
|
_err "Unable to get consumerKey"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug consumerKey "$consumerKey"
|
_debug consumerKey "$consumerKey"
|
||||||
|
|
||||||
OVH_CK="$consumerKey"
|
OVH_CK="$consumerKey"
|
||||||
_saveaccountconf OVH_CK "$OVH_CK"
|
_saveaccountconf OVH_CK "$OVH_CK"
|
||||||
|
|
||||||
_info "Please open this link to do authentication: $(__green "$validationUrl" )"
|
|
||||||
|
|
||||||
_info "Here is a guide for you: $(__green "$wiki" )"
|
_info "Please open this link to do authentication: $(__green "$validationUrl")"
|
||||||
|
|
||||||
|
_info "Here is a guide for you: $(__green "$wiki")"
|
||||||
_info "Please retry after the authentication is done."
|
_info "Please retry after the authentication is done."
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#_acme-challenge.www.domain.com
|
#_acme-challenge.www.domain.com
|
||||||
#returns
|
#returns
|
||||||
# _sub_domain=_acme-challenge.www
|
# _sub_domain=_acme-challenge.www
|
||||||
# _domain=domain.com
|
# _domain=domain.com
|
||||||
# _domain_id=sdjkglgdfewsdfg
|
|
||||||
_get_root() {
|
_get_root() {
|
||||||
domain=$1
|
domain=$1
|
||||||
i=2
|
i=2
|
||||||
p=1
|
p=1
|
||||||
while [ '1' ] ; do
|
while true; do
|
||||||
h=$(printf $domain | cut -d . -f $i-100)
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
if [ -z "$h" ] ; then
|
if [ -z "$h" ]; then
|
||||||
#not valid
|
#not valid
|
||||||
return 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! _ovh_rest GET "domain/zone/$h" ; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! _contains "$response" "This service does not exist" >/dev/null ; then
|
if ! _ovh_rest GET "domain/zone/$h"; then
|
||||||
_sub_domain=$(printf $domain | cut -d . -f 1-$p)
|
return 1
|
||||||
_domain=$h
|
fi
|
||||||
|
|
||||||
|
if ! _contains "$response" "This service does not exist" >/dev/null; then
|
||||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||||
|
_domain="$h"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
p=$i
|
p=$i
|
||||||
i=$(expr $i + 1)
|
i=$(_math "$i" + 1)
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -272,9 +262,8 @@ _ovh_rest() {
|
|||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
data="$3"
|
data="$3"
|
||||||
_debug $ep
|
_debug "$ep"
|
||||||
|
|
||||||
|
|
||||||
_ovh_url="$OVH_API/$ep"
|
_ovh_url="$OVH_API/$ep"
|
||||||
_debug2 _ovh_url "$_ovh_url"
|
_debug2 _ovh_url "$_ovh_url"
|
||||||
_ovh_t="$(_ovh_timestamp)"
|
_ovh_t="$(_ovh_timestamp)"
|
||||||
@ -283,7 +272,6 @@ _ovh_rest() {
|
|||||||
_debug _ovh_p "$_ovh_p"
|
_debug _ovh_p "$_ovh_p"
|
||||||
_ovh_hex="$(printf "%s" "$_ovh_p" | _digest sha1 hex)"
|
_ovh_hex="$(printf "%s" "$_ovh_p" | _digest sha1 hex)"
|
||||||
_debug2 _ovh_hex "$_ovh_hex"
|
_debug2 _ovh_hex "$_ovh_hex"
|
||||||
|
|
||||||
|
|
||||||
_H1="X-Ovh-Application: $OVH_AK"
|
_H1="X-Ovh-Application: $OVH_AK"
|
||||||
_H2="X-Ovh-Signature: \$1\$$_ovh_hex"
|
_H2="X-Ovh-Signature: \$1\$$_ovh_hex"
|
||||||
@ -291,19 +279,17 @@ _ovh_rest() {
|
|||||||
_H3="X-Ovh-Timestamp: $_ovh_t"
|
_H3="X-Ovh-Timestamp: $_ovh_t"
|
||||||
_H4="X-Ovh-Consumer: $OVH_CK"
|
_H4="X-Ovh-Consumer: $OVH_CK"
|
||||||
_H5="Content-Type: application/json;charset=utf-8"
|
_H5="Content-Type: application/json;charset=utf-8"
|
||||||
if [ "$data" ] || [ "$m" = "POST" ] || [ "$m" = "PUT" ] ; then
|
if [ "$data" ] || [ "$m" = "POST" ] || [ "$m" = "PUT" ]; then
|
||||||
_debug data "$data"
|
_debug data "$data"
|
||||||
response="$(_post "$data" "$_ovh_url" "" $m)"
|
response="$(_post "$data" "$_ovh_url" "" "$m")"
|
||||||
else
|
else
|
||||||
response="$(_get "$_ovh_url")"
|
response="$(_get "$_ovh_url")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,70 +16,71 @@ dns_pdns_add() {
|
|||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
txtvalue=$2
|
txtvalue=$2
|
||||||
|
|
||||||
if [ -z "$PDNS_Url" ] ; then
|
if [ -z "$PDNS_Url" ]; then
|
||||||
|
PDNS_Url=""
|
||||||
_err "You don't specify PowerDNS address."
|
_err "You don't specify PowerDNS address."
|
||||||
_err "Please set PDNS_Url and try again."
|
_err "Please set PDNS_Url and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PDNS_ServerId" ] ; then
|
if [ -z "$PDNS_ServerId" ]; then
|
||||||
|
PDNS_ServerId=""
|
||||||
_err "You don't specify PowerDNS server id."
|
_err "You don't specify PowerDNS server id."
|
||||||
_err "Please set you PDNS_ServerId and try again."
|
_err "Please set you PDNS_ServerId and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PDNS_Token" ] ; then
|
if [ -z "$PDNS_Token" ]; then
|
||||||
|
PDNS_Token=""
|
||||||
_err "You don't specify PowerDNS token."
|
_err "You don't specify PowerDNS token."
|
||||||
_err "Please create you PDNS_Token and try again."
|
_err "Please create you PDNS_Token and try again."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PDNS_Ttl" ] ; then
|
if [ -z "$PDNS_Ttl" ]; then
|
||||||
PDNS_Ttl=$DEFAULT_PDNS_TTL
|
PDNS_Ttl="$DEFAULT_PDNS_TTL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#save the api addr and key to the account conf file.
|
#save the api addr and key to the account conf file.
|
||||||
_saveaccountconf PDNS_Url "$PDNS_Url"
|
_saveaccountconf PDNS_Url "$PDNS_Url"
|
||||||
_saveaccountconf PDNS_ServerId "$PDNS_ServerId"
|
_saveaccountconf PDNS_ServerId "$PDNS_ServerId"
|
||||||
_saveaccountconf PDNS_Token "$PDNS_Token"
|
_saveaccountconf PDNS_Token "$PDNS_Token"
|
||||||
|
|
||||||
if [ "$PDNS_Ttl" != "$DEFAULT_PDNS_TTL" ] ; then
|
if [ "$PDNS_Ttl" != "$DEFAULT_PDNS_TTL" ]; then
|
||||||
_saveaccountconf PDNS_Ttl "$PDNS_Ttl"
|
_saveaccountconf PDNS_Ttl "$PDNS_Ttl"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_debug "First detect the root zone"
|
_debug "First detect the root zone"
|
||||||
if ! _get_root $fulldomain ; then
|
if ! _get_root "$fulldomain"; then
|
||||||
_err "invalid domain"
|
_err "invalid domain"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug _domain "$_domain"
|
_debug _domain "$_domain"
|
||||||
|
|
||||||
if ! set_record "$_domain" "$fulldomain" "$txtvalue" ; then
|
if ! set_record "$_domain" "$fulldomain" "$txtvalue"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#fulldomain
|
#fulldomain
|
||||||
dns_pdns_rm() {
|
dns_pdns_rm() {
|
||||||
fulldomain=$1
|
fulldomain=$1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set_record() {
|
set_record() {
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
root=$1
|
root=$1
|
||||||
full=$2
|
full=$2
|
||||||
txtvalue=$3
|
txtvalue=$3
|
||||||
|
|
||||||
if ! _pdns_rest "PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root." "{\"rrsets\": [{\"name\": \"$full.\", \"changetype\": \"REPLACE\", \"type\": \"TXT\", \"ttl\": $PDNS_Ttl, \"records\": [{\"name\": \"$full.\", \"type\": \"TXT\", \"content\": \"\\\"$txtvalue\\\"\", \"disabled\": false, \"ttl\": $PDNS_Ttl}]}]}" ; then
|
if ! _pdns_rest "PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root." "{\"rrsets\": [{\"name\": \"$full.\", \"changetype\": \"REPLACE\", \"type\": \"TXT\", \"ttl\": $PDNS_Ttl, \"records\": [{\"name\": \"$full.\", \"type\": \"TXT\", \"content\": \"\\\"$txtvalue\\\"\", \"disabled\": false, \"ttl\": $PDNS_Ttl}]}]}"; then
|
||||||
_err "Set txt record error."
|
_err "Set txt record error."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! _pdns_rest "PUT" "/api/v1/servers/$PDNS_ServerId/zones/$root./notify" ; then
|
if ! _pdns_rest "PUT" "/api/v1/servers/$PDNS_ServerId/zones/$root./notify"; then
|
||||||
_err "Notify servers error."
|
_err "Notify servers error."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -93,25 +94,23 @@ set_record() {
|
|||||||
_get_root() {
|
_get_root() {
|
||||||
domain=$1
|
domain=$1
|
||||||
i=1
|
i=1
|
||||||
p=1
|
|
||||||
|
|
||||||
if _pdns_rest "GET" "/api/v1/servers/$PDNS_ServerId/zones" ; then
|
if _pdns_rest "GET" "/api/v1/servers/$PDNS_ServerId/zones"; then
|
||||||
_zones_response=$response
|
_zones_response="$response"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ '1' ] ; do
|
while true; do
|
||||||
h=$(printf $domain | cut -d . -f $i-100)
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||||
if [ -z "$h" ] ; then
|
if [ -z "$h" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if printf "$_zones_response" | grep "\"name\": \"$h.\"" >/dev/null ; then
|
if _contains "$_zones_response" "\"name\": \"$h.\""; then
|
||||||
_domain=$h
|
_domain="$h"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
p=$i
|
i=$(_math $i + 1)
|
||||||
i=$(expr $i + 1)
|
|
||||||
done
|
done
|
||||||
_debug "$domain not found"
|
_debug "$domain not found"
|
||||||
return 1
|
return 1
|
||||||
@ -124,18 +123,18 @@ _pdns_rest() {
|
|||||||
|
|
||||||
_H1="X-API-Key: $PDNS_Token"
|
_H1="X-API-Key: $PDNS_Token"
|
||||||
|
|
||||||
if [ ! "$method" = "GET" ] ; then
|
if [ ! "$method" = "GET" ]; then
|
||||||
_debug data "$data"
|
_debug data "$data"
|
||||||
response="$(_post "$data" "$PDNS_Url$ep" "" "$method")"
|
response="$(_post "$data" "$PDNS_Url$ep" "" "$method")"
|
||||||
else
|
else
|
||||||
response="$(_get "$PDNS_Url$ep")"
|
response="$(_get "$PDNS_Url$ep")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user