From ad31d6627f1f81154ba80c2bc114a08ee21567b2 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 16 Mar 2018 16:36:27 -0400 Subject: [PATCH 01/31] Remove debug print in Login.js Signed-off-by: Mcat12 --- src/views/Login.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/views/Login.js b/src/views/Login.js index 2972b4d..d9fa9a0 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -107,10 +107,7 @@ export default class Login extends Component { From 57413e7cc18cb8c8daa85728a4625d2bfc769c24 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 6 Apr 2018 20:09:39 -0400 Subject: [PATCH 02/31] Authenticate against the API using `/admin/api/auth` Signed-off-by: Mcat12 --- src/utils.js | 25 ++++++++++++++++++++++--- src/views/Login.js | 20 ++++++++++---------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/utils.js b/src/utils.js index e78fae5..2296cca 100644 --- a/src/utils.js +++ b/src/utils.js @@ -67,6 +67,14 @@ export const ignoreCancel = err => { }; export const api = { + authenticate(key) { + return fetch(api.urlFor("auth"), { + headers: new Headers({ "X-Pi-hole-Authenticate": key }), + credentials: this.credentialType() + }) + .then(api.convertJSON) + .then(api.checkForErrors); + }, getSummary() { return api.get("stats/summary"); }, @@ -119,7 +127,9 @@ export const api = { return api.delete("dns/wildlist/" + domain); }, get(url) { - return fetch(api.urlFor(url)) + return fetch(api.urlFor(url), { + credentials: this.credentialType() + }) .then(api.convertJSON) .then(api.checkForErrors); }, @@ -127,13 +137,17 @@ export const api = { return fetch(api.urlFor(url), { method: "POST", body: JSON.stringify(data), - headers: new Headers({ "Content-Type": "application/json" }) + headers: new Headers({ "Content-Type": "application/json" }), + credentials: this.credentialType() }) .then(api.convertJSON) .then(api.checkForErrors); }, delete(url) { - return fetch(api.urlFor(url), { method: "DELETE" }) + return fetch(api.urlFor(url), { + method: "DELETE", + credentials: this.credentialType() + }) .then(api.convertJSON) .then(api.checkForErrors); }, @@ -160,5 +174,10 @@ export const api = { apiLocation = window.location.hostname + (window.location.port ? ':' + window.location.port : '') + "/admin/api"; return window.location.protocol + "//" + apiLocation + "/" + endpoint; + }, + credentialType() { + // Development API requests use a different origin (pi.hole) since it is running off of the developer's machine. + // Therefore, allow credentials to be used across origins when in development mode. + return config.developmentMode ? "include" : "same-origin"; } }; \ No newline at end of file diff --git a/src/views/Login.js b/src/views/Login.js index d9fa9a0..1b6039e 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -9,6 +9,7 @@ * Please see LICENSE file for your rights under this license. */ import React, { Component } from 'react'; +import { api } from "../utils"; import logo from '../img/logo.svg'; export default class Login extends Component { @@ -27,17 +28,16 @@ export default class Login extends Component { }; onAuth = () => { - this.setState({ password: '' }); + this.setState({ password: '', error: false }); - // TODO: Authenticate against server - let auth = false; - - if(auth) { - - } - else { - this.setState({ error: true }); - } + api.authenticate(this.state.password) + .then(() => { + // Assume it's ok since there was no error + // TODO: verify response + // TODO: transition to logged in mode + console.log("Logged In"); + }) + .catch(() => this.setState({ error: true })); }; render() { From 5c66a7d1de09ba01dbeade93900bc04c1959f7a4 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 29 Apr 2018 23:52:17 -0400 Subject: [PATCH 03/31] Get password before calling setState to clear the password Signed-off-by: Mcat12 --- src/views/Login.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/Login.js b/src/views/Login.js index 1b6039e..163c9eb 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -20,17 +20,17 @@ export default class Login extends Component { }; handlePasswordChange = e => { - if(e.keyCode === 13) { + if(e.keyCode === 13) this.onAuth(); - } else this.setState({ password: e.target.value }) }; onAuth = () => { + const password = this.state.password; this.setState({ password: '', error: false }); - api.authenticate(this.state.password) + api.authenticate(password) .then(() => { // Assume it's ok since there was no error // TODO: verify response From e7ecb9e4fc19590418aaae3bee1ad726cbc25ce8 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 00:12:04 -0400 Subject: [PATCH 04/31] Hash the password before checking with the API Signed-off-by: Mcat12 --- package-lock.json | 1471 +++++++++++++++++++++++++++++++++++++++++++- package.json | 3 +- src/views/Login.js | 10 +- 3 files changed, 1462 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index b1f44af..5224467 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1861,6 +1861,7 @@ "requires": { "anymatch": "1.3.2", "async-each": "1.0.1", + "fsevents": "1.2.3", "glob-parent": "2.0.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", @@ -2311,7 +2312,7 @@ "cipher-base": "1.0.4", "inherits": "2.0.3", "ripemd160": "2.0.1", - "sha.js": "2.4.8" + "sha.js": "2.4.11" } }, "create-hmac": { @@ -2325,7 +2326,7 @@ "inherits": "2.0.3", "ripemd160": "2.0.1", "safe-buffer": "5.1.1", - "sha.js": "2.4.8" + "sha.js": "2.4.11" } }, "create-react-class": { @@ -4223,6 +4224,542 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.3.tgz", + "integrity": "sha512-X+57O5YkDTiEQGiw8i7wYc2nQgweIekqkepI8Q3y4wVlurgBt2SuwxTeYUYMZIGpLZH3r/TsMjczCMXE5ZOt7Q==", + "dev": true, + "optional": true, + "requires": { + "nan": "2.10.0", + "node-pre-gyp": "0.9.1" + }, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.3.6" + } + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "bundled": true, + "dev": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "chownr": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "debug": { + "version": "2.6.9", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "bundled": true, + "dev": true, + "optional": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true, + "dev": true, + "optional": true + }, + "fs-minipass": { + "version": "1.2.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minipass": "2.2.4" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "1.2.0", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "iconv-lite": { + "version": "0.4.21", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safer-buffer": "2.1.2" + } + }, + "ignore-walk": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minimatch": "3.0.4" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "ini": { + "version": "1.3.5", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true + }, + "minipass": { + "version": "2.2.4", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "5.1.1", + "yallist": "3.0.2" + } + }, + "minizlib": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minipass": "2.2.4" + } + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "nan": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", + "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==", + "dev": true, + "optional": true + }, + "needle": { + "version": "2.2.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "2.6.9", + "iconv-lite": "0.4.21", + "sax": "1.2.4" + } + }, + "node-pre-gyp": { + "version": "0.9.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "detect-libc": "1.0.3", + "mkdirp": "0.5.1", + "needle": "2.2.0", + "nopt": "4.0.1", + "npm-packlist": "1.1.10", + "npmlog": "4.1.2", + "rc": "1.2.6", + "rimraf": "2.6.2", + "semver": "5.5.0", + "tar": "4.4.1" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1.1.1", + "osenv": "0.1.5" + } + }, + "npm-bundled": { + "version": "1.0.3", + "bundled": true, + "dev": true, + "optional": true + }, + "npm-packlist": { + "version": "1.1.10", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ignore-walk": "3.0.1", + "npm-bundled": "1.0.3" + } + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.5", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.1", + "string_decoder": "1.1.1", + "util-deprecate": "1.0.2" + } + }, + "rimraf": { + "version": "2.6.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.1.1", + "bundled": true, + "dev": true + }, + "safer-buffer": { + "version": "2.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sax": { + "version": "1.2.4", + "bundled": true, + "dev": true, + "optional": true + }, + "semver": { + "version": "5.5.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "4.4.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "chownr": "1.0.1", + "fs-minipass": "1.2.5", + "minipass": "2.2.4", + "minizlib": "1.1.0", + "mkdirp": "0.5.1", + "safe-buffer": "5.1.1", + "yallist": "3.0.2" + } + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "yallist": { + "version": "3.0.2", + "bundled": true, + "dev": true + } + } + }, "fstream": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", @@ -5282,8 +5819,7 @@ "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "ini": { "version": "1.3.4", @@ -8008,7 +8544,7 @@ "create-hmac": "1.1.6", "ripemd160": "2.0.1", "safe-buffer": "5.1.1", - "sha.js": "2.4.8" + "sha.js": "2.4.11" } }, "performance-now": { @@ -9855,6 +10391,7 @@ "extract-text-webpack-plugin": "3.0.0", "file-loader": "0.11.2", "fs-extra": "3.0.1", + "fsevents": "1.1.2", "html-webpack-plugin": "2.29.0", "jest": "20.0.4", "object-assign": "4.1.1", @@ -9871,6 +10408,905 @@ "whatwg-fetch": "2.0.3" }, "dependencies": { + "fsevents": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.2.tgz", + "integrity": "sha512-Sn44E5wQW4bTHXvQmvSHwqbuiXtduD6Rrjm2ZtUEGbyrig+nUH3t/QD4M4/ZXViY556TBpRgZkHLDx3JxPwxiw==", + "dev": true, + "optional": true, + "requires": { + "nan": "2.6.2", + "node-pre-gyp": "0.6.36" + }, + "dependencies": { + "abbrev": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "ajv": { + "version": "4.11.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "co": "4.6.0", + "json-stable-stringify": "1.0.1" + } + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "aproba": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.2.9" + } + }, + "asn1": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "assert-plus": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "asynckit": { + "version": "0.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws-sign2": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "aws4": { + "version": "1.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "balanced-match": { + "version": "0.4.2", + "bundled": true, + "dev": true + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "block-stream": { + "version": "0.0.9", + "bundled": true, + "dev": true, + "requires": { + "inherits": "2.0.3" + } + }, + "boom": { + "version": "2.10.1", + "bundled": true, + "dev": true, + "requires": { + "hoek": "2.16.3" + } + }, + "brace-expansion": { + "version": "1.1.7", + "bundled": true, + "dev": true, + "requires": { + "balanced-match": "0.4.2", + "concat-map": "0.0.1" + } + }, + "buffer-shims": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "caseless": { + "version": "0.12.0", + "bundled": true, + "dev": true, + "optional": true + }, + "co": { + "version": "4.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "combined-stream": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "cryptiles": { + "version": "2.0.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "boom": "2.10.1" + } + }, + "dashdash": { + "version": "1.14.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "debug": { + "version": "2.6.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "bundled": true, + "dev": true, + "optional": true + }, + "delayed-stream": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "ecc-jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "extend": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "extsprintf": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "forever-agent": { + "version": "0.6.1", + "bundled": true, + "dev": true, + "optional": true + }, + "form-data": { + "version": "2.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.15" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "fstream": { + "version": "1.0.11", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "inherits": "2.0.3", + "mkdirp": "0.5.1", + "rimraf": "2.6.1" + } + }, + "fstream-ignore": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fstream": "1.0.11", + "inherits": "2.0.3", + "minimatch": "3.0.4" + } + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "1.1.1", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "getpass": { + "version": "0.1.7", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "bundled": true, + "dev": true + }, + "har-schema": { + "version": "1.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "har-validator": { + "version": "4.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ajv": "4.11.8", + "har-schema": "1.0.5" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "hawk": { + "version": "3.1.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "boom": "2.10.1", + "cryptiles": "2.0.5", + "hoek": "2.16.3", + "sntp": "1.0.9" + } + }, + "hoek": { + "version": "2.16.3", + "bundled": true, + "dev": true + }, + "http-signature": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "0.2.0", + "jsprim": "1.4.0", + "sshpk": "1.13.0" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "ini": { + "version": "1.3.4", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "isstream": { + "version": "0.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "jodid25519": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "jsbn": { + "version": "0.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "bundled": true, + "dev": true, + "optional": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "jsonify": "0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "jsonify": { + "version": "0.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "jsprim": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.0.2", + "json-schema": "0.2.3", + "verror": "1.3.6" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "mime-db": { + "version": "1.27.0", + "bundled": true, + "dev": true + }, + "mime-types": { + "version": "2.1.15", + "bundled": true, + "dev": true, + "requires": { + "mime-db": "1.27.0" + } + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "requires": { + "brace-expansion": "1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "node-pre-gyp": { + "version": "0.6.36", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "mkdirp": "0.5.1", + "nopt": "4.0.1", + "npmlog": "4.1.0", + "rc": "1.2.1", + "request": "2.81.0", + "rimraf": "2.6.1", + "semver": "5.3.0", + "tar": "2.2.1", + "tar-pack": "3.4.0" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1.1.0", + "osenv": "0.1.4" + } + }, + "npmlog": { + "version": "4.1.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "oauth-sign": { + "version": "0.8.2", + "bundled": true, + "dev": true, + "optional": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "performance-now": { + "version": "0.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "1.0.7", + "bundled": true, + "dev": true + }, + "punycode": { + "version": "1.4.1", + "bundled": true, + "dev": true, + "optional": true + }, + "qs": { + "version": "6.4.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.4", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.2.9", + "bundled": true, + "dev": true, + "requires": { + "buffer-shims": "1.0.0", + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "string_decoder": "1.0.1", + "util-deprecate": "1.0.2" + } + }, + "request": { + "version": "2.81.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aws-sign2": "0.6.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.1.4", + "har-validator": "4.2.1", + "hawk": "3.1.3", + "http-signature": "1.1.1", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.15", + "oauth-sign": "0.8.2", + "performance-now": "0.2.0", + "qs": "6.4.0", + "safe-buffer": "5.0.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.2", + "tunnel-agent": "0.6.0", + "uuid": "3.0.1" + } + }, + "rimraf": { + "version": "2.6.1", + "bundled": true, + "dev": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.0.1", + "bundled": true, + "dev": true + }, + "semver": { + "version": "5.3.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sntp": { + "version": "1.0.9", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "hoek": "2.16.3" + } + }, + "sshpk": { + "version": "1.13.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jodid25519": "1.0.2", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "stringstream": { + "version": "0.0.5", + "bundled": true, + "dev": true, + "optional": true + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "2.2.1", + "bundled": true, + "dev": true, + "requires": { + "block-stream": "0.0.9", + "fstream": "1.0.11", + "inherits": "2.0.3" + } + }, + "tar-pack": { + "version": "3.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "2.6.8", + "fstream": "1.0.11", + "fstream-ignore": "1.0.5", + "once": "1.4.0", + "readable-stream": "2.2.9", + "rimraf": "2.6.1", + "tar": "2.2.1", + "uid-number": "0.0.6" + } + }, + "tough-cookie": { + "version": "2.3.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "bundled": true, + "dev": true, + "optional": true + }, + "uid-number": { + "version": "0.0.6", + "bundled": true, + "dev": true, + "optional": true + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "uuid": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "verror": { + "version": "1.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "extsprintf": "1.0.2" + } + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + } + } + }, "promise": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/promise/-/promise-8.0.1.tgz", @@ -10460,8 +11896,7 @@ "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", - "dev": true + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "sane": { "version": "1.6.0", @@ -10730,12 +12165,12 @@ "dev": true }, "sha.js": { - "version": "2.4.8", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.8.tgz", - "integrity": "sha1-NwaMLEdra69ALRSknGf1l5IfY08=", - "dev": true, + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "requires": { - "inherits": "2.0.3" + "inherits": "2.0.3", + "safe-buffer": "5.1.1" } }, "shebang-command": { @@ -11104,12 +12539,6 @@ "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=", "dev": true }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", - "dev": true - }, "string-length": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz", @@ -11130,6 +12559,12 @@ "strip-ansi": "3.0.1" } }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", diff --git a/package.json b/package.json index 31a4b2c..d53e3bb 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "react-router-dom": "4.1.1", "react-table": "^6.5.1", "react-transition-group": "^1.2.0", - "reactstrap": "4.6.2" + "reactstrap": "4.6.2", + "sha.js": "^2.4.11" }, "scripts": { "start": "react-scripts start", diff --git a/src/views/Login.js b/src/views/Login.js index 163c9eb..fe8b5c5 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -9,6 +9,7 @@ * Please see LICENSE file for your rights under this license. */ import React, { Component } from 'react'; +import sha from 'sha.js'; import { api } from "../utils"; import logo from '../img/logo.svg'; @@ -27,10 +28,11 @@ export default class Login extends Component { }; onAuth = () => { - const password = this.state.password; - this.setState({ password: '', error: false }); + // Hash the password twice before sending to the API + let hashedPassword = sha("sha256").update(this.state.password).digest("hex"); + hashedPassword = sha("sha256").update(hashedPassword).digest("hex"); - api.authenticate(password) + api.authenticate(hashedPassword) .then(() => { // Assume it's ok since there was no error // TODO: verify response @@ -38,6 +40,8 @@ export default class Login extends Component { console.log("Logged In"); }) .catch(() => this.setState({ error: true })); + + this.setState({ password: '', error: false }); }; render() { From bcc4e854c92370234fcb2bebc29548c9c85a79df Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 00:38:41 -0400 Subject: [PATCH 05/31] Add a loggedIn boolean to the api object Signed-off-by: Mcat12 --- src/utils.js | 1 + src/views/Login.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/utils.js b/src/utils.js index 2296cca..26358de 100644 --- a/src/utils.js +++ b/src/utils.js @@ -67,6 +67,7 @@ export const ignoreCancel = err => { }; export const api = { + loggedIn: false, authenticate(key) { return fetch(api.urlFor("auth"), { headers: new Headers({ "X-Pi-hole-Authenticate": key }), diff --git a/src/views/Login.js b/src/views/Login.js index fe8b5c5..467f946 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -37,6 +37,7 @@ export default class Login extends Component { // Assume it's ok since there was no error // TODO: verify response // TODO: transition to logged in mode + api.loggedIn = true; console.log("Logged In"); }) .catch(() => this.setState({ error: true })); From 821588f1be38486c65d0e46d75b70bc485ae5462 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 13:18:49 -0400 Subject: [PATCH 06/31] Don't show all graphs on the dashboard when not logged in Signed-off-by: Mcat12 --- src/views/Dashboard.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/views/Dashboard.js b/src/views/Dashboard.js index c75eba9..1b2ca6e 100644 --- a/src/views/Dashboard.js +++ b/src/views/Dashboard.js @@ -8,7 +8,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -import React from 'react'; +import React, { Fragment } from 'react'; import SummaryStats from '../components/SummaryStats'; import QueriesGraph from '../components/QueriesGraph'; import QueryTypesOverTime from '../components/QueryTypesOverTime'; @@ -16,19 +16,26 @@ import ForwardDestOverTime from '../components/ForwardDestOverTime'; import TopDomains from '../components/TopDomains'; import TopBlocked from '../components/TopBlocked'; import TopClients from '../components/TopClients'; +import { api } from "../utils"; export default () => (
-
- - -
-
- - - -
+ { + api.loggedIn ? + +
+ + +
+
+ + + +
+
+ : null + }
); From 7b4ba8003ac63dcf68232c4da9d19c1e274973bd Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 13:19:34 -0400 Subject: [PATCH 07/31] Add an auth field to the sidebar to make it change when logged in Signed-off-by: Mcat12 --- src/components/Sidebar.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js index 058cb6f..7203f20 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -13,44 +13,52 @@ import { NavLink } from 'react-router-dom' import { Nav, NavItem } from 'reactstrap'; import logo from '../img/logo.svg'; import { mobileSidebarHide } from "./Header"; +import { api } from "../utils"; const nav = { items: [ { name: 'Dashboard', url: '/dashboard', - icon: 'fa fa-dashboard' + icon: 'fa fa-dashboard', + auth: false }, { name: 'Query Log', url: '/query-log', - icon: 'fa fa-database' + icon: 'fa fa-database', + auth: true }, { name: 'Whitelist', url: '/whitelist', - icon: 'fa fa-check-circle-o' + icon: 'fa fa-check-circle-o', + auth: false }, { name: 'Blacklist', icon: 'fa fa-ban', + auth: false, children: [ { name: 'Exact', url: '/blacklist', - icon: 'fa fa-ban' + icon: 'fa fa-ban', + auth: false }, { name: 'Wildcard', url: '/wildlist', - icon: 'fa fa-ban' + icon: 'fa fa-ban', + auth: false } ] }, { name: 'Login', - url: '/login', - icon: 'fa fa-user' + url: '/login', icon: 'fa fa-user', + auth: false, + authStrict: true } ] }; @@ -81,7 +89,18 @@ const navDropdown = (item, key, props) => ( ); const navList = (items, props) => - items.map((item, index) => item.children ? navDropdown(item, index, props) : navItem(item, index)); + items.map((item, index) => { + // Don't show an item if it requires auth and we're not logged in + if(item.auth && !api.loggedIn) + return null; + + // Some items (login page) should only be shown when logged in or logged out, not both + if(item.authStrict && item.auth !== api.loggedIn) + return null; + + // At this point it's ok to show the item + return item.children ? navDropdown(item, index, props) : navItem(item, index); + }); export default props => { return ( From d49bc3343cff70c8bbe3c71ab8fb0c77d5c4b885 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 14:47:38 -0400 Subject: [PATCH 08/31] Turn off list modification when not logged in Signed-off-by: Mcat12 --- src/components/DomainInput.js | 13 +++++++++---- src/components/DomainList.js | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/DomainInput.js b/src/components/DomainInput.js index ff3bad9..707327b 100644 --- a/src/components/DomainInput.js +++ b/src/components/DomainInput.js @@ -10,7 +10,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { ignoreCancel, makeCancelable } from "../utils"; +import { api, ignoreCancel, makeCancelable } from "../utils"; export default class DomainInput extends Component { state = { @@ -49,11 +49,16 @@ export default class DomainInput extends Component { type="text" className="form-control" placeholder="Add a domain (example.com or sub.example.com)" value={this.state.domain} onKeyPress={(e) => e.charCode === 13 ? this.onAdd() : null} onChange={this.handleChange} + disabled={!api.loggedIn} /> - + { + api.loggedIn ? + + : null + } diff --git a/src/components/DomainList.js b/src/components/DomainList.js index 35ee9ab..62312a0 100644 --- a/src/components/DomainList.js +++ b/src/components/DomainList.js @@ -10,7 +10,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { ignoreCancel, makeCancelable } from "../utils"; +import { api, ignoreCancel, makeCancelable } from "../utils"; export default class DomainList extends Component { onRemove(domain) { @@ -34,9 +34,13 @@ export default class DomainList extends Component { ? this.props.domains.map(item => (
  • - + { + api.loggedIn ? + + : null + } {item} From cc22d3e16c7d4d324cc003da23160526537a2b31 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 14:58:16 -0400 Subject: [PATCH 09/31] Redirect to home when logged in Signed-off-by: Mcat12 --- src/views/Login.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/views/Login.js b/src/views/Login.js index 467f946..2916f2d 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -36,9 +36,8 @@ export default class Login extends Component { .then(() => { // Assume it's ok since there was no error // TODO: verify response - // TODO: transition to logged in mode api.loggedIn = true; - console.log("Logged In"); + this.props.history.push('/'); }) .catch(() => this.setState({ error: true })); From d46755db2a3eab03194d5c8f63277dd6eb316af8 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 14:58:38 -0400 Subject: [PATCH 10/31] Add Logout button Signed-off-by: Mcat12 --- src/components/Sidebar.js | 10 +++++++++- src/containers/Full.js | 2 ++ src/routes.js | 3 ++- src/views/Logout.js | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/views/Logout.js diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js index 7203f20..974d8f1 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -56,9 +56,17 @@ const nav = { }, { name: 'Login', - url: '/login', icon: 'fa fa-user', + url: '/login', + icon: 'fa fa-user', auth: false, authStrict: true + }, + { + name: 'Logout', + url: '/logout', + icon: 'fa fa-user-times', + auth: true, + authStrict: true } ] }; diff --git a/src/containers/Full.js b/src/containers/Full.js index 4d7d144..c2adaa9 100644 --- a/src/containers/Full.js +++ b/src/containers/Full.js @@ -21,6 +21,7 @@ import Whitelist from "../views/Whitelist"; import Blacklist from "../views/Blacklist"; import Wildlist from "../views/Wildlist"; import Login from "../views/Login"; +import Logout from "../views/Logout"; export default props => (
    @@ -38,6 +39,7 @@ export default props => ( +
    diff --git a/src/routes.js b/src/routes.js index a7a3c0a..b06e93a 100644 --- a/src/routes.js +++ b/src/routes.js @@ -14,5 +14,6 @@ export default { '/whitelist': 'Whitelist', '/blacklist': 'Blacklist (Exact)', '/wildlist': 'Blacklist (Wildcard)', - '/login': 'Login' + '/login': 'Login', + '/logout': 'Logout' }; diff --git a/src/views/Logout.js b/src/views/Logout.js new file mode 100644 index 0000000..21c2ade --- /dev/null +++ b/src/views/Logout.js @@ -0,0 +1,24 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* Web Interface +* Logout the user +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ + +import { Component } from 'react'; +import { api } from "../utils"; + +export default class Logout extends Component { + componentWillMount() { + // TODO: remove auth cookie + api.loggedIn = false; + this.props.history.push('/'); + } + + render() { + return null; + } +} From 001fe33366f56361bd215600a8ff16182ab79f33 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 15:19:30 -0400 Subject: [PATCH 11/31] Log out via the API when logout is clicked Signed-off-by: Mcat12 --- src/utils.js | 3 +++ src/views/Logout.js | 1 + 2 files changed, 4 insertions(+) diff --git a/src/utils.js b/src/utils.js index 26358de..d4ac9ba 100644 --- a/src/utils.js +++ b/src/utils.js @@ -76,6 +76,9 @@ export const api = { .then(api.convertJSON) .then(api.checkForErrors); }, + logout() { + return api.delete("auth"); + }, getSummary() { return api.get("stats/summary"); }, diff --git a/src/views/Logout.js b/src/views/Logout.js index 21c2ade..41a5b59 100644 --- a/src/views/Logout.js +++ b/src/views/Logout.js @@ -15,6 +15,7 @@ export default class Logout extends Component { componentWillMount() { // TODO: remove auth cookie api.loggedIn = false; + api.logout(); this.props.history.push('/'); } From c0f78c26b9429d8ee647a2fcfb325a33a0c84653 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 15:23:16 -0400 Subject: [PATCH 12/31] Remove finished logout todo Signed-off-by: Mcat12 --- src/views/Logout.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/views/Logout.js b/src/views/Logout.js index 41a5b59..d3adcc8 100644 --- a/src/views/Logout.js +++ b/src/views/Logout.js @@ -13,7 +13,6 @@ import { api } from "../utils"; export default class Logout extends Component { componentWillMount() { - // TODO: remove auth cookie api.loggedIn = false; api.logout(); this.props.history.push('/'); From f184445aa12848aba2712c70a5273f1de13f576e Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 15:32:17 -0400 Subject: [PATCH 13/31] Change to cleaner logout redirect Signed-off-by: Mcat12 --- src/views/Logout.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/Logout.js b/src/views/Logout.js index d3adcc8..90244b5 100644 --- a/src/views/Logout.js +++ b/src/views/Logout.js @@ -8,17 +8,17 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -import { Component } from 'react'; +import React, { Component } from 'react'; +import { Redirect } from 'react-router-dom'; import { api } from "../utils"; export default class Logout extends Component { componentWillMount() { api.loggedIn = false; api.logout(); - this.props.history.push('/'); } render() { - return null; + return ; } } From 65555f61dc025deb1e10d875acf2699640b84c14 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 15:32:40 -0400 Subject: [PATCH 14/31] Redirect to home from login page if already logged in Signed-off-by: Mcat12 --- src/views/Login.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/views/Login.js b/src/views/Login.js index 2916f2d..e9d20d0 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -9,6 +9,7 @@ * Please see LICENSE file for your rights under this license. */ import React, { Component } from 'react'; +import { Redirect } from 'react-router-dom'; import sha from 'sha.js'; import { api } from "../utils"; import logo from '../img/logo.svg'; @@ -45,6 +46,9 @@ export default class Login extends Component { }; render() { + if(api.loggedIn) + return ; + return (
    From 2d7032788797c8d98351a89b53db5bca85944fe6 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 15:41:37 -0400 Subject: [PATCH 15/31] Require authentication to certain routes through the Router This prevents people from just going directly to the protected pages. They will get redirected to the login page. Signed-off-by: Mcat12 --- src/containers/Full.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/containers/Full.js b/src/containers/Full.js index c2adaa9..a574571 100644 --- a/src/containers/Full.js +++ b/src/containers/Full.js @@ -22,6 +22,7 @@ import Blacklist from "../views/Blacklist"; import Wildlist from "../views/Wildlist"; import Login from "../views/Login"; import Logout from "../views/Logout"; +import { api } from "../utils"; export default props => (
    @@ -34,12 +35,12 @@ export default props => ( - + - +
    @@ -48,3 +49,31 @@ export default props => (
    ); + +/** + * Create a route which requires authentication. + * If the user is unauthenticated, they will be redirected to the login page. + * If the user logs in at the redirected login page, they will go to their original destination. + * + * @param Component The component that the authenticated user will see + * @param rest The rest of the Route arguments + * @returns Route + */ +const AuthRoute = ({ component: Component, ...rest }) => ( + + api.loggedIn ? ( + + ) : ( + + ) + } + /> +); + From f4ee15ed07f6ebac9a9015c2f3716e35845eba40 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 15:48:28 -0400 Subject: [PATCH 16/31] Redirect users to their original destination when logging in If a user goes to a protected page and is redirected to the login page, tell them that they will be redirected upon successful login and do that. Signed-off-by: Mcat12 --- src/views/Login.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/views/Login.js b/src/views/Login.js index e9d20d0..f0fc0ab 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -8,11 +8,12 @@ * 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 React, { Component, Fragment } from 'react'; import { Redirect } from 'react-router-dom'; import sha from 'sha.js'; import { api } from "../utils"; import logo from '../img/logo.svg'; +import routes from "../routes"; export default class Login extends Component { state = { @@ -38,7 +39,10 @@ export default class Login extends Component { // Assume it's ok since there was no error // TODO: verify response api.loggedIn = true; - this.props.history.push('/'); + + // Redirect to the page the user was originally going to, or if that doesn't exist, go to home + const redirect = this.props.location.state.from || '/'; + this.props.history.push(redirect); }) .catch(() => this.setState({ error: true })); @@ -65,6 +69,15 @@ export default class Login extends Component {

    Sign in to start your session + { + this.props.location.state && this.props.location.state.from.pathname in routes ? + ( + +
    + You will be transferred to the {routes[this.props.location.state.from.pathname]} +
    + ) : null + }

    - : - null + : null } From e978568eb7b5b918f8f5e52333efdd102b005fdd Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 30 Apr 2018 17:31:14 -0400 Subject: [PATCH 18/31] Verify that login was successful Signed-off-by: Mcat12 --- src/views/Login.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/views/Login.js b/src/views/Login.js index ea4c69c..c877c64 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -42,9 +42,14 @@ export default class Login extends Component { hashedPassword = sha("sha256").update(hashedPassword).digest("hex"); api.authenticate(hashedPassword) - .then(() => { - // Assume it's ok since there was no error - // TODO: verify response + .then(data => { + // Verify status + if(data.status !== "success") { + console.log("Failed to log in:"); + console.log(data); + return; + } + api.loggedIn = true; // Redirect to the page the user was originally going to, or if that doesn't exist, go to home From 3093933f3a4495bb8573242dd8e1b2bffe916336 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 2 May 2018 17:02:01 -0400 Subject: [PATCH 19/31] Change cursor on login button Signed-off-by: Mcat12 --- src/views/Login.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/Login.js b/src/views/Login.js index c877c64..391b830 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -125,7 +125,7 @@ export default class Login extends Component {
    -
    From 78f86b78370cb9ff12dd474c971dacf3e90df60e Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 2 May 2018 17:03:52 -0400 Subject: [PATCH 20/31] Clear the password before authenticating but after hashing Signed-off-by: Mcat12 --- src/views/Login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/Login.js b/src/views/Login.js index 391b830..cbc1604 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -41,6 +41,8 @@ export default class Login extends Component { let hashedPassword = sha("sha256").update(this.state.password).digest("hex"); hashedPassword = sha("sha256").update(hashedPassword).digest("hex"); + this.setState({ password: '', error: false }); + api.authenticate(hashedPassword) .then(data => { // Verify status @@ -57,8 +59,6 @@ export default class Login extends Component { this.props.history.push(redirect); }) .catch(() => this.setState({ error: true })); - - this.setState({ password: '', error: false }); }; render() { From 7312ec50e76877d98c76a274ec6b2b34979c5174 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 2 May 2018 17:20:11 -0400 Subject: [PATCH 21/31] Split out the forgot password reminder into a new component Signed-off-by: Mcat12 --- src/components/ForgotPassword.js | 65 ++++++++++++++++++++++++++++++++ src/views/Login.js | 32 +--------------- 2 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 src/components/ForgotPassword.js diff --git a/src/components/ForgotPassword.js b/src/components/ForgotPassword.js new file mode 100644 index 0000000..a698ca8 --- /dev/null +++ b/src/components/ForgotPassword.js @@ -0,0 +1,65 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* Web Interface +* Forgot Password Reminder +* +* 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 PropTypes from 'prop-types'; + +export default class ForgotPassword extends Component { + state = { + collapsed: true + }; + + /** + * Handle collapsing the body when clicked + */ + onClick = () => { + this.setState({ collapsed: !this.state.collapsed }); + }; + + /** + * @returns {Boolean|boolean} If the body should be collapsed + */ + isCollapsed = () => this.props.error || !this.state.collapsed; + + render() { + return ( +
    +
    +
    +
    +

    + Forgot password +

    + + + + +
    +
    + After installing Pi-hole for the first time, a password is generated and displayed to the user. + The password cannot be retrieved later on, but it is possible to set a new password (or + explicitly disable the password by setting an empty password) using the command: +
    sudo pihole -a -p
    +
    +
    +
    +
    + ); + } +} + +ForgotPassword.propTypes = { + error: PropTypes.bool.isRequired +}; \ No newline at end of file diff --git a/src/views/Login.js b/src/views/Login.js index cbc1604..86fc5b1 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -14,12 +14,12 @@ import sha from 'sha.js'; import { api } from "../utils"; import logo from '../img/logo.svg'; import routes from "../routes"; +import ForgotPassword from "../components/ForgotPassword"; export default class Login extends Component { state = { password: '', error: false, - forgotPasswordCollapsed: true, cookiesEnabled: false }; @@ -131,35 +131,7 @@ export default class Login extends Component {
    -
    -
    -
    -
    -

    - Forgot password -

    - - - - -
    -
    - After installing Pi-hole for the first time, a password is generated and displayed to the user. - The password cannot be retrieved later on, but it is possible to set a new password (or - explicitly disable the password by setting an empty password) using the command: -
    sudo pihole -a -p
    -
    -
    -
    -
    + From 0b056580d35e08af87f3646232b6184d141eee22 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 2 May 2018 17:42:05 -0400 Subject: [PATCH 22/31] Remove the Return and Ctrl+Return text from the login page Signed-off-by: Mcat12 --- src/components/ForgotPassword.js | 42 +++++++++++++++----------------- src/views/Login.js | 10 ++------ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/components/ForgotPassword.js b/src/components/ForgotPassword.js index a698ca8..6e7092c 100644 --- a/src/components/ForgotPassword.js +++ b/src/components/ForgotPassword.js @@ -30,29 +30,27 @@ export default class ForgotPassword extends Component { render() { return ( -
    -
    -
    -
    -

    - Forgot password -

    +
    +
    +
    +

    + Forgot password +

    - - - -
    -
    - After installing Pi-hole for the first time, a password is generated and displayed to the user. - The password cannot be retrieved later on, but it is possible to set a new password (or - explicitly disable the password by setting an empty password) using the command: -
    sudo pihole -a -p
    -
    + + + +
    +
    + After installing Pi-hole for the first time, a password is generated and displayed to the user. + The password cannot be retrieved later on, but it is possible to set a new password (or + explicitly disable the password by setting an empty password) using the command: +
    sudo pihole -a -p
    diff --git a/src/views/Login.js b/src/views/Login.js index 86fc5b1..1f294c9 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -118,14 +118,8 @@ export default class Login extends Component { placeholder="Password" autoFocus/>
    -
    -
      -
    • Return → Log in
    • -
    • Ctrl+Return → Log in and go to Settings page
    • -
    -
    -
    -
    From c6f8e9bba585cbcc924c874d1abe53da45f9503e Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 2 May 2018 17:54:23 -0400 Subject: [PATCH 23/31] Add some documentation to Login Signed-off-by: Mcat12 --- src/utils.js | 2 +- src/views/Login.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index d4ac9ba..c122e4f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -173,7 +173,7 @@ export const api = { if(config.fakeAPI) apiLocation = window.location.host + process.env.PUBLIC_URL + "/fakeAPI"; else if(config.developmentMode) - apiLocation = "pi.hole/admin/api"; + apiLocation = "pi.hole:8000/admin/api"; else apiLocation = window.location.hostname + (window.location.port ? ':' + window.location.port : '') + "/admin/api"; diff --git a/src/views/Login.js b/src/views/Login.js index 1f294c9..d39d083 100644 --- a/src/views/Login.js +++ b/src/views/Login.js @@ -29,20 +29,32 @@ export default class Login extends Component { this.setState({ cookiesEnabled: true }); } + /** + * Called when the user types into the password box. + * If they clicked Enter, try to authenticate them. + * Otherwise update the password in the state. + * + * @param e the event + */ handlePasswordChange = e => { if(e.keyCode === 13) - this.onAuth(); + this.authenticate(); else this.setState({ password: e.target.value }) }; - onAuth = () => { + /** + * Try to authenticate the user + */ + authenticate = () => { // Hash the password twice before sending to the API let hashedPassword = sha("sha256").update(this.state.password).digest("hex"); hashedPassword = sha("sha256").update(hashedPassword).digest("hex"); + // Clear the state this.setState({ password: '', error: false }); + // Send the password to the API to authenticate the user api.authenticate(hashedPassword) .then(data => { // Verify status @@ -58,10 +70,12 @@ export default class Login extends Component { const redirect = this.props.location.state.from || '/'; this.props.history.push(redirect); }) + // If there was an error, tell the user they used the wrong password .catch(() => this.setState({ error: true })); }; render() { + // If the user is already logged in, then go to the home page if(api.loggedIn) return ; @@ -82,6 +96,8 @@ export default class Login extends Component {

    Sign in to start your session { + // If the user tried to go to a protected page and is not logged in, + // tell them they will be redirected once login is successful this.props.location.state && this.props.location.state.from.pathname in routes ? ( @@ -91,6 +107,7 @@ export default class Login extends Component { ) : null } { + // If cookies are not enabled (or detected), show a warning !this.state.cookiesEnabled ?

    Verify that cookies are allowed for {window.location.host} @@ -119,7 +136,8 @@ export default class Login extends Component {
    -
    From 9fd526735d77cac65fc06e81d41d212bb8a52b8f Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Thu, 3 May 2018 20:14:26 -0400 Subject: [PATCH 24/31] Log the user out when the session lapses Signed-off-by: Mcat12 --- src/index.js | 6 ++++++ src/utils.js | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index cf71897..9337d82 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,12 @@ import ReactDOM from 'react-dom'; import { HashRouter, Route, Switch } from 'react-router-dom' import 'ionicons/dist/css/ionicons.min.css'; import Full from './containers/Full' +import { api } from "./utils"; + +// Before rendering anything, check if there is a session cookie. +// Note: the user could have an old session, so the first API call +// will set loggedIn to false if necessary +api.loggedIn = document.cookie.includes("user_id="); ReactDOM.render( ( diff --git a/src/utils.js b/src/utils.js index c122e4f..1397679 100644 --- a/src/utils.js +++ b/src/utils.js @@ -33,7 +33,7 @@ export const makeCancelable = (promise, { repeat = null, interval = 0 } = {}) => const handle = (resolve, reject, val, isError) => { if(hasCanceled) - reject({isCanceled: true}); + reject({ isCanceled: true }); else { if(isError) reject(val); @@ -134,6 +134,7 @@ export const api = { return fetch(api.urlFor(url), { credentials: this.credentialType() }) + .then(api.checkIfLoggedOut) .then(api.convertJSON) .then(api.checkForErrors); }, @@ -155,6 +156,20 @@ export const api = { .then(api.convertJSON) .then(api.checkForErrors); }, + /** + * If the user is logged in, check if the user's session has lapsed. + * If so, log them out and refresh the page. + */ + checkIfLoggedOut(response) { + if(api.loggedIn && response.status === 401) { + // Clear the user's old session and refresh the page + document.cookie = 'user_id=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; + window.location.reload(); + return Promise.reject({ isCanceled: true }) + } + + return Promise.resolve(response); + }, async convertJSON(data) { if(!data.ok) return Promise.reject({ data, json: await data.json() }); From c716773baecbf390c601402af42f533f4b80d2f2 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 16 May 2018 15:08:59 -0400 Subject: [PATCH 25/31] Upload builds to ftl.pi-hole.net On master, the builds have fake data and are configured to be deployed to web.pi-hole.io. On other branches, they are build without fake data. Signed-off-by: Mcat12 --- .travis.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e84f88..303592f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,17 @@ env: script: - npm run gulp sass - rm public/fakeAPI/.gitignore # Make sure that the fakeAPI data is deployed - - npm run build-fake - - echo "web.pi-hole.io" > build/CNAME + - 'if [ "$TRAVIS_BRANCH" = "master" ]; then + npm run build-fake + echo "web.pi-hole.io" > build/CNAME; + else + npm run build + fi' + - tar -czvf pihole-web.tar.gz build + - wget https://ftl.pi-hole.net:8080/FTL-client + - chmod +x ./FTL-client + - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./FTL-client "${TRAVIS_BRANCH}" pihole-web.tar.gz "${TRAVIS_SECRET}"; fi' + - rm ./FTL-client deploy: provider: pages From 990ba3d455a915ef58e21d89e09dfc9b4b271911 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 16 May 2018 15:12:50 -0400 Subject: [PATCH 26/31] Add more semicolons Signed-off-by: Mcat12 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 303592f..9f90d61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,10 +11,10 @@ script: - npm run gulp sass - rm public/fakeAPI/.gitignore # Make sure that the fakeAPI data is deployed - 'if [ "$TRAVIS_BRANCH" = "master" ]; then - npm run build-fake + npm run build-fake; echo "web.pi-hole.io" > build/CNAME; else - npm run build + npm run build; fi' - tar -czvf pihole-web.tar.gz build - wget https://ftl.pi-hole.net:8080/FTL-client From c14b601b6be81214ca2f4fcd04b965fcaecda6ea Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 26 May 2018 23:38:42 -0400 Subject: [PATCH 27/31] Don't make a top level build folder in the uploaded build Signed-off-by: Mcat12 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9f90d61..0fe326e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ script: else npm run build; fi' - - tar -czvf pihole-web.tar.gz build + - tar -czvf pihole-web.tar.gz -C build . - wget https://ftl.pi-hole.net:8080/FTL-client - chmod +x ./FTL-client - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./FTL-client "${TRAVIS_BRANCH}" pihole-web.tar.gz "${TRAVIS_SECRET}"; fi' From 966bebd32c8749bfa5505a09c1863fda660bd4d3 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 2 Jun 2018 12:06:12 -0400 Subject: [PATCH 28/31] Check if logged out for POST and DELETE requests Signed-off-by: Mcat12 --- src/utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils.js b/src/utils.js index 03b1678..7ef0219 100644 --- a/src/utils.js +++ b/src/utils.js @@ -132,6 +132,7 @@ export const api = { headers: new Headers({ "Content-Type": "application/json" }), credentials: this.credentialType() }) + .then(api.checkIfLoggedOut) .then(api.convertJSON) .then(api.checkForErrors); }, @@ -140,6 +141,7 @@ export const api = { method: "DELETE", credentials: this.credentialType() }) + .then(api.checkIfLoggedOut) .then(api.convertJSON) .then(api.checkForErrors); }, From 1bbd379d1bd4a705b8316154b179e3e2f4999ca9 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 2 Jun 2018 12:36:47 -0400 Subject: [PATCH 29/31] Rename isCollapsed in ForgotPassword to make more sense Signed-off-by: Mcat12 --- src/components/ForgotPassword.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/ForgotPassword.js b/src/components/ForgotPassword.js index 6e7092c..c1a0131 100644 --- a/src/components/ForgotPassword.js +++ b/src/components/ForgotPassword.js @@ -24,14 +24,14 @@ export default class ForgotPassword extends Component { }; /** - * @returns {Boolean|boolean} If the body should be collapsed + * @returns {Boolean|boolean} If the body should be expanded */ - isCollapsed = () => this.props.error || !this.state.collapsed; + isExpanded = () => this.props.error || !this.state.collapsed; render() { return (
    -
    +

    @@ -41,11 +41,11 @@ export default class ForgotPassword extends Component {

    -
    After installing Pi-hole for the first time, a password is generated and displayed to the user. The password cannot be retrieved later on, but it is possible to set a new password (or From 98bdb6ef8db38fb713f5db691d8faff211492002 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Thu, 15 Mar 2018 13:39:19 -0700 Subject: [PATCH 30/31] Display the current status in the sidebar (used to be static) Signed-off-by: Mcat12 --- src/components/Sidebar.js | 3 ++- src/components/StatusBadge.js | 34 ++++++++++++++++++++++++++++++++++ src/utils.js | 3 +++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/components/StatusBadge.js diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js index 974d8f1..7192f75 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -14,6 +14,7 @@ import { Nav, NavItem } from 'reactstrap'; import logo from '../img/logo.svg'; import { mobileSidebarHide } from "./Header"; import { api } from "../utils"; +import StatusBadge from "./StatusBadge"; const nav = { items: [ @@ -126,7 +127,7 @@ export default props => {


    - Online +
  • {navList(nav.items, props)} diff --git a/src/components/StatusBadge.js b/src/components/StatusBadge.js new file mode 100644 index 0000000..6507a9f --- /dev/null +++ b/src/components/StatusBadge.js @@ -0,0 +1,34 @@ +import React, { Component } from 'react'; +import { api, makeCancelable, ignoreCancel } from '../utils'; + +export default class StatusBadge extends Component { + state = { + status: "enabled" + }; + + updateStatus = () => { + this.updateHandler = makeCancelable(api.getStatus(), { repeat: this.updateStatus, interval: 5000 }); + this.updateHandler.promise + .then(res => { + this.setState({ status: res.status }); + }) + .catch(ignoreCancel) + .catch(() => { + this.setState({ status: "unknown" }); + }); + }; + + componentDidMount() { + this.updateStatus(); + } + + render() { + return ( + this.state.status === "enabled" + ? + Online + : + Offline + ); + } +} \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 7ef0219..1735aba 100644 --- a/src/utils.js +++ b/src/utils.js @@ -117,6 +117,9 @@ export const api = { removeWildlist(domain) { return api.delete("dns/wildlist/" + domain); }, + getStatus() { + return api.get("dns/status") + }, get(url) { return fetch(api.urlFor(url), { credentials: this.credentialType() From 359a983ec53bcaf8905bb2047e3541e938068106 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 2 Jun 2018 12:56:41 -0400 Subject: [PATCH 31/31] Change StatusBadge text Signed-off-by: Mcat12 --- src/components/StatusBadge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/StatusBadge.js b/src/components/StatusBadge.js index 6507a9f..6275304 100644 --- a/src/components/StatusBadge.js +++ b/src/components/StatusBadge.js @@ -26,9 +26,9 @@ export default class StatusBadge extends Component { return ( this.state.status === "enabled" ? - Online + Enabled : - Offline + Disabled ); } } \ No newline at end of file