Add warning for downgrading dash. url protocol

This commit is contained in:
Manuel
2023-02-06 20:52:36 +01:00
parent ebd0802003
commit 58d42ea00c
2 changed files with 31 additions and 11 deletions

View File

@@ -28,7 +28,11 @@
"title": "Dash.", "title": "Dash.",
"errors": { "errors": {
"noService": "No Dash. service found. Please add one to your Homarr dashboard or set a Dash. URL in the module options", "noService": "No Dash. service found. Please add one to your Homarr dashboard or set a Dash. URL in the module options",
"noInformation": "Cannot acquire information from dash. - are you running the latest version?" "noInformation": "Cannot acquire information from dash. - are you running the latest version?",
"protocolDowngrade": {
"title": "Detected protocol downgrade",
"text": "The protocol to your Dash. instance is being downgraded. This is security risk, since HTTP is unencrypted and attackers could abuse this connection. Make sure that Dash. is running on HTTPS too or downgrade Homarr to HTTP (not recommended)."
}
}, },
"graphs": { "graphs": {
"storage": { "storage": {

View File

@@ -1,4 +1,5 @@
import { createStyles, Group, Title } from '@mantine/core'; import { Center, createStyles, Group, Stack, Text, Title } from '@mantine/core';
import { IconUnlink } from '@tabler/icons';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import axios from 'axios'; import axios from 'axios';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
@@ -55,7 +56,7 @@ const definition = defineWidget({
component: DashDotTile, component: DashDotTile,
}); });
export type IDashDotTile = IWidget<typeof definition['id'], typeof definition>; export type IDashDotTile = IWidget<(typeof definition)['id'], typeof definition>;
interface DashDotTileProps { interface DashDotTileProps {
widget: IDashDotTile; widget: IDashDotTile;
@@ -66,11 +67,29 @@ function DashDotTile({ widget }: DashDotTileProps) {
const { t } = useTranslation('modules/dashdot'); const { t } = useTranslation('modules/dashdot');
const dashDotUrl = widget.properties.url; const dashDotUrl = widget.properties.url;
const locationProtocol = window.location.protocol;
const detectedProtocolDowngrade =
locationProtocol === 'https:' && dashDotUrl.toLowerCase().startsWith('http:');
const { data: info } = useDashDotInfo({ const { data: info } = useDashDotInfo({
dashDotUrl, dashDotUrl,
enabled: !detectedProtocolDowngrade,
}); });
if (detectedProtocolDowngrade) {
return (
<Center h="100%">
<Stack spacing="xs" align="center">
<IconUnlink size={40} strokeWidth={1.2} />
<Title order={5}>{t('card.errors.protocolDowngrade.title')}</Title>
<Text align="center" size="sm">
{t('card.errors.protocolDowngrade.text')}
</Text>
</Stack>
</Center>
);
}
const graphs = widget?.properties.graphs.map((graph) => ({ const graphs = widget?.properties.graphs.map((graph) => ({
id: graph, id: graph,
name: t(`card.graphs.${graph}.title`), name: t(`card.graphs.${graph}.title`),
@@ -80,12 +99,6 @@ function DashDotTile({ widget }: DashDotTileProps) {
(graph === 'storage' && widget.properties.storageMultiView), (graph === 'storage' && widget.properties.storageMultiView),
})); }));
const heading = (
<Title order={3} mb="xs">
{t('card.title')}
</Title>
);
const isCompact = widget?.properties.useCompactView ?? false; const isCompact = widget?.properties.useCompactView ?? false;
const isCompactStorageVisible = graphs?.some((g) => g.id === 'storage' && isCompact); const isCompactStorageVisible = graphs?.some((g) => g.id === 'storage' && isCompact);
@@ -100,7 +113,9 @@ function DashDotTile({ widget }: DashDotTileProps) {
return ( return (
<> <>
{heading} <Title order={3} mb="xs">
{t('card.title')}
</Title>
{!info && <p>{t('card.errors.noInformation')}</p>} {!info && <p>{t('card.errors.noInformation')}</p>}
{info && ( {info && (
<div className={classes.graphsContainer}> <div className={classes.graphsContainer}>
@@ -125,7 +140,7 @@ function DashDotTile({ widget }: DashDotTileProps) {
); );
} }
const useDashDotInfo = ({ dashDotUrl }: { dashDotUrl: string }) => { const useDashDotInfo = ({ dashDotUrl, enabled }: { dashDotUrl: string; enabled: boolean }) => {
const { name: configName } = useConfigContext(); const { name: configName } = useConfigContext();
return useQuery({ return useQuery({
refetchInterval: 50000, refetchInterval: 50000,
@@ -137,6 +152,7 @@ const useDashDotInfo = ({ dashDotUrl }: { dashDotUrl: string }) => {
}, },
], ],
queryFn: () => fetchDashDotInfo(configName), queryFn: () => fetchDashDotInfo(configName),
enabled,
}); });
}; };