]> git.proxmox.com Git - proxmox-acme.git/blobdiff - src/proxmox-acme
dns plugin: improve 'data' string encoding/passing
[proxmox-acme.git] / src / proxmox-acme
index ff9fec863a3dc1f4e8a3145b4ea9137bea942451..49a86adb984601c074b5a264d0c3974dc5e2843f 100644 (file)
@@ -9,6 +9,8 @@ USER_AGENT="$PROJECT_NAME/$VER"
 DNS_PLUGIN_PATH="/usr/share/proxmox-acme/dnsapi"
 HTTP_HEADER="$(mktemp)"
 
+DEBUG="0"
+
 _base64() {
   openssl base64 -e | tr -d '\r\n'
 }
@@ -532,27 +534,31 @@ _cleardomainconf() {
 }
 
 _debug() {
-  return
+  if [[ $DEBUG -eq 0 ]]; then
+    return
+  fi
+  printf -- "%s" "[$(date)] " >&1
+  echo "$1 $2"
 }
 
 _debug2() {
-  return
+  _debug $1 $2
 }
 
 _debug3() {
-  return
+  _debug $1 $2
 }
 
 _secure_debug() {
-  return
+  _debug $1 $2
 }
 
 _secure_debug2() {
-  return
+  _debug $1 $2
 }
 
 _secure_debug3() {
-  return
+  _debug $1 $2
 }
 
 _saveaccountconf() {
@@ -577,21 +583,15 @@ _source_plugin_config() {
 
 # Proxmox implementation to inject the DNSAPI variables
 _load_plugin_config() {
-    tmp_str="${plugin_conf_string//[^,]}"
-    index="$(_math ${#tmp_str} + 1)"
-    while [ "$index" -gt "0" ]
-    do
-       field=$(_getfield $plugin_conf_string "$index" ",")
-       ADDR=(${field/=/ })
+    while IFS= read -r line; do
+       ADDR=(${line/=/ })
        key="${ADDR[0]}"
        value="${ADDR[1]}"
 
-       # decode base64 encoded values
-       value=$(echo $value | /usr/bin/openssl base64 -d -A)
-
        # acme.sh uses eval insted of export
-       export "$key"="$value"
-       index="$(_math "$index" - 1)"
+       if [ -n "$key" ]; then
+           export "$key"="$value"
+       fi
     done
 }
 
@@ -601,12 +601,14 @@ _load_plugin_config() {
 # $2 <String> Fully Qualified Domain Name
 # $3 <String> value for TXT record
 # $4 <String> DNS plugin auth and config parameter separated by ","
+# $5 <Integer> 0 is off, and the default all others are on.
 
 setup() {
   dns_plugin="dns_$1"
   dns_plugin_path="${DNS_PLUGIN_PATH}/${dns_plugin}.sh"
   fqdn="_acme-challenge.$2"
-  txtvalue=$3
+  DEBUG=$3
+  IFS= read -r txtvalue
   plugin_conf_string=$4
 
   _load_plugin_config
@@ -632,8 +634,8 @@ teardown() {
   dns_plugin="dns_$1"
   dns_plugin_path="${DNS_PLUGIN_PATH}/${dns_plugin}.sh"
   fqdn="_acme-challenge.$2"
-  txtvalue=$3
-  plugin_conf_string=$4
+  DEBUG=$3
+  IFS= read -r txtvalue
 
   _load_plugin_config