source: extensions/nbc_HistoryIPExcluder/trunk/main.inc.php @ 6760

Last change on this file since 6760 was 6760, checked in by Eric, 14 years ago
  • Add of description.txt files
  • Property svn:eol-style set to LF
File size: 4.0 KB
Line 
1<?php
2/*
3Plugin Name: History IP Excluder
4Version: 2.1.1
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://phpwebgallery.net/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
26--------------------------------------------------------------------------------
27*/
28
29if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
30
31if (!defined('HIPE_DIR')) define('HIPE_DIR' , basename(dirname(__FILE__)));
32if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
33
34include_once (HIPE_PATH.'/include/functions.inc.php');
35
36load_language('plugin.lang', HIPE_PATH);
37
38add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer');
39add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu');
40
41/* Set the administration panel of the plugin */
42function HIPE_admin_menu($menu)
43{
44// +-----------------------------------------------------------------------+
45// |                      Getting plugin name                              |
46// +-----------------------------------------------------------------------+
47  $plugin =  HIPE_infos(HIPE_PATH);
48  $name = $plugin['name'];
49 
50  array_push($menu,
51    array(
52      'NAME' => $name,
53      'URL' => get_admin_plugin_menu_link(HIPE_PATH.'admin/HIPE_admin.php')
54    )
55  );
56   
57  return $menu;
58}
59
60
61function HIPE_IP_Filtrer($do_log)
62{
63  global $conf;
64
65  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
66
67  if (!$do_log)
68    return $do_log;
69  else
70  {
71    $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']);
72 
73    foreach ($conf_HIPE as $Exclusion)
74    {
75      $IP_Exclude = explode('.', $Exclusion);
76 
77      if (
78        (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and
79        (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and
80        (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and
81        (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%'))
82      )
83      {
84        $do_log = false;
85      }   
86    }
87     
88    return $do_log;
89  }
90}
91
92/* Check users registration */
93add_event_handler('register_user_check', 'HIPE_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL +2, 2);
94
95function HIPE_RegistrationCheck($err, $user)
96{
97  global $errors, $conf;
98  load_language('plugin.lang', HIPE_PATH);
99 
100  if (count($err)!=0 ) return $err;
101 
102  $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']);
103  $HIPE_Config = unserialize($conf['HistoryIPConfig']);
104  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
105 
106  if (isset($HIPE_Config['Blacklist']) and $HIPE_Config['Blacklist'] == true)
107  {
108    foreach ($conf_HIPE as $Exclusion)
109    {
110      $IP_Exclude = explode('.', $Exclusion);
111 
112      if (
113        (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and
114        (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and
115        (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and
116        (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%'))
117      )
118      {
119        $err = l10n('Error_HIPE_BlacklistedIP');
120      }
121    }
122    return $err;
123  }
124}
125?>
Note: See TracBrowser for help on using the repository browser.