source: extensions/AntiAspi/admin.php @ 31952

Last change on this file since 31952 was 31952, checked in by plg, 5 years ago

cleaner configuration manager on install/update

File size: 5.7 KB
RevLine 
[31362]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'];
[31370]20        $template->func_combine_css(array('id'=>'dst','path'=>ANTIASPI_PATH.'antiaspi.css'));
[31362]21
22
23    $tabsheet = new tabsheet();
24    $tabsheet->add('ipban', l10n('IP ban'), ANTIASPI_ADMIN . '-ipban');
[31370]25        $tabsheet->add('ipconfig', l10n('Configuration '), ANTIASPI_ADMIN . '-ipconfig ');
[31362]26    $tabsheet->select($page['tab']);
27    $tabsheet->assign();
28
29switch ($page['tab']) {
30    case 'ipban':
[31370]31          $template->assign(
32       'ipbangest', array(
[31372]33       'A' => 'a',
[31370]34    ));
[31362]35        $ipban = pwg_query("SELECT * FROM " . ANTIASPI_TABLE . ";");
[31372]36    $antiaspi = safe_unserialize($conf['antiaspi']);
[31367]37       
[31362]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
[31366]60    $_SESSION['page_infos'] = array(l10n('IP ban deleted'));
[31362]61    redirect($admin_base_url);
62  }
[31371]63 
64  if (isset($_POST['submitdeleteall'])) {
65        $query = 'DELETE FROM ' . ANTIASPI_TABLE . ';';
66    pwg_query($query);
[31362]67        redirect($admin_base_url);
[31372]68  }
69  if (isset($_POST['submitdeletedeprecated'])) {
70        $query = 'DELETE FROM ' . ANTIASPI_TABLE . ' WHERE date < ADDTIME(NOW(), "-' . $antiaspi['banned during'] . '");';
71        pwg_query($query);
72        redirect($admin_base_url);
73  }
[31362]74        break;
[31370]75        case 'ipconfig':
[31952]76        antiaspi_check_old_conf();
[31370]77  global $conf, $template;
78  $admin_base_url = ANTIASPI_ADMIN . '-ipconfig';
79  $antiaspi = safe_unserialize($conf['antiaspi']);     
80/*
81$conf['antiaspi'] = array(
82  'diff' => '20 pages in 00:00:10' , // IP banned if 20 different pages viewed in 10 seconds
83  'same' => '15 pages in 00:00:30' , // IP banned if same 15 pages viewed in 30 seconds
84  'banned during' => '23:59:59' ,    // IP banned during hh:mm:ss
85  'only guest' => true ,             // If true, don't ban registered users
86  'only picture' => false ,          // If true, apply antiaspi only on picture page
87  'allowed ip' => array()            // Autorized IP (robots for example)
88);
89*/
90$diff = explode(" pages in ", $antiaspi['diff']);
91$tempsdiff= explode(":", $diff[1]);
92$tempsdiffsec=$tempsdiff[2]+($tempsdiff[1]*60)+($tempsdiff[0]*60*60);
93
94$same = explode(" pages in ", $antiaspi['same']);
95$tempssame= explode(":", $same[1]);
96$tempssamesec=$tempssame[2]+($tempssame[1]*60)+($tempssame[0]*60*60);
97
98$onlyguest = array(
[31372]99l10n('Yes'),
100l10n('No'),
[31370]101);
102$onlyguestv = array(
103true,
104false,
105);
106$onlypicture = array(
[31372]107l10n('Yes'),
108l10n('No'),
[31370]109);
110$onlypicturev = array(
111true,
112false,
113); 
114  $template->assign(
115   'ipconfiggest', array(
116          'DIFFA' => $diff[0],
117          'DIFFB' => $tempsdiffsec,
118          'SAMEA' => $same[0],
119          'SAMEB' => $tempssamesec,
120          'ONLYGUEST' => $onlyguest,
121          'ONLYGUESTV' => $onlyguestv,
122          'ONLYGUESTSELECT' => $antiaspi['only guest'],
123          'ONLYPICTURE' => $onlypicture,
124          'ONLYPICTUREV' => $onlypicturev,
125          'ONLYPICTURESELECT' => $antiaspi['only picture'],
126  ));
127  $i = 0;
128  while ($i < count($antiaspi['allowed ip'])) {
129
130        $items = array(
131                'IP' => $antiaspi['allowed ip'][$i],
132                'U_DELETE' => $admin_base_url . '&amp;delete='.$i ,
133        );
134
135        $template->append('allowip', $items);
136        $i++;
137  }
138 
139 
140        /*$time = '7000';
141echo date('h:i:s', $time);
142*/
143
144if (isset($_POST['submitconfban'])) {
145        /*$time = date('h:i:s', $_POST['insdiffb']);  revoir fonction date HS ?*/
146        $antiaspi['diff']=$_POST['insdiffa'].' pages in '.date('00:i:s', ($_POST['insdiffb']));
147        $antiaspi['same']=$_POST['inssamea'].' pages in '.date('00:i:s', ($_POST['inssameb']));
148        $antiaspi['only guest']=$_POST['insonlyguest'];
149        $antiaspi['only picture']=$_POST['insonlypicturet'];
150       
151        conf_update_param('antiaspi', $antiaspi);
152        redirect($admin_base_url);
[31362]153}
[31370]154
155if (isset($_POST['submitaddipallowed'])) {
156         $i = 0;
157        while ($i < count($antiaspi['allowed ip'])) {
158                if($_POST['insipallowed']==$antiaspi['allowed ip'][$i])
159                {
160                        $_SESSION['page_errors'] = array(l10n('IP already allowed'));
[31952]161                        redirect($admin_base_url);
[31370]162                }
163                $i++;
164        };
165
166        $antiaspi['allowed ip'][]=$_POST['insipallowed'];
167        conf_update_param('antiaspi', $antiaspi);
168        redirect($admin_base_url);
169}
170
171  if (isset($_GET['delete'])) {
172    check_input_parameter('delete', $_GET, false, PATTERN_ID);
173        unset($antiaspi['allowed ip'][($_GET['delete'])]);
174        $antiaspi['allowed ip'] = array_values($antiaspi['allowed ip']);
175    conf_update_param('antiaspi', $antiaspi);
176        redirect($admin_base_url);
177  }
178
179
180        break;
181}
[31362]182       
183
184$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl'));
185$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
186?>
Note: See TracBrowser for help on using the repository browser.