neil
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 721 additions and 56 deletions
-
12acme.sh
-
52deploy/routeros.sh
-
5deploy/synology_dsm.sh
-
6dnsapi/dns_cf.sh
-
159dnsapi/dns_curanet.sh
-
221dnsapi/dns_geoscaling.sh
-
2dnsapi/dns_ispconfig.sh
-
48dnsapi/dns_loopia.sh
-
3dnsapi/dns_opnsense.sh
-
160dnsapi/dns_udr.sh
-
6dnsapi/dns_world4you.sh
-
49notify/weixin_work.sh
@ -0,0 +1,159 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
#Script to use with curanet.dk, scannet.dk, wannafind.dk, dandomain.dk DNS management. |
|||
#Requires api credentials with scope: dns |
|||
#Author: Peter L. Hansen <peter@r12.dk> |
|||
#Version 1.0 |
|||
|
|||
CURANET_REST_URL="https://api.curanet.dk/dns/v1/Domains" |
|||
CURANET_AUTH_URL="https://apiauth.dk.team.blue/auth/realms/Curanet/protocol/openid-connect/token" |
|||
CURANET_ACCESS_TOKEN="" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: dns_curanet_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_curanet_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
_info "Using curanet" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
CURANET_AUTHCLIENTID="${CURANET_AUTHCLIENTID:-$(_readaccountconf_mutable CURANET_AUTHCLIENTID)}" |
|||
CURANET_AUTHSECRET="${CURANET_AUTHSECRET:-$(_readaccountconf_mutable CURANET_AUTHSECRET)}" |
|||
if [ -z "$CURANET_AUTHCLIENTID" ] || [ -z "$CURANET_AUTHSECRET" ]; then |
|||
CURANET_AUTHCLIENTID="" |
|||
CURANET_AUTHSECRET="" |
|||
_err "You don't specify curanet api client and secret." |
|||
_err "Please create your auth info and try again." |
|||
return 1 |
|||
fi |
|||
|
|||
#save the credentials to the account conf file. |
|||
_saveaccountconf_mutable CURANET_AUTHCLIENTID "$CURANET_AUTHCLIENTID" |
|||
_saveaccountconf_mutable CURANET_AUTHSECRET "$CURANET_AUTHSECRET" |
|||
|
|||
if ! _get_token; then |
|||
_err "Unable to get token" |
|||
return 1 |
|||
fi |
|||
|
|||
if ! _get_root "$fulldomain"; then |
|||
_err "Invalid domain" |
|||
return 1 |
|||
fi |
|||
|
|||
export _H1="Content-Type: application/json-patch+json" |
|||
export _H2="Accept: application/json" |
|||
export _H3="Authorization: Bearer $CURANET_ACCESS_TOKEN" |
|||
data="{\"name\": \"$fulldomain\",\"type\": \"TXT\",\"ttl\": 60,\"priority\": 0,\"data\": \"$txtvalue\"}" |
|||
response="$(_post "$data" "$CURANET_REST_URL/${_domain}/Records" "" "")" |
|||
|
|||
if _contains "$response" "$txtvalue"; then |
|||
_debug "TXT record added OK" |
|||
else |
|||
_err "Unable to add TXT record" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
#Usage: fulldomain txtvalue |
|||
#Remove the txt record after validation. |
|||
dns_curanet_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
_info "Using curanet" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
CURANET_AUTHCLIENTID="${CURANET_AUTHCLIENTID:-$(_readaccountconf_mutable CURANET_AUTHCLIENTID)}" |
|||
CURANET_AUTHSECRET="${CURANET_AUTHSECRET:-$(_readaccountconf_mutable CURANET_AUTHSECRET)}" |
|||
|
|||
if ! _get_token; then |
|||
_err "Unable to get token" |
|||
return 1 |
|||
fi |
|||
|
|||
if ! _get_root "$fulldomain"; then |
|||
_err "Invalid domain" |
|||
return 1 |
|||
fi |
|||
|
|||
_debug "Getting current record list to identify TXT to delete" |
|||
|
|||
export _H1="Content-Type: application/json" |
|||
export _H2="Accept: application/json" |
|||
export _H3="Authorization: Bearer $CURANET_ACCESS_TOKEN" |
|||
|
|||
response="$(_get "$CURANET_REST_URL/${_domain}/Records" "" "")" |
|||
|
|||
if ! _contains "$response" "$txtvalue"; then |
|||
_err "Unable to delete record (does not contain $txtvalue )" |
|||
return 1 |
|||
fi |
|||
|
|||
recordid=$(echo "$response" | _egrep_o "{\"id\":[0-9]+,\"name\":\"$fulldomain\",\"type\":\"TXT\",\"ttl\":60,\"priority\":0,\"data\":\"..$txtvalue" | _egrep_o "id\":[0-9]+" | cut -c 5-) |
|||
|
|||
if [ -z "$recordid" ]; then |
|||
_err "Unable to get recordid" |
|||
_debug "regex {\"id\":[0-9]+,\"name\":\"$fulldomain\",\"type\":\"TXT\",\"ttl\":60,\"priority\":0,\"data\":\"..$txtvalue" |
|||
_debug "response $response" |
|||
return 1 |
|||
fi |
|||
|
|||
_debug "Deleting recordID $recordid" |
|||
response="$(_post "" "$CURANET_REST_URL/${_domain}/Records/$recordid" "" "DELETE")" |
|||
return 0 |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
_get_token() { |
|||
response="$(_post "grant_type=client_credentials&client_id=$CURANET_AUTHCLIENTID&client_secret=$CURANET_AUTHSECRET&scope=dns" "$CURANET_AUTH_URL" "" "")" |
|||
if ! _contains "$response" "access_token"; then |
|||
_err "Unable get access token" |
|||
return 1 |
|||
fi |
|||
CURANET_ACCESS_TOKEN=$(echo "$response" | _egrep_o "\"access_token\":\"[^\"]+" | cut -c 17-) |
|||
|
|||
if [ -z "$CURANET_ACCESS_TOKEN" ]; then |
|||
_err "Unable to get token" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
|
|||
} |
|||
|
|||
#_acme-challenge.www.domain.com |
|||
#returns |
|||
# _domain=domain.com |
|||
# _domain_id=sdjkglgdfewsdfg |
|||
_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 |
|||
#not valid |
|||
return 1 |
|||
fi |
|||
|
|||
export _H1="Content-Type: application/json" |
|||
export _H2="Accept: application/json" |
|||
export _H3="Authorization: Bearer $CURANET_ACCESS_TOKEN" |
|||
response="$(_get "$CURANET_REST_URL/$h/Records" "" "")" |
|||
|
|||
if [ ! "$(echo "$response" | _egrep_o "Entity not found")" ]; then |
|||
_domain=$h |
|||
return 0 |
|||
fi |
|||
|
|||
i=$(_math "$i" + 1) |
|||
done |
|||
return 1 |
|||
} |
@ -0,0 +1,221 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
######################################################################## |
|||
# Geoscaling hook script for acme.sh |
|||
# |
|||
# Environment variables: |
|||
# |
|||
# - $GEOSCALING_Username (your Geoscaling username - this is usually NOT an amail address) |
|||
# - $GEOSCALING_Password (your Geoscaling password) |
|||
|
|||
#-- dns_geoscaling_add() - Add TXT record -------------------------------------- |
|||
# Usage: dns_geoscaling_add _acme-challenge.subdomain.domain.com "XyZ123..." |
|||
|
|||
dns_geoscaling_add() { |
|||
full_domain=$1 |
|||
txt_value=$2 |
|||
_info "Using DNS-01 Geoscaling DNS2 hook" |
|||
|
|||
GEOSCALING_Username="${GEOSCALING_Username:-$(_readaccountconf_mutable GEOSCALING_Username)}" |
|||
GEOSCALING_Password="${GEOSCALING_Password:-$(_readaccountconf_mutable GEOSCALING_Password)}" |
|||
if [ -z "$GEOSCALING_Username" ] || [ -z "$GEOSCALING_Password" ]; then |
|||
GEOSCALING_Username= |
|||
GEOSCALING_Password= |
|||
_err "No auth details provided. Please set user credentials using the \$GEOSCALING_Username and \$GEOSCALING_Password environment variables." |
|||
return 1 |
|||
fi |
|||
_saveaccountconf_mutable GEOSCALING_Username "${GEOSCALING_Username}" |
|||
_saveaccountconf_mutable GEOSCALING_Password "${GEOSCALING_Password}" |
|||
|
|||
# Fills in the $zone_id and $zone_name |
|||
find_zone "${full_domain}" || return 1 |
|||
_debug "Zone id '${zone_id}' will be used." |
|||
|
|||
# We're logged in here |
|||
|
|||
# we should add ${full_domain} minus the trailing ${zone_name} |
|||
|
|||
prefix=$(echo "${full_domain}" | sed "s|\\.${zone_name}\$||") |
|||
|
|||
body="id=${zone_id}&name=${prefix}&type=TXT&content=${txt_value}&ttl=300&prio=0" |
|||
|
|||
do_post "$body" "https://www.geoscaling.com/dns2/ajax/add_record.php" |
|||
exit_code="$?" |
|||
if [ "${exit_code}" -eq 0 ]; then |
|||
_info "TXT record added successfully." |
|||
else |
|||
_err "Couldn't add the TXT record." |
|||
fi |
|||
do_logout |
|||
return "${exit_code}" |
|||
} |
|||
|
|||
#-- dns_geoscaling_rm() - Remove TXT record ------------------------------------ |
|||
# Usage: dns_geoscaling_rm _acme-challenge.subdomain.domain.com "XyZ123..." |
|||
|
|||
dns_geoscaling_rm() { |
|||
full_domain=$1 |
|||
txt_value=$2 |
|||
_info "Cleaning up after DNS-01 Geoscaling DNS2 hook" |
|||
|
|||
# fills in the $zone_id |
|||
find_zone "${full_domain}" || return 1 |
|||
_debug "Zone id '${zone_id}' will be used." |
|||
|
|||
# Here we're logged in |
|||
# Find the record id to clean |
|||
|
|||
# get the domain |
|||
response=$(do_get "https://www.geoscaling.com/dns2/index.php?module=domain&id=${zone_id}") |
|||
_debug2 "response" "$response" |
|||
|
|||
table="$(echo "${response}" | tr -d '\n' | sed 's|.*<div class="box"><div class="boxtitle">Basic Records</div><div class="boxtext"><table|<table|; s|</table>.*|</table>|')" |
|||
_debug2 table "${table}" |
|||
names=$(echo "${table}" | _egrep_o 'id="[0-9]+\.name">[^<]*</td>' | sed 's|</td>||; s|.*>||') |
|||
ids=$(echo "${table}" | _egrep_o 'id="[0-9]+\.name">[^<]*</td>' | sed 's|\.name">.*||; s|id="||') |
|||
types=$(echo "${table}" | _egrep_o 'id="[0-9]+\.type">[^<]*</td>' | sed 's|</td>||; s|.*>||') |
|||
values=$(echo "${table}" | _egrep_o 'id="[0-9]+\.content">[^<]*</td>' | sed 's|</td>||; s|.*>||') |
|||
|
|||
_debug2 names "${names}" |
|||
_debug2 ids "${ids}" |
|||
_debug2 types "${types}" |
|||
_debug2 values "${values}" |
|||
|
|||
# look for line whose name is ${full_domain}, whose type is TXT, and whose value is ${txt_value} |
|||
line_num="$(echo "${values}" | grep -F -n -- "${txt_value}" | _head_n 1 | cut -d ':' -f 1)" |
|||
_debug2 line_num "${line_num}" |
|||
found_id= |
|||
if [ -n "$line_num" ]; then |
|||
type=$(echo "${types}" | sed -n "${line_num}p") |
|||
name=$(echo "${names}" | sed -n "${line_num}p") |
|||
id=$(echo "${ids}" | sed -n "${line_num}p") |
|||
|
|||
_debug2 type "$type" |
|||
_debug2 name "$name" |
|||
_debug2 id "$id" |
|||
_debug2 full_domain "$full_domain" |
|||
|
|||
if [ "${type}" = "TXT" ] && [ "${name}" = "${full_domain}" ]; then |
|||
found_id=${id} |
|||
fi |
|||
fi |
|||
|
|||
if [ "${found_id}" = "" ]; then |
|||
_err "Can not find record id." |
|||
return 0 |
|||
fi |
|||
|
|||
# Remove the record |
|||
body="id=${zone_id}&record_id=${found_id}" |
|||
response=$(do_post "$body" "https://www.geoscaling.com/dns2/ajax/delete_record.php") |
|||
exit_code="$?" |
|||
if [ "$exit_code" -eq 0 ]; then |
|||
_info "Record removed successfully." |
|||
else |
|||
_err "Could not clean (remove) up the record. Please go to Geoscaling administration interface and clean it by hand." |
|||
fi |
|||
do_logout |
|||
return "${exit_code}" |
|||
} |
|||
|
|||
########################## PRIVATE FUNCTIONS ########################### |
|||
|
|||
do_get() { |
|||
_url=$1 |
|||
export _H1="Cookie: $geoscaling_phpsessid_cookie" |
|||
_get "${_url}" |
|||
} |
|||
|
|||
do_post() { |
|||
_body=$1 |
|||
_url=$2 |
|||
export _H1="Cookie: $geoscaling_phpsessid_cookie" |
|||
_post "${_body}" "${_url}" |
|||
} |
|||
|
|||
do_login() { |
|||
|
|||
_info "Logging in..." |
|||
|
|||
username_encoded="$(printf "%s" "${GEOSCALING_Username}" | _url_encode)" |
|||
password_encoded="$(printf "%s" "${GEOSCALING_Password}" | _url_encode)" |
|||
body="username=${username_encoded}&password=${password_encoded}" |
|||
|
|||
response=$(_post "$body" "https://www.geoscaling.com/dns2/index.php?module=auth") |
|||
_debug2 response "${response}" |
|||
|
|||
#retcode=$(grep '^HTTP[^ ]*' "${HTTP_HEADER}" | _head_n 1 | _egrep_o '[0-9]+$') |
|||
retcode=$(grep '^HTTP[^ ]*' "${HTTP_HEADER}" | _head_n 1 | cut -d ' ' -f 2) |
|||
|
|||
if [ "$retcode" != "302" ]; then |
|||
_err "Geoscaling login failed for user ${GEOSCALING_Username}. Check ${HTTP_HEADER} file" |
|||
return 1 |
|||
fi |
|||
|
|||
geoscaling_phpsessid_cookie="$(grep -i '^set-cookie:' "${HTTP_HEADER}" | _egrep_o 'PHPSESSID=[^;]*;' | tr -d ';')" |
|||
return 0 |
|||
|
|||
} |
|||
|
|||
do_logout() { |
|||
_info "Logging out." |
|||
response="$(do_get "https://www.geoscaling.com/dns2/index.php?module=auth")" |
|||
_debug2 response "$response" |
|||
return 0 |
|||
} |
|||
|
|||
find_zone() { |
|||
domain="$1" |
|||
|
|||
# do login |
|||
do_login || return 1 |
|||
|
|||
# get zones |
|||
response="$(do_get "https://www.geoscaling.com/dns2/index.php?module=domains")" |
|||
|
|||
table="$(echo "${response}" | tr -d '\n' | sed 's|.*<div class="box"><div class="boxtitle">Your domains</div><div class="boxtext"><table|<table|; s|</table>.*|</table>|')" |
|||
_debug2 table "${table}" |
|||
zone_names="$(echo "${table}" | _egrep_o '<b>[^<]*</b>' | sed 's|<b>||;s|</b>||')" |
|||
_debug2 _matches "${zone_names}" |
|||
# Zone names and zone IDs are in same order |
|||
zone_ids=$(echo "${table}" | _egrep_o '<a href=.index\.php\?module=domain&id=[0-9]+. onclick="javascript:show_loader\(\);">' | sed 's|.*id=||;s|. .*||') |
|||
|
|||
_debug2 "These are the zones on this Geoscaling account:" |
|||
_debug2 "zone_names" "${zone_names}" |
|||
_debug2 "And these are their respective IDs:" |
|||
_debug2 "zone_ids" "${zone_ids}" |
|||
if [ -z "${zone_names}" ] || [ -z "${zone_ids}" ]; then |
|||
_err "Can not get zone names or IDs." |
|||
return 1 |
|||
fi |
|||
# Walk through all possible zone names |
|||
strip_counter=1 |
|||
while true; do |
|||
attempted_zone=$(echo "${domain}" | cut -d . -f ${strip_counter}-) |
|||
|
|||
# All possible zone names have been tried |
|||
if [ -z "${attempted_zone}" ]; then |
|||
_err "No zone for domain '${domain}' found." |
|||
return 1 |
|||
fi |
|||
|
|||
_debug "Looking for zone '${attempted_zone}'" |
|||
|
|||
line_num="$(echo "${zone_names}" | grep -n "^${attempted_zone}\$" | _head_n 1 | cut -d : -f 1)" |
|||
_debug2 line_num "${line_num}" |
|||
if [ "$line_num" ]; then |
|||
zone_id=$(echo "${zone_ids}" | sed -n "${line_num}p") |
|||
zone_name=$(echo "${zone_names}" | sed -n "${line_num}p") |
|||
if [ -z "${zone_id}" ]; then |
|||
_err "Can not find zone id." |
|||
return 1 |
|||
fi |
|||
_debug "Found relevant zone '${attempted_zone}' with id '${zone_id}' - will be used for domain '${domain}'." |
|||
return 0 |
|||
fi |
|||
|
|||
_debug "Zone '${attempted_zone}' doesn't exist, let's try a less specific zone." |
|||
strip_counter=$(_math "${strip_counter}" + 1) |
|||
done |
|||
} |
|||
# vim: et:ts=2:sw=2: |
@ -0,0 +1,160 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
# united-domains Reselling (https://www.ud-reselling.com/) DNS API |
|||
# Author: Andreas Scherer (https://github.com/andischerer) |
|||
# Created: 2021-02-01 |
|||
# |
|||
# Set the environment variables as below: |
|||
# |
|||
# export UDR_USER="your_username_goes_here" |
|||
# export UDR_PASS="some_password_goes_here" |
|||
# |
|||
|
|||
UDR_API="https://api.domainreselling.de/api/call.cgi" |
|||
UDR_TTL="30" |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt" |
|||
dns_udr_add() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
UDR_USER="${UDR_USER:-$(_readaccountconf_mutable UDR_USER)}" |
|||
UDR_PASS="${UDR_PASS:-$(_readaccountconf_mutable UDR_PASS)}" |
|||
if [ -z "$UDR_USER" ] || [ -z "$UDR_PASS" ]; then |
|||
UDR_USER="" |
|||
UDR_PASS="" |
|||
_err "You didn't specify an UD-Reselling username and password yet" |
|||
return 1 |
|||
fi |
|||
# save the username and password to the account conf file. |
|||
_saveaccountconf_mutable UDR_USER "$UDR_USER" |
|||
_saveaccountconf_mutable UDR_PASS "$UDR_PASS" |
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
|
|||
_debug _dnszone "${_dnszone}" |
|||
|
|||
_debug "Getting txt records" |
|||
if ! _udr_rest "QueryDNSZoneRRList" "dnszone=${_dnszone}"; then |
|||
return 1 |
|||
fi |
|||
|
|||
rr="${fulldomain}. ${UDR_TTL} IN TXT ${txtvalue}" |
|||
_debug resource_record "${rr}" |
|||
if _contains "$response" "$rr" >/dev/null; then |
|||
_err "Error, it would appear that this record already exists. Please review existing TXT records for this domain." |
|||
return 1 |
|||
fi |
|||
|
|||
_info "Adding record" |
|||
if ! _udr_rest "UpdateDNSZone" "dnszone=${_dnszone}&addrr0=${rr}"; then |
|||
_err "Adding the record did not succeed, please verify/check." |
|||
return 1 |
|||
fi |
|||
|
|||
_info "Added, OK" |
|||
return 0 |
|||
} |
|||
|
|||
dns_udr_rm() { |
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
|
|||
UDR_USER="${UDR_USER:-$(_readaccountconf_mutable UDR_USER)}" |
|||
UDR_PASS="${UDR_PASS:-$(_readaccountconf_mutable UDR_PASS)}" |
|||
if [ -z "$UDR_USER" ] || [ -z "$UDR_PASS" ]; then |
|||
UDR_USER="" |
|||
UDR_PASS="" |
|||
_err "You didn't specify an UD-Reselling username and password yet" |
|||
return 1 |
|||
fi |
|||
|
|||
_debug "First detect the root zone" |
|||
if ! _get_root "$fulldomain"; then |
|||
_err "invalid domain" |
|||
return 1 |
|||
fi |
|||
_debug _dnszone "${_dnszone}" |
|||
|
|||
_debug "Getting txt records" |
|||
if ! _udr_rest "QueryDNSZoneRRList" "dnszone=${_dnszone}"; then |
|||
return 1 |
|||
fi |
|||
|
|||
rr="${fulldomain}. ${UDR_TTL} IN TXT ${txtvalue}" |
|||
_debug resource_record "${rr}" |
|||
if _contains "$response" "$rr" >/dev/null; then |
|||
if ! _udr_rest "UpdateDNSZone" "dnszone=${_dnszone}&delrr0=${rr}"; then |
|||
_err "Deleting the record did not succeed, please verify/check." |
|||
return 1 |
|||
fi |
|||
_info "Removed, OK" |
|||
return 0 |
|||
else |
|||
_info "Text record is not present, will not delete anything." |
|||
return 0 |
|||
fi |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
#_acme-challenge.www.domain.com |
|||
#returns |
|||
# _sub_domain=_acme-challenge.www |
|||
# _domain=domain.com |
|||
_get_root() { |
|||
domain=$1 |
|||
i=1 |
|||
|
|||
if ! _udr_rest "QueryDNSZoneList" ""; then |
|||
return 1 |
|||
fi |
|||
|
|||
while true; do |
|||
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
|||
_debug h "$h" |
|||
|
|||
if [ -z "$h" ]; then |
|||
#not valid |
|||
return 1 |
|||
fi |
|||
|
|||
if _contains "${response}" "${h}." >/dev/null; then |
|||
_dnszone=$(echo "$response" | _egrep_o "${h}") |
|||
if [ "$_dnszone" ]; then |
|||
return 0 |
|||
fi |
|||
return 1 |
|||
fi |
|||
i=$(_math "$i" + 1) |
|||
done |
|||
return 1 |
|||
} |
|||
|
|||
_udr_rest() { |
|||
if [ -n "$2" ]; then |
|||
data="command=$1&$2" |
|||
else |
|||
data="command=$1" |
|||
fi |
|||
|
|||
_debug data "${data}" |
|||
response="$(_post "${data}" "${UDR_API}?s_login=${UDR_USER}&s_pw=${UDR_PASS}" "" "POST")" |
|||
|
|||
_code=$(echo "$response" | _egrep_o "code = ([0-9]+)" | _head_n 1 | cut -d = -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') |
|||
_description=$(echo "$response" | _egrep_o "description = .*" | _head_n 1 | cut -d = -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') |
|||
|
|||
_debug response_code "$_code" |
|||
_debug response_description "$_description" |
|||
|
|||
if [ ! "$_code" = "200" ]; then |
|||
_err "DNS-API-Error: $_description" |
|||
return 1 |
|||
fi |
|||
|
|||
return 0 |
|||
} |
@ -0,0 +1,49 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
#Support weixin work webhooks api |
|||
|
|||
#WEIXIN_WORK_WEBHOOK="xxxx" |
|||
|
|||
#optional |
|||
#WEIXIN_WORK_KEYWORD="yyyy" |
|||
|
|||
#`WEIXIN_WORK_SIGNING_KEY`="SEC08ffdbd403cbc3fc8a65xxxxxxxxxxxxxxxxxxxx" |
|||
|
|||
# subject content statusCode |
|||
weixin_work_send() { |
|||
_subject="$1" |
|||
_content="$2" |
|||
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped |
|||
_debug "_subject" "$_subject" |
|||
_debug "_content" "$_content" |
|||
_debug "_statusCode" "$_statusCode" |
|||
|
|||
WEIXIN_WORK_WEBHOOK="${WEIXIN_WORK_WEBHOOK:-$(_readaccountconf_mutable WEIXIN_WORK_WEBHOOK)}" |
|||
if [ -z "$WEIXIN_WORK_WEBHOOK" ]; then |
|||
WEIXIN_WORK_WEBHOOK="" |
|||
_err "You didn't specify a weixin_work webhooks WEIXIN_WORK_WEBHOOK yet." |
|||
_err "You can get yours from https://work.weixin.qq.com/api/doc/90000/90136/91770" |
|||
return 1 |
|||
fi |
|||
_saveaccountconf_mutable WEIXIN_WORK_WEBHOOK "$WEIXIN_WORK_WEBHOOK" |
|||
|
|||
WEIXIN_WORK_KEYWORD="${WEIXIN_WORK_KEYWORD:-$(_readaccountconf_mutable WEIXIN_WORK_KEYWORD)}" |
|||
if [ "$WEIXIN_WORK_KEYWORD" ]; then |
|||
_saveaccountconf_mutable WEIXIN_WORK_KEYWORD "$WEIXIN_WORK_KEYWORD" |
|||
fi |
|||
|
|||
_content=$(echo "$_content" | _json_encode) |
|||
_subject=$(echo "$_subject" | _json_encode) |
|||
_data="{\"msgtype\": \"text\", \"text\": {\"content\": \"[$WEIXIN_WORK_KEYWORD]\n$_subject\n$_content\"}}" |
|||
|
|||
response="$(_post "$_data" "$WEIXIN_WORK_WEBHOOK" "" "POST" "application/json")" |
|||
|
|||
if [ "$?" = "0" ] && _contains "$response" "errmsg\":\"ok"; then |
|||
_info "weixin_work webhooks event fired success." |
|||
return 0 |
|||
fi |
|||
|
|||
_err "weixin_work webhooks event fired error." |
|||
_err "$response" |
|||
return 1 |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue