@ayende You ought to try Mercurial. in reply to ayende 1 week ago

The Three Strikes and You’re Out API

One feature of Three Strikes And You’re Out is that it includes a couple of hooks and an internal log which allows other plugins to add their own rules, such as logging failed captcha attempts or implementing a blacklist or whitelist. There are two hooks which allow you to do this: an action, three_strikes, and a filter, three_strikes_count.Because these are implemented as hooks, plugins that use them will normally function correctly if you do not have Three Strikes And You’re Out installed.

three_strikes

This is an action which adds an event to the strike log. To use it in your plugin, you need to add a simple method call:

do_action('three_strikes', $source, $message);

where $source is the name of your plugin and $message is a short message indicating what happened. These values should be strings up to 100 characters long; if they are longer than this they will be truncated.

three_strikes_count

This is a filter which allows you to manipulate the hit count, for example, to implement whitelists or blacklists. Your filter should receive two arguments: the original count and the IP address, and it should return the updated count.

Because it takes two arguments, you will need to specify this explicitly in your add_filter declaration:

add_filter('three_strikes_count', 'my_filter', 10, 2);

The following example would allow you to implement a comment blacklist and a whitelist:

// Make sure this filter runs after all other filters
add_filter('three_strikes_count', 'three_strikes_blacklist_and_whitelist', 1000, 2);

function three_strikes_blacklist_and_whitelist($count, $ip)
{
    //implementing is_on_blacklist and is_on_whitelist are left
    //as an exercise for the reader
    if (is_on_blacklist($ip)) {
        return THREE_STRIKES_LIMIT;
    }
    elseif (is_on_whitelist($ip)) {
        return 0;
    }
    else {
        return $count;
    }
}

Comments

RSS feed for comments on this entryAdd your comments



(Personal blogs only please: leave blank if you don't have one)

Your comments:

-) razz mad lol cool ??? shock sad smile

Maximum 2 links per comment. Do not use BBCode.