mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 16:34:52 +03:00
fix(ssl): preserve independent IP certificates and enable Alpine renewal
This commit is contained in:
+13
-2
@@ -223,6 +223,15 @@ ip_ssl_shell_quote() {
|
||||
printf "'%s'" "$value"
|
||||
}
|
||||
|
||||
ip_ssl_enable_openrc_cron() {
|
||||
[[ "$1" == alpine ]] || return 0
|
||||
if rc-service crond status >/dev/null 2>&1; then return 0; fi
|
||||
if ! rc-update add dcron default || ! rc-service dcron start; then
|
||||
printf 'Could not enable the OpenRC cron service for IP certificate renewal.\n' >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# The public paths always resolve through one generation pointer after migration.
|
||||
ip_ssl_link() {
|
||||
local state="$1" target="$2" link="$3"
|
||||
@@ -287,12 +296,14 @@ ip_ssl_retire_legacy() {
|
||||
fi
|
||||
done <<< "$destinations"
|
||||
done
|
||||
# The requested entries can also be unfinished orders with no destinations.
|
||||
# Retire unfinished orders for this IP. A completed cert without saved
|
||||
# destinations may be in use directly by another service.
|
||||
for name in "$ipv4" "${ipv4}_ecc"; do
|
||||
entry="$home/$name"
|
||||
conf="$entry/$ipv4.conf"
|
||||
[[ -d "$entry" && ! -L "$entry" ]] || continue
|
||||
if [[ ! -f "$conf" ]] || ! grep -Eq "^Le_(Real(Cert|Key|CACert|FullChain)Path|ReloadCmd|DeployHook)='[^']+" "$conf"; then
|
||||
[[ ! -s "$entry/fullchain.cer" && ! -s "$entry/$ipv4.cer" ]] || continue
|
||||
if [[ ! -f "$conf" ]] || ! grep -Eq "^Le_(Real(Cert|Key|CACert|FullChain)Path|(Pre|Post|Renew|Deploy)Hook|ReloadCmd)='[^']+" "$conf"; then
|
||||
retire+=("$name")
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -254,6 +254,9 @@ if ! live_is new || [[ ! -f "$state/current/reload-pending" ]]; then fail 'reloa
|
||||
[[ "$(stat -Lc %a "$cert_dir/privkey.pem")" == 600 ]] || fail 'private key permissions changed'
|
||||
[[ "$(stat -Lc %a "$cert_dir/fullchain.pem")" == 644 ]] || fail 'certificate permissions changed'
|
||||
[[ ! -e "$legacy/$ipv4" && ! -e "$legacy/${ipv4}_ecc" ]] || fail 'old cron can still target live paths'
|
||||
mkdir "$legacy/$ipv4"
|
||||
cp "$TEMP/old.pem" "$legacy/$ipv4/fullchain.cer"
|
||||
printf "Le_Alt='no'\n" > "$legacy/$ipv4/$ipv4.conf"
|
||||
[[ "$(grep -cx 'arg=--listen-v4' "$ACME_LOG")" == 1 && "$(grep -cx 'arg=--listen-v6' "$ACME_LOG")" == 1 ]] || fail 'dual-stack flags absent'
|
||||
[[ "$(grep -cx "arg=$ipv6" "$ACME_LOG")" == 1 ]] || fail 'IPv6 SAN duplicated or missing'
|
||||
grep -Fq '/unrelated-cron' "$CRON_FILE" || fail 'crontab lost an unrelated entry'
|
||||
@@ -365,6 +368,7 @@ if wait "$failed_pid"; then fail 'injected promotion failure reported success';
|
||||
wait "$waiting_pid" || { cat "$TEMP/waiting-promotion"; fail 'second promotion failed'; }
|
||||
unset -f mv
|
||||
live_is later || fail 'rollback overwrote a newer promotion'
|
||||
cmp "$TEMP/old.pem" "$legacy/$ipv4/fullchain.cer" || fail 'an unrelated certificate using the same IP was retired'
|
||||
printf 'PASS: a failed promotion cannot roll back another operation on the same paths\n'
|
||||
|
||||
before=$(wc -l < "$ACME_LOG")
|
||||
|
||||
@@ -48,7 +48,14 @@ printf 'PASS: installer consent, explicit configuration, no unattended prompts,
|
||||
|
||||
setup_ip_certificate() { return 1; }
|
||||
systemctl() { :; }
|
||||
rc-service() { :; }
|
||||
rc-service() {
|
||||
case "$*" in
|
||||
'x-ui stop') : ;;
|
||||
'crond status') [[ "${CROND_RUNNING:-0}" == 1 ]] ;;
|
||||
'dcron start') printf 'rc-service %s\n' "$*" >> "$TEMP/cron" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
NONINTERACTIVE=1
|
||||
export XUI_SSL_IPV6='2001:4860::1'
|
||||
for release in ubuntu alpine; do
|
||||
@@ -58,3 +65,11 @@ for release in ubuntu alpine; do
|
||||
[[ "$SSL_HOST" == 198.51.100.8 ]] || fail 'the installer lost its access host after a failed certificate'
|
||||
done
|
||||
printf 'PASS: a failed IP certificate is reported and the installer carries on on systemd/OpenRC\n'
|
||||
|
||||
rc-update() { printf 'rc-update %s\n' "$*" >> "$TEMP/cron"; }
|
||||
ip_ssl_enable_openrc_cron ubuntu
|
||||
CROND_RUNNING=1 ip_ssl_enable_openrc_cron alpine
|
||||
[[ ! -e "$TEMP/cron" ]] || fail 'an existing cron service was disturbed'
|
||||
ip_ssl_enable_openrc_cron alpine
|
||||
[[ "$(cat "$TEMP/cron")" == $'rc-update add dcron default\nrc-service dcron start' ]] || fail 'Alpine cron was not enabled and started'
|
||||
printf 'PASS: IP setup keeps an existing daemon and enables Alpine cron when needed\n'
|
||||
|
||||
Reference in New Issue
Block a user