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

Last change on this file since 5162 was 5162, checked in by Eric, 14 years ago

[nbc_HistoryIPExcluder]

  • Removing "NBC" references
  • Display the good plugin's name
  • Database upgrade process for next version
  • Property svn:eol-style set to LF
File size: 3.5 KB
Line 
1<?php
2/*
3Plugin Name: History IP Excluder
4Version: 2.0.1
5Description: Permet l'exclusion d'une IP ou d'une plage d'IP de l historique - Excludes one IP or a range of IP from the history.
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
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13if (!defined('HIPE_DIR')) define('HIPE_DIR' , basename(dirname(__FILE__)));
14if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
15
16load_language('plugin.lang', HIPE_PATH);
17
18add_event_handler('pwg_log_allowed', 'HIPE_IP_Filtrer');
19add_event_handler('get_admin_plugin_menu_links', 'HIPE_admin_menu');
20
21/* Set the administration panel of the plugin */
22function HIPE_admin_menu($menu)
23{
24// +-----------------------------------------------------------------------+
25// |                      Getting plugin name                              |
26// +-----------------------------------------------------------------------+
27  $plugin =  PluginNfo(HIPE_PATH);
28  $name = $plugin['name'];
29 
30  array_push($menu,
31    array(
32      'NAME' => $name,
33      'URL' => get_admin_plugin_menu_link(HIPE_PATH.'admin/HIPE_admin.php')
34    )
35  );
36   
37  return $menu;
38}
39
40
41function HIPE_IP_Filtrer($do_log)
42{
43  global $conf;
44
45  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
46
47  if (!$do_log)
48    return $do_log;
49  else
50  {
51    $IP_Client = explode('.', $_SERVER['REMOTE_ADDR']);
52 
53    foreach ($conf_HIPE as $Exclusion)
54    {
55      $IP_Exclude = explode('.', $Exclusion);
56 
57      if (
58        (($IP_Client[0] == $IP_Exclude[0]) or ($IP_Exclude[0] == '%')) and
59        (!isset($IP_Exclude[1]) or ($IP_Client[1] == $IP_Exclude[1]) or ($IP_Exclude[1] == '%')) and
60        (!isset($IP_Exclude[2]) or ($IP_Client[2] == $IP_Exclude[2]) or ($IP_Exclude[2] == '%')) and
61        (!isset($IP_Exclude[3]) or ($IP_Client[3] == $IP_Exclude[3]) or ($IP_Exclude[3] == '%'))
62      )
63      {
64        $do_log = false;
65      }   
66    }
67     
68    return $do_log;
69  }
70}
71
72
73/* Email sending debugger function */
74function DebugLog($value1,$value2)
75{
76   $fo=fopen (HIPE_PATH.'admin/log.txt','a') ;
77   fwrite($fo,"======================\n") ;
78   fwrite($fo, "\n" . $value1 . "\r\n") ;
79   fwrite($fo, "\n" . $value2 . "\r\n") ;
80   fclose($fo) ;
81}
82
83/* Function called to get the plugin name */
84function PluginNfo($dir)
85{
86  $path = $dir;
87
88  $plg_data = implode( '', file($path.'main.inc.php') );
89  if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
90  {
91    $plugin['name'] = trim( $val[1] );
92  }
93  if (preg_match("|Version: (.*)|", $plg_data, $val))
94  {
95    $plugin['version'] = trim($val[1]);
96  }
97  if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
98  {
99    $plugin['uri'] = trim($val[1]);
100  }
101  if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
102  {
103    $plugin['description'] = trim($desc);
104  }
105  elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
106  {
107    $plugin['description'] = trim($val[1]);
108  }
109  if ( preg_match("|Author: (.*)|", $plg_data, $val) )
110  {
111    $plugin['author'] = trim($val[1]);
112  }
113  if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
114  {
115    $plugin['author uri'] = trim($val[1]);
116  }
117  if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
118  {
119    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
120    if (is_numeric($extension)) $plugin['extension'] = $extension;
121  }
122// IMPORTANT SECURITY !
123  $plugin = array_map('htmlspecialchars', $plugin);
124
125  return $plugin ;
126}
127
128?>
Note: See TracBrowser for help on using the repository browser.