diff --git a/package-lock.json b/package-lock.json index 7cf758b..cce606c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2957,7 +2957,7 @@ "inherits": "2.0.3", "md5.js": "1.3.4", "ripemd160": "2.0.2", - "sha.js": "2.4.8" + "sha.js": "2.4.11" } }, "create-hmac": { @@ -2971,7 +2971,7 @@ "inherits": "2.0.3", "ripemd160": "2.0.2", "safe-buffer": "5.1.1", - "sha.js": "2.4.8" + "sha.js": "2.4.11" } }, "cross-spawn": { @@ -6783,8 +6783,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", @@ -9830,7 +9829,7 @@ "create-hmac": "1.1.7", "ripemd160": "2.0.2", "safe-buffer": "5.1.1", - "sha.js": "2.4.8" + "sha.js": "2.4.11" } }, "performance-now": { @@ -12296,8 +12295,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==" }, "safe-regex": { "version": "1.1.0", @@ -12609,12 +12607,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": { diff --git a/package.json b/package.json index ad5d2ed..dcb9d52 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "react-router-dom": "^4.2.2", "react-table": "^6.8.2", "react-transition-group": "^2.3.1", - "reactstrap": "^5.0.0" + "reactstrap": "^5.0.0", + "sha.js": "^2.4.11" }, "scripts": { "start": "react-scripts start", 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} diff --git a/src/components/ForgotPassword.js b/src/components/ForgotPassword.js new file mode 100644 index 0000000..c1a0131 --- /dev/null +++ b/src/components/ForgotPassword.js @@ -0,0 +1,63 @@ +/* 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 expanded + */ + isExpanded = () => 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/components/Sidebar.js b/src/components/Sidebar.js index 058cb6f..974d8f1 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -13,44 +13,60 @@ 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' + icon: 'fa fa-user', + auth: false, + authStrict: true + }, + { + name: 'Logout', + url: '/logout', + icon: 'fa fa-user-times', + auth: true, + authStrict: true } ] }; @@ -81,7 +97,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 ( diff --git a/src/containers/Full.js b/src/containers/Full.js index 4d7d144..a574571 100644 --- a/src/containers/Full.js +++ b/src/containers/Full.js @@ -21,6 +21,8 @@ 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"; +import { api } from "../utils"; export default props => (
    @@ -33,11 +35,12 @@ export default props => ( - + +
    @@ -46,3 +49,31 @@ export default props => (