WordPress.org

Ready to get started?Download WordPress

Forums

Bad Behavior
Lots of notices in 2.2 version (7 posts)

  1. GabSoftware
    Member
    Posted 3 years ago #

    Hi,

    First thank you for providing Bad Behavior, it's a wonderful plugin.

    I would like to report that the plugin throws a lot of notices in the wp-admin/tools.php?page=bb2_manage page.

    Here they are:

    Notice: Undefined index: paged in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 107
    Notice: Undefined index: key in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 108
    Notice: Undefined index: blocked in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 109
    Notice: Undefined index: permitted in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 110
    Notice: Undefined index: ip in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 111
    Notice: Undefined index: user_agent in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 112
    Notice: Undefined index: request_method in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 113
    Notice: Undefined index: key in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 151
    Notice: Undefined index: blocked in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 151
    Notice: Undefined index: key in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 152
    Notice: Undefined index: permitted in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 152
    Notice: Undefined index: httpbl in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 57
    (the last line appears many times)

    I know that notices can be turned off using error_reporting() but I think that fixing the cause of the notices is a better idea :)

    http://wordpress.org/extend/plugins/bad-behavior/

  2. GabSoftware
    Member
    Posted 3 years ago #

    Also while saving settings, I got the following:

    Notice: Undefined index: display_stats in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 218
    Notice: Undefined index: strict in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 223
    Notice: Undefined index: verbose in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 228
    Notice: Undefined index: offsite_forms in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 263
    Notice: Undefined index: reverse_proxy in /xxx/wp-content/plugins/bad-behavior/bad-behavior-wordpress-admin.php on line 268
  3. GabSoftware
    Member
    Posted 3 years ago #

    Also, warnings and notices were thrown on my blog frontend after defining in my wp-config.php:

    define( 'WP_DEBUG', TRUE );
    error_reporting( E_ALL | E_STRICT );
    ini_set('display_errors', 1);

    So I modified the file bad-behavior-wordpress.php.
    line 149:
    return ( isset( $url['path'] ) ? $url['path'] . '/' : '/' );

    line 167:
    if( ! isset( $_SESSION ) ) session_start();

    This got rid of the warnings and notices on my blog frontend.

  4. GabSoftware
    Member
    Posted 3 years ago #

    Fixed use of deprecated user levels in bad-behavior-wordpress-admin.php.

    Changed:

    line 22
    add_options_page(__("Bad Behavior"), __("Bad Behavior"), ( function_exists('current_user_can') ? 'manage_options' : 8 ), 'bb2_options', 'bb2_options');

    line 24
    add_management_page(__("Bad Behavior"), __("Bad Behavior"), ( function_exists('current_user_can') ? 'manage_options' : 8 ), 'bb2_manage', 'bb2_manage');

  5. GabSoftware
    Member
    Posted 3 years ago #

    Fixed lot of notices generated by the bb2_options() function:

    $request_uri =  ( isset( $_SERVER["REQUEST_URI"] ) ? $_SERVER["REQUEST_URI"] : false );
    if ( ! $request_uri ) $request_uri = $_SERVER['SCRIPT_NAME'];	# IIS
    
    if ( isset( $_POST ) ) {
    	if ( isset( $_POST['display_stats'] ) ) {
    		$settings['display_stats'] = true;
    	} else {
    		$settings['display_stats'] = false;
    	}
    	if ( isset( $_POST['strict'] ) ) {
    		$settings['strict'] = true;
    	} else {
    		$settings['strict'] = false;
    	}
    	if ( isset( $_POST['verbose'] ) ) {
    		$settings['verbose'] = true;
    	} else {
    		$settings['verbose'] = false;
    	}
    	if ( isset( $_POST['logging'] ) ) {
    		if ($_POST['logging'] == 'verbose') {
    			$settings['verbose'] = true;
    			$settings['logging'] = true;
    		} else if ($_POST['logging'] == 'normal') {
    			$settings['verbose'] = false;
    			$settings['logging'] = true;
    		} else {
    			$settings['verbose'] = false;
    			$settings['logging'] = false;
    		}
    	} else {
    		$settings['verbose'] = false;
    		$settings['logging'] = false;
    	}
    	if ( isset( $_POST['httpbl_key'] ) ) {
    		$settings['httpbl_key'] = $_POST['httpbl_key'];
    	} else {
    		$settings['httpbl_key'] = '';
    	}
    	if ( isset( $_POST['httpbl_threat'] ) ) {
    		$settings['httpbl_threat'] = $_POST['httpbl_threat'];
    	} else {
    		$settings['httpbl_threat'] = '25';
    	}
    	if ( isset( $_POST['httpbl_maxage'] ) ) {
    		$settings['httpbl_maxage'] = $_POST['httpbl_maxage'];
    	} else {
    		$settings['httpbl_maxage'] = '30';
    	}
    	if ( isset( $_POST['offsite_forms'] ) ) {
    		$settings['offsite_forms'] = true;
    	} else {
    		$settings['offsite_forms'] = false;
    	}
    	if ( isset( $_POST['reverse_proxy'] ) ) {
    		$settings['reverse_proxy'] = true;
    	} else {
    		$settings['reverse_proxy'] = false;
    	}
    	if ( isset( $_POST['reverse_proxy_header'] ) ) {
    		$settings['reverse_proxy_header'] = uc_all($_POST['reverse_proxy_header']);
    	} else {
    		$settings['reverse_proxy_header'] = 'X-Forwarded-For';
    	}
    	if ( isset( $_POST['reverse_proxy_addresses'] ) ) {
    		$settings['reverse_proxy_addresses'] = preg_split("/[\s,]+/m", $_POST['reverse_proxy_addresses']);
    	} else {
    		$settings['reverse_proxy_addresses'] = array();
    	}
    	bb2_write_settings($settings);

    Basically, please use isset() to test if a variable has been set. :)

  6. GabSoftware
    Member
    Posted 3 years ago #

    Changed the following lines in bad-behavior-wordpress-admin.php:

    line 57:
    $r = ( isset( $_SESSION['httpbl'] ) && isset( $_SESSION['httpbl'][$ip] ) ? $_SESSION['httpbl'][$ip] : false );

    lines 107~113:

    $paged = 0 + ( isset( $_GET['paged'] ) ? $_GET['paged'] : 0 ); if (!$paged) $paged = 1;
    if ( isset( $_GET['key'] ) ) $where .= "AND <code>key</code> = '" . $wpdb->escape($_GET['key']) . "' ";
    if ( isset( $_GET['blocked'] ) ) $where .= "AND <code>key</code> != '00000000' ";
    else if ( isset( $_GET['permitted'] ) ) $where .= "AND <code>key</code> = '00000000' ";
    if ( isset( $_GET['ip'] ) ) $where .= "AND <code>ip</code> = '" . $wpdb->escape($_GET['ip']) . "' ";
    if ( isset( $_GET['user_agent'] ) ) $where .= "AND <code>user_agent</code> = '" . $wpdb->escape($_GET['user_agent']) . "' ";
    if ( isset( $_GET['request_method'] ) ) $where .= "AND <code>request_method</code> = '" . $wpdb->escape($_GET['request_method']) . "' ";

    lines 142~152:

    <?php if ( isset( $_GET['key'] ) ) echo "Status [<a href=\"" . remove_query_arg(array("paged", "key"), $request_uri) . "\">X</a>] "; ?>
    <?php if ( isset( $_GET['blocked'] ) ) echo "Blocked [<a href=\"" . remove_query_arg(array("paged", "blocked", "permitted"), $request_uri) . "\">X</a>] "; ?>
    <?php if ( isset( $_GET['permitted'] ) ) echo "Permitted [<a href=\"" . remove_query_arg(array("paged", "blocked", "permitted"), $request_uri) . "\">X</a>] "; ?>
    <?php if ( isset( $_GET['ip'] ) ) echo "IP [<a href=\"" . remove_query_arg(array("paged", "ip"), $request_uri) . "\">X</a>] "; ?>
    <?php if ( isset( $_GET['user_agent'] ) ) echo "User Agent [<a href=\"" . remove_query_arg(array("paged", "user_agent"), $request_uri) . "\">X</a>] "; ?>
    <?php if ( isset( $_GET['request_method'] ) ) echo "GET/POST [<a href=\"" . remove_query_arg(array("paged", "request_method"), $request_uri) . "\">X</a>] "; ?>
    <?php else: ?>
    Displaying all <strong><?php echo $totalcount; ?></strong> records<br/>
    <?php endif; ?>
    <?php if (! isset( $_GET['key'] ) && ! isset( $_GET['blocked'] ) ) { ?><a href="<?php echo add_query_arg(array("blocked" => "1", "permitted" => "0", "paged" => false), $request_uri); ?>">Show Blocked</a> <?php } ?>
    <?php if (! isset( $_GET['key'] ) && ! isset( $_GET['permitted'] ) ) { ?><a href="<?php echo add_query_arg(array("permitted" => "1", "blocked" => "0", "paged" => false), $request_uri); ?>">Show Permitted</a> <?php } ?>

    Then only after all those modifications, the warnings and notices seem to be gone :)

  7. GabSoftware
    Member
    Posted 3 years ago #

    The author hasn't updated the plugin with the fixes in the new version. I have to modify everything by hand again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic