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

Last change on this file since 32400 was 32400, checked in by ddtddt, 3 years ago

[BanIP] piwigo 11

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