[31368] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: BanIP |
---|
| 4 | Version: auto |
---|
[31394] | 5 | Description: Ban adresse IP or range adresse IP. |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=824 |
---|
[31368] | 7 | Author: ddtddt |
---|
[31408] | 8 | Author URI: http://temmii.com/piwigo/ |
---|
[31368] | 9 | */ |
---|
| 10 | |
---|
[31373] | 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | Ban IP plugin for piwigo | |
---|
| 13 | // +-----------------------------------------------------------------------+ |
---|
[31746] | 14 | // | Copyright(C) 2016-2017 ddtddt http://temmii.com/piwigo/ | |
---|
[31373] | 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 | |
---|
[31368] | 31 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 32 | |
---|
| 33 | global $prefixeTable; |
---|
| 34 | |
---|
| 35 | // +-----------------------------------------------------------------------+ |
---|
| 36 | // | Define plugin constants | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | |
---|
| 39 | define('BANIP_ID', basename(dirname(__FILE__))); |
---|
| 40 | define('BANIP_PATH', PHPWG_PLUGINS_PATH.BANIP_ID.'/'); |
---|
| 41 | define('BANIP_TABLE' , $prefixeTable . 'ip_ban'); |
---|
| 42 | define('BANIP_ADMIN',get_root_url().'admin.php?page=plugin-'.BANIP_ID); |
---|
| 43 | |
---|
| 44 | add_event_handler('loc_end_section_init', 'banip'); |
---|
| 45 | |
---|
| 46 | function 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 | { |
---|
[31373] | 70 | die("IP " . $ip . " ".l10n('Range IP address banned')); |
---|
[31368] | 71 | } |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | // Plugin for admin |
---|
| 76 | if (script_basename() == 'admin') { |
---|
| 77 | include_once(dirname(__FILE__) . '/initadmin.php'); |
---|
| 78 | } |
---|