source: extensions/AntiAspi/admin.php @ 31953

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

Simpler user interface, display banned IP current status, regroup IP management

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