1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-06-15 13:36:35 +02:00

Compare commits

..

20 Commits

Author SHA1 Message Date
c32137e29a Bump v5.1.3 2020-09-11 18:00:05 +02:00
be7349661f Merge branch 'ssid-validation' into 'dev'
Ssid validation

Closes reforis#218

See merge request turris/reforis/foris-js!128
2020-09-11 17:39:05 +02:00
5186385b9f Update snapshots 2020-09-11 17:32:46 +02:00
002786d073 Add test 2020-09-11 17:32:46 +02:00
4d246540c1 Add SSID validation for bytes count 2020-09-11 17:32:45 +02:00
35b97ec0fe Add validation for SSID with diacritic 2020-09-11 17:32:45 +02:00
e1d75d8328 Merge branch 'release-v5.1.2' into 'dev'
Bump v5.1.2

See merge request turris/reforis/foris-js!126
2020-09-08 18:36:28 +02:00
0f85713483 Bump v5.1.2 2020-09-08 18:26:15 +02:00
c3cdafce13 Merge branch 'fix-ws-loop' into 'dev'
Fix infinity loop caused by WebSockets

Closes #17

See merge request turris/reforis/foris-js!125
2020-09-08 18:11:05 +02:00
b96b434a3e Update Snapshots 2020-09-02 17:55:53 +02:00
0ea5f7de84 Decrease Switch's margin-bottom with headings 2020-09-02 17:55:44 +02:00
0c7997f6c0 Fix Reboot page URL in respective dropdown 2020-09-02 17:55:44 +02:00
90ce866869 Fix infinity loop caused by WebSockets 2020-09-02 17:55:25 +02:00
4ff814f0fd Merge branch 'small-fixes' into 'dev'
Add "inline" option to RadioSet

See merge request turris/reforis/foris-js!123
2020-08-31 18:19:12 +02:00
896277b62a Bump v5.1.1 2020-08-31 16:04:03 +02:00
b0365e3b06 NPM audit fix 2020-08-31 15:56:01 +02:00
8bd71a08af Update Snapshots 2020-08-31 15:56:01 +02:00
1903016f13 Add "inline" option to RadioSet 2020-08-31 15:56:00 +02:00
443f14d26c Add ability to select switch's form-group 2020-08-31 15:56:00 +02:00
61b349c6cc Merge branch 'fluid-aid' into 'dev'
Add auxiliary features in order to support Fluid Layout

See merge request turris/reforis/foris-js!121
2020-08-25 17:35:28 +02:00
14 changed files with 115 additions and 69 deletions

92
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "foris",
"version": "5.1.0",
"version": "5.1.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -5906,9 +5906,9 @@
"dev": true
},
"copy-webpack-plugin": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-5.1.1.tgz",
"integrity": "sha512-P15M5ZC8dyCjQHWwd4Ia/dm0SgVvZJMYeykVIVYXbGyqO4dWB5oyPHp9i7wjwo5LhtlhKbiBCdS2NvM07Wlybg==",
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-5.1.2.tgz",
"integrity": "sha512-Uh7crJAco3AjBvgAy9Z75CjK8IG+gxaErro71THQ+vv/bl4HaQcpkexAY8KVW/T6D2W2IRr+couF/knIRkZMIQ==",
"dev": true,
"requires": {
"cacache": "^12.0.3",
@ -5921,7 +5921,7 @@
"normalize-path": "^3.0.0",
"p-limit": "^2.2.1",
"schema-utils": "^1.0.0",
"serialize-javascript": "^2.1.2",
"serialize-javascript": "^4.0.0",
"webpack-log": "^2.0.0"
},
"dependencies": {
@ -5962,6 +5962,15 @@
"ajv-keywords": "^3.1.0"
}
},
"serialize-javascript": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz",
"integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==",
"dev": true,
"requires": {
"randombytes": "^2.1.0"
}
},
"slash": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",
@ -15717,12 +15726,6 @@
}
}
},
"serialize-javascript": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-2.1.2.tgz",
"integrity": "sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==",
"dev": true
},
"serve-index": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz",
@ -16879,25 +16882,6 @@
"supports-hyperlinks": "^2.0.0"
}
},
"terser": {
"version": "4.6.7",
"resolved": "https://registry.npmjs.org/terser/-/terser-4.6.7.tgz",
"integrity": "sha512-fmr7M1f7DBly5cX2+rFDvmGBAaaZyPrHYK4mMdHEDAdNTqXSZgSOfqsfGq2HqPGT/1V0foZZuCZFx8CHKgAk3g==",
"dev": true,
"requires": {
"commander": "^2.20.0",
"source-map": "~0.6.1",
"source-map-support": "~0.5.12"
},
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
}
}
},
"terser-webpack-plugin": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-2.3.8.tgz",
@ -18108,20 +18092,51 @@
"dev": true
},
"terser-webpack-plugin": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.4.3.tgz",
"integrity": "sha512-QMxecFz/gHQwteWwSo5nTc6UaICqN1bMedC5sMtUc7y3Ha3Q8y6ZO0iCR8pq4RJC8Hjf0FEPEHZqcMB/+DFCrA==",
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.4.5.tgz",
"integrity": "sha512-04Rfe496lN8EYruwi6oPQkG0vo8C+HT49X687FZnpPF0qMAIHONI6HEXYPKDOE8e5HjXTyKfqRd/agHtH0kOtw==",
"dev": true,
"requires": {
"cacache": "^12.0.2",
"find-cache-dir": "^2.1.0",
"is-wsl": "^1.1.0",
"schema-utils": "^1.0.0",
"serialize-javascript": "^2.1.2",
"serialize-javascript": "^4.0.0",
"source-map": "^0.6.1",
"terser": "^4.1.2",
"webpack-sources": "^1.4.0",
"worker-farm": "^1.7.0"
},
"dependencies": {
"serialize-javascript": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz",
"integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==",
"dev": true,
"requires": {
"randombytes": "^2.1.0"
}
},
"terser": {
"version": "4.8.0",
"resolved": "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz",
"integrity": "sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==",
"dev": true,
"requires": {
"commander": "^2.20.0",
"source-map": "~0.6.1",
"source-map-support": "~0.5.12"
}
},
"worker-farm": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.7.0.tgz",
"integrity": "sha512-rvw3QTZc8lAxyVrqcSGVm5yP/IJ2UcB3U0graE3LCFoZ0Yn2x4EoVSqJKdB/T5M+FLcRPjz4TDacRf3OCfNUzw==",
"dev": true,
"requires": {
"errno": "~0.1.7"
}
}
}
}
}
@ -18483,15 +18498,6 @@
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
"dev": true
},
"worker-farm": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.7.0.tgz",
"integrity": "sha512-rvw3QTZc8lAxyVrqcSGVm5yP/IJ2UcB3U0graE3LCFoZ0Yn2x4EoVSqJKdB/T5M+FLcRPjz4TDacRf3OCfNUzw==",
"dev": true,
"requires": {
"errno": "~0.1.7"
}
},
"worker-rpc": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/worker-rpc/-/worker-rpc-0.1.1.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "foris",
"version": "5.1.0",
"version": "5.1.3",
"description": "Set of components and utils for Foris and its plugins.",
"author": "CZ.NIC, z.s.p.o.",
"repository": {

View File

@ -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.
@ -33,9 +33,18 @@ RadioSet.propTypes = {
value: PropTypes.string,
/** Help text message . */
helpText: PropTypes.string,
inline: PropTypes.bool,
};
export function RadioSet({ name, label, choices, value, helpText, ...props }) {
export function RadioSet({
name,
label,
choices,
value,
helpText,
inline,
...props
}) {
const uid = useUID();
const radios = choices.map((choice, key) => {
const id = `${name}-${key}`;
@ -48,6 +57,7 @@ export function RadioSet({ name, label, choices, value, helpText, ...props }) {
value={choice.value}
helpText={choice.helpText}
checked={choice.value === value}
inline={inline}
{...props}
/>
);
@ -76,15 +86,16 @@ Radio.propTypes = {
PropTypes.arrayOf(PropTypes.node),
]).isRequired,
id: PropTypes.string.isRequired,
inline: PropTypes.bool,
helpText: PropTypes.string,
};
export function Radio({ label, id, helpText, ...props }) {
export function Radio({ label, id, helpText, inline, ...props }) {
return (
<>
<div
className={`custom-control custom-radio ${
!helpText ? "custom-control-inline" : ""
inline ? "custom-control-inline" : ""
}`.trim()}
>
<input

View File

@ -23,7 +23,7 @@ Switch.propTypes = {
export function Switch({ label, helpText, switchHeading, ...props }) {
const uid = useUID();
return (
<div className="form-group">
<div className={`form-group ${switchHeading ? "switch" : ""}`}>
<div
className={`custom-control custom-switch ${
!helpText ? "custom-control-inline" : ""

View File

@ -11,7 +11,7 @@ exports[`<RadioSet/> Render radio set 1`] = `
Radios set label
</label>
<div
class="custom-control custom-radio custom-control-inline"
class="custom-control custom-radio"
>
<input
checked=""
@ -29,7 +29,7 @@ exports[`<RadioSet/> Render radio set 1`] = `
</label>
</div>
<div
class="custom-control custom-radio custom-control-inline"
class="custom-control custom-radio"
>
<input
class="custom-control-input"
@ -46,7 +46,7 @@ exports[`<RadioSet/> Render radio set 1`] = `
</label>
</div>
<div
class="custom-control custom-radio custom-control-inline"
class="custom-control custom-radio"
>
<input
class="custom-control-input"

View File

@ -2,7 +2,7 @@
exports[`<Switch/> Render switch 1`] = `
<div
class="form-group"
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"
class="form-group "
>
<div
class="custom-control custom-switch"

View File

@ -105,6 +105,7 @@ function DeviceForm({
label="SSID"
value={formData.SSID}
error={formErrors.SSID || null}
helpText={HELP_TEXTS.ssid}
required
onChange={setFormValue((value) => ({
devices: {

View File

@ -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]: {

View File

@ -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 = _(

View File

@ -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);
});
});

View File

@ -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
@ -255,7 +255,7 @@ exports[`<WiFiSettings/> Snapshot both modules disabled. 1`] = `
>
<form>
<div
class="form-group"
class="form-group switch"
>
<div
class="custom-control custom-switch custom-control-inline switch-heading"
@ -277,7 +277,7 @@ exports[`<WiFiSettings/> Snapshot both modules disabled. 1`] = `
</div>
<hr />
<div
class="form-group"
class="form-group switch"
>
<div
class="custom-control custom-switch custom-control-inline switch-heading"
@ -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\\"
@ -423,10 +428,10 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
+ </div>
<hr />
<div
class=\\"form-group\\"
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 custom-control-inline\\"
+ class=\\"custom-control custom-radio\\"
+ >
+ <input
+ class=\\"custom-control-input\\"
@ -577,7 +587,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
+ </label>
+ </div>
+ <div
+ class=\\"custom-control custom-radio custom-control-inline\\"
+ class=\\"custom-control custom-radio\\"
+ >
+ <input
+ checked=\\"\\"
@ -876,7 +886,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
+ </select>
+ </div>
+ <div
+ class=\\"form-group\\"
+ class=\\"form-group \\"
+ >
+ <div
+ class=\\"custom-control custom-switch\\"
@ -905,7 +915,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
+ </div>
<hr />
<div
class=\\"form-group\\"
class=\\"form-group switch\\"
>
<div"
`;

View File

@ -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.
`),

View File

@ -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

View File

@ -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;