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
f3e77a98
Unverified
Commit
f3e77a98
authored
Aug 25, 2022
by
Marvo2011
Committed by
GitHub
Aug 25, 2022
Browse files
Merge branch 'acmesh-official:dev' into dev
parents
f3539b03
238ecfc5
Changes
46
Show whitespace changes
Inline
Side-by-side
dnsapi/dns_regru.sh
View file @
f3e77a98
...
@@ -92,10 +92,10 @@ _get_root() {
...
@@ -92,10 +92,10 @@ _get_root() {
domains_list
=
$(
echo
"
${
response
}
"
|
grep
dname |
sed
-r
"s/.*dname=
\"
([^
\"
]+)
\"
.*/
\\
1/g"
)
domains_list
=
$(
echo
"
${
response
}
"
|
grep
dname |
sed
-r
"s/.*dname=
\"
([^
\"
]+)
\"
.*/
\\
1/g"
)
for
ITEM
in
${
domains_list
}
;
do
for
ITEM
in
${
domains_list
}
;
do
IDN_ITEM
=
"
$(
_idn
"
${
ITEM
}
"
)
"
IDN_ITEM
=
${
ITEM
}
case
"
${
domain
}
"
in
case
"
${
domain
}
"
in
*${
IDN_ITEM
}*
)
*${
IDN_ITEM
}*
)
_domain
=
${
IDN_
ITEM
}
_domain
=
"
$(
_idn
"
${
ITEM
}
"
)
"
_debug _domain
"
${
_domain
}
"
_debug _domain
"
${
_domain
}
"
return
0
return
0
;;
;;
...
...
dnsapi/dns_selectel.sh
View file @
f3e77a98
...
@@ -76,7 +76,7 @@ dns_selectel_rm() {
...
@@ -76,7 +76,7 @@ dns_selectel_rm() {
return
1
return
1
fi
fi
_record_seg
=
"
$(
echo
"
$response
"
| _egrep_o
"
\"
content
\"
*: *
\"
$txtvalue
\"
[^}]*}"
)
"
_record_seg
=
"
$(
echo
"
$response
"
| _egrep_o
"
[^{]*
\"
content
\"
*: *
\"
$txtvalue
\"
[^}]*}"
)
"
_debug2
"_record_seg"
"
$_record_seg
"
_debug2
"_record_seg"
"
$_record_seg
"
if
[
-z
"
$_record_seg
"
]
;
then
if
[
-z
"
$_record_seg
"
]
;
then
_err
"can not find _record_seg"
_err
"can not find _record_seg"
...
@@ -120,7 +120,7 @@ _get_root() {
...
@@ -120,7 +120,7 @@ _get_root() {
return
1
return
1
fi
fi
if
_contains
"
$response
"
"
\"
name
\"
:
\"
$h
\"
,"
;
then
if
_contains
"
$response
"
"
\"
name
\"
*
:
*
\"
$h
\"
,"
;
then
_sub_domain
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
1-
$p
)
_sub_domain
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
1-
$p
)
_domain
=
$h
_domain
=
$h
_debug
"Getting domain id for
$h
"
_debug
"Getting domain id for
$h
"
...
...
dnsapi/dns_ultra.sh
View file @
f3e77a98
...
@@ -5,7 +5,8 @@
...
@@ -5,7 +5,8 @@
#
#
# ULTRA_PWD="some_password_goes_here"
# ULTRA_PWD="some_password_goes_here"
ULTRA_API
=
"https://restapi.ultradns.com/v2/"
ULTRA_API
=
"https://api.ultradns.com/v3/"
ULTRA_AUTH_API
=
"https://api.ultradns.com/v2/"
#Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt"
#Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt"
dns_ultra_add
()
{
dns_ultra_add
()
{
...
@@ -121,7 +122,7 @@ _get_root() {
...
@@ -121,7 +122,7 @@ _get_root() {
return
1
return
1
fi
fi
if
_contains
"
${
response
}
"
"
${
h
}
."
>
/dev/null
;
then
if
_contains
"
${
response
}
"
"
${
h
}
."
>
/dev/null
;
then
_domain_id
=
$(
echo
"
$response
"
| _egrep_o
"
${
h
}
"
)
_domain_id
=
$(
echo
"
$response
"
| _egrep_o
"
${
h
}
"
|
head
-1
)
if
[
"
$_domain_id
"
]
;
then
if
[
"
$_domain_id
"
]
;
then
_sub_domain
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
1-
$p
)
_sub_domain
=
$(
printf
"%s"
"
$domain
"
|
cut
-d
.
-f
1-
$p
)
_domain
=
"
${
h
}
"
_domain
=
"
${
h
}
"
...
@@ -142,23 +143,25 @@ _ultra_rest() {
...
@@ -142,23 +143,25 @@ _ultra_rest() {
ep
=
"
$2
"
ep
=
"
$2
"
data
=
"
$3
"
data
=
"
$3
"
_debug
"
$ep
"
_debug
"
$ep
"
_debug TOKEN
"
${
AUTH_TOKEN
}
"
if
[
-z
"
$AUTH_TOKEN
"
]
;
then
_ultra_login
_ultra_login
fi
_debug TOKEN
"
$AUTH_TOKEN
"
export
_H1
=
"Content-Type: application/json"
export
_H1
=
"Content-Type: application/json"
export
_H2
=
"Authorization: Bearer
$
{
AUTH_TOKEN
}
"
export
_H2
=
"Authorization: Bearer
$AUTH_TOKEN
"
if
[
"
$m
"
!=
"GET"
]
;
then
if
[
"
$m
"
!=
"GET"
]
;
then
_debug data
"
$
{
data
}
"
_debug data
"
$data
"
response
=
"
$(
_post
"
$
{
data
}
"
"
$
{
ULTRA_API
}
"
/
"
${
ep
}
"
""
"
$
{
m
}
"
)
"
response
=
"
$(
_post
"
$data
"
"
$ULTRA_API
$
ep
"
""
"
$
m
"
)
"
else
else
response
=
"
$(
_get
"
$ULTRA_API
/
$ep
"
)
"
response
=
"
$(
_get
"
$ULTRA_API$ep
"
)
"
fi
fi
}
}
_ultra_login
()
{
_ultra_login
()
{
export
_H1
=
""
export
_H1
=
""
export
_H2
=
""
export
_H2
=
""
AUTH_TOKEN
=
$(
_post
"grant_type=password&username=
${
ULTRA_USR
}
&password=
${
ULTRA_PWD
}
"
"
${
ULTRA_API
}
authorization/token"
|
cut
-d
,
-f3
|
cut
-d
\"
-f4
)
AUTH_TOKEN
=
$(
_post
"grant_type=password&username=
${
ULTRA_USR
}
&password=
${
ULTRA_PWD
}
"
"
${
ULTRA_
AUTH_
API
}
authorization/token"
|
cut
-d
,
-f3
|
cut
-d
\"
-f4
)
export
AUTH_TOKEN
export
AUTH_TOKEN
}
}
dnsapi/dns_vultr.sh
View file @
f3e77a98
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
#
#
#VULTR_API_KEY=000011112222333344445555666677778888
#VULTR_API_KEY=000011112222333344445555666677778888
VULTR_Api
=
"https://api.vultr.com/v
1
"
VULTR_Api
=
"https://api.vultr.com/v
2
"
######## Public functions #####################
######## Public functions #####################
#
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_vultr_add
()
{
dns_vultr_add
()
{
fulldomain
=
$1
fulldomain
=
$1
...
@@ -31,14 +31,14 @@ dns_vultr_add() {
...
@@ -31,14 +31,14 @@ dns_vultr_add() {
_debug _domain
"
$_domain
"
_debug _domain
"
$_domain
"
_debug
'Getting txt records'
_debug
'Getting txt records'
_vultr_rest GET
"
dns/records?
domain
=
$_domain
"
_vultr_rest GET
"domain
s/
$_domain
/records
"
if
printf
"%s
\n
"
"
$response
"
|
grep
--
"
\"
type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$fulldomain
\"
"
>
/dev/null
;
then
if
printf
"%s
\n
"
"
$response
"
|
grep
--
"
\"
type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$fulldomain
\"
"
>
/dev/null
;
then
_err
'Error'
_err
'Error'
return
1
return
1
fi
fi
if
!
_vultr_rest POST
'dns/create_record'
"domain
=
$_domain
&name=
$_sub_domain
&
data
=
\"
$txtvalue
\"
&
type
=TXT
"
;
then
if
!
_vultr_rest POST
"domain
s/
$_domain
/records"
"{
\"
name
\"
:
\"
$_sub_domain
\"
,
\"
data
\"
:
\"
$txtvalue
\"
,
\"
type
\"
:
\"
TXT
\"
}
"
;
then
_err
"
$response
"
_err
"
$response
"
return
1
return
1
fi
fi
...
@@ -71,14 +71,14 @@ dns_vultr_rm() {
...
@@ -71,14 +71,14 @@ dns_vultr_rm() {
_debug _domain
"
$_domain
"
_debug _domain
"
$_domain
"
_debug
'Getting txt records'
_debug
'Getting txt records'
_vultr_rest GET
"
dns/records?
domain
=
$_domain
"
_vultr_rest GET
"domain
s/
$_domain
/records
"
if
printf
"%s
\n
"
"
$response
"
|
grep
--
"
\"
type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$fulldomain
\"
"
>
/dev/null
;
then
if
printf
"%s
\n
"
"
$response
"
|
grep
--
"
\"
type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$fulldomain
\"
"
>
/dev/null
;
then
_err
'Error'
_err
'Error'
return
1
return
1
fi
fi
_record_id
=
"
$(
echo
"
$response
"
|
tr
'{}'
'\n'
|
grep
'"TXT"'
|
grep
--
"
$txtvalue
"
|
tr
','
'\n'
|
grep
-i
'
RECORDID
'
|
cut
-d
:
-f
2
)
"
_record_id
=
"
$(
echo
"
$response
"
|
tr
'{}'
'\n'
|
grep
'"TXT"'
|
grep
--
"
$txtvalue
"
|
tr
','
'\n'
|
grep
-i
'
id
'
|
cut
-d
:
-f
2
)
"
_debug _record_id
"
$_record_id
"
_debug _record_id
"
$_record_id
"
if
[
"
$_record_id
"
]
;
then
if
[
"
$_record_id
"
]
;
then
_info
"Successfully retrieved the record id for ACME challenge."
_info
"Successfully retrieved the record id for ACME challenge."
...
@@ -87,7 +87,7 @@ dns_vultr_rm() {
...
@@ -87,7 +87,7 @@ dns_vultr_rm() {
return
0
return
0
fi
fi
if
!
_vultr_rest
POST
'dns/delete_record'
"domain
=
$_domain
&RECORDID=
$_record_id
"
;
then
if
!
_vultr_rest
DELETE
"domain
s/
$_domain
/records/
$_record_id
"
;
then
_err
"
$response
"
_err
"
$response
"
return
1
return
1
fi
fi
...
@@ -112,11 +112,11 @@ _get_root() {
...
@@ -112,11 +112,11 @@ _get_root() {
return
1
return
1
fi
fi
if
!
_vultr_rest GET
"d
ns/list
"
;
then
if
!
_vultr_rest GET
"d
omains
"
;
then
return
1
return
1
fi
fi
if
printf
"%s
\n
"
"
$response
"
|
grep
'^\
[
.*\
]
'
>
/dev/null
;
then
if
printf
"%s
\n
"
"
$response
"
|
grep
'^\
{
.*\
}
'
>
/dev/null
;
then
if
_contains
"
$response
"
"
\"
domain
\"
:
\"
$_domain
\"
"
;
then
if
_contains
"
$response
"
"
\"
domain
\"
:
\"
$_domain
\"
"
;
then
_sub_domain
=
"
$(
echo
"
$fulldomain
"
|
sed
"s/
\\
.
$_domain
\$
//"
)
"
_sub_domain
=
"
$(
echo
"
$fulldomain
"
|
sed
"s/
\\
.
$_domain
\$
//"
)
"
return
0
return
0
...
@@ -141,8 +141,8 @@ _vultr_rest() {
...
@@ -141,8 +141,8 @@ _vultr_rest() {
api_key_trimmed
=
$(
echo
$VULTR_API_KEY
|
tr
-d
'"'
)
api_key_trimmed
=
$(
echo
$VULTR_API_KEY
|
tr
-d
'"'
)
export
_H1
=
"A
pi-Key:
$api_key_trimmed
"
export
_H1
=
"A
uthorization: Bearer
$api_key_trimmed
"
export
_H2
=
'Content-Type: application/
x-www-form-urlencoded
'
export
_H2
=
'Content-Type: application/
json
'
if
[
"
$m
"
!=
"GET"
]
;
then
if
[
"
$m
"
!=
"GET"
]
;
then
_debug data
"
$data
"
_debug data
"
$data
"
...
...
dnsapi/dns_world4you.sh
View file @
f3e77a98
...
@@ -12,7 +12,7 @@ RECORD=''
...
@@ -12,7 +12,7 @@ RECORD=''
# Usage: dns_world4you_add <fqdn> <value>
# Usage: dns_world4you_add <fqdn> <value>
dns_world4you_add
()
{
dns_world4you_add
()
{
fqdn
=
"
$1
"
fqdn
=
$(
echo
"
$1
"
| _lower_case
)
value
=
"
$2
"
value
=
"
$2
"
_info
"Using world4you to add record"
_info
"Using world4you to add record"
_debug fulldomain
"
$fqdn
"
_debug fulldomain
"
$fqdn
"
...
@@ -49,12 +49,12 @@ dns_world4you_add() {
...
@@ -49,12 +49,12 @@ dns_world4you_add() {
ret
=
$(
_post
"
$body
"
"
$WORLD4YOU_API
/
$paketnr
/dns"
''
POST
'application/x-www-form-urlencoded'
)
ret
=
$(
_post
"
$body
"
"
$WORLD4YOU_API
/
$paketnr
/dns"
''
POST
'application/x-www-form-urlencoded'
)
_resethttp
_resethttp
if
_contains
"
$(
_head_n
3
<
"
$HTTP_HEADER
"
)
"
'302'
;
then
if
_contains
"
$(
_head_n
1
<
"
$HTTP_HEADER
"
)
"
'302'
;
then
res
=
$(
_get
"
$WORLD4YOU_API
/
$paketnr
/dns"
)
res
=
$(
_get
"
$WORLD4YOU_API
/
$paketnr
/dns"
)
if
_contains
"
$res
"
"successfully"
;
then
if
_contains
"
$res
"
"successfully"
;
then
return
0
return
0
else
else
msg
=
$(
echo
"
$res
"
|
grep
-A
15
'data-type="danger"'
|
grep
"<h3[^>]*>[^<]"
|
sed
's/<[^>]*>
\|
^\s*//g'
)
msg
=
$(
echo
"
$res
"
|
grep
-A
15
'data-type="danger"'
|
grep
"<h3[^>]*>[^<]"
|
sed
's/<[^>]*>
//g'
|
sed
's/
^\s*//g'
)
if
[
"
$msg
"
=
''
]
;
then
if
[
"
$msg
"
=
''
]
;
then
_err
"Unable to add record: Unknown error"
_err
"Unable to add record: Unknown error"
echo
"
$ret
"
>
'error-01.html'
echo
"
$ret
"
>
'error-01.html'
...
@@ -66,15 +66,15 @@ dns_world4you_add() {
...
@@ -66,15 +66,15 @@ dns_world4you_add() {
return
1
return
1
fi
fi
else
else
_err
"
$(
_head_n 3 <
"
$HTTP_HEADER
"
)
"
msg
=
$(
echo
"
$ret
"
|
grep
'"form-error-message"'
|
sed
's/^.*<div class="form-error-message">\([^<]*\)<\/div>.*$/\1/'
)
_err
"
View
$HTTP_HEADER
for debuggin
g"
_err
"
Unable to add record: my.world4you.com:
$ms
g
"
return
1
return
1
fi
fi
}
}
# Usage: dns_world4you_rm <fqdn> <value>
# Usage: dns_world4you_rm <fqdn> <value>
dns_world4you_rm
()
{
dns_world4you_rm
()
{
fqdn
=
"
$1
"
fqdn
=
$(
echo
"
$1
"
| _lower_case
)
value
=
"
$2
"
value
=
"
$2
"
_info
"Using world4you to remove record"
_info
"Using world4you to remove record"
_debug fulldomain
"
$fqdn
"
_debug fulldomain
"
$fqdn
"
...
@@ -113,12 +113,12 @@ dns_world4you_rm() {
...
@@ -113,12 +113,12 @@ dns_world4you_rm() {
ret
=
$(
_post
"
$body
"
"
$WORLD4YOU_API
/
$paketnr
/dns/record/delete"
''
POST
'application/x-www-form-urlencoded'
)
ret
=
$(
_post
"
$body
"
"
$WORLD4YOU_API
/
$paketnr
/dns/record/delete"
''
POST
'application/x-www-form-urlencoded'
)
_resethttp
_resethttp
if
_contains
"
$(
_head_n
3
<
"
$HTTP_HEADER
"
)
"
'302'
;
then
if
_contains
"
$(
_head_n
1
<
"
$HTTP_HEADER
"
)
"
'302'
;
then
res
=
$(
_get
"
$WORLD4YOU_API
/
$paketnr
/dns"
)
res
=
$(
_get
"
$WORLD4YOU_API
/
$paketnr
/dns"
)
if
_contains
"
$res
"
"successfully"
;
then
if
_contains
"
$res
"
"successfully"
;
then
return
0
return
0
else
else
msg
=
$(
echo
"
$res
"
|
grep
-A
15
'data-type="danger"'
|
grep
"<h3[^>]*>[^<]"
|
sed
's/<[^>]*>
\|
^\s*//g'
)
msg
=
$(
echo
"
$res
"
|
grep
-A
15
'data-type="danger"'
|
grep
"<h3[^>]*>[^<]"
|
sed
's/<[^>]*>
//g'
|
sed
's/
^\s*//g'
)
if
[
"
$msg
"
=
''
]
;
then
if
[
"
$msg
"
=
''
]
;
then
_err
"Unable to remove record: Unknown error"
_err
"Unable to remove record: Unknown error"
echo
"
$ret
"
>
'error-01.html'
echo
"
$ret
"
>
'error-01.html'
...
@@ -130,8 +130,8 @@ dns_world4you_rm() {
...
@@ -130,8 +130,8 @@ dns_world4you_rm() {
return
1
return
1
fi
fi
else
else
_err
"
$(
_head_n 3 <
"
$HTTP_HEADER
"
)
"
msg
=
$(
echo
"
$ret
"
|
grep
"form-error-message"
|
sed
's/^.*<div class="form-error-message">\([^<]*\)<\/div>.*$/\1/'
)
_err
"
View
$HTTP_HEADER
for debuggin
g"
_err
"
Unable to remove record: my.world4you.com:
$ms
g
"
return
1
return
1
fi
fi
}
}
...
@@ -155,29 +155,42 @@ _login() {
...
@@ -155,29 +155,42 @@ _login() {
_saveaccountconf_mutable WORLD4YOU_USERNAME
"
$WORLD4YOU_USERNAME
"
_saveaccountconf_mutable WORLD4YOU_USERNAME
"
$WORLD4YOU_USERNAME
"
_saveaccountconf_mutable WORLD4YOU_PASSWORD
"
$WORLD4YOU_PASSWORD
"
_saveaccountconf_mutable WORLD4YOU_PASSWORD
"
$WORLD4YOU_PASSWORD
"
_resethttp
export
ACME_HTTP_NO_REDIRECTS
=
1
page
=
$(
_get
"
$WORLD4YOU_API
/login"
)
_resethttp
if
_contains
"
$(
_head_n 1 <
"
$HTTP_HEADER
"
)
"
'302'
;
then
_info
"Already logged in"
_parse_sessid
return
0
fi
_info
"Logging in..."
_info
"Logging in..."
username
=
"
$WORLD4YOU_USERNAME
"
username
=
"
$WORLD4YOU_USERNAME
"
password
=
"
$WORLD4YOU_PASSWORD
"
password
=
"
$WORLD4YOU_PASSWORD
"
csrf_token
=
$(
_get
"
$WORLD4YOU_API
/login
"
|
grep
'_csrf_token'
|
sed
's/^.*<input[^>]*value=\"\([^"]*\)\".*$/\1/'
)
csrf_token
=
$(
echo
"
$page
"
|
grep
'_csrf_token'
|
sed
's/^.*<input[^>]*value=\"\([^"]*\)\".*$/\1/'
)
sessid
=
$(
grep
'W4YSESSID'
<
"
$HTTP_HEADER
"
|
sed
's/^.*W4YSESSID=\([^;]*\);.*$/\1/'
)
_parse_sessid
export
_H1
=
"Cookie: W4YSESSID=
$sessid
"
export
_H1
=
"Cookie: W4YSESSID=
$sessid
"
export
_H2
=
"X-Requested-With: XMLHttpRequest"
export
_H2
=
"X-Requested-With: XMLHttpRequest"
body
=
"_username=
$username
&_password=
$password
&_csrf_token=
$csrf_token
"
body
=
"_username=
$username
&_password=
$password
&_csrf_token=
$csrf_token
"
ret
=
$(
_post
"
$body
"
"
$WORLD4YOU_API
/login"
''
POST
'application/x-www-form-urlencoded'
)
ret
=
$(
_post
"
$body
"
"
$WORLD4YOU_API
/login"
''
POST
'application/x-www-form-urlencoded'
)
unset
_H2
unset
_H2
_debug ret
"
$ret
"
_debug ret
"
$ret
"
if
_contains
"
$ret
"
"
\"
success
\"
:true"
;
then
if
_contains
"
$ret
"
"
\"
success
\"
:true"
;
then
_info
"Successfully logged in"
_info
"Successfully logged in"
sessid
=
$(
grep
'W4YSESSID'
<
"
$HTTP_HEADER
"
|
sed
's/^.*W4YSESSID=\([^;]*\);.*$/\1/'
)
_parse_sessid
else
else
_err
"Unable to log in:
$(
echo
"
$ret
"
|
sed
's/^.*"message":"\([^\"]*\)".*$/\1/'
)
"
msg
=
$(
echo
"
$ret
"
|
sed
's/^.*"message":"\([^\"]*\)".*$/\1/'
)
_err
"Unable to log in: my.world4you.com:
$msg
"
return
1
return
1
fi
fi
}
}
# Usage _get_paketnr <fqdn> <form>
# Usage
:
_get_paketnr <fqdn> <form>
_get_paketnr
()
{
_get_paketnr
()
{
fqdn
=
"
$1
"
fqdn
=
"
$1
"
form
=
"
$2
"
form
=
"
$2
"
...
@@ -200,3 +213,8 @@ _get_paketnr() {
...
@@ -200,3 +213,8 @@ _get_paketnr() {
PAKETNR
=
$(
echo
"
$form
"
|
grep
"data-textfilter=
\"
.*
$domain
"
| _tail_n 1 |
sed
"s|.*
$WORLD4YOU_API
/
\\
([0-9]*
\\
)/.*|
\\
1|"
)
PAKETNR
=
$(
echo
"
$form
"
|
grep
"data-textfilter=
\"
.*
$domain
"
| _tail_n 1 |
sed
"s|.*
$WORLD4YOU_API
/
\\
([0-9]*
\\
)/.*|
\\
1|"
)
return
0
return
0
}
}
# Usage: _parse_sessid
_parse_sessid
()
{
sessid
=
$(
grep
'W4YSESSID'
<
"
$HTTP_HEADER
"
| _tail_n 1 |
sed
's/^.*W4YSESSID=\([^;]*\);.*$/\1/'
)
}
notify/slack_app.sh
0 → 100755
View file @
f3e77a98
#!/usr/bin/env sh
#Support Slack APP notifications
#SLACK_APP_CHANNEL=""
#SLACK_APP_TOKEN=""
slack_app_send
()
{
_subject
=
"
$1
"
_content
=
"
$2
"
_statusCode
=
"
$3
"
#0: success, 1: error 2($RENEW_SKIP): skipped
_debug
"_statusCode"
"
$_statusCode
"
SLACK_APP_CHANNEL
=
"
${
SLACK_APP_CHANNEL
:-
$(
_readaccountconf_mutable SLACK_APP_CHANNEL
)
}
"
if
[
-n
"
$SLACK_APP_CHANNEL
"
]
;
then
_saveaccountconf_mutable SLACK_APP_CHANNEL
"
$SLACK_APP_CHANNEL
"
fi
SLACK_APP_TOKEN
=
"
${
SLACK_APP_TOKEN
:-
$(
_readaccountconf_mutable SLACK_APP_TOKEN
)
}
"
if
[
-n
"
$SLACK_APP_TOKEN
"
]
;
then
_saveaccountconf_mutable SLACK_APP_TOKEN
"
$SLACK_APP_TOKEN
"
fi
_content
=
"
$(
printf
"*%s*
\n
%s"
"
$_subject
"
"
$_content
"
| _json_encode
)
"
_data
=
"{
\"
text
\"
:
\"
$_content
\"
, "
if
[
-n
"
$SLACK_APP_CHANNEL
"
]
;
then
_data
=
"
$_data
\"
channel
\"
:
\"
$SLACK_APP_CHANNEL
\"
, "
fi
_data
=
"
$_data
\"
mrkdwn
\"
:
\"
true
\"
}"
export
_H1
=
"Authorization: Bearer
$SLACK_APP_TOKEN
"
SLACK_APP_API_URL
=
"https://slack.com/api/chat.postMessage"
if
_post
"
$_data
"
"
$SLACK_APP_API_URL
"
""
"POST"
"application/json; charset=utf-8"
;
then
# shellcheck disable=SC2154
SLACK_APP_RESULT_OK
=
$(
echo
"
$response
"
| _egrep_o
'ok" *: *true'
)
if
[
"
$?
"
=
"0"
]
&&
[
"
$SLACK_APP_RESULT_OK
"
]
;
then
_info
"slack send success."
return
0
fi
fi
_err
"slack send error."
_err
"
$response
"
return
1
}
Prev
1
2
3
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