diff --git a/README.md b/README.md index 356526c..30c829f 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,20 @@ -YourlsBlacklistIPs +YourlsWhiteListDomains -Plugin for Yourls allowing to blacklist IPs +Plugin for Yourls allowing only whitelisted domains This plugin is intended to be used with YOURLS (cf. http://yourls.org) It has been tested on YOURLS v1.5 and v1.5.1 -Current version is 1.1, updated on 09/03/2012 +Current version is 1.0 -Contact : Ludo at Ludo.Boggio+GitHub@GMail.com +Contact : panthro.rafael@gmail.com INSTALL : -- In /user/plugins, create a new folder named BlackListIP +- In /user/plugins, create a new folder named whitelist-domains - In this new directory, copy the plugin.php file from this repository - Go to the Plugins administration page and activate the plugin -You will see in the admin section a new admin page where you can add the IP addresses you want to blacklist. +You will see in the admin section a new admin page where you can add the domain addresses to the whitelist. -Please enter one IP address per line. Other syntax should provide unexpected behaviours. - -Roadmap contains the possibility to use regexp to specify the IP addresses. No, no date provided :) +Enter one domain in each line, please, remove the www when adding a new domain, the code works on both. diff --git a/plugin.php b/plugin.php index 8044a8c..5f901e0 100644 --- a/plugin.php +++ b/plugin.php @@ -1,69 +1,73 @@ Your IP has been blacklisted."; - die(); +// Get whitelisted domains from YOURLS options feature and compare with current domain address +function panthro_whitelist_domain_root ( $bol, $url ) { + $parse = parse_url($url); + $domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST)); + $return = false; + $domain_list = yourls_get_option ('panthro_whitelist_domain_list'); + if ( $domain_list ) { + $domain_list_display = unserialize ( $domain_list ); + //if (!in_array($domain, $domain_list_display)) { + if (strpos($domain_list_display,$domain) === false) { + $return['status'] = 'fail'; + $return['code'] = 'error:domain-not-allowed'; + $return['message'] = 'This domain is not allowed'; + $return['errorCode'] = '400'; } } + return $return; } // Add admin page -function ludo_blacklist_ip_add_page () { - yourls_register_plugin_page( 'ludo_blacklist_ip', 'Blacklist IPs', 'ludo_blacklist_ip_do_page' ); +function panthro_whitelist_domain_add_page () { + yourls_register_plugin_page( 'panthro_whitelist_domain', 'Whitelist domains', 'panthro_whitelist_domain_do_page' ); } // Display admin page -function ludo_blacklist_ip_do_page () { - if( isset( $_POST['action'] ) && $_POST['action'] == 'blacklist_ip' ) { - ludo_blacklist_ip_process (); +function panthro_whitelist_domain_do_page () { + if( isset( $_POST['action'] ) && $_POST['action'] == 'whitelist_domain' ) { + panthro_whitelist_domain_process (); } else { - ludo_blacklist_ip_form (); + panthro_whitelist_domain_form (); } } -// Display form to administrate blacklisted IPs list -function ludo_blacklist_ip_form () { - $nonce = yourls_create_nonce( 'blacklist_ip' ) ; - $liste_ip = yourls_get_option ('ludo_blacklist_ip_liste','Enter IP addresses here, one per line'); - if ($liste_ip != 'Enter IP addresses here, one per line' ) - $liste_ip_display = implode ( "\n" , unserialize ( $liste_ip ) ); +// Display form to administrate whitelisted domains list +function panthro_whitelist_domain_form () { + $nonce = yourls_create_nonce( 'whitelist_domain' ) ; + $domain_list = yourls_get_option ('panthro_whitelist_domain_list','Enter domain addresses here, one per line'); + if ($domain_list != 'Enter domain addresses here, one per line' ){ + $domain_list_display = unserialize ( $domain_list ); + }else{ + $domain_list_display = $domain_list; + } echo << BlackList IPs +