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

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

Another upgrade bug fixed

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