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