8 Commits
0.06 ... 0.07

2 changed files with 42 additions and 12 deletions

View File

@@ -6,9 +6,9 @@ Plugin for Yourls that disallows blacklisted domains. Further, if YourlsBlacklis
This plugin is intended to be used with YOURLS (cf. <https://yourls.org>)
It has been tested on YOURLS v1.5.1 and YourlsBlacklistIPs v1.3
It has been tested on YOURLS v1.9.2 and YourlsBlacklistIPs v1.3
Current version is 0.04
Current version is 0.07
**INSTALL :**
@@ -35,12 +35,13 @@ Thanks to [Panthro](https://github.com/Panthro) for [YourlsWhiteListDomains](htt
> You are free to fork whatever you want, that's what code is for!
Also thanks to [LudoBoggio](https://github.com/LudoBoggio) for the [YourlsBlacklistIPs](https://github.com/LudoBoggio/YourlsBlacklistIPs) plugin which was the base for YourlsWhiteListDomains.
>I've written this plugin for the community, to help Yourls users, to help Yourls author, to help to spread this software, to pay my free use of it, and to learn a bit more of programming. I didn't provide any license informations because I never tried to understand them. Therefore, I leave you all rights to use my plugin in any way you want, the fact that it help to bring more Yourls user is just enough from my point of view.
> I've written this plugin for the community, to help Yourls users, to help Yourls author, to help to spread this software, to pay my free use of it, and to learn a bit more of programming. I didn't provide any license information because I never tried to understand them. Therefore, I leave you all rights to use my plugin in any way you want, the fact that it help to bring more Yourls user is just enough from my point of view.
## Changelog
---------
v0.07 Maingron added regex support
v0.06 Alphabetize the blacklist
v0.05 Fix all links being blocked
v0.04 Fix https and not both https and http blocking

View File

@@ -3,7 +3,7 @@
Plugin Name: Better Yourls BlackList Domains
Plugin URI: https://git.oldgate.org/Sophia/better-yourls-blacklist-domains
Description: Plugin which disallows blacklisted domains and bans the submitter's IP address. GPL v3
Version: 0.06
Version: 0.07
Author: Sophia Atkinson
Author URI: https://sophia.wtf
Original Author: apelly
@@ -45,13 +45,20 @@ function better_blacklist_domain_check( $shunt, $url ) {
$blacklisted_domains = unserialize( $blacklisted_domains );
foreach ( $blacklisted_domains as $blacklisted_domain ) {
// Use a regex to match the domain or subdomain
// Check if the entry starts with '/', then consider regex handling
if (strpos($blacklisted_domain, '/') === 0) {
if (@preg_match($blacklisted_domain, $domain)) {
return blacklist_fail_response();
}
} else {
// Otherwise treat as plain domain (old behavior)
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
if ( preg_match( $pattern, $domain ) ) {
return blacklist_fail_response();
}
}
}
}
// No match, allow the URL
return $shunt;
@@ -96,7 +103,29 @@ function better_blacklist_display_form() {
<input type="hidden" name="action" value="blacklist_domain" />
<input type="hidden" name="nonce" value="$nonce" />
<p>Enter domains to blacklist (one per line):</p>
<textarea class="blacklist-domains" cols="60" rows="15" name="blacklist_form">$blacklist_domains</textarea>
<details>
<summary>Advanced Usage (Regex)</summary>
<div>
<p>
You can use regular expressions (Regex) to define more complex patterns for blacklisting domains.<br>
To use Regex, enter your pattern between slashes (/).<br>
For example, to block all subdomains of example.com, you could enter <code>/\.example\.com$/i</code>.<br>
The <kbd>i</kbd> flag at the end makes the match case-insensitive. Usually you want to use this flag.
</p>
<p>
<b>Further examples:</b><br>
<code>/.*\.xxx$/i</code> - Blocks all domains ending with .xxx<br>
<br>
Be cautious when using Regex, as incorrect patterns can lead to unintended blocking of domains.<br>
Always test your Regex patterns to ensure they work as expected.
</p>
</div>
</details><br>
<textarea class="blacklist-domains" cols="60" rows="15" name="blacklist_form" placeholder="Example: block.example.com">$blacklist_domains</textarea>
<p><input type="submit" value="Save" /></p>
</form>
HTML;