import { TextControl, RadioControl, TextareaControl, __experimentalNumberControl as NumberControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import License from "./License/License"; import Password from "./Password"; import SelectControl from "./SelectControl"; import Host from "./Host/Host"; import Hyperlink from "../utils/Hyperlink"; import LetsEncrypt from "../LetsEncrypt/LetsEncrypt"; import Activate from "../LetsEncrypt/Activate"; import MixedContentScan from "./MixedContentScan/MixedContentScan"; import PermissionsPolicy from "./PermissionsPolicy"; import CheckboxControl from "./CheckboxControl"; import Support from "./Support"; import LearningMode from "./LearningMode/LearningMode"; import RiskComponent from "./RiskConfiguration/RiskComponent"; import VulnerabilitiesOverview from "./RiskConfiguration/vulnerabilitiesOverview"; import IpAddressDatatable from "./LimitLoginAttempts/IpAddressDatatable"; import TwoFaRolesDropDown from "./TwoFA/TwoFaRolesDropDown"; import Button from "./Button"; import Icon from "../utils/Icon"; import { useEffect, useState, useRef } from "@wordpress/element"; import useFields from "./FieldsData"; import PostDropdown from "./PostDropDown"; import NotificationTester from "./RiskConfiguration/NotificationTester"; import getAnchor from "../utils/getAnchor"; import useMenu from "../Menu/MenuData"; import UserDatatable from "./LimitLoginAttempts/UserDatatable"; import CountryDatatable from "./LimitLoginAttempts/CountryDatatable"; import BlockListDatatable from "./GeoBlockList/BlockListDatatable"; import TwoFaDataTable from "./TwoFA/TwoFaDataTable"; import EventLogDataTable from "./EventLog/EventLogDataTable"; import DOMPurify from "dompurify"; import RolesDropDown from "./RolesDropDown"; import GeoDatatable from "./GeoBlockList/GeoDatatable"; import WhiteListDatatable from "./GeoBlockList/WhiteListDatatable"; import Captcha from "./Captcha/Captcha"; import CaptchaKey from "./Captcha/CaptchaKey"; import UserAgentTable from "./firewall/UserAgentTable"; import TwoFaEnabledDropDown from "./TwoFA/TwoFaEnabledDropDown"; const Field = (props) => { const scrollAnchor = useRef(null); const { updateField, setChangedField, highLightField, setHighLightField , getFieldValue} = useFields(); const [anchor, setAnchor] = useState(null); const { selectedFilter, setSelectedFilter } = useMenu(); useEffect(() => { // Check URL for anchor and highlightfield parameters const anchor = getAnchor('anchor'); const highlightField = getAnchor('highlightfield'); setAnchor(anchor); if (highlightField) { setHighLightField(highlightField); } if (highlightField === props.field.id && scrollAnchor.current) { scrollAnchor.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } //if the field is a captcha provider, scroll to the captcha provider is a temp fix cause i can't get the scroll to work properly. if (highLightField === 'enabled_captcha_provider' && props.fields) { let captchaField = document.getElementsByClassName('rsssl-highlight')[0]; if (captchaField) { captchaField.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } if (anchor && anchor === props.field.id) { scrollAnchor.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }, []); useEffect(() => { handleAnchor(); }, [anchor]); window.addEventListener('hashchange', () => { const anchor = getAnchor('anchor'); const highlightField = getAnchor('highlightfield'); setAnchor(anchor); if (highlightField) { setHighLightField(highlightField); } if (highlightField === props.field.id && scrollAnchor.current) { scrollAnchor.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } if (anchor && anchor === props.field.id) { scrollAnchor.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); const handleAnchor = () => { if (anchor && anchor === props.field.id) { scrollAnchor.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }; const onChangeHandler = (fieldValue) => { let field = props.field; if (field.pattern) { const regex = new RegExp(field.pattern, 'g'); const allowedCharactersArray = fieldValue.match(regex); fieldValue = allowedCharactersArray ? allowedCharactersArray.join('') : ''; } updateField(field.id, fieldValue); // We can configure other fields if a field is enabled, or set to a certain value. let configureFieldCondition = false; if (field.configure_on_activation) { if (field.configure_on_activation.hasOwnProperty('condition') && props.field.value == field.configure_on_activation.condition) { configureFieldCondition = true; } let configureField = field.configure_on_activation[0]; for (let fieldId in configureField) { if (configureFieldCondition && configureField.hasOwnProperty(fieldId)) { updateField(fieldId, configureField[fieldId]); } } } setChangedField(field.id, fieldValue); }; const labelWrap = (field) => { let tooltipColor = field.warning ? 'red' : 'black'; return ( <>
{field.label}
{field.tooltip && } ); }; let field = props.field; let fieldValue = field.value; let disabled = field.disabled; let highLightClass = 'rsssl-field-wrap'; if (highLightField === props.field.id) { highLightClass = 'rsssl-field-wrap rsssl-highlight'; } let options = []; if (field.options) { for (let key in field.options) { if (field.options.hasOwnProperty(key)) { let item = {}; item.label = field.options[key]; item.value = key; options.push(item); } } } // If a feature can only be used on networkwide or single site setups, pass that info here. if (!rsssl_settings.networkwide_active && field.networkwide_required) { disabled = true; field.comment = ( <> {__("This feature is only available networkwide.", "really-simple-ssl")} ); } if (field.conditionallyDisabled) { disabled = true; } if (!field.visible) { return null; } if ( field.type==='checkbox' ) { return (
onChangeHandler( fieldValue ) } /> { field.comment &&
/* nosemgrep: react-dangerouslysetinnerhtml */ }
); } if ( field.type==='hidden' ){ return ( ); } if ( field.type==='radio' ){ return (
onChangeHandler(fieldValue) } selected={ fieldValue } options={ options } />
); } if (field.type==='email'){ const sendVerificationEmailField = props.fields.find(field => field.id === 'send_verification_email'); const emailIsVerified = sendVerificationEmailField && (sendVerificationEmailField.disabled === false); return (
onChangeHandler(fieldValue) } value= { fieldValue } /> { sendVerificationEmailField &&
{!emailIsVerified ? : }
}
); } if (field.type==='captcha_key') { return (
) } if ( field.type==='number' ){ return (
onChangeHandler(fieldValue) } value= { fieldValue } />
); } if (field.type==='text' ){ return (
onChangeHandler(fieldValue) } value= { fieldValue } />
); } if ( field.type==='button' ){ return (
); } if ( field.type==='password' ){ return (
); } if ( field.type==='textarea' ) { // Handle csp_frame_ancestors_urls differently. Disable on select change let fieldDisabled = false if ( field.id === 'csp_frame_ancestors_urls') { if ( getFieldValue('csp_frame_ancestors') === 'disabled' ) { fieldDisabled = true } } else { fieldDisabled = field.disabled } return (
onChangeHandler(fieldValue) } disabled={ fieldDisabled } />
); } if ( field.type==='license' ){ let field = props.field; let fieldValue = field.value; return (
); } if ( field.type==='number' ){ return (
onChangeHandler(fieldValue) } help={ field.comment } label={ field.label } value= { fieldValue } />
); } if ( field.type==='email' ){ return (
this.onChangeHandler(fieldValue) } value= { fieldValue } />
); } if ( field.type==='host') { return (
) } if ( field.type==='select') { return (
onChangeHandler(fieldValue) } value= { fieldValue } options={ options } field={field} />
) } if ( field.type==='support' ) { return (
) } if ( field.type==='postdropdown' ) { return (
) } if ( field.type==='permissionspolicy' ) { return (
) } if (field.type==='captcha') { return (
) } if ( field.type==='learningmode' ) { return(
) } if ( field.type==='riskcomponent' ) { return (
) } if ( field.type === 'mixedcontentscan' ) { return (
) } if (field.type === 'vulnerabilitiestable') { return (
) } if (field.type === 'two_fa_roles') { return (
); } if (field.type === 'eventlog-datatable') { return (
) } if (field.type === 'twofa-datatable') { return (
) } if (field.type === 'ip-address-datatable') { return (
) } if (field.type === 'user-datatable') { return (
) } if (field.type === 'country-datatable') { return (
) } if (field.type === 'geo-datatable') { return (
) } if (field.type === 'geo-ip-datatable') { return (
) } if (field.type === 'blocklist-datatable') { return (
) } if (field.type === 'user-agents-datatable') { return (
) } if (field.type === 'roles_dropdown') { return (
); } if (field.type === 'roles_enabled_dropdown') { return (
); } if(field.type === 'notificationtester') { return (
) } if ( field.type === 'letsencrypt' ) { return ( ) } if ( field.type === 'activate' ) { return ( ) } return ( 'not found field type '+field.type ); } export default Field;