Merge branch 'development' into lf

This commit is contained in:
Mark Drobnak
2019-12-18 11:49:51 -05:00
committed by GitHub
11 changed files with 162 additions and 17 deletions
+5 -3
View File
@@ -86,13 +86,15 @@
"test": "react-scripts test --env=jsdom",
"coverage": "react-scripts test --env=jsdom --coverage",
"eject": "react-scripts eject",
"format": "prettier --write \"src/**/*.tsx\"",
"check-format": "prettier --list-different \"src/**/*.tsx\""
"format": "prettier --write \"**/*.{js,tsx}\"",
"check-format": "prettier --list-different \"**/*.{js,tsx}\""
},
"browserslist": [
"defaults",
">0.2%",
"not dead",
"not ie <= 11",
"Explorer 11",
"not ExplorerMobile <= 11",
"not op_mini all"
]
}
+2 -2
View File
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pi-hole Web Interface</title>
<script type="text/javascript">
<script>
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
+4 -1
View File
@@ -28,5 +28,8 @@
"Detected custom upstream server": "Detected custom upstream server",
"DNS Options": "DNS Options",
"Rapid Commit": "Rapid Commit",
"Prefix length (CIDR)": "Prefix length (CIDR)"
"Prefix length (CIDR)": "Prefix length (CIDR)",
"DNS cache size": "DNS cache size",
"DNS cache evictions": "DNS cache evictions",
"DNS cache insertions": "DNS cache insertions"
}
+2 -3
View File
@@ -2,13 +2,12 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="%PUBLIC_URL%/img/favicon.png">
<title>Pi-hole Web Interface</title>
<!-- Start Single Page Apps for GitHub Pages -->
<script type="text/javascript">
<script>
// Single Page Apps for GitHub Pages
// https://github.com/rafrex/spa-github-pages
// Copyright (c) 2016 Rafael Pedicini, licensed under the MIT License
@@ -42,7 +41,7 @@
<body class="app header-fixed sidebar-fixed sidebar-lg-show boxcontainer background-image">
<noscript>
<p align="center">Please enable JavaScript! This web interface will not work without it.</p>
<p style="text-align: center">Please enable JavaScript! This web interface will not work without it.</p>
</noscript>
<div id="root"></div>
+3 -3
View File
@@ -15,9 +15,9 @@ const ISO6391 = require("iso-639-1");
const languages = fs.readdirSync("public/i18n");
const languageMap = languages.map(lang => {
return {
"code": lang,
"name": ISO6391.getName(lang)
}
code: lang,
name: ISO6391.getName(lang)
};
});
// Save the language list so the web interface knows what's available
+20 -5
View File
@@ -56,8 +56,8 @@ function history(length) {
client: isHostname
? faker.internet.domainWord() + ".local"
: isIPv4
? faker.internet.ip()
: faker.internet.ipv6(),
? faker.internet.ip()
: faker.internet.ipv6(),
dnssec: Math.floor(Math.random() * 5.9),
reply: Math.floor(Math.random() * 7.9),
response_time: Math.floor(Math.random() * 100.9)
@@ -381,7 +381,15 @@ function getPreferences() {
return {
layout: "boxed",
language: "en"
}
};
}
function cacheinfo() {
return {
cache_size: faker.random.number(),
cache_evicted: faker.random.number(),
cache_inserted: faker.random.number()
};
}
console.log("Deleting old fake API data...");
@@ -396,6 +404,7 @@ write("public/fakeAPI/dns/whitelist", list());
write("public/fakeAPI/dns/blacklist", list());
write("public/fakeAPI/dns/regexlist", list());
write("public/fakeAPI/dns/status", status());
write("public/fakeAPI/dns/cacheinfo", cacheinfo());
write("public/fakeAPI/settings/dhcp", getDHCPInfo());
write("public/fakeAPI/settings/dns", getDNSInfo());
write("public/fakeAPI/settings/network", getNetworkInfo());
@@ -412,14 +421,20 @@ write("public/fakeAPI/stats/top_domains", topDomains(10));
write("public/fakeAPI/stats/top_clients", topClients(10));
write("public/fakeAPI/stats/top_blocked_clients", topBlockedClients(10));
write("public/fakeAPI/stats/database/overTime/history", historyOverTime(144));
write("public/fakeAPI/stats/database/overTime/clients", clientsOverTime(144, 5));
write(
"public/fakeAPI/stats/database/overTime/clients",
clientsOverTime(144, 5)
);
write("public/fakeAPI/stats/database/summary", summary());
write("public/fakeAPI/stats/database/query_types", queryTypes());
write("public/fakeAPI/stats/database/upstreams", upstreams(3));
write("public/fakeAPI/stats/database/top_blocked", topBlockedDomains(10));
write("public/fakeAPI/stats/database/top_domains", topDomains(10));
write("public/fakeAPI/stats/database/top_clients", topClients(10));
write("public/fakeAPI/stats/database/top_blocked_clients", topBlockedClients(10));
write(
"public/fakeAPI/stats/database/top_blocked_clients",
topBlockedClients(10)
);
write("public/fakeAPI/auth", auth());
write("public/fakeAPI/version", getVersionInfo());
+108
View File
@@ -0,0 +1,108 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* Web Interface
* Settings :: DNS Cache Information component
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
import React, { Component } from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import { Form, Col, Input, FormGroup, Label } from "reactstrap";
import api from "../../util/api";
import {
CancelablePromise,
ignoreCancel,
makeCancelable
} from "../../util/CancelablePromise";
export interface CacheInfoState {
cache_size: number;
cache_evicted: number;
cache_inserted: number;
}
class CacheInfo extends Component<WithTranslation, CacheInfoState> {
state: CacheInfoState = {
cache_size: 0,
cache_evicted: 0,
cache_inserted: 0
};
componentDidMount() {
this.loadCacheInfo();
}
componentWillUnmount() {
if (this.loadHandler) {
this.loadHandler.cancel();
}
}
private loadHandler: undefined | CancelablePromise<ApiCacheResponse>;
loadCacheInfo = () => {
this.loadHandler = makeCancelable(api.getCacheInfo());
this.loadHandler.promise
.then(res => {
this.setState({
cache_size: res.cache_size,
cache_evicted: res.cache_evicted,
cache_inserted: res.cache_inserted
});
})
.catch(ignoreCancel);
};
render() {
const { t } = this.props;
return (
<Form>
<FormGroup row>
<Label className="font-weight-bold" for="cache_size" sm={4}>
{t("DNS cache size")}
</Label>
<Col sm={8}>
<Input
plaintext
readOnly
id="cache_size"
value={this.state.cache_size.toLocaleString()}
/>
</Col>
</FormGroup>
<FormGroup row>
<Label className="font-weight-bold" for="cache_evicted" sm={4}>
{t("DNS cache evictions")}
</Label>
<Col sm={8}>
<Input
plaintext
readOnly
id="cache_evicted"
value={this.state.cache_evicted.toLocaleString()}
/>
</Col>
</FormGroup>
<FormGroup row>
<Label className="font-weight-bold" for="cache_inserted" sm={4}>
{t("DNS cache insertions")}
</Label>
<Col sm={8}>
<Input
plaintext
readOnly
id="cache_inserted"
value={this.state.cache_inserted.toLocaleString()}
/>
</Col>
</FormGroup>
</Form>
);
}
}
export default withTranslation(["settings"])(CacheInfo);
+6
View File
@@ -76,6 +76,12 @@ interface ApiFtlDbResponse {
sqlite_version: string;
}
interface ApiCacheResponse {
cache_size: number;
cache_evicted: number;
cache_inserted: number;
}
interface ApiSuccessResponse {
status: "success";
}
+5
View File
@@ -394,5 +394,10 @@ describe("ApiClient", () => {
await expect(api.updatePreferences(settings)).resolves.toEqual(putData);
expect(httpClient.put).toHaveBeenCalledWith("settings/web", settings);
});
it("should call get dns cache endpoint", async () => {
await expect(api.getCacheInfo()).resolves.toEqual(getData);
expect(httpClient.get).toHaveBeenCalledWith("dns/cacheinfo");
});
});
});
+4
View File
@@ -239,6 +239,10 @@ export class ApiClient {
return this.http.get("settings/ftldb");
};
getCacheInfo = (): Promise<ApiCacheResponse> => {
return this.http.get("dns/cacheinfo");
};
getDNSInfo = (): Promise<ApiDnsSettings> => {
return this.http.get("settings/dns");
};
+3
View File
@@ -13,6 +13,7 @@ import { WithTranslation, withTranslation } from "react-i18next";
import { Nav, NavItem, NavLink, TabContent, TabPane } from "reactstrap";
import DHCPInfo from "../components/settings/DHCPInfo";
import DNSInfo from "../components/settings/DNSInfo";
import CacheInfo from "../components/settings/CacheInfo";
import NetworkInfo from "../components/settings/NetworkInfo";
import FTLInfo from "../components/settings/FTLInfo";
@@ -77,12 +78,14 @@ class Networking extends Component<WithTranslation, NetworkingState> {
{this.tab("dhcp", t("DHCP"))}
{this.tab("dns", t("DNS"))}
{this.tab("ftl", t("FTL"))}
{this.tab("cache", t("Cache"))}
</Nav>
<TabContent activeTab={this.state.activeTab}>
{this.tabContent("network", <NetworkInfo />)}
{this.tabContent("dhcp", <DHCPInfo />)}
{this.tabContent("dns", <DNSInfo />)}
{this.tabContent("ftl", <FTLInfo />)}
{this.tabContent("cache", <CacheInfo />)}
</TabContent>
</div>
);