source: extensions/nbc_HistoryIPExcluder/trunk/admin/HIPE_admin.php @ 6758

Last change on this file since 6758 was 6758, checked in by Eric, 14 years ago
  • Bug 1511 fixed - New function to blacklist excluded IPs or ranged IPs for registration
  • Bug 1792 fixed (Thx to TOnin)
  • Property svn:eol-style set to LF
File size: 6.1 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5load_language('plugin.lang', HIPE_PATH);
6
7// +-----------------------------------------------------------------------+
8// |                      Getting plugin version                           |
9// +-----------------------------------------------------------------------+
10$plugin =  HIPE_infos(HIPE_PATH);
11$version = $plugin['version'];
12$name = $plugin['name'];
13
14
15$ip_geolocalisation1 = '<a href="http://www.geoiptool.com/fr/?IP=';
16$ip_geolocalisation2 = '" title="Geo IP localisation" target="_blank"><img src="'.HIPE_PATH.'/geoip.ico" class="button" alt="'.l10n('IP_geolocalisation').'"></a>';
17
18$ip_ripe1 = '<a href="http://www.ripe.net/whois?form_type=simple&amp;full_query_string=&amp;searchtext=';
19$ip_ripe2 = '+&amp;do_search=Search" title="Ripe Whois" target="_blank">';
20$ip_ripe3 = '</a>';
21
22
23
24if ( isset($_POST['submit']) and !is_adviser() )
25{
26  $v = $_POST['HIPE_IPs_Excluded'];
27  $v = str_replace( "\r\n", ",", $v );
28  $v = str_replace( ",,", ",", $v );
29
30  $conf['HistoryIPExcluder'] = stripslashes($v);
31
32  $query = '
33    UPDATE '.CONFIG_TABLE.'
34    SET value="'.$conf['HistoryIPExcluder'].'"
35    WHERE param="HistoryIPExcluder"
36    LIMIT 1';
37  pwg_query($query);
38
39  if (!isset($_POST['HIPE_chkb'])) $_POST['HIPE_chkb'] = '0';
40  $newconf_HIPE = array(
41    'Blacklist' => $_POST['HIPE_chkb'],
42    'Version'   => $version,
43  );
44 
45  $conf['HistoryIPConfig'] = serialize($newconf_HIPE);
46
47  $query = '
48    UPDATE '.CONFIG_TABLE.'
49    SET value="'.addslashes($conf['HistoryIPConfig']).'"
50    WHERE param="HistoryIPConfig"
51    LIMIT 1';
52  pwg_query($query);
53
54  // information message
55  array_push($page['infos'], l10n('HIPE_save_config'));
56}
57elseif ( isset($_POST['CleanHist']) )
58{
59  $conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
60
61  foreach ( $conf_HIPE as $Exclusion )
62  {
63    $query = '
64      delete FROM '.HISTORY_TABLE.' where
65      IP like \''.$Exclusion.'\';';
66    pwg_query($query);
67   }
68
69
70  $query = '
71    truncate '.HISTORY_SUMMARY_TABLE.';';
72  pwg_query($query);
73
74  $query = '
75    UPDATE '.HISTORY_TABLE.'
76    SET summarized = \'false\';';
77  pwg_query($query);
78
79  // information message
80  array_push($page['infos'], l10n('HIPE_hist_cleaned'));
81}
82elseif ( isset($_POST['HIPE_IPByMember']) )
83{
84  $template->assign(
85    array(
86      'HIPE_DESCRIPTION2' => l10n('HIPE_IPByMember_description'),
87    )
88  );
89
90  $query = '
91    select distinct h.ip, u.username
92    from '.HISTORY_TABLE.' as h
93    inner join '.USERS_TABLE.' as u on u.id = h.user_id
94    where h.user_id <> 2
95    order by h.ip
96  ;';
97 
98  $subresult = pwg_query($query);
99
100  while ($subrow = pwg_db_fetch_assoc($subresult))
101  {
102    $template->append(
103      'resultat',
104      array(
105        'HIPE_RESULTAT1' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
106        'HIPE_RESULTAT2' => $subrow['username'],
107      )
108    );   
109  }
110
111  // information message
112  array_push($page['infos'], l10n('HIPE_resquet_ok'));
113}
114elseif ( isset($_POST['HIPE_OnlyGuest']) )
115{
116  $template->assign(
117    array(
118      'HIPE_DESCRIPTION2' => l10n('HIPE_OnlyGuest_description'),
119    )
120  );
121
122  $query1 = '
123    select distinct h.ip
124    from '.HISTORY_TABLE.' as h
125    where h.user_id <> 2
126  ;';
127 
128  $IPsMember = array_from_query($query1, 'ip');
129
130  $query = '
131    select h.ip, count(h.ip) as nbreIP
132    from '.HISTORY_TABLE.' as h
133    where h.ip not in (\''.implode('\',\'', $IPsMember).'\')
134    group by h.ip
135    order by nbreIP desc
136  ;';
137 
138  $subresult = pwg_query($query);
139
140  while ($subrow = pwg_db_fetch_assoc($subresult))
141  {
142    $template->append(
143      'resultat',
144      array(
145        'HIPE_RESULTAT1' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
146        'HIPE_RESULTAT2' => $subrow['nbreIP'],
147      )
148    );   
149  }
150
151  // information message
152  array_push($page['infos'], l10n('HIPE_resquet_ok'));
153}
154elseif ( isset($_POST['HIPE_IPForMember']) and isset($_POST['HIPE_input']))
155{
156  $template->assign(
157    array(
158      'HIPE_DESCRIPTION2' => l10n('HIPE_IPForMember_description'),
159    )
160  );
161
162  $query = '
163    select h.ip, u.username
164    from '.HISTORY_TABLE.' as h
165    inner join '.USERS_TABLE.' as u on u.id = h.user_id
166    where u.username like \''.$_POST['HIPE_input'].'\'
167    group by h.ip
168    order by h.ip
169  ;';
170 
171  $subresult = pwg_query($query);
172
173  while ($subrow = pwg_db_fetch_assoc($subresult))
174  {
175    $template->append(
176      'resultat',
177      array(
178        'HIPE_RESULTAT1' => $subrow['username'],
179        'HIPE_RESULTAT2' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
180      )
181    );   
182  }
183
184  // information message
185  array_push($page['infos'], l10n('HIPE_resquet_ok'));
186}
187elseif ( isset($_POST['HIPE_MemberForIp']) and isset($_POST['HIPE_input']))
188{
189  $template->append(
190    array(
191      'HIPE_DESCRIPTION2' => l10n('HIPE_MemberForIp_description'),
192    )
193  );
194
195  $query = '
196    select h.ip, u.username
197    from '.HISTORY_TABLE.' as h
198    inner join '.USERS_TABLE.' as u on u.id = h.user_id
199    where h.ip like \''.$_POST['HIPE_input'].'\'
200    group by u.username
201    order by u.username
202  ;';
203 
204  $subresult = pwg_query($query);
205
206  while ($subrow = pwg_db_fetch_assoc($subresult))
207  {
208    $template->assign(
209      'resultat',
210      array(
211        'HIPE_RESULTAT1' => $ip_geolocalisation1.$subrow['ip'].$ip_geolocalisation2.' '.$ip_ripe1.$subrow['ip'].$ip_ripe2.$subrow['ip'].$ip_ripe3,
212        'HIPE_RESULTAT2' => $subrow['username'],
213      )
214    );   
215  }
216
217  // information message
218  array_push($page['infos'], l10n('HIPE_resquet_ok'));
219}
220
221$conf_HIPE = explode("," , $conf['HistoryIPExcluder']);
222$HIPE_Config = unserialize($conf['HistoryIPConfig']);
223
224$template->assign(
225  array(
226    'HIPE_VERSION' => $version,
227    'HIPE_NAME'    => $name,
228    'HIPE_PATH'    => HIPE_PATH,
229    'IPs_EXCLUDED' => implode("\n", $conf_HIPE),
230  )
231);
232
233  if ($HIPE_Config['Blacklist'] == 1) $template->assign(array('HIPE_IPBlacklisted' => 'checked="checked"'));
234
235  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/HIPE_admin.tpl');
236  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
237
238?>
Note: See TracBrowser for help on using the repository browser.