source: extensions/whois_online/config.php

Last change on this file was 32643, checked in by plg, 2 years ago

slightly modernized code for compatibility with Piwigo 12

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