4 # User must provide login data and URL to the ISPConfig installation incl. port. The remote user in ISPConfig must have access to:
7 # Report bugs to https://github.com/sjau/acme.sh
10 # export ISPC_User="remoteUser"
11 # export ISPC_Password="remotePassword"
12 # export ISPC_Api="https://ispc.domain.tld:8080/remote/json.php"
13 # export ISPC_Api_Insecure=1 # Set 1 for insecure and 0 for secure -> difference is whether ssl cert is checked for validity (0) or whether it is just accepted (1)
15 ######## Public functions #####################
17 #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
21 _debug
"Calling: dns_ispconfig_add() '${fulldomain}' '${txtvalue}'"
22 _ISPC_credentials
&& _ISPC_login
&& _ISPC_getZoneInfo
&& _ISPC_addTxt
25 #Usage: dns_myapi_rm _acme-challenge.www.domain.com
28 _debug
"Calling: dns_ispconfig_rm() '${fulldomain}'"
29 _ISPC_credentials
&& _ISPC_login
&& _ISPC_rmTxt
32 #################### Private functions below ##################################
35 if [ -z "${ISPC_User}" ] || [ -z "$ISPC_Password" ] || [ -z "${ISPC_Api}" ] || [ -z "${ISPC_Api_Insecure}" ]; then
40 _err
"You haven't specified the ISPConfig Login data, URL and whether you want check the ISPC SSL cert. Please try again."
43 _saveaccountconf ISPC_User
"${ISPC_User}"
44 _saveaccountconf ISPC_Password
"${ISPC_Password}"
45 _saveaccountconf ISPC_Api
"${ISPC_Api}"
46 _saveaccountconf ISPC_Api_Insecure
"${ISPC_Api_Insecure}"
47 # Set whether curl should use secure or insecure mode
48 export HTTPS_INSECURE
="${ISPC_Api_Insecure}"
53 _info
"Getting Session ID"
54 curData
="{\"username\":\"${ISPC_User}\",\"password\":\"${ISPC_Password}\",\"client_login\":false}"
55 curResult
="$(_post "${curData}" "${ISPC_Api}?login
")"
56 _debug
"Calling _ISPC_login: '${curData}' '${ISPC_Api}?login'"
57 _debug
"Result of _ISPC_login: '$curResult'"
58 if _contains
"${curResult}" '"code":"ok"'; then
59 sessionID
=$
(echo "${curResult}" | _egrep_o
"response.*" | cut
-d ':' -f 2 | cut
-d '"' -f 2)
60 _info
"Retrieved Session ID."
61 _debug
"Session ID: '${sessionID}'"
63 _err
"Couldn't retrieve the Session ID."
69 _info
"Getting Zoneinfo"
71 curZone
="${fulldomain}"
72 while [ "${zoneEnd}" = false
]; do
73 # we can strip the first part of the fulldomain, since it's just the _acme-challenge string
74 curZone
="${curZone#*.}"
75 # suffix . needed for zone -> domain.tld.
76 curData
="{\"session_id\":\"${sessionID}\",\"primary_id\":{\"origin\":\"${curZone}.\"}}"
77 curResult
="$(_post "${curData}" "${ISPC_Api}?dns_zone_get
")"
78 _debug
"Calling _ISPC_getZoneInfo: '${curData}' '${ISPC_Api}?login'"
79 _debug
"Result of _ISPC_getZoneInfo: '$curResult'"
80 if _contains
"${curResult}" '"id":"'; then
83 _info
"Retrieved zone data."
84 _debug
"Zone data: '${curResult}'"
86 if [ "${curZone#*.}" != "$curZone" ]; then
87 _debug2
"$curZone still contains a '.' - so we can check next higher level"
90 _err
"Couldn't retrieve zone data."
94 if [ "${zoneFound}" ]; then
95 server_id
=$
(echo "${curResult}" | _egrep_o
"server_id.*" | cut
-d ':' -f 2 | cut
-d '"' -f 2)
96 _debug
"Server ID: '${server_id}'"
97 case "${server_id}" in
99 _err
"Server ID is not numeric."
102 *) _info
"Retrieved Server ID" ;;
104 zone
=$
(echo "${curResult}" | _egrep_o
"\"id.*" | cut
-d ':' -f 2 | cut
-d '"' -f 2)
105 _debug
"Zone: '${zone}'"
108 _err
"Zone ID is not numeric."
111 *) _info
"Retrieved Zone ID" ;;
113 client_id
=$
(echo "${curResult}" | _egrep_o
"sys_userid.*" | cut
-d ':' -f 2 | cut
-d '"' -f 2)
114 _debug
"Client ID: '${client_id}'"
115 case "${client_id}" in
117 _err
"Client ID is not numeric."
120 *) _info
"Retrieved Client ID." ;;
128 curSerial
="$(date +%s)"
129 curStamp
="$(date +'%F %T')"
130 params
="\"server_id\":\"${server_id}\",\"zone\":\"${zone}\",\"name\":\"${fulldomain}.\",\"type\":\"txt\",\"data\":\"${txtvalue}\",\"aux\":\"0\",\"ttl\":\"3600\",\"active\":\"y\",\"stamp\":\"${curStamp}\",\"serial\":\"${curSerial}\""
131 curData
="{\"session_id\":\"${sessionID}\",\"client_id\":\"${client_id}\",\"params\":{${params}},\"update_serial\":true}"
132 curResult
="$(_post "${curData}" "${ISPC_Api}?dns_txt_add
")"
133 _debug
"Calling _ISPC_addTxt: '${curData}' '${ISPC_Api}?dns_txt_add'"
134 _debug
"Result of _ISPC_addTxt: '$curResult'"
135 record_id
=$
(echo "${curResult}" | _egrep_o
"\"response.*" | cut
-d ':' -f 2 | cut
-d '"' -f 2)
136 _debug
"Record ID: '${record_id}'"
137 case "${record_id}" in
139 _err
"Couldn't add ACME Challenge TXT record to zone."
142 *) _info
"Added ACME Challenge TXT record to zone." ;;
147 # Need to get the record ID.
148 curData
="{\"session_id\":\"${sessionID}\",\"primary_id\":{\"name\":\"${fulldomain}.\",\"type\":\"TXT\"}}"
149 curResult
="$(_post "${curData}" "${ISPC_Api}?dns_txt_get
")"
150 _debug
"Calling _ISPC_rmTxt: '${curData}' '${ISPC_Api}?dns_txt_get'"
151 _debug
"Result of _ISPC_rmTxt: '$curResult'"
152 if _contains
"${curResult}" '"code":"ok"'; then
153 record_id
=$
(echo "${curResult}" | _egrep_o
"\"id.*" | cut
-d ':' -f 2 | cut
-d '"' -f 2)
154 _debug
"Record ID: '${record_id}'"
155 case "${record_id}" in
157 _err
"Record ID is not numeric."
162 _info
"Retrieved Record ID."
163 curData
="{\"session_id\":\"${sessionID}\",\"primary_id\":\"${record_id}\",\"update_serial\":true}"
164 curResult
="$(_post "${curData}" "${ISPC_Api}?dns_txt_delete
")"
165 _debug
"Calling _ISPC_rmTxt: '${curData}' '${ISPC_Api}?dns_txt_delete'"
166 _debug
"Result of _ISPC_rmTxt: '$curResult'"
167 if _contains
"${curResult}" '"code":"ok"'; then
168 _info
"Removed ACME Challenge TXT record from zone."
170 _err
"Couldn't remove ACME Challenge TXT record from zone."