From 67f8e0c2b8ceabada0858d945bd35a6e71293b4e Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 12 Oct 2015 17:01:40 +0530 Subject: [PATCH 01/48] Change table view into a grid view (list of agents) --- js/app.jsx | 2 +- js/components/FilterableAgentTable.jsx | 95 +++++++++++++++++++------- 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index deb2c04..0c5c7ec 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -88,7 +88,7 @@ const About = (props) => { class Agents extends React.Component { render() { - return + return } } diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index e2333d8..c1067f5 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -18,7 +18,7 @@ export class FilterableAgentTable extends React.Component { } render() { return ( -
+

AGENTS

- {' '} - Only show OFFLINE agents + Only show offline agents
@@ -80,7 +80,7 @@ class AgentSearchBar extends React.Component { } } -class AgentTable extends React.Component { +class AgentGrid extends React.Component { render() { var rows = []; this.props.agents.forEach( @@ -88,45 +88,94 @@ class AgentTable extends React.Component { if ((agent.host_name.toLowerCase().indexOf(this.props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && this.props.offlineOnly)) { return } - rows.push() + rows.push() } ); return ( - - - - - - - - {rows} -
HostStatus
+
+ {rows} +
) } } -class AgentRow extends React.Component { +class AgentBox extends React.Component { render() { var agentLink = '/agents/'+this.props.agent.uid; var styles = { online: { padding: '0.4rem', - color:'#fff', - backgroundColor:'#6cc644', + color:'#004400', + backgroundColor:'#88cc88', borderRadius: '0.2rem', + margin: '0.2rem', }, offline: { padding: '0.4rem', - color:'#fff', - backgroundColor:'#d32f2f', + color:'#550000', + backgroundColor:'#ffaaaa', borderRadius: '0.2rem', + margin: '0.2rem', + }, + hostname: { + offline: { + fontWeight: '700', + width:'100%', + borderRadius:'0.2rem', + }, + online: { + fontWeight: '700', + width:'100%', + borderRadius:'0.2rem', + }, }, }; return( - - {this.props.agent.host_name} - {(this.props.agent.status === 'online')?ONLINE:OFFLINE} - + +
+
{this.props.agent.host_name}
+
{this.props.agent.status}
+
+ ) } } + +class MemoryPercentage extends React.Component { + constructor(props) { + super(props); + this.loadDataFromServer = this.loadDataFromServer.bind(this); + this.state = { + data: [], + } + } + + loadDataFromServer() { + $.ajax({ + url: 'http://192.168.1.119:3000/api/events?uid='+this.props.uid+'&policy_name=default_system_data', + dataType: 'json', + cache: false, + success: function(data) { + this.setState({data: data}); + }.bind(this), + error: function(xhr, status, err) { + console.error(this.props.url, status, err.toString()); + }.bind(this), + }) + } + componentDidMount() { + this.loadDataFromServer(); + setInterval(this.loadDataFromServer, this.props.pollInterval); + } + render() { + if (this.props.status === 'offline' ||this.state.data === null || this.state.data.length === 0) { + return

Memory: unknown

+ } else { + var m = this.state.data[this.state.data.length-1]; + var activeMemory = m.Data.memory.active.substring(0,m.Data.memory.active.length-3); + var totalMemory = m.Data.memory.total.substring(0,m.Data.memory.total.length-3); + var activeMemPercentage = activeMemory/totalMemory * 100; + return

Memory: {activeMemPercentage.toFixed(2)} %

+ } + } +} From 31d890d36ad2c8877e3b042d23877639c25f99e9 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Tue, 13 Oct 2015 11:09:45 +0530 Subject: [PATCH 02/48] Make MemoryData a dumb component SummarizedSystemData will contain MemoryData, CPUData, etc. --- js/components/FilterableAgentTable.jsx | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index c1067f5..44fda42 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -131,17 +131,18 @@ class AgentBox extends React.Component { }, }; return( - +
{this.props.agent.host_name}
-
{this.props.agent.status}
+
{this.props.agent.status}
+
) } } -class MemoryPercentage extends React.Component { +class SummarizedSystemData extends React.Component { constructor(props) { super(props); this.loadDataFromServer = this.loadDataFromServer.bind(this); @@ -168,14 +169,20 @@ class MemoryPercentage extends React.Component { setInterval(this.loadDataFromServer, this.props.pollInterval); } render() { - if (this.props.status === 'offline' ||this.state.data === null || this.state.data.length === 0) { - return

Memory: unknown

- } else { - var m = this.state.data[this.state.data.length-1]; - var activeMemory = m.Data.memory.active.substring(0,m.Data.memory.active.length-3); - var totalMemory = m.Data.memory.total.substring(0,m.Data.memory.total.length-3); - var activeMemPercentage = activeMemory/totalMemory * 100; - return

Memory: {activeMemPercentage.toFixed(2)} %

- } + return ( + + ) + } +} + +const MemoryData = (props) => { + if (props.status === 'offline' ||props.data === null || props.data.length === 0) { + return

Active Memory: unknown

+ } else { + var m = props.data[props.data.length-1]; + var activeMemory = m.Data.memory.active.substring(0, m.Data.memory.active.length-3); + var totalMemory = m.Data.memory.total.substring(0, m.Data.memory.total.length-3); + var activeMemPercentage = activeMemory/totalMemory * 100; + return

Active Memory: {activeMemPercentage.toFixed(2)} %

} } From c2364be3a22992b5e2bd530ae8d35e69d7f8d7cf Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 19 Oct 2015 12:06:58 +0530 Subject: [PATCH 03/48] Add a fixed height to agent boxes --- js/components/FilterableAgentTable.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 44fda42..8b2ded4 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -109,6 +109,7 @@ class AgentBox extends React.Component { backgroundColor:'#88cc88', borderRadius: '0.2rem', margin: '0.2rem', + height: '8rem', }, offline: { padding: '0.4rem', @@ -116,6 +117,7 @@ class AgentBox extends React.Component { backgroundColor:'#ffaaaa', borderRadius: '0.2rem', margin: '0.2rem', + height: '8rem', }, hostname: { offline: { @@ -170,19 +172,21 @@ class SummarizedSystemData extends React.Component { } render() { return ( - +
+ +
) } } const MemoryData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return

Active Memory: unknown

+ return
Active Memory: unknown
} else { var m = props.data[props.data.length-1]; var activeMemory = m.Data.memory.active.substring(0, m.Data.memory.active.length-3); var totalMemory = m.Data.memory.total.substring(0, m.Data.memory.total.length-3); var activeMemPercentage = activeMemory/totalMemory * 100; - return

Active Memory: {activeMemPercentage.toFixed(2)} %

+ return
Active Memory: {activeMemPercentage.toFixed(2)} %
} } From 95c4b9f53d4b0f91d3edd697b6bddc4f31d7785a Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 19 Oct 2015 13:11:11 +0530 Subject: [PATCH 04/48] Fix memory leak related to setInterval setInterval tries to setState even when the component is unmounted. So, clear the interval using its ID when a component will unmount. --- js/app.jsx | 5 ++++- js/components/FilterableAgentTable.jsx | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index 0c5c7ec..c58d468 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -115,7 +115,10 @@ class AgentTableWrapper extends React.Component { } componentDidMount() { this.loadDataFromServer(); - setInterval(this.loadDataFromServer, this.props.pollInterval); + this.intervalID = setInterval(this.loadDataFromServer, this.props.pollInterval); + } + componentWillUnmount() { + clearInterval(this.intervalID); } render() { return diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 8b2ded4..51d552e 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -43,7 +43,6 @@ class AgentSearchBar extends React.Component { this.handleChange = this.handleChange.bind(this); } handleChange() { - console.log(ReactDOM.findDOMNode(this.refs.filterTextInput).value); // delete this this.props.onUserInput( ReactDOM.findDOMNode(this.refs.filterTextInput).value, ReactDOM.findDOMNode(this.refs.offlineOnlyInput).checked @@ -168,7 +167,10 @@ class SummarizedSystemData extends React.Component { } componentDidMount() { this.loadDataFromServer(); - setInterval(this.loadDataFromServer, this.props.pollInterval); + this.intervalID = setInterval(this.loadDataFromServer, this.props.pollInterval); + } + componentWillUnmount() { + clearInterval(this.intervalID); } render() { return ( From 75521c0a3b547700063b33dc499459ce69a4d6bf Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 19 Oct 2015 17:16:39 +0530 Subject: [PATCH 05/48] Add history as dependency and update some devDependencies --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9642b5b..0f783b2 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "homepage": "https://github.com/codeignition/muzzle#readme", "dependencies": { + "history": "^1.12.5", "react": "^0.14.0", "react-dom": "^0.14.0", "react-router": "^1.0.0-rc2" @@ -27,11 +28,11 @@ "babel-eslint": "^4.1.3", "babel-loader": "^5.3.2", "css-loader": "^0.19.0", - "eslint": "^1.6.0", + "eslint": "^1.7.1", "eslint-loader": "^1.0.0", - "eslint-plugin-react": "^3.4.2", + "eslint-plugin-react": "^3.6.2", "style-loader": "^0.12.4", "webpack": "^1.12.2", - "webpack-dev-server": "^1.12.0" + "webpack-dev-server": "^1.12.1" } } From e2380896513e7740a4ad2337bd06eb0d44f96108 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 19 Oct 2015 17:45:22 +0530 Subject: [PATCH 06/48] Add auth flow Mostly copied from the auth-flow example of react-router. Currently, it is contrived and doesn't even connect to the server for login or signup. --- js/app.jsx | 164 ++++++++++++++++++++++++++++++++++++++++------------ js/auth.jsx | 57 ++++++++++++++++++ 2 files changed, 184 insertions(+), 37 deletions(-) create mode 100644 js/auth.jsx diff --git a/js/app.jsx b/js/app.jsx index c58d468..af87b36 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -1,20 +1,48 @@ import React from 'react' import ReactDOM from 'react-dom' -import { Router, Link, Route } from 'react-router' +import { Router, Link, Route, History } from 'react-router' +import { createHashHistory } from 'history' import '../css/muzzle.css' // Try loading common css in html itself import { FilterableAgentTable } from './components/FilterableAgentTable' +import { Auth } from './auth' -const App = (props) => { - return ( -
- -
-
- {props.children || } -
-
-
- ) +class App extends React.Component { + constructor(props) { + super(props); + this.state = { + loggedIn: Auth.loggedIn(), + } + this.updateAuth = this.updateAuth.bind(this); + } + updateAuth(loggedIn) { + this.setState({ + loggedIn: loggedIn, + }) + } + componentWillMount() { + Auth.onChange = this.updateAuth + Auth.login() + } + render() { + if (this.state.loggedIn) { + return ( +
+ +
+ {Auth.getToken()} + Log out +
+ {this.props.children || } +
+
+
+ ) + } else { + return ( + Sign in + ) + } + } } const Home = (props) => { @@ -42,28 +70,28 @@ const Navbar = (props) => { ) } @@ -152,11 +180,73 @@ const NoMatch = (props) => { ) } +var Login = React.createClass({ + mixins: [ History ], + + getInitialState() { + return { + error: false, + } + }, + + handleSubmit(event) { + event.preventDefault(); + + var email = ReactDOM.findDOMNode(this.refs.email).value + var pass = ReactDOM.findDOMNode(this.refs.pass).value + + Auth.login(email, pass, (loggedIn) => { + if (!loggedIn) { + return this.setState({ error: true }) + } + + var { location } = this.props + + if (location.state && location.state.nextPathname) { + this.history.replaceState(null, location.state.nextPathname) + } else { + this.history.replaceState(null, '/agents') + } + }) + }, + + render() { + return ( +
+ + (hint: password1)
+ + {this.state.error && ( +

Bad login information

+ )} +
+ ) + }, +}); + +class Logout extends React.Component { + componentDidMount() { + Auth.logout() + } + render() { + return

You are now logged out

+ } +} + +function requireAuth(nextState, replaceState) { + if (!Auth.loggedIn()) + replaceState({ nextPathname: nextState.location.pathname }, '/login') +} + +const history = createHashHistory(); + ReactDOM.render( - + + + - - + + diff --git a/js/auth.jsx b/js/auth.jsx new file mode 100644 index 0000000..ddbce1f --- /dev/null +++ b/js/auth.jsx @@ -0,0 +1,57 @@ +export const Auth = { + login(email, pass, cb) { + cb = arguments[arguments.length - 1] + if (localStorage.token) { + if (cb) { + cb(true); + this.onChange(true); + return + } + } + pretendRequest(email, pass, (res) => { + if (res.authenticated) { + localStorage.token = res.token + if (cb) { + cb(true); + this.onChange(true); + } + } else { + if (cb) { + cb(false); + this.onChange(false); + } + } + }) + }, + + getToken() { + return localStorage.token + }, + + logout(cb) { + delete localStorage.token + if (cb) { + cb(); + this.onChange(false); + } + }, + + loggedIn() { + return !!localStorage.token + }, + + onChange() {}, +} + +function pretendRequest(email, pass, cb) { + setTimeout(() => { + if (email === 'joe@example.com' && pass === 'password1') { + cb({ + authenticated: true, + token: Math.random().toString(36).substring(7), + }) + } else { + cb({ authenticated: false }) + } + }, 0) +} From a2acdd639959ae97c27c7aca0ea463c4a04b2713 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Tue, 20 Oct 2015 11:44:45 +0530 Subject: [PATCH 07/48] Add requireAuth on root route It makes the app require auth for all the child routes, instead of adding for each of the child routes --- js/app.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index af87b36..063422d 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -244,9 +244,9 @@ ReactDOM.render( - - - + + + From ef8737bd09f54a5b03a8f4a06e76eacf9d7b1b90 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Tue, 20 Oct 2015 15:32:55 +0530 Subject: [PATCH 08/48] Change styles for login and logout pages --- js/app.jsx | 60 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index 063422d..86ab232 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -24,24 +24,26 @@ class App extends React.Component { Auth.login() } render() { + let c; if (this.state.loggedIn) { - return ( + c = (
{Auth.getToken()} Log out -
- {this.props.children || } -
+
{this.props.children || }
) } else { - return ( - Sign in - ) + c = Sign in } + return ( +
+ {c} +
+ ) } } @@ -203,7 +205,11 @@ var Login = React.createClass({ var { location } = this.props if (location.state && location.state.nextPathname) { - this.history.replaceState(null, location.state.nextPathname) + if (location.state.nextPathname === '/') { + this.history.replaceState(null, '/agents') + } else { + this.history.replaceState(null, location.state.nextPathname) + } } else { this.history.replaceState(null, '/agents') } @@ -212,14 +218,31 @@ var Login = React.createClass({ render() { return ( +
+

- - (hint: password1)
- - {this.state.error && ( -

Bad login information

- )} +
+
+ +
+
+
+
+ +
+
+ + { + this.state.error && ( +

Bad login information

+ ) + }
+
) }, }); @@ -229,7 +252,14 @@ class Logout extends React.Component { Auth.logout() } render() { - return

You are now logged out

+ let s = { + margin: '20%', + } + return ( +
+

You are now logged out!

Log In
+
+ ) } } From 25e302c78526db7eb36d52d16b6b705e95e224a3 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Tue, 20 Oct 2015 16:45:34 +0530 Subject: [PATCH 09/48] Reorder components to fix formatting issue --- js/app.jsx | 79 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index 86ab232..cc77cac 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -182,6 +182,23 @@ const NoMatch = (props) => { ) } +class Logout extends React.Component { + componentDidMount() { + Auth.logout() + } + render() { + let s = { + margin: '20%', + } + return ( +
+

You are now logged out!

Log In
+
+ ) + } +} + + var Login = React.createClass({ mixins: [ History ], @@ -219,50 +236,34 @@ var Login = React.createClass({ render() { return (
-

-
-
-
- -
-
-
-
- -
+

+ +
+
+ +
+
+
+
+ +
+
+ + { + this.state.error && ( +

Bad login information

+ ) + } +
- - { - this.state.error && ( -

Bad login information

- ) - } - -
) }, }); -class Logout extends React.Component { - componentDidMount() { - Auth.logout() - } - render() { - let s = { - margin: '20%', - } - return ( -
-

You are now logged out!

Log In
-
- ) - } -} - function requireAuth(nextState, replaceState) { if (!Auth.loggedIn()) replaceState({ nextPathname: nextState.location.pathname }, '/login') From 72133d7825368b96fafd3fcc53156c7ae7e88af0 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 21 Oct 2015 11:30:18 +0530 Subject: [PATCH 10/48] Style changes to Login page --- js/app.jsx | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index cc77cac..3f68e75 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -235,30 +235,38 @@ var Login = React.createClass({ render() { return ( -
-

-
-
-
- -
+
+
+
+
-
-
-
- - { - this.state.error && ( -

Bad login information

- ) - } - +
+
+
) }, From 53b6c70163c54ed5116c9923d20a8528ecb617a1 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 21 Oct 2015 12:02:49 +0530 Subject: [PATCH 11/48] Add stub for Register component and move about page to top level Now, a user need not be logged in to view the about page --- js/app.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/app.jsx b/js/app.jsx index 3f68e75..b7e3e4b 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -272,6 +272,12 @@ var Login = React.createClass({ }, }); +const Register = (props) => { + return ( +

Registration page

+ ) +} + function requireAuth(nextState, replaceState) { if (!Auth.loggedIn()) replaceState({ nextPathname: nextState.location.pathname }, '/login') @@ -283,10 +289,11 @@ ReactDOM.render( + + - , From 8642cc319667034da9c1903068cd557509f120e7 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 21 Oct 2015 12:16:45 +0530 Subject: [PATCH 12/48] Make APIserver a constant in app.jsx It is easy to change the APIserver at one place. Also change style for the about page. --- js/app.jsx | 22 ++++++++++------------ js/components/FilterableAgentTable.jsx | 3 ++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index b7e3e4b..f6b3fd8 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -6,6 +6,8 @@ import '../css/muzzle.css' // Try loading common css in html itself import { FilterableAgentTable } from './components/FilterableAgentTable' import { Auth } from './auth' +const APIserver = 'http://192.168.1.119:3000' + class App extends React.Component { constructor(props) { super(props); @@ -99,17 +101,13 @@ const Navbar = (props) => { } const About = (props) => { - var styles = { - errorBox: { - marginLeft: '25%', - marginRight: '25%', - position: 'absolute', - textAlign: 'center', - top: '40%', - }, + var s = { + margin: '0 auto', + padding: '4rem', + position: 'absolute', } return ( -
+

About

Recon is the brainchild of the people at CodeIgnition. Recon is completely opensource and aims to make monitoring simple and intuitive. If you have any issues / suggestions, please open an issue at our Github repository.

@@ -118,7 +116,7 @@ const About = (props) => { class Agents extends React.Component { render() { - return + return } } @@ -245,8 +243,8 @@ var Login = React.createClass({
- - + +
diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 51d552e..f916ca5 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -1,6 +1,7 @@ import React from 'react' import ReactDOM from 'react-dom' import { Link } from 'react-router' +import { APIserver } from './../app' export class FilterableAgentTable extends React.Component { constructor(props) { @@ -154,7 +155,7 @@ class SummarizedSystemData extends React.Component { loadDataFromServer() { $.ajax({ - url: 'http://192.168.1.119:3000/api/events?uid='+this.props.uid+'&policy_name=default_system_data', + url: APIserver+'/api/events?uid='+this.props.uid+'&policy_name=default_system_data', dataType: 'json', cache: false, success: function(data) { From c9afdf510cd6a755482729d658651046e1b3cc52 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 21 Oct 2015 12:42:54 +0530 Subject: [PATCH 13/48] Add email in localStorage on login, and getEmail() helper function --- js/auth.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/auth.jsx b/js/auth.jsx index ddbce1f..2d94d79 100644 --- a/js/auth.jsx +++ b/js/auth.jsx @@ -11,6 +11,7 @@ export const Auth = { pretendRequest(email, pass, (res) => { if (res.authenticated) { localStorage.token = res.token + localStorage.email = email if (cb) { cb(true); this.onChange(true); @@ -28,6 +29,10 @@ export const Auth = { return localStorage.token }, + getEmail() { + return localStorage.email + }, + logout(cb) { delete localStorage.token if (cb) { From f6e98584ba1e3c0947811652a31093a3497ad605 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 21 Oct 2015 12:45:02 +0530 Subject: [PATCH 14/48] Pass user email as a prop to Navbar --- js/app.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index f6b3fd8..72040a7 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -27,13 +27,13 @@ class App extends React.Component { } render() { let c; + // let authToken = Auth.getToken(); + let userEmail = Auth.getEmail(); if (this.state.loggedIn) { c = (
- +
- {Auth.getToken()} - Log out
{this.props.children || }
@@ -87,7 +87,7 @@ const Navbar = (props) => {
Profile From 2398160b24c5e4b0a7d7605681736bcfc460038e Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 11:17:44 +0530 Subject: [PATCH 15/48] Export APIserver constant from app.jsx forgot to do that in the previous commits --- js/app.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/app.jsx b/js/app.jsx index 72040a7..b489daa 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -6,7 +6,7 @@ import '../css/muzzle.css' // Try loading common css in html itself import { FilterableAgentTable } from './components/FilterableAgentTable' import { Auth } from './auth' -const APIserver = 'http://192.168.1.119:3000' +export const APIserver = 'http://192.168.1.119:3000' class App extends React.Component { constructor(props) { From d632598b0db951b066557ef235c0bc6de2e3e75c Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 12:15:22 +0530 Subject: [PATCH 16/48] Update eslint and eslint-plugin-react --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0f783b2..f50e849 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "babel-eslint": "^4.1.3", "babel-loader": "^5.3.2", "css-loader": "^0.19.0", - "eslint": "^1.7.1", + "eslint": "^1.7.3", "eslint-loader": "^1.0.0", - "eslint-plugin-react": "^3.6.2", + "eslint-plugin-react": "^3.6.3", "style-loader": "^0.12.4", "webpack": "^1.12.2", "webpack-dev-server": "^1.12.1" From 8d4f285df8daa45e142c4f7ed84688a2f31f8cbd Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 12:33:28 +0530 Subject: [PATCH 17/48] Simplify styles by using ES7 spread feature --- js/components/FilterableAgentTable.jsx | 35 +++++++++++--------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index f916ca5..984f707 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -101,41 +101,34 @@ class AgentGrid extends React.Component { class AgentBox extends React.Component { render() { - var agentLink = '/agents/'+this.props.agent.uid; - var styles = { + let agentLink = '/agents/'+this.props.agent.uid; + const baseStyle = { + padding: '0.4rem', + borderRadius: '0.2rem', + margin: '0.2rem', + height: '8rem', + } + const styles = { online: { - padding: '0.4rem', + ...baseStyle, color:'#004400', backgroundColor:'#88cc88', - borderRadius: '0.2rem', - margin: '0.2rem', - height: '8rem', }, offline: { - padding: '0.4rem', + ...baseStyle, color:'#550000', backgroundColor:'#ffaaaa', - borderRadius: '0.2rem', - margin: '0.2rem', - height: '8rem', }, hostname: { - offline: { - fontWeight: '700', - width:'100%', - borderRadius:'0.2rem', - }, - online: { - fontWeight: '700', - width:'100%', - borderRadius:'0.2rem', - }, + fontWeight: '700', + width:'100%', + borderRadius:'0.2rem', }, }; return(
-
{this.props.agent.host_name}
+
{this.props.agent.host_name}
{this.props.agent.status}
From c0ca60e6cae7fb56b13c8a535fedcd8e4233c87f Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 12:53:12 +0530 Subject: [PATCH 18/48] Change occurences of var to let in FilterableAgentTable --- js/components/FilterableAgentTable.jsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 984f707..d8e142a 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -82,7 +82,7 @@ class AgentSearchBar extends React.Component { class AgentGrid extends React.Component { render() { - var rows = []; + let rows = []; this.props.agents.forEach( (agent) => { if ((agent.host_name.toLowerCase().indexOf(this.props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && this.props.offlineOnly)) { @@ -145,7 +145,6 @@ class SummarizedSystemData extends React.Component { data: [], } } - loadDataFromServer() { $.ajax({ url: APIserver+'/api/events?uid='+this.props.uid+'&policy_name=default_system_data', @@ -179,10 +178,10 @@ const MemoryData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { return
Active Memory: unknown
} else { - var m = props.data[props.data.length-1]; - var activeMemory = m.Data.memory.active.substring(0, m.Data.memory.active.length-3); - var totalMemory = m.Data.memory.total.substring(0, m.Data.memory.total.length-3); - var activeMemPercentage = activeMemory/totalMemory * 100; + let m = props.data[props.data.length-1]; + let activeMemory = m.Data.memory.active.substring(0, m.Data.memory.active.length-3); + let totalMemory = m.Data.memory.total.substring(0, m.Data.memory.total.length-3); + let activeMemPercentage = activeMemory/totalMemory * 100; return
Active Memory: {activeMemPercentage.toFixed(2)} %
} } From 08db9e909fa0080d9d84bfa0382b7bb627d6ae0a Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 13:33:15 +0530 Subject: [PATCH 19/48] Make code concise, use let and const wherever appropriate --- js/app.jsx | 83 +++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index b489daa..e5c44c6 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -50,17 +50,15 @@ class App extends React.Component { } const Home = (props) => { - var styles = { - errorBox: { - marginLeft: '25%', - marginRight: '25%', - position: 'absolute', - textAlign: 'center', - top: '40%', - }, + const s = { + marginLeft: '25%', + marginRight: '25%', + position: 'absolute', + textAlign: 'center', + top: '40%', } return ( -
+

Welcome to Recon

Defaut dashboard? @@ -72,36 +70,28 @@ const Home = (props) => { const Navbar = (props) => { return (

) } const About = (props) => { - var s = { + const s = { margin: '0 auto', padding: '4rem', position: 'absolute', @@ -160,17 +150,15 @@ const Agent = (props) => { } const NoMatch = (props) => { - var styles = { - errorBox: { - marginLeft: '25%', - marginRight: '25%', - position: 'absolute', - textAlign: 'center', - top: '40%', - }, + const s = { + marginLeft: '25%', + marginRight: '25%', + position: 'absolute', + textAlign: 'center', + top: '40%', } return ( -
+

Sorry, this page isn't available.

The link you followed may be broken, or the page may have been removed. @@ -209,15 +197,15 @@ var Login = React.createClass({ handleSubmit(event) { event.preventDefault(); - var email = ReactDOM.findDOMNode(this.refs.email).value - var pass = ReactDOM.findDOMNode(this.refs.pass).value + let email = ReactDOM.findDOMNode(this.refs.email).value + let pass = ReactDOM.findDOMNode(this.refs.pass).value Auth.login(email, pass, (loggedIn) => { if (!loggedIn) { return this.setState({ error: true }) } - var { location } = this.props + let { location } = this.props if (location.state && location.state.nextPathname) { if (location.state.nextPathname === '/') { @@ -277,8 +265,9 @@ const Register = (props) => { } function requireAuth(nextState, replaceState) { - if (!Auth.loggedIn()) + if (!Auth.loggedIn()) { replaceState({ nextPathname: nextState.location.pathname }, '/login') + } } const history = createHashHistory(); From 83e6aff230aca535125603058578a51d140be5a2 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 13:36:20 +0530 Subject: [PATCH 20/48] Change MemoryData component to read the data properly from new API --- js/components/FilterableAgentTable.jsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index d8e142a..245c3e3 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -93,7 +93,7 @@ class AgentGrid extends React.Component { ); return (

- {rows} + {rows}
) } @@ -110,12 +110,12 @@ class AgentBox extends React.Component { } const styles = { online: { - ...baseStyle, + ...baseStyle, color:'#004400', backgroundColor:'#88cc88', }, offline: { - ...baseStyle, + ...baseStyle, color:'#550000', backgroundColor:'#ffaaaa', }, @@ -176,12 +176,17 @@ class SummarizedSystemData extends React.Component { const MemoryData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Active Memory: unknown
+ return
Memory usage: unknown
} else { - let m = props.data[props.data.length-1]; - let activeMemory = m.Data.memory.active.substring(0, m.Data.memory.active.length-3); - let totalMemory = m.Data.memory.total.substring(0, m.Data.memory.total.length-3); - let activeMemPercentage = activeMemory/totalMemory * 100; - return
Active Memory: {activeMemPercentage.toFixed(2)} %
+ console.log(props.data); + let m = props.data[props.data.length-1].Data.Memory; + // We are not counting cached and buffer memory in used memory. + // htop does the same thing. + // check http://askubuntu.com/a/369589 and http://www.linuxatemyram.com/ + // TODO: Should we move this logic to the API? + let usedMemory = m.Used-m.Cached-m.Buffers; + let totalMemory = m.Total; + let activeMemPercentage = usedMemory/totalMemory * 100; + return
Memory usage: {activeMemPercentage.toFixed(2)} %
} } From 169d067fc616bf2c914b37ed4a1b59b63b41e9a0 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 13:43:53 +0530 Subject: [PATCH 21/48] Make AgentGrid a dumb component It makes the code more simple and possibly allow for optimizations by React --- js/components/FilterableAgentTable.jsx | 35 ++++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 245c3e3..4629b91 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -52,7 +52,6 @@ class AgentSearchBar extends React.Component { render() { return ( -
{ - if ((agent.host_name.toLowerCase().indexOf(this.props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && this.props.offlineOnly)) { - return - } - rows.push() +const AgentGrid = (props) => { + let rows = []; + props.agents.forEach( + (agent) => { + if ((agent.host_name.toLowerCase().indexOf(this.props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && this.props.offlineOnly)) { + return } - ); - return ( -
- {rows} -
- ) - } + rows.push() + } + ); + return ( +
+ {rows} +
+ ) } class AgentBox extends React.Component { @@ -110,12 +107,12 @@ class AgentBox extends React.Component { } const styles = { online: { - ...baseStyle, + ...baseStyle, color:'#004400', backgroundColor:'#88cc88', }, offline: { - ...baseStyle, + ...baseStyle, color:'#550000', backgroundColor:'#ffaaaa', }, From bfc6353d9995ff3cbbb0c2e5d9ad2f17a95da46f Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 22 Oct 2015 13:47:28 +0530 Subject: [PATCH 22/48] Fix oversight in the previous commit --- js/components/FilterableAgentTable.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 4629b91..5eb044c 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -83,7 +83,7 @@ const AgentGrid = (props) => { let rows = []; props.agents.forEach( (agent) => { - if ((agent.host_name.toLowerCase().indexOf(this.props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && this.props.offlineOnly)) { + if ((agent.host_name.toLowerCase().indexOf(props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && props.offlineOnly)) { return } rows.push() From a9c1a3ddda9079e6777dfbfec1c5984bae6b285d Mon Sep 17 00:00:00 2001 From: Hari haran Date: Tue, 27 Oct 2015 15:39:53 +0530 Subject: [PATCH 23/48] Show userspace CPU data Also, change the offline color to grey and Do not show ONLINE or OFFLINE as they are implicitly color coded. --- js/components/FilterableAgentTable.jsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 5eb044c..42393e5 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -103,7 +103,6 @@ class AgentBox extends React.Component { padding: '0.4rem', borderRadius: '0.2rem', margin: '0.2rem', - height: '8rem', } const styles = { online: { @@ -113,8 +112,8 @@ class AgentBox extends React.Component { }, offline: { ...baseStyle, - color:'#550000', - backgroundColor:'#ffaaaa', + color:'#333', + backgroundColor:'#ddd', }, hostname: { fontWeight: '700', @@ -126,7 +125,6 @@ class AgentBox extends React.Component {
{this.props.agent.host_name}
-
{this.props.agent.status}
@@ -166,6 +164,7 @@ class SummarizedSystemData extends React.Component { return (
+
) } @@ -173,7 +172,7 @@ class SummarizedSystemData extends React.Component { const MemoryData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Memory usage: unknown
+ return
Memory used NA
} else { console.log(props.data); let m = props.data[props.data.length-1].Data.Memory; @@ -184,6 +183,15 @@ const MemoryData = (props) => { let usedMemory = m.Used-m.Cached-m.Buffers; let totalMemory = m.Total; let activeMemPercentage = usedMemory/totalMemory * 100; - return
Memory usage: {activeMemPercentage.toFixed(2)} %
+ return
Memory used {activeMemPercentage.toFixed(2)} %
+ } +} + +const CPUData = (props) => { + if (props.status === 'offline' ||props.data === null || props.data.length === 0) { + return
Userspace CPU NA
+ } else { + let c = props.data[props.data.length-1].Data.CPU; + return
Userspace CPU {c.Userspace.toFixed(2)} %
} } From 8afd853aaf46c4b5dac651831dcb81c1ab768fb8 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 29 Oct 2015 11:32:17 +0530 Subject: [PATCH 24/48] Add bundled files to gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dd55084..75fcdaf 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,8 @@ build/Release # Dependency directory # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git -node_modules \ No newline at end of file +node_modules + +# Bundled js files +js/bundle.js +js/bundle.js.map \ No newline at end of file From 3962cee9a9702b8299e243f795d7e5269940a2d8 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 29 Oct 2015 11:32:33 +0530 Subject: [PATCH 25/48] Change entry into an array to fix some webpack issue --- webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index 4ef203e..d54c025 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,5 @@ module.exports = { - entry: './js/app.jsx', + entry: ['./js/app.jsx'], output: { filename: './js/bundle.js' }, From 5311e0a7df989bfbd7ef9549aa55d21a7447f3cb Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 29 Oct 2015 11:33:12 +0530 Subject: [PATCH 26/48] Change fake login credentials --- js/auth.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/auth.jsx b/js/auth.jsx index 2d94d79..71fb15a 100644 --- a/js/auth.jsx +++ b/js/auth.jsx @@ -50,7 +50,7 @@ export const Auth = { function pretendRequest(email, pass, cb) { setTimeout(() => { - if (email === 'joe@example.com' && pass === 'password1') { + if (email === 'tony@starkindustries.com' && pass === 'ironman') { cb({ authenticated: true, token: Math.random().toString(36).substring(7), From d45744620d67d71cfcdb2cf4b786f32e298da1e2 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 29 Oct 2015 12:13:43 +0530 Subject: [PATCH 27/48] Add stub for disk data --- js/components/FilterableAgentTable.jsx | 28 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 42393e5..3d15bfa 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -113,7 +113,7 @@ class AgentBox extends React.Component { offline: { ...baseStyle, color:'#333', - backgroundColor:'#ddd', + backgroundColor:'#f5f5f5', }, hostname: { fontWeight: '700', @@ -165,6 +165,7 @@ class SummarizedSystemData extends React.Component {
+
) } @@ -174,16 +175,15 @@ const MemoryData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { return
Memory used NA
} else { - console.log(props.data); - let m = props.data[props.data.length-1].Data.Memory; + let m = props.data[props.data.length-1].Data.system.memory; // We are not counting cached and buffer memory in used memory. // htop does the same thing. // check http://askubuntu.com/a/369589 and http://www.linuxatemyram.com/ // TODO: Should we move this logic to the API? - let usedMemory = m.Used-m.Cached-m.Buffers; - let totalMemory = m.Total; - let activeMemPercentage = usedMemory/totalMemory * 100; - return
Memory used {activeMemPercentage.toFixed(2)} %
+ let used = m.used-m.cached-m.buffers; + let total = m.total; + let p = used/total * 100; + return
Memory used {p.toFixed(2)} %
} } @@ -191,7 +191,17 @@ const CPUData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { return
Userspace CPU NA
} else { - let c = props.data[props.data.length-1].Data.CPU; - return
Userspace CPU {c.Userspace.toFixed(2)} %
+ let c = props.data[props.data.length-1].Data.system.cpu; + return
Userspace CPU {c.userspace.toFixed(2)} %
+ } +} + +const DiskData = (props) => { + if (props.status === 'offline' ||props.data === null || props.data.length === 0) { + return
Disk usage NA
+ } else { + let c = props.data[props.data.length-1].Data.system.disk; + let sda1p = c['/dev/sda1'].percentage_used + return
{'/dev/sda1'} {sda1p.slice(0,sda1p.length-1)} %
} } From 7db0de519e19458d9d70f260b5148d77516a673d Mon Sep 17 00:00:00 2001 From: Hari haran Date: Thu, 29 Oct 2015 16:33:12 +0530 Subject: [PATCH 28/48] Add link to home in the about page --- js/app.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/js/app.jsx b/js/app.jsx index e5c44c6..a2f77e7 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -100,6 +100,7 @@ const About = (props) => {

About

Recon is the brainchild of the people at CodeIgnition. Recon is completely opensource and aims to make monitoring simple and intuitive. If you have any issues / suggestions, please open an issue at our Github repository.

+

Go back to Home.

) } From de0d121a16800ba8a01e9ecb0453a84689814d83 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 30 Oct 2015 12:43:34 +0530 Subject: [PATCH 29/48] Specify the CSS import in a separate line for clarity --- js/app.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/app.jsx b/js/app.jsx index a2f77e7..56312aa 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -2,10 +2,11 @@ import React from 'react' import ReactDOM from 'react-dom' import { Router, Link, Route, History } from 'react-router' import { createHashHistory } from 'history' -import '../css/muzzle.css' // Try loading common css in html itself import { FilterableAgentTable } from './components/FilterableAgentTable' import { Auth } from './auth' +import '../css/muzzle.css' + export const APIserver = 'http://192.168.1.119:3000' class App extends React.Component { From b32bcbebef696da4aa9713954edba9e2a72eedd8 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 30 Oct 2015 12:53:25 +0530 Subject: [PATCH 30/48] Change text color for offline agents --- js/components/FilterableAgentTable.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 3d15bfa..808a0c8 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -112,7 +112,7 @@ class AgentBox extends React.Component { }, offline: { ...baseStyle, - color:'#333', + color:'#626466', backgroundColor:'#f5f5f5', }, hostname: { From 6caf98d7ec3df982f2f09d1cc5db947a733fb182 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 30 Oct 2015 12:55:42 +0530 Subject: [PATCH 31/48] Remove redundant style declaration --- js/components/FilterableAgentTable.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 808a0c8..b622abe 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -54,7 +54,6 @@ class AgentSearchBar extends React.Component {
Date: Fri, 30 Oct 2015 14:32:28 +0530 Subject: [PATCH 32/48] Show disk partitions in the summary --- js/components/FilterableAgentTable.jsx | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index b622abe..0f1526a 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -27,7 +27,6 @@ export class FilterableAgentTable extends React.Component { offlineOnly={this.state.offlineOnly} onUserInput={this.handleUserInput.bind(this)} /> -
{ } ); return ( -
+
{rows}
) @@ -197,10 +196,29 @@ const CPUData = (props) => { const DiskData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Disk usage NA
+ return
Disk usage NA
} else { - let c = props.data[props.data.length-1].Data.system.disk; - let sda1p = c['/dev/sda1'].percentage_used - return
{'/dev/sda1'} {sda1p.slice(0,sda1p.length-1)} %
+ let d = props.data[props.data.length-1].Data.system.disk; + var rows = []; + for (let k in d) { + if (!d.hasOwnProperty(k)) { + continue; + } + rows.push() + } + return ( +
+ {rows} +
+ ) } } + +const DiskPartitionData = (props) => { + let p = props.data.percentage_used + return ( +
+ {props.name} {p.slice(0,p.length-1)} % +
+ ) +} From 4e1ebe9e5bda64cddf0a96624ac7ad400a7f839e Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 30 Oct 2015 15:06:14 +0530 Subject: [PATCH 33/48] Show abbreviated forms in the system summary The details are mentioned as the title html attribute so that they will show up on hover. --- js/components/FilterableAgentTable.jsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 0f1526a..41fce0e 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -171,7 +171,7 @@ class SummarizedSystemData extends React.Component { const MemoryData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Memory used NA
+ return
Memory NA
} else { let m = props.data[props.data.length-1].Data.system.memory; // We are not counting cached and buffer memory in used memory. @@ -181,22 +181,28 @@ const MemoryData = (props) => { let used = m.used-m.cached-m.buffers; let total = m.total; let p = used/total * 100; - return
Memory used {p.toFixed(2)} %
+ return
Memory {p.toFixed(2)} %
} } const CPUData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Userspace CPU NA
+ return
CPU NA
} else { let c = props.data[props.data.length-1].Data.system.cpu; - return
Userspace CPU {c.userspace.toFixed(2)} %
+ return
CPU {c.userspace.toFixed(2)} %
} } const DiskData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Disk usage NA
+ return ( +
+ + Disk NA + +
+ ) } else { let d = props.data[props.data.length-1].Data.system.disk; var rows = []; From 0102263cbf5cf342b17a319ee049b70e5f5b58b3 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 2 Nov 2015 12:47:13 +0530 Subject: [PATCH 34/48] Call constructor with props --- js/components/FilterableAgentTable.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 41fce0e..b8fd285 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -38,8 +38,8 @@ export class FilterableAgentTable extends React.Component { } class AgentSearchBar extends React.Component { - constructor() { - super(); + constructor(props) { + super(props); this.handleChange = this.handleChange.bind(this); } handleChange() { From 5389ab479f8b2fb104885e814a675f02b076310a Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 2 Nov 2015 13:01:05 +0530 Subject: [PATCH 35/48] Change top to 30% for Home and NoMatch components --- js/app.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index 56312aa..7c3ef33 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -56,13 +56,13 @@ const Home = (props) => { marginRight: '25%', position: 'absolute', textAlign: 'center', - top: '40%', + top: '30%', } return (

Welcome to Recon

- Defaut dashboard? + Defaut dashboard

) @@ -157,7 +157,7 @@ const NoMatch = (props) => { marginRight: '25%', position: 'absolute', textAlign: 'center', - top: '40%', + top: '30%', } return (
From 9210f913adac0d7d6a7904818210e72b54948998 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 2 Nov 2015 13:11:57 +0530 Subject: [PATCH 36/48] Move Agent component to a separate file --- js/app.jsx | 7 +------ js/components/Agent.jsx | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 js/components/Agent.jsx diff --git a/js/app.jsx b/js/app.jsx index 7c3ef33..f34ec45 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom' import { Router, Link, Route, History } from 'react-router' import { createHashHistory } from 'history' import { FilterableAgentTable } from './components/FilterableAgentTable' +import { Agent } from './components/Agent' import { Auth } from './auth' import '../css/muzzle.css' @@ -145,12 +146,6 @@ class AgentTableWrapper extends React.Component { } } -const Agent = (props) => { - return ( -

Agent {props.params.uid}

- ) -} - const NoMatch = (props) => { const s = { marginLeft: '25%', diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx new file mode 100644 index 0000000..bc9cab4 --- /dev/null +++ b/js/components/Agent.jsx @@ -0,0 +1,7 @@ +import React from 'react' + +export const Agent = (props) => { + return ( +

Agent {props.params.uid}

+ ) +} From a0ce99be5b9a7f704ec9b65fcb357d8da5233520 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 2 Nov 2015 15:09:12 +0530 Subject: [PATCH 37/48] Change requireAuth into an arrow function --- js/app.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index f34ec45..db438b5 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -181,7 +181,6 @@ class Logout extends React.Component { } } - var Login = React.createClass({ mixins: [ History ], @@ -261,7 +260,7 @@ const Register = (props) => { ) } -function requireAuth(nextState, replaceState) { +const requireAuth = (nextState, replaceState) => { if (!Auth.loggedIn()) { replaceState({ nextPathname: nextState.location.pathname }, '/login') } From 3fc760fe13dadc8f2d710d107613c7c502c99d69 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Mon, 2 Nov 2015 16:14:56 +0530 Subject: [PATCH 38/48] Use 'RAM' instead of 'Memory' --- js/components/FilterableAgentTable.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index b8fd285..5468f0c 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -161,7 +161,7 @@ class SummarizedSystemData extends React.Component { render() { return (
- +
@@ -169,9 +169,9 @@ class SummarizedSystemData extends React.Component { } } -const MemoryData = (props) => { +const RAMData = (props) => { if (props.status === 'offline' ||props.data === null || props.data.length === 0) { - return
Memory NA
+ return
RAM NA
} else { let m = props.data[props.data.length-1].Data.system.memory; // We are not counting cached and buffer memory in used memory. @@ -181,7 +181,7 @@ const MemoryData = (props) => { let used = m.used-m.cached-m.buffers; let total = m.total; let p = used/total * 100; - return
Memory {p.toFixed(2)} %
+ return
RAM {p.toFixed(2)} %
} } From d6f6c5788c235d1b15db717f4779102495ca2d37 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 10:26:45 +0530 Subject: [PATCH 39/48] Add import scripts for d3 and c3 in index.html There was a problem installing c3 using npm. So, we are adding it manually. --- index.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.html b/index.html index 7606598..6f4d0d8 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,8 @@ + +
@@ -17,6 +19,9 @@ + + + From 275ba56953f16d6dda17aa4d8c077e26167aff53 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 10:28:47 +0530 Subject: [PATCH 40/48] Add /api suffix to the APIServer constant --- js/app.jsx | 6 +++--- js/components/FilterableAgentTable.jsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/app.jsx b/js/app.jsx index db438b5..ac493f0 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -8,7 +8,7 @@ import { Auth } from './auth' import '../css/muzzle.css' -export const APIserver = 'http://192.168.1.119:3000' +export const APIserver = 'http://192.168.1.119:3000/api' class App extends React.Component { constructor(props) { @@ -109,7 +109,7 @@ const About = (props) => { class Agents extends React.Component { render() { - return + return } } @@ -130,7 +130,7 @@ class AgentTableWrapper extends React.Component { this.setState({data: data}); }.bind(this), error: function(xhr, status, err) { - console.error(this.props.url, status, err.toString()); + console.error(this.props.source, status, err.toString()); }.bind(this), }) } diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index 5468f0c..a192881 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -140,7 +140,7 @@ class SummarizedSystemData extends React.Component { } loadDataFromServer() { $.ajax({ - url: APIserver+'/api/events?uid='+this.props.uid+'&policy_name=default_system_data', + url: APIserver+'/events?uid='+this.props.uid+'&policy_name=default_system_data', dataType: 'json', cache: false, success: function(data) { From aa515c2af8966ce99b0ed750c73084a77917794f Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 10:30:12 +0530 Subject: [PATCH 41/48] Add charts in the Agent component Although they are basic and are buggy, checking in for reference. --- js/components/Agent.jsx | 279 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 277 insertions(+), 2 deletions(-) diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx index bc9cab4..0b8b135 100644 --- a/js/components/Agent.jsx +++ b/js/components/Agent.jsx @@ -1,7 +1,282 @@ import React from 'react' +import { APIserver } from './../app' -export const Agent = (props) => { +export class Agent extends React.Component { + constructor(props) { + super(props); + this.loadDataFromServer = this.loadDataFromServer.bind(this); + this.state = { + data: [], + } + } + loadDataFromServer() { + let url = APIserver+'/agents/'+this.props.params.uid; + $.ajax({ + url: url, + dataType: 'json', + cache: false, + success: function(data) { + this.setState({data: data}); + }.bind(this), + error: function(xhr, status, err) { + console.error(url, status, err.toString()); + }.bind(this), + }) + } + componentDidMount() { + this.loadDataFromServer(); + this.intervalID = setInterval(this.loadDataFromServer, 2000); + } + componentWillUnmount() { + clearInterval(this.intervalID); + } + render() { + return ( +
+
+ + +
+ ) + } +} + +const AgentDetails = (props) => { return ( -

Agent {props.params.uid}

+
+

{props.data.host_name}

+ {' '} + +
) } + +const AgentStatus = (props) => { + const baseStyle = { + padding: '0.4rem', + borderRadius: '0.2rem', + margin: '0.2rem', + textTransform: 'uppercase', + fontWeight: 600, + } + const styles = { + online: { + ...baseStyle, + color:'#004400', + backgroundColor:'#88cc88', + }, + offline: { + ...baseStyle, + color:'#626466', + backgroundColor:'#f5f5f5', + }, + } + return ( + {props.status} + ) +} + +class AgentCharts extends React.Component { + constructor(props) { + super(props); + this.loadDataFromServer = this.loadDataFromServer.bind(this); + this.state = { + data: [], + } + } + loadDataFromServer() { + $.ajax({ + url: APIserver+'/events?uid='+this.props.uid+'&policy_name=default_system_data', + dataType: 'json', + cache: false, + success: function(data) { + this.setState({data: data}); + }.bind(this), + error: function(xhr, status, err) { + console.error(this.props.url, status, err.toString()); + }.bind(this), + }) + } + componentDidMount() { + this.loadDataFromServer(); + this.intervalID = setInterval(this.loadDataFromServer, this.props.pollInterval); + } + componentWillUnmount() { + clearInterval(this.intervalID); + } + render() { + return ( +
+ + + +
+ ) + } +} + +class CPUChart extends React.Component { + constructor(props) { + super(props); + this._renderChart = this._renderChart.bind(this); + } + _renderChart(d) { + let x = ['x']; + let cpu = ['cpu']; + for (let i = 0; i < d.length; i++) { + x[i+1] = new Date(d[i].Time); + cpu[i+1] = d[i].Data.system.cpu.userspace; + } + this.chart = c3.generate({ + size: { + // in pixels + height: 150, + }, + data: { + x: 'x', + columns: [x, cpu], + types:{ + cpu: 'area-spline', + }, + }, + point: { + show: false, + }, + axis: { + y: { + padding: { + top: 0, + bottom: 0, + }, + tick: { + count: 5, + }, + max: 100, + min: 0, + }, + x: { + type: 'timeseries', + tick: { + format: '%I:%M:%S', // format string is also available for timeseries data + }, + }, + }, + legend: { + show: false, + }, + bindto: '#cpu-chart', + }); + } + componentDidMount() { + this._renderChart(this.props.data); + } + componentWillReceiveProps(newProps) { + this._renderChart(newProps.data); + // this.chart.load(newProps.data); // TODO: need to pass modified data to c3 + } + render() { + const baseStyle = { + margin: '0.6rem 0', + } + return ( +
+
CPU
+
+
+ ) + } +} + +class RAMChart extends React.Component { + constructor(props) { + super(props); + } + _renderChart(d) { + let x = ['x']; + let ram = ['ram']; + for (let i = 0; i < d.length; i++) { + x[i+1] = new Date(d[i].Time); + let m = d[i].Data.system.memory; + let used = m.used-m.cached-m.buffers; + let total = m.total; + let p = used/total * 100; + ram[i+1] = p.toFixed(2); + } + this.chart = c3.generate({ + size: { + // in pixels + height: 150, + }, + data: { + x: 'x', + columns:[x, ram], + types:{ + ram: 'area-spline', + }, + }, + point: { + show: false, + }, + axis: { + y: { + padding: { + top: 0, + bottom: 0, + }, + tick: { + count: 5, + }, + max: 100, + min: 0, + }, + x: { + type: 'timeseries', + tick: { + format: '%I:%M:%S', // format string is also available for timeseries data + }, + }, + }, + legend: { + show: false, + }, + color: { + pattern: ['#ff7f0e'], + }, + bindto: '#ram-chart', + }); + } + componentDidMount() { + this._renderChart(this.props.data); + } + componentWillReceiveProps(newProps) { + this._renderChart(newProps.data); + // this.chart.load(newProps.data); // TODO: need to pass modified data to c3 + } + render() { + const baseStyle = { + margin: '0.6rem 0', + } + return ( +
+
RAM
+
+
+ ) + } +} + +class DiskCharts extends React.Component { + constructor(props) { + super(props); + } + render() { + const baseStyle = { + margin: '0.6rem 0', + } + return ( +
+
Disks
+
+ ) + } +} From f486df3b29a8a24af48def107014dec8f6c4b1b3 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 11:12:42 +0530 Subject: [PATCH 42/48] Update dependencies react and react-router --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f50e849..84f724c 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "homepage": "https://github.com/codeignition/muzzle#readme", "dependencies": { "history": "^1.12.5", - "react": "^0.14.0", + "react": "^0.14.2", "react-dom": "^0.14.0", - "react-router": "^1.0.0-rc2" + "react-router": "^1.0.0-rc4" }, "devDependencies": { "babel-eslint": "^4.1.3", From 3759813d9acbd57cfc526b16bfff864cdc6ba4c2 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 11:50:11 +0530 Subject: [PATCH 43/48] Change color for agent status when online --- js/components/Agent.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx index 0b8b135..858bea1 100644 --- a/js/components/Agent.jsx +++ b/js/components/Agent.jsx @@ -62,7 +62,7 @@ const AgentStatus = (props) => { const styles = { online: { ...baseStyle, - color:'#004400', + color:'#fff', backgroundColor:'#88cc88', }, offline: { From 004be0f4556fef53920dc66fc12f8d1405674c01 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 11:56:25 +0530 Subject: [PATCH 44/48] Change interval time for loading data in the root Agent component As it was 2000, the charts were also getting updated every 2 secs, which led to a bad UX. (React updates all the child components on setState call). To keep it consistent with the loading time of chart data which is 5000, we are changing this value to 5000 as well. --- js/components/Agent.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx index 858bea1..a4eebb9 100644 --- a/js/components/Agent.jsx +++ b/js/components/Agent.jsx @@ -25,7 +25,7 @@ export class Agent extends React.Component { } componentDidMount() { this.loadDataFromServer(); - this.intervalID = setInterval(this.loadDataFromServer, 2000); + this.intervalID = setInterval(this.loadDataFromServer, 5000); } componentWillUnmount() { clearInterval(this.intervalID); From f2207bf613bb8408d181fdea56e5c12cbb319eb4 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Wed, 4 Nov 2015 13:36:48 +0530 Subject: [PATCH 45/48] Check for null data before rendering the charts --- js/components/Agent.jsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx index a4eebb9..01d9aa3 100644 --- a/js/components/Agent.jsx +++ b/js/components/Agent.jsx @@ -123,9 +123,11 @@ class CPUChart extends React.Component { _renderChart(d) { let x = ['x']; let cpu = ['cpu']; - for (let i = 0; i < d.length; i++) { - x[i+1] = new Date(d[i].Time); - cpu[i+1] = d[i].Data.system.cpu.userspace; + if (d !== null) { + for (let i = 0; i < d.length; i++) { + x[i+1] = new Date(d[i].Time); + cpu[i+1] = d[i].Data.system.cpu.userspace; + } } this.chart = c3.generate({ size: { @@ -194,13 +196,15 @@ class RAMChart extends React.Component { _renderChart(d) { let x = ['x']; let ram = ['ram']; - for (let i = 0; i < d.length; i++) { - x[i+1] = new Date(d[i].Time); - let m = d[i].Data.system.memory; - let used = m.used-m.cached-m.buffers; - let total = m.total; - let p = used/total * 100; - ram[i+1] = p.toFixed(2); + if (d !== null) { + for (let i = 0; i < d.length; i++) { + x[i+1] = new Date(d[i].Time); + let m = d[i].Data.system.memory; + let used = m.used-m.cached-m.buffers; + let total = m.total; + let p = used/total * 100; + ram[i+1] = p.toFixed(2); + } } this.chart = c3.generate({ size: { From d0916f96641af38a11529ca1f3b134fb052f1035 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 6 Nov 2015 13:57:12 +0530 Subject: [PATCH 46/48] Fix indentation --- js/components/FilterableAgentTable.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx index a192881..f9c1e28 100644 --- a/js/components/FilterableAgentTable.jsx +++ b/js/components/FilterableAgentTable.jsx @@ -121,10 +121,10 @@ class AgentBox extends React.Component { }; return( -
-
{this.props.agent.host_name}
- -
+
+
{this.props.agent.host_name}
+ +
) } From aaf3c7d6c9d8e9d715eff9312602397b55c63737 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 6 Nov 2015 13:57:49 +0530 Subject: [PATCH 47/48] Change APIServer address We will serve marksman on port 3456 --- js/app.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/app.jsx b/js/app.jsx index ac493f0..1d664ef 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -8,7 +8,7 @@ import { Auth } from './auth' import '../css/muzzle.css' -export const APIserver = 'http://192.168.1.119:3000/api' +export const APIserver = 'http://localhost:3456/api' class App extends React.Component { constructor(props) { From 1cb8396a81228e66c9adfa15d64a44a34c183a73 Mon Sep 17 00:00:00 2001 From: Hari haran Date: Fri, 6 Nov 2015 14:35:51 +0530 Subject: [PATCH 48/48] Remove auth and other unnecessary components --- js/app.jsx | 212 ++-------------------------------------- js/auth.jsx | 62 ------------ js/components/Agent.jsx | 17 ---- 3 files changed, 9 insertions(+), 282 deletions(-) delete mode 100644 js/auth.jsx diff --git a/js/app.jsx b/js/app.jsx index 1d664ef..d8bf16c 100644 --- a/js/app.jsx +++ b/js/app.jsx @@ -1,108 +1,21 @@ import React from 'react' import ReactDOM from 'react-dom' -import { Router, Link, Route, History } from 'react-router' -import { createHashHistory } from 'history' +import { Router, Link, Route } from 'react-router' import { FilterableAgentTable } from './components/FilterableAgentTable' import { Agent } from './components/Agent' -import { Auth } from './auth' import '../css/muzzle.css' export const APIserver = 'http://localhost:3456/api' -class App extends React.Component { - constructor(props) { - super(props); - this.state = { - loggedIn: Auth.loggedIn(), - } - this.updateAuth = this.updateAuth.bind(this); - } - updateAuth(loggedIn) { - this.setState({ - loggedIn: loggedIn, - }) - } - componentWillMount() { - Auth.onChange = this.updateAuth - Auth.login() - } - render() { - let c; - // let authToken = Auth.getToken(); - let userEmail = Auth.getEmail(); - if (this.state.loggedIn) { - c = ( -
- -
-
{this.props.children || }
-
-
- ) - } else { - c = Sign in - } - return ( -
- {c} -
- ) - } -} - -const Home = (props) => { - const s = { - marginLeft: '25%', - marginRight: '25%', - position: 'absolute', - textAlign: 'center', - top: '30%', - } - return ( -
-

Welcome to Recon

-

- Defaut dashboard -

-
- ) -} - -const Navbar = (props) => { +const App = (props) => { return ( - - ) -} - -const About = (props) => { - const s = { - margin: '0 auto', - padding: '4rem', - position: 'absolute', - } - return ( -
-

About

-

Recon is the brainchild of the people at CodeIgnition. Recon is completely opensource and aims to make monitoring simple and intuitive. If you have any issues / suggestions, please open an issue at our Github repository.

-

Go back to Home.

) } @@ -165,116 +78,9 @@ const NoMatch = (props) => { ) } -class Logout extends React.Component { - componentDidMount() { - Auth.logout() - } - render() { - let s = { - margin: '20%', - } - return ( -
-

You are now logged out!

Log In
-
- ) - } -} - -var Login = React.createClass({ - mixins: [ History ], - - getInitialState() { - return { - error: false, - } - }, - - handleSubmit(event) { - event.preventDefault(); - - let email = ReactDOM.findDOMNode(this.refs.email).value - let pass = ReactDOM.findDOMNode(this.refs.pass).value - - Auth.login(email, pass, (loggedIn) => { - if (!loggedIn) { - return this.setState({ error: true }) - } - - let { location } = this.props - - if (location.state && location.state.nextPathname) { - if (location.state.nextPathname === '/') { - this.history.replaceState(null, '/agents') - } else { - this.history.replaceState(null, location.state.nextPathname) - } - } else { - this.history.replaceState(null, '/agents') - } - }) - }, - - render() { - return ( -
-
-
-
-
-
-
- - -
- - -
-
- - -
- - { - this.state.error && ( -

Bad login information

- ) - } - -
-

- Don't have an account? Register here! -

-
-
-
-
-
- ) - }, -}); - -const Register = (props) => { - return ( -

Registration page

- ) -} - -const requireAuth = (nextState, replaceState) => { - if (!Auth.loggedIn()) { - replaceState({ nextPathname: nextState.location.pathname }, '/login') - } -} - -const history = createHashHistory(); - ReactDOM.render( - - - - - - + + diff --git a/js/auth.jsx b/js/auth.jsx deleted file mode 100644 index 71fb15a..0000000 --- a/js/auth.jsx +++ /dev/null @@ -1,62 +0,0 @@ -export const Auth = { - login(email, pass, cb) { - cb = arguments[arguments.length - 1] - if (localStorage.token) { - if (cb) { - cb(true); - this.onChange(true); - return - } - } - pretendRequest(email, pass, (res) => { - if (res.authenticated) { - localStorage.token = res.token - localStorage.email = email - if (cb) { - cb(true); - this.onChange(true); - } - } else { - if (cb) { - cb(false); - this.onChange(false); - } - } - }) - }, - - getToken() { - return localStorage.token - }, - - getEmail() { - return localStorage.email - }, - - logout(cb) { - delete localStorage.token - if (cb) { - cb(); - this.onChange(false); - } - }, - - loggedIn() { - return !!localStorage.token - }, - - onChange() {}, -} - -function pretendRequest(email, pass, cb) { - setTimeout(() => { - if (email === 'tony@starkindustries.com' && pass === 'ironman') { - cb({ - authenticated: true, - token: Math.random().toString(36).substring(7), - }) - } else { - cb({ authenticated: false }) - } - }, 0) -} diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx index 01d9aa3..88557e7 100644 --- a/js/components/Agent.jsx +++ b/js/components/Agent.jsx @@ -109,7 +109,6 @@ class AgentCharts extends React.Component {
-
) } @@ -268,19 +267,3 @@ class RAMChart extends React.Component { ) } } - -class DiskCharts extends React.Component { - constructor(props) { - super(props); - } - render() { - const baseStyle = { - margin: '0.6rem 0', - } - return ( -
-
Disks
-
- ) - } -}