From 5f531f2de1340f39fae89a3140d91ee86293f11c Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Mon, 7 Oct 2024 15:13:38 +0200 Subject: [PATCH] Set Cert paths for the panel Option to automatically set the web certificate and key file paths for the panel --- x-ui.sh | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/x-ui.sh b/x-ui.sh index 2827c2bf..615a7708 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -789,6 +789,7 @@ ssl_cert_issue_main() { echo -e "${green}\t2.${plain} Revoke" echo -e "${green}\t3.${plain} Force Renew" echo -e "${green}\t4.${plain} Show Existing Domains" + echo -e "${green}\t5.${plain} Set Cert paths for the panel" echo -e "${green}\t0.${plain} Back to Main Menu" read -p "Choose an option: " choice @@ -800,7 +801,6 @@ ssl_cert_issue_main() { ssl_cert_issue ;; 2) - # Auto-detect existing domains for revoking local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) if [ -z "$domains" ]; then echo "No certificates found to revoke." @@ -817,7 +817,6 @@ ssl_cert_issue_main() { fi ;; 3) - # Auto-detect existing domains for force renewal local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) if [ -z "$domains" ]; then echo "No certificates found to renew." @@ -834,7 +833,6 @@ ssl_cert_issue_main() { fi ;; 4) - # Show existing certificate paths for all domains local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) if [ -z "$domains" ]; then echo "No certificates found." @@ -853,7 +851,33 @@ ssl_cert_issue_main() { done fi ;; - *) + 5) + local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) + if [ -z "$domains" ]; then + echo "No certificates found." + else + echo "Available domains:" + echo "$domains" + read -p "Please choose a domain to set the panel paths: " domain + if [[ " $domains " =~ " $domain " ]]; then + local webCertFile="/root/cert/${domain}/fullchain.pem" + local webKeyFile="/root/cert/${domain}/privkey.pem" + + if [[ -f "${webCertFile}" && -f "${webKeyFile}" ]]; then + /usr/local/x-ui/x-ui setting -webCert "$webCertFile" + /usr/local/x-ui/x-ui setting -webCertKey "$webKeyFile" + echo "Panel paths set for domain: $domain" + echo " - Certificate File: $webCertFile" + echo " - Private Key File: $webKeyFile" + else + echo "Certificate or private key not found for domain: $domain." + fi + else + echo "Invalid domain entered." + fi + fi + ;; + *) echo "Invalid choice" ;; esac