Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add pihole integration #860

Merged
merged 4 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions public/locales/en/modules/dns-hole-controls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"descriptor": {
"name": "DNS hole controls",
"description": "Control PiHole or AdGuard from your dashboard"
},
"card": {
"buttons": {
"enableAll": "Enable all",
"disableAll": "Disable all"
},
"status": {
"enabled": "Enabled",
"disabled": "Disabled"
}
}
}
21 changes: 21 additions & 0 deletions public/locales/en/modules/dns-hole-summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"descriptor": {
"name": "DNS hole summary",
"description": "Displays important data from PiHole or AdGuard",
"settings": {
"title": "Settings for DNS Hole summary",
"usePiHoleColors": {
"label": "Use colors from PiHole"
}
}
},
"card": {
"metrics": {
"domainsOnAdlist": "Domains on adlists",
"queriesToday": "Queries today",
"adsBlockedTodayPercentage": "{{percentage}}%",
"queriesBlockedTodayPercentage": "blocked today",
manuel-rw marked this conversation as resolved.
Show resolved Hide resolved
"queriesBlockedToday": "blocked today"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export const IntegrationSelector = ({ form }: IntegrationSelectorProps) => {
image: 'https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/png/plex.png',
label: 'Plex',
},
{
value: 'pihole',
image: 'https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/png/pihole.png',
label: 'PiHole',
},
].filter((x) => Object.keys(integrationFieldProperties).includes(x.value));

const getNewProperties = (value: string | null): AppIntegrationPropertyType[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ export const AvailableElementTypes = ({
icon={<IconBoxAlignTop size={40} strokeWidth={1.3} />}
onClick={onClickCreateCategory}
/>
{/*<ElementItem
name="Static Element"
icon={<IconTextResize size={40} strokeWidth={1.3} />}
onClick={onOpenStaticElements}
/>*/}
</Group>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const GenericAvailableElementType = ({
: image;

return (
<Grid.Col span="auto">
<Grid.Col xs={12} sm={4} md={3}>
<Card style={{ height: '100%' }}>
<Stack justify="space-between" style={{ height: '100%' }}>
<Stack spacing="xs">
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/Wrappers/WrapperContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { GridStack } from 'fily-publish-gridstack';
import { MutableRefObject, RefObject } from 'react';
import { AppType } from '../../../types/app';
import Widgets from '../../../widgets';
import { IWidget, IWidgetDefinition } from '../../../widgets/widgets';
import { WidgetWrapper } from '../../../widgets/WidgetWrapper';
import { IWidget, IWidgetDefinition } from '../../../widgets/widgets';
import { appTileDefinition } from '../Tiles/Apps/AppTile';
import { GridstackTileWrapper } from '../Tiles/TileWrapper';
import { useGridstackStore } from './gridstack/store';
Expand Down
3 changes: 1 addition & 2 deletions src/pages/api/configs/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import Consola from 'consola';

import { NextApiRequest, NextApiResponse } from 'next';

import { BackendConfigType, ConfigType } from '../../../types/config';
import { getConfig } from '../../../tools/config/getConfig';
import widgets from '../../../widgets';
import { BackendConfigType, ConfigType } from '../../../types/config';
import { IRssWidget } from '../../../widgets/rss/RssWidgetTile';

function Put(req: NextApiRequest, res: NextApiResponse) {
Expand Down
53 changes: 53 additions & 0 deletions src/pages/api/modules/dns-hole/control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable no-await-in-loop */
import { z } from 'zod';
import { getCookie } from 'cookies-next';
import { NextApiRequest, NextApiResponse } from 'next';
import { getConfig } from '../../../../tools/config/getConfig';
import { findAppProperty } from '../../../../tools/client/app-properties';
import { PiHoleClient } from '../../../../tools/server/sdk/pihole/piHole';

const getQuerySchema = z.object({
status: z.enum(['enabled', 'disabled']),
});

export const Post = async (request: NextApiRequest, response: NextApiResponse) => {
const configName = getCookie('config-name', { req: request });
const config = getConfig(configName?.toString() ?? 'default');

const parseResult = getQuerySchema.safeParse(request.query);

if (!parseResult.success) {
response.status(400).json({ message: 'invalid query parameters, please specify the status' });
return;
}

const applicableApps = config.apps.filter((x) => x.integration?.type === 'pihole');

for (let i = 0; i < applicableApps.length; i += 1) {
const app = applicableApps[i];

const pihole = new PiHoleClient(
app.url,
findAppProperty(app, 'password')
);

switch (parseResult.data.status) {
case 'enabled':
await pihole.enable();
break;
case 'disabled':
await pihole.disable();
break;
}
}

response.status(200).json({});
};

export default async (request: NextApiRequest, response: NextApiResponse) => {
if (request.method === 'POST') {
return Post(request, response);
}

return response.status(405).json({});
};