Commit 5daefc01 authored by neil's avatar neil Committed by GitHub
Browse files

Merge pull request #375 from Neilpang/dev

Add shfmt to format source code
parents cfd0b040 44edb2bd
language: bash
env:
global:
- SHFMT_URL=https://github.com/mvdan/sh/releases/download/v0.4.0/shfmt_v0.4.0_linux_amd64
script:
- curl -sSL $SHFMT_URL -o ~/shfmt
- chmod +x ~/shfmt
- ~/shfmt -l -w -i 2 .
- git diff --exit-code || (echo "Run shfmt to fix the formatting issues" && false)
This diff is collapsed.
...@@ -6,8 +6,6 @@ ...@@ -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
...@@ -24,10 +22,7 @@ myapi_deploy() { ...@@ -24,10 +22,7 @@ myapi_deploy() {
_debug _cca "$_cca" _debug _cca "$_cca"
_debug _cfullchain "$_cfullchain" _debug _cfullchain "$_cfullchain"
_err "Not implemented yet" _err "Not implemented yet"
return 1 return 1
} }
#!/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
_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
...@@ -27,7 +25,7 @@ dns_cf_add(){ ...@@ -27,7 +25,7 @@ dns_cf_add(){
_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
...@@ -38,17 +36,17 @@ dns_cf_add(){ ...@@ -38,17 +36,17 @@ dns_cf_add(){
_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 "$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,7 +59,7 @@ dns_cf_add(){ ...@@ -61,7 +59,7 @@ 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\"}"
...@@ -69,7 +67,7 @@ dns_cf_add(){ ...@@ -69,7 +67,7 @@ dns_cf_add(){
_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
...@@ -77,14 +75,12 @@ dns_cf_add(){ ...@@ -77,14 +75,12 @@ dns_cf_add(){
} }
#fulldomain #fulldomain
dns_cf_rm() { dns_cf_rm() {
fulldomain=$1 fulldomain=$1
} }
#################### Private functions bellow ################################## #################### Private functions bellow ##################################
#_acme-challenge.www.domain.com #_acme-challenge.www.domain.com
#returns #returns
...@@ -95,20 +91,20 @@ _get_root() { ...@@ -95,20 +91,20 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ] ; do while [ '1' ]; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf $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 ! _cf_rest GET "zones?name=$h" ; then if ! _cf_rest GET "zones?name=$h"; then
return 1 return 1
fi fi
if printf $response | grep \"name\":\"$h\" >/dev/null ; then if printf $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 \") _domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | head -n 1 | cut -d : -f 2 | tr -d \")
if [ "$_domain_id" ] ; then if [ "$_domain_id" ]; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf $domain | cut -d . -f 1-$p)
_domain=$h _domain=$h
return 0 return 0
...@@ -131,19 +127,17 @@ _cf_rest() { ...@@ -131,19 +127,17 @@ _cf_rest() {
_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
} }
...@@ -6,10 +6,8 @@ ...@@ -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 #####################
...@@ -18,7 +16,7 @@ dns_cx_add() { ...@@ -18,7 +16,7 @@ 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
_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
...@@ -30,41 +28,37 @@ dns_cx_add() { ...@@ -30,41 +28,37 @@ dns_cx_add() {
_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.
...@@ -74,17 +68,17 @@ existing_records() { ...@@ -74,17 +68,17 @@ existing_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 "$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"
...@@ -120,16 +114,13 @@ update_record() { ...@@ -120,16 +114,13 @@ update_record() {
_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
...@@ -141,24 +132,24 @@ _get_root() { ...@@ -141,24 +132,24 @@ _get_root() {
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 [ '1' ]; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf $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 printf "$response" | grep "$h." >/dev/null; 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 $domain | cut -d . -f 1-$p)
_debug _sub_domain $_sub_domain _debug _sub_domain $_sub_domain
_domain=$h _domain=$h
...@@ -173,7 +164,6 @@ _get_root() { ...@@ -173,7 +164,6 @@ _get_root() {
return 1 return 1
} }
#Usage: method URI data #Usage: method URI data
_rest() { _rest() {
m=$1 m=$1
...@@ -190,7 +180,7 @@ _rest() { ...@@ -190,7 +180,7 @@ _rest() {
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 "$sec" | openssl md5 | cut -d " " -f 2)
_debug hmac "$hmac" _debug hmac "$hmac"
_H1="API-KEY: $CX_Key" _H1="API-KEY: $CX_Key"
...@@ -198,21 +188,19 @@ _rest() { ...@@ -198,21 +188,19 @@ _rest() {
_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 ! printf "$response" | grep '"message":"success"' >/dev/null; then
return 1 return 1
fi fi
return 0 return 0
} }
...@@ -6,10 +6,8 @@ ...@@ -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 #####################
...@@ -18,7 +16,7 @@ dns_dp_add() { ...@@ -18,7 +16,7 @@ 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
_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
...@@ -30,36 +28,32 @@ dns_dp_add() { ...@@ -30,36 +28,32 @@ dns_dp_add() {
_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.
...@@ -73,12 +67,12 @@ existing_records() { ...@@ -73,12 +67,12 @@ existing_records() {
return 1 return 1
fi fi
if printf "$response" | grep 'No records' ; then if printf "$response" | grep 'No records'; then
count=0; count=0
return 0 return 0
fi fi
if printf "$response" | grep "Action completed successful" >/dev/null ; then if printf "$response" | grep "Action completed successful" >/dev/null; then
count=$(printf "$response" | grep '<type>TXT</type>' | wc -l) count=$(printf "$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 "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)
return 0 return 0
...@@ -87,7 +81,6 @@ existing_records() { ...@@ -87,7 +81,6 @@ existing_records() {
return 1 return 1
fi fi
count=0 count=0
} }
...@@ -105,12 +98,11 @@ add_record() { ...@@ -105,12 +98,11 @@ add_record() {
return 1 return 1
fi fi
if printf "$response" | grep "Action completed successful" ; then if printf "$response" | grep "Action completed successful"; then
return 0 return 0
fi fi
return 1 #error return 1 #error
} }
...@@ -128,7 +120,7 @@ update_record() { ...@@ -128,7 +120,7 @@ update_record() {
return 1 return 1
fi fi
if printf "$response" | grep "Action completed successful" ; then if printf "$response" | grep "Action completed successful"; then
return 0 return 0
fi fi
...@@ -136,9 +128,6 @@ update_record() { ...@@ -136,9 +128,6 @@ update_record() {
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,21 +138,21 @@ _get_root() { ...@@ -149,21 +138,21 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ] ; do while [ '1' ]; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf $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 printf "$response" | grep "Action completed successful" >/dev/null; 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 $domain | cut -d . -f 1-$p)
_debug _sub_domain $_sub_domain _debug _sub_domain $_sub_domain
_domain=$h _domain=$h
...@@ -178,7 +167,6 @@ _get_root() { ...@@ -178,7 +167,6 @@ _get_root() {
return 1 return 1
} }
#Usage: method URI data #Usage: method URI data
_rest() { _rest() {
m=$1 m=$1
...@@ -189,19 +177,17 @@ _rest() { ...@@ -189,19 +177,17 @@ _rest() {
_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,17 +6,16 @@ ...@@ -6,17 +6,16 @@
# #
#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
_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
...@@ -27,7 +26,7 @@ dns_gd_add(){ ...@@ -27,7 +26,7 @@ dns_gd_add(){
_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
...@@ -35,10 +34,9 @@ dns_gd_add(){ ...@@ -35,10 +34,9 @@ dns_gd_add(){
_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
...@@ -53,17 +51,12 @@ dns_gd_add(){ ...@@ -53,17 +51,12 @@ dns_gd_add(){
} }
#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
...@@ -74,18 +67,18 @@ _get_root() { ...@@ -74,18 +67,18 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ] ; do while [ '1' ]; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf $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 ! _gd_rest GET "domains/$h" ; then if ! _gd_rest GET "domains/$h"; then
return 1 return 1
fi fi
if printf "$response" | grep '"code":"NOT_FOUND"' >/dev/null ; then if printf "$response" | grep '"code":"NOT_FOUND"' >/dev/null; then
_debug "$h not found" _debug "$h not found"
else else
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf $domain | cut -d . -f 1-$p)
...@@ -107,19 +100,17 @@ _gd_rest() { ...@@ -107,19 +100,17 @@ _gd_rest() {
_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
} }
...@@ -16,12 +16,12 @@ dns_lexicon_add() { ...@@ -16,12 +16,12 @@ dns_lexicon_add() {
domain=$(printf "$fulldomain" | cut -d . -f 2-999) domain=$(printf "$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
_err "Please define env PROVIDER first: $wiki" _err "Please define env PROVIDER first: $wiki"
return 1 return 1
fi fi
...@@ -32,7 +32,7 @@ dns_lexicon_add() { ...@@ -32,7 +32,7 @@ dns_lexicon_add() {
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" eval Lx_name_v="\$$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" export "$Lx_name"
fi fi
...@@ -40,7 +40,7 @@ dns_lexicon_add() { ...@@ -40,7 +40,7 @@ dns_lexicon_add() {
Lx_token=$(echo LEXICON_${PROVIDER}_TOKEN | tr [a-z] [A-Z]) Lx_token=$(echo LEXICON_${PROVIDER}_TOKEN | tr [a-z] [A-Z])
eval Lx_token_v="\$$Lx_token" eval Lx_token_v="\$$Lx_token"
_debug "$Lx_token" "$Lx_token_v" _debug "$Lx_token" "$Lx_token_v"
if [ "$Lx_token_v" ] ; then if [ "$Lx_token_v" ]; then
_saveaccountconf $Lx_token "$Lx_token_v" _saveaccountconf $Lx_token "$Lx_token_v"
export "$Lx_token" export "$Lx_token"
fi fi
...@@ -48,7 +48,7 @@ dns_lexicon_add() { ...@@ -48,7 +48,7 @@ dns_lexicon_add() {
Lx_password=$(echo LEXICON_${PROVIDER}_PASSWORD | tr [a-z] [A-Z]) Lx_password=$(echo LEXICON_${PROVIDER}_PASSWORD | tr [a-z] [A-Z])
eval Lx_password_v="\$$Lx_password" eval Lx_password_v="\$$Lx_password"
_debug "$Lx_password" "$Lx_password_v" _debug "$Lx_password" "$Lx_password_v"
if [ "$Lx_password_v" ] ; then if [ "$Lx_password_v" ]; then
_saveaccountconf $Lx_password "$Lx_password_v" _saveaccountconf $Lx_password "$Lx_password_v"
export "$Lx_password" export "$Lx_password"
fi fi
...@@ -56,7 +56,7 @@ dns_lexicon_add() { ...@@ -56,7 +56,7 @@ dns_lexicon_add() {
Lx_domaintoken=$(echo LEXICON_${PROVIDER}_DOMAINTOKEN | tr [a-z] [A-Z]) Lx_domaintoken=$(echo LEXICON_${PROVIDER}_DOMAINTOKEN | tr [a-z] [A-Z])
eval Lx_domaintoken_v="\$$Lx_domaintoken" eval Lx_domaintoken_v="\$$Lx_domaintoken"
_debug "$Lx_domaintoken" "$Lx_domaintoken_v" _debug "$Lx_domaintoken" "$Lx_domaintoken_v"
if [ "$Lx_domaintoken_v" ] ; then if [ "$Lx_domaintoken_v" ]; then
export "$Lx_domaintoken" export "$Lx_domaintoken"
_saveaccountconf $Lx_domaintoken "$Lx_domaintoken_v" _saveaccountconf $Lx_domaintoken "$Lx_domaintoken_v"
fi fi
...@@ -65,14 +65,8 @@ dns_lexicon_add() { ...@@ -65,14 +65,8 @@ dns_lexicon_add() {
} }
#fulldomain #fulldomain
dns_lexicon_rm() { dns_lexicon_rm() {
fulldomain=$1 fulldomain=$1
} }
This diff is collapsed.
...@@ -6,8 +6,6 @@ ...@@ -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() { ...@@ -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() { ...@@ -42,7 +37,7 @@ _err() {
} }
_debug() { _debug() {
if [ -z "$DEBUG" ] ; then if [ -z "$DEBUG" ]; then
return return
fi fi
_err "$@" _err "$@"
...@@ -50,7 +45,7 @@ _debug() { ...@@ -50,7 +45,7 @@ _debug() {
} }
_debug2() { _debug2() {
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ] ; then if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then
_debug "$@" _debug "$@"
fi fi
return return
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment