From 9e6154b0de4a83c9dbe835b27dc4f87ccb046577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20R=C3=B6gl-Brunner?= Date: Thu, 29 Jan 2026 13:40:19 +0100 Subject: [PATCH] fix: allow domain names for APT Cacher in container creation UI - Add validateHostname and validateAptCacherAddress (IPv4 or hostname) - Use new validator for var_apt_cacher_ip; error message: Invalid IPv4 or hostname - Label: APT Cacher host or IP; placeholder shows IP or hostname example Fixes #404 --- src/app/_components/ConfigurationModal.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/app/_components/ConfigurationModal.tsx b/src/app/_components/ConfigurationModal.tsx index 45fc8c5..13d63f4 100644 --- a/src/app/_components/ConfigurationModal.tsx +++ b/src/app/_components/ConfigurationModal.tsx @@ -199,6 +199,17 @@ export function ConfigurationModal({ return !isNaN(num) && num > 0; }; + const validateHostname = (hostname: string): boolean => { + if (!hostname || hostname.length > 253) return false; + const label = /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/; + const labels = hostname.split('.'); + return labels.length >= 1 && labels.every(l => l.length >= 1 && l.length <= 63 && label.test(l)); + }; + + const validateAptCacherAddress = (value: string): boolean => { + return validateIPv4(value) || validateHostname(value); + }; + const validateForm = (): boolean => { const newErrors: Record = {}; @@ -216,8 +227,8 @@ export function ConfigurationModal({ if (advancedVars.var_ns && !validateIPv4(advancedVars.var_ns as string)) { newErrors.var_ns = 'Invalid IPv4 address'; } - if (advancedVars.var_apt_cacher_ip && !validateIPv4(advancedVars.var_apt_cacher_ip as string)) { - newErrors.var_apt_cacher_ip = 'Invalid IPv4 address'; + if (advancedVars.var_apt_cacher_ip && !validateAptCacherAddress(advancedVars.var_apt_cacher_ip as string)) { + newErrors.var_apt_cacher_ip = 'Invalid IPv4 address or hostname'; } // Validate IPv4 CIDR if network mode is static const netValue = advancedVars.var_net; @@ -904,13 +915,13 @@ export function ConfigurationModal({
updateAdvancedVar('var_apt_cacher_ip', e.target.value)} - placeholder="192.168.1.10" + placeholder="192.168.1.10 or apt-cacher.internal" className={errors.var_apt_cacher_ip ? 'border-destructive' : ''} /> {errors.var_apt_cacher_ip && (