mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-06-15 13:36:35 +02:00
Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
aaf4087c96 | |||
240db88661 | |||
913a7d7b75 | |||
bdc8726791 | |||
1c986519f6 | |||
defc363f01 | |||
69723f6b0b | |||
c32137e29a | |||
be7349661f | |||
5186385b9f | |||
002786d073 | |||
4d246540c1 | |||
35b97ec0fe | |||
e1d75d8328 | |||
0f85713483 | |||
c3cdafce13 | |||
b96b434a3e | |||
0ea5f7de84 | |||
0c7997f6c0 | |||
90ce866869 | |||
4ff814f0fd |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "foris",
|
||||
"version": "5.1.1",
|
||||
"version": "5.1.4",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "foris",
|
||||
"version": "5.1.1",
|
||||
"version": "5.1.4",
|
||||
"description": "Set of components and utils for Foris and its plugins.",
|
||||
"author": "CZ.NIC, z.s.p.o.",
|
||||
"repository": {
|
||||
|
@ -37,7 +37,11 @@ Alert.defaultProps = {
|
||||
|
||||
export function Alert({ type, onDismiss, children }) {
|
||||
return (
|
||||
<div className={`alert alert-dismissible alert-${type}`}>
|
||||
<div
|
||||
className={`alert ${
|
||||
onDismiss ? "alert-dismissible" : ""
|
||||
} alert-${type}`}
|
||||
>
|
||||
{onDismiss ? (
|
||||
<button type="button" className="close" onClick={onDismiss}>
|
||||
×
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
* Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
import React, { useRef } from "react";
|
||||
import React, { useRef, useEffect } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import { Portal } from "../utils/Portal";
|
||||
@ -31,6 +31,19 @@ export function Modal({ shown, setShown, scrollable, children }) {
|
||||
|
||||
useClickOutside(dialogRef, () => setShown(false));
|
||||
|
||||
useEffect(() => {
|
||||
const handleEsc = (event) => {
|
||||
if (event.keyCode === 27) {
|
||||
setShown(false);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", handleEsc);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", handleEsc);
|
||||
};
|
||||
}, [setShown]);
|
||||
|
||||
return (
|
||||
<Portal containerId="modal-container">
|
||||
<div className={`modal fade ${shown ? "show" : ""}`} role="dialog">
|
||||
|
@ -23,7 +23,7 @@ Switch.propTypes = {
|
||||
export function Switch({ label, helpText, switchHeading, ...props }) {
|
||||
const uid = useUID();
|
||||
return (
|
||||
<div className="form-group switch">
|
||||
<div className={`form-group ${switchHeading ? "switch" : ""}`}>
|
||||
<div
|
||||
className={`custom-control custom-switch ${
|
||||
!helpText ? "custom-control-inline" : ""
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
exports[`<Switch/> Render switch 1`] = `
|
||||
<div
|
||||
class="form-group switch"
|
||||
class="form-group "
|
||||
>
|
||||
<div
|
||||
class="custom-control custom-switch"
|
||||
@ -30,7 +30,7 @@ exports[`<Switch/> Render switch 1`] = `
|
||||
|
||||
exports[`<Switch/> Render uncheked switch 1`] = `
|
||||
<div
|
||||
class="form-group switch"
|
||||
class="form-group "
|
||||
>
|
||||
<div
|
||||
class="custom-control custom-switch"
|
||||
|
@ -63,7 +63,7 @@ RebootModal.propTypes = {
|
||||
function RebootModal({ shown, setShown, onReboot }) {
|
||||
return (
|
||||
<Modal shown={shown} setShown={setShown}>
|
||||
<ModalHeader setShown={setShown} title={_("Reboot confirmation")} />
|
||||
<ModalHeader setShown={setShown} title={_("Warning!")} />
|
||||
<ModalBody>
|
||||
<p>{_("Are you sure you want to restart the router?")}</p>
|
||||
</ModalBody>
|
||||
|
@ -105,6 +105,7 @@ function DeviceForm({
|
||||
label="SSID"
|
||||
value={formData.SSID}
|
||||
error={formErrors.SSID || null}
|
||||
helpText={HELP_TEXTS.ssid}
|
||||
required
|
||||
onChange={setFormValue((value) => ({
|
||||
devices: {
|
||||
@ -156,6 +157,7 @@ function DeviceForm({
|
||||
choices={getHwmodeChoices(formData)}
|
||||
value={formData.hwmode}
|
||||
helpText={HELP_TEXTS.hwmode}
|
||||
inline
|
||||
onChange={setFormValue((value) => ({
|
||||
devices: {
|
||||
[deviceIndex]: {
|
||||
|
@ -57,6 +57,7 @@ export default function WifiGuestForm({
|
||||
label="SSID"
|
||||
value={formData.SSID}
|
||||
error={formErrors.SSID}
|
||||
helpText={HELP_TEXTS.ssid}
|
||||
onChange={setFormValue((value) => ({
|
||||
devices: {
|
||||
[formData.id]: {
|
||||
|
@ -63,6 +63,12 @@ function prepDataToSubmit(formData) {
|
||||
return formData;
|
||||
}
|
||||
|
||||
export function byteCount(string) {
|
||||
const buffer = Buffer.from(string, "utf-8");
|
||||
const count = buffer.byteLength;
|
||||
return count;
|
||||
}
|
||||
|
||||
export function validator(formData) {
|
||||
const formErrors = formData.devices.map((device) => {
|
||||
if (!device.enabled) return {};
|
||||
@ -71,6 +77,8 @@ export function validator(formData) {
|
||||
if (device.SSID.length > 32)
|
||||
errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||
if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty");
|
||||
if (byteCount(device.SSID) > 32)
|
||||
errors.SSID = _("SSID can't be longer than 32 bytes");
|
||||
|
||||
if (device.password.length < 8)
|
||||
errors.password = _("Password must contain at least 8 symbols");
|
||||
@ -82,6 +90,8 @@ export function validator(formData) {
|
||||
guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||
if (device.guest_wifi.SSID.length === 0)
|
||||
guest_wifi_errors.SSID = _("SSID can't be empty");
|
||||
if (byteCount(device.guest_wifi.SSID) > 32)
|
||||
guest_wifi_errors.SSID = _("SSID can't be longer than 32 bytes");
|
||||
|
||||
if (device.guest_wifi.password.length < 8)
|
||||
guest_wifi_errors.password = _(
|
||||
|
@ -19,7 +19,7 @@ import {
|
||||
twoDevices,
|
||||
threeDevices,
|
||||
} from "./__fixtures__/wifiSettings";
|
||||
import { WiFiSettings, validator } from "../WiFiSettings";
|
||||
import { WiFiSettings, validator, byteCount } from "../WiFiSettings";
|
||||
|
||||
describe("<WiFiSettings/>", () => {
|
||||
let firstRender;
|
||||
@ -213,4 +213,8 @@ describe("<WiFiSettings/>", () => {
|
||||
];
|
||||
expect(validator(threeDevices)).toEqual(threeDevicesFormErrors);
|
||||
});
|
||||
|
||||
it("ByteCount function", () => {
|
||||
expect(byteCount("abc")).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
@ -5,7 +5,7 @@ exports[`<WiFiSettings/> Snapshot 2.4 GHz 1`] = `
|
||||
- First value
|
||||
+ Second value
|
||||
|
||||
@@ -245,207 +245,95 @@
|
||||
@@ -250,207 +250,95 @@
|
||||
value=\\"0\\"
|
||||
>
|
||||
auto
|
||||
@ -336,7 +336,7 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
|
||||
- First value
|
||||
+ Second value
|
||||
|
||||
@@ -474,10 +474,89 @@
|
||||
@@ -479,10 +479,94 @@
|
||||
Parameters of the guest network can be set in the Guest network tab.
|
||||
|
||||
</small>
|
||||
@ -375,6 +375,11 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
|
||||
+ </button>
|
||||
+ </div>
|
||||
+ </div>
|
||||
+ <small
|
||||
+ class=\\"form-text text-muted\\"
|
||||
+ >
|
||||
+ SSID which contains non-standard characters could cause problems on some devices.
|
||||
+ </small>
|
||||
+ </div>
|
||||
+ <div
|
||||
+ class=\\"form-group\\"
|
||||
@ -426,7 +431,7 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
|
||||
class=\\"form-group switch\\"
|
||||
>
|
||||
<div
|
||||
@@ -501,10 +580,11 @@
|
||||
@@ -506,10 +590,11 @@
|
||||
<div
|
||||
class=\\"text-right\\"
|
||||
>
|
||||
@ -445,7 +450,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||
- First value
|
||||
+ Second value
|
||||
|
||||
@@ -22,10 +22,462 @@
|
||||
@@ -22,10 +22,467 @@
|
||||
Wi-Fi 1
|
||||
</h2>
|
||||
</label>
|
||||
@ -485,6 +490,11 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||
+ </button>
|
||||
+ </div>
|
||||
+ </div>
|
||||
+ <small
|
||||
+ class=\\"form-text text-muted\\"
|
||||
+ >
|
||||
+ SSID which contains non-standard characters could cause problems on some devices.
|
||||
+ </small>
|
||||
+ </div>
|
||||
+ <div
|
||||
+ class=\\"form-group\\"
|
||||
@ -560,7 +570,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||
+ GHz
|
||||
+ </label>
|
||||
+ <div
|
||||
+ class=\\"custom-control custom-radio\\"
|
||||
+ class=\\"custom-control custom-radio custom-control-inline\\"
|
||||
+ >
|
||||
+ <input
|
||||
+ class=\\"custom-control-input\\"
|
||||
@ -577,7 +587,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||
+ </label>
|
||||
+ </div>
|
||||
+ <div
|
||||
+ class=\\"custom-control custom-radio\\"
|
||||
+ class=\\"custom-control custom-radio custom-control-inline\\"
|
||||
+ >
|
||||
+ <input
|
||||
+ checked=\\"\\"
|
||||
@ -876,7 +886,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||
+ </select>
|
||||
+ </div>
|
||||
+ <div
|
||||
+ class=\\"form-group switch\\"
|
||||
+ class=\\"form-group \\"
|
||||
+ >
|
||||
+ <div
|
||||
+ class=\\"custom-control custom-switch\\"
|
||||
|
@ -19,6 +19,9 @@ export const HWMODES = {
|
||||
"11a": "5",
|
||||
};
|
||||
export const HELP_TEXTS = {
|
||||
ssid: _(
|
||||
`SSID which contains non-standard characters could cause problems on some devices.`
|
||||
),
|
||||
password: _(`
|
||||
WPA2 pre-shared key, that is required to connect to the network.
|
||||
`),
|
||||
|
@ -22,7 +22,7 @@ exports[`<RebootButton/> Render modal. 1`] = `
|
||||
<h5
|
||||
class="modal-title"
|
||||
>
|
||||
Reboot confirmation
|
||||
Warning!
|
||||
</h5>
|
||||
<button
|
||||
class="close"
|
||||
|
@ -27,7 +27,7 @@ export const ForisURLs = {
|
||||
|
||||
approveUpdates: "/package-management/updates",
|
||||
languages: "/package-management/languages",
|
||||
rebootPage: "/reforis/administration/reboot",
|
||||
rebootPage: "/administration/reboot",
|
||||
luci: "/cgi-bin/luci",
|
||||
|
||||
// API
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
* Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
@ -12,7 +12,7 @@ import { ForisURLs } from "../utils/forisUrls";
|
||||
const PROTOCOL = window.location.protocol === "http:" ? "ws" : "wss";
|
||||
|
||||
const URL = process.env.LIGHTTPD
|
||||
? `${PROTOCOL}://${window.location.hostname}/foris-ws`
|
||||
? `${PROTOCOL}://${window.location.host}/foris-ws`
|
||||
: `${PROTOCOL}://${window.location.hostname}:${9081}`;
|
||||
|
||||
const WAITING_FOR_CONNECTION_TIMEOUT = 500;
|
||||
|
Reference in New Issue
Block a user