source: extensions/AntiAspi/admin.php @ 31954

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

Simplify yes/no settings (use checkboxes instead of radio buttons)

Localisation (EN/FR for now)

File size: 5.1 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
21if (!isset($_GET['tab']))
22{
23  $page['tab'] = 'ipban';
24}
25else
26{
27  $page['tab'] = $_GET['tab'];
28}
29
30$template->func_combine_css(array('id'=>'dst','path'=>ANTIASPI_PATH.'antiaspi.css'));
31
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();
37
38if ('ipban' == $page['tab'])
39{
40  $template->assign(
41    'ipbangest',
42    array(
43      'A' => 'a',
44    )
45  );
46
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);
55
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        'STATUS_LABEL' => l10n('status-'.$ipban2['status']),
69        'U_DELETE' => $admin_base_url . '&amp;delete=' . $ipban2['id'],
70      );
71
72      $template->append('ipban2', $items);
73    }
74  }
75   
76  if (isset($_GET['delete']))
77  {
78    check_input_parameter('delete', $_GET, false, PATTERN_ID);
79
80    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ' WHERE id = ' . $_GET['delete'] . ';';
81    pwg_query($query);
82
83    $_SESSION['page_infos'] = array(l10n('IP ban deleted'));
84    redirect($admin_base_url);
85  }
86 
87  if (isset($_POST['submitdeleteall']))
88  {
89    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ';';
90    pwg_query($query);
91    redirect($admin_base_url);
92  }
93
94  if (isset($_POST['submitdeletedeprecated']))
95  {
96    $query = 'DELETE FROM ' . ANTIASPI_TABLE . ' WHERE date < ADDTIME(NOW(), "-' . $antiaspi['banned during'] . '");';
97    pwg_query($query);
98    redirect($admin_base_url);
99  }
100
101  $i = 0;
102  while ($i < count($antiaspi['allowed ip']))
103  {
104    $items = array(
105      'IP' => $antiaspi['allowed ip'][$i],
106      'U_DELETE' => $admin_base_url . '&amp;deleteallowed='.$i ,
107    );
108
109    $template->append('allowip', $items);
110    $i++;
111  }
112
113  if (isset($_POST['submitaddipallowed']))
114  {
115    $i = 0;
116    while ($i < count($antiaspi['allowed ip']))
117    {
118      if ($_POST['insipallowed']==$antiaspi['allowed ip'][$i])
119      {
120        $_SESSION['page_errors'] = array(l10n('IP already allowed'));
121        redirect($admin_base_url);
122      }
123      $i++;
124    }
125
126    $antiaspi['allowed ip'][] = $_POST['insipallowed'];
127    conf_update_param('antiaspi', $antiaspi, true);
128    redirect($admin_base_url);
129  }
130
131  if (isset($_GET['deleteallowed']))
132  {
133    check_input_parameter('deleteallowed', $_GET, false, PATTERN_ID);
134
135    unset($antiaspi['allowed ip'][ $_GET['deleteallowed'] ]);
136
137    $antiaspi['allowed ip'] = array_values($antiaspi['allowed ip']);
138    conf_update_param('antiaspi', $antiaspi);
139    redirect($admin_base_url);
140  }
141}
142
143if ('ipconfig' == $page['tab'])
144{
145  antiaspi_check_old_conf();
146
147  $admin_base_url = ANTIASPI_ADMIN . '-ipconfig';
148  $antiaspi = safe_unserialize($conf['antiaspi']); 
149
150  $diff = explode(" pages in ", $antiaspi['diff']);
151  $tempsdiff= explode(":", $diff[1]);
152  $tempsdiffsec=$tempsdiff[2]+($tempsdiff[1]*60)+($tempsdiff[0]*60*60);
153
154  $same = explode(" pages in ", $antiaspi['same']);
155  $tempssame= explode(":", $same[1]);
156  $tempssamesec=$tempssame[2]+($tempssame[1]*60)+($tempssame[0]*60*60);
157
158  $template->assign(
159    'ipconfiggest',
160    array(
161      'DIFFA' => $diff[0],
162      'DIFFB' => $tempsdiffsec,
163      'SAMEA' => $same[0],
164      'SAMEB' => $tempssamesec,
165      'ONLYGUEST' => $antiaspi['only guest'],
166      'ONLYPICTURE' => $antiaspi['only picture'],
167    )
168  );
169
170  if (isset($_POST['submitconfban']))
171  {
172    /*$time = date('h:i:s', $_POST['insdiffb']);  revoir fonction date HS ?*/
173    $antiaspi['diff'] = $_POST['insdiffa'].' pages in '.date('00:i:s', ($_POST['insdiffb']));
174    $antiaspi['same'] = $_POST['inssamea'].' pages in '.date('00:i:s', ($_POST['inssameb']));
175    $antiaspi['only guest'] = isset($_POST['insonlyguest']);
176    $antiaspi['only picture'] = isset($_POST['insonlypicture']);
177
178    conf_update_param('antiaspi', $antiaspi);
179    redirect($admin_base_url);
180  }
181}
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.