mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-10-04 11:50:09 +00:00
404 hosts add update complete, fix certbot renewals
and remove the need for email and agreement on cert requests
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { intl } from "src/locale";
|
||||
|
||||
const validateString = (minLength = 0, maxLength = 0) => {
|
||||
if (minLength <= 0 && maxLength <= 0) {
|
||||
// this doesn't require translation
|
||||
@@ -6,12 +8,14 @@ const validateString = (minLength = 0, maxLength = 0) => {
|
||||
|
||||
return (value: string): string | undefined => {
|
||||
if (minLength && (typeof value === "undefined" || !value.length)) {
|
||||
return "This is required";
|
||||
return intl.formatMessage({ id: "error.required" });
|
||||
}
|
||||
if (minLength && value.length < minLength) {
|
||||
// TODO: i18n
|
||||
return `Minimum length is ${minLength} character${minLength === 1 ? "" : "s"}`;
|
||||
}
|
||||
if (maxLength && (typeof value === "undefined" || value.length > maxLength)) {
|
||||
// TODO: i18n
|
||||
return `Maximum length is ${maxLength} character${maxLength === 1 ? "" : "s"}`;
|
||||
}
|
||||
};
|
||||
@@ -26,12 +30,14 @@ const validateNumber = (min = -1, max = -1) => {
|
||||
return (value: string): string | undefined => {
|
||||
const int: number = +value;
|
||||
if (min > -1 && !int) {
|
||||
return "This is required";
|
||||
return intl.formatMessage({ id: "error.required" });
|
||||
}
|
||||
if (min > -1 && int < min) {
|
||||
// TODO: i18n
|
||||
return `Minimum is ${min}`;
|
||||
}
|
||||
if (max > -1 && int > max) {
|
||||
// TODO: i18n
|
||||
return `Maximum is ${max}`;
|
||||
}
|
||||
};
|
||||
@@ -40,12 +46,62 @@ const validateNumber = (min = -1, max = -1) => {
|
||||
const validateEmail = () => {
|
||||
return (value: string): string | undefined => {
|
||||
if (!value.length) {
|
||||
return "This is required";
|
||||
return intl.formatMessage({ id: "error.required" });
|
||||
}
|
||||
if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)) {
|
||||
return "Invalid email address";
|
||||
return intl.formatMessage({ id: "error.invalid-email" });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export { validateEmail, validateNumber, validateString };
|
||||
const validateDomain = (allowWildcards = false) => {
|
||||
return (d: string): boolean => {
|
||||
const dom = d.trim().toLowerCase();
|
||||
|
||||
if (dom.length < 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prevent wildcards
|
||||
if (!allowWildcards && dom.indexOf("*") !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prevent duplicate * in domain
|
||||
if ((dom.match(/\*/g) || []).length > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prevent some invalid characters
|
||||
if ((dom.match(/(@|,|!|&|\$|#|%|\^|\(|\))/g) || []).length > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This will match *.com type domains,
|
||||
return dom.match(/\*\.[^.]+$/m) === null;
|
||||
};
|
||||
};
|
||||
|
||||
const validateDomains = (allowWildcards = false, maxDomains?: number) => {
|
||||
const vDom = validateDomain(allowWildcards);
|
||||
|
||||
return (value: string[]): string | undefined => {
|
||||
if (!value.length) {
|
||||
return intl.formatMessage({ id: "error.required" });
|
||||
}
|
||||
|
||||
// Deny if the list of domains is hit
|
||||
if (maxDomains && value.length >= maxDomains) {
|
||||
return intl.formatMessage({ id: "error.max-domains" }, { max: maxDomains });
|
||||
}
|
||||
|
||||
// validate each domain
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
if (!vDom(value[i])) {
|
||||
return intl.formatMessage({ id: "error.invalid-domain" }, { domain: value[i] });
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export { validateEmail, validateNumber, validateString, validateDomains, validateDomain };
|
||||
|
Reference in New Issue
Block a user