r23107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23106‎ | r23107 | r23108 >
Date:23:10, 19 June 2007
Author:aaron
Status:old
Tags:
Comment:
*Add wfXFFChainIsSquid(), do not record XFFs just from our squids, kinda floods some results, fix user summary ordering of IPs, mention if an IP is blocked
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -353,11 +353,14 @@
354354 $users_agentsets[$row->cuc_user_text][] = $row->cuc_agent;
355355 }
356356 }
 357+
357358 # Reverse the order so it's first -> last
358 - foreach( $users_infosets as $set )
359 - $set = array_reverse( $set );
360 - foreach( $users_agentsets as $set )
361 - $set = array_reverse( $set );
 359+ foreach( $users_infosets as $name => $set ) {
 360+ $users_infosets[$name] = array_reverse( $set );
 361+ }
 362+ foreach( $users_agentsets as $name => $set ) {
 363+ $users_agentsets[$name] = array_reverse( $set );
 364+ }
362365
363366 $logs = SpecialPage::getTitleFor( 'Log' );
364367 $s = '<ul>';
@@ -477,6 +480,8 @@
478481 $wgOut->addHTML( $s );
479482 return;
480483 }
 484+
 485+ $sk = $wgUser->getSkin();
481486
482487 if( !$this->addLogEntry( time() , $wgUser->getName() ,
483488 "got IPs for" , htmlspecialchars( $user ) , $wgDBname , $reason) )
@@ -499,6 +504,8 @@
500505 $ips_edits[$row->cuc_ip]+=1;
501506 $ips_first[$row->cuc_ip]=$row->cuc_timestamp;
502507 }
 508+
 509+ $logs = SpecialPage::getTitleFor( 'Log' );
503510 $s = '<ul>';
504511 foreach( $ips_edits as $ip => $edits ) {
505512 $s .= '<li>';
@@ -506,6 +513,22 @@
507514 $s .= ' (<a href="' . $blockip->escapeLocalURL( 'ip=' . urlencode( $ip ) ) . '">' . wfMsgHtml('blocklink') . '</a>)';
508515 $s .= ' (' . $wgLang->timeanddate( $ips_first[$ip], true ) . ' -- ' . $wgLang->timeanddate( $ips_last[$ip], true ) . ') ';
509516 $s .= ' <strong>[' . $edits . ']</strong>';
 517+
 518+ # If this IP is blocked, give a link to the block log
 519+ $block = new Block();
 520+ $block->fromMaster( false ); // use slaves
 521+ if( $block->load( $ip, 0 ) ) {
 522+ if( IP::isIPAddress($block->mAddress) && strpos($block->mAddress,'/') ) {
 523+ $userpage = Title::makeTitle( NS_USER, $block->mAddress );
 524+ $blocklog = $sk->makeKnownLinkObj( $logs, wfMsgHtml('blockedtitle'), 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 525+ $s .= ' <strong>(' . $blocklog . ' - ' . $block->mAddress . ')</strong><br/>';
 526+ } else {
 527+ $userpage = Title::makeTitle( NS_USER, $ip );
 528+ $blocklog = $sk->makeKnownLinkObj( $logs, wfMsgHtml('blockedtitle'), 'type=block&page=' . urlencode( $userpage->getPrefixedText() ) );
 529+ $s .= ' <strong>(' . $blocklog . ')</strong><br/>';
 530+ }
 531+ }
 532+
510533 $s .= '</li>';
511534 }
512535 $s .= '</ul>';
Index: trunk/extensions/CheckUser/CheckUser.php
@@ -42,6 +42,8 @@
4343
4444 $xff = wfGetForwardedFor();
4545 list($xff_ip,$trusted) = wfGetClientIPfromXFF( $xff );
 46+ // Our squid XFFs can flood this up sometimes
 47+ $isSquidOnly = wfXFFChainIsSquid( $xff );
4648
4749 $agent = wfGetAgent();
4850
@@ -60,9 +62,9 @@
6163 'cuc_type' => $rc_type,
6264 'cuc_timestamp' => $rc_timestamp,
6365 'cuc_ip' => $ip,
64 - 'cuc_ip_hex' => ($ip) ? IP::toHex( $ip ) : null,
65 - 'cuc_xff' => $xff,
66 - 'cuc_xff_hex' => ($xff_ip) ? IP::toHex( $xff_ip ) : null,
 66+ 'cuc_ip_hex' => $ip ? IP::toHex( $ip ) : null,
 67+ 'cuc_xff' => !$isSquidOnly ? $xff : '',
 68+ 'cuc_xff_hex' => ($xff_ip && !$isSquidOnly) ? IP::toHex( $xff_ip ) : null,
6769 'cuc_agent' => $agent,
6870 ), __METHOD__
6971 );
@@ -117,6 +119,31 @@
118120 return array( $client, $trusted );
119121 }
120122
 123+function wfXFFChainIsSquid( $xff ) {
 124+ global $wgSquidServers, $wgSquidServersNoPurge;
 125+
 126+ if ( !$xff ) false;
 127+ // Avoid annoyingly long xff hacks
 128+ $xff = trim( substr( $xff, 0, 255 ) );
 129+ $squidOnly = true;
 130+ // Check each IP, assuming they are separated by commas
 131+ $ips = explode(',',$xff);
 132+ foreach( $ips as $n => $ip ) {
 133+ $ip = trim($ip);
 134+ // If it is a valid IP, not a hash or such
 135+ if ( IP::isIPAddress($ip) ) {
 136+ if ( $n==0 ) {
 137+ // The first IP should be the client...
 138+ } else if ( !in_array($ip,$wgSquidServers) && !in_array($ip,$wgSquidServersNoPurge) ) {
 139+ $squidOnly = false;
 140+ break;
 141+ }
 142+ }
 143+ }
 144+
 145+ return $squidOnly;
 146+}
 147+
121148 /**
122149 * Tell the parser test engine to create a stub cu_changes table,
123150 * or temporary pages won't save correctly during the test run.

Status & tagging log