Skip to content

Commit

Permalink
Rework & reword
Browse files Browse the repository at this point in the history
  • Loading branch information
ozh committed Apr 25, 2022
1 parent 1a913f5 commit 75bf208
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
34 changes: 18 additions & 16 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/*
Plugin Name: Anti spam
Plugin URI: http://yourls.org/
Description: Absolute anti-spam plugin. Checks URL against major black lists and removes all crap. Might OR MIGHT NOT work for you. Read the readme.
Version: 1.0.4
Description: Checks URL against DNS blacklists. Might OR MIGHT NOT work for you. Read the readme.
Version: 1.1
Author: Ozh
Author URI: http://ozh.org/
*/
Expand All @@ -27,7 +27,7 @@ function ozh_yourls_antispam_check_add( $false, $url ) {
'errorCode' => '400',
);
}

if ( ozh_yourls_antispam_is_blacklisted( $url ) != false ) {
return array(
'status' => 'fail',
Expand All @@ -36,7 +36,7 @@ function ozh_yourls_antispam_check_add( $false, $url ) {
'errorCode' => '403',
);
}

// All clear, not interrupting the normal flow of events
return $false;
}
Expand All @@ -45,20 +45,20 @@ function ozh_yourls_antispam_check_add( $false, $url ) {
// Has the remote link become compromised lately? Check on redirection
yourls_add_action( 'redirect_shorturl', 'ozh_yourls_antispam_check_redirect' );
function ozh_yourls_antispam_check_redirect( $url, $keyword = false ) {

if( is_array( $url ) && $keyword == false ) {
$keyword = $url[1];
$url = $url[0];
}

// Check when the link was added
// If shorturl is fresh (ie probably clicked more often?) check once every 15 times, otherwise once every 5 times
// Define fresh = 3 days = 259200 secondes
// TODO: when there's a shorturl_meta table, store last check date to allow checking every 2 or 3 days
$now = date( 'U' );
$then = date( 'U', strtotime( yourls_get_keyword_timestamp( $keyword ) ) );
$chances = ( ( $now - $then ) > 259200 ? 15 : 5 );

if( $chances == mt_rand( 1, $chances ) ) {
if( ozh_yourls_antispam_is_blacklisted( $url ) != false ) {
// Delete link & die
Expand All @@ -75,30 +75,32 @@ function ozh_yourls_antispam_check_redirect( $url, $keyword = false ) {
// Is the link spam? true for "yes it's shit", false for "nope, safe"
function ozh_yourls_antispam_is_blacklisted( $url ) {
$parsed = parse_url( $url );

if( !isset( $parsed['host'] ) )
return yourls_apply_filter( 'ozh_yourls_antispam_malformed', 'malformed' );

// Remove www. from domain (but not from www.com)
$parsed['host'] = preg_replace( '/^www\.(.+\.)/i', '$1', $parsed['host'] );

// Major blacklists. There's a filter if you want to manipulate this.
$blacklists = yourls_apply_filter( 'ozh_yourls_antispam_list',
array(
'dbl.spamhaus.org',
'multi.surbl.org',
)
'zen.spamhaus.org',
'multi.surbl.org',
'bl.spamcop.net',
'combined.abuse.ch',
'dnsbl.sorbs.net', )
);

// Check against each blacklist, exit if blacklisted
foreach( $blacklists as $blacklist ) {
$domain = $parsed['host'] . '.' . $blacklist . '.';
$record = @dns_get_record( $domain );

if( $record && count( $record ) > 0 )
return yourls_apply_filter( 'ozh_yourls_antispam_blacklisted', true );
}

// All clear, probably not spam
return yourls_apply_filter( 'ozh_yourls_antispam_clean', false );
}
27 changes: 19 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
Plugin for YOURLS 1.5+: Antispam
# Plugin for YOURLS 1.5+: Antispam

# What for
## What for

This is a __merciless__ __antispam__ plugin that uses the three major blacklists (<a href="http://spamhaus.org">Spamhaus</a>, <a href="http://uribl.com/">URIBL</a> and <a href="http://surbl.org/">SURBL</a>).
This is an antispam plugin that uses major DNS blacklists to detect spam, at link creation time and at visit time :

URL are checked against the blacklist when short urls are created. They are also randomly checked when someone follows a short
URL and if the link has been compromised recently, the short URL is deleted.
- URL are checked against the blacklist when short urls are created.
- They are also randomly checked when someone follows a short URL and if the link has been compromised recently, the
short URL is deleted.

# How to
DNS backlists used: `zen.spamhaus.org`, `multi.surbl.org`, `bl.spamcop.net`, `combined.abuse.ch`, `dnsbl.sorbs.net`.

## How to

* In `/user/plugins`, create a new folder named `antispam`
* Drop these files in that directory
* Go to the Plugins administration page and activate the plugin
* Have fun

# Disclaimer
## Disclaimer - please read

Checking against DNS blacklists may or may not work for you, this may depend on the type of spam you are getting and on
other factors such as your server IP, your server ISP, the DNS you are using. It may even result in all domains being
blacklisted from your server. Try and see.

If you're not sure what DNS blacklists are, you can check out the [DNSBLs list](https://www.dnsbl.info/).

Checking against blacklists may or may not work for you, this may depend on the type of spam you are getting and on other factors such as your server IP, your server ISP, the DNS you are using. It may even result in all domains being blacklisted from your server. Try and see.
If you're still not sure this plugin is for you, we recommend you use another plugin, such as
[Google Safe Browsing](https://github.com/YOURLS/google-safe-browsing), or a plugin that will add a captcha to your
public interface -- see the plugin list at https://github.com/YOURLS/awesome-yourls.

0 comments on commit 75bf208

Please sign in to comment.