Index: trunk/phase3/includes/ProxyTools.php |
— | — | @@ -80,8 +80,6 @@ |
81 | 81 | return $ip; |
82 | 82 | } |
83 | 83 | |
84 | | - $ipchain = array(); |
85 | | - |
86 | 84 | /* collect the originating ips */ |
87 | 85 | # Client connecting to this webserver |
88 | 86 | if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
— | — | @@ -89,30 +87,29 @@ |
90 | 88 | } elseif( $wgCommandLineMode ) { |
91 | 89 | $ip = '127.0.0.1'; |
92 | 90 | } |
93 | | - if( $ip ) { |
94 | | - $ipchain[] = $ip; |
95 | | - } |
96 | 91 | |
97 | | - # Append XFF on to $ipchain |
| 92 | + # Append XFF |
98 | 93 | $forwardedFor = wfGetForwardedFor(); |
99 | | - if ( isset( $forwardedFor ) ) { |
100 | | - $xff = array_map( 'trim', explode( ',', $forwardedFor ) ); |
101 | | - $xff = array_reverse( $xff ); |
102 | | - $ipchain = array_merge( $ipchain, $xff ); |
103 | | - } |
| 94 | + if ( $forwardedFor !== null ) { |
| 95 | + $ipchain = array_map( 'trim', explode( ',', $forwardedFor ) ); |
| 96 | + $ipchain = array_reverse( $ipchain ); |
| 97 | + if ( $ip ) { |
| 98 | + array_unshift( $ipchain, $ip ); |
| 99 | + } |
104 | 100 | |
105 | | - # Step through XFF list and find the last address in the list which is a trusted server |
106 | | - # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) |
107 | | - foreach ( $ipchain as $i => $curIP ) { |
108 | | - $curIP = IP::canonicalize( $curIP ); |
109 | | - if ( wfIsTrustedProxy( $curIP ) ) { |
110 | | - if ( isset( $ipchain[$i + 1] ) ) { |
111 | | - if( $wgUsePrivateIPs || IP::isPublic( $ipchain[$i + 1 ] ) ) { |
112 | | - $ip = $ipchain[$i + 1]; |
| 101 | + # Step through XFF list and find the last address in the list which is a trusted server |
| 102 | + # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) |
| 103 | + foreach ( $ipchain as $i => $curIP ) { |
| 104 | + $curIP = IP::canonicalize( $curIP ); |
| 105 | + if ( wfIsTrustedProxy( $curIP ) ) { |
| 106 | + if ( isset( $ipchain[$i + 1] ) ) { |
| 107 | + if( $wgUsePrivateIPs || IP::isPublic( $ipchain[$i + 1 ] ) ) { |
| 108 | + $ip = $ipchain[$i + 1]; |
| 109 | + } |
113 | 110 | } |
| 111 | + } else { |
| 112 | + break; |
114 | 113 | } |
115 | | - } else { |
116 | | - break; |
117 | 114 | } |
118 | 115 | } |
119 | 116 | |