2021-04-12 13:32:25 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import { pull } from "lodash";
|
|
|
|
|
|
|
|
import KolideIcon from "components/icons/KolideIcon";
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
import Dropdown from "components/forms/fields/Dropdown";
|
|
|
|
import Form from "components/forms/Form";
|
|
|
|
import formFieldInterface from "interfaces/form_field";
|
|
|
|
import InputField from "components/forms/fields/InputField";
|
|
|
|
import validate from "components/forms/ConfigurePackQueryForm/validate";
|
|
|
|
|
|
|
|
const baseClass = "configure-pack-query-form";
|
|
|
|
const fieldNames = [
|
|
|
|
"query_id",
|
|
|
|
"interval",
|
|
|
|
"logging_type",
|
|
|
|
"platform",
|
|
|
|
"shard",
|
|
|
|
"version",
|
|
|
|
];
|
2016-12-21 17:25:54 +00:00
|
|
|
const platformOptions = [
|
2021-04-12 13:32:25 +00:00
|
|
|
{ label: "All", value: "" },
|
|
|
|
{ label: "Windows", value: "windows" },
|
|
|
|
{ label: "Linux", value: "linux" },
|
|
|
|
{ label: "macOS", value: "darwin" },
|
2016-12-21 17:25:54 +00:00
|
|
|
];
|
|
|
|
const loggingTypeOptions = [
|
2021-04-12 13:32:25 +00:00
|
|
|
{ label: "Differential", value: "differential" },
|
|
|
|
{
|
|
|
|
label: "Differential (Ignore Removals)",
|
|
|
|
value: "differential_ignore_removals",
|
|
|
|
},
|
|
|
|
{ label: "Snapshot", value: "snapshot" },
|
2016-12-21 17:25:54 +00:00
|
|
|
];
|
|
|
|
const minOsqueryVersionOptions = [
|
2021-04-12 13:32:25 +00:00
|
|
|
{ label: "All", value: "" },
|
|
|
|
{ label: "4.7.0 +", value: "4.7.0" },
|
|
|
|
{ label: "4.6.0 +", value: "4.6.0" },
|
|
|
|
{ label: "4.5.1 +", value: "4.5.1" },
|
|
|
|
{ label: "4.5.0 +", value: "4.5.0" },
|
|
|
|
{ label: "4.4.0 +", value: "4.4.0" },
|
|
|
|
{ label: "4.3.0 +", value: "4.3.0" },
|
|
|
|
{ label: "4.2.0 +", value: "4.2.0" },
|
|
|
|
{ label: "4.1.2 +", value: "4.1.2" },
|
|
|
|
{ label: "4.1.1 +", value: "4.1.1" },
|
|
|
|
{ label: "4.1.0 +", value: "4.1.0" },
|
|
|
|
{ label: "4.0.2 +", value: "4.0.2" },
|
|
|
|
{ label: "4.0.1 +", value: "4.0.1" },
|
|
|
|
{ label: "4.0.0 +", value: "4.0.0" },
|
|
|
|
{ label: "3.4.0 +", value: "3.4.0" },
|
|
|
|
{ label: "3.3.2 +", value: "3.3.2" },
|
|
|
|
{ label: "3.3.1 +", value: "3.3.1" },
|
|
|
|
{ label: "3.2.6 +", value: "3.2.6" },
|
|
|
|
{ label: "2.2.1 +", value: "2.2.1" },
|
|
|
|
{ label: "2.2.0 +", value: "2.2.0" },
|
|
|
|
{ label: "2.1.2 +", value: "2.1.2" },
|
|
|
|
{ label: "2.1.1 +", value: "2.1.1" },
|
|
|
|
{ label: "2.0.0 +", value: "2.0.0" },
|
|
|
|
{ label: "1.8.2 +", value: "1.8.2" },
|
|
|
|
{ label: "1.8.1 +", value: "1.8.1" },
|
2016-12-21 17:25:54 +00:00
|
|
|
];
|
|
|
|
|
2017-03-08 16:11:47 +00:00
|
|
|
export class ConfigurePackQueryForm extends Component {
|
2016-12-21 17:25:54 +00:00
|
|
|
static propTypes = {
|
|
|
|
fields: PropTypes.shape({
|
|
|
|
interval: formFieldInterface.isRequired,
|
|
|
|
logging_type: formFieldInterface.isRequired,
|
|
|
|
platform: formFieldInterface.isRequired,
|
|
|
|
version: formFieldInterface.isRequired,
|
2020-07-07 02:31:48 +00:00
|
|
|
shard: formFieldInterface.isRequired,
|
2016-12-21 17:25:54 +00:00
|
|
|
}).isRequired,
|
2017-02-17 18:11:43 +00:00
|
|
|
formData: PropTypes.shape({
|
|
|
|
id: PropTypes.number,
|
|
|
|
}),
|
2016-12-21 17:25:54 +00:00
|
|
|
handleSubmit: PropTypes.func,
|
|
|
|
onCancel: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
componentWillMount() {
|
2017-03-13 13:32:47 +00:00
|
|
|
const { fields } = this.props;
|
|
|
|
|
2020-07-07 02:31:48 +00:00
|
|
|
if (fields && fields.shard && !fields.shard.value) {
|
2021-04-12 13:32:25 +00:00
|
|
|
fields.shard.value = "";
|
2017-03-13 13:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 17:25:54 +00:00
|
|
|
onCancel = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
2017-02-17 18:11:43 +00:00
|
|
|
const { formData, onCancel: handleCancel } = this.props;
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2017-02-17 18:11:43 +00:00
|
|
|
return handleCancel(formData);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2017-02-17 18:11:43 +00:00
|
|
|
|
2017-03-08 16:11:47 +00:00
|
|
|
handlePlatformChoice = (value) => {
|
2021-04-12 13:32:25 +00:00
|
|
|
const {
|
|
|
|
fields: { platform },
|
|
|
|
} = this.props;
|
|
|
|
const valArray = value.split(",");
|
2017-03-08 16:11:47 +00:00
|
|
|
|
|
|
|
// Remove All if another OS is chosen
|
2021-04-12 13:32:25 +00:00
|
|
|
if (valArray.indexOf("") === 0 && valArray.length > 1) {
|
|
|
|
return platform.onChange(pull(valArray, "").join(","));
|
2017-03-08 16:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove OS if All is chosen
|
2021-04-12 13:32:25 +00:00
|
|
|
if (valArray.length > 1 && valArray.indexOf("") > -1) {
|
|
|
|
return platform.onChange("");
|
2017-03-08 16:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return platform.onChange(value);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2017-03-08 16:11:47 +00:00
|
|
|
|
2017-02-17 18:11:43 +00:00
|
|
|
renderCancelButton = () => {
|
|
|
|
const { formData } = this.props;
|
|
|
|
const { onCancel } = this;
|
|
|
|
|
|
|
|
if (!formData.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-04-12 13:32:25 +00:00
|
|
|
<Button
|
|
|
|
className={`${baseClass}__cancel-btn`}
|
|
|
|
onClick={onCancel}
|
|
|
|
variant="inverse"
|
|
|
|
>
|
2017-02-17 18:11:43 +00:00
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
};
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
render() {
|
2016-12-21 17:25:54 +00:00
|
|
|
const { fields, handleSubmit } = this.props;
|
2017-03-08 16:11:47 +00:00
|
|
|
const { handlePlatformChoice, renderCancelButton } = this;
|
2016-12-21 17:25:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<form className={baseClass} onSubmit={handleSubmit}>
|
2021-06-01 13:10:35 +00:00
|
|
|
<h2 className={`${baseClass}__title`}>Configuration</h2>
|
2016-12-21 17:25:54 +00:00
|
|
|
<div className={`${baseClass}__fields`}>
|
|
|
|
<InputField
|
|
|
|
{...fields.interval}
|
2021-06-01 13:10:35 +00:00
|
|
|
inputWrapperClass={`${baseClass}__form-field ${baseClass}__form-field--frequency`}
|
2016-12-21 17:25:54 +00:00
|
|
|
placeholder="- - -"
|
2021-06-01 13:10:35 +00:00
|
|
|
label="Frequency (seconds)"
|
|
|
|
// hint="Seconds"
|
2016-12-21 17:25:54 +00:00
|
|
|
type="number"
|
|
|
|
/>
|
|
|
|
<Dropdown
|
|
|
|
{...fields.platform}
|
|
|
|
options={platformOptions}
|
|
|
|
placeholder="- - -"
|
|
|
|
label="Platform"
|
2017-03-08 16:11:47 +00:00
|
|
|
onChange={handlePlatformChoice}
|
2017-01-24 23:52:48 +00:00
|
|
|
multi
|
2016-12-21 17:25:54 +00:00
|
|
|
wrapperClassName={`${baseClass}__form-field ${baseClass}__form-field--platform`}
|
|
|
|
/>
|
|
|
|
<Dropdown
|
|
|
|
{...fields.version}
|
|
|
|
options={minOsqueryVersionOptions}
|
|
|
|
placeholder="- - -"
|
2021-06-01 13:10:35 +00:00
|
|
|
label="Minimum osquery version"
|
2016-12-21 17:25:54 +00:00
|
|
|
wrapperClassName={`${baseClass}__form-field ${baseClass}__form-field--osquer-vers`}
|
|
|
|
/>
|
|
|
|
<Dropdown
|
|
|
|
{...fields.logging_type}
|
|
|
|
options={loggingTypeOptions}
|
|
|
|
placeholder="- - -"
|
|
|
|
label="Logging"
|
|
|
|
wrapperClassName={`${baseClass}__form-field ${baseClass}__form-field--logging`}
|
|
|
|
/>
|
2017-02-01 20:48:08 +00:00
|
|
|
<InputField
|
|
|
|
{...fields.shard}
|
|
|
|
inputWrapperClass={`${baseClass}__form-field ${baseClass}__form-field--shard`}
|
|
|
|
placeholder="- - -"
|
|
|
|
label="Shard"
|
|
|
|
type="number"
|
|
|
|
/>
|
2016-12-21 17:25:54 +00:00
|
|
|
<div className={`${baseClass}__btn-wrapper`}>
|
2017-02-17 18:11:43 +00:00
|
|
|
{renderCancelButton()}
|
2021-04-12 13:32:25 +00:00
|
|
|
<Button
|
|
|
|
className={`${baseClass}__submit-btn`}
|
|
|
|
type="submit"
|
|
|
|
variant="brand"
|
|
|
|
>
|
2016-12-28 15:24:52 +00:00
|
|
|
Save
|
|
|
|
</Button>
|
2016-12-21 17:25:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Form(ConfigurePackQueryForm, {
|
|
|
|
fields: fieldNames,
|
|
|
|
validate,
|
|
|
|
});
|