source: extensions/BanIP/main.inc.php

Last change on this file was 33038, checked in by ddtddt, 3 months ago

[BanIP] check php 8.3 / update RegEx

File size: 3.3 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-2023 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  if (isset($Vip)){
55    $plage= explode(".", $Vip);
56    $Vip2=$plage[0].".".$plage[1].".".$plage[2].".*";
57    $Vip3=$plage[0].".".$plage[1].".*.*";
58  }
59
60  $query = 'SELECT ip FROM ' . BANIP_TABLE . ' WHERE ip="' . $Vip . '";'; 
61  $result = pwg_query($query);
62
63  while(list($ip) = pwg_db_fetch_row($result))
64  {
65
66    die("IP " . $ip . "  ".l10n('IP ban'));
67  }
68
69  $query = 'SELECT ip FROM ' . BANIP_TABLE . ' WHERE ip="' . $Vip2 . '";';
70  $result = pwg_query($query);
71
72  while(list($ip) = pwg_db_fetch_row($result))
73  {
74    die("IP " . $ip . "  ".l10n('Range IP address banned'));
75  }
76
77  $query = 'SELECT ip FROM ' . BANIP_TABLE . ' WHERE ip="' . $Vip3 . '";';
78  $result = pwg_query($query);
79 
80  while(list($ip) = pwg_db_fetch_row($result))
81  {
82    die("IP " . $ip . "  ".l10n('Range IP address banned'));
83  }
84
85 
86}
87
88// Plugin for admin
89if (script_basename() == 'admin') {
90    include_once(dirname(__FILE__) . '/initadmin.php');
91}
Note: See TracBrowser for help on using the repository browser.