From bd050d27c445a597800fed508a4f11784b1254d0 Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:11:39 +0200 Subject: [PATCH 1/6] Add possible regex handling --- plugin.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugin.php b/plugin.php index b557ce7..8d6366d 100644 --- a/plugin.php +++ b/plugin.php @@ -45,10 +45,17 @@ 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 - $pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i'; - if ( preg_match( $pattern, $domain ) ) { - return blacklist_fail_response(); + // 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(); + } } } } @@ -126,4 +133,4 @@ function better_blacklist_process_form() { } echo ""; } -} \ No newline at end of file +} -- 2.49.1 From fa220e04707e5fc6deb5d8c08f673ba0bd4e6751 Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:22:31 +0200 Subject: [PATCH 2/6] Add regex docs to plugin.php page --- plugin.php | 256 +++++++++++++++++++++++++++++------------------------ 1 file changed, 139 insertions(+), 117 deletions(-) diff --git a/plugin.php b/plugin.php index 8d6366d..a67e73d 100644 --- a/plugin.php +++ b/plugin.php @@ -1,136 +1,158 @@ - 'fail', - 'code' => 'error:url', - 'message' => 'This domain is blacklisted', - 'errorCode' => '403', - ); -} - -// Add admin page to handle blacklist management -function better_blacklist_add_admin_page() { - yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); -} - -// Display the blacklist admin page -function better_blacklist_admin_page() { - if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'blacklist_domain' ) { - better_blacklist_process_form(); - } else { - better_blacklist_display_form(); - } -} - -// Display the form to update the blacklist -function better_blacklist_display_form() { - $nonce = yourls_create_nonce( 'blacklist_domain' ); - $blacklist_domains = yourls_get_option( 'better_blacklist_domain_list', 'Enter domain addresses here, one per line' ); - - if ( $blacklist_domains !== 'Enter domain addresses here, one per line' ) { - $blacklist_domains = implode( "\r\n", unserialize( $blacklist_domains ) ); + // Return failure response for blacklisted URLs + function blacklist_fail_response() { + return array( + 'status' => 'fail', + 'code' => 'error:url', + 'message' => 'This domain is blacklisted', + 'errorCode' => '403', + ); } - echo <<Blacklist Domains -
- - -

Enter domains to blacklist (one per line):

- -

-
-HTML; -} + // Add admin page to handle blacklist management + function better_blacklist_add_admin_page() { + yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); + } -// Process the blacklist form submission -function better_blacklist_process_form() { - // Verify nonce for security - yourls_verify_nonce( 'blacklist_domain' ); - - // Sanitize and process the form input - $blacklist_form = array_filter( array_map( 'trim', explode( "\r\n", $_POST['blacklist_form'] ) ) ); - - // Alphabetize the blacklist - sort($blacklist_form, SORT_STRING | SORT_FLAG_CASE); - - // Update the option with serialized data - yourls_update_option( 'better_blacklist_domain_list', serialize( $blacklist_form ) ); - - echo "

Blacklist updated!

"; - if ( empty( $blacklist_form ) ) { - echo "

The blacklist is currently empty.

"; - } else { - echo "

Current blacklisted domains:

"; } -} -- 2.49.1 From 7ea141cc239420ec5832319faaf80b80f5ce501f Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:24:06 +0200 Subject: [PATCH 3/6] Update Readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0123222..bf67549 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This plugin is intended to be used with YOURLS (cf. ) It has been tested on YOURLS v1.9.2 and YourlsBlacklistIPs v1.3 -Current version is 0.04 +Current version is 0.07 **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.05 Fix all links being blocked v0.04 Fix https and not both https and http blocking -- 2.49.1 From b4c196292c71cf436a0a3902c3131d9e98c03f9e Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:29:43 +0200 Subject: [PATCH 4/6] Fix missing line breaks in Readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf67549..9cfc050 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ Also thanks to [LudoBoggio](https://github.com/LudoBoggio) for the [YourlsBlackl --------- -v0.07 Maingron added regex support -v0.06 Alphabetize the blacklist -v0.05 Fix all links being blocked +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 v0.03 Fix some crap code (of mine) v0.02 Cosmetic changes -- 2.49.1 From 7235f4d8bce9095623ef6cfa7d844e87fdd8e2a9 Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:32:14 +0200 Subject: [PATCH 5/6] Fix typo in Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cfc050..92e629e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ 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 -- 2.49.1 From 764b858de6caaf397e675f8e04255d03f70ee18b Mon Sep 17 00:00:00 2001 From: Maingron Date: Sat, 13 Sep 2025 02:35:18 +0200 Subject: [PATCH 6/6] Bump version in plugin.php and remove tabs that someone put there by sleeping on the keyboard, I guess. whoops --- plugin.php | 278 ++++++++++++++++++++++++++--------------------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/plugin.php b/plugin.php index a67e73d..c70bf41 100644 --- a/plugin.php +++ b/plugin.php @@ -1,158 +1,158 @@ - 'fail', - 'code' => 'error:url', - 'message' => 'This domain is blacklisted', - 'errorCode' => '403', - ); + // No match, allow the URL + return $shunt; +} + +// Return failure response for blacklisted URLs +function blacklist_fail_response() { + return array( + 'status' => 'fail', + 'code' => 'error:url', + 'message' => 'This domain is blacklisted', + 'errorCode' => '403', + ); +} + +// Add admin page to handle blacklist management +function better_blacklist_add_admin_page() { + yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); +} + +// Display the blacklist admin page +function better_blacklist_admin_page() { + if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'blacklist_domain' ) { + better_blacklist_process_form(); + } else { + better_blacklist_display_form(); + } +} + +// Display the form to update the blacklist +function better_blacklist_display_form() { + $nonce = yourls_create_nonce( 'blacklist_domain' ); + $blacklist_domains = yourls_get_option( 'better_blacklist_domain_list', 'Enter domain addresses here, one per line' ); + + if ( $blacklist_domains !== 'Enter domain addresses here, one per line' ) { + $blacklist_domains = implode( "\r\n", unserialize( $blacklist_domains ) ); } - // Add admin page to handle blacklist management - function better_blacklist_add_admin_page() { - yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); - } + echo <<Blacklist Domains +
+ + +

Enter domains to blacklist (one per line):

- // Display the blacklist admin page - function better_blacklist_admin_page() { - if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'blacklist_domain' ) { - better_blacklist_process_form(); - } else { - better_blacklist_display_form(); - } - } - - // Display the form to update the blacklist - function better_blacklist_display_form() { - $nonce = yourls_create_nonce( 'blacklist_domain' ); - $blacklist_domains = yourls_get_option( 'better_blacklist_domain_list', 'Enter domain addresses here, one per line' ); - - if ( $blacklist_domains !== 'Enter domain addresses here, one per line' ) { - $blacklist_domains = implode( "\r\n", unserialize( $blacklist_domains ) ); - } - - echo <<Blacklist Domains - - - -

Enter domains to blacklist (one per line):

- -
- Advanced Usage (Regex) -
-

- You can use regular expressions (Regex) to define more complex patterns for blacklisting domains.
- To use Regex, enter your pattern between slashes (/).
- - For example, to block all subdomains of example.com, you could enter /\.example\.com$/i.
- The i flag at the end makes the match case-insensitive. Usually you want to use this flag. -

- -

- Further examples:
- /.*\.xxx$/i - Blocks all domains ending with .xxx
-
- - Be cautious when using Regex, as incorrect patterns can lead to unintended blocking of domains.
- Always test your Regex patterns to ensure they work as expected. -

-
-

- -

-
- HTML; - } - - // Process the blacklist form submission - function better_blacklist_process_form() { - // Verify nonce for security - yourls_verify_nonce( 'blacklist_domain' ); - - // Sanitize and process the form input - $blacklist_form = array_filter( array_map( 'trim', explode( "\r\n", $_POST['blacklist_form'] ) ) ); - - // Alphabetize the blacklist - sort($blacklist_form, SORT_STRING | SORT_FLAG_CASE); - - // Update the option with serialized data - yourls_update_option( 'better_blacklist_domain_list', serialize( $blacklist_form ) ); - - echo "

Blacklist updated!

"; - if ( empty( $blacklist_form ) ) { - echo "

The blacklist is currently empty.

"; - } else { - echo "

Current blacklisted domains:

    "; - foreach ( $blacklist_form as $domain ) { - echo "
  • " . htmlspecialchars($domain, ENT_QUOTES) . "
  • "; - } - echo "
"; +
+ Advanced Usage (Regex) +
+

+ You can use regular expressions (Regex) to define more complex patterns for blacklisting domains.
+ To use Regex, enter your pattern between slashes (/).
+ + For example, to block all subdomains of example.com, you could enter /\.example\.com$/i.
+ The i flag at the end makes the match case-insensitive. Usually you want to use this flag. +

+ +

+ Further examples:
+ /.*\.xxx$/i - Blocks all domains ending with .xxx
+
+ + Be cautious when using Regex, as incorrect patterns can lead to unintended blocking of domains.
+ Always test your Regex patterns to ensure they work as expected. +

+
+

+ +

+ +HTML; +} + +// Process the blacklist form submission +function better_blacklist_process_form() { + // Verify nonce for security + yourls_verify_nonce( 'blacklist_domain' ); + + // Sanitize and process the form input + $blacklist_form = array_filter( array_map( 'trim', explode( "\r\n", $_POST['blacklist_form'] ) ) ); + + // Alphabetize the blacklist + sort($blacklist_form, SORT_STRING | SORT_FLAG_CASE); + + // Update the option with serialized data + yourls_update_option( 'better_blacklist_domain_list', serialize( $blacklist_form ) ); + + echo "

Blacklist updated!

"; + if ( empty( $blacklist_form ) ) { + echo "

The blacklist is currently empty.

"; + } else { + echo "

Current blacklisted domains:

    "; + foreach ( $blacklist_form as $domain ) { + echo "
  • " . htmlspecialchars($domain, ENT_QUOTES) . "
  • "; } + echo "
"; } +} -- 2.49.1