2022-08-25 18:37:22 +03:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
import Widget from "../widget";
|
|
|
|
import Block from "../block";
|
|
|
|
|
2022-09-04 21:58:42 +03:00
|
|
|
import { formatApiUrl } from "utils/api-helpers";
|
|
|
|
|
2022-08-25 18:37:22 +03:00
|
|
|
export default function Pihole({ service }) {
|
|
|
|
const config = service.widget;
|
|
|
|
|
2022-09-04 21:58:42 +03:00
|
|
|
const { data: piholeData, error: piholeError } = useSWR(formatApiUrl(config, "api.php"));
|
2022-08-25 18:37:22 +03:00
|
|
|
|
|
|
|
if (piholeError) {
|
|
|
|
return <Widget error="PiHole API Error" />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!piholeData) {
|
|
|
|
return (
|
|
|
|
<Widget>
|
|
|
|
<Block label="Queries" />
|
|
|
|
<Block label="Blocked" />
|
|
|
|
<Block label="Gravity" />
|
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Widget>
|
|
|
|
<Block label="Queries" value={piholeData.dns_queries_today.toLocaleString()} />
|
|
|
|
<Block label="Blocked" value={piholeData.ads_blocked_today.toLocaleString()} />
|
|
|
|
<Block label="Gravity" value={piholeData.domains_being_blocked.toLocaleString()} />
|
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
}
|