source: extensions/AntiAspi/admin.php @ 32542

Last change on this file since 32542 was 32381, checked in by plg, 4 years ago
  • make UI more compatible with Piwigo 11 (sliders)
  • specific colors for roma/clear admin themes
File size: 5.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $conf, $user;
6
7include_once(PHPWG_ROOT_PATH . 'admin/include/tabsheet.class.php');
8
9load_language('plugin.lang', ANTIASPI_PATH);
10
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// +-----------------------------------------------------------------------+
16
17check_status(ACCESS_ADMINISTRATOR);
18
19//-------------------------------------------------------- sections definitions
20
21$template->assign('ADMIN_PAGE_TITLE', l10n('AntiAspi'));
22
23if (!isset($_GET['tab']))
24{
25  $page['tab'] = 'ipban';
26}
27else
28{
29  $page['tab'] = $_GET['tab'];
30}
31
32$template->func_combine_css(array('id'=>'dst','path'=>ANTIASPI_PATH.'antiaspi.css'));
33
34$theme_css = ANTIASPI_PATH.'antiaspi_'.$conf['admin_theme'].'.css';
35if (file_exists($theme_css))
36{
37  $template->func_combine_css(array('path'=>$theme_css));
38}
39
40$tabsheet = new tabsheet();
41$tabsheet->add('ipban', '<i class="icon-network"></i> '.l10n('IP addresses'), ANTIASPI_ADMIN . '-ipban');
42$tabsheet->add('ipconfig', '<i class="icon-tools"></i> '.l10n('Configuration'), ANTIASPI_ADMIN . '-ipconfig ');
43$tabsheet->select($page['tab']);
44$tabsheet->assign();
45
46if ('ipban' == $page['tab'])
47{
48  $template->assign(
49    'ipbangest',
50    array(
51      'A' => 'a',
52    )
53  );
54
55  $query = '
56SELECT
57    *,
58    IF (date > SUBTIME(NOW(), "'.$conf['antiaspi']['banned during'].'"), "active", "deprecated") AS status
59  FROM '.ANTIASPI_TABLE.'
60  ORDER BY id DESC
61;';
62  $ipban = pwg_query($query);
63
64  $antiaspi = safe_unserialize($conf['antiaspi']);
65
66  $admin_base_url = ANTIASPI_ADMIN . '-ipban';
67  if (pwg_db_num_rows($ipban))
68  {
69    while ($ipban2 = pwg_db_fetch_assoc($ipban))
70    {
71      $items = array(
72        'ID' => $ipban2['id'],
73        'IP' => $ipban2['ip'],
74        'DATE' => $ipban2['date'],
75        'STATUS' => $ipban2['status'],
76        'STATUS_LABEL' => l10n('status-'.$ipban2['status']),
77        'U_DELETE' => $admin_base_url . '&amp;delete=' . $ipban2['id'],
78      );
79
80      $template->append('ipban2', $items);
81    }
82  }
83   
84  if (isset($_GET['delete']))
85  {
86    check_input_parameter('delete', $_GET, false, PATTERN_ID);
87
88    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ' WHERE id = ' . $_GET['delete'] . ';';
89    pwg_query($query);
90
91    $_SESSION['page_infos'] = array(l10n('IP ban deleted'));
92    redirect($admin_base_url);
93  }
94 
95  if (isset($_POST['submitdeleteall']))
96  {
97    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ';';
98    pwg_query($query);
99    redirect($admin_base_url);
100  }
101
102  if (isset($_POST['submitdeletedeprecated']))
103  {
104    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ' WHERE date < ADDTIME(NOW(), "-' . $antiaspi['banned during'] . '");';
105    pwg_query($query);
106    redirect($admin_base_url);
107  }
108
109  $i = 0;
110  while ($i < count($antiaspi['allowed ip']))
111  {
112    $items = array(
113      'IP' => $antiaspi['allowed ip'][$i],
114      'U_DELETE' => $admin_base_url . '&amp;deleteallowed='.$i ,
115    );
116
117    $template->append('allowip', $items);
118    $i++;
119  }
120
121  if (isset($_POST['submitaddipallowed']))
122  {
123    $i = 0;
124    while ($i < count($antiaspi['allowed ip']))
125    {
126      if ($_POST['insipallowed']==$antiaspi['allowed ip'][$i])
127      {
128        $_SESSION['page_errors'] = array(l10n('IP already allowed'));
129        redirect($admin_base_url);
130      }
131      $i++;
132    }
133
134    $antiaspi['allowed ip'][] = $_POST['insipallowed'];
135    conf_update_param('antiaspi', $antiaspi, true);
136    redirect($admin_base_url);
137  }
138
139  if (isset($_GET['deleteallowed']))
140  {
141    check_input_parameter('deleteallowed', $_GET, false, PATTERN_ID);
142
143    unset($antiaspi['allowed ip'][ $_GET['deleteallowed'] ]);
144
145    $antiaspi['allowed ip'] = array_values($antiaspi['allowed ip']);
146    conf_update_param('antiaspi', $antiaspi);
147    redirect($admin_base_url);
148  }
149}
150
151if ('ipconfig' == $page['tab'])
152{
153  antiaspi_check_old_conf();
154
155  $admin_base_url = ANTIASPI_ADMIN . '-ipconfig';
156  $antiaspi = safe_unserialize($conf['antiaspi']); 
157
158  $diff = explode(" pages in ", $antiaspi['diff']);
159  $tempsdiff= explode(":", $diff[1]);
160  $tempsdiffsec=$tempsdiff[2]+($tempsdiff[1]*60)+($tempsdiff[0]*60*60);
161
162  $same = explode(" pages in ", $antiaspi['same']);
163  $tempssame= explode(":", $same[1]);
164  $tempssamesec=$tempssame[2]+($tempssame[1]*60)+($tempssame[0]*60*60);
165
166  $template->assign(
167    'ipconfiggest',
168    array(
169      'DIFFA' => $diff[0],
170      'DIFFB' => $tempsdiffsec,
171      'SAMEA' => $same[0],
172      'SAMEB' => $tempssamesec,
173      'ONLYGUEST' => $antiaspi['only guest'],
174      'ONLYPICTURE' => $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'] = isset($_POST['insonlyguest']);
184    $antiaspi['only picture'] = isset($_POST['insonlypicture']);
185
186    conf_update_param('antiaspi', $antiaspi);
187    redirect($admin_base_url);
188  }
189}
190 
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.