[17453] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: History IP Excluder |
---|
[18486] | 4 | Version: auto |
---|
[17453] | 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 |
---|
| 6 | Plugin URI: http://piwigo.org/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 | |
---|
| 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 |
---|
| 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 |
---|
| 25 | |
---|
| 26 | 2.2.0 - Compliance with Piwigo 2.2.x |
---|
| 27 | - Plugin directory renamed from nbc_HistoryIPExcluder to HistoryIPExcluder |
---|
| 28 | |
---|
| 29 | 2.2.1 - Bug fixed on plugin upgrade from 2.1.x version |
---|
| 30 | |
---|
| 31 | 2.2.2 - Another bug fixed on plugin upgrade from 2.2.x version |
---|
| 32 | |
---|
| 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 |
---|
| 34 | |
---|
| 35 | 2.3.0 - Piwigo 2.3.0 compliant (alpha release for Piwigo 2.3.0RC) |
---|
| 36 | - Use data serialization for database storage |
---|
| 37 | - Use pwg_db_real_escape_string() instead of addslashes() |
---|
| 38 | |
---|
| 39 | 2.4.0 - Piwigo 2.4 compliant |
---|
| 40 | - Add pl_PL translation (thanks to larky) |
---|
| 41 | |
---|
| 42 | 2.4.1 - Add cs_CZ translation (thanks to lanius and ZdenekMaterna) |
---|
| 43 | - Add ru_RU translation (thanks to nadusha) |
---|
| 44 | |
---|
| 45 | 2.4.2 - Update ru_RU translation (thanks to nadusha) |
---|
[18486] | 46 | |
---|
| 47 | 2.4.3 - Update hu_HU translation (thanks to samli) |
---|
| 48 | - Update pl_PL translation (thanks to kuba) |
---|
| 49 | - Update cs_CZ translation (thanks to sichr) |
---|
| 50 | - Update el_GR translation (thanks to bas_alba) |
---|
| 51 | - Update lv_LV translation (thanks to agrisans) |
---|
| 52 | - Add uk_UA translation (thanks to animan) |
---|
| 53 | |
---|
| 54 | 2.4.4 - Update uk_UA, thanks to : animan |
---|
| 55 | - Update es_ES, thanks to : jpr928 |
---|
| 56 | - Update it_IT, thanks to : virgigiole |
---|
[18487] | 57 | - Add sk_SK, thanks to : dodo |
---|
[18486] | 58 | - Add da_DK, thanks to : Kaare |
---|
[21116] | 59 | |
---|
| 60 | 2.5.0 - Compliance with Piwigo 2.5 |
---|
| 61 | - Add tr_TR, thanks to : LazBoy |
---|
[22453] | 62 | |
---|
| 63 | 2.5.1 - Add pt_BR, thanks to : flaviove |
---|
[22874] | 64 | |
---|
| 65 | 2.5.2 - Add pt_PT, thanks to : ddtddt & ANO |
---|
[23568] | 66 | |
---|
| 67 | 2.5.3 - Add nl_NL, thanks to : Kees Hessels |
---|
| 68 | - Update el_GR, thanks to : bas_alba |
---|
| 69 | - Update da_DK, thanks to : Kaare |
---|
| 70 | - Update ru_RU, thanks to : Konve |
---|
| 71 | - Translation keys fixed |
---|
| 72 | - Delete unused translation keys |
---|
[24304] | 73 | |
---|
| 74 | 2.5.4 - Update es_ES, thanks to : jpr928 |
---|
| 75 | - Update tr_TR, thanks to : LazBoy |
---|
| 76 | - Update lv_LV, thanks to : agrisans |
---|
| 77 | - Update pt_PT, thanks to : ANO |
---|
| 78 | - Update sk_SK, thanks to : dodo |
---|
| 79 | - Update pl_PL, thanks to : K.S. |
---|
| 80 | - Update it_IT, thanks to : Sugar888 |
---|
| 81 | - Update pt_BR, thanks to : glaucio |
---|
| 82 | - Update de_DE, thanks to : fs101299 |
---|
| 83 | - Update nl_NL, thanks to : Kees Hessels |
---|
[26083] | 84 | |
---|
| 85 | 2.6.0 - Compatibility checked with Piwigo 2.6 |
---|
| 86 | - Update uk_UA, thanks to : animan |
---|
| 87 | - Update cs_CZ, thanks to : elpresidento |
---|
[27445] | 88 | |
---|
| 89 | 2.6.1 - Fix obsolete is_adviser() |
---|
[29341] | 90 | |
---|
| 91 | 2.7.0 - Compatibility with Piwigo 2.7 |
---|
| 92 | - Update zh_CN, thanks to : dennisyan |
---|
[30351] | 93 | |
---|
| 94 | 2.7.1 - Add nb_NO, thanks to : paulen |
---|
[30678] | 95 | |
---|
| 96 | 2.7.2 - Update nb_NO, thanks to paulen |
---|
| 97 | - Update de_DE, thanks to bigant |
---|
[17453] | 98 | -------------------------------------------------------------------------------- |
---|
| 99 | */ |
---|
| 100 | |
---|
| 101 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 102 | |
---|
| 103 | if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 104 | |
---|
| 105 | include_once (HIPE_PATH.'/include/functions.inc.php'); |
---|
| 106 | |
---|
| 107 | load_language('plugin.lang', HIPE_PATH); |
---|
| 108 | |
---|
| 109 | add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu'); |
---|
| 110 | |
---|
| 111 | /* Set the administration panel of the plugin */ |
---|
| 112 | function HIPE_admin_menu($menu) |
---|
| 113 | { |
---|
| 114 | // +-----------------------------------------------------------------------+ |
---|
| 115 | // | Getting plugin name | |
---|
| 116 | // +-----------------------------------------------------------------------+ |
---|
| 117 | $plugin = HIPE_infos(HIPE_PATH); |
---|
| 118 | $name = $plugin['name']; |
---|
| 119 | |
---|
| 120 | array_push($menu, |
---|
| 121 | array( |
---|
| 122 | 'NAME' => $name, |
---|
| 123 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(HIPE_PATH) |
---|
| 124 | ) |
---|
| 125 | ); |
---|
| 126 | |
---|
| 127 | return $menu; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | // IP exclusion from logs |
---|
| 131 | add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer'); |
---|
| 132 | |
---|
| 133 | function HIPE_IP_Filtrer($do_log) |
---|
| 134 | { |
---|
| 135 | global $conf; |
---|
| 136 | |
---|
| 137 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
| 138 | |
---|
| 139 | if (!$do_log) |
---|
| 140 | return $do_log; |
---|
| 141 | else |
---|
| 142 | { |
---|
| 143 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
| 144 | |
---|
| 145 | foreach ($conf_HIPE as $Exclusion) |
---|
| 146 | { |
---|
| 147 | $IP_Exclude = explode('.', $Exclusion); |
---|
| 148 | |
---|
| 149 | if ( |
---|
| 150 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
| 151 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
| 152 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
| 153 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
| 154 | ) |
---|
| 155 | { |
---|
| 156 | $do_log = false; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | return $do_log; |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | /* Check users registration */ |
---|
| 165 | add_event_handler('register_user_check', 'HIPE_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL +2, 2); |
---|
| 166 | |
---|
| 167 | function HIPE_RegistrationCheck($err, $user) |
---|
| 168 | { |
---|
| 169 | global $errors, $conf; |
---|
| 170 | load_language('plugin.lang', HIPE_PATH); |
---|
| 171 | |
---|
| 172 | if (count($err)!=0 ) return $err; |
---|
| 173 | |
---|
| 174 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
| 175 | $HIPE_Config = unserialize($conf['HistoryIPConfig']); |
---|
| 176 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
| 177 | |
---|
| 178 | if (isset($HIPE_Config['Blacklist']) and $HIPE_Config['Blacklist'] == true) |
---|
| 179 | { |
---|
| 180 | foreach ($conf_HIPE as $Exclusion) |
---|
| 181 | { |
---|
| 182 | $IP_Exclude = explode('.', $Exclusion); |
---|
| 183 | |
---|
| 184 | if ( |
---|
| 185 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
| 186 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
| 187 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
| 188 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
| 189 | ) |
---|
| 190 | { |
---|
| 191 | $err = l10n('Error_HIPE_BlacklistedIP'); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | return $err; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | ?> |
---|