[5099] | 1 | <?php |
---|
| 2 | /* |
---|
[5162] | 3 | Plugin Name: History IP Excluder |
---|
[14222] | 4 | Version: 2.4.0 |
---|
[10045] | 5 | Description: Permet l'exclusion d'une IP ou d'une plage d'IP de l'historique et de les blacklister à l'inscription / Excludes one IP or a range of IP from the history and to blacklist them on registration |
---|
[10042] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=147 |
---|
[5099] | 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 | |
---|
[10042] | 31 | 2.2.2 - Another bug fixed on plugin upgrade from 2.2.x version |
---|
| 32 | |
---|
[10045] | 33 | 2.2.3 - Improved update mechanism. When no structural update of database is necessary, it sets the correct version number in plugin's configuration |
---|
[12150] | 34 | |
---|
[12288] | 35 | 2.3.0 - Piwigo 2.3.0 compliant (alpha release for Piwigo 2.3.0RC) |
---|
[12150] | 36 | - Use data serialization for database storage |
---|
| 37 | - Use pwg_db_real_escape_string() instead of addslashes() |
---|
[14222] | 38 | |
---|
| 39 | 2.4.0 - Piwigo 2.4 compliant |
---|
| 40 | - Add pl_PL translation (thanks to larky) |
---|
| 41 | |
---|
[5615] | 42 | -------------------------------------------------------------------------------- |
---|
| 43 | */ |
---|
| 44 | |
---|
[5099] | 45 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 46 | |
---|
| 47 | if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 48 | |
---|
[5615] | 49 | include_once (HIPE_PATH.'/include/functions.inc.php'); |
---|
| 50 | |
---|
[5099] | 51 | load_language('plugin.lang', HIPE_PATH); |
---|
| 52 | |
---|
| 53 | add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu'); |
---|
| 54 | |
---|
| 55 | /* Set the administration panel of the plugin */ |
---|
| 56 | function HIPE_admin_menu($menu) |
---|
| 57 | { |
---|
[5162] | 58 | // +-----------------------------------------------------------------------+ |
---|
| 59 | // | Getting plugin name | |
---|
| 60 | // +-----------------------------------------------------------------------+ |
---|
[5615] | 61 | $plugin = HIPE_infos(HIPE_PATH); |
---|
[5162] | 62 | $name = $plugin['name']; |
---|
| 63 | |
---|
[5099] | 64 | array_push($menu, |
---|
| 65 | array( |
---|
[5162] | 66 | 'NAME' => $name, |
---|
[9870] | 67 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(HIPE_PATH) |
---|
[5099] | 68 | ) |
---|
| 69 | ); |
---|
| 70 | |
---|
| 71 | return $menu; |
---|
| 72 | } |
---|
| 73 | |
---|
[9870] | 74 | // IP exclusion from logs |
---|
| 75 | add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer'); |
---|
[5099] | 76 | |
---|
| 77 | function HIPE_IP_Filtrer($do_log) |
---|
| 78 | { |
---|
| 79 | global $conf; |
---|
| 80 | |
---|
[5162] | 81 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
[5099] | 82 | |
---|
[5113] | 83 | if (!$do_log) |
---|
[5099] | 84 | return $do_log; |
---|
| 85 | else |
---|
| 86 | { |
---|
[5113] | 87 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
[5099] | 88 | |
---|
[5113] | 89 | foreach ($conf_HIPE as $Exclusion) |
---|
[5099] | 90 | { |
---|
[5113] | 91 | $IP_Exclude = explode('.', $Exclusion); |
---|
[5099] | 92 | |
---|
| 93 | if ( |
---|
| 94 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
| 95 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
| 96 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
| 97 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
| 98 | ) |
---|
| 99 | { |
---|
| 100 | $do_log = false; |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | return $do_log; |
---|
| 105 | } |
---|
| 106 | } |
---|
[6758] | 107 | |
---|
| 108 | /* Check users registration */ |
---|
| 109 | add_event_handler('register_user_check', 'HIPE_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL +2, 2); |
---|
| 110 | |
---|
| 111 | function HIPE_RegistrationCheck($err, $user) |
---|
| 112 | { |
---|
| 113 | global $errors, $conf; |
---|
| 114 | load_language('plugin.lang', HIPE_PATH); |
---|
| 115 | |
---|
| 116 | if (count($err)!=0 ) return $err; |
---|
| 117 | |
---|
| 118 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
| 119 | $HIPE_Config = unserialize($conf['HistoryIPConfig']); |
---|
| 120 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
| 121 | |
---|
| 122 | if (isset($HIPE_Config['Blacklist']) and $HIPE_Config['Blacklist'] == true) |
---|
| 123 | { |
---|
| 124 | foreach ($conf_HIPE as $Exclusion) |
---|
| 125 | { |
---|
| 126 | $IP_Exclude = explode('.', $Exclusion); |
---|
| 127 | |
---|
| 128 | if ( |
---|
| 129 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
| 130 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
| 131 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
| 132 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
| 133 | ) |
---|
| 134 | { |
---|
| 135 | $err = l10n('Error_HIPE_BlacklistedIP'); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | return $err; |
---|
| 139 | } |
---|
| 140 | } |
---|
[5121] | 141 | ?> |
---|