fixed all links being blocked

This commit is contained in:
2024-09-27 00:27:15 -07:00
parent 915d7a4f75
commit daf1e7f4ef
2 changed files with 11 additions and 3 deletions

View File

@ -41,6 +41,7 @@ Also thanks to [LudoBoggio](https://github.com/LudoBoggio) for the [YourlsBlackl
---------
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

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.04
Version: 0.05
Author: Sophia Atkinson
Author URI: https://sophia.wtf
Original Author: apelly
@ -23,11 +23,18 @@ yourls_add_action( 'plugins_loaded', 'better_blacklist_add_admin_page' );
function better_blacklist_domain_check( $shunt, $url ) {
// Parse the URL and extract the host
$parsed_url = parse_url( $url );
$domain = $parsed_url['host'] ?? '';
// If parsing fails or host is empty, deny the URL
if (empty($parsed_url['host'])) {
return blacklist_fail_response();
}
$domain = $parsed_url['host'];
// Block if using blacklisted protocols
if ( isset($parsed_url['scheme']) && in_array( $parsed_url['scheme'], ['http', 'https'], true ) ) {
return blacklist_fail_response();
// Instead of blocking here, we return the original shunt
// to avoid blocking all URLs with blacklisted protocols
}
// Retrieve blacklisted domains from options