Skip to content

Commit bef7c76

Browse files
committed
v2.2.4.1
1 parent 6b9d8b7 commit bef7c76

File tree

16 files changed

+306
-112
lines changed

16 files changed

+306
-112
lines changed

defines.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
defined( 'ABSPATH' ) or die( 'Something went wrong.' );
33

4-
define( 'SECUPRESS_VERSION' , '2.2.3' );
4+
define( 'SECUPRESS_VERSION' , '2.2.4.1' );
55
define( 'SECUPRESS_MAJOR_VERSION' , '2.2' );
66
define( 'SECUPRESS_PATH' , realpath( dirname( SECUPRESS_FILE ) ) . DIRECTORY_SEPARATOR );
77
define( 'SECUPRESS_INC_PATH' , SECUPRESS_PATH . 'free' . DIRECTORY_SEPARATOR );

free/admin/functions/admin.php

+52
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,55 @@ function secupress_print_pro_advantages() {
288288
</div>
289289
<?php
290290
}
291+
292+
293+
/**
294+
* Retrieve messages by their ID and format them by wrapping them in `<ul>` and `<li>` tags.
295+
*
296+
* @since 1.0
297+
*
298+
* @param (array) $msgs An array of messages.
299+
* @param (string) $test_name The scanner name.
300+
*
301+
* @return (string) An HTML list of formatted messages.
302+
*/
303+
function secupress_format_message( $msgs, $test_name ) {
304+
$classname = 'SecuPress_Scan_' . $test_name;
305+
$messages = $classname::get_instance()->get_messages();
306+
307+
$output = array();
308+
309+
if ( empty( $msgs ) ) {
310+
return implode( '<br/>', $output );
311+
}
312+
313+
foreach ( $msgs as $id => $atts ) {
314+
315+
if ( ! isset( $messages[ $id ] ) ) {
316+
317+
$string = __( 'Fix done.', 'secupress' );
318+
319+
} elseif ( is_array( $messages[ $id ] ) ) {
320+
321+
$count = array_shift( $atts );
322+
$string = translate_nooped_plural( $messages[ $id ], $count );
323+
324+
} else {
325+
326+
$string = $messages[ $id ];
327+
328+
}
329+
330+
if ( $atts ) {
331+
foreach ( $atts as $i => $att ) {
332+
if ( is_array( $att ) ) {
333+
$atts[ $i ] = wp_sprintf_l( '%l', $att );
334+
}
335+
}
336+
}
337+
338+
$output[] = ! empty( $atts ) ? vsprintf( $string, $atts ) : $string;
339+
}
340+
341+
return implode( '<br/>', $output );
342+
}

free/admin/functions/ajax-post.php

-51
Original file line numberDiff line numberDiff line change
@@ -165,54 +165,3 @@ function secupress_check_admin_referer( $action = -1, $query_arg = '_wpnonce' )
165165
}
166166
}
167167

168-
169-
/**
170-
* Retrieve messages by their ID and format them by wrapping them in `<ul>` and `<li>` tags.
171-
*
172-
* @since 1.0
173-
*
174-
* @param (array) $msgs An array of messages.
175-
* @param (string) $test_name The scanner name.
176-
*
177-
* @return (string) An HTML list of formatted messages.
178-
*/
179-
function secupress_format_message( $msgs, $test_name ) {
180-
$classname = 'SecuPress_Scan_' . $test_name;
181-
$messages = $classname::get_instance()->get_messages();
182-
183-
$output = array();
184-
185-
if ( empty( $msgs ) ) {
186-
return implode( '<br/>', $output );
187-
}
188-
189-
foreach ( $msgs as $id => $atts ) {
190-
191-
if ( ! isset( $messages[ $id ] ) ) {
192-
193-
$string = __( 'Fix done.', 'secupress' );
194-
195-
} elseif ( is_array( $messages[ $id ] ) ) {
196-
197-
$count = array_shift( $atts );
198-
$string = translate_nooped_plural( $messages[ $id ], $count );
199-
200-
} else {
201-
202-
$string = $messages[ $id ];
203-
204-
}
205-
206-
if ( $atts ) {
207-
foreach ( $atts as $i => $att ) {
208-
if ( is_array( $att ) ) {
209-
$atts[ $i ] = wp_sprintf_l( '%l', $att );
210-
}
211-
}
212-
}
213-
214-
$output[] = ! empty( $atts ) ? vsprintf( $string, $atts ) : $string;
215-
}
216-
217-
return implode( '<br/>', $output );
218-
}

free/classes/settings/class-secupress-settings.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ protected function field( $args ) {
886886
} elseif ( method_exists( $this, $args['type'] ) ) {
887887
call_user_func( array( $this, $args['type'] ), $args );
888888
} else {
889-
echo 'Missing or incorrect type'; // Do not translate.
889+
echo '<!--// Missing or incorrect type //-->'; // Do not translate.
890890
}
891891
}
892892

free/functions/files.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ function secupress_create_mu_plugin( $filename_part, $contents ) {
690690
* @return (string) The path with no heading slash and a trailing slash.
691691
*/
692692
function secupress_trailingslash_only( $slug ) {
693-
return ltrim( trim( $slug, '/' ) . '/', '/' );
693+
return ! is_null( $slug ) ? ltrim( trim( $slug, '/' ) . '/', '/' ) : '';
694694
}
695695

696696

free/functions/ip.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ function secupress_is_ip_in_range( $ip, $ips ) {
797797
$first_ip = str_replace( '0/255', '0', $mask );
798798
$last_ip = str_replace( '0/255', '255', $mask );
799799

800-
if ( secupress_ipv6_numeric( $ip ) >= secupress_ipv6_numeric( $first_ip ) && secupress_ipv6_numeric( $ip ) <= secupress_ipv6_numeric( $last_ip ) ) {
800+
if ( ip2long( $ip ) >= ip2long( $first_ip ) && ip2long( $ip ) <= ip2long( $last_ip ) ) {
801801
return true;
802802
}
803803
continue;

free/modules/antispam/callbacks.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function secupress_antispam_settings_callback( $settings ) {
3939
$settings['antispam_block-shortcodes'] = (int) ! empty( $settings['antispam_block-shortcodes'] );
4040
$settings['antispam_better-blacklist-comment'] = (int) ! empty( $settings['antispam_better-blacklist-comment'] );
4141
$settings['antispam_forbid-pings-trackbacks'] = (int) ! empty( $settings['antispam_forbid-pings-trackbacks'] );
42+
$settings['antispam_comment-delay'] = (int) ! empty( $settings['antispam_comment-delay'] );
4243

4344
/**
4445
* Filter the settings before saving.

free/modules/antispam/plugins/fightspam.php

+146-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function secupress_fightspam_blacklist_as_spam_check( $approved, $commentdata )
314314
}
315315

316316
// Test.
317-
if ( wp_blacklist_check(
317+
if ( wp_check_comment_disallowed_list(
318318
$commentdata['comment_author'],
319319
$commentdata['comment_author_email'],
320320
$commentdata['comment_author_url'],
@@ -758,3 +758,148 @@ function secupress_fightspam_get_spam_status( $value ) {
758758

759759
return $status;
760760
}
761+
762+
add_action( 'wp_footer', 'secupress_fightspam_dont_comment_too_soon_timer' );
763+
/**
764+
* Add a timer to change and disabled the submit button on the comment form
765+
*
766+
* @author Julio Potier
767+
* @since 2.3
768+
**/
769+
function secupress_fightspam_dont_comment_too_soon_timer() {
770+
// Do not do it if the setting is not set
771+
if ( ! secupress_get_module_option( 'antispam_comment-delay', 1, 'antispam' ) ) {
772+
return;
773+
}
774+
// Only do this if we are on a post type page which supports comments with a non logged in user
775+
if ( is_user_logged_in() || ! get_post_type() || ! post_type_supports( get_post_type(), 'comments' ) ) {
776+
return;
777+
}
778+
// Set our timer in PHP with a filter
779+
/**
780+
* Filter the default timer, 30 by default
781+
*/
782+
$secupress_dcts_timer = (int) apply_filters( 'secupress.plugins.fightspam.comment_timer', 30 );
783+
// Just check if it's correct (>0)
784+
if ( $secupress_dcts_timer <= 0 ) {
785+
return;
786+
}
787+
// Get the 2 filtered IDs for the form
788+
$comment_form_defaults = [ 'id_form' => 'commentform', 'id_submit' => 'submit' ];
789+
$comment_form_defaults = wp_parse_args( $comment_form_defaults, apply_filters( 'comment_form_defaults', $comment_form_defaults ) );
790+
?>
791+
<script>
792+
//<![CDATA[
793+
// Get the submit from the WP comment form
794+
var secupress_dcts_submit = document.getElementById('<?php echo esc_js( $comment_form_defaults['id_form'] ); ?>').querySelectorAll('#<?php echo esc_js( $comment_form_defaults['id_submit'] ); ?>');
795+
// If there is not, bail.
796+
if ( secupress_dcts_submit.length ) {
797+
// Get the button label
798+
var secupress_dcts_submit_value = secupress_dcts_submit[0].value;
799+
// Set our timer in JS from our filter
800+
var secupress_dcts_timer = <?php echo esc_js( $secupress_dcts_timer ); ?>;
801+
// Disable the button and make it alpha 50%
802+
secupress_dcts_submit[0].setAttribute("disabled", "");
803+
secupress_dcts_submit[0].style.opacity = 0.5;
804+
// Change the label to include the timer at max value
805+
secupress_dcts_submit[0].value = secupress_dcts_submit[0].value + ' (' + secupress_dcts_timer + ')';
806+
// Every second, reduce the timer by 1 and print it in the button
807+
secupress_dcts_submit_interval = setInterval(
808+
function() {
809+
secupress_dcts_timer--;
810+
secupress_dcts_submit[0].value = secupress_dcts_submit_value + ' (' + secupress_dcts_timer + ')';
811+
},
812+
1000 );
813+
// When the timer is done, rset the label, alpha, disabled status of the button
814+
setTimeout(
815+
function() {
816+
clearInterval( secupress_dcts_submit_interval );
817+
secupress_dcts_submit[0].value = secupress_dcts_submit_value;
818+
secupress_dcts_submit[0].removeAttribute("disabled");
819+
secupress_dcts_submit[0].style.opacity = 1;
820+
},
821+
secupress_dcts_timer * 1000 );
822+
823+
var xmlhttp = new XMLHttpRequest();
824+
// Do the AJAX request, vanilla style
825+
xmlhttp.onreadystatechange = function() {
826+
if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4
827+
if (xmlhttp.status == 200) {
828+
document.getElementById("secupress_dcts_timer").value = xmlhttp.responseText;
829+
}
830+
}
831+
};
832+
833+
xmlhttp.open("GET", "<?php echo esc_js( esc_url( admin_url( 'admin-ajax.php?action=secupress_dcts_timer' ) ) ); ?>", true);
834+
xmlhttp.send();
835+
}
836+
//]]>
837+
</script>
838+
<?php
839+
}
840+
841+
add_action( 'comment_form_top', 'secupress_fightspam_dont_comment_too_soon_field' );
842+
/**
843+
* Add our field at the top of the form
844+
*
845+
* @since 2.3
846+
* @author Julio Potier
847+
**/
848+
function secupress_fightspam_dont_comment_too_soon_field() {
849+
// Do not do it if the setting is not set
850+
if ( ! secupress_get_module_option( 'antispam_comment-delay', 1, 'antispam' ) ) {
851+
return;
852+
}
853+
// Trust the logged in users.
854+
if ( is_user_logged_in() ) {
855+
return;
856+
}
857+
// Our timer field
858+
echo '<input type="hidden" name="secupress_dcts_timer" id="secupress_dcts_timer" value="' . time() . '" />';
859+
}
860+
861+
add_action( 'pre_comment_on_post', 'secupress_fightspam_dont_comment_too_soon_check', 9 );
862+
/**
863+
* Early block the comment if the timer is too short
864+
*
865+
* @author Julio Potier
866+
* @return void
867+
**/
868+
function secupress_fightspam_dont_comment_too_soon_check() {
869+
// Do not do it if the setting is not set
870+
if ( ! secupress_get_module_option( 'antispam_comment-delay', 1, 'antispam' ) ) {
871+
return;
872+
}
873+
// Trust the logged in users.
874+
if ( is_user_logged_in() ) {
875+
return;
876+
}
877+
/**
878+
* Filter the deffault timer, 30 by default
879+
*/
880+
$secupress_dcts_timer = (int) apply_filters( 'secupress.plugins.fightspam.comment_timer', 30 );
881+
// Bad timer? Bail!
882+
if ( $secupress_dcts_timer <= 0 ) {
883+
return;
884+
}
885+
// Timer is too short, block!
886+
if ( ! isset( $_POST['secupress_dcts_timer'] ) || ( time() - $_POST['secupress_dcts_timer'] ) < ( $secupress_dcts_timer + 1 ) ) { // +1sec because of page load + AJAX call.
887+
secupress_block( 'ATS', __( 'Sorry, you cannot send that now.', 'secupress' ) );
888+
}
889+
}
890+
891+
add_action( 'wp_ajax_nopriv_secupress_dcts_timer', 'secupress_dcts_timer_cb' );
892+
/**
893+
* Get a timer with AJAX
894+
*
895+
* @author Julio Potier
896+
* @since 2.3
897+
**/
898+
function secupress_dcts_timer_cb() {
899+
// Do not do it if the setting is not set
900+
if ( ! secupress_get_module_option( 'antispam_comment-delay', 1, 'antispam' ) ) {
901+
return;
902+
}
903+
echo time();
904+
die();
905+
}

free/modules/antispam/settings/antispam.php

+16
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,19 @@
118118
),
119119
),
120120
) );
121+
122+
$this->add_field( array(
123+
'title' => __( 'Delay before posting a comment', 'secupress' ),
124+
'description' => __( 'A human has to read the post then write a comment before posting. Let them wait 30 secondes before posting.', 'secupress' ),
125+
'depends' => $main_field_name,
126+
'label_for' => $this->get_field_name( 'comment-delay' ),
127+
'type' => 'checkbox',
128+
'default' => 1,
129+
'label' => __( '<strong>Wait 30 seconds</strong> before posting a comment', 'secupress' ),
130+
'helpers' => array(
131+
array(
132+
'type' => 'description',
133+
'description' => __( 'If someone tries to post before that, we consider it a bot and block it.', 'secupress' ),
134+
),
135+
),
136+
) );

free/modules/firewall/tools.php

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function secupress_block_bad_content_but_what( $function, $server, $block_id ) {
117117
/**
118118
* Translate block IDs into understandable things.
119119
*
120+
* @since 2.3 ATS
120121
* @since 2.1 NOUSER
121122
* @since 2.0 BRU
122123
* @since 1.4.9 BHC, BRC
@@ -132,6 +133,7 @@ function secupress_firewall_block_id( $module ) {
132133
$block_ids = array(
133134
// Antispam.
134135
'AAU' => __( 'Antispam, Anti-Usurpation', 'secupress' ),
136+
'ATS' => __( 'Antispam, Too soon', 'secupress' ),
135137
// Firewall.
136138
'BRU' => __( 'Bad Referer URL', 'secupress' ),
137139
// URL Contents.

free/modules/users-login/settings/blacklist-logins.php

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
[ 'type' => 'warning', 'description' => $is_plugin_active ? __( 'You have to deactivate the module first to change the default role.', 'secupress' ) : '', ],
7575
]
7676
) );
77+
$this->add_field( array(
78+
'type' => 'html',
79+
'value' => $is_plugin_active ? '<input type="hidden" name="secupress_users-login_settings[blacklist-logins_default-role]" value="' . esc_attr( get_option( 'default_role' ) ) . '" ' . disabled( $is_plugin_active, false, false ) . '/>' : '',
80+
) );
7781

7882
$usable = get_option( 'users_can_register' );
7983
$main_field_name = $this->get_field_name( 'membership-activated' );

languages/secupress-fr_FR.mo

219 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)