forked from Sophia/better-yourls-blacklist-domains
Compare commits
4 Commits
7ea141cc23
...
0.07
| Author | SHA1 | Date | |
|---|---|---|---|
| 66c68b3586 | |||
|
|
764b858de6 | ||
|
|
7235f4d8bc | ||
|
|
b4c196292c |
@@ -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
|
||||
|
||||
|
||||
72
plugin.php
72
plugin.php
@@ -1,26 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
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
|
||||
Author: Sophia Atkinson
|
||||
Author URI: https://sophia.wtf
|
||||
Original Author: apelly
|
||||
Original Author URI: http://len.io
|
||||
*/
|
||||
<?php
|
||||
/*
|
||||
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.07
|
||||
Author: Sophia Atkinson
|
||||
Author URI: https://sophia.wtf
|
||||
Original Author: apelly
|
||||
Original Author URI: http://len.io
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
if( !defined( 'YOURLS_ABSPATH' ) ) die();
|
||||
// No direct access
|
||||
if( !defined( 'YOURLS_ABSPATH' ) ) die();
|
||||
|
||||
// Hook the custom function into the 'shunt_add_new_link' event
|
||||
yourls_add_filter( 'shunt_add_new_link', 'better_blacklist_domain_check' );
|
||||
// Hook the custom function into the 'shunt_add_new_link' event
|
||||
yourls_add_filter( 'shunt_add_new_link', 'better_blacklist_domain_check' );
|
||||
|
||||
// Hook the admin page into the 'plugins_loaded' event
|
||||
yourls_add_action( 'plugins_loaded', 'better_blacklist_add_admin_page' );
|
||||
// Hook the admin page into the 'plugins_loaded' event
|
||||
yourls_add_action( 'plugins_loaded', 'better_blacklist_add_admin_page' );
|
||||
|
||||
// Function to check if a domain is blacklisted
|
||||
function better_blacklist_domain_check( $shunt, $url ) {
|
||||
// Function to check if a domain is blacklisted
|
||||
function better_blacklist_domain_check( $shunt, $url ) {
|
||||
// Parse the URL and extract the host
|
||||
$parsed_url = parse_url( $url );
|
||||
|
||||
@@ -62,34 +62,34 @@
|
||||
|
||||
// No match, allow the URL
|
||||
return $shunt;
|
||||
}
|
||||
}
|
||||
|
||||
// Return failure response for blacklisted URLs
|
||||
function blacklist_fail_response() {
|
||||
// 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() {
|
||||
// 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() {
|
||||
// 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() {
|
||||
// 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' );
|
||||
|
||||
@@ -128,11 +128,11 @@
|
||||
<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;
|
||||
}
|
||||
HTML;
|
||||
}
|
||||
|
||||
// Process the blacklist form submission
|
||||
function better_blacklist_process_form() {
|
||||
// Process the blacklist form submission
|
||||
function better_blacklist_process_form() {
|
||||
// Verify nonce for security
|
||||
yourls_verify_nonce( 'blacklist_domain' );
|
||||
|
||||
@@ -155,4 +155,4 @@
|
||||
}
|
||||
echo "</ul>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user