Fix hostname/IP validation to prevent whitespace input in the SSL and Create New Service form (closes #114)
This commit is contained in:
@@ -25,6 +25,10 @@ export const useServiceSchema = () => {
|
||||
type: z.enum(["http", "ping", "tcp", "dns"]),
|
||||
url: z.string()
|
||||
.min(1, t("urlDomainHostRequired"))
|
||||
.refine(
|
||||
(value) => !/\s/.test(value),
|
||||
t("spacesNotAllowed")
|
||||
)
|
||||
.refine(
|
||||
(value) => value.trim().length > 0,
|
||||
t("enterValidUrlHostnameDomain")
|
||||
|
||||
@@ -17,15 +17,6 @@ import { alertConfigService, AlertConfiguration } from "@/services/alertConfigSe
|
||||
import { sslNotificationTemplateService, SslNotificationTemplate } from "@/services/sslNotificationTemplateService";
|
||||
import { useLanguage } from "@/contexts/LanguageContext";
|
||||
|
||||
const formSchema = z.object({
|
||||
domain: z.string().min(1, "Domain is required"),
|
||||
warning_threshold: z.coerce.number().int().min(1).max(365),
|
||||
expiry_threshold: z.coerce.number().int().min(1).max(30),
|
||||
notification_channels: z.array(z.string()).optional(),
|
||||
alert_template: z.string().optional(),
|
||||
check_interval: z.coerce.number().int().min(1).max(30).optional()
|
||||
});
|
||||
|
||||
interface AddSSLCertificateFormProps {
|
||||
onSubmit: (data: AddSSLCertificateDto) => Promise<void>;
|
||||
onCancel: () => void;
|
||||
@@ -38,6 +29,21 @@ export const AddSSLCertificateForm = ({
|
||||
isPending = false
|
||||
}: AddSSLCertificateFormProps) => {
|
||||
const { t } = useLanguage();
|
||||
|
||||
const formSchema = z.object({
|
||||
domain: z.string()
|
||||
.min(1, t("domain") + " is required")
|
||||
.refine(
|
||||
(value) => !/\s/.test(value),
|
||||
t("spacesNotAllowed")
|
||||
),
|
||||
warning_threshold: z.coerce.number().int().min(1).max(365),
|
||||
expiry_threshold: z.coerce.number().int().min(1).max(30),
|
||||
notification_channels: z.array(z.string()).optional(),
|
||||
alert_template: z.string().optional(),
|
||||
check_interval: z.coerce.number().int().min(1).max(30).optional()
|
||||
});
|
||||
|
||||
const [alertConfigs, setAlertConfigs] = useState<AlertConfiguration[]>([]);
|
||||
const [sslTemplates, setSslTemplates] = useState<SslNotificationTemplate[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
@@ -154,7 +160,6 @@ export const AddSSLCertificateForm = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="expiry_threshold"
|
||||
@@ -189,7 +194,6 @@ export const AddSSLCertificateForm = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="notification_channels"
|
||||
@@ -289,7 +293,6 @@ export const AddSSLCertificateForm = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={onCancel}>{t('cancel')}</Button>
|
||||
<Button type="submit" disabled={isPending || isLoading}>
|
||||
|
||||
@@ -88,6 +88,7 @@ export const servicesTranslations: ServicesTranslations = {
|
||||
serviceNameRequired: "Service name is required",
|
||||
urlDomainHostRequired: "URL/Domain/Host is required",
|
||||
enterValidUrlHostnameDomain: "Please enter a valid URL, hostname, or domain",
|
||||
spacesNotAllowed: "Spaces are not allowed",
|
||||
|
||||
// Dashboard
|
||||
upServices: "UP SERVICES",
|
||||
|
||||
@@ -88,6 +88,7 @@ export const servicesTranslations: ServicesTranslations = {
|
||||
serviceNameRequired: "តម្រូវឱ្យមានឈ្មោះសេវាកម្ម",
|
||||
urlDomainHostRequired: "តម្រូវឱ្យមាន URL/ដែន/ម៉ាស៊ីន",
|
||||
enterValidUrlHostnameDomain: "សូមបញ្ចូល URL, ឈ្មោះម៉ាស៊ីន ឬដែនដែលត្រឹមត្រូវ",
|
||||
spacesNotAllowed: "មិនអនុញ្ញាតឱ្យមានចន្លោះទំនេរទេ",
|
||||
|
||||
// Dashboard
|
||||
upServices: "សេវាកម្មដំណើរការ",
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
|
||||
export interface ServicesTranslations {
|
||||
|
||||
serviceStatus: string;
|
||||
uptime: string;
|
||||
lastChecked: string;
|
||||
noServices: string;
|
||||
currentlyMonitoring: string;
|
||||
retry: string;
|
||||
overview: string;
|
||||
newService: string;
|
||||
rowsPerPage: string;
|
||||
search: string;
|
||||
allTypes: string;
|
||||
createNewService: string;
|
||||
createNewServiceDesc: string;
|
||||
serviceStatus: string;
|
||||
uptime: string;
|
||||
lastChecked: string;
|
||||
noServices: string;
|
||||
currentlyMonitoring: string;
|
||||
retry: string;
|
||||
overview: string;
|
||||
newService: string;
|
||||
rowsPerPage: string;
|
||||
search: string;
|
||||
allTypes: string;
|
||||
createNewService: string;
|
||||
createNewServiceDesc: string;
|
||||
|
||||
// ServiceBasicFields.tsx
|
||||
serviceName: string;
|
||||
@@ -87,6 +87,7 @@ export interface ServicesTranslations {
|
||||
serviceNameRequired: string;
|
||||
urlDomainHostRequired: string;
|
||||
enterValidUrlHostnameDomain: string;
|
||||
spacesNotAllowed: string;
|
||||
|
||||
// Dashboard
|
||||
upServices: string;
|
||||
|
||||
@@ -112,4 +112,5 @@ export interface SSLTranslations {
|
||||
lastNotification: string;
|
||||
collectionId: string;
|
||||
noCertificatesFound: string;
|
||||
spacesNotAllowed: string;
|
||||
}
|
||||
Reference in New Issue
Block a user