Index: trunk/extensions/HoneypotIntegration/HoneypotIntegration.php |
— | — | @@ -31,7 +31,8 @@ |
32 | 32 | $wgHooks['GetUserPermissionsErrorsExpensive'][] = |
33 | 33 | 'HoneypotIntegration::onGetUserPermissionsErrorsExpensive'; |
34 | 34 | |
35 | | -$wgHoneypotURLs = array( 'http://www.google.com' ); |
| 35 | +$wgHoneypotURLSource = ''; |
| 36 | + |
36 | 37 | $wgHoneypotTemplates = array( |
37 | 38 | '<a href="honeypoturl"><!-- randomtext --></a>', |
38 | 39 | ); |
— | — | @@ -40,6 +41,3 @@ |
41 | 42 | |
42 | 43 | $wgHoneypotDataFile = false; |
43 | 44 | |
44 | | -if ( !extension_loaded( 'fss' ) ) { |
45 | | - die( "FastStringSearch is required for Project Honeypot Integration" ); |
46 | | -} |
Index: trunk/extensions/HoneypotIntegration/HoneypotIntegration.class.php |
— | — | @@ -33,12 +33,41 @@ |
34 | 34 | $out->addHTML( self::generateHoneypotLink( $randomText ) ); |
35 | 35 | return 1; |
36 | 36 | } |
| 37 | + |
| 38 | + public static function getHoneypotURLs() { |
| 39 | + $key = wfMemcKey( 'honeypot-integration-urls' ); |
| 40 | + |
| 41 | + global $wgMemc; |
| 42 | + $urls = $wgMemc->get( $key ); |
| 43 | + |
| 44 | + if ( is_array($urls) ) { |
| 45 | + return $urls; |
| 46 | + } |
| 47 | + |
| 48 | + global $wgHoneypotAutoLoad; |
| 49 | + if (!$wgHoneypotAutoLoad) |
| 50 | + return array( 'http://www.google.com' ); // Dummy URL |
| 51 | + |
| 52 | + global $wgHoneypotURLSource; |
| 53 | + // Curl opt is a hack because the honeypot folks don't seem to have a valid |
| 54 | + // certificate. |
| 55 | + $data = Http::get( $wgHoneypotURLSource, 'default', |
| 56 | + array( CURLOPT_SSL_VERIFYHOST => 1 ) ); |
| 57 | + |
| 58 | + $urls = explode( "\n", $data ); |
| 59 | + |
| 60 | + $wgMemc->set( $key, $urls, 86400 ); |
| 61 | + |
| 62 | + return $urls; |
| 63 | + } |
37 | 64 | |
38 | 65 | public static function generateHoneypotLink( $randomText = null ) { |
39 | | - global $wgHoneypotURLs, $wgHoneypotTemplates; |
| 66 | + global $wgHoneypotTemplates; |
| 67 | + |
| 68 | + $urls = self::getHoneypotURLs(); |
40 | 69 | |
41 | | - $index = rand( 0, count( $wgHoneypotURLs ) - 1 ); |
42 | | - $url = $wgHoneypotURLs[$index]; |
| 70 | + $index = rand( 0, count( $urls ) - 1 ); |
| 71 | + $url = $urls[$index]; |
43 | 72 | $index = rand( 0, count( $wgHoneypotTemplates ) - 1 ); |
44 | 73 | $template = $wgHoneypotTemplates[$index]; |
45 | 74 | |
— | — | @@ -59,9 +88,8 @@ |
60 | 89 | public static function isIPListed( $ip ) { |
61 | 90 | $subnet = substr( IP::toHex( $ip ), 0, -6 ); |
62 | 91 | $subnet_ips = self::getHoneypotIPs( $subnet ); |
63 | | - |
64 | | - $fss = fss_prep_search( "[$ip]" ); |
65 | | - return false !== fss_exec_search( $fss, $subnet_ips ); |
| 92 | + |
| 93 | + return !empty($subnet_ips[$ip]); |
66 | 94 | } |
67 | 95 | |
68 | 96 | // Gets data from memcached |
— | — | @@ -124,6 +152,7 @@ |
125 | 153 | |
126 | 154 | global $wgMemc; |
127 | 155 | foreach ( $ips as $subnet => $ipData ) { |
| 156 | + wfDebugLog( 'HoneypotDebug', "Inserting data for subnet $subnet" ); |
128 | 157 | $wgMemc->set( wfMemcKey( 'honeypot-data', $subnet ), $data[$subnet], 86400 ); |
129 | 158 | $wgMemc->set( wfMemcKey( 'honeypot-ips', $subnet ), $ips[$subnet], 86400 ); |
130 | 159 | } |
— | — | @@ -139,6 +168,8 @@ |
140 | 169 | $save_data = array(); |
141 | 170 | $ips = array(); |
142 | 171 | |
| 172 | + $count = 0; |
| 173 | + |
143 | 174 | while ( !feof($fh) ) { |
144 | 175 | $line = trim( fgets( $fh ) ); |
145 | 176 | $data = preg_split( '/\s/', $line, 3 ); |
— | — | @@ -147,12 +178,18 @@ |
148 | 179 | $subnet = substr( IP::toHex( $data[0] ), 0, -6 ); |
149 | 180 | |
150 | 181 | if ( !isset($ips[$subnet]) ) |
151 | | - $ips[$subnet] = ''; |
| 182 | + $ips[$subnet] = array(); |
152 | 183 | if ( !isset( $save_data[$subnet] ) ) |
153 | 184 | $save_data[$subnet] = array(); |
154 | 185 | |
155 | 186 | $save_data[$subnet][$data[0]] = $data; |
156 | | - $ips[$subnet] .= '['.$data[0]."]\n"; |
| 187 | + $ips[$subnet][$data[0]] = true; |
| 188 | + |
| 189 | + $count++; |
| 190 | + |
| 191 | + if ( $count % 100 == 0) { |
| 192 | + wfDebugLog( 'HoneypotDebug', "Done $count IPs -- $data[0]" ); |
| 193 | + } |
157 | 194 | } |
158 | 195 | } |
159 | 196 | |