Browse Source

Merge pull request #2486 from Neilpang/dev

sync
neil 1 month ago
parent
commit
73b89c554e
No account linked to committer's email address
6 changed files with 260 additions and 5 deletions
  1. 11
    2
      acme.sh
  2. 1
    1
      dnsapi/dns_ali.sh
  3. 155
    0
      dnsapi/dns_domeneshop.sh
  4. 2
    1
      dnsapi/dns_linode_v4.sh
  5. 1
    1
      dnsapi/dns_namesilo.sh
  6. 90
    0
      notify/xmpp.sh

+ 11
- 2
acme.sh View File

@@ -2799,6 +2799,11 @@ _setNginx() {
2799 2799
       _debug NGINX_CONF "$NGINX_CONF"
2800 2800
       NGINX_CONF="$(echo "$NGINX_CONF" | cut -d = -f 2)"
2801 2801
       _debug NGINX_CONF "$NGINX_CONF"
2802
+      if [ -z "$NGINX_CONF" ]; then
2803
+        _err "Can not find nginx conf."
2804
+        NGINX_CONF=""
2805
+        return 1
2806
+      fi
2802 2807
       if [ ! -f "$NGINX_CONF" ]; then
2803 2808
         _err "'$NGINX_CONF' doesn't exist."
2804 2809
         NGINX_CONF=""
@@ -6241,8 +6246,8 @@ _checkSudo() {
6241 6246
       #it's root using sudo, no matter it's using sudo or not, just fine
6242 6247
       return 0
6243 6248
     fi
6244
-    if [ "$SUDO_COMMAND" = "/bin/su" ]; then
6245
-      #it's a normal user doing "sudo su"
6249
+    if [ "$SUDO_COMMAND" = "/bin/su" ] || [ "$SUDO_COMMAND" = "/bin/bash" ]; then
6250
+      #it's a normal user doing "sudo su", or `sudo -i` or `sudo -s`
6246 6251
       #fine
6247 6252
       return 0
6248 6253
     fi
@@ -6503,6 +6508,10 @@ _process() {
6503 6508
         ;;
6504 6509
       --nginx)
6505 6510
         wvalue="$NGINX"
6511
+        if [ "$2" ] && ! _startswith "$2" "-"; then
6512
+          wvalue="$NGINX$2"
6513
+          shift
6514
+        fi
6506 6515
         if [ -z "$_webroot" ]; then
6507 6516
           _webroot="$wvalue"
6508 6517
         else

+ 1
- 1
dnsapi/dns_ali.sh View File

@@ -185,7 +185,7 @@ _clean() {
185 185
     return 1
186 186
   fi
187 187
 
188
-  record_id="$(echo "$response" | tr '{' "\n" | grep "$_sub_domain" | grep "$txtvalue" | tr "," "\n" | grep RecordId | cut -d '"' -f 4)"
188
+  record_id="$(echo "$response" | tr '{' "\n" | grep "$_sub_domain" | grep -- "$txtvalue" | tr "," "\n" | grep RecordId | cut -d '"' -f 4)"
189 189
   _debug2 record_id "$record_id"
190 190
 
191 191
   if [ -z "$record_id" ]; then

+ 155
- 0
dnsapi/dns_domeneshop.sh View File

@@ -0,0 +1,155 @@
1
+#!/usr/bin/env sh
2
+
3
+DOMENESHOP_Api_Endpoint="https://api.domeneshop.no/v0"
4
+
5
+#####################  Public functions #####################
6
+
7
+# Usage: dns_domeneshop_add <full domain> <txt record>
8
+# Example: dns_domeneshop_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
9
+dns_domeneshop_add() {
10
+  fulldomain=$1
11
+  txtvalue=$2
12
+
13
+  # Get token and secret
14
+  DOMENESHOP_Token="${DOMENESHOP_Token:-$(_readaccountconf_mutable DOMENESHOP_Token)}"
15
+  DOMENESHOP_Secret="${DOMENESHOP_Secret:-$(_readaccountconf_mutable DOMENESHOP_Secret)}"
16
+
17
+  if [ -z "$DOMENESHOP_Token" ] || [ -z "$DOMENESHOP_Secret" ]; then
18
+    DOMENESHOP_Token=""
19
+    DOMENESHOP_Secret=""
20
+    _err "You need to spesify a Domeneshop/Domainnameshop API Token and Secret."
21
+    return 1
22
+  fi
23
+
24
+  # Save the api token and secret.
25
+  _saveaccountconf_mutable DOMENESHOP_Token "$DOMENESHOP_Token"
26
+  _saveaccountconf_mutable DOMENESHOP_Secret "$DOMENESHOP_Secret"
27
+
28
+  # Get the domain name id
29
+  if ! _get_domainid "$fulldomain"; then
30
+    _err "Did not find domainname"
31
+    return 1
32
+  fi
33
+
34
+  # Create record
35
+  _domeneshop_rest POST "domains/$_domainid/dns" "{\"type\":\"TXT\",\"host\":\"$_sub_domain\",\"data\":\"$txtvalue\",\"ttl\":120}"
36
+}
37
+
38
+# Usage: dns_domeneshop_rm <full domain> <txt record>
39
+# Example: dns_domeneshop_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
40
+dns_domeneshop_rm() {
41
+  fulldomain=$1
42
+  txtvalue=$2
43
+
44
+  # Get token and secret
45
+  DOMENESHOP_Token="${DOMENESHOP_Token:-$(_readaccountconf_mutable DOMENESHOP_Token)}"
46
+  DOMENESHOP_Secret="${DOMENESHOP_Secret:-$(_readaccountconf_mutable DOMENESHOP_Secret)}"
47
+
48
+  if [ -z "$DOMENESHOP_Token" ] || [ -z "$DOMENESHOP_Secret" ]; then
49
+    DOMENESHOP_Token=""
50
+    DOMENESHOP_Secret=""
51
+    _err "You need to spesify a Domeneshop/Domainnameshop API Token and Secret."
52
+    return 1
53
+  fi
54
+
55
+  # Get the domain name id
56
+  if ! _get_domainid "$fulldomain"; then
57
+    _err "Did not find domainname"
58
+    return 1
59
+  fi
60
+
61
+  # Find record
62
+  if ! _get_recordid "$_domainid" "$_sub_domain" "$txtvalue"; then
63
+    _err "Did not find dns record"
64
+    return 1
65
+  fi
66
+
67
+  # Remove record
68
+  _domeneshop_rest DELETE "domains/$_domainid/dns/$_recordid"
69
+}
70
+
71
+#####################  Private functions #####################
72
+
73
+_get_domainid() {
74
+  domain=$1
75
+
76
+  # Get domains
77
+  _domeneshop_rest GET "domains"
78
+
79
+  if ! _contains "$response" "\"id\":"; then
80
+    _err "failed to get domain names"
81
+    return 1
82
+  fi
83
+
84
+  i=2
85
+  p=1
86
+  while true; do
87
+    h=$(printf "%s" "$domain" | cut -d . -f $i-100)
88
+    _debug "h" "$h"
89
+    if [ -z "$h" ]; then
90
+      #not valid
91
+      return 1
92
+    fi
93
+
94
+    if _contains "$response" "\"$h\"" >/dev/null; then
95
+      # We have found the domain name.
96
+      _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
97
+      _domain=$h
98
+      _domainid=$(printf "%s" "$response" | _egrep_o "[^{]*\"domain\":\"$_domain\"[^}]*" | _egrep_o "\"id\":[0-9]+" | cut -d : -f 2)
99
+      return 0
100
+    fi
101
+    p=$i
102
+    i=$(_math "$i" + 1)
103
+  done
104
+  return 1
105
+}
106
+
107
+_get_recordid() {
108
+  domainid=$1
109
+  subdomain=$2
110
+  txtvalue=$3
111
+
112
+  # Get all dns records for the domainname
113
+  _domeneshop_rest GET "domains/$domainid/dns"
114
+
115
+  if ! _contains "$response" "\"id\":"; then
116
+    _debug "No records in dns"
117
+    return 1
118
+  fi
119
+
120
+  if ! _contains "$response" "\"host\":\"$subdomain\""; then
121
+    _debug "Record does not exist"
122
+    return 1
123
+  fi
124
+
125
+  # Get the id of the record in question
126
+  _recordid=$(printf "%s" "$response" | _egrep_o "[^{]*\"host\":\"$subdomain\"[^}]*" | _egrep_o "[^{]*\"data\":\"$txtvalue\"[^}]*" | _egrep_o "\"id\":[0-9]+" | cut -d : -f 2)
127
+  if [ -z "$_recordid" ]; then
128
+    return 1
129
+  fi
130
+  return 0
131
+}
132
+
133
+_domeneshop_rest() {
134
+  method=$1
135
+  endpoint=$2
136
+  data=$3
137
+
138
+  credentials=$(printf "%b" "$DOMENESHOP_Token:$DOMENESHOP_Secret" | _base64)
139
+
140
+  export _H1="Authorization: Basic $credentials"
141
+  export _H2="Content-Type: application/json"
142
+
143
+  if [ "$method" != "GET" ]; then
144
+    response="$(_post "$data" "$DOMENESHOP_Api_Endpoint/$endpoint" "" "$method")"
145
+  else
146
+    response="$(_get "$DOMENESHOP_Api_Endpoint/$endpoint")"
147
+  fi
148
+
149
+  if [ "$?" != "0" ]; then
150
+    _err "error $endpoint"
151
+    return 1
152
+  fi
153
+
154
+  return 0
155
+}

+ 2
- 1
dnsapi/dns_linode_v4.sh View File

@@ -31,7 +31,8 @@ dns_linode_v4_add() {
31 31
   _payload="{
32 32
               \"type\": \"TXT\",
33 33
               \"name\": \"$_sub_domain\",
34
-              \"target\": \"$txtvalue\"
34
+              \"target\": \"$txtvalue\",
35
+              \"ttl_sec\": 300
35 36
             }"
36 37
 
37 38
   if _rest POST "/$_domain_id/records" "$_payload" && [ -n "$response" ]; then

+ 1
- 1
dnsapi/dns_namesilo.sh View File

@@ -110,7 +110,7 @@ _get_root() {
110 110
       return 1
111 111
     fi
112 112
 
113
-    if _contains "$response" "$host"; then
113
+    if _contains "$response" "<domain>$host"; then
114 114
       _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
115 115
       _domain="$host"
116 116
       return 0

+ 90
- 0
notify/xmpp.sh View File

@@ -0,0 +1,90 @@
1
+#!/usr/bin/env sh
2
+
3
+#Support xmpp via sendxmpp
4
+
5
+#XMPP_BIN="/usr/bin/sendxmpp"
6
+#XMPP_BIN_ARGS="-n -t --tls-ca-path=/etc/ssl/certs"
7
+#XMPP_TO="zzzz@example.com"
8
+
9
+xmpp_send() {
10
+  _subject="$1"
11
+  _content="$2"
12
+  _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
13
+  _debug "_subject" "$_subject"
14
+  _debug "_content" "$_content"
15
+  _debug "_statusCode" "$_statusCode"
16
+
17
+  XMPP_BIN="${XMPP_BIN:-$(_readaccountconf_mutable XMPP_BIN)}"
18
+  if [ -n "$XMPP_BIN" ] && ! _exists "$XMPP_BIN"; then
19
+    _err "It seems that the command $XMPP_BIN is not in path."
20
+    return 1
21
+  fi
22
+  _XMPP_BIN=$(_xmpp_bin)
23
+  if [ -n "$XMPP_BIN" ]; then
24
+    _saveaccountconf_mutable XMPP_BIN "$XMPP_BIN"
25
+  else
26
+    _clearaccountconf "XMPP_BIN"
27
+  fi
28
+
29
+  XMPP_BIN_ARGS="${XMPP_BIN_ARGS:-$(_readaccountconf_mutable XMPP_BIN_ARGS)}"
30
+  if [ -n "$XMPP_BIN_ARGS" ]; then
31
+    _saveaccountconf_mutable XMPP_BIN_ARGS "$XMPP_BIN_ARGS"
32
+  else
33
+    _clearaccountconf "XMPP_BIN_ARGS"
34
+  fi
35
+
36
+  XMPP_TO="${XMPP_TO:-$(_readaccountconf_mutable XMPP_TO)}"
37
+  if [ -n "$XMPP_TO" ]; then
38
+    if ! _xmpp_valid "$XMPP_TO"; then
39
+      _err "It seems that the XMPP_TO=$XMPP_TO is not a valid xmpp address."
40
+      return 1
41
+    fi
42
+
43
+    _saveaccountconf_mutable XMPP_TO "$XMPP_TO"
44
+  fi
45
+
46
+  result=$({ _xmpp_message | eval "$(_xmpp_cmnd)"; } 2>&1)
47
+
48
+  # shellcheck disable=SC2181
49
+  if [ $? -ne 0 ]; then
50
+    _debug "xmpp send error."
51
+    _err "$result"
52
+    return 1
53
+  fi
54
+
55
+  _debug "xmpp send success."
56
+  return 0
57
+}
58
+
59
+_xmpp_bin() {
60
+  if [ -n "$XMPP_BIN" ]; then
61
+    _XMPP_BIN="$XMPP_BIN"
62
+  elif _exists "sendxmpp"; then
63
+    _XMPP_BIN="sendxmpp"
64
+  else
65
+    _err "Please install sendxmpp first."
66
+    return 1
67
+  fi
68
+
69
+  echo "$_XMPP_BIN"
70
+}
71
+
72
+_xmpp_cmnd() {
73
+  case $(basename "$_XMPP_BIN") in
74
+    sendxmpp)
75
+      echo "'$_XMPP_BIN' '$XMPP_TO' $XMPP_BIN_ARGS"
76
+      ;;
77
+    *)
78
+      _err "Command $XMPP_BIN is not supported, use sendxmpp."
79
+      return 1
80
+      ;;
81
+  esac
82
+}
83
+
84
+_xmpp_message() {
85
+  echo "$_subject"
86
+}
87
+
88
+_xmpp_valid() {
89
+  _contains "$1" "@"
90
+}

Loading…
Cancel
Save