8 Commits
0.06 ... 0.07

Author SHA1 Message Date
66c68b3586 Merge pull request 'Regex support' (#1) from Maingron/better-yourls-blacklist-domains:master into master
Reviewed-on: #1
2025-09-12 22:36:09 -07:00
Maingron
764b858de6 Bump version in plugin.php and remove tabs that someone put there by sleeping on the keyboard, I guess. whoops 2025-09-13 02:35:18 +02:00
Maingron
7235f4d8bc Fix typo in Readme 2025-09-13 02:32:14 +02:00
Maingron
b4c196292c Fix missing line breaks in Readme 2025-09-13 02:29:43 +02:00
Maingron
7ea141cc23 Update Readme 2025-09-13 02:24:06 +02:00
Maingron
fa220e0470 Add regex docs to plugin.php page 2025-09-13 02:22:31 +02:00
Maingron
bd050d27c4 Add possible regex handling 2025-09-13 02:11:39 +02:00
5247655a50 fix tested version 2024-10-11 21:43:06 -07:00
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>) 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 :** **INSTALL :**
@@ -35,14 +35,15 @@ Thanks to [Panthro](https://github.com/Panthro) for [YourlsWhiteListDomains](htt
> You are free to fork whatever you want, that's what code is for! > 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. 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 ## Changelog
--------- ---------
v0.06 Alphabetize the blacklist v0.07 Maingron added regex support
v0.05 Fix all links being blocked v0.06 Alphabetize the blacklist
v0.05 Fix all links being blocked
v0.04 Fix https and not both https and http blocking v0.04 Fix https and not both https and http blocking
v0.03 Fix some crap code (of mine) v0.03 Fix some crap code (of mine)
v0.02 Cosmetic changes v0.02 Cosmetic changes

View File

@@ -3,7 +3,7 @@
Plugin Name: Better Yourls BlackList Domains Plugin Name: Better Yourls BlackList Domains
Plugin URI: https://git.oldgate.org/Sophia/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 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: Sophia Atkinson
Author URI: https://sophia.wtf Author URI: https://sophia.wtf
Original Author: apelly Original Author: apelly
@@ -45,10 +45,17 @@ function better_blacklist_domain_check( $shunt, $url ) {
$blacklisted_domains = unserialize( $blacklisted_domains ); $blacklisted_domains = unserialize( $blacklisted_domains );
foreach ( $blacklisted_domains as $blacklisted_domain ) { 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
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i'; if (strpos($blacklisted_domain, '/') === 0) {
if ( preg_match( $pattern, $domain ) ) { if (@preg_match($blacklisted_domain, $domain)) {
return blacklist_fail_response(); 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();
}
} }
} }
} }
@@ -96,7 +103,29 @@ function better_blacklist_display_form() {
<input type="hidden" name="action" value="blacklist_domain" /> <input type="hidden" name="action" value="blacklist_domain" />
<input type="hidden" name="nonce" value="$nonce" /> <input type="hidden" name="nonce" value="$nonce" />
<p>Enter domains to blacklist (one per line):</p> <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> <p><input type="submit" value="Save" /></p>
</form> </form>
HTML; HTML;
@@ -126,4 +155,4 @@ function better_blacklist_process_form() {
} }
echo "</ul>"; echo "</ul>";
} }
} }