diff --git a/src/app/[orgId]/settings/resources/[resourceId]/proxy/page.tsx b/src/app/[orgId]/settings/resources/[resourceId]/proxy/page.tsx index 2ca6244f..c9c5eea6 100644 --- a/src/app/[orgId]/settings/resources/[resourceId]/proxy/page.tsx +++ b/src/app/[orgId]/settings/resources/[resourceId]/proxy/page.tsx @@ -128,7 +128,7 @@ export default function ReverseProxyTargets(props: { return true; }, { - message: t('proxyErrorInvalidHeader') + message: t("proxyErrorInvalidHeader") } ) }); @@ -146,7 +146,7 @@ export default function ReverseProxyTargets(props: { return true; }, { - message: t('proxyErrorTls') + message: t("proxyErrorTls") } ) }); @@ -203,10 +203,10 @@ export default function ReverseProxyTargets(props: { console.error(err); toast({ variant: "destructive", - title: t('targetErrorFetch'), + title: t("targetErrorFetch"), description: formatAxiosError( err, - t('targetErrorFetchDescription') + t("targetErrorFetchDescription") ) }); } finally { @@ -228,10 +228,10 @@ export default function ReverseProxyTargets(props: { console.error(err); toast({ variant: "destructive", - title: t('siteErrorFetch'), + title: t("siteErrorFetch"), description: formatAxiosError( err, - t('siteErrorFetchDescription') + t("siteErrorFetchDescription") ) }); } @@ -251,8 +251,8 @@ export default function ReverseProxyTargets(props: { if (isDuplicate) { toast({ variant: "destructive", - title: t('targetErrorDuplicate'), - description: t('targetErrorDuplicateDescription') + title: t("targetErrorDuplicate"), + description: t("targetErrorDuplicateDescription") }); return; } @@ -261,11 +261,23 @@ export default function ReverseProxyTargets(props: { // make sure that the target IP is within the site subnet const targetIp = data.ip; const subnet = site.subnet; - if (!isIPInSubnet(targetIp, subnet)) { + try { + if (!isIPInSubnet(targetIp, subnet)) { + toast({ + variant: "destructive", + title: t("targetWireGuardErrorInvalidIp"), + description: t( + "targetWireGuardErrorInvalidIpDescription" + ) + }); + return; + } + } catch (error) { + console.error(error); toast({ variant: "destructive", - title: t('targetWireGuardErrorInvalidIp'), - description: t('targetWireGuardErrorInvalidIpDescription') + title: t("targetWireGuardErrorInvalidIp"), + description: t("targetWireGuardErrorInvalidIpDescription") }); return; } @@ -343,8 +355,8 @@ export default function ReverseProxyTargets(props: { updateResource({ stickySession: stickySessionData.stickySession }); toast({ - title: t('targetsUpdated'), - description: t('targetsUpdatedDescription') + title: t("targetsUpdated"), + description: t("targetsUpdatedDescription") }); setTargetsToRemove([]); @@ -353,10 +365,10 @@ export default function ReverseProxyTargets(props: { console.error(err); toast({ variant: "destructive", - title: t('targetsErrorUpdate'), + title: t("targetsErrorUpdate"), description: formatAxiosError( err, - t('targetsErrorUpdateDescription') + t("targetsErrorUpdateDescription") ) }); } finally { @@ -377,17 +389,17 @@ export default function ReverseProxyTargets(props: { tlsServerName: data.tlsServerName || null }); toast({ - title: t('targetTlsUpdate'), - description: t('targetTlsUpdateDescription') + title: t("targetTlsUpdate"), + description: t("targetTlsUpdateDescription") }); } catch (err) { console.error(err); toast({ variant: "destructive", - title: t('targetErrorTlsUpdate'), + title: t("targetErrorTlsUpdate"), description: formatAxiosError( err, - t('targetErrorTlsUpdateDescription') + t("targetErrorTlsUpdateDescription") ) }); } finally { @@ -406,17 +418,17 @@ export default function ReverseProxyTargets(props: { setHostHeader: data.setHostHeader || null }); toast({ - title: t('proxyUpdated'), - description: t('proxyUpdatedDescription') + title: t("proxyUpdated"), + description: t("proxyUpdatedDescription") }); } catch (err) { console.error(err); toast({ variant: "destructive", - title: t('proxyErrorUpdate'), + title: t("proxyErrorUpdate"), description: formatAxiosError( err, - t('proxyErrorUpdateDescription') + t("proxyErrorUpdateDescription") ) }); } finally { @@ -427,7 +439,7 @@ export default function ReverseProxyTargets(props: { const columns: ColumnDef[] = [ { accessorKey: "ip", - header: t('targetAddr'), + header: t("targetAddr"), cell: ({ row }) => ( ( ( removeTarget(row.original.targetId)} > - {t('delete')} + {t("delete")} @@ -514,7 +526,7 @@ export default function ReverseProxyTargets(props: { if (resource.http) { const methodCol: ColumnDef = { accessorKey: "method", - header: t('method'), + header: t("method"), cell: ({ row }) => ( - + @@ -662,7 +682,9 @@ export default function ReverseProxyTargets(props: { name="ip" render={({ field }) => ( - {t('targetAddr')} + + {t("targetAddr")} + @@ -695,7 +717,9 @@ export default function ReverseProxyTargets(props: { name="port" render={({ field }) => ( - {t('targetPort')} + + {t("targetPort")} + - {t('targetSubmit')} + {t("targetSubmit")} @@ -758,13 +782,13 @@ export default function ReverseProxyTargets(props: { colSpan={columns.length} className="h-24 text-center" > - {t('targetNoOne')} + {t("targetNoOne")} )} - {t('targetNoOneDescription')} + {t("targetNoOneDescription")} @@ -775,7 +799,7 @@ export default function ReverseProxyTargets(props: { disabled={targetsLoading} form="targets-settings-form" > - {t('targetsSubmit')} + {t("targetsSubmit")} @@ -785,10 +809,10 @@ export default function ReverseProxyTargets(props: { - {t('targetTlsSettings')} + {t("targetTlsSettings")} - {t('targetTlsSettingsDescription')} + {t("targetTlsSettingsDescription")} @@ -809,7 +833,9 @@ export default function ReverseProxyTargets(props: {

- {t('targetTlsSettingsAdvanced')} + {t( + "targetTlsSettingsAdvanced" + )}

@@ -858,7 +886,9 @@ export default function ReverseProxyTargets(props: { render={({ field }) => ( - {t('targetTlsSni')} + {t( + "targetTlsSni" + )} - {t('targetTlsSniDescription')} + {t( + "targetTlsSniDescription" + )} @@ -884,17 +916,17 @@ export default function ReverseProxyTargets(props: { loading={httpsTlsLoading} form="tls-settings-form" > - {t('targetTlsSubmit')} + {t("targetTlsSubmit")} - {t('proxyAdditional')} + {t("proxyAdditional")} - {t('proxyAdditionalDescription')} + {t("proxyAdditionalDescription")} @@ -913,13 +945,15 @@ export default function ReverseProxyTargets(props: { render={({ field }) => ( - {t('proxyCustomHeader')} + {t("proxyCustomHeader")} - {t('proxyCustomHeaderDescription')} + {t( + "proxyCustomHeaderDescription" + )} @@ -935,7 +969,7 @@ export default function ReverseProxyTargets(props: { loading={proxySettingsLoading} form="proxy-settings-form" > - {t('targetTlsSubmit')} + {t("targetTlsSubmit")} @@ -950,10 +984,8 @@ function isIPInSubnet(subnet: string, ip: string): boolean { const [subnetIP, maskBits] = subnet.split("/"); const mask = parseInt(maskBits); - const t = useTranslations(); - if (mask < 0 || mask > 32) { - throw new Error(t('subnetMaskErrorInvalid')); + throw new Error("subnetMaskErrorInvalid"); } // Convert IP addresses to binary numbers @@ -970,17 +1002,16 @@ function isIPInSubnet(subnet: string, ip: string): boolean { function ipToNumber(ip: string): number { // Validate IP address format const parts = ip.split("."); - const t = useTranslations(); if (parts.length !== 4) { - throw new Error(t('ipAddressErrorInvalidFormat')); + throw new Error("ipAddressErrorInvalidFormat"); } // Convert IP octets to 32-bit number return parts.reduce((num, octet) => { const oct = parseInt(octet); if (isNaN(oct) || oct < 0 || oct > 255) { - throw new Error(t('ipAddressErrorInvalidOctet')); + throw new Error("ipAddressErrorInvalidOctet"); } return (num << 8) + oct; }, 0);