source: extensions/HistoryIPExcluder/tags/2.4.3/main.inc.php @ 17442

Last change on this file since 17442 was 17441, checked in by Eric, 12 years ago

New version 2.4.3 hard coded for publication :
Update hu_HU translation (thanks to samli)
Update pl_PL translation (thanks to kuba)
Update cs_CZ translation (thanks to sichr)
Update el_GR translation (thanks to bas_alba)
Update lv_LV translation (thanks to agrisans)
Add uk_UA translation (thanks to animan)

  • Property svn:eol-style set to LF
File size: 5.2 KB
Line 
1<?php
2/*
3Plugin Name: History IP Excluder
4Version: 2.4.3
5Description: 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
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=147
7Author: Nicco, Eric
8Author URI: http://gallery-nicco.no-ip.org - http://www.infernoweb.net
9*/
10
11/*
12:: HISTORY
13
141.0.x to 1.6.x          - Plugin only for PWG 1.7.x
15
162.0.0             - Compliance with Piwigo 2.0.x
17
182.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                 
232.1.1             - Bug 1792 fixed (Thx to TOnin)
24                  - Bug 1511 fixed - New function to blacklist excluded IPs or ranged IPs for registration
25
262.2.0             - Compliance with Piwigo 2.2.x
27                  - Plugin directory renamed from nbc_HistoryIPExcluder to HistoryIPExcluder
28
292.2.1             - Bug fixed on plugin upgrade from 2.1.x version
30
312.2.2             - Another bug fixed on plugin upgrade from 2.2.x version
32
332.2.3             - Improved update mechanism. When no structural update of database is necessary, it sets the correct version number in plugin's configuration
34
352.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
392.4.0             - Piwigo 2.4 compliant
40                  - Add pl_PL translation (thanks to larky)
41
422.4.1             - Add  cs_CZ translation (thanks to lanius and ZdenekMaterna)
43                  - Add  ru_RU translation (thanks to nadusha)
44
452.4.2             - Update ru_RU translation (thanks to nadusha)
46
472.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--------------------------------------------------------------------------------
55*/
56
57if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
58
59if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
60
61include_once (HIPE_PATH.'/include/functions.inc.php');
62
63load_language('plugin.lang', HIPE_PATH);
64
65add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu');
66
67/* Set the administration panel of the plugin */
68function HIPE_admin_menu($menu)
69{
70// +-----------------------------------------------------------------------+
71// |                      Getting plugin name                              |
72// +-----------------------------------------------------------------------+
73  $plugin =  HIPE_infos(HIPE_PATH);
74  $name = $plugin['name'];
75 
76  array_push($menu,
77    array(
78      'NAME' => $name,
79      'URL' => get_root_url().'admin.php?page=plugin-'.basename(HIPE_PATH)
80    )
81  );
82   
83  return $menu;
84}
85
86// IP exclusion from logs
87add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer');
88
89function HIPE_IP_Filtrer($do_log)
90{
91  global $conf;
92
93  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
94
95  if (!$do_log)
96    return $do_log;
97  else
98  {
99    $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']);
100 
101    foreach ($conf_HIPE as $Exclusion)
102    {
103      $IP_Exclude = explode('.', $Exclusion);
104 
105      if (
106        (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and
107        (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and
108        (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and
109        (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%'))
110      )
111      {
112        $do_log = false;
113      }   
114    }
115     
116    return $do_log;
117  }
118}
119
120/* Check users registration */
121add_event_handler('register_user_check', 'HIPE_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL +2, 2);
122
123function HIPE_RegistrationCheck($err, $user)
124{
125  global $errors, $conf;
126  load_language('plugin.lang', HIPE_PATH);
127 
128  if (count($err)!=0 ) return $err;
129 
130  $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']);
131  $HIPE_Config = unserialize($conf['HistoryIPConfig']);
132  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
133 
134  if (isset($HIPE_Config['Blacklist']) and $HIPE_Config['Blacklist'] == true)
135  {
136    foreach ($conf_HIPE as $Exclusion)
137    {
138      $IP_Exclude = explode('.', $Exclusion);
139 
140      if (
141        (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and
142        (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and
143        (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and
144        (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%'))
145      )
146      {
147        $err = l10n('Error_HIPE_BlacklistedIP');
148      }
149    }
150    return $err;
151  }
152}
153?>
Note: See TracBrowser for help on using the repository browser.