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
3d2df3ba
Unverified
Commit
3d2df3ba
authored
Nov 03, 2019
by
neil
Committed by
GitHub
Nov 03, 2019
Browse files
Merge pull request #2571 from Neilpang/dev
sync
parents
54143ae6
eb623878
Changes
25
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_rcode0.sh
0 → 100755
View file @
3d2df3ba
#!/usr/bin/env sh
#Rcode0 API Integration
#https://my.rcodezero.at/api-doc
#
# log into https://my.rcodezero.at/enableapi and get your ACME API Token (the ACME API token has limited
# access to the REST calls needed for acme.sh only)
#
#RCODE0_URL="https://my.rcodezero.at"
#RCODE0_API_TOKEN="0123456789ABCDEF"
#RCODE0_TTL=60
DEFAULT_RCODE0_URL
=
"https://my.rcodezero.at"
DEFAULT_RCODE0_TTL
=
60
######## Public functions #####################
#Usage: add _acme-challenge.www.domain.com "123456789ABCDEF0000000000000000000000000000000000000"
#fulldomain
#txtvalue
dns_rcode0_add
()
{
fulldomain
=
$1
txtvalue
=
$2
RCODE0_API_TOKEN
=
"
${
RCODE0_API_TOKEN
:-
$(
_readaccountconf_mutable RCODE0_API_TOKEN
)
}
"
RCODE0_URL
=
"
${
RCODE0_URL
:-
$(
_readaccountconf_mutable RCODE0_URL
)
}
"
RCODE0_TTL
=
"
${
RCODE0_TTL
:-
$(
_readaccountconf_mutable RCODE0_TTL
)
}
"
if
[
-z
"
$RCODE0_URL
"
]
;
then
RCODE0_URL
=
"
$DEFAULT_RCODE0_URL
"
fi
if
[
-z
"
$RCODE0_API_TOKEN
"
]
;
then
RCODE0_API_TOKEN
=
""
_err
"Missing Rcode0 ACME API Token."
_err
"Please login and create your token at httsp://my.rcodezero.at/enableapi and try again."
return
1
fi
if
[
-z
"
$RCODE0_TTL
"
]
;
then
RCODE0_TTL
=
"
$DEFAULT_RCODE0_TTL
"
fi
#save the token to the account conf file.
_saveaccountconf_mutable RCODE0_API_TOKEN
"
$RCODE0_API_TOKEN
"
if
[
"
$RCODE0_URL
"
!=
"
$DEFAULT_RCODE0_URL
"
]
;
then
_saveaccountconf_mutable RCODE0_URL
"
$RCODE0_URL
"
fi
if
[
"
$RCODE0_TTL
"
!=
"
$DEFAULT_RCODE0_TTL
"
]
;
then
_saveaccountconf_mutable RCODE0_TTL
"
$RCODE0_TTL
"
fi
_debug
"Detect root zone"
if
!
_get_root
"
$fulldomain
"
;
then
_err
"No 'MASTER' zone for
$fulldomain
found at RcodeZero Anycast."
return
1
fi
_debug _domain
"
$_domain
"
_debug
"Adding record"
_record_string
=
""
_build_record_string
"
$txtvalue
"
_list_existingchallenges
for
oldchallenge
in
$_existing_challenges
;
do
_build_record_string
"
$oldchallenge
"
done
_debug
"Challenges:
$_existing_challenges
"
if
[
-z
"
$_existing_challenges
"
]
;
then
if
!
_rcode0_rest
"PATCH"
"/api/v1/acme/zones/
$_domain
/rrsets"
"[{
\"
changetype
\"
:
\"
add
\"
,
\"
name
\"
:
\"
$fulldomain
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
:
$RCODE0_TTL
,
\"
records
\"
: [
$_record_string
]}]"
;
then
_err
"Add txt record error."
return
1
fi
else
# try update in case a records exists (need for wildcard certs)
if
!
_rcode0_rest
"PATCH"
"/api/v1/acme/zones/
$_domain
/rrsets"
"[{
\"
changetype
\"
:
\"
update
\"
,
\"
name
\"
:
\"
$fulldomain
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
:
$RCODE0_TTL
,
\"
records
\"
: [
$_record_string
]}]"
;
then
_err
"Set txt record error."
return
1
fi
fi
return
0
}
#fulldomain txtvalue
dns_rcode0_rm
()
{
fulldomain
=
$1
txtvalue
=
$2
RCODE0_API_TOKEN
=
"
${
RCODE0_API_TOKEN
:-
$(
_readaccountconf_mutable RCODE0_API_TOKEN
)
}
"
RCODE0_URL
=
"
${
RCODE0_URL
:-
$(
_readaccountconf_mutable RCODE0_URL
)
}
"
RCODE0_TTL
=
"
${
RCODE0_TTL
:-
$(
_readaccountconf_mutable RCODE0_TTL
)
}
"
if
[
-z
"
$RCODE0_URL
"
]
;
then
RCODE0_URL
=
"
$DEFAULT_RCODE0_URL
"
fi
if
[
-z
"
$RCODE0_API_TOKEN
"
]
;
then
RCODE0_API_TOKEN
=
""
_err
"Missing Rcode0 API Token."
_err
"Please login and create your token at httsp://my.rcodezero.at/enableapi and try again."
return
1
fi
#save the api addr and key to the account conf file.
_saveaccountconf_mutable RCODE0_URL
"
$RCODE0_URL
"
_saveaccountconf_mutable RCODE0_API_TOKEN
"
$RCODE0_API_TOKEN
"
if
[
"
$RCODE0_TTL
"
!=
"
$DEFAULT_RCODE0_TTL
"
]
;
then
_saveaccountconf_mutable RCODE0_TTL
"
$RCODE0_TTL
"
fi
if
[
-z
"
$RCODE0_TTL
"
]
;
then
RCODE0_TTL
=
"
$DEFAULT_RCODE0_TTL
"
fi
_debug
"Detect root zone"
if
!
_get_root
"
$fulldomain
"
;
then
_err
"invalid domain"
return
1
fi
_debug
"Remove record"
#Enumerate existing acme challenges
_list_existingchallenges
if
_contains
"
$_existing_challenges
"
"
$txtvalue
"
;
then
#Delete all challenges (PowerDNS API does not allow to delete content)
if
!
_rcode0_rest
"PATCH"
"/api/v1/acme/zones/
$_domain
/rrsets"
"[{
\"
changetype
\"
:
\"
delete
\"
,
\"
name
\"
:
\"
$fulldomain
.
\"
,
\"
type
\"
:
\"
TXT
\"
}]"
;
then
_err
"Delete txt record error."
return
1
fi
_record_string
=
""
#If the only existing challenge was the challenge to delete: nothing to do
if
!
[
"
$_existing_challenges
"
=
"
$txtvalue
"
]
;
then
for
oldchallenge
in
$_existing_challenges
;
do
#Build up the challenges to re-add, ommitting the one what should be deleted
if
!
[
"
$oldchallenge
"
=
"
$txtvalue
"
]
;
then
_build_record_string
"
$oldchallenge
"
fi
done
#Recreate the existing challenges
if
!
_rcode0_rest
"PATCH"
"/api/v1/acme/zones/
$_domain
/rrsets"
"[{
\"
changetype
\"
:
\"
update
\"
,
\"
name
\"
:
\"
$fulldomain
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
:
$RCODE0_TTL
,
\"
records
\"
: [
$_record_string
]}]"
;
then
_err
"Set txt record error."
return
1
fi
fi
else
_info
"Record not found, nothing to remove"
fi
return
0
}
#################### Private functions below ##################################
#_acme-challenge.www.domain.com
#returns
# _domain=domain.com
_get_root
()
{
domain
=
$1
i
=
1
while
true
;
do
h
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
$i
-100
)
_debug
"try to find:
$h
"
if
_rcode0_rest
"GET"
"/api/v1/acme/zones/
$h
"
;
then
if
[
"
$response
"
=
"[
\"
found
\"
]"
]
;
then
_domain
=
"
$h
"
if
[
-z
"
$h
"
]
;
then
_domain
=
"=2E"
fi
return
0
elif
[
"
$response
"
=
"[
\"
not a master domain
\"
]"
]
;
then
return
1
fi
fi
if
[
-z
"
$h
"
]
;
then
return
1
fi
i
=
$(
_math
$i
+ 1
)
done
_debug
"no matching domain for
$domain
found"
return
1
}
_rcode0_rest
()
{
method
=
$1
ep
=
$2
data
=
$3
export
_H1
=
"Authorization: Bearer
$RCODE0_API_TOKEN
"
if
[
!
"
$method
"
=
"GET"
]
;
then
_debug data
"
$data
"
response
=
"
$(
_post
"
$data
"
"
$RCODE0_URL$ep
"
""
"
$method
"
)
"
else
response
=
"
$(
_get
"
$RCODE0_URL$ep
"
)
"
fi
if
[
"
$?
"
!=
"0"
]
;
then
_err
"error
$ep
"
return
1
fi
_debug2 response
"
$response
"
return
0
}
_build_record_string
()
{
_record_string
=
"
${
_record_string
:+
${
_record_string
}
,
}
{
\"
content
\"
:
\"\\\"
${
1
}
\\\"\"
,
\"
disabled
\"
: false}"
}
_list_existingchallenges
()
{
_rcode0_rest
"GET"
"/api/v1/acme/zones/
$_domain
/rrsets"
_existing_challenges
=
$(
echo
"
$response
"
| _normalizeJson | _egrep_o
"
\"
name
\"
:
\"
${
fulldomain
}
[^]]*}"
| _egrep_o
'content\":\"\\"[^\\]*'
|
sed
-n
's/^content":"\\"//p'
)
_debug2
"
$_existing_challenges
"
}
dnsapi/dns_variomedia.sh
0 → 100644
View file @
3d2df3ba
#!/usr/bin/env sh
#
#VARIOMEDIA_API_TOKEN=000011112222333344445555666677778888
VARIOMEDIA_API
=
"https://api.variomedia.de"
######## Public functions #####################
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_variomedia_add
()
{
fulldomain
=
$1
txtvalue
=
$2
_debug fulldomain
"
$fulldomain
"
_debug txtvalue
"
$txtvalue
"
VARIOMEDIA_API_TOKEN
=
"
${
VARIOMEDIA_API_TOKEN
:-
$(
_readaccountconf_mutable VARIOMEDIA_API_TOKEN
)
}
"
if
test
-z
"
$VARIOMEDIA_API_TOKEN
"
;
then
VARIOMEDIA_API_TOKEN
=
""
_err
'VARIOMEDIA_API_TOKEN was not exported'
return
1
fi
_saveaccountconf_mutable VARIOMEDIA_API_TOKEN
"
$VARIOMEDIA_API_TOKEN
"
_debug
'First detect the root zone'
if
!
_get_root
"
$fulldomain
"
;
then
return
1
fi
_debug _sub_domain
"
$_sub_domain
"
_debug _domain
"
$_domain
"
if
!
_variomedia_rest POST
"dns-records"
"{
\"
data
\"
: {
\"
type
\"
:
\"
dns-record
\"
,
\"
attributes
\"
: {
\"
record_type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$_sub_domain
\"
,
\"
domain
\"
:
\"
$_domain
\"
,
\"
data
\"
:
\"
$txtvalue
\"
,
\"
ttl
\"
:300}}}"
;
then
_err
"
$response
"
return
1
fi
_debug2 _response
"
$response
"
return
0
}
#fulldomain txtvalue
dns_variomedia_rm
()
{
fulldomain
=
$1
txtvalue
=
$2
_debug fulldomain
"
$fulldomain
"
_debug txtvalue
"
$txtvalue
"
VARIOMEDIA_API_TOKEN
=
"
${
VARIOMEDIA_API_TOKEN
:-
$(
_readaccountconf_mutable VARIOMEDIA_API_TOKEN
)
}
"
if
test
-z
"
$VARIOMEDIA_API_TOKEN
"
;
then
VARIOMEDIA_API_TOKEN
=
""
_err
'VARIOMEDIA_API_TOKEN was not exported'
return
1
fi
_saveaccountconf_mutable VARIOMEDIA_API_TOKEN
"
$VARIOMEDIA_API_TOKEN
"
_debug
'First detect the root zone'
if
!
_get_root
"
$fulldomain
"
;
then
return
1
fi
_debug _sub_domain
"
$_sub_domain
"
_debug _domain
"
$_domain
"
_debug
'Getting txt records'
if
!
_variomedia_rest GET
"dns-records?filter[domain]=
$_domain
"
;
then
_err
'Error'
return
1
fi
_record_id
=
"
$(
echo
"
$response
"
|
cut
-d
'['
-f2
|
cut
-d
']'
-f1
|
sed
's/},[ \t]*{/\},§\{/g'
|
tr
§
'\n'
|
grep
"
$_sub_domain
"
|
grep
"
$txtvalue
"
|
sed
's/^{//;s/}[,]?$//'
|
tr
,
'\n'
|
tr
-d
'\"'
|
grep
^id |
cut
-d
:
-f2
|
tr
-d
' '
)
"
_debug _record_id
"
$_record_id
"
if
[
"
$_record_id
"
]
;
then
_info
"Successfully retrieved the record id for ACME challenge."
else
_info
"Empty record id, it seems no such record."
return
0
fi
if
!
_variomedia_rest DELETE
"/dns-records/
$_record_id
"
;
then
_err
"
$response
"
return
1
fi
_debug2 _response
"
$response
"
return
0
}
#################### Private functions below ##################################
#_acme-challenge.www.domain.com
#returns
# _sub_domain=_acme-challenge.www
# _domain=domain.com
_get_root
()
{
fulldomain
=
$1
i
=
1
while
true
;
do
h
=
$(
printf
"%s"
"
$fulldomain
"
|
cut
-d
.
-f
$i
-100
)
_debug h
"
$h
"
if
[
-z
"
$h
"
]
;
then
return
1
fi
if
!
_variomedia_rest GET
"domains/
$h
"
;
then
return
1
fi
if
_startswith
"
$response
"
"
\{\"
data
\"
:"
;
then
if
_contains
"
$response
"
"
\"
id
\"
:
\"
$h
\"
"
;
then
_sub_domain
=
"
$(
echo
"
$fulldomain
"
|
sed
"s/
\\
.
$h
\$
//"
)
"
_domain
=
$h
return
0
fi
fi
i
=
$(
_math
"
$i
"
+ 1
)
done
_debug
"root domain not found"
return
1
}
_variomedia_rest
()
{
m
=
$1
ep
=
"
$2
"
data
=
"
$3
"
_debug
"
$ep
"
export
_H1
=
"Authorization: token
$VARIOMEDIA_API_TOKEN
"
export
_H2
=
"Content-Type: application/vnd.api+json"
export
_H3
=
"Accept: application/vnd.variomedia.v1+json"
if
[
"
$m
"
!=
"GET"
]
;
then
_debug data
"
$data
"
response
=
"
$(
_post
"
$data
"
"
$VARIOMEDIA_API
/
$ep
"
""
"
$m
"
)
"
else
response
=
"
$(
_get
"
$VARIOMEDIA_API
/
$ep
"
)
"
fi
if
[
"
$?
"
!=
"0"
]
;
then
_err
"Error
$ep
"
return
1
fi
_debug2 response
"
$response
"
return
0
}
dnsapi/dns_vscale.sh
View file @
3d2df3ba
...
...
@@ -102,7 +102,7 @@ _get_root() {
return
1
fi
hostedzone
=
"
$(
echo
"
$response
"
| _egrep_o
"
{.*
\"
name
\"
:
\s
*
\"
$h
\"
.*}"
)
"
hostedzone
=
"
$(
echo
"
$response
"
|
tr
"{"
"
\n
"
|
_egrep_o
"
\"
name
\"
:
\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
...
...
dnsapi/dns_vultr.sh
View file @
3d2df3ba
...
...
@@ -106,9 +106,9 @@ _get_root() {
domain
=
$1
i
=
1
while
true
;
do
h
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
$i
-100
)
_debug h
"
$
h
"
if
[
-z
"
$
h
"
]
;
then
_domain
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
$i
-100
)
_debug h
"
$
_domain
"
if
[
-z
"
$
_domain
"
]
;
then
return
1
fi
...
...
@@ -119,11 +119,9 @@ _get_root() {
if
printf
"%s
\n
"
"
$response
"
|
grep
'^\[.*\]'
>
/dev/null
;
then
if
_contains
"
$response
"
"
\"
domain
\"
:
\"
$_domain
\"
"
;
then
_sub_domain
=
"
$(
echo
"
$fulldomain
"
|
sed
"s/
\\
.
$_domain
\$
//"
)
"
_domain
=
$_domain
return
0
else
_err
'Invalid domain'
return
1
_debug
"Go to next level of
$_domain
"
fi
else
_err
"
$response
"
...
...
notify/dingtalk.sh
0 → 100644
View file @
3d2df3ba
#!/usr/bin/env sh
#Support dingtalk webhooks api
#DINGTALK_WEBHOOK="xxxx"
#optional
#DINGTALK_KEYWORD="yyyy"
#DINGTALK_SIGNING_KEY="SEC08ffdbd403cbc3fc8a65xxxxxxxxxxxxxxxxxxxx"
# subject content statusCode
dingtalk_send
()
{
_subject
=
"
$1
"
_content
=
"
$2
"
_statusCode
=
"
$3
"
#0: success, 1: error 2($RENEW_SKIP): skipped
_debug
"_subject"
"
$_subject
"
_debug
"_content"
"
$_content
"
_debug
"_statusCode"
"
$_statusCode
"
DINGTALK_WEBHOOK
=
"
${
DINGTALK_WEBHOOK
:-
$(
_readaccountconf_mutable DINGTALK_WEBHOOK
)
}
"
if
[
-z
"
$DINGTALK_WEBHOOK
"
]
;
then
DINGTALK_WEBHOOK
=
""
_err
"You didn't specify a dingtalk webhooks DINGTALK_WEBHOOK yet."
_err
"You can get yours from https://dingtalk.com"
return
1
fi
_saveaccountconf_mutable DINGTALK_WEBHOOK
"
$DINGTALK_WEBHOOK
"
DINGTALK_KEYWORD
=
"
${
DINGTALK_KEYWORD
:-
$(
_readaccountconf_mutable DINGTALK_KEYWORD
)
}
"
if
[
"
$DINGTALK_KEYWORD
"
]
;
then
_saveaccountconf_mutable DINGTALK_KEYWORD
"
$DINGTALK_KEYWORD
"
fi
# DINGTALK_SIGNING_KEY="${DINGTALK_SIGNING_KEY:-$(_readaccountconf_mutable DINGTALK_SIGNING_KEY)}"
# if [ -z "$DINGTALK_SIGNING_KEY" ]; then
# DINGTALK_SIGNING_KEY="value1"
# _info "The DINGTALK_SIGNING_KEY is not set, so use the default value1 as key."
# elif ! _hasfield "$_IFTTT_AVAIL_MSG_KEYS" "$DINGTALK_SIGNING_KEY"; then
# _err "The DINGTALK_SIGNING_KEY \"$DINGTALK_SIGNING_KEY\" is not available, should be one of $_IFTTT_AVAIL_MSG_KEYS"
# DINGTALK_SIGNING_KEY=""
# return 1
# else
# _saveaccountconf_mutable DINGTALK_SIGNING_KEY "$DINGTALK_SIGNING_KEY"
# fi
# if [ "$DINGTALK_SIGNING_KEY" = "$IFTTT_CONTENT_KEY" ]; then
# DINGTALK_SIGNING_KEY=""
# IFTTT_CONTENT_KEY=""
# _err "The DINGTALK_SIGNING_KEY must not be same as IFTTT_CONTENT_KEY."
# return 1
# fi
_content
=
$(
echo
"
$_content
"
| _json_encode
)
_subject
=
$(
echo
"
$_subject
"
| _json_encode
)
_data
=
"{
\"
msgtype
\"
:
\"
text
\"
,
\"
text
\"
: {
\"
content
\"
:
\"
[
$DINGTALK_KEYWORD
]
\n
$_subject
\n
$_content
\"
}}"
response
=
"
$(
_post
"
$_data
"
"
$DINGTALK_WEBHOOK
"
""
"POST"
"application/json"
)
"
if
[
"
$?
"
=
"0"
]
&&
_contains
"
$response
"
"errmsg
\"
:
\"
ok"
;
then
_info
"dingtalk webhooks event fired success."
return
0
fi
_err
"dingtalk webhooks event fired error."
_err
"
$response
"
return
1
}
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