Changeset 1291
- Timestamp:
- 08/16/08 19:26:06 (4 months ago)
- Files:
-
- mini-track/trunk/mini-track-admin.php (modified) (4 diffs)
- mini-track/trunk/mini-track.php (modified) (9 diffs)
- mini-track/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mini-track/trunk/mini-track-admin.php
r1288 r1291 15 15 16 16 if (isset($_GET['mini_track_reset'])) {mini_track_activation(); mini_track_init();} 17 elseif (isset($_GET['mini_track_ban']) && isset($mini_track[$_GET['mini_track_ban']])) {$mini_track[$_GET['mini_track_ban']]->ban=1; mini_track_save();}18 elseif (isset($_GET['mini_track_unban']) && isset($mini_track[$_GET['mini_track_unban']])) {unset($mini_track[$_GET['mini_track_unban']]->ban); mini_track_save();}17 elseif (isset($_GET['mini_track_ban']) && isset($mini_track[$_GET['mini_track_ban']])) {$mini_track[$_GET['mini_track_ban']]->ban=1; $mini_track[$_GET['mini_track_ban']]->ok=0; mini_track_save();} 18 elseif (isset($_GET['mini_track_unban']) && isset($mini_track[$_GET['mini_track_unban']])) {unset($mini_track[$_GET['mini_track_unban']]->ban); $mini_track[$_GET['mini_track_unban']]->ok=1; mini_track_save();} 19 19 bb_send_headers(); 20 20 echo "<html><head><title>".count($mini_track)." Users Online « ".bb_get_option('name')."</title> … … 63 63 $actual[7][$counter]=$time-$value->time; 64 64 65 if (isset($value->ban)) {$td[8][$counter]="<span class=bot>banned</span> [<a href='$uri"."&mini_track_unban=$key'>x</a>]";} 65 if (isset($value->ok) && $value->ok && isset($value->bot)) {$td[8][$counter]="<span class=new>verified</span>";} 66 elseif (isset($value->ban)) {$td[8][$counter]="<span class=bot>banned</span> [<a href='$uri"."&mini_track_unban=$key'>x</a>]";} 66 67 elseif ($value->pages>9 && $bb_current_user->ID!=$value->id) {$td[8][$counter]="<a href='$uri"."&mini_track_ban=$key'>ban?</a>";} 67 68 elseif ($value->pages<3 && $total<2 && $last<2) {$td[8][$counter]="<span class=new>new</span>";} … … 107 108 if (!bb_current_user_can('administrate') || !$_GET['mini_track_ip']) {return;} 108 109 $ip=$_GET['mini_track_ip']; $rdns=gethostbyaddr($ip); if ($rdns==$ip) {$rdns="(no rDNS)";} 110 bb_send_headers(); 109 111 echo "<html><pre><h2>IP ".$ip."</h2><h3>".$rdns."</h3>"; 110 $data=mini_track_ip_lookup($ip); 111 foreach ($data as $key=>$value) { 112 if (eregi("abuse|tech|nettype|comment|remark|ReferralServer|signature|auth|encryption",$key)===false) {echo "$key: $value <br />";} 113 } 112 $data=mini_track_ip_lookup($ip); 113 if (!isset($data) || !is_array($data)) {echo "<small>reloading...</small><br />"; sleep(1); $data=mini_track_ip_lookup($ip);} // try a 2nd time before giving up 114 if (isset($data) && is_array($data)) { 115 foreach ($data as $key=>$value) { 116 if (eregi("abuse|tech|nettype|comment|remark|ReferralServer|signature|auth|encryption",$key)===false) { 117 if (intval($key)===$key) {echo "$value <br />";} else {echo "$key: <b>$value</b><br />";} 118 } 119 } 120 } else {echo "lookup error, <a href='?mini_track_ip=$ip'>try again?</a>";} 114 121 exit(); 115 122 } … … 117 124 function mini_track_ip_lookup($ip,$server=0) { 118 125 if (!bb_current_user_can('administrate') || !$_GET['mini_track_ip']) {return;} 126 // error_reporting(E_ALL); ini_set("display_errors", 1); // debug 119 127 $host=array('ws.arin.net','wq.apnic.net','www.db.ripe.net','lacnic.net','www.afrinic.net'); 120 128 $keyword=array('arin.net','apnic.net','ripe.net','lacnic.net','afrinic.net'); 121 129 $path=array('/whois/?queryinput=','/apnic-bin/whois.pl?searchtext=','/whois/?form_type=simple&searchtext=','/cgi-bin/lacnic/whois?query=','/cgi-bin/whois?form_type=simple&searchtext='); 122 do {unset($data); 130 do {unset($data); $data=""; 123 131 if ($fp = fsockopen ($host[$server], 80, &$errno, &$errstr, 10)) { 124 132 $request = "GET $path[$server]$ip HTTP/1.0\r\nHost: $host[$server]\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n\r\n"; 125 $page=''; fputs ($fp, $request); while (!feof($fp)) {$page.=fgets ($fp,1024);} fclose ($fp); // echo $page; 126 preg_match("/\<pre\>(.*)\<\/pre\>/sim",$page,$temp); $lines=explode("\n",strip_tags($temp[0])); 127 foreach ($lines as $line) {$line=trim($line);if ((!ereg('^\#|\%.*$',$line)) && ($line>'')) {$temp=explode(":",$line,2); $data[trim($temp[0])] = trim($temp[1]);}} 133 $page=''; fputs ($fp, $request); while (!feof($fp)) {$page.=fgets ($fp,1024);} fclose ($fp); // echo $page; // debug 134 preg_match("/\<pre\>(.*)\<\/pre\>/sim",$page,$temp); $lines=explode("\n",strip_tags($temp[0])); // print_r($temp); // debug 135 foreach ($lines as $line) {$line=trim($line); 136 if (!empty($line) && !ereg("^(\#|\%)",$line)) {if (strpos($line,":")) {$temp=explode(":",$line,2); $data[trim($temp[0])] = trim($temp[1]);} else {$data[]=$line;}} 137 } 128 138 } else {$data['error'] = "$errstr ($errno)\n";} 129 139 $server=0; for ($i = 1; $i <= count($host); $i++){if (isset($data['ReferralServer']) && strpos($data['ReferralServer'],$keyword[$i])){$server=$i;break;}} mini-track/trunk/mini-track.php
r1289 r1291 6 6 Author: _ck_ 7 7 Author URI: http://bbShowcase.org 8 Version: 0.1. 58 Version: 0.1.6 9 9 10 10 License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ … … 38 38 $mini_track_options['fast_index'] = false; // false = accurately tracks NAT/proxy/spoofing users // true = faster but by IP only 39 39 40 $mini_track_options['ban_speed'] = 50; // temporarily ban any user for the track_time if they exceed this many pages per minute 41 // (not recommended to set this lower than 50 ppm because some bots like google move that fast) 40 $mini_track_options['ban_speed'] = 50; // temporarily ban any user for the track_time if they exceed this many pages per minute 42 41 // set to 0 (zero) to disable. 43 $mini_track_options['ban_pages'] = 200; // temporarily ban any user for the track_time if they exceed this many pages in a single session 44 // (not recommended to set this lower than 200 because some bots like google take that many at once) 42 $mini_track_options['ban_pages'] = 100; // temporarily ban any user for the track_time if they exceed this many pages in a single session 45 43 // set to 0 (zero) to disable. 46 44 47 // you will be able to also temporarily ban (or unban) via the realtime display panel 45 // good bots like google are now verified by rdns when they exceed bans and are whitelisted 46 // you can also temporarily ban (or unban) via the realtime display panel 48 47 // note about banning: it still loads the bbPress core, just doesn't serve any content 49 48 $mini_track_options['style']=" … … 60 59 /* STOP EDITING HERE */ 61 60 62 $mini_track_options['geoip'] = false; // false; // "ip2c"; // cc lookup -> false | mysql | ip2c 63 $mini_track_options['flags'] = false; // false; // "/images/flags/"; // images instead of cc - path to flags 61 $mini_track_options['topic_views'] = false; // true = replace bb-topic-views plugin, works better as no sessions needed 62 63 $mini_track_options['geoip'] = false; // "ip2c"; // cc lookup -> false | mysql | ip2c 64 $mini_track_options['flags'] = false; // "/images/flags/"; // images instead of cc - path to flags 64 65 65 66 $mini_track_options['debug'] = false; // true = shows more info when you hover over IP in display panel - makes saved data very large, don't use regularly … … 86 87 87 88 // hooks and triggers 88 add_action('bb_init','mini_track_init' );89 add_action('bb_init','mini_track_init',9); // 9 so it runs before most other plugins execute 89 90 add_action('bb_foot','mini_track',99); 90 91 add_action('bb_admin_footer', 'mini_track',99); … … 102 103 add_action('user_register','mini_track_statistics_update'); 103 104 104 105 105 // admin hooks 106 106 if (defined('BB_IS_ADMIN') && BB_IS_ADMIN && isset($_GET['action']) && $_GET['action']=="activate" && $_GET['plugin'] && strpos($_GET['action'],basename(__FILE__)) ) { … … 115 115 116 116 function mini_track_init() { 117 global $mini_track, $mini_track_options, $mini_track_current, $bb_current_user, $bbdb; 118 117 global $mini_track, $mini_track_options, $mini_track_current, $bb_current_user, $bbdb, $topic_id; 118 119 $time=time(); // snapshot time for all calculations 119 120 $mini_track=bb_get_option('mini_track'); // start with latest data from db 120 $time=time(); // snapshot time for all calculations 121 122 if ($mini_track_options['topic_views']) { // remove bb-topic-views hook as to not duplicate counts or start sessions 123 remove_filter('bb_head', 'update_view_count'); 124 remove_action('bb_init', 'views_session_check'); 125 } 121 126 122 127 if (!empty($mini_track)) { … … 164 169 $mini_track[$index]->pages=1; 165 170 } // end of first seen checks 166 else { 171 172 else { // repeat user 173 167 174 $mini_track[$index]->pages++; // count how many pages they've viewed 168 175 169 176 // check for ban-able activity 177 if (!isset($mini_track[$index]->ban) && !(isset($mini_track[$index]->ok) && $mini_track[$index]->ok)) { 170 178 $active=$time - $mini_track[$index]->seen; // seconds active 171 if ($mini_track[$index]->pages>30 && $active>30 && !($bb_current_user->ID && bb_current_user_can('administrate'))) { 172 if ($mini_track_options['ban_speed'] && ($mini_track[$index]->pages/$active)>$mini_track_options['ban_speed']/60) {$mini_track[$index]->ban=1;} 173 if ($mini_track_options['ban_pages'] && $mini_track[$index]->pages>$mini_track_options['ban_pages']) {$mini_track[$index]->ban=1;} 179 if ( $mini_track[$index]->pages>30 && $active>30 && !($bb_current_user->ID && bb_current_user_can('administrate'))) { 180 if ($mini_track_options['ban_speed'] && ($mini_track[$index]->pages/$active)>$mini_track_options['ban_speed']/60) {$mini_track[$index]->ban=1;} 181 if ($mini_track_options['ban_pages'] && $mini_track[$index]->pages>$mini_track_options['ban_pages']) {$mini_track[$index]->ban=1;} 182 if ($mini_track[$index]->ban==1 && !isset($mini_track[$index]->ok)) { 183 $mini_track[$index]->ok=((mini_track_verify($mini_track[$index]->ip)) ? 1 : 0); // check if it's a legit bot 184 if ($mini_track[$index]->ok) {unset($mini_track[$index]->ban);} // if so, let it through 185 } 174 186 } 187 } 175 188 176 189 } // end repeat user 177 190 178 191 $mini_track[$index]->time=$time; 179 $mini_track[$index]->url=mini_track_safe_url($_SERVER['REQUEST_URI']); // current page 180 if ($mini_track_options['debug']) {$mini_track[$index]->debug=$debug;} // save debug info if in debug mode 192 $mini_track[$index]->url=mini_track_safe_url($_SERVER['REQUEST_URI']); // current page 193 if ($mini_track_options['debug']) {$mini_track[$index]->debug=$debug;} // save debug info if in debug mode 194 195 if ($mini_track_options['topic_views'] && is_topic()) { // for topic view counts, replacing bb-topic-views plugin 196 bb_repermalink(); 197 if (empty($mini_track[$index]->topic) || $topic_id!=$mini_track[$index]->topic) {mini_track_update_view_count(); $mini_track[$index]->topic=$topic_id;} 198 } 181 199 182 200 // tally new tracking data for all users … … 254 272 } 255 273 274 function mini_track_update_view_count() { // all this to prevent bbPress's read-before-write on meta data :-( 275 global $topic, $bb_topic_cache, $bbdb; 276 if (empty($topic) || empty($topic->topic_id)) {return;} // should never happen but just in case to prevent corrupt data 277 if (empty($topic->views)) { // it's a new value to insert, never used before, use post count as initial view count 278 if (bb_get_option('bb_db_version')>1600) {@$bbdb->query("INSERT INTO $bbdb->meta (object_id, object_type, meta_key, meta_value) VALUES ($topic->topic_id, 'bb_topic', 'views', $topic->topic_posts)");} 279 else {@$bbdb->query("INSERT INTO $bbdb->topicmeta (topic_id, meta_key, meta_value) VALUES ($topic->topic_id, 'views', $topic->topic_posts)");} 280 $topic->views=$topic->posts; $bb_topic_cache[$topic->topic_id]->views=$topic->posts; 281 } else { // update existing value: we don't force a specific value just in case there's a collision with another user viewing the topic since it was loaded 282 if (bb_get_option('bb_db_version')>1600) {@$bbdb->query("UPDATE $bbdb->meta SET meta_value=meta_value+1 WHERE object_type='bb_topic' AND object_id=$topic->topic_id AND meta_key='views' LIMIT 1");} 283 else {@$bbdb->query("UPDATE $bbdb->topicmeta SET meta_value=meta_value+1 WHERE topic_id=$topic->topic_id AND meta_key='views' LIMIT 1");} 284 $topic->views++; $bb_topic_cache[$topic->topic_id]->views++; 285 } 286 } 287 256 288 function mini_track_index($id=0) { 257 289 global $mini_track_options; … … 274 306 return $_SERVER['HTTP_X_FORWARDED_FOR']; 275 307 } else {return $_SERVER['REMOTE_ADDR'];} 308 } 309 310 function mini_track_verify_addr($ip=0) { 311 if ($rdns=gethostbyaddr($ip) && $rdns!=$ip) { 312 if (eregi("\.(msn\.com|alexa\.com|yahoo\.net|google\.com|googlebot\.com)$",$rdns)) {return true;} 313 } 314 return false; 276 315 } 277 316 mini-track/trunk/readme.txt
r1286 r1291 141 141 * temporary ban ability (with automatic/manual action) 142 142 143 = Version 0.1.6 (2008-08-16) = 144 145 * bot verification via rdns to allow excessive page counts 146 147 * can replace the view count function of bb-topic-views without using sessions 148 143 149 == To Do == 144 150
