2019-06-26 20:03:47 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2019-01-07 01:25:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-17 17:12:41 +00:00
|
|
|
import AceEditor from 'react-ace';
|
2016-10-17 18:55:03 +00:00
|
|
|
import { connect } from 'react-redux';
|
2016-12-05 15:21:03 +00:00
|
|
|
import { push } from 'react-router-redux';
|
2020-03-30 02:19:54 +00:00
|
|
|
import { sortBy } from 'lodash';
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2017-01-20 17:52:57 +00:00
|
|
|
import AddHostModal from 'components/hosts/AddHostModal';
|
2017-11-07 17:54:56 +00:00
|
|
|
import Button from 'components/buttons/Button';
|
2020-11-05 01:07:58 +00:00
|
|
|
import configInterface from 'interfaces/config';
|
2017-11-07 17:54:56 +00:00
|
|
|
import HostContainer from 'components/hosts/HostContainer';
|
|
|
|
import HostPagination from 'components/hosts/HostPagination';
|
|
|
|
import HostSidePanel from 'components/side_panels/HostSidePanel';
|
|
|
|
import LabelForm from 'components/forms/LabelForm';
|
|
|
|
import Modal from 'components/modals/Modal';
|
2016-11-17 17:12:41 +00:00
|
|
|
import QuerySidePanel from 'components/side_panels/QuerySidePanel';
|
2017-11-07 17:54:56 +00:00
|
|
|
import labelInterface from 'interfaces/label';
|
|
|
|
import hostInterface from 'interfaces/host';
|
|
|
|
import osqueryTableInterface from 'interfaces/osquery_table';
|
2017-01-16 20:59:01 +00:00
|
|
|
import statusLabelsInterface from 'interfaces/status_labels';
|
2020-05-29 16:12:39 +00:00
|
|
|
import enrollSecretInterface from 'interfaces/enroll_secret';
|
2017-11-07 17:54:56 +00:00
|
|
|
import { selectOsqueryTable } from 'redux/nodes/components/QueryPages/actions';
|
2020-03-30 02:19:54 +00:00
|
|
|
import {
|
|
|
|
getStatusLabelCounts,
|
|
|
|
setPagination,
|
|
|
|
} from 'redux/nodes/components/ManageHostsPage/actions';
|
2017-11-07 17:54:56 +00:00
|
|
|
import hostActions from 'redux/nodes/entities/hosts/actions';
|
|
|
|
import labelActions from 'redux/nodes/entities/labels/actions';
|
|
|
|
import { renderFlash } from 'redux/nodes/notifications/actions';
|
|
|
|
import entityGetter from 'redux/utilities/entityGetter';
|
2019-10-16 23:40:45 +00:00
|
|
|
import PATHS from 'router/paths';
|
2017-11-07 17:54:56 +00:00
|
|
|
import deepDifference from 'utilities/deep_difference';
|
|
|
|
import scrollToTop from 'utilities/scroll_to_top';
|
|
|
|
import helpers from './helpers';
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2016-12-05 15:21:03 +00:00
|
|
|
const NEW_LABEL_HASH = '#new_label';
|
2016-12-15 14:44:45 +00:00
|
|
|
const baseClass = 'manage-hosts';
|
2016-12-05 15:21:03 +00:00
|
|
|
|
2019-06-26 20:03:47 +00:00
|
|
|
export class ManageHostsPage extends PureComponent {
|
2016-10-17 18:55:03 +00:00
|
|
|
static propTypes = {
|
2020-11-05 01:07:58 +00:00
|
|
|
config: configInterface,
|
2016-10-17 18:55:03 +00:00
|
|
|
dispatch: PropTypes.func,
|
2016-10-21 23:13:41 +00:00
|
|
|
hosts: PropTypes.arrayOf(hostInterface),
|
2016-12-05 15:21:03 +00:00
|
|
|
isAddLabel: PropTypes.bool,
|
2017-01-06 00:01:17 +00:00
|
|
|
labelErrors: PropTypes.shape({
|
|
|
|
base: PropTypes.string,
|
|
|
|
}),
|
2016-11-17 17:12:41 +00:00
|
|
|
labels: PropTypes.arrayOf(labelInterface),
|
2017-01-27 15:05:44 +00:00
|
|
|
loadingHosts: PropTypes.bool.isRequired,
|
|
|
|
loadingLabels: PropTypes.bool.isRequired,
|
2020-05-29 16:12:39 +00:00
|
|
|
enrollSecret: enrollSecretInterface,
|
2020-03-30 02:19:54 +00:00
|
|
|
selectedFilter: PropTypes.string,
|
2016-11-17 17:12:41 +00:00
|
|
|
selectedLabel: labelInterface,
|
|
|
|
selectedOsqueryTable: osqueryTableInterface,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels: statusLabelsInterface,
|
2020-03-30 02:19:54 +00:00
|
|
|
page: PropTypes.number,
|
|
|
|
perPage: PropTypes.number,
|
2016-10-17 18:55:03 +00:00
|
|
|
};
|
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
static defaultProps = {
|
2020-03-30 02:19:54 +00:00
|
|
|
page: 1,
|
|
|
|
perPage: 100,
|
2017-02-13 23:19:00 +00:00
|
|
|
loadingHosts: false,
|
|
|
|
loadingLabels: false,
|
2016-11-21 16:26:58 +00:00
|
|
|
};
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-02-15 14:51:19 +00:00
|
|
|
isEditLabel: false,
|
2016-11-17 17:12:41 +00:00
|
|
|
labelQueryText: '',
|
2017-11-07 17:54:56 +00:00
|
|
|
pagedHosts: [],
|
2017-01-20 17:52:57 +00:00
|
|
|
showDeleteHostModal: false,
|
|
|
|
showAddHostModal: false,
|
2017-01-19 23:39:06 +00:00
|
|
|
selectedHost: null,
|
|
|
|
showDeleteLabelModal: false,
|
2017-11-07 17:54:56 +00:00
|
|
|
showHostContainerSpinner: false,
|
2016-11-17 17:12:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-25 17:27:58 +00:00
|
|
|
componentDidMount () {
|
2020-03-30 02:19:54 +00:00
|
|
|
const { dispatch, page, perPage, selectedFilter } = this.props;
|
2017-01-25 17:27:58 +00:00
|
|
|
|
2020-03-30 02:19:54 +00:00
|
|
|
dispatch(setPagination(page, perPage, selectedFilter));
|
2017-11-07 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 17:27:58 +00:00
|
|
|
componentWillUnmount () {
|
2019-06-26 20:03:47 +00:00
|
|
|
this.clearHostUpdates();
|
2017-01-25 17:27:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
onAddLabelClick = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
2019-10-16 23:40:45 +00:00
|
|
|
dispatch(push(`${PATHS.MANAGE_HOSTS}${NEW_LABEL_HASH}`));
|
2017-01-19 23:39:06 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
onCancelAddLabel = () => {
|
2016-12-05 15:21:03 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
2019-10-16 23:40:45 +00:00
|
|
|
dispatch(push(PATHS.MANAGE_HOSTS));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-20 17:52:57 +00:00
|
|
|
onAddHostClick = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const { toggleAddHostModal } = this;
|
|
|
|
toggleAddHostModal();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
onDestroyHost = (evt) => {
|
2016-11-17 17:12:41 +00:00
|
|
|
evt.preventDefault();
|
|
|
|
|
2016-12-05 15:21:03 +00:00
|
|
|
const { dispatch } = this.props;
|
2017-01-19 23:39:06 +00:00
|
|
|
const { selectedHost } = this.state;
|
2016-12-05 15:21:03 +00:00
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
dispatch(hostActions.destroy(selectedHost))
|
|
|
|
.then(() => {
|
2017-01-20 17:52:57 +00:00
|
|
|
this.toggleDeleteHostModal(null)();
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
dispatch(getStatusLabelCounts);
|
|
|
|
dispatch(renderFlash('success', `Host "${selectedHost.hostname}" was successfully deleted`));
|
|
|
|
});
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
return false;
|
2016-10-17 18:55:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-15 14:51:19 +00:00
|
|
|
onEditLabel = (formData) => {
|
|
|
|
const { dispatch, selectedLabel } = this.props;
|
|
|
|
const updateAttrs = deepDifference(formData, selectedLabel);
|
|
|
|
|
|
|
|
return dispatch(labelActions.update(selectedLabel, updateAttrs))
|
|
|
|
.then(() => {
|
|
|
|
this.toggleEditLabel();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.catch(() => false);
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
onLabelClick = (selectedLabel) => {
|
|
|
|
return (evt) => {
|
|
|
|
evt.preventDefault();
|
2020-03-30 02:19:54 +00:00
|
|
|
const { dispatch, perPage } = this.props;
|
2019-10-16 23:40:45 +00:00
|
|
|
const { MANAGE_HOSTS } = PATHS;
|
2020-03-30 02:19:54 +00:00
|
|
|
const { slug, type } = selectedLabel;
|
|
|
|
const nextLocation = type === 'all' ? MANAGE_HOSTS : `${MANAGE_HOSTS}/${slug}`;
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2016-12-12 16:48:50 +00:00
|
|
|
dispatch(push(nextLocation));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2020-03-30 02:19:54 +00:00
|
|
|
dispatch(setPagination(1, perPage, selectedLabel.slug));
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onOsqueryTableSelect = (tableName) => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(selectOsqueryTable(tableName));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-07 17:54:56 +00:00
|
|
|
onPaginationChange = (page) => {
|
2020-03-30 02:19:54 +00:00
|
|
|
const { dispatch, selectedFilter, perPage } = this.props;
|
2017-11-07 17:54:56 +00:00
|
|
|
|
2020-03-30 02:19:54 +00:00
|
|
|
dispatch(setPagination(page, perPage, selectedFilter));
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2017-11-07 17:54:56 +00:00
|
|
|
scrollToTop();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
onSaveAddLabel = (formData) => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
return dispatch(labelActions.create(formData))
|
|
|
|
.then(() => {
|
2019-10-16 23:40:45 +00:00
|
|
|
dispatch(push(PATHS.MANAGE_HOSTS));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-19 17:57:59 +00:00
|
|
|
onDeleteLabel = () => {
|
2017-01-20 17:52:57 +00:00
|
|
|
const { toggleDeleteLabelModal } = this;
|
2017-01-19 17:57:59 +00:00
|
|
|
const { dispatch, selectedLabel } = this.props;
|
2019-10-16 23:40:45 +00:00
|
|
|
const { MANAGE_HOSTS } = PATHS;
|
2017-01-19 17:57:59 +00:00
|
|
|
|
|
|
|
return dispatch(labelActions.destroy(selectedLabel))
|
|
|
|
.then(() => {
|
2017-01-20 17:52:57 +00:00
|
|
|
toggleDeleteLabelModal();
|
2017-01-19 17:57:59 +00:00
|
|
|
dispatch(push(MANAGE_HOSTS));
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-20 23:07:54 +00:00
|
|
|
onQueryHost = (host) => {
|
|
|
|
return (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const { dispatch } = this.props;
|
2019-10-16 23:40:45 +00:00
|
|
|
const { NEW_QUERY } = PATHS;
|
2017-01-20 23:07:54 +00:00
|
|
|
|
|
|
|
dispatch(push({
|
|
|
|
pathname: NEW_QUERY,
|
|
|
|
query: { host_ids: [host.id] },
|
|
|
|
}));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:03:47 +00:00
|
|
|
clearHostUpdates () {
|
|
|
|
if (this.timeout) {
|
|
|
|
global.window.clearTimeout(this.timeout);
|
|
|
|
this.timeout = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 17:54:56 +00:00
|
|
|
filterAllHosts = (hosts, selectedLabel) => {
|
|
|
|
const { filterHosts } = helpers;
|
|
|
|
|
|
|
|
return filterHosts(hosts, selectedLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
sortHosts = (hosts) => {
|
2020-03-30 02:19:54 +00:00
|
|
|
return sortBy(hosts, (h) => { return h.hostname; });
|
2017-11-07 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 17:52:57 +00:00
|
|
|
toggleAddHostModal = () => {
|
|
|
|
const { showAddHostModal } = this.state;
|
|
|
|
this.setState({ showAddHostModal: !showAddHostModal });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleDeleteHostModal = (selectedHost) => {
|
2017-01-19 23:39:06 +00:00
|
|
|
return () => {
|
|
|
|
const { showDeleteHostModal } = this.state;
|
2017-01-19 17:57:59 +00:00
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
this.setState({
|
|
|
|
selectedHost,
|
|
|
|
showDeleteHostModal: !showDeleteHostModal,
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-20 17:52:57 +00:00
|
|
|
toggleDeleteLabelModal = () => {
|
2017-01-19 23:39:06 +00:00
|
|
|
const { showDeleteLabelModal } = this.state;
|
|
|
|
|
|
|
|
this.setState({ showDeleteLabelModal: !showDeleteLabelModal });
|
2017-01-19 17:57:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-15 14:51:19 +00:00
|
|
|
toggleEditLabel = () => {
|
|
|
|
const { isEditLabel } = this.state;
|
|
|
|
|
|
|
|
this.setState({ isEditLabel: !isEditLabel });
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-20 17:52:57 +00:00
|
|
|
renderAddHostModal = () => {
|
2020-11-05 01:07:58 +00:00
|
|
|
const { toggleAddHostModal } = this;
|
2017-01-20 17:52:57 +00:00
|
|
|
const { showAddHostModal } = this.state;
|
2020-11-05 01:07:58 +00:00
|
|
|
const { enrollSecret, config } = this.props;
|
2017-01-20 17:52:57 +00:00
|
|
|
|
|
|
|
if (!showAddHostModal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
2020-12-04 20:19:08 +00:00
|
|
|
title="New host"
|
2017-01-20 17:52:57 +00:00
|
|
|
onExit={toggleAddHostModal}
|
|
|
|
className={`${baseClass}__invite-modal`}
|
|
|
|
>
|
|
|
|
<AddHostModal
|
|
|
|
onReturnToApp={toggleAddHostModal}
|
2020-05-29 16:12:39 +00:00
|
|
|
enrollSecret={enrollSecret}
|
2020-11-05 01:07:58 +00:00
|
|
|
config={config}
|
2017-01-20 17:52:57 +00:00
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDeleteHostModal = () => {
|
2020-10-01 16:38:43 +00:00
|
|
|
const { showDeleteHostModal, selectedHost } = this.state;
|
2017-01-20 17:52:57 +00:00
|
|
|
const { toggleDeleteHostModal, onDestroyHost } = this;
|
2017-01-19 23:39:06 +00:00
|
|
|
|
|
|
|
if (!showDeleteHostModal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title="Delete Host"
|
2017-01-20 17:52:57 +00:00
|
|
|
onExit={toggleDeleteHostModal(null)}
|
2017-01-19 23:39:06 +00:00
|
|
|
className={`${baseClass}__modal`}
|
|
|
|
>
|
2020-10-01 16:38:43 +00:00
|
|
|
<p>This action will delete the host <strong>{selectedHost.hostname}</strong> from your Fleet instance.</p>
|
2019-01-24 17:39:32 +00:00
|
|
|
<p>If the host comes back online it will automatically re-enroll. To prevent the host from re-enrolling please disable or uninstall osquery on the host.</p>
|
2017-01-25 14:28:40 +00:00
|
|
|
<div className={`${baseClass}__modal-buttons`}>
|
2017-01-19 23:39:06 +00:00
|
|
|
<Button onClick={onDestroyHost} variant="alert">Delete</Button>
|
2017-01-25 14:28:40 +00:00
|
|
|
<Button onClick={toggleDeleteHostModal(null)} variant="inverse">Cancel</Button>
|
2017-01-19 23:39:06 +00:00
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-20 17:52:57 +00:00
|
|
|
renderDeleteLabelModal = () => {
|
2017-01-19 23:39:06 +00:00
|
|
|
const { showDeleteLabelModal } = this.state;
|
2017-01-20 17:52:57 +00:00
|
|
|
const { toggleDeleteLabelModal, onDeleteLabel } = this;
|
2017-01-19 17:57:59 +00:00
|
|
|
|
2017-01-19 23:39:06 +00:00
|
|
|
if (!showDeleteLabelModal) {
|
2017-01-19 17:57:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title="Delete Label"
|
2017-01-20 17:52:57 +00:00
|
|
|
onExit={toggleDeleteLabelModal}
|
2019-07-31 19:05:10 +00:00
|
|
|
className={`${baseClass}_delete-label__modal`}
|
2017-01-19 17:57:59 +00:00
|
|
|
>
|
|
|
|
<p>Are you sure you wish to delete this label?</p>
|
2019-07-31 19:05:10 +00:00
|
|
|
<div className={`${baseClass}__modal-buttons`}>
|
2017-01-19 17:57:59 +00:00
|
|
|
<Button onClick={onDeleteLabel} variant="alert">Delete</Button>
|
2019-07-31 19:05:10 +00:00
|
|
|
<Button onClick={toggleDeleteLabelModal} variant="inverse">Cancel</Button>
|
2017-01-19 17:57:59 +00:00
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDeleteButton = () => {
|
2017-02-15 14:51:19 +00:00
|
|
|
const { toggleDeleteLabelModal, toggleEditLabel } = this;
|
2017-01-19 17:57:59 +00:00
|
|
|
const { selectedLabel: { type } } = this.props;
|
|
|
|
|
|
|
|
if (type !== 'custom') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-12-07 23:08:59 +00:00
|
|
|
<div className={`${baseClass}__label-actions`}>
|
2017-02-15 14:51:19 +00:00
|
|
|
<Button onClick={toggleEditLabel} variant="inverse">Edit</Button>
|
2020-12-07 23:08:59 +00:00
|
|
|
<Button onClick={toggleDeleteLabelModal} variant="inverse-alert">Delete</Button>
|
2017-01-19 17:57:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-11 19:08:27 +00:00
|
|
|
renderQuery = () => {
|
|
|
|
const { selectedLabel } = this.props;
|
2020-04-07 22:12:32 +00:00
|
|
|
const { slug, label_type: labelType, label_membership_type: membershipType, query } = selectedLabel;
|
2017-01-11 19:08:27 +00:00
|
|
|
|
2020-04-07 22:12:32 +00:00
|
|
|
if (membershipType === 'manual' && labelType !== 'builtin') {
|
|
|
|
return (
|
|
|
|
<h4 title="Manage manual labels with fleetctl">Manually managed</h4>
|
|
|
|
);
|
|
|
|
}
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2020-04-07 22:12:32 +00:00
|
|
|
if (!query || slug === 'all-hosts') {
|
2017-01-11 19:08:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AceEditor
|
|
|
|
editorProps={{ $blockScrolling: Infinity }}
|
|
|
|
mode="kolide"
|
|
|
|
minLines={1}
|
|
|
|
maxLines={20}
|
|
|
|
name="label-header"
|
|
|
|
readOnly
|
|
|
|
setOptions={{ wrap: true }}
|
|
|
|
showGutter={false}
|
|
|
|
showPrintMargin={false}
|
|
|
|
theme="kolide"
|
|
|
|
value={query}
|
|
|
|
width="100%"
|
|
|
|
fontSize={14}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
renderHeader = () => {
|
2020-12-04 20:19:08 +00:00
|
|
|
const { renderDeleteButton } = this;
|
2020-11-30 18:23:58 +00:00
|
|
|
const { isAddLabel, selectedLabel, statusLabels } = this.props;
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
if (!selectedLabel || isAddLabel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 21:29:49 +00:00
|
|
|
const { count, description, display_text: displayText, statusLabelKey, type } = selectedLabel;
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2017-01-19 21:29:49 +00:00
|
|
|
const hostCount = type === 'status' ? statusLabels[`${statusLabelKey}`] : count;
|
2020-11-30 18:23:58 +00:00
|
|
|
const hostsTotalDisplay = hostCount === 1 ? '1 host' : `${hostCount} hosts`;
|
2017-02-21 22:40:59 +00:00
|
|
|
const defaultDescription = 'No description available.';
|
2017-01-17 21:44:00 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
return (
|
2016-12-15 14:44:45 +00:00
|
|
|
<div className={`${baseClass}__header`}>
|
2020-12-07 23:08:59 +00:00
|
|
|
<div className={`${baseClass}__text`}>
|
|
|
|
<h1 className={`${baseClass}__title`}>
|
|
|
|
<span>{displayText}</span>
|
|
|
|
</h1>
|
|
|
|
<div className={`${baseClass}__description`}>
|
|
|
|
<p>{description || <em>{defaultDescription}</em>}</p>
|
|
|
|
</div>
|
|
|
|
<div className={`${baseClass}__topper`}>
|
|
|
|
<p className={`${baseClass}__host-count`}>{hostsTotalDisplay}</p>
|
|
|
|
</div>
|
2016-11-21 16:26:58 +00:00
|
|
|
</div>
|
2020-12-07 23:08:59 +00:00
|
|
|
{renderDeleteButton()}
|
2016-11-17 17:12:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
renderForm = () => {
|
2017-02-15 14:51:19 +00:00
|
|
|
const { isAddLabel, labelErrors, selectedLabel } = this.props;
|
|
|
|
const { isEditLabel } = this.state;
|
2016-11-17 17:12:41 +00:00
|
|
|
const {
|
|
|
|
onCancelAddLabel,
|
2017-02-15 14:51:19 +00:00
|
|
|
onEditLabel,
|
2017-01-06 00:01:17 +00:00
|
|
|
onOsqueryTableSelect,
|
2016-11-17 17:12:41 +00:00
|
|
|
onSaveAddLabel,
|
2017-02-15 14:51:19 +00:00
|
|
|
toggleEditLabel,
|
2016-11-17 17:12:41 +00:00
|
|
|
} = this;
|
|
|
|
|
|
|
|
if (isAddLabel) {
|
|
|
|
return (
|
2017-01-10 19:20:36 +00:00
|
|
|
<div className="body-wrap">
|
2017-02-15 14:51:19 +00:00
|
|
|
<LabelForm
|
2017-01-10 19:20:36 +00:00
|
|
|
onCancel={onCancelAddLabel}
|
|
|
|
onOsqueryTableSelect={onOsqueryTableSelect}
|
|
|
|
handleSubmit={onSaveAddLabel}
|
2017-02-15 14:51:19 +00:00
|
|
|
serverErrors={labelErrors}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEditLabel) {
|
|
|
|
return (
|
|
|
|
<div className="body-wrap">
|
|
|
|
<LabelForm
|
|
|
|
formData={selectedLabel}
|
|
|
|
onCancel={toggleEditLabel}
|
|
|
|
onOsqueryTableSelect={onOsqueryTableSelect}
|
|
|
|
handleSubmit={onEditLabel}
|
|
|
|
isEdit
|
2017-01-10 19:20:36 +00:00
|
|
|
serverErrors={labelErrors}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-11-17 17:12:41 +00:00
|
|
|
);
|
|
|
|
}
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
return false;
|
2016-10-17 18:55:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
renderSidePanel = () => {
|
|
|
|
let SidePanel;
|
|
|
|
const {
|
2016-12-05 15:21:03 +00:00
|
|
|
isAddLabel,
|
2016-11-17 17:12:41 +00:00
|
|
|
labels,
|
2020-03-30 02:19:54 +00:00
|
|
|
selectedFilter,
|
2016-11-17 17:12:41 +00:00
|
|
|
selectedOsqueryTable,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels,
|
2016-11-17 17:12:41 +00:00
|
|
|
} = this.props;
|
2020-12-04 20:19:08 +00:00
|
|
|
const { onAddLabelClick, onLabelClick, onOsqueryTableSelect } = this;
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
if (isAddLabel) {
|
|
|
|
SidePanel = (
|
|
|
|
<QuerySidePanel
|
|
|
|
key="query-side-panel"
|
|
|
|
onOsqueryTableSelect={onOsqueryTableSelect}
|
|
|
|
selectedOsqueryTable={selectedOsqueryTable}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
SidePanel = (
|
|
|
|
<HostSidePanel
|
|
|
|
key="hosts-side-panel"
|
|
|
|
labels={labels}
|
|
|
|
onAddLabelClick={onAddLabelClick}
|
|
|
|
onLabelClick={onLabelClick}
|
2020-03-30 02:19:54 +00:00
|
|
|
selectedFilter={selectedFilter}
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels={statusLabels}
|
2016-11-17 17:12:41 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-06 15:36:51 +00:00
|
|
|
return SidePanel;
|
2016-11-17 17:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 18:55:03 +00:00
|
|
|
render () {
|
2017-11-07 17:54:56 +00:00
|
|
|
const {
|
|
|
|
onQueryHost,
|
|
|
|
onPaginationChange,
|
|
|
|
renderForm,
|
|
|
|
renderHeader,
|
|
|
|
renderSidePanel,
|
|
|
|
renderAddHostModal,
|
|
|
|
renderDeleteHostModal,
|
|
|
|
renderDeleteLabelModal,
|
2020-12-04 20:19:08 +00:00
|
|
|
renderQuery,
|
2017-11-07 17:54:56 +00:00
|
|
|
toggleAddHostModal,
|
|
|
|
toggleDeleteHostModal,
|
|
|
|
} = this;
|
2020-03-30 02:19:54 +00:00
|
|
|
const {
|
|
|
|
page,
|
|
|
|
perPage,
|
|
|
|
hosts,
|
|
|
|
isAddLabel,
|
|
|
|
loadingLabels,
|
|
|
|
loadingHosts,
|
|
|
|
selectedLabel,
|
|
|
|
statusLabels,
|
|
|
|
} = this.props;
|
|
|
|
const { isEditLabel } = this.state;
|
2017-01-27 15:05:44 +00:00
|
|
|
|
2020-12-04 20:19:08 +00:00
|
|
|
const { onAddHostClick } = this;
|
|
|
|
|
2020-03-30 02:19:54 +00:00
|
|
|
const sortedHosts = this.sortHosts(hosts);
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2020-03-30 02:19:54 +00:00
|
|
|
|
|
|
|
let hostCount = 0;
|
|
|
|
if (hostCount === 0) {
|
|
|
|
switch (selectedLabel ? selectedLabel.id : '') {
|
|
|
|
case 'all-hosts':
|
|
|
|
hostCount = statusLabels.total_count;
|
|
|
|
break;
|
|
|
|
case 'new':
|
|
|
|
hostCount = statusLabels.new_count;
|
|
|
|
break;
|
|
|
|
case 'online':
|
|
|
|
hostCount = statusLabels.online_count;
|
|
|
|
break;
|
|
|
|
case 'offline':
|
|
|
|
hostCount = statusLabels.offline_count;
|
|
|
|
break;
|
|
|
|
case 'mia':
|
|
|
|
hostCount = statusLabels.mia_count;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hostCount = selectedLabel ? selectedLabel.count : 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2016-10-17 18:55:03 +00:00
|
|
|
return (
|
2016-12-15 14:44:45 +00:00
|
|
|
<div className="has-sidebar">
|
2016-12-21 18:39:40 +00:00
|
|
|
{renderForm()}
|
2017-03-02 16:53:08 +00:00
|
|
|
|
2017-02-15 14:51:19 +00:00
|
|
|
{!isAddLabel && !isEditLabel &&
|
2016-12-21 18:39:40 +00:00
|
|
|
<div className={`${baseClass} body-wrap`}>
|
2020-12-04 20:19:08 +00:00
|
|
|
<div className="header-wrap">
|
|
|
|
{renderHeader()}
|
|
|
|
<Button onClick={onAddHostClick} className={`${baseClass}__add-hosts button button--brand`}>
|
|
|
|
<span>Add new host</span>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
{selectedLabel && renderQuery()}
|
2020-11-30 18:23:58 +00:00
|
|
|
<div className={`${baseClass}__list`}>
|
2017-11-07 17:54:56 +00:00
|
|
|
<HostContainer
|
2020-03-30 02:19:54 +00:00
|
|
|
hosts={sortedHosts}
|
2017-11-07 17:54:56 +00:00
|
|
|
selectedLabel={selectedLabel}
|
2019-06-26 20:03:47 +00:00
|
|
|
loadingHosts={loadingHosts}
|
2017-11-07 17:54:56 +00:00
|
|
|
toggleAddHostModal={toggleAddHostModal}
|
|
|
|
toggleDeleteHostModal={toggleDeleteHostModal}
|
|
|
|
onQueryHost={onQueryHost}
|
|
|
|
/>
|
2019-06-26 20:03:47 +00:00
|
|
|
{!loadingHosts && <HostPagination
|
2020-03-30 02:19:54 +00:00
|
|
|
allHostCount={hostCount}
|
|
|
|
currentPage={page}
|
|
|
|
hostsPerPage={perPage}
|
2017-11-07 17:54:56 +00:00
|
|
|
onPaginationChange={onPaginationChange}
|
|
|
|
/>}
|
2016-12-21 18:39:40 +00:00
|
|
|
</div>
|
2016-12-15 14:44:45 +00:00
|
|
|
</div>
|
2016-12-21 18:39:40 +00:00
|
|
|
}
|
2016-12-15 14:44:45 +00:00
|
|
|
|
2017-03-02 16:53:08 +00:00
|
|
|
{!loadingLabels && renderSidePanel()}
|
2017-01-20 17:52:57 +00:00
|
|
|
{renderAddHostModal()}
|
|
|
|
{renderDeleteHostModal()}
|
|
|
|
{renderDeleteLabelModal()}
|
2016-10-17 18:55:03 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 16:48:50 +00:00
|
|
|
const mapStateToProps = (state, { location, params }) => {
|
2020-03-30 02:19:54 +00:00
|
|
|
const { active_label: activeLabel, label_id: labelID } = params;
|
|
|
|
const activeLabelSlug = activeLabel || 'all-hosts';
|
|
|
|
const selectedFilter = labelID ? `labels/${labelID}` : activeLabelSlug;
|
2020-07-01 17:51:34 +00:00
|
|
|
|
2020-11-30 18:23:58 +00:00
|
|
|
const { status_labels: statusLabels, page, perPage } = state.components.ManageHostsPage;
|
2016-10-17 18:55:03 +00:00
|
|
|
const { entities: hosts } = entityGetter(state).get('hosts');
|
2016-12-12 16:48:50 +00:00
|
|
|
const labelEntities = entityGetter(state).get('labels');
|
|
|
|
const { entities: labels } = labelEntities;
|
2016-12-05 15:21:03 +00:00
|
|
|
const isAddLabel = location.hash === NEW_LABEL_HASH;
|
2016-12-12 16:48:50 +00:00
|
|
|
const selectedLabel = labelEntities.findBy(
|
2020-03-30 02:19:54 +00:00
|
|
|
{ slug: selectedFilter },
|
2016-12-12 16:48:50 +00:00
|
|
|
{ ignoreCase: true },
|
|
|
|
);
|
2016-11-17 17:12:41 +00:00
|
|
|
const { selectedOsqueryTable } = state.components.QueryPages;
|
2017-01-27 15:05:44 +00:00
|
|
|
const { errors: labelErrors, loading: loadingLabels } = state.entities.labels;
|
|
|
|
const { loading: loadingHosts } = state.entities.hosts;
|
2020-05-29 16:12:39 +00:00
|
|
|
const enrollSecret = state.app.enrollSecret;
|
2020-11-05 01:07:58 +00:00
|
|
|
const config = state.app.config;
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
return {
|
2020-03-30 02:19:54 +00:00
|
|
|
selectedFilter,
|
|
|
|
page,
|
|
|
|
perPage,
|
2016-11-17 17:12:41 +00:00
|
|
|
hosts,
|
2016-12-05 15:21:03 +00:00
|
|
|
isAddLabel,
|
2017-01-06 00:01:17 +00:00
|
|
|
labelErrors,
|
2016-11-17 17:12:41 +00:00
|
|
|
labels,
|
2017-01-27 15:05:44 +00:00
|
|
|
loadingHosts,
|
|
|
|
loadingLabels,
|
2020-05-29 16:12:39 +00:00
|
|
|
enrollSecret,
|
2016-11-17 17:12:41 +00:00
|
|
|
selectedLabel,
|
|
|
|
selectedOsqueryTable,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels,
|
2020-11-05 01:07:58 +00:00
|
|
|
config,
|
2016-11-17 17:12:41 +00:00
|
|
|
};
|
2016-10-17 18:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ManageHostsPage);
|