[PR #4004] [MERGED] Fix SSL domain setup on reinstall: reuse existing certs and avoid false success/failure logs #5581

Closed
opened 2026-10-31 20:47:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4004
Author: @Kookiejarz
Created: 4/7/2026
Status: ✅ Merged
Merged: 4/17/2026
Merged by: @MHSanaei

Base: main ← Head: main


📝 Commits (4)

  • e1a09b5 perf: replace /dev/urandom | tr with openssl rand to fix CPU spike
  • 09d3447 Merge branch 'MHSanaei:main' into main
  • 99ce1fc fix: add cron to default package installation and improve SSL certificate handling
  • 03e7e4c Reworked --installcert success criteria, cleanup behavior adjusted.

📊 Changes

3 files changed (+156 additions, -99 deletions)

View changed files

📝 install.sh (+59 -38)
📝 update.sh (+60 -39)
📝 x-ui.sh (+37 -22)

📄 Description

What is the pull request?

closes #4002 #3851 #3979

This PR fixes SSL setup logic in interactive install/update scripts for domain certificates.

It resolves cases where:

  • an existing cert is detected but not applied to panel paths,
  • acme.sh --installcert returns non-zero only because --reloadcmd failed (while cert files were already installed),
  • outer flow still prints success even when ssl_cert_issue failed.

Problem

During reinstall / setup with an already-issued domain cert, scripts could show contradictory output:

  • Installing certificate failed, exiting.
  • followed by ✓ SSL certificate configured successfully with domain: ...

Also, existing certs were treated as hard failure (return 1 / exit 1) instead of being reused and installed to panel cert paths.

Root Cause

  1. Existing certificate handling in ssl_cert_issue aborted early.
  2. --installcert return code was used as strict success criteria, but acme.sh can exit non-zero when reload command fails even if cert files are written.
  3. Caller (prompt_and_setup_ssl) did not gate success message on ssl_cert_issue return status.

Changes

In domain SSL flow, when ${domain} already exists in acme.sh --list, scripts
now:

  • log that existing cert is found,
  • skip re-issue,
  • continue to install cert files to /root/cert/${domain}/... and proceed with panel cert-path setup flow.

For acme.sh --installcert:

  • keep execution even if reloadcmd fails (... || true),
  • treat installation as successful if both files exist:
    • /root/cert/${domain}/privkey.pem
    • /root/cert/${domain}/fullchain.pem

This avoids false negatives caused only by reload command environment differences.

In prompt_and_setup_ssl (domain option):

  • now checks if ssl_cert_issue; then ... else ... fi
  • only prints SSL certificate configured successfully on real success
  • uses SSL_ISSUED_DOMAIN from current flow (fallback to list lookup only if
    needed)

Files Changed

  • install.sh
  • update.sh
  • x-ui.sh

Validation

  • Reproduced with an existing domain cert in acme.sh --list.
  • Confirmed flow now reuses existing cert and proceeds to panel cert path setup.

Which part of the application is affected by the change?

  • Frontend
  • Backend

Type of Changes

  • Bug fix
  • New feature
  • Refactoring
  • Other

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4004 **Author:** [@Kookiejarz](https://github.com/Kookiejarz) **Created:** 4/7/2026 **Status:** ✅ Merged **Merged:** 4/17/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (4) - [`e1a09b5`](https://github.com/MHSanaei/3x-ui/commit/e1a09b5f682ceebf3f3bce279dde5a6faa66492c) perf: replace /dev/urandom | tr with openssl rand to fix CPU spike - [`09d3447`](https://github.com/MHSanaei/3x-ui/commit/09d3447cb6f54decd923e95aa25086beb3009d43) Merge branch 'MHSanaei:main' into main - [`99ce1fc`](https://github.com/MHSanaei/3x-ui/commit/99ce1fcba5fd8005b1fd841869d60b7b153e4805) fix: add cron to default package installation and improve SSL certificate handling - [`03e7e4c`](https://github.com/MHSanaei/3x-ui/commit/03e7e4cd2073c981f6108f11221a68679e9e4ac8) Reworked `--installcert` success criteria, cleanup behavior adjusted. ### 📊 Changes **3 files changed** (+156 additions, -99 deletions) <details> <summary>View changed files</summary> 📝 `install.sh` (+59 -38) 📝 `update.sh` (+60 -39) 📝 `x-ui.sh` (+37 -22) </details> ### 📄 Description ## What is the pull request? closes #4002 #3851 #3979 This PR fixes SSL setup logic in interactive install/update scripts for domain certificates. It resolves cases where: - an existing cert is detected but not applied to panel paths, - acme.sh --installcert returns non-zero only because --reloadcmd failed (while cert files were already installed), - outer flow still prints success even when ssl_cert_issue failed. ## Problem During reinstall / setup with an already-issued domain cert, scripts could show contradictory output: - Installing certificate failed, exiting. - followed by ✓ SSL certificate configured successfully with domain: ... Also, existing certs were treated as hard failure (return 1 / exit 1) instead of being reused and installed to panel cert paths. ## Root Cause 1. Existing certificate handling in ssl_cert_issue aborted early. 2. --installcert return code was used as strict success criteria, but acme.sh can exit non-zero when reload command fails even if cert files are written. 3. Caller (prompt_and_setup_ssl) did not gate success message on ssl_cert_issue return status. ## Changes In domain SSL flow, when ${domain} already exists in acme.sh --list, scripts now: - log that existing cert is found, - skip re-issue, - continue to install cert files to /root/cert/${domain}/... and proceed with panel cert-path setup flow. For acme.sh --installcert: - keep execution even if reloadcmd fails (... || true), - treat installation as successful if both files exist: - /root/cert/${domain}/privkey.pem - /root/cert/${domain}/fullchain.pem This avoids false negatives caused only by reload command environment differences. In prompt_and_setup_ssl (domain option): - now checks if ssl_cert_issue; then ... else ... fi - only prints SSL certificate configured successfully on real success - uses SSL_ISSUED_DOMAIN from current flow (fallback to list lookup only if needed) ## Files Changed - install.sh - update.sh - x-ui.sh ## Validation - Reproduced with an existing domain cert in `acme.sh --list`. - Confirmed flow now reuses existing cert and proceeds to panel cert path setup. ## Which part of the application is affected by the change? - [ ] Frontend - [x] Backend ## Type of Changes - [x] Bug fix - [ ] New feature - [ ] Refactoring - [ ] Other --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:47:57 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5581
No description provided.