source: extensions/whois_online/config.php @ 6214

Last change on this file since 6214 was 6214, checked in by vdigital, 14 years ago

Fix: Menu was forced to Tools or Plugins on other admin functions

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1<?php
2
3/* Whois online Configuration, Radar and cleaning */
4
5/*
6 TODO list:
7- User comments… (Delete all comments or partial delete)
8- Bots identification (for exclusion maybe a sharing feature with antiaspi to lock user/IP)
9- hits level (to suggest a new bot)
10- IPV6 Support
11- Map
12*/
13
14if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
15if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!');
16global $conf, $conf_whois, $lang;
17$conf['show_gt'] = true;
18load_language('plugin.lang', WHOIS_ONLINE_PATH);
19
20pwg_debug('*********** Whois configuration ***********');
21
22if (!isset($conf_whois['Active'])) $conf_whois = whois_online_conf();
23$errors = array();
24$infos = array();
25add_event_handler('loc_end_admin', 'whois_select_menu' );
26
27// Get Current data
28$conf['Whois Online Update'] = false;
29whois_online_management();
30
31$template->set_filenames(array(
32    'plugin_admin_content' => dirname(__FILE__) . '/config.tpl',
33                'double_select' => 'double_select.tpl'
34                ));
35
36// Tabsheets
37include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
38$_url = get_admin_plugin_menu_link(__FILE__);
39if (!isset($_GET['tab'])) $page['tab'] = 'config';
40else $page['tab'] = $_GET['tab']; 
41
42$tabsheet = new tabsheet();
43$tabsheet->add('config', l10n('config'), $_url.'&amp;tab=config');
44$tabsheet->add('monitor', l10n('Monitor'), $_url.'&amp;tab=monitor');
45$tabsheet->add('report', l10n('Report'), $_url.'&amp;tab=report');
46$tabsheet->select($page['tab']);
47$tabsheet->assign();
48$template->assign('page', $page['tab']);
49
50$sub = ( isset($_POST['submit']) ) ? true : false;
51
52// Check input on config
53if ($sub and isset($_POST['from']) and $_POST['from']=='config') {
54  if (!is_numeric($_POST['Level']) or $_POST['Level'] < 10 or $_POST['Level'] > 200) 
55                array_push($errors, l10n('Error range: '). l10n('Delete level [10-200] (ratio between obsolete and active)'));
56  if (!is_numeric($_POST['Limit']) or $_POST['Limit'] < 10 or $_POST['Limit'] > 200) 
57                array_push($errors, l10n('Error range: '). l10n('Obsolete limit [20-100] (obsolete data count)'));
58        if (!is_numeric($_POST['Radar_limit']) or $_POST['Radar_limit'] < 10 or $_POST['Radar_limit'] > 200) 
59                array_push($errors, l10n('Error range: '). l10n('Radar_limit [10-200] (Users with image cluetips on radar page)'));
60        if (!is_numeric($_POST['Webmaster_management']) or $_POST['Webmaster_management'] > 2) 
61                array_push($errors, l10n('User follow up error'));
62        if (!is_numeric($_POST['Administrator_management']) or $_POST['Administrator_management'] > 2) 
63                array_push($errors, l10n('User follow up error'));
64        $conf_whois = array_merge($conf_whois, Array(
65                'Active' => ($_POST['Active']==1) ? true:false,
66                'Delete level' => $_POST['Level'],
67                'Obsolete limit' => $_POST['Limit'],
68                'Radar limit' => $_POST['Radar_limit'],
69                'Webmasters' => (int) $_POST['Webmaster_management'],
70                'Administrators' => (int) $_POST['Administrator_management'],
71                'Add to Plugins menu' => ($_POST['Plugins_menu']==1) ? true:false,
72                'Add icon to History' => ($_POST['History_icon']==1) ? true:false,
73                'Keep data' => ($_POST['Keep_data']==1) ? true:false,
74                'Default display' => ($_POST['Display']==1) ? true:false,
75                'Version' => WHOIS_ONLINE_VER,
76        ));
77}
78
79// Submit and Advisor => Thanks
80if ( $sub and is_adviser() )
81        array_push($infos, l10n('You are Adviser and you are not authorized to change this configuration.'));
82
83        // Submit and not Advisor => Update Config table
84if ( $sub and count($errors) == 0 and $_POST['from']=='config' and !is_adviser()) {
85        if ( $conf['Whois Online'] != serialize($conf_whois) ) {
86                $conf['Whois Online'] = serialize($conf_whois);
87                pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
88    VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
89                array_push($infos, l10n('Configuration has been saved.'));
90        }
91}
92
93// Switch users on right side (=> Temporary)
94if ( isset($_POST['falsify']) and !is_adviser() 
95    and count($errors) == 0 and $_POST['from']=='monitor'
96    and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) {
97      pwg_query('UPDATE '.WHOIS_ONLINE_TABLE.'
98  SET `permanent` = \'false\'
99  WHERE `session_id` IN ("'.implode('","', $_POST['cat_true']).'");');
100}
101// Switch users on left side (Permanent <=)
102if ( isset($_POST['trueify']) and !is_adviser() 
103    and count($errors) == 0 and $_POST['from']=='monitor'
104    and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) {
105      pwg_query('UPDATE '.WHOIS_ONLINE_TABLE.'
106  SET `permanent` = \'true\'
107  WHERE `session_id` IN ("'.implode('","', $_POST['cat_false']).'");');
108}
109// Delete users from > 24 h temporary list
110if ( isset($_POST['prs_delete']) and !is_adviser() 
111    and count($errors) == 0 and $_POST['from']=='monitor'
112    and isset($_POST['prs_remove']) and count($_POST['prs_remove']) > 0) {
113     pwg_query('DELETE FROM '.WHOIS_ONLINE_TABLE.'
114  WHERE `permanent` = \'false\'
115    AND `session_id` IN ("'.implode('","', $_POST['prs_remove']).'");');
116}
117// Compress it!
118if ( isset($_GET['check']) and !is_adviser() ) {
119  pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `last_access` < ' . (time() - (3*24*60*60)) . '
120    AND `permanent` = \'false\' AND `IP` <> \'global\';');
121  pwg_query('CHECK TABLE '.WHOIS_ONLINE_TABLE);
122  pwg_query('OPTIMIZE TABLE '.WHOIS_ONLINE_TABLE);
123}
124// The whois_online table summary
125if (isset($_GET['tab']) and $_GET['tab']=='monitor') {
126  $whois_status = mysql_fetch_assoc(pwg_query('SHOW TABLE STATUS LIKE "' . WHOIS_ONLINE_TABLE .'%" ;'));
127  $whois_status['table'] = WHOIS_ONLINE_TABLE;
128  $whois_status['size'] = ($whois_status['Data_length'] + $whois_status['Index_length']) . ' bytes';
129  if ($whois_status['size'] > 1024) $whois_status['size'] = round($whois_status['size'] / 1024, 1) . ' Kb';
130  if ($whois_status['size'] > 1024) $whois_status['size'] = round($whois_status['size'] / 1024, 1) . ' Mb';
131  $whois_status['spacef'] = $whois_status['Data_free'] . ' bytes';
132  if ($whois_status['spacef'] > 1024) $whois_status['spacef'] = round($whois_status['spacef'] / 1024, 1) . ' Kb';
133  if ($whois_status['spacef'] > 1024) $whois_status['spacef'] = round($whois_status['spacef'] / 1024, 1) . ' Mb';
134        $whois_status['Rows']--;
135        $whois_status['url'] = get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php');
136  $template->assign( array( 'WO_status' => $whois_status, ));
137}
138
139// The Radar page
140if (isset($_GET['tab']) and $_GET['tab']=='monitor') {
141        $query_true = 'SELECT `session_id`, `username`
142          FROM '.WHOIS_ONLINE_TABLE.'
143          WHERE `permanent` = \'true\'
144            AND `user_id`<> ' . $conf['guest_id'] . ' AND `IP` <> \'global\';';
145        $result = pwg_query($query_true);
146        $tpl = array();
147        if (!empty($result))
148        {
149                while ($row = mysql_fetch_assoc($result))
150                {
151                        $tpl[$row['session_id']] = $row['username'];
152                }
153        }
154        $template->assign( 'category_option_true', $tpl);
155        $template->assign( 'category_option_true_selected', array());
156
157        $query_false = 'SELECT `session_id`, `username`, `last_access`
158          FROM '.WHOIS_ONLINE_TABLE.'
159          WHERE `permanent` = \'false\'
160            AND `user_id`<> ' . $conf['guest_id'] . ' AND `IP` <> \'global\';';
161        $result = pwg_query($query_false);
162        $tpl = array();
163        $del = array();
164        $six_ago = time()-360;                  // 6 minutes ago
165        if (!empty($result))
166        {
167                while ($row = mysql_fetch_assoc($result))
168                {
169                        $tpl[$row['session_id']] = $row['username'];
170                        if ($row['last_access'] < $six_ago) $del[$row['session_id']] = $row['username'];
171                }
172        }
173        $template->assign( 'category_option_false', $tpl);
174        $template->assign( 'category_option_false_selected', array());
175        $template->assign( 'present_remove', $del);
176        $template->assign( 'present_remove_selected', array());
177}
178
179// Send data
180$template->assign(Array(
181        'Whois_version' => WHOIS_ONLINE_VER,
182        'Whois_path' => WHOIS_ONLINE_PATH,
183        'F_ACTION' => '',
184        'L_CAT_OPTIONS_TRUE' => l10n('Permanent users (3 months min)'),
185        'L_CAT_OPTIONS_FALSE' => l10n('Temporary users (around 72 hours)'),
186));
187$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
188
189if (count($errors) != 0) $template->assign('errors', $errors);
190if (count($infos) != 0) $template->assign('infos', $infos);
191if (isset($_GET['tab']) and $_GET['tab']=='report') {
192  // Once for all, prepare the stupid History search ... (even if History search will recreate it)
193        if (!isset($conf_whois['Search id']) or $conf_whois['Search id'] == 0) {
194          pwg_query('INSERT INTO '.SEARCH_TABLE.'  (rules)
195          VALUES (\''. 
196          'a:1:{s:6:"fields";a:5:{s:10:"date-after";s:10:"2009-09-09";s:11:"date-before";s:10:"2009-09-09";s:5:"types";a:4:{i:0;s:4:"none";i:1;s:7:"picture";i:2;s:4:"high";i:3;s:5:"other";}s:4:"user";s:2:"-1";s:17:"display_thumbnail";s:26:"display_thumbnail_hoverbox";}}'
197          .'\');');
198          $conf_whois['Search id'] = mysql_insert_id();
199                $conf['Whois Online'] = serialize($conf_whois);
200                pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment)
201          VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');");
202        }
203        // Get and Set to current date the stupid History search.
204        list($serialized_rules) = mysql_fetch_row(pwg_query('SELECT rules FROM '.SEARCH_TABLE.'
205          WHERE id = '.$conf_whois['Search id'].';'));
206        $page['search'] = unserialize($serialized_rules);
207        $today = date('Y-m-d');
208        $page['search']['fields']['date-after'] = $today;
209        $page['search']['fields']['date-before'] = $today;
210        pwg_query('REPLACE INTO '.SEARCH_TABLE.'  (id, rules)
211          VALUES (' . $conf_whois['Search id'] . ', \''. serialize($page['search']) .'\');');
212        // Most members ever online was
213        if (!isset($conf_whois['Users']['count']) or $conf_whois['Users']['count'] == 0) {
214                $count = mysql_fetch_assoc(pwg_query('SELECT MAX(`'. $conf['user_fields']['id'] .'`) AS `ctr` FROM ' . USERS_TABLE));
215                $conf_whois['Users']['count'] = $count['ctr'];
216        }
217        //$conf_whois['Users']['Date'] = date('Y-m-d H:i',$conf_whois['Users']['When']);
218        $template->assign(array(
219                'Members' => $conf_whois['Users'],
220                'Whois_url' => WHOIS_ONLINE_PATH,
221                'Whois_Smarty' => 'file:' . dirname(__FILE__),
222        ));
223  // Include reload.php for first request (Filtering is an intrusive jQuery)
224  include_once(WHOIS_ONLINE_PATH.'reload.php');
225}
226
227pwg_debug('*********** Whois configuration ended ***********');
228
229$template->assign('Option', array(
230                'Active' => ($conf_whois['Active']) ? 1 : 0,
231                'Level' => $conf_whois['Delete level'],
232                'Limit' => $conf_whois['Obsolete limit'],
233                'Radar_limit' => $conf_whois['Radar limit'],
234                'Webmasters' => $conf_whois['Webmasters'],
235                'Administrators' => $conf_whois['Administrators'],
236                'Plugins_menu' => ($conf_whois['Add to Plugins menu']) ? 1 : 0,
237                'History_icon' => ($conf_whois['Add icon to History'] or !$conf_whois['Add to Plugins menu']) ? 1 : 0,
238                'Keep_data' => ($conf_whois['Keep data']) ? 1 : 0,
239                'Display' => ($conf_whois['Default display']) ? 1 : 0,
240        ) );
241$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
242
243?>
Note: See TracBrowser for help on using the repository browser.