| 55 | | if (isset($_GET['mini_track_display']) || isset($_GET['mini_track_reset'])) {add_action('bb_init','mini_track_display');} |
|---|
| 56 | | |
|---|
| 57 | | function mini_track($display=0) { |
|---|
| 58 | | global $mini_track_options, $mini_track_done, $mini_track, $bb_current_user; |
|---|
| 59 | | |
|---|
| 60 | | if (isset($mini_track_done)) {return;} $mini_track_done=true; // only run once if manually called |
|---|
| | 64 | if (isset($_GET['mini_track_display']) || isset($_GET['mini_track_reset'])) {add_action('bb_init','mini_track_display',100);} |
|---|
| | 65 | if (isset($_GET['mini_track_ip'])) {add_action('bb_init','mini_track_ip',100);} |
|---|
| | 66 | |
|---|
| | 67 | function mini_track_init() { |
|---|
| | 68 | global $mini_track, $mini_track_options, $mini_track_current, $bb_current_user, $bbdb; |
|---|
| | 69 | $users=0; $members=0; $bots=0; $onpage=0; $names=""; $index=""; $debug=""; |
|---|
| | 70 | $mini_track=bb_get_option('mini_track'); |
|---|
| | 71 | list($index,$debug)=mini_track_index($bb_current_user->ID); |
|---|
| | 72 | |
|---|
| | 73 | // store first seen date when they arrive |
|---|
| | 74 | if (!is_array($mini_track) || !array_key_exists($index,$mini_track)) {$mini_track[$index]->seen=time(); if ($bb_current_user->ID) {@bb_update_usermeta($bb_current_user->ID,'mini_track',date('r'));}} |
|---|
| | 75 | |
|---|
| | 76 | $mini_track[$index]->time=time(); |
|---|
| | 77 | $mini_track[$index]->ip=$_SERVER['REMOTE_ADDR']; |
|---|
| | 78 | $mini_track[$index]->url=$_SERVER['REQUEST_URI']; // this also has some issues with dynamic url cruft but is acceptable |
|---|
| | 79 | $mini_track[$index]->id=$bb_current_user->ID; |
|---|
| | 80 | if ($bb_current_user->ID) {$mini_track[$index]->name=$bb_current_user->data->user_login;} |
|---|
| | 81 | else { |
|---|
| | 82 | // if (eregi($mini_track_options['bots'],$_SERVER['HTTP_USER_AGENT'])) {$mini_track[$index]->bot=1;} |
|---|
| | 83 | $agent=strtolower($_SERVER['HTTP_USER_AGENT']); |
|---|
| | 84 | foreach ($mini_track_options['bots'] as $key=>$name) {if (!(strpos($agent,$name)===false)) {$mini_track[$index]->bot=$key+1; break;}} |
|---|
| | 85 | } // detect/save bots |
|---|
| | 86 | ++$mini_track[$index]->pages; // count how many pages they've viewed |
|---|
| | 87 | |
|---|
| | 88 | $bb_uri=bb_get_option('uri'); $profile=$bb_uri."profile.php?id="; |
|---|
| | 89 | $cutoff=time()-$mini_track_options['track_time']*60; // seconds to consider user "online" |
|---|
| | 90 | |
|---|
| | 91 | if ($mini_track_options['debug']) {$mini_track[$index]->debug=$debug;} // debug |
|---|
| | 92 | |
|---|
| | 93 | foreach ($mini_track as $key=>$value) { |
|---|
| | 94 | if ($value->time<$cutoff) { |
|---|
| | 95 | // store last seen date when they leave |
|---|
| | 96 | if ($value->id) {mini_track_logout($value->id);} |
|---|
| | 97 | unset($mini_track[$key]); |
|---|
| | 98 | } else {$users++; |
|---|
| | 99 | if ($value->id) {$members++; $names.="<a href='$profile$value->id'>$value->name</a>, ";} |
|---|
| | 100 | if (isset($value->bot)) {$bots++;} |
|---|
| | 101 | if ($value->url==$mini_track[$index]->url) {$onpage++;} |
|---|
| | 102 | } |
|---|
| | 103 | } |
|---|
| | 104 | // @bb_update_option('mini_track',$mini_track); // argh stupid bbPress read before write wastes queries |
|---|
| | 105 | // $bbdb->get_var("UPDATE bb_topicmeta SET `meta_value` = '' WHERE topic_id = '0' AND meta_key = 'mini_track' LIMIT 1"); |
|---|
| | 106 | $bbdb->update( $bbdb->topicmeta, array( 'meta_value' => bb_maybe_serialize( $mini_track )), array( 'topic_id' => 0, 'meta_key' => 'mini_track' ) ); |
|---|
| | 107 | |
|---|
| | 108 | // this serialized string will get nasty for more than a few dozen people online |
|---|
| | 109 | $mini_track_current['users']=$users; |
|---|
| | 110 | $mini_track_current['members']=$members; |
|---|
| | 111 | $mini_track_current['bots']=$bots; |
|---|
| | 112 | $mini_track_current['names']=rtrim($names,", "); |
|---|
| | 113 | $mini_track_current['onpage']=$onpage; |
|---|
| | 114 | } // mini_track_init |
|---|
| | 115 | |
|---|
| | 116 | |
|---|
| | 117 | function mini_track($display=0) { |
|---|
| | 118 | global $mini_track, $mini_track_options, $mini_track_current, $mini_track_done; |
|---|
| | 119 | if (isset($mini_track_done)) {return;} $mini_track_done=true; // only run once if manually called |
|---|
| 66 | | $mini_track=bb_get_option('mini_track'); |
|---|
| 67 | | $users=0; $members=0; $bots=0; $onpage=0; $names=""; $index=""; |
|---|
| 68 | | |
|---|
| 69 | | if ($mini_track_options['fast_index']) { |
|---|
| 70 | | $index=ip2long($_SERVER["REMOTE_ADDR"]); // this has some limitations and bugs - disable if you use the next two lines |
|---|
| 71 | | } else { |
|---|
| 72 | | // more advanced indexing technique on the next two lines - disable for speed at expense of no NAT/proxy detection |
|---|
| 73 | | $indexlist=array('REMOTE_ADDR','HTTP_USER_AGENT','HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR','HTTP_FORWARDED','HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM'); |
|---|
| 74 | | foreach ($indexlist as $check) {if (isset($_SERVER[$check])) {$index.=$_SERVER[$check];}} $index=md5($index); |
|---|
| 75 | | } |
|---|
| 76 | | |
|---|
| 77 | | // store first seen date when they arrive |
|---|
| 78 | | if ($bb_current_user->ID && is_array($mini_track) && !array_key_exists($index,$mini_track)) {@bb_update_usermeta($bb_current_user->ID,'mini_track',date('r'));} |
|---|
| 79 | | |
|---|
| 80 | | $mini_track[$index]->time=time(); |
|---|
| 81 | | $mini_track[$index]->url=addslashes(urlencode($_SERVER["REQUEST_URI"])); // this also has some issues with dynamic url cruft but is acceptable |
|---|
| 82 | | $mini_track[$index]->id=$bb_current_user->ID; |
|---|
| 83 | | if ($bb_current_user->ID) {$mini_track[$index]->name=$bb_current_user->data->user_login;} |
|---|
| 84 | | elseif (eregi($mini_track_options['bots'],$_SERVER['HTTP_USER_AGENT'])) {$mini_track[$index]->bot=1;} // detect/save bots |
|---|
| 85 | | ++$mini_track[$index]->pages; // count how many pages they've viewed |
|---|
| 86 | | |
|---|
| 87 | | $bb_uri=bb_get_option('uri'); $profile=$bb_uri."profile.php?id="; |
|---|
| 88 | | $cutoff=time()-$mini_track_options['track_time']*60; // seconds to consider user "online" |
|---|
| 89 | | |
|---|
| 90 | | foreach ($mini_track as $key=>$value) { |
|---|
| 91 | | if ($value->time<$cutoff) { |
|---|
| 92 | | // store last seen date when they leave |
|---|
| 93 | | if ($mini_track[$key]->id) {@bb_update_usermeta($mini_track[$key]->id,'mini_track',date('r',$mini_track[$key]->time));} |
|---|
| 94 | | unset($mini_track[$key]);} |
|---|
| 95 | | else {$users++; |
|---|
| 96 | | if ($value->id) {$members++; $names.="<a href='$profile$value->id'>$value->name</a>, ";} |
|---|
| 97 | | if (isset($value->bot)) {$bots++;} |
|---|
| 98 | | if ($value->url==$mini_track[$index]->url) {$onpage++;} |
|---|
| 99 | | } |
|---|
| 100 | | } |
|---|
| 101 | | |
|---|
| 104 | | echo "<div class='mini_track'>There are <strong>$users</strong> total $start"."users online".$end."."; |
|---|
| 105 | | echo " <strong>$members</strong> of them are members"; |
|---|
| 106 | | if ($members && ($display==2 || $display=="members")) {echo ": ".rtrim($names,", ").".";} else {echo ".";} |
|---|
| 107 | | if ($onpage>1 && !$mini_track_options['show_only_on_front_page']) {echo " <strong>$onpage</strong> of them are on this page.</div>";} |
|---|
| 108 | | } |
|---|
| 109 | | |
|---|
| 110 | | @bb_update_option('mini_track',$mini_track); // this serialized string will get nasty for more than a few dozen people online |
|---|
| | 127 | echo "<div class='mini_track'>There are <strong>".$mini_track_current['users']."</strong> total $start"."users online".$end."."; |
|---|
| | 128 | if ($mini_track_current['onpage']>1 && !$mini_track_options['show_only_on_front_page']) {echo " <strong>".$mini_track_current['onpage']."</strong> of them are on this page.";} |
|---|
| | 129 | if ($mini_track_current['members']>0) {echo " <strong>".$mini_track_current['members']."</strong> of them are members";} |
|---|
| | 130 | if ($mini_track_current['members']>0 && ($display==2 || $display=="members")) {echo ": ".$mini_track_current['names'];} |
|---|
| | 131 | elseif ($mini_track_current['members']>0 && $display==1) {echo ".";} |
|---|
| | 132 | echo "</div>"; |
|---|
| | 133 | } |
|---|
| | 161 | } |
|---|
| | 162 | |
|---|
| | 163 | function mini_track_index($id=0) { |
|---|
| | 164 | global $mini_track_options; |
|---|
| | 165 | $id=intval($id); |
|---|
| | 166 | if ($mini_track_options['fast_index']) { |
|---|
| | 167 | $index=ip2long($_SERVER['REMOTE_ADDR']); // this has some limitations |
|---|
| | 168 | } else { |
|---|
| | 169 | // more advanced indexing technique on the next two lines - disable for speed at expense of no NAT/proxy detection |
|---|
| | 170 | $indexlist=array('REMOTE_ADDR','HTTP_USER_AGENT','HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR','HTTP_FORWARDED','HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM'); |
|---|
| | 171 | $meta=$id; foreach ($indexlist as $check) {if (isset($_SERVER[$check])) {$meta.=" ".$_SERVER[$check];}} $index=md5($meta); |
|---|
| | 172 | } |
|---|
| | 173 | // $array['index']=$index; $array['debug']=$meta; return $array; |
|---|
| | 174 | return array($index,$meta); |
|---|
| 169 | | function mini_track_activation() {bb_update_option('mini_track',array());} |
|---|
| | 208 | function mini_track_activation() {global $mini_track,$mini_track_done; unset($mini_track_done); $mini_track=array(); @bb_update_option('mini_track',$mini_track);} |
|---|
| | 209 | |
|---|
| | 210 | function mini_track_logout($id=0) { |
|---|
| | 211 | global $mini_track, $bb_current_user; |
|---|
| | 212 | $mini_track=bb_get_option('mini_track'); |
|---|
| | 213 | if (!$id) {$id=$bb_current_user->ID;} |
|---|
| | 214 | if ($id) { |
|---|
| | 215 | foreach ($mini_track as $key=>$value) { |
|---|
| | 216 | if ($value->id==$id) {@bb_update_usermeta($value->id,'mini_track',date('r',$value->time)); unset($mini_track[$key]); @bb_update_option('mini_track',$mini_track); break;} |
|---|
| | 217 | } |
|---|
| | 218 | } |
|---|
| | 219 | } |
|---|
| | 220 | function mini_track_login($id=0) { |
|---|
| | 221 | global $mini_track; |
|---|
| | 222 | $mini_track=bb_get_option('mini_track'); |
|---|
| | 223 | list($index,$debug)=mini_track_index(0); unset($mini_track[$index]); // remove the entity with same info but 0 user id |
|---|
| | 224 | @bb_update_option('mini_track',$mini_track); |
|---|
| | 225 | } |
|---|
| | 226 | |
|---|
| | 227 | function mini_track_ip(){ |
|---|
| | 228 | if (!bb_current_user_can('administrate') || !$_GET['mini_track_ip']) {return;} |
|---|
| | 229 | $ip=$_GET['mini_track_ip']; $rdns=gethostbyaddr($ip); if ($rdns==$ip) {$rdns="(no rDNS)";} |
|---|
| | 230 | echo "<html><pre><h2>IP ".$ip."</h2><h3>".$rdns."</h3>"; |
|---|
| | 231 | $data=mini_track_ip_lookup($ip); |
|---|
| | 232 | foreach ($data as $key=>$value) { |
|---|
| | 233 | if (eregi("abuse|tech|nettype|comment|remark|ReferralServer|signature|auth|encryption",$key)===false) {echo "$key: $value <br />";} |
|---|
| | 234 | } |
|---|
| | 235 | exit(); |
|---|
| | 236 | } |
|---|
| | 237 | |
|---|
| | 238 | function mini_track_ip_lookup($ip,$server=0){ |
|---|
| | 239 | $host=array('ws.arin.net','wq.apnic.net','www.db.ripe.net','lacnic.net','www.afrinic.net'); |
|---|
| | 240 | $keyword=array('arin.net','apnic.net','ripe.net','lacnic.net','afrinic.net'); |
|---|
| | 241 | $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='); |
|---|
| | 242 | do {unset($data); |
|---|
| | 243 | if ($fp = fsockopen ($host[$server], 80, &$errno, &$errstr, 10)) { |
|---|
| | 244 | $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"; |
|---|
| | 245 | $page=''; fputs ($fp, $request); while (!feof($fp)) {$page.=fgets ($fp,1024);} fclose ($fp); // echo $page; |
|---|
| | 246 | preg_match("/\<pre\>(.*)\<\/pre\>/sim",$page,$temp); $lines=explode("\n",strip_tags($temp[0])); |
|---|
| | 247 | foreach ($lines as $line) {$line=trim($line);if ((!ereg('^\#|\%.*$',$line)) && ($line>'')) {$temp=explode(":",$line,2); $data[trim($temp[0])] = trim($temp[1]);}} |
|---|
| | 248 | } else {$data['error'] = "$errstr ($errno)\n";} |
|---|
| | 249 | $server=0; for ($i = 1; $i <= count($host); $i++){if (strpos($data['ReferralServer'],$keyword[$i])){$server=$i;break;}} |
|---|
| | 250 | } while ($server>0); |
|---|
| | 251 | return $data; |
|---|
| | 252 | } |
|---|