2020-08-13 08:15:45 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2018-08-30 14:25:33 +00:00
|
|
|
import { HashRouter, Route } from 'react-router-dom';
|
2018-09-19 15:58:55 +00:00
|
|
|
import LoadingBar from 'react-redux-loading-bar';
|
2020-08-13 08:15:45 +00:00
|
|
|
import { hot } from 'react-hot-loader/root';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
import 'react-table/react-table.css';
|
|
|
|
import '../ui/Tabler.css';
|
|
|
|
import '../ui/ReactTable.css';
|
|
|
|
import './index.css';
|
|
|
|
|
2020-08-13 08:15:45 +00:00
|
|
|
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
|
2019-06-03 12:41:45 +00:00
|
|
|
|
2020-08-13 08:15:45 +00:00
|
|
|
import propTypes from 'prop-types';
|
2018-09-14 12:37:35 +00:00
|
|
|
import Toasts from '../Toasts';
|
2019-03-19 13:19:53 +00:00
|
|
|
import Footer from '../ui/Footer';
|
2018-08-30 14:25:33 +00:00
|
|
|
import Status from '../ui/Status';
|
2019-02-20 13:54:14 +00:00
|
|
|
import UpdateTopline from '../ui/UpdateTopline';
|
2019-05-16 14:24:30 +00:00
|
|
|
import UpdateOverlay from '../ui/UpdateOverlay';
|
2019-02-18 13:06:27 +00:00
|
|
|
import EncryptionTopline from '../ui/EncryptionTopline';
|
2019-05-23 09:32:51 +00:00
|
|
|
import Icons from '../ui/Icons';
|
2018-11-22 14:56:57 +00:00
|
|
|
import i18n from '../../i18n';
|
2019-12-06 15:00:01 +00:00
|
|
|
import Loading from '../ui/Loading';
|
2020-06-05 10:03:48 +00:00
|
|
|
import { FILTERS_URLS, MENU_URLS, SETTINGS_URLS } from '../../helpers/constants';
|
2020-07-13 13:06:56 +00:00
|
|
|
import { getLogsUrlParams, setHtmlLangAttr } from '../../helpers/helpers';
|
2020-08-13 08:15:45 +00:00
|
|
|
import Header from '../Header';
|
|
|
|
import { changeLanguage, getDnsStatus } from '../../actions';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
2020-08-13 08:15:45 +00:00
|
|
|
import Dashboard from '../../containers/Dashboard';
|
|
|
|
import SetupGuide from '../../containers/SetupGuide';
|
|
|
|
import Settings from '../../containers/Settings';
|
|
|
|
import Dns from '../../containers/Dns';
|
|
|
|
import Encryption from '../../containers/Encryption';
|
2020-08-19 15:23:05 +00:00
|
|
|
import Dhcp from '../Settings/Dhcp';
|
2020-08-13 08:15:45 +00:00
|
|
|
import Clients from '../../containers/Clients';
|
|
|
|
import DnsBlocklist from '../../containers/DnsBlocklist';
|
|
|
|
import DnsAllowlist from '../../containers/DnsAllowlist';
|
|
|
|
import DnsRewrites from '../../containers/DnsRewrites';
|
|
|
|
import CustomRules from '../../containers/CustomRules';
|
|
|
|
import Services from '../Filters/Services';
|
2020-09-01 13:30:30 +00:00
|
|
|
import Logs from '../Logs';
|
2018-11-22 14:56:57 +00:00
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
|
2020-08-13 08:15:45 +00:00
|
|
|
const ROUTES = [
|
|
|
|
{
|
|
|
|
path: MENU_URLS.root,
|
|
|
|
component: Dashboard,
|
|
|
|
exact: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: [`${MENU_URLS.logs}${getLogsUrlParams(':search?', ':response_status?')}`, MENU_URLS.logs],
|
|
|
|
component: Logs,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: MENU_URLS.guide,
|
|
|
|
component: SetupGuide,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: SETTINGS_URLS.settings,
|
|
|
|
component: Settings,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: SETTINGS_URLS.dns,
|
|
|
|
component: Dns,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: SETTINGS_URLS.encryption,
|
|
|
|
component: Encryption,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: SETTINGS_URLS.dhcp,
|
|
|
|
component: Dhcp,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: SETTINGS_URLS.clients,
|
|
|
|
component: Clients,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: FILTERS_URLS.dns_blocklists,
|
|
|
|
component: DnsBlocklist,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: FILTERS_URLS.dns_allowlists,
|
|
|
|
component: DnsAllowlist,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: FILTERS_URLS.dns_rewrites,
|
|
|
|
component: DnsRewrites,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: FILTERS_URLS.custom_rules,
|
|
|
|
component: CustomRules,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: FILTERS_URLS.blocked_services,
|
|
|
|
component: Services,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const renderRoute = ({ path, component, exact }, idx) => <Route
|
2020-08-19 15:23:05 +00:00
|
|
|
key={idx}
|
|
|
|
exact={exact}
|
|
|
|
path={path}
|
|
|
|
component={component}
|
2020-08-13 08:15:45 +00:00
|
|
|
/>;
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const {
|
|
|
|
language,
|
|
|
|
isCoreRunning,
|
|
|
|
isUpdateAvailable,
|
|
|
|
processing,
|
|
|
|
} = useSelector((state) => state.dashboard, shallowEqual);
|
|
|
|
|
|
|
|
const { processing: processingEncryption } = useSelector((
|
|
|
|
state,
|
|
|
|
) => state.encryption, shallowEqual);
|
|
|
|
|
|
|
|
const updateAvailable = isCoreRunning && isUpdateAvailable;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
dispatch(getDnsStatus());
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const setLanguage = () => {
|
2018-11-22 14:56:57 +00:00
|
|
|
if (!processing) {
|
2018-11-26 08:48:06 +00:00
|
|
|
if (language) {
|
2018-11-22 14:56:57 +00:00
|
|
|
i18n.changeLanguage(language);
|
2020-07-03 08:14:54 +00:00
|
|
|
setHtmlLangAttr(language);
|
2018-11-22 14:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i18n.on('languageChanged', (lang) => {
|
2020-08-13 08:15:45 +00:00
|
|
|
dispatch(changeLanguage(lang));
|
2018-11-22 14:56:57 +00:00
|
|
|
});
|
2019-06-03 12:41:45 +00:00
|
|
|
};
|
2018-11-22 14:56:57 +00:00
|
|
|
|
2020-08-13 08:15:45 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setLanguage();
|
|
|
|
}, [language]);
|
|
|
|
|
|
|
|
const reloadPage = () => {
|
|
|
|
window.location.reload();
|
|
|
|
};
|
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
return <HashRouter hashType="noslash">
|
|
|
|
{updateAvailable && <>
|
|
|
|
<UpdateTopline />
|
|
|
|
<UpdateOverlay />
|
|
|
|
</>}
|
|
|
|
{!processingEncryption && <EncryptionTopline />}
|
|
|
|
<LoadingBar className="loading-bar" updateTime={1000} />
|
|
|
|
<Header />
|
|
|
|
<div className="container container--wrap pb-5">
|
|
|
|
{processing && <Loading />}
|
|
|
|
{!isCoreRunning && <div className="row row-cards">
|
|
|
|
<div className="col-lg-12">
|
|
|
|
<Status reloadPage={reloadPage} message="dns_start" />
|
|
|
|
<Loading />
|
2020-08-13 08:15:45 +00:00
|
|
|
</div>
|
2020-08-19 15:23:05 +00:00
|
|
|
</div>}
|
|
|
|
{!processing && isCoreRunning && ROUTES.map(renderRoute)}
|
|
|
|
</div>
|
|
|
|
<Footer />
|
|
|
|
<Toasts />
|
|
|
|
<Icons />
|
|
|
|
</HashRouter>;
|
2020-08-13 08:15:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
renderRoute.propTypes = {
|
|
|
|
path: propTypes.oneOfType([propTypes.string, propTypes.arrayOf(propTypes.string)]).isRequired,
|
|
|
|
component: propTypes.element.isRequired,
|
|
|
|
exact: propTypes.bool,
|
2018-08-30 14:25:33 +00:00
|
|
|
};
|
|
|
|
|
2020-08-13 08:15:45 +00:00
|
|
|
export default hot(App);
|