Merge pull request #80 from stephb9959/main

2.5.44
This commit is contained in:
Charles
2022-02-10 18:59:48 +00:00
committed by GitHub
13 changed files with 201 additions and 63 deletions

29
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ucentral-client",
"version": "2.5.36",
"version": "2.5.44",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ucentral-client",
"version": "2.5.36",
"version": "2.5.44",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
@@ -23,6 +23,7 @@
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-apexcharts": "^1.3.9",
"react-csv": "^2.2.2",
"react-dom": "^17.0.2",
"react-flow-renderer": "^9.6.6",
"react-i18next": "^11.11.0",
@@ -32,7 +33,7 @@
"react-tooltip": "^4.2.21",
"react-widgets": "^5.1.1",
"sass": "^1.35.1",
"ucentral-libs": "^1.0.59",
"ucentral-libs": "^1.0.60",
"uuid": "^8.3.2"
},
"devDependencies": {
@@ -10914,6 +10915,11 @@
"react": ">=0.13"
}
},
"node_modules/react-csv": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/react-csv/-/react-csv-2.2.2.tgz",
"integrity": "sha512-RG5hOcZKZFigIGE8LxIEV/OgS1vigFQT4EkaHeKgyuCbUAu9Nbd/1RYq++bJcJJ9VOqO/n9TZRADsXNDR4VEpw=="
},
"node_modules/react-dom": {
"version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz",
@@ -13327,9 +13333,9 @@
}
},
"node_modules/ucentral-libs": {
"version": "1.0.59",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-1.0.59.tgz",
"integrity": "sha512-QtfJmHLmQRfRIMYttjAS4JpyPsbf9KVCZd1kn9VC7/j5K9EaZlzCLgZkAPTqW76EvQzvitmkXU4B0WWaHhflrg==",
"version": "1.0.60",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-1.0.60.tgz",
"integrity": "sha512-PRw2QTcbnHdrA8rPQhREI1FOKyuZUt48H3KcSGQgHpik2Ni+0una7jRfMFXwOU9yHzxQAlYG0EWLrzBnrKRvGA==",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
@@ -22977,6 +22983,11 @@
"prop-types": "^15.5.7"
}
},
"react-csv": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/react-csv/-/react-csv-2.2.2.tgz",
"integrity": "sha512-RG5hOcZKZFigIGE8LxIEV/OgS1vigFQT4EkaHeKgyuCbUAu9Nbd/1RYq++bJcJJ9VOqO/n9TZRADsXNDR4VEpw=="
},
"react-dom": {
"version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz",
@@ -24849,9 +24860,9 @@
}
},
"ucentral-libs": {
"version": "1.0.59",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-1.0.59.tgz",
"integrity": "sha512-QtfJmHLmQRfRIMYttjAS4JpyPsbf9KVCZd1kn9VC7/j5K9EaZlzCLgZkAPTqW76EvQzvitmkXU4B0WWaHhflrg==",
"version": "1.0.60",
"resolved": "https://registry.npmjs.org/ucentral-libs/-/ucentral-libs-1.0.60.tgz",
"integrity": "sha512-PRw2QTcbnHdrA8rPQhREI1FOKyuZUt48H3KcSGQgHpik2Ni+0una7jRfMFXwOU9yHzxQAlYG0EWLrzBnrKRvGA==",
"requires": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "2.5.36",
"version": "2.5.44",
"dependencies": {
"@coreui/coreui": "^3.4.0",
"@coreui/icons": "^2.0.1",
@@ -17,6 +17,7 @@
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-apexcharts": "^1.3.9",
"react-csv": "^2.2.2",
"react-dom": "^17.0.2",
"react-flow-renderer": "^9.6.6",
"react-i18next": "^11.11.0",
@@ -26,7 +27,7 @@
"react-tooltip": "^4.2.21",
"react-widgets": "^5.1.1",
"sass": "^1.35.1",
"ucentral-libs": "^1.0.59",
"ucentral-libs": "^1.0.60",
"uuid": "^8.3.2"
},
"main": "index.js",

View File

@@ -596,7 +596,7 @@
"channel": "Kanal",
"directions": "Starten Sie einen WiFi-Scan dieses Geräts, der ungefähr 25 Sekunden dauern sollte.",
"re_scan": "Erneut scannen",
"result_directions": "Bitte klicken Sie auf die Schaltfläche '$t(scan.re_scan)', wenn Sie einen Scan mit derselben Konfiguration wie beim letzten Scan durchführen möchten.",
"result_directions": "Sie können oben rechts auf die Schaltfläche „Scannen“ klicken, um $t(scan.re_scan)",
"results": "Ergebnisse des WiFi-Scans",
"scan": "Scan",
"scanning": "Scannen... ",

View File

@@ -596,7 +596,7 @@
"channel": "Channel",
"directions": "Launch a wifi scan of this device, which should take approximately 25 seconds.",
"re_scan": "Re-Scan",
"result_directions": "Please click the '$t(scan.re_scan)' button if you would like to do a scan with the same configuration as the last.",
"result_directions": "You can click the 'Scan' button at the top right to $t(scan.re_scan)",
"results": "Wi-Fi Scan Results",
"scan": "Scan",
"scanning": "Scanning... ",

View File

@@ -596,7 +596,7 @@
"channel": "Canal",
"directions": "Ejecute un escaneo wifi de este dispositivo, que debería tomar aproximadamente 25 segundos.",
"re_scan": "Vuelva a escanear",
"result_directions": "Haga clic en el botón '$ t (scan.re_scan)' si desea realizar un escaneo con la misma configuración que el anterior.",
"result_directions": "Puede hacer clic en el botón 'Escanear' en la parte superior derecha para $t(scan.re_scan)",
"results": "Resultados de escaneo Wi-Fi",
"scan": "Escanear",
"scanning": "Exploración... ",

View File

@@ -596,7 +596,7 @@
"channel": "Canal",
"directions": "Lancez une analyse wifi de cet appareil, ce qui devrait prendre environ 25 secondes.",
"re_scan": "Nouvelle analyse",
"result_directions": "Veuillez cliquer sur le bouton '$t(scan.re_scan)' si vous souhaitez effectuer un scan avec la même configuration que le précédent.",
"result_directions": "Vous pouvez cliquer sur le bouton 'Scan' en haut à droite pour $t(scan.re_scan)",
"results": "Résultats de l'analyse Wi-Fi",
"scan": "Balayage",
"scanning": "Balayage... ",

View File

@@ -596,7 +596,7 @@
"channel": "Canal",
"directions": "Inicie uma verificação de wi-fi deste dispositivo, o que deve levar aproximadamente 25 segundos.",
"re_scan": "Verificar novamente",
"result_directions": "Clique no botão '$ t (scan.re_scan)' se desejar fazer uma varredura com a mesma configuração da anterior.",
"result_directions": "Você pode clicar no botão 'Scan' no canto superior direito para $t(scan.re_scan)",
"results": "Resultados da verificação de Wi-Fi",
"scan": "Varredura",
"scanning": "Scanning... ",

View File

@@ -15,7 +15,7 @@ const DeviceSearchBar = ({ action }) => {
const search = (value) => {
if (socket.readyState === WebSocket.OPEN) {
if (value.length > 0 && value.match('^[a-fA-F0-9]+$')) {
if (value.length > 1 && value.match('^[a-fA-F0-9-*]+$')) {
setWaitingSearch('');
socket.send(
JSON.stringify({ command: 'serial_number_search', serial_prefix: value.toLowerCase() }),

View File

@@ -76,6 +76,16 @@ const StatisticsChartList = ({ setOptions, section, setStart, setEnd, time }) =>
memoryUsed[2].data.push(Math.floor(log.data.unit.memory.cached / 1024 / 1024));
}
const newUsed = memoryUsed[0].data;
if (newUsed.length > 0) newUsed.shift();
memoryUsed[0].data = newUsed;
const newBuff = memoryUsed[1].data;
if (newBuff.length > 0) newBuff.shift();
memoryUsed[1].data = newBuff;
const newCached = memoryUsed[2].data;
if (newCached.length > 0) newCached.shift();
memoryUsed[2].data = newCached;
// This dictionary will have a key that is the interface name and a value of it's index in the final array
const interfaceTypes = {};
const interfaceList = [];
@@ -135,16 +145,23 @@ const StatisticsChartList = ({ setOptions, section, setStart, setEnd, time }) =>
totalRx += assoc.rx_bytes ?? 0;
}
} else {
totalTx += assoc.tx_bytes - prevTx ?? 0;
totalRx += assoc.rx_bytes - prevRx ?? 0;
prevTx = assoc.tx_bytes;
prevRx = assoc.rx_bytes;
totalTx += assoc.tx_bytes ?? 0;
totalRx += assoc.rx_bytes ?? 0;
}
}
}
}
interfaceList[interfaceTypes[inter.name]][0].data.push(Math.floor(totalTx / 1024));
interfaceList[interfaceTypes[inter.name]][1].data.push(Math.floor(totalRx / 1024));
if (version > 0) {
const tx = Math.floor(totalTx / 1024);
const rx = Math.floor(totalRx / 1024);
interfaceList[interfaceTypes[inter.name]][0].data.push(Math.max(tx - prevTx, 0));
interfaceList[interfaceTypes[inter.name]][1].data.push(Math.max(rx - prevRx, 0));
prevTx = tx;
prevRx = rx;
} else {
interfaceList[interfaceTypes[inter.name]][0].data.push(Math.floor(totalTx / 1024));
interfaceList[interfaceTypes[inter.name]][1].data.push(Math.floor(totalRx / 1024));
}
} else {
interfaceList[interfaceTypes[inter.name]][0].data.push(
inter.counters ? Math.floor(inter.counters.tx_bytes) : 0,

View File

@@ -5,7 +5,6 @@ import {
CModalHeader,
CModalTitle,
CModalBody,
CModalFooter,
CRow,
CForm,
CSwitch,
@@ -14,15 +13,17 @@ import {
CPopover,
} from '@coreui/react';
import CIcon from '@coreui/icons-react';
import { cilX } from '@coreui/icons';
import React, { useState, useEffect } from 'react';
import { cilCloudDownload, cilGauge, cilX } from '@coreui/icons';
import React, { useCallback, useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import axiosInstance from 'utils/axiosInstance';
import eventBus from 'utils/eventBus';
import { LoadingButton, useAuth, useDevice } from 'ucentral-libs';
import { prettyDateForFile } from 'utils/helper';
import { useAuth, useDevice } from 'ucentral-libs';
import WifiChannelTable from 'components/WifiScanResultModal/WifiChannelTable';
import 'react-widgets/styles.css';
import { CSVLink } from 'react-csv';
const WifiScanModal = ({ show, toggleModal }) => {
const { t } = useTranslation();
@@ -36,6 +37,7 @@ const WifiScanModal = ({ show, toggleModal }) => {
const [activeScan, setActiveScan] = useState(false);
const [hideOptions, setHideOptions] = useState(false);
const [channelList, setChannelList] = useState([]);
const [csvData, setCsvData] = useState(null);
const toggleDfs = () => {
setDfs(!dfs);
@@ -50,6 +52,7 @@ const WifiScanModal = ({ show, toggleModal }) => {
setHadFailure(false);
setWaiting(false);
setChannelList([]);
setCsvData(null);
setDfs(true);
setActiveScan(false);
setHideOptions(false);
@@ -76,7 +79,10 @@ const WifiScanModal = ({ show, toggleModal }) => {
scanList.forEach((device) => {
if (device.channel === channelNumber) {
const deviceToAdd = {};
deviceToAdd.SSID = device.ssid ?? 'N/A';
if (device.ssid && device.ssid.length > 0) deviceToAdd.SSID = device.ssid;
else {
deviceToAdd.SSID = device.meshid && device.meshid.length > 0 ? device.meshid : 'N/A';
}
deviceToAdd.Signal = (dbmNumber - device.signal) * -1;
channel.devices.push(deviceToAdd);
}
@@ -87,6 +93,40 @@ const WifiScanModal = ({ show, toggleModal }) => {
return finalList;
};
const getData = useCallback((scanResults) => {
if (scanResults === null || scanResults.length === 0) return [];
const dbmNumber = 4294967295;
const listOfChannels = [];
const listCsv = [];
scanResults.forEach((scan) => {
if (!listOfChannels.includes(scan.channel)) {
listOfChannels.push(scan.channel);
}
});
listOfChannels.forEach((channelNumber) => {
const channel = {
channel: channelNumber,
devices: [],
};
scanResults.forEach((device) => {
if (device.channel === channelNumber) {
const deviceToAdd = {};
if (device.ssid && device.ssid.length > 0) deviceToAdd.SSID = device.ssid;
else {
deviceToAdd.SSID = device.meshid && device.meshid.length > 0 ? device.meshid : 'N/A';
}
deviceToAdd.Signal = (dbmNumber - device.signal) * -1;
channel.devices.push(deviceToAdd);
listCsv.push({ ...deviceToAdd, ...device });
}
});
});
return listCsv;
}, []);
const doAction = () => {
setHadFailure(false);
setHadSuccess(false);
@@ -113,6 +153,7 @@ const WifiScanModal = ({ show, toggleModal }) => {
if (scanList) {
setChannelList(parseThroughList(scanList));
setCsvData(getData(scanList));
setErrorCode(response.data.errorCode ?? 0);
setHideOptions(true);
setHadSuccess(true);
@@ -134,6 +175,35 @@ const WifiScanModal = ({ show, toggleModal }) => {
<CModalHeader className="p-1">
<CModalTitle className="pl-1 pt-1">{t('actions.wifi_scan')}</CModalTitle>
<div className="text-right">
{csvData !== null ? (
<CPopover content={t('common.download')}>
<CSVLink
filename={`wifi_scan_${deviceSerialNumber}_${prettyDateForFile(
new Date().getTime() / 1000,
)}.csv`}
data={csvData}
>
<CButton color="primary" variant="outline" className="ml-2">
<CIcon content={cilCloudDownload} />
</CButton>
</CSVLink>
</CPopover>
) : (
<CButton color="primary" variant="outline" className="ml-2" disabled>
<CIcon content={cilCloudDownload} />
</CButton>
)}
<CPopover content={t('scan.scan')}>
<CButton
color="primary"
variant="outline"
className="ml-2"
onClick={doAction}
disabled={waiting}
>
<CIcon content={cilGauge} />
</CButton>
</CPopover>
<CPopover content={t('common.close')}>
<CButton color="primary" variant="outline" className="ml-2" onClick={toggleModal}>
<CIcon content={cilX} />
@@ -205,20 +275,6 @@ const WifiScanModal = ({ show, toggleModal }) => {
<WifiChannelTable channels={channelList} />
</div>
</CModalBody>
<CModalFooter>
<LoadingButton
label={!hadSuccess && !hadFailure ? t('scan.scan') : t('scan.re_scan')}
isLoadingLabel={t('scan.scanning')}
isLoading={waiting}
action={doAction}
variant="outline"
block={false}
disabled={waiting}
/>
<CButton color="secondary" onClick={toggleModal}>
{!hadSuccess && !hadFailure ? t('common.cancel') : t('common.exit')}
</CButton>
</CModalFooter>
</CModal>
);
};

View File

@@ -1,21 +1,58 @@
/* eslint-disable-rule prefer-destructuring */
import React from 'react';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { CButton, CModal, CModalHeader, CModalBody, CModalTitle, CPopover } from '@coreui/react';
import CIcon from '@coreui/icons-react';
import { cilX } from '@coreui/icons';
import { cilCloudDownload, cilX } from '@coreui/icons';
import PropTypes from 'prop-types';
import { prettyDate } from 'utils/helper';
import { prettyDate, prettyDateForFile } from 'utils/helper';
import { useDevice } from 'ucentral-libs';
import { CSVLink } from 'react-csv';
import WifiChannelTable from './WifiChannelTable';
const WifiScanResultModal = ({ show, toggle, scanResults, date }) => {
const { t } = useTranslation();
const { deviceSerialNumber } = useDevice();
const parseThroughList = (scanList) => {
const getData = useCallback(() => {
if (scanResults === null || scanResults.length === 0) return [];
const dbmNumber = 4294967295;
const listOfChannels = [];
const listCsv = [];
scanResults.forEach((scan) => {
if (!listOfChannels.includes(scan.channel)) {
listOfChannels.push(scan.channel);
}
});
listOfChannels.forEach((channelNumber) => {
const channel = {
channel: channelNumber,
devices: [],
};
scanResults.forEach((device) => {
if (device.channel === channelNumber) {
const deviceToAdd = {};
if (device.ssid && device.ssid.length > 0) deviceToAdd.SSID = device.ssid;
else {
deviceToAdd.SSID = device.meshid && device.meshid.length > 0 ? device.meshid : 'N/A';
}
deviceToAdd.Signal = (dbmNumber - device.signal) * -1;
channel.devices.push(deviceToAdd);
listCsv.push({ ...deviceToAdd, ...device });
}
});
});
return listCsv;
}, [scanResults]);
const parseThroughList = useCallback(() => {
const dbmNumber = 4294967295;
const listOfChannels = [];
scanList.forEach((scan) => {
scanResults.forEach((scan) => {
if (!listOfChannels.includes(scan.channel)) {
listOfChannels.push(scan.channel);
}
@@ -28,10 +65,13 @@ const WifiScanResultModal = ({ show, toggle, scanResults, date }) => {
devices: [],
};
scanList.forEach((device) => {
scanResults.forEach((device) => {
if (device.channel === channelNumber) {
const deviceToAdd = {};
deviceToAdd.SSID = device.ssid ?? 'N/A';
if (device.ssid && device.ssid.length > 0) deviceToAdd.SSID = device.ssid;
else {
deviceToAdd.SSID = device.meshid && device.meshid.length > 0 ? device.meshid : 'N/A';
}
deviceToAdd.Signal = (dbmNumber - device.signal) * -1;
channel.devices.push(deviceToAdd);
}
@@ -40,7 +80,8 @@ const WifiScanResultModal = ({ show, toggle, scanResults, date }) => {
finalList.push(channel);
});
return finalList;
};
}, [scanResults]);
return (
<CModal size="lg" show={show} onClose={toggle}>
<CModalHeader>
@@ -48,6 +89,18 @@ const WifiScanResultModal = ({ show, toggle, scanResults, date }) => {
{date !== '' ? prettyDate(date) : ''} {t('scan.results')}
</CModalTitle>
<div className="text-right">
<CPopover content={t('common.download')}>
<CSVLink
filename={`wifi_scan_${deviceSerialNumber}_${
date !== '' ? prettyDateForFile(date) : ''
}.csv`}
data={getData()}
>
<CButton color="primary" variant="outline" className="ml-2">
<CIcon content={cilCloudDownload} />
</CButton>
</CSVLink>
</CPopover>
<CPopover content={t('common.close')}>
<CButton color="primary" variant="outline" className="ml-2" onClick={toggle}>
<CIcon content={cilX} />
@@ -56,9 +109,7 @@ const WifiScanResultModal = ({ show, toggle, scanResults, date }) => {
</div>
</CModalHeader>
<CModalBody>
{scanResults === null ? null : (
<WifiChannelTable channels={parseThroughList(scanResults)} />
)}
{scanResults === null ? null : <WifiChannelTable channels={parseThroughList()} />}
</CModalBody>
</CModal>
);

View File

@@ -7,7 +7,7 @@ import DeviceLogs from 'components/DeviceLogs';
import DeviceStatisticsCard from 'components/InterfaceStatistics';
import DeviceActionCard from 'components/DeviceActionCard';
import axiosInstance from 'utils/axiosInstance';
import { DeviceProvider, useAuth, useToast } from 'ucentral-libs';
import { DeviceProvider, useAuth } from 'ucentral-libs';
import { useTranslation } from 'react-i18next';
import ConfigurationDisplay from 'components/ConfigurationDisplay';
import WifiAnalysis from 'components/WifiAnalysis';
@@ -21,7 +21,6 @@ const DevicePage = () => {
const { deviceId } = useParams();
const [index, setIndex] = useState(0);
const { currentToken, endpoints } = useAuth();
const { addToast } = useToast();
const [lastStats, setLastStats] = useState(null);
const [status, setStatus] = useState(null);
const [deviceConfig, setDeviceConfig] = useState(null);
@@ -63,14 +62,8 @@ const DevicePage = () => {
.then((response) => {
if (response) setDeviceConfig({ ...deviceInfo, extendedInfo: response.data.extendedInfo });
})
.catch((e) => {
setDeviceConfig(null);
addToast({
title: t('common.error'),
body: t('device.error_fetching_device', { error: e.response?.data?.ErrorDescription }),
color: 'danger',
autohide: true,
});
.catch(() => {
setDeviceConfig(deviceInfo);
});
};

View File

@@ -28,6 +28,15 @@ export const prettyDate = (dateString) => {
date.getSeconds(),
)}`;
};
export const prettyDateForFile = (dateString) => {
const convertedTimestamp = unixToDateString(dateString);
const date = new Date(convertedTimestamp);
return `${date.getFullYear()}_${prettyNumber(date.getMonth() + 1)}_${prettyNumber(
date.getDate(),
)}_${prettyNumber(date.getHours())}h${prettyNumber(date.getMinutes())}m${prettyNumber(
date.getSeconds(),
)}s`;
};
export const unixToTime = (dateString) => {
const convertedTimestamp = unixToDateString(dateString);