[5099] | 1 | <?php |
---|
| 2 | /* |
---|
[5162] | 3 | Plugin Name: History IP Excluder |
---|
[9882] | 4 | Version: 2.2.1 |
---|
[6760] | 5 | Description: Permet l'exclusion d'une IP ou d'une plage d'IP de l'historique et de les blacklister à l'inscription - Base MySql seulement! / Excludes one IP or a range of IP from the history and to blacklist them on registration - MySql database only! |
---|
[5099] | 6 | Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=147 |
---|
| 7 | Author: Nicco, Eric |
---|
| 8 | Author URI: http://gallery-nicco.no-ip.org - http://www.infernoweb.net |
---|
| 9 | */ |
---|
| 10 | |
---|
[5615] | 11 | /* |
---|
| 12 | :: HISTORY |
---|
| 13 | |
---|
| 14 | 1.0.x to 1.6.x - Plugin only for PWG 1.7.x |
---|
| 15 | |
---|
| 16 | 2.0.0 - Compliance with Piwigo 2.0.x |
---|
| 17 | |
---|
| 18 | 2.1.0 - Compliance with Piwigo 2.1.x |
---|
| 19 | - Multiple database support |
---|
| 20 | - Removing "nbc_" prefix in plugin code and display in piwigo's plugin manager |
---|
| 21 | - Displaying the good plugin name and current version in admin panel |
---|
[6758] | 22 | |
---|
| 23 | 2.1.1 - Bug 1792 fixed (Thx to TOnin) |
---|
| 24 | - Bug 1511 fixed - New function to blacklist excluded IPs or ranged IPs for registration |
---|
[5615] | 25 | |
---|
[9870] | 26 | 2.2.0 - Compliance with Piwigo 2.2.x |
---|
| 27 | - Plugin directory renamed from nbc_HistoryIPExcluder to HistoryIPExcluder |
---|
| 28 | |
---|
[9882] | 29 | 2.2.1 - Bug fixed on plugin upgrade from 2.1.x version |
---|
| 30 | |
---|
[5615] | 31 | -------------------------------------------------------------------------------- |
---|
| 32 | */ |
---|
| 33 | |
---|
[5099] | 34 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 35 | |
---|
| 36 | if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 37 | |
---|
[5615] | 38 | include_once (HIPE_PATH.'/include/functions.inc.php'); |
---|
| 39 | |
---|
[5099] | 40 | load_language('plugin.lang', HIPE_PATH); |
---|
| 41 | |
---|
| 42 | add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu'); |
---|
| 43 | |
---|
| 44 | /* Set the administration panel of the plugin */ |
---|
| 45 | function HIPE_admin_menu($menu) |
---|
| 46 | { |
---|
[5162] | 47 | // +-----------------------------------------------------------------------+ |
---|
| 48 | // | Getting plugin name | |
---|
| 49 | // +-----------------------------------------------------------------------+ |
---|
[5615] | 50 | $plugin = HIPE_infos(HIPE_PATH); |
---|
[5162] | 51 | $name = $plugin['name']; |
---|
| 52 | |
---|
[5099] | 53 | array_push($menu, |
---|
| 54 | array( |
---|
[5162] | 55 | 'NAME' => $name, |
---|
[9870] | 56 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(HIPE_PATH) |
---|
[5099] | 57 | ) |
---|
| 58 | ); |
---|
| 59 | |
---|
| 60 | return $menu; |
---|
| 61 | } |
---|
| 62 | |
---|
[9870] | 63 | // IP exclusion from logs |
---|
| 64 | add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer'); |
---|
[5099] | 65 | |
---|
| 66 | function HIPE_IP_Filtrer($do_log) |
---|
| 67 | { |
---|
| 68 | global $conf; |
---|
| 69 | |
---|
[5162] | 70 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
[5099] | 71 | |
---|
[5113] | 72 | if (!$do_log) |
---|
[5099] | 73 | return $do_log; |
---|
| 74 | else |
---|
| 75 | { |
---|
[5113] | 76 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
[5099] | 77 | |
---|
[5113] | 78 | foreach ($conf_HIPE as $Exclusion) |
---|
[5099] | 79 | { |
---|
[5113] | 80 | $IP_Exclude = explode('.', $Exclusion); |
---|
[5099] | 81 | |
---|
| 82 | if ( |
---|
| 83 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
| 84 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
| 85 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
| 86 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
| 87 | ) |
---|
| 88 | { |
---|
| 89 | $do_log = false; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | return $do_log; |
---|
| 94 | } |
---|
| 95 | } |
---|
[6758] | 96 | |
---|
| 97 | /* Check users registration */ |
---|
| 98 | add_event_handler('register_user_check', 'HIPE_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL +2, 2); |
---|
| 99 | |
---|
| 100 | function HIPE_RegistrationCheck($err, $user) |
---|
| 101 | { |
---|
| 102 | global $errors, $conf; |
---|
| 103 | load_language('plugin.lang', HIPE_PATH); |
---|
| 104 | |
---|
| 105 | if (count($err)!=0 ) return $err; |
---|
| 106 | |
---|
| 107 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
| 108 | $HIPE_Config = unserialize($conf['HistoryIPConfig']); |
---|
| 109 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
| 110 | |
---|
| 111 | if (isset($HIPE_Config['Blacklist']) and $HIPE_Config['Blacklist'] == true) |
---|
| 112 | { |
---|
| 113 | foreach ($conf_HIPE as $Exclusion) |
---|
| 114 | { |
---|
| 115 | $IP_Exclude = explode('.', $Exclusion); |
---|
| 116 | |
---|
| 117 | if ( |
---|
| 118 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
| 119 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
| 120 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
| 121 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
| 122 | ) |
---|
| 123 | { |
---|
| 124 | $err = l10n('Error_HIPE_BlacklistedIP'); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | return $err; |
---|
| 128 | } |
---|
| 129 | } |
---|
[5121] | 130 | ?> |
---|