2020-06-17 21:36:19 +00:00
|
|
|
import React, { Fragment, useEffect, useState } from 'react';
|
2018-08-30 14:25:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-17 21:36:19 +00:00
|
|
|
import { Trans } from 'react-i18next';
|
|
|
|
import Modal from 'react-modal';
|
2020-07-13 13:06:56 +00:00
|
|
|
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import queryString from 'query-string';
|
2020-07-15 17:55:13 +00:00
|
|
|
import classNames from 'classnames';
|
2020-05-22 14:06:05 +00:00
|
|
|
import {
|
2020-07-13 13:06:56 +00:00
|
|
|
BLOCK_ACTIONS,
|
2020-06-17 21:36:19 +00:00
|
|
|
TABLE_DEFAULT_PAGE_SIZE,
|
|
|
|
TABLE_FIRST_PAGE,
|
2020-07-13 13:06:56 +00:00
|
|
|
smallScreenSize,
|
2020-05-22 14:06:05 +00:00
|
|
|
} from '../../helpers/constants';
|
2018-08-30 14:25:33 +00:00
|
|
|
import Loading from '../ui/Loading';
|
2020-06-17 21:36:19 +00:00
|
|
|
import Filters from './Filters';
|
|
|
|
import Table from './Table';
|
|
|
|
import Disabled from './Disabled';
|
|
|
|
import { getFilteringStatus } from '../../actions/filtering';
|
|
|
|
import { getClients } from '../../actions';
|
|
|
|
import { getDnsConfig } from '../../actions/dnsConfig';
|
2020-07-13 13:06:56 +00:00
|
|
|
import {
|
|
|
|
getLogsConfig,
|
|
|
|
refreshFilteredLogs,
|
|
|
|
resetFilteredLogs,
|
|
|
|
setFilteredLogs,
|
|
|
|
} from '../../actions/queryLogs';
|
2020-06-17 21:36:19 +00:00
|
|
|
import { addSuccessToast } from '../../actions/toasts';
|
2020-07-03 16:17:58 +00:00
|
|
|
import './Logs.css';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
2020-07-15 17:55:13 +00:00
|
|
|
const processContent = (data, buttonType) => Object.entries(data)
|
2020-06-17 21:36:19 +00:00
|
|
|
.map(([key, value]) => {
|
2020-07-13 12:23:13 +00:00
|
|
|
if (!value) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
const isTitle = value === 'title';
|
|
|
|
const isButton = key === buttonType;
|
|
|
|
const isBoolean = typeof value === 'boolean';
|
|
|
|
const isHidden = isBoolean && value === false;
|
2019-09-20 12:05:10 +00:00
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
let keyClass = 'key-colon';
|
2018-09-03 12:55:20 +00:00
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
if (isTitle) {
|
|
|
|
keyClass = 'title--border';
|
2019-08-30 13:03:36 +00:00
|
|
|
}
|
2020-06-17 21:36:19 +00:00
|
|
|
if (isButton || isBoolean) {
|
|
|
|
keyClass = '';
|
2018-09-28 13:30:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
return isHidden ? null : <Fragment key={key}>
|
|
|
|
<div
|
2020-07-15 17:55:13 +00:00
|
|
|
className={classNames(`key__${key}`, keyClass, {
|
|
|
|
'font-weight-bold': isBoolean && value === true,
|
|
|
|
})}>
|
2020-06-17 21:36:19 +00:00
|
|
|
<Trans>{isButton ? value : key}</Trans>
|
2018-09-28 13:30:52 +00:00
|
|
|
</div>
|
2020-06-17 21:36:19 +00:00
|
|
|
<div className={`value__${key} text-pre text-truncate`}>
|
|
|
|
<Trans>{(isTitle || isButton || isBoolean) ? '' : value || '—'}</Trans>
|
2019-08-30 13:03:36 +00:00
|
|
|
</div>
|
2020-06-17 21:36:19 +00:00
|
|
|
</Fragment>;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const Logs = (props) => {
|
|
|
|
const dispatch = useDispatch();
|
2020-07-13 13:06:56 +00:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const {
|
|
|
|
response_status: response_status_url_param = '',
|
|
|
|
search: search_url_param = '',
|
|
|
|
} = queryString.parse(history.location.search);
|
|
|
|
|
|
|
|
const { filter } = useSelector((state) => state.queryLogs, shallowEqual);
|
|
|
|
|
|
|
|
const search = filter?.search || search_url_param;
|
|
|
|
const response_status = filter?.response_status || response_status_url_param;
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
const [isSmallScreen, setIsSmallScreen] = useState(window.innerWidth < smallScreenSize);
|
|
|
|
const [detailedDataCurrent, setDetailedDataCurrent] = useState({});
|
|
|
|
const [buttonType, setButtonType] = useState(BLOCK_ACTIONS.BLOCK);
|
|
|
|
const [isModalOpened, setModalOpened] = useState(false);
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
2020-07-13 13:06:56 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
setIsLoading(true);
|
|
|
|
await dispatch(setFilteredLogs({
|
|
|
|
search,
|
|
|
|
response_status,
|
|
|
|
}));
|
|
|
|
setIsLoading(false);
|
|
|
|
})();
|
|
|
|
}, [response_status, search]);
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
const {
|
|
|
|
filtering,
|
|
|
|
setLogsPage,
|
|
|
|
setLogsPagination,
|
|
|
|
toggleDetailedLogs,
|
|
|
|
dashboard,
|
|
|
|
dnsConfig,
|
|
|
|
queryLogs: {
|
|
|
|
enabled,
|
|
|
|
processingGetConfig,
|
|
|
|
processingAdditionalLogs,
|
|
|
|
processingGetLogs,
|
|
|
|
oldest,
|
|
|
|
logs,
|
|
|
|
pages,
|
|
|
|
page,
|
|
|
|
isDetailed,
|
|
|
|
},
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const mediaQuery = window.matchMedia(`(max-width: ${smallScreenSize}px)`);
|
|
|
|
const mediaQueryHandler = (e) => {
|
|
|
|
setIsSmallScreen(e.matches);
|
|
|
|
if (e.matches) {
|
|
|
|
toggleDetailedLogs(false);
|
2020-01-29 12:00:37 +00:00
|
|
|
}
|
2019-08-30 13:03:36 +00:00
|
|
|
};
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
const closeModal = () => setModalOpened(false);
|
2019-09-26 08:36:02 +00:00
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
const getLogs = (older_than, page, initial) => {
|
2020-07-13 13:06:56 +00:00
|
|
|
if (enabled) {
|
2020-06-17 21:36:19 +00:00
|
|
|
props.getLogs({
|
|
|
|
older_than,
|
|
|
|
page,
|
|
|
|
pageSize: TABLE_DEFAULT_PAGE_SIZE,
|
|
|
|
initial,
|
|
|
|
});
|
2019-09-20 12:05:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
useEffect(() => {
|
2020-07-15 17:55:13 +00:00
|
|
|
try {
|
|
|
|
mediaQuery.addEventListener('change', mediaQueryHandler);
|
|
|
|
} catch (e1) {
|
|
|
|
try {
|
|
|
|
// Safari 13.1 do not support mediaQuery.addEventListener('change', handler)
|
|
|
|
mediaQuery.addListener(mediaQueryHandler);
|
|
|
|
} catch (e2) {
|
|
|
|
console.error(e2);
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 13:06:56 +00:00
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
(async () => {
|
|
|
|
setIsLoading(true);
|
|
|
|
dispatch(setLogsPage(TABLE_FIRST_PAGE));
|
|
|
|
dispatch(getFilteringStatus());
|
|
|
|
dispatch(getClients());
|
|
|
|
try {
|
|
|
|
await Promise.all([
|
|
|
|
dispatch(getLogsConfig()),
|
|
|
|
dispatch(getDnsConfig()),
|
|
|
|
]);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
} finally {
|
|
|
|
setIsLoading(false);
|
|
|
|
}
|
|
|
|
})();
|
2020-07-13 13:06:56 +00:00
|
|
|
|
|
|
|
return () => {
|
2020-07-15 17:55:13 +00:00
|
|
|
try {
|
|
|
|
mediaQuery.removeEventListener('change', mediaQueryHandler);
|
|
|
|
} catch (e1) {
|
|
|
|
try {
|
|
|
|
mediaQuery.removeListener(mediaQueryHandler);
|
|
|
|
} catch (e2) {
|
|
|
|
console.error(e2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 13:06:56 +00:00
|
|
|
dispatch(resetFilteredLogs());
|
|
|
|
};
|
2020-06-17 21:36:19 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const refreshLogs = async () => {
|
|
|
|
setIsLoading(true);
|
|
|
|
await Promise.all([
|
|
|
|
dispatch(setLogsPage(TABLE_FIRST_PAGE)),
|
2020-07-13 13:06:56 +00:00
|
|
|
dispatch(refreshFilteredLogs()),
|
2020-06-17 21:36:19 +00:00
|
|
|
]);
|
|
|
|
dispatch(addSuccessToast('query_log_updated'));
|
|
|
|
setIsLoading(false);
|
2019-11-18 11:51:09 +00:00
|
|
|
};
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{enabled && processingGetConfig && <Loading />}
|
|
|
|
{enabled && !processingGetConfig && (
|
2020-07-13 13:06:56 +00:00
|
|
|
<>
|
2020-06-17 21:36:19 +00:00
|
|
|
<Filters
|
2020-07-13 13:06:56 +00:00
|
|
|
filter={{
|
|
|
|
response_status,
|
|
|
|
search,
|
|
|
|
}}
|
2020-06-17 21:36:19 +00:00
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
processingGetLogs={processingGetLogs}
|
|
|
|
processingAdditionalLogs={processingAdditionalLogs}
|
|
|
|
refreshLogs={refreshLogs}
|
|
|
|
/>
|
|
|
|
<Table
|
|
|
|
isLoading={isLoading}
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
logs={logs}
|
|
|
|
pages={pages}
|
|
|
|
page={page}
|
|
|
|
autoClients={dashboard.autoClients}
|
|
|
|
oldest={oldest}
|
|
|
|
filtering={filtering}
|
|
|
|
processingGetLogs={processingGetLogs}
|
|
|
|
processingGetConfig={processingGetConfig}
|
|
|
|
isDetailed={isDetailed}
|
|
|
|
setLogsPagination={setLogsPagination}
|
|
|
|
setLogsPage={setLogsPage}
|
|
|
|
toggleDetailedLogs={toggleDetailedLogs}
|
|
|
|
getLogs={getLogs}
|
|
|
|
setRules={props.setRules}
|
|
|
|
addSuccessToast={props.addSuccessToast}
|
|
|
|
getFilteringStatus={props.getFilteringStatus}
|
|
|
|
dnssec_enabled={dnsConfig.dnssec_enabled}
|
|
|
|
setDetailedDataCurrent={setDetailedDataCurrent}
|
|
|
|
setButtonType={setButtonType}
|
|
|
|
setModalOpened={setModalOpened}
|
|
|
|
isSmallScreen={isSmallScreen}
|
|
|
|
/>
|
|
|
|
<Modal portalClassName='grid' isOpen={isSmallScreen && isModalOpened}
|
|
|
|
onRequestClose={closeModal}
|
|
|
|
style={{
|
|
|
|
content: {
|
|
|
|
width: '100%',
|
|
|
|
height: 'fit-content',
|
|
|
|
left: 0,
|
|
|
|
top: 47,
|
|
|
|
padding: '1rem 1.5rem 1rem',
|
|
|
|
},
|
|
|
|
overlay: {
|
|
|
|
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<svg
|
|
|
|
className="icon icon--small icon-cross d-block d-md-none cursor--pointer"
|
|
|
|
onClick={closeModal}>
|
|
|
|
<use xlinkHref="#cross" />
|
|
|
|
</svg>
|
|
|
|
{processContent(detailedDataCurrent, buttonType)}
|
|
|
|
</Modal>
|
2020-07-13 13:06:56 +00:00
|
|
|
</>
|
2020-06-17 21:36:19 +00:00
|
|
|
)}
|
|
|
|
{!enabled && !processingGetConfig && (
|
|
|
|
<Disabled />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
Logs.propTypes = {
|
2019-08-30 13:03:36 +00:00
|
|
|
getLogs: PropTypes.func.isRequired,
|
|
|
|
queryLogs: PropTypes.object.isRequired,
|
|
|
|
dashboard: PropTypes.object.isRequired,
|
|
|
|
getFilteringStatus: PropTypes.func.isRequired,
|
|
|
|
filtering: PropTypes.object.isRequired,
|
|
|
|
setRules: PropTypes.func.isRequired,
|
|
|
|
addSuccessToast: PropTypes.func.isRequired,
|
2019-09-20 12:05:10 +00:00
|
|
|
setLogsPagination: PropTypes.func.isRequired,
|
2019-11-15 07:51:45 +00:00
|
|
|
setLogsPage: PropTypes.func.isRequired,
|
2020-06-17 21:36:19 +00:00
|
|
|
toggleDetailedLogs: PropTypes.func.isRequired,
|
|
|
|
dnsConfig: PropTypes.object.isRequired,
|
2018-08-30 14:25:33 +00:00
|
|
|
};
|
|
|
|
|
2020-06-17 21:36:19 +00:00
|
|
|
export default Logs;
|