source: extensions/BanIP/main.inc.php @ 31809

Last change on this file since 31809 was 31746, checked in by ddtddt, 8 years ago

[extensions] - Ban IP - add table Ip list - datatables

File size: 3.0 KB
Line 
1<?php
2/*
3Plugin Name: BanIP
4Version: auto
5Description: Ban adresse IP or range adresse IP.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=824
7Author: ddtddt
8Author URI: http://temmii.com/piwigo/
9*/
10
11// +-----------------------------------------------------------------------+
12// | Ban IP plugin for piwigo                                              |
13// +-----------------------------------------------------------------------+
14// | Copyright(C) 2016-2017 ddtddt               http://temmii.com/piwigo/ |
15// +-----------------------------------------------------------------------+
16// | This program is free software; you can redistribute it and/or modify  |
17// | it under the terms of the GNU General Public License as published by  |
18// | the Free Software Foundation                                          |
19// |                                                                       |
20// | This program is distributed in the hope that it will be useful, but   |
21// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
22// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
23// | General Public License for more details.                              |
24// |                                                                       |
25// | You should have received a copy of the GNU General Public License     |
26// | along with this program; if not, write to the Free Software           |
27// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
28// | USA.                                                                  |
29// +-----------------------------------------------------------------------+
30
31if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
32
33global $prefixeTable;
34
35// +-----------------------------------------------------------------------+
36// | Define plugin constants                                               |
37// +-----------------------------------------------------------------------+
38
39define('BANIP_ID', basename(dirname(__FILE__)));
40define('BANIP_PATH', PHPWG_PLUGINS_PATH.BANIP_ID.'/');
41define('BANIP_TABLE' , $prefixeTable . 'ip_ban');
42define('BANIP_ADMIN',get_root_url().'admin.php?page=plugin-'.BANIP_ID);
43
44add_event_handler('loc_end_section_init', 'banip');
45
46function banip()
47{
48  global $user, $page;
49   load_language('plugin.lang', BANIP_PATH);
50  if (is_admin() ) return;
51 
52  $Vip = $_SERVER["REMOTE_ADDR"];
53  $plage= explode(".", $Vip);
54  $Vip2=$plage[0].".".$plage[1].".".$plage[2].".*";
55
56  $query = 'SELECT ip FROM ' . BANIP_TABLE . ' WHERE ip="' . $Vip . '";'; 
57  $result = pwg_query($query);
58
59  while(list($ip) = pwg_db_fetch_row($result))
60  {
61
62    die("IP " . $ip . "  ".l10n('IP ban'));
63  }
64
65  $query = 'SELECT ip FROM ' . BANIP_TABLE . ' WHERE ip="' . $Vip2 . '";';
66  $result = pwg_query($query);
67
68  while(list($ip) = pwg_db_fetch_row($result))
69  {
70    die("IP " . $ip . "  ".l10n('Range IP address banned'));
71  }
72 
73}
74
75// Plugin for admin
76if (script_basename() == 'admin') {
77    include_once(dirname(__FILE__) . '/initadmin.php');
78}
Note: See TracBrowser for help on using the repository browser.