source: extensions/AntiAspi/admin.php @ 31371

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

[extensions] - AntiAspi - update page admin ip ban

File size: 5.4 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH'))
4    die('Hacking attempt!');
5global $template, $conf, $user;
6include_once(PHPWG_ROOT_PATH . 'admin/include/tabsheet.class.php');
7load_language('plugin.lang', ANTIASPI_PATH);
8$my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugin-'; //get_admin_plugin_menu_link(__FILE__);
9
10// +-----------------------------------------------------------------------+
11// | Check Access and exit when user status is not ok                      |
12// +-----------------------------------------------------------------------+
13check_status(ACCESS_ADMINISTRATOR);
14
15//-------------------------------------------------------- sections definitions
16if (!isset($_GET['tab']))
17    $page['tab'] = 'ipban';
18else
19    $page['tab'] = $_GET['tab'];
20        $template->func_combine_css(array('id'=>'dst','path'=>ANTIASPI_PATH.'antiaspi.css'));
21
22
23    $tabsheet = new tabsheet();
24    $tabsheet->add('ipban', l10n('IP ban'), ANTIASPI_ADMIN . '-ipban');
25        $tabsheet->add('ipconfig', l10n('Configuration '), ANTIASPI_ADMIN . '-ipconfig ');
26    $tabsheet->select($page['tab']);
27    $tabsheet->assign();
28
29switch ($page['tab']) {
30    case 'ipban':
31          $template->assign(
32       'ipbangest', array(
33       'A' => 'a'
34    ));
35        $ipban = pwg_query("SELECT * FROM " . ANTIASPI_TABLE . ";");
36
37       
38    $admin_base_url = ANTIASPI_ADMIN . '-ipban';
39        if (pwg_db_num_rows($ipban)) {
40            while ($ipban2 = pwg_db_fetch_assoc($ipban)) {
41                               
42                $items = array(
43                    'ID' => $ipban2['id'],
44                    'IP' => $ipban2['ip'],
45                    'DATE' => $ipban2['date'],
46                    'U_DELETE' => $admin_base_url . '&amp;delete=' . $ipban2['id'],
47                    'U_EDIT' => $admin_base_url . '&amp;edit=' . $ipban2['id'],
48                );
49
50                $template->append('ipban2', $items);
51            }
52        }
53               
54  if (isset($_GET['delete'])) {
55
56    check_input_parameter('delete', $_GET, false, PATTERN_ID);
57    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ' WHERE id = ' . $_GET['delete'] . ';';
58    pwg_query($query);
59
60    $_SESSION['page_infos'] = array(l10n('IP ban deleted'));
61    redirect($admin_base_url);
62  }
63 
64  if (isset($_POST['submitdeleteall'])) {
65        $query = 'DELETE FROM ' . ANTIASPI_TABLE . ';';
66    pwg_query($query);
67        redirect($admin_base_url);
68}
69 
70        break;
71        case 'ipconfig':
72  global $conf, $template;
73  $admin_base_url = ANTIASPI_ADMIN . '-ipconfig';
74  $antiaspi = safe_unserialize($conf['antiaspi']);     
75/*
76$conf['antiaspi'] = array(
77  'diff' => '20 pages in 00:00:10' , // IP banned if 20 different pages viewed in 10 seconds
78  'same' => '15 pages in 00:00:30' , // IP banned if same 15 pages viewed in 30 seconds
79  'banned during' => '23:59:59' ,    // IP banned during hh:mm:ss
80  'only guest' => true ,             // If true, don't ban registered users
81  'only picture' => false ,          // If true, apply antiaspi only on picture page
82  'allowed ip' => array()            // Autorized IP (robots for example)
83);
84*/
85$diff = explode(" pages in ", $antiaspi['diff']);
86$tempsdiff= explode(":", $diff[1]);
87$tempsdiffsec=$tempsdiff[2]+($tempsdiff[1]*60)+($tempsdiff[0]*60*60);
88
89$same = explode(" pages in ", $antiaspi['same']);
90$tempssame= explode(":", $same[1]);
91$tempssamesec=$tempssame[2]+($tempssame[1]*60)+($tempssame[0]*60*60);
92
93$onlyguest = array(
94l10n('yes'),
95l10n('no'),
96);
97$onlyguestv = array(
98true,
99false,
100);
101$onlypicture = array(
102l10n('yes'),
103l10n('no'),
104);
105$onlypicturev = array(
106true,
107false,
108); 
109  $template->assign(
110   'ipconfiggest', array(
111          'DIFFA' => $diff[0],
112          'DIFFB' => $tempsdiffsec,
113          'SAMEA' => $same[0],
114          'SAMEB' => $tempssamesec,
115          'ONLYGUEST' => $onlyguest,
116          'ONLYGUESTV' => $onlyguestv,
117          'ONLYGUESTSELECT' => $antiaspi['only guest'],
118          'ONLYPICTURE' => $onlypicture,
119          'ONLYPICTUREV' => $onlypicturev,
120          'ONLYPICTURESELECT' => $antiaspi['only picture'],
121  ));
122  $i = 0;
123  while ($i < count($antiaspi['allowed ip'])) {
124
125        $items = array(
126                'IP' => $antiaspi['allowed ip'][$i],
127                'U_DELETE' => $admin_base_url . '&amp;delete='.$i ,
128        );
129
130        $template->append('allowip', $items);
131        $i++;
132  }
133 
134 
135        /*$time = '7000';
136echo date('h:i:s', $time);
137*/
138
139if (isset($_POST['submitconfban'])) {
140        /*$time = date('h:i:s', $_POST['insdiffb']);  revoir fonction date HS ?*/
141        $antiaspi['diff']=$_POST['insdiffa'].' pages in '.date('00:i:s', ($_POST['insdiffb']));
142        $antiaspi['same']=$_POST['inssamea'].' pages in '.date('00:i:s', ($_POST['inssameb']));
143        $antiaspi['only guest']=$_POST['insonlyguest'];
144        $antiaspi['only picture']=$_POST['insonlypicturet'];
145       
146        conf_update_param('antiaspi', $antiaspi);
147        redirect($admin_base_url);
148}
149
150if (isset($_POST['submitaddipallowed'])) {
151         $i = 0;
152        while ($i < count($antiaspi['allowed ip'])) {
153                if($_POST['insipallowed']==$antiaspi['allowed ip'][$i])
154                {
155                        $_SESSION['page_errors'] = array(l10n('IP already allowed'));
156                        redirect($admin_base_url);
157                }
158                $i++;
159        };
160
161        $antiaspi['allowed ip'][]=$_POST['insipallowed'];
162        conf_update_param('antiaspi', $antiaspi);
163        redirect($admin_base_url);
164}
165
166  if (isset($_GET['delete'])) {
167    check_input_parameter('delete', $_GET, false, PATTERN_ID);
168        unset($antiaspi['allowed ip'][($_GET['delete'])]);
169        $antiaspi['allowed ip'] = array_values($antiaspi['allowed ip']);
170    conf_update_param('antiaspi', $antiaspi);
171        redirect($admin_base_url);
172  }
173
174
175        break;
176}
177       
178
179$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl'));
180$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
181?>
Note: See TracBrowser for help on using the repository browser.