From 798f36ab4b960154595277ad031e8bf771e78cf7 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 22 Mar 2025 01:37:21 +0800 Subject: [PATCH] Fixed command not found --- mbadmin.jps | 25 +++++++++------- scripts/ssl-manager/ssl_manager.sh | 46 +++++++++++++++++++----------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/mbadmin.jps b/mbadmin.jps index 37181d6..7132d09 100644 --- a/mbadmin.jps +++ b/mbadmin.jps @@ -588,19 +588,24 @@ actions: type: info message: "${response.out}" remove_ssl_cert: + - if: ${settings.confirm} != true + return: + type: error + message: "Confirmation checkbox must be checked to proceed with certificate removal." + - cmd[cp]: user: root commands: - - > - if [[ "${settings.confirm}" == "true" ]]; then - bash /home/litespeed/mbmanager/ssl-manager/ssl_manager.sh --domain="${settings.domain}" --remove-cert=yes --confirm=yes - else - echo "Confirmation checkbox must be checked to proceed with certificate removal." - exit 1 - fi - - return: - type: info - message: "${response.out}" + - bash /home/litespeed/mbmanager/ssl-manager/ssl_manager.sh --domain="${settings.domain}" --remove-cert=yes --confirm=yes + + - if: ${response.exitcode} == 0 + return: + type: success + message: "SSL certificate for '${settings.domain}' has been successfully removed." + - else: + return: + type: error + message: "Failed to remove SSL certificate: ${response.out}" responses: enableSuccess: diff --git a/scripts/ssl-manager/ssl_manager.sh b/scripts/ssl-manager/ssl_manager.sh index 833e1c9..2f586fc 100644 --- a/scripts/ssl-manager/ssl_manager.sh +++ b/scripts/ssl-manager/ssl_manager.sh @@ -764,11 +764,15 @@ remove_ssl_certificate() { return 1 fi - # Remove the HTTPS-domain listener section + # Remove the HTTPS-domain listener section - find both and tags to handle inconsistencies + grep -n -E "<(name|n)>HTTPS-${domain}" "$config_file" > /dev/null || { + log "No listener found for domain ${domain}, continuing with certificate removal only."; + } + awk -v domain="$domain" ' BEGIN { skip = 0; } - /HTTPS-'"$domain"'<\/name>/,/<\/listener>/ { - if ($0 ~ /HTTPS-'"$domain"'<\/name>/) { + /HTTPS-'"$domain"'/,/<\/listener>/ { + if ($0 ~ /HTTPS-'"$domain"'/) { skip = 1; print ""; } @@ -785,21 +789,29 @@ remove_ssl_certificate() { log "Removing domain-specific virtual host if it exists..." local vhost_name="${domain//[.]/_}" - awk -v vhost="$vhost_name" ' - BEGIN { skip = 0; } - /'"$vhost"'<\/name>/,/<\/virtualHost>/ { - if ($0 ~ /'"$vhost"'<\/name>/) { - skip = 1; - print ""; - } - if ($0 ~ /<\/virtualHost>/ && skip == 1) { - skip = 0; - next; - } - if (skip) next; + # Check if virtualhost exists + grep -n -E "<(name|n)>${vhost_name}" "$config_file" > /dev/null || { + log "No virtual host found for ${vhost_name}, skipping this step."; + cp "$temp_file" "${temp_file}.new"; } - { if (!skip) print; } - ' "$temp_file" > "${temp_file}.new" + + if [ ! -f "${temp_file}.new" ]; then + awk -v vhost="$vhost_name" ' + BEGIN { skip = 0; } + /'"$vhost"'/,/<\/virtualHost>/ { + if ($0 ~ /'"$vhost"'/) { + skip = 1; + print ""; + } + if ($0 ~ /<\/virtualHost>/ && skip == 1) { + skip = 0; + next; + } + if (skip) next; + } + { if (!skip) print; } + ' "$temp_file" > "${temp_file}.new" + fi # 4. Remove any domain mappings from shared listeners log "Removing domain mappings from shared listeners..."