mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-10-30 22:20:31 +01:00 
			
		
		
		
	Add SSID validation for bytes count
This commit is contained in:
		| @@ -105,6 +105,7 @@ function DeviceForm({ | |||||||
|                         label="SSID" |                         label="SSID" | ||||||
|                         value={formData.SSID} |                         value={formData.SSID} | ||||||
|                         error={formErrors.SSID || null} |                         error={formErrors.SSID || null} | ||||||
|  |                         helpText={HELP_TEXTS.ssid} | ||||||
|                         required |                         required | ||||||
|                         onChange={setFormValue((value) => ({ |                         onChange={setFormValue((value) => ({ | ||||||
|                             devices: { |                             devices: { | ||||||
|   | |||||||
| @@ -57,6 +57,7 @@ export default function WifiGuestForm({ | |||||||
|                         label="SSID" |                         label="SSID" | ||||||
|                         value={formData.SSID} |                         value={formData.SSID} | ||||||
|                         error={formErrors.SSID} |                         error={formErrors.SSID} | ||||||
|  |                         helpText={HELP_TEXTS.ssid} | ||||||
|                         onChange={setFormValue((value) => ({ |                         onChange={setFormValue((value) => ({ | ||||||
|                             devices: { |                             devices: { | ||||||
|                                 [formData.id]: { |                                 [formData.id]: { | ||||||
|   | |||||||
| @@ -63,14 +63,10 @@ function prepDataToSubmit(formData) { | |||||||
|     return formData; |     return formData; | ||||||
| } | } | ||||||
|  |  | ||||||
| function diacriticValidation(string) { | export function byteCount(string) { | ||||||
|     for (let i = 0; i < string.length; i++) { |     const buffer = Buffer.from(string, "utf-8"); | ||||||
|         const charCode = string.charCodeAt(i); |     const count = buffer.byteLength; | ||||||
|         if (charCode < 32 || charCode > 127) { |     return count; | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     return true; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| export function validator(formData) { | export function validator(formData) { | ||||||
| @@ -81,10 +77,8 @@ export function validator(formData) { | |||||||
|         if (device.SSID.length > 32) |         if (device.SSID.length > 32) | ||||||
|             errors.SSID = _("SSID can't be longer than 32 symbols"); |             errors.SSID = _("SSID can't be longer than 32 symbols"); | ||||||
|         if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty"); |         if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty"); | ||||||
|         if (!diacriticValidation(device.SSID)) |         if (byteCount(device.SSID) > 32) | ||||||
|             errors.SSID = _( |             errors.SSID = _("SSID can't be longer than 32 bytes"); | ||||||
|                 "Your SSID contains non-standard characters. These are not forbidden, but could cause problems on some devices." |  | ||||||
|             ); |  | ||||||
|  |  | ||||||
|         if (device.password.length < 8) |         if (device.password.length < 8) | ||||||
|             errors.password = _("Password must contain at least 8 symbols"); |             errors.password = _("Password must contain at least 8 symbols"); | ||||||
| @@ -96,6 +90,8 @@ export function validator(formData) { | |||||||
|             guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols"); |             guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols"); | ||||||
|         if (device.guest_wifi.SSID.length === 0) |         if (device.guest_wifi.SSID.length === 0) | ||||||
|             guest_wifi_errors.SSID = _("SSID can't be empty"); |             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) |         if (device.guest_wifi.password.length < 8) | ||||||
|             guest_wifi_errors.password = _( |             guest_wifi_errors.password = _( | ||||||
|   | |||||||
| @@ -19,6 +19,9 @@ export const HWMODES = { | |||||||
|     "11a": "5", |     "11a": "5", | ||||||
| }; | }; | ||||||
| export const HELP_TEXTS = { | export const HELP_TEXTS = { | ||||||
|  |     ssid: _( | ||||||
|  |         `SSID which contains non-standard characters could cause problems on some devices.` | ||||||
|  |     ), | ||||||
|     password: _(` |     password: _(` | ||||||
|         WPA2 pre-shared key, that is required to connect to the network. |         WPA2 pre-shared key, that is required to connect to the network. | ||||||
|     `), |     `), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user