1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: History IP Excluder |
---|
4 | Version: 2.4.2 |
---|
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) |
---|
46 | |
---|
47 | -------------------------------------------------------------------------------- |
---|
48 | */ |
---|
49 | |
---|
50 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
51 | |
---|
52 | if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
53 | |
---|
54 | include_once (HIPE_PATH.'/include/functions.inc.php'); |
---|
55 | |
---|
56 | load_language('plugin.lang', HIPE_PATH); |
---|
57 | |
---|
58 | add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu'); |
---|
59 | |
---|
60 | /* Set the administration panel of the plugin */ |
---|
61 | function HIPE_admin_menu($menu) |
---|
62 | { |
---|
63 | // +-----------------------------------------------------------------------+ |
---|
64 | // | Getting plugin name | |
---|
65 | // +-----------------------------------------------------------------------+ |
---|
66 | $plugin = HIPE_infos(HIPE_PATH); |
---|
67 | $name = $plugin['name']; |
---|
68 | |
---|
69 | array_push($menu, |
---|
70 | array( |
---|
71 | 'NAME' => $name, |
---|
72 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(HIPE_PATH) |
---|
73 | ) |
---|
74 | ); |
---|
75 | |
---|
76 | return $menu; |
---|
77 | } |
---|
78 | |
---|
79 | // IP exclusion from logs |
---|
80 | add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer'); |
---|
81 | |
---|
82 | function HIPE_IP_Filtrer($do_log) |
---|
83 | { |
---|
84 | global $conf; |
---|
85 | |
---|
86 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
87 | |
---|
88 | if (!$do_log) |
---|
89 | return $do_log; |
---|
90 | else |
---|
91 | { |
---|
92 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
93 | |
---|
94 | foreach ($conf_HIPE as $Exclusion) |
---|
95 | { |
---|
96 | $IP_Exclude = explode('.', $Exclusion); |
---|
97 | |
---|
98 | if ( |
---|
99 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
100 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
101 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
102 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
103 | ) |
---|
104 | { |
---|
105 | $do_log = false; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | return $do_log; |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | /* Check users registration */ |
---|
114 | add_event_handler('register_user_check', 'HIPE_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL +2, 2); |
---|
115 | |
---|
116 | function HIPE_RegistrationCheck($err, $user) |
---|
117 | { |
---|
118 | global $errors, $conf; |
---|
119 | load_language('plugin.lang', HIPE_PATH); |
---|
120 | |
---|
121 | if (count($err)!=0 ) return $err; |
---|
122 | |
---|
123 | $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
124 | $HIPE_Config = unserialize($conf['HistoryIPConfig']); |
---|
125 | $conf_HIPE = explode("," , $conf['HistoryIPExcluder']); |
---|
126 | |
---|
127 | if (isset($HIPE_Config['Blacklist']) and $HIPE_Config['Blacklist'] == true) |
---|
128 | { |
---|
129 | foreach ($conf_HIPE as $Exclusion) |
---|
130 | { |
---|
131 | $IP_Exclude = explode('.', $Exclusion); |
---|
132 | |
---|
133 | if ( |
---|
134 | (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and |
---|
135 | (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and |
---|
136 | (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and |
---|
137 | (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%')) |
---|
138 | ) |
---|
139 | { |
---|
140 | $err = l10n('Error_HIPE_BlacklistedIP'); |
---|
141 | } |
---|
142 | } |
---|
143 | return $err; |
---|
144 | } |
---|
145 | } |
---|
146 | ?> |
---|