[3319] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /* Whois online Configuration, Radar and cleaning */ |
---|
| 4 | |
---|
| 5 | /* |
---|
| 6 | TODO list: |
---|
[9145] | 7 | - User comments… (Delete all comments or partial delete) |
---|
[3319] | 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!'); |
---|
[3340] | 16 | global $conf, $conf_whois, $lang; |
---|
[3695] | 17 | $conf['show_gt'] = true; |
---|
[3319] | 18 | load_language('plugin.lang', WHOIS_ONLINE_PATH); |
---|
| 19 | |
---|
| 20 | pwg_debug('*********** Whois configuration ***********'); |
---|
| 21 | |
---|
[3340] | 22 | if (!isset($conf_whois['Active'])) $conf_whois = whois_online_conf(); |
---|
[3319] | 23 | $errors = array(); |
---|
| 24 | $infos = array(); |
---|
[6214] | 25 | add_event_handler('loc_end_admin', 'whois_select_menu' ); |
---|
[3319] | 26 | |
---|
| 27 | // Get Current data |
---|
| 28 | $conf['Whois Online Update'] = false; |
---|
| 29 | whois_online_management(); |
---|
| 30 | |
---|
| 31 | $template->set_filenames(array( |
---|
| 32 | 'plugin_admin_content' => dirname(__FILE__) . '/config.tpl', |
---|
| 33 | 'double_select' => 'double_select.tpl' |
---|
| 34 | )); |
---|
| 35 | |
---|
[9145] | 36 | if (!defined('ROOT_URL')) |
---|
| 37 | define( 'ROOT_URL', get_root_url().'/' ); |
---|
| 38 | |
---|
| 39 | $WHOIS_PATH_ABS=str_replace('\\','/',dirname(__FILE__) ); |
---|
| 40 | if (!defined('WHOIS_PATH_ABS')) |
---|
| 41 | define( |
---|
| 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 | |
---|
[3319] | 58 | // Tabsheets |
---|
| 59 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
| 60 | $_url = get_admin_plugin_menu_link(__FILE__); |
---|
| 61 | if (!isset($_GET['tab'])) $page['tab'] = 'config'; |
---|
| 62 | else $page['tab'] = $_GET['tab']; |
---|
| 63 | |
---|
| 64 | $tabsheet = new tabsheet(); |
---|
| 65 | $tabsheet->add('config', l10n('config'), $_url.'&tab=config'); |
---|
| 66 | $tabsheet->add('monitor', l10n('Monitor'), $_url.'&tab=monitor'); |
---|
| 67 | $tabsheet->add('report', l10n('Report'), $_url.'&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 |
---|
| 75 | if ($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 | // Submit and Advisor => Thanks |
---|
| 102 | if ( $sub and is_adviser() ) |
---|
| 103 | array_push($infos, l10n('You are Adviser and you are not authorized to change this configuration.')); |
---|
| 104 | |
---|
| 105 | // Submit and not Advisor => Update Config table |
---|
| 106 | if ( $sub and count($errors) == 0 and $_POST['from']=='config' and !is_adviser()) { |
---|
| 107 | if ( $conf['Whois Online'] != serialize($conf_whois) ) { |
---|
[3695] | 108 | $conf['Whois Online'] = serialize($conf_whois); |
---|
[3319] | 109 | pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) |
---|
[3695] | 110 | VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); |
---|
[3319] | 111 | array_push($infos, l10n('Configuration has been saved.')); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | // Switch users on right side (=> Temporary) |
---|
| 116 | if ( isset($_POST['falsify']) and !is_adviser() |
---|
| 117 | and count($errors) == 0 and $_POST['from']=='monitor' |
---|
| 118 | and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) { |
---|
| 119 | pwg_query('UPDATE '.WHOIS_ONLINE_TABLE.' |
---|
| 120 | SET `permanent` = \'false\' |
---|
| 121 | WHERE `session_id` IN ("'.implode('","', $_POST['cat_true']).'");'); |
---|
| 122 | } |
---|
| 123 | // Switch users on left side (Permanent <=) |
---|
| 124 | if ( isset($_POST['trueify']) and !is_adviser() |
---|
| 125 | and count($errors) == 0 and $_POST['from']=='monitor' |
---|
| 126 | and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) { |
---|
| 127 | pwg_query('UPDATE '.WHOIS_ONLINE_TABLE.' |
---|
| 128 | SET `permanent` = \'true\' |
---|
| 129 | WHERE `session_id` IN ("'.implode('","', $_POST['cat_false']).'");'); |
---|
| 130 | } |
---|
| 131 | // Delete users from > 24 h temporary list |
---|
| 132 | if ( isset($_POST['prs_delete']) and !is_adviser() |
---|
| 133 | and count($errors) == 0 and $_POST['from']=='monitor' |
---|
| 134 | and isset($_POST['prs_remove']) and count($_POST['prs_remove']) > 0) { |
---|
| 135 | pwg_query('DELETE FROM '.WHOIS_ONLINE_TABLE.' |
---|
| 136 | WHERE `permanent` = \'false\' |
---|
| 137 | AND `session_id` IN ("'.implode('","', $_POST['prs_remove']).'");'); |
---|
| 138 | } |
---|
| 139 | // Compress it! |
---|
| 140 | if ( isset($_GET['check']) and !is_adviser() ) { |
---|
| 141 | pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `last_access` < ' . (time() - (3*24*60*60)) . ' |
---|
| 142 | AND `permanent` = \'false\' AND `IP` <> \'global\';'); |
---|
| 143 | pwg_query('CHECK TABLE '.WHOIS_ONLINE_TABLE); |
---|
| 144 | pwg_query('OPTIMIZE TABLE '.WHOIS_ONLINE_TABLE); |
---|
| 145 | } |
---|
| 146 | // The whois_online table summary |
---|
| 147 | if (isset($_GET['tab']) and $_GET['tab']=='monitor') { |
---|
[21237] | 148 | $whois_status = pwg_db_fetch_assoc(pwg_query('SHOW TABLE STATUS LIKE "' . WHOIS_ONLINE_TABLE .'%" ;')); |
---|
[3319] | 149 | $whois_status['table'] = WHOIS_ONLINE_TABLE; |
---|
| 150 | $whois_status['size'] = ($whois_status['Data_length'] + $whois_status['Index_length']) . ' bytes'; |
---|
| 151 | if ($whois_status['size'] > 1024) $whois_status['size'] = round($whois_status['size'] / 1024, 1) . ' Kb'; |
---|
| 152 | if ($whois_status['size'] > 1024) $whois_status['size'] = round($whois_status['size'] / 1024, 1) . ' Mb'; |
---|
| 153 | $whois_status['spacef'] = $whois_status['Data_free'] . ' bytes'; |
---|
| 154 | if ($whois_status['spacef'] > 1024) $whois_status['spacef'] = round($whois_status['spacef'] / 1024, 1) . ' Kb'; |
---|
| 155 | if ($whois_status['spacef'] > 1024) $whois_status['spacef'] = round($whois_status['spacef'] / 1024, 1) . ' Mb'; |
---|
| 156 | $whois_status['Rows']--; |
---|
| 157 | $whois_status['url'] = get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php'); |
---|
| 158 | $template->assign( array( 'WO_status' => $whois_status, )); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // The Radar page |
---|
| 162 | if (isset($_GET['tab']) and $_GET['tab']=='monitor') { |
---|
| 163 | $query_true = 'SELECT `session_id`, `username` |
---|
| 164 | FROM '.WHOIS_ONLINE_TABLE.' |
---|
| 165 | WHERE `permanent` = \'true\' |
---|
| 166 | AND `user_id`<> ' . $conf['guest_id'] . ' AND `IP` <> \'global\';'; |
---|
| 167 | $result = pwg_query($query_true); |
---|
| 168 | $tpl = array(); |
---|
| 169 | if (!empty($result)) |
---|
| 170 | { |
---|
[21237] | 171 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[3319] | 172 | { |
---|
| 173 | $tpl[$row['session_id']] = $row['username']; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | $template->assign( 'category_option_true', $tpl); |
---|
| 177 | $template->assign( 'category_option_true_selected', array()); |
---|
| 178 | |
---|
| 179 | $query_false = 'SELECT `session_id`, `username`, `last_access` |
---|
| 180 | FROM '.WHOIS_ONLINE_TABLE.' |
---|
| 181 | WHERE `permanent` = \'false\' |
---|
| 182 | AND `user_id`<> ' . $conf['guest_id'] . ' AND `IP` <> \'global\';'; |
---|
| 183 | $result = pwg_query($query_false); |
---|
| 184 | $tpl = array(); |
---|
| 185 | $del = array(); |
---|
| 186 | $six_ago = time()-360; // 6 minutes ago |
---|
| 187 | if (!empty($result)) |
---|
| 188 | { |
---|
[21237] | 189 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[3319] | 190 | { |
---|
| 191 | $tpl[$row['session_id']] = $row['username']; |
---|
| 192 | if ($row['last_access'] < $six_ago) $del[$row['session_id']] = $row['username']; |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | $template->assign( 'category_option_false', $tpl); |
---|
| 196 | $template->assign( 'category_option_false_selected', array()); |
---|
| 197 | $template->assign( 'present_remove', $del); |
---|
| 198 | $template->assign( 'present_remove_selected', array()); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | // Send data |
---|
| 202 | $template->assign(Array( |
---|
| 203 | 'Whois_version' => WHOIS_ONLINE_VER, |
---|
| 204 | 'Whois_path' => WHOIS_ONLINE_PATH, |
---|
| 205 | 'F_ACTION' => '', |
---|
| 206 | 'L_CAT_OPTIONS_TRUE' => l10n('Permanent users (3 months min)'), |
---|
| 207 | 'L_CAT_OPTIONS_FALSE' => l10n('Temporary users (around 72 hours)'), |
---|
| 208 | )); |
---|
| 209 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
| 210 | |
---|
| 211 | if (count($errors) != 0) $template->assign('errors', $errors); |
---|
| 212 | if (count($infos) != 0) $template->assign('infos', $infos); |
---|
| 213 | if (isset($_GET['tab']) and $_GET['tab']=='report') { |
---|
| 214 | // Once for all, prepare the stupid History search ... (even if History search will recreate it) |
---|
| 215 | if (!isset($conf_whois['Search id']) or $conf_whois['Search id'] == 0) { |
---|
| 216 | pwg_query('INSERT INTO '.SEARCH_TABLE.' (rules) |
---|
| 217 | VALUES (\''. |
---|
| 218 | '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";}}' |
---|
| 219 | .'\');'); |
---|
[21237] | 220 | $conf_whois['Search id'] = pwg_db_insert_id(); |
---|
[3319] | 221 | $conf['Whois Online'] = serialize($conf_whois); |
---|
| 222 | pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) |
---|
| 223 | VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); |
---|
| 224 | } |
---|
| 225 | // Get and Set to current date the stupid History search. |
---|
[21237] | 226 | list($serialized_rules) = pwg_db_fetch_row(pwg_query('SELECT rules FROM '.SEARCH_TABLE.' |
---|
[3319] | 227 | WHERE id = '.$conf_whois['Search id'].';')); |
---|
| 228 | $page['search'] = unserialize($serialized_rules); |
---|
| 229 | $today = date('Y-m-d'); |
---|
| 230 | $page['search']['fields']['date-after'] = $today; |
---|
| 231 | $page['search']['fields']['date-before'] = $today; |
---|
| 232 | pwg_query('REPLACE INTO '.SEARCH_TABLE.' (id, rules) |
---|
| 233 | VALUES (' . $conf_whois['Search id'] . ', \''. serialize($page['search']) .'\');'); |
---|
| 234 | // Most members ever online was |
---|
| 235 | if (!isset($conf_whois['Users']['count']) or $conf_whois['Users']['count'] == 0) { |
---|
[21237] | 236 | $count = pwg_db_fetch_assoc(pwg_query('SELECT MAX(`'. $conf['user_fields']['id'] .'`) AS `ctr` FROM ' . USERS_TABLE)); |
---|
[3319] | 237 | $conf_whois['Users']['count'] = $count['ctr']; |
---|
| 238 | } |
---|
| 239 | //$conf_whois['Users']['Date'] = date('Y-m-d H:i',$conf_whois['Users']['When']); |
---|
| 240 | $template->assign(array( |
---|
| 241 | 'Members' => $conf_whois['Users'], |
---|
| 242 | 'Whois_url' => WHOIS_ONLINE_PATH, |
---|
[6193] | 243 | 'Whois_Smarty' => 'file:' . dirname(__FILE__), |
---|
[3319] | 244 | )); |
---|
| 245 | // Include reload.php for first request (Filtering is an intrusive jQuery) |
---|
| 246 | include_once(WHOIS_ONLINE_PATH.'reload.php'); |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | pwg_debug('*********** Whois configuration ended ***********'); |
---|
| 250 | |
---|
| 251 | $template->assign('Option', array( |
---|
| 252 | 'Active' => ($conf_whois['Active']) ? 1 : 0, |
---|
| 253 | 'Level' => $conf_whois['Delete level'], |
---|
| 254 | 'Limit' => $conf_whois['Obsolete limit'], |
---|
| 255 | 'Radar_limit' => $conf_whois['Radar limit'], |
---|
| 256 | 'Webmasters' => $conf_whois['Webmasters'], |
---|
| 257 | 'Administrators' => $conf_whois['Administrators'], |
---|
| 258 | 'Plugins_menu' => ($conf_whois['Add to Plugins menu']) ? 1 : 0, |
---|
[6201] | 259 | 'History_icon' => ($conf_whois['Add icon to History'] or !$conf_whois['Add to Plugins menu']) ? 1 : 0, |
---|
[3319] | 260 | 'Keep_data' => ($conf_whois['Keep data']) ? 1 : 0, |
---|
| 261 | 'Display' => ($conf_whois['Default display']) ? 1 : 0, |
---|
| 262 | ) ); |
---|
| 263 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 264 | |
---|
| 265 | ?> |
---|