diff --git a/admin/CF7_AntiSpam_Admin_Customizations.php b/admin/CF7_AntiSpam_Admin_Customizations.php index 743ad3c..cc2315d 100644 --- a/admin/CF7_AntiSpam_Admin_Customizations.php +++ b/admin/CF7_AntiSpam_Admin_Customizations.php @@ -829,7 +829,13 @@ public function cf7a_print_user_agent() { public function cf7a_print_dnsbl() { printf( '

%s

', esc_html__( 'Check sender ip on DNS Blacklists, DNSBL are real-time lists of proven/recognised spam addresses. These may include lists of addresses of zombie computers or other machines used to send spam, Internet Service Providers (ISPs) that voluntarily host spammers, BUT they could also be users behind a proxy and that is why the method is no longer 100 per cent reliable. Add a DSNBL server url each line ', 'cf7-antispam' ) ); /** Translators: %s%s%s - a spam score of xyz will be added */ - printf( '

%s%s%s

', esc_html__( '⚠️ Use the servers you trust as safe, and consider that for each server reporting the ip a spam score of ', 'cf7-antispam' ), floatval( $this->options['score']['_dnsbl'] ), esc_html__( ' will be added.', 'cf7-antispam' ) ); + printf( '

%s%s%s

', esc_html__( '⚠️ Use FEW servers, those you tested reliable, and consider that for each server reporting the ip a spam score of ', 'cf7-antispam' ), floatval( $this->options['score']['_dnsbl'] ), esc_html__( ' will be added to the spam rating, 1 equal spam.', 'cf7-antispam' ) ); + printf( + '

%s%s

', + esc_html__( 'Here a you can find a list of servers: ', 'cf7-antispam' ), + esc_url( 'https://gist.github.com/search?q=dnsbl+list&ref=searchresults' ), + esc_url_raw( 'gist.github.com/search?q=dnsbl+list' ) + ); } /** It prints the honeypot info text */ @@ -1049,24 +1055,29 @@ private function cf7a_clean_recursive( $json_data ) { */ public function cf7a_sanitize_options( $input ) { /* get the import options */ - $new_input = $this->options; - $import_data = isset( $_POST['to-import'] ) ? sanitize_text_field( $_POST['to-import'] ) : false; - if ( ! empty( $import_data ) ) { - $json_data = json_decode( wp_unslash( $import_data ) ); - $input = $this->cf7a_clean_recursive( $json_data ); - // monkey pathing arrays that needs to be imploded - $input['bad_ip_list'] = implode( ',', $input['bad_ip_list'] ); - $input['ip_whitelist'] = implode( ',', $input['ip_whitelist'] ); - $input['bad_email_strings_list'] = implode( ',', $input['bad_email_strings_list'] ); - $input['bad_user_agent_list'] = implode( ',', $input['bad_user_agent_list'] ); - $input['dnsbl_list'] = implode( ',', $input['dnsbl_list'] ); - $input['honeypot_input_names'] = implode( ',', $input['honeypot_input_names'] ); - $input['bad_words_list'] = implode( ',', $input['bad_words_list'] ); - $input['languages_locales']['allowed'] = implode( ',', $input['languages_locales']['allowed'] ); - $input['languages_locales']['disallowed'] = implode( ',', $input['languages_locales']['disallowed'] ); - $input['cf7a_enabled'] = 1; - $input['cf7a_enable'] = 1; - $input['cf7a_version'] = CF7ANTISPAM_VERSION; + $new_input = $this->options; + if ( isset( $_POST['to-import'] ) ) { + $json_data = json_decode( stripslashes( $_POST['to-import'] ) ); + if ( ! empty( $json_data ) && is_object( $json_data ) ) { + $input = $this->cf7a_clean_recursive( $json_data ); + // monkey pathing arrays that needs to be imploded + $input['bad_ip_list'] = implode( ',', $input['bad_ip_list'] ); + $input['ip_whitelist'] = implode( ',', $input['ip_whitelist'] ); + $input['bad_email_strings_list'] = implode( ',', $input['bad_email_strings_list'] ); + $input['bad_user_agent_list'] = implode( ',', $input['bad_user_agent_list'] ); + $input['dnsbl_list'] = implode( ',', $input['dnsbl_list'] ); + $input['honeypot_input_names'] = implode( ',', $input['honeypot_input_names'] ); + $input['bad_words_list'] = implode( ',', $input['bad_words_list'] ); + $input['languages_locales']['allowed'] = implode( ',', $input['languages_locales']['allowed'] ); + $input['languages_locales']['disallowed'] = implode( ',', $input['languages_locales']['disallowed'] ); + $input['cf7a_enabled'] = 1; + $input['cf7a_enable'] = 1; + $input['cf7a_version'] = CF7ANTISPAM_VERSION; + } else { + cf7a_log( print_r( $_POST['to-import'], true ) ); + cf7a_log( 'CF7 AntiSpam: The import data is invalid' ); + return $this->options; + } } $new_input['cf7a_enabled'] = isset( $input['cf7a_enabled'] ) ? 1 : 0; diff --git a/src/settings/importExport.js b/src/settings/importExport.js index ba92206..9e79fde 100644 --- a/src/settings/importExport.js +++ b/src/settings/importExport.js @@ -1,3 +1,14 @@ +const loader = () => { + // create an element to show loading with a svg loader + const i = document.createElement('div'); + i.innerHTML = ` + + + `; + i.className = 'cf7a-loader'; + return i; +}; + window.onload = function () { // Example for download button document @@ -38,12 +49,19 @@ function importExportOptions(e) { alert('Invalid JSON. Please check your file and try again.'); return; } + /** * Get the submit form data and append the cf7-ntispam options to the form data options * @type {FormData} */ const data = new FormData(e.target); - data.append('to-import', encodeURIComponent(JSON.stringify(cf7aOptions))); + data.append('to-import', JSON.stringify(cf7aOptions)); + + // append after the form data options a spinning loader + const loaderElement = loader(); + e.target + .querySelector('#cf7a_import_button') + .insertAdjacentElement('afterend', loaderElement); // Make an AJAX request to save the merged options fetch(e.target.getAttribute('action'), { @@ -53,8 +71,6 @@ function importExportOptions(e) { .then((response) => response) .then((response) => { // Handle the response - // eslint-disable-next-line no-console - console.log(response); if (response.status === 200) { // emulate the php non async behavior window.location.href = response.url; @@ -64,6 +80,7 @@ function importExportOptions(e) { // Handle the error // eslint-disable-next-line no-console console.error(error); + loaderElement.innerHTML = null; }); } diff --git a/src/settings/settings.scss b/src/settings/settings.scss index 1e04d57..b62c9e2 100644 --- a/src/settings/settings.scss +++ b/src/settings/settings.scss @@ -62,6 +62,15 @@ $color__info: $color__blue; max-width: 900px; } + .cf7a-loader { + display: inline-block; + height: 25px; + vertical-align: middle; + width: 25px; + margin: 3px 12px; + opacity: 0.5; + } + form { // input style h2 { @@ -142,6 +151,7 @@ $color__info: $color__blue; .cf7a-option-notice { padding: 4px 8px; border: 2px solid $color__yellow; + display: block; border-radius: 8px; }