forked from Sophia/better-yourls-blacklist-domains
Compare commits
3 Commits
5247655a50
...
7ea141cc23
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ea141cc23 | ||
|
|
fa220e0470 | ||
|
|
bd050d27c4 |
@@ -8,7 +8,7 @@ This plugin is intended to be used with YOURLS (cf. <https://yourls.org>)
|
|||||||
|
|
||||||
It has been tested on YOURLS v1.9.2 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 :**
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ Also thanks to [LudoBoggio](https://github.com/LudoBoggio) for the [YourlsBlackl
|
|||||||
|
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
v0.07 Maingron added regex support
|
||||||
v0.06 Alphabetize the blacklist
|
v0.06 Alphabetize the blacklist
|
||||||
v0.05 Fix all links being blocked
|
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
|
||||||
|
|||||||
33
plugin.php
33
plugin.php
@@ -45,13 +45,20 @@ 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
|
||||||
|
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';
|
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
|
||||||
if ( preg_match( $pattern, $domain ) ) {
|
if ( preg_match( $pattern, $domain ) ) {
|
||||||
return blacklist_fail_response();
|
return blacklist_fail_response();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// No match, allow the URL
|
// No match, allow the URL
|
||||||
return $shunt;
|
return $shunt;
|
||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user