Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
e82ea94b
Commit
e82ea94b
authored
Feb 05, 2017
by
nytral
Browse files
Merge remote-tracking branch 'upstream/master'
parents
a9b15f1c
a5025238
Changes
24
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_myapi.sh
View file @
e82ea94b
...
@@ -5,48 +5,31 @@
...
@@ -5,48 +5,31 @@
#So, here must be a method dns_myapi_add()
#So, here must be a method dns_myapi_add()
#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.
#
#Author: Neilpang
#Report Bugs here: https://github.com/Neilpang/acme.sh
#
######## 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"
dns_myapi_add
()
{
dns_myapi_add
()
{
fulldomain
=
$1
fulldomain
=
$1
txtvalue
=
$2
txtvalue
=
$2
_info
"Using myapi"
_debug fulldomain
"
$fulldomain
"
_debug txtvalue
"
$txtvalue
"
_err
"Not implemented!"
_err
"Not implemented!"
return
1
return
1
}
}
#fulldomain
#Usage: fulldomain txtvalue
#Remove the txt record after validation.
dns_myapi_rm
()
{
dns_myapi_rm
()
{
fulldomain
=
$1
fulldomain
=
$1
txtvalue
=
$2
}
_info
"Using myapi"
_debug fulldomain
"
$fulldomain
"
#################### Private functions bellow ##################################
_debug txtvalue
"
$txtvalue
"
_info
()
{
if
[
-z
"
$2
"
]
;
then
echo
"[
$(
date
)
]
$1
"
else
echo
"[
$(
date
)
]
$1
='
$2
'"
fi
}
_err
()
{
_info
"
$@
"
>
&2
return
1
}
_debug
()
{
if
[
-z
"
$DEBUG
"
]
;
then
return
fi
_err
"
$@
"
return
0
}
}
_debug2
()
{
#################### Private functions below ##################################
if
[
"
$DEBUG
"
]
&&
[
"
$DEBUG
"
-ge
"2"
]
;
then
_debug
"
$@
"
fi
return
}
dnsapi/dns_nsupdate.sh
0 → 100755
View file @
e82ea94b
#!/usr/bin/env sh
######## Public functions #####################
#Usage: dns_nsupdate_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_nsupdate_add
()
{
fulldomain
=
$1
txtvalue
=
$2
_checkKeyFile
||
return
1
[
-n
"
${
NSUPDATE_SERVER
}
"
]
||
NSUPDATE_SERVER
=
"localhost"
# save the dns server and key to the account conf file.
_saveaccountconf NSUPDATE_SERVER
"
${
NSUPDATE_SERVER
}
"
_saveaccountconf NSUPDATE_KEY
"
${
NSUPDATE_KEY
}
"
_info
"adding
${
fulldomain
}
. 60 in txt
\"
${
txtvalue
}
\"
"
nsupdate
-k
"
${
NSUPDATE_KEY
}
"
<<
EOF
server
${
NSUPDATE_SERVER
}
update add
${
fulldomain
}
. 60 in txt "
${
txtvalue
}
"
send
EOF
if
[
$?
-ne
0
]
;
then
_err
"error updating domain"
return
1
fi
return
0
}
#Usage: dns_nsupdate_rm _acme-challenge.www.domain.com
dns_nsupdate_rm
()
{
fulldomain
=
$1
_checkKeyFile
||
return
1
[
-n
"
${
NSUPDATE_SERVER
}
"
]
||
NSUPDATE_SERVER
=
"localhost"
_info
"removing
${
fulldomain
}
. txt"
nsupdate
-k
"
${
NSUPDATE_KEY
}
"
<<
EOF
server
${
NSUPDATE_SERVER
}
update delete
${
fulldomain
}
. txt
send
EOF
if
[
$?
-ne
0
]
;
then
_err
"error updating domain"
return
1
fi
return
0
}
#################### Private functions below ##################################
_checkKeyFile
()
{
if
[
-z
"
${
NSUPDATE_KEY
}
"
]
;
then
_err
"you must specify a path to the nsupdate key file"
return
1
fi
if
[
!
-r
"
${
NSUPDATE_KEY
}
"
]
;
then
_err
"key
${
NSUPDATE_KEY
}
is unreadable"
return
1
fi
}
dnsapi/dns_ovh.sh
View file @
e82ea94b
...
@@ -182,7 +182,7 @@ dns_ovh_rm() {
...
@@ -182,7 +182,7 @@ dns_ovh_rm() {
}
}
#################### Private functions bel
l
ow ##################################
#################### Private functions below ##################################
_ovh_authentication
()
{
_ovh_authentication
()
{
...
@@ -273,12 +273,12 @@ _ovh_rest() {
...
@@ -273,12 +273,12 @@ _ovh_rest() {
_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
"
export
_H1
=
"X-Ovh-Application:
$OVH_AK
"
_H2
=
"X-Ovh-Signature:
\$
1
\$
$_ovh_hex
"
export
_H2
=
"X-Ovh-Signature:
\$
1
\$
$_ovh_hex
"
_debug2 _H2
"
$_H2
"
_debug2 _H2
"
$_H2
"
_H3
=
"X-Ovh-Timestamp:
$_ovh_t
"
export
_H3
=
"X-Ovh-Timestamp:
$_ovh_t
"
_H4
=
"X-Ovh-Consumer:
$OVH_CK
"
export
_H4
=
"X-Ovh-Consumer:
$OVH_CK
"
_H5
=
"Content-Type: application/json;charset=utf-8"
export
_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
"
)
"
...
...
dnsapi/dns_pdns.sh
View file @
e82ea94b
...
@@ -12,6 +12,8 @@ DEFAULT_PDNS_TTL=60
...
@@ -12,6 +12,8 @@ DEFAULT_PDNS_TTL=60
######## Public functions #####################
######## Public functions #####################
#Usage: add _acme-challenge.www.domain.com "123456789ABCDEF0000000000000000000000000000000000000"
#Usage: add _acme-challenge.www.domain.com "123456789ABCDEF0000000000000000000000000000000000000"
#fulldomain
#txtvalue
dns_pdns_add
()
{
dns_pdns_add
()
{
fulldomain
=
$1
fulldomain
=
$1
txtvalue
=
$2
txtvalue
=
$2
...
@@ -50,7 +52,7 @@ dns_pdns_add() {
...
@@ -50,7 +52,7 @@ dns_pdns_add() {
_saveaccountconf PDNS_Ttl
"
$PDNS_Ttl
"
_saveaccountconf PDNS_Ttl
"
$PDNS_Ttl
"
fi
fi
_debug
"
First d
etect
the
root zone"
_debug
"
D
etect root zone"
if
!
_get_root
"
$fulldomain
"
;
then
if
!
_get_root
"
$fulldomain
"
;
then
_err
"invalid domain"
_err
"invalid domain"
return
1
return
1
...
@@ -68,6 +70,18 @@ dns_pdns_add() {
...
@@ -68,6 +70,18 @@ dns_pdns_add() {
dns_pdns_rm
()
{
dns_pdns_rm
()
{
fulldomain
=
$1
fulldomain
=
$1
_debug
"Detect root zone"
if
!
_get_root
"
$fulldomain
"
;
then
_err
"invalid domain"
return
1
fi
_debug _domain
"
$_domain
"
if
!
rm_record
"
$_domain
"
"
$fulldomain
"
;
then
return
1
fi
return
0
}
}
set_record
()
{
set_record
()
{
...
@@ -76,18 +90,47 @@ set_record() {
...
@@ -76,18 +90,47 @@ set_record() {
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
\"
: [{
\"
changetype
\"
:
\"
REPLACE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
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
!
notify_slaves
"
$root
"
;
then
return
1
fi
return
0
}
rm_record
()
{
_info
"Remove record"
root
=
$1
full
=
$2
if
!
_pdns_rest
"PATCH"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
."
"{
\"
rrsets
\"
: [{
\"
changetype
\"
:
\"
DELETE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
}]}"
;
then
_err
"Delete txt record error."
return
1
fi
if
!
notify_slaves
"
$root
"
;
then
return
1
fi
return
0
}
notify_slaves
()
{
root
=
$1
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 s
er
ve
r
s error."
_err
"Notify s
la
ves error."
return
1
return
1
fi
fi
return
0
return
0
}
}
#################### Private functions bel
l
ow ##################################
#################### Private functions below ##################################
#_acme-challenge.www.domain.com
#_acme-challenge.www.domain.com
#returns
#returns
# _domain=domain.com
# _domain=domain.com
...
@@ -113,6 +156,7 @@ _get_root() {
...
@@ -113,6 +156,7 @@ _get_root() {
i
=
$(
_math
$i
+ 1
)
i
=
$(
_math
$i
+ 1
)
done
done
_debug
"
$domain
not found"
_debug
"
$domain
not found"
return
1
return
1
}
}
...
@@ -121,7 +165,7 @@ _pdns_rest() {
...
@@ -121,7 +165,7 @@ _pdns_rest() {
ep
=
$2
ep
=
$2
data
=
$3
data
=
$3
_H1
=
"X-API-Key:
$PDNS_Token
"
export
_H1
=
"X-API-Key:
$PDNS_Token
"
if
[
!
"
$method
"
=
"GET"
]
;
then
if
[
!
"
$method
"
=
"GET"
]
;
then
_debug data
"
$data
"
_debug data
"
$data
"
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment