diff --git a/.travis.yml b/.travis.yml index 2e84f88..0fe326e 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 -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' + - rm ./FTL-client deploy: provider: pages diff --git a/package-lock.json b/package-lock.json index d88cb4f..fab32e0 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": { @@ -6820,8 +6820,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", @@ -9875,7 +9874,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": { @@ -12905,8 +12904,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", @@ -13218,12 +13216,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 cbed52a..dc378f7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,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 143d119..55857e6 100644 --- a/src/components/DomainInput.js +++ b/src/components/DomainInput.js @@ -11,7 +11,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { translate } from 'react-i18next'; -import { ignoreCancel, makeCancelable } from "../utils"; +import { api, ignoreCancel, makeCancelable } from "../utils"; class DomainInput extends Component { state = { @@ -52,11 +52,16 @@ class DomainInput extends Component { type="text" className="form-control" placeholder={t("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 0b9b6ed..8ab054b 100644 --- a/src/components/DomainList.js +++ b/src/components/DomainList.js @@ -11,7 +11,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { translate } from 'react-i18next'; -import { ignoreCancel, makeCancelable } from "../utils"; +import { api, ignoreCancel, makeCancelable } from "../utils"; class DomainList extends Component { onRemove(domain) { @@ -37,9 +37,13 @@ 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 c66a5d0..397d82f 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -14,44 +14,61 @@ 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"; +import StatusBadge from "./StatusBadge"; 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 } ] }; @@ -82,7 +99,18 @@ const navDropdown = (item, key, props) => ( ); const navList = (items, props) => - items.map((item, index) => item.children ? navDropdown(item, index, props) : navItem(item, index, props)); + 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, props); + }); const Sidebar = props => { return ( @@ -100,7 +128,7 @@ const Sidebar = props => {


    - Online +
  • {navList(nav.items, props)} diff --git a/src/components/StatusBadge.js b/src/components/StatusBadge.js new file mode 100644 index 0000000..6275304 --- /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" + ? + Enabled + : + Disabled + ); + } +} \ No newline at end of file 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 => (