source: extensions/HistoryIPExcluder/trunk/main.inc.php @ 12150

Last change on this file since 12150 was 12150, checked in by Eric, 13 years ago

New alpha version hard coded : 2.3.0a (for test with Piwigo 2.3.0RC only)

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