Changeset 1008022
- Timestamp:
- 10/15/2014 05:48:36 PM (11 years ago)
- File:
-
- 1 edited
-
asgard/trunk/asgard.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
asgard/trunk/asgard.php
r1007296 r1008022 141 141 $zip = asgard_zip_files( $toscan, $basepath ); 142 142 $scanres = asgard_scan_zip( $zip ); 143 if ( $scanres && $scanres ->match) {144 foreach ( $scanres ->verdictas $path => $verdict ) {143 if ( $scanres && $scanres['match'] ) { 144 foreach ( $scanres['verdict'] as $path => $verdict ) { 145 145 $result[$basepath . $path] = $verdict; 146 146 } … … 244 244 $extensions = array( 245 245 'php', 246 'php5', 247 'php4', 246 248 'phtml', 247 'php5',248 249 'html', 249 250 'htaccess', … … 265 266 } 266 267 267 268 function asgard_scan_zip( $path ) { 269 $body = array( 270 'file' => '@' . $path 271 ); 268 function asgard_api_post( $url, $body, $json=false ) { 272 269 $ch = curl_init(); 273 curl_setopt( $ch, CURLOPT_URL, ASGARD_API . '/scan_zip');270 curl_setopt( $ch, CURLOPT_URL, $url ); 274 271 curl_setopt( $ch, CURLOPT_POST, 1 ); 275 272 curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); 276 273 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 274 curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 2 ); 275 curl_setopt( $ch, CURLOPT_TIMEOUT, 60 ); 276 if ( $json ) curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8' ) ); 277 277 $result = curl_exec( $ch ); 278 $errno = curl_errno( $ch ); 279 if ( $errno != 0 ) { 280 asgard_html_error( sprintf( 'POST %s: error=%s code=%d', $url, $errno, curl_error( $ch ) ) ); 281 } 282 278 283 $http_status = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); 279 $errno = curl_errno( $ch );280 284 if ( $http_status != 200 ) { 281 asgard_html_error( 'Scan error: code=' . $http_status . '. Please, try again later.' ); 282 } 285 asgard_html_error( sprintf( 'POST %s error: code=%d. Please, try again later.', $url, $http_status ) ); 286 } 287 283 288 curl_close( $ch ); 284 return json_decode( $result ); 289 return json_decode( $result, true ); 290 } 291 292 function asgard_scan_zip( $path ) { 293 return asgard_api_post( ASGARD_API . '/scan_zip', array( 'file' => '@' . $path ) ); 285 294 } 286 295 … … 292 301 // send blog url and email for auth 293 302 $plugin_info = get_plugin_data( __FILE__ ); 294 $ args= build_query( array(303 $q = build_query( array( 295 304 'checksum' => md5( $body ) , 296 305 'site_url' => get_site_url() , … … 300 309 'asgard_version' => $plugin_info['Version'], 301 310 ) ); 302 $response = wp_remote_post( ASGARD_API . '/check?' . $args, array( 303 'body' => $body, 304 'headers' => array( 305 'Content-Type' => 'application/json; charset=utf-8', 306 ) , 307 ) ); 308 if ( is_wp_error( $response ) ) { 309 $error_message = $response->get_error_message(); 310 die( "Something went wrong: $error_message" ); 311 } 312 if ( $response['response']['code'] != 200 ) { 313 asgard_html_error( 'Send Hashes error: code=' . $response['response']['code'] . '. Please, try again later.' ); 314 } 315 $result = json_decode( $response['body'], true ); 316 return $result['result']; 317 } 318 319 320 function asgard_auth_key() { 321 $plugin_info = get_plugin_data( __FILE__ ); 322 $body = array( 323 'site_url' => get_site_url() , 324 'admin_email' => get_option( 'admin_email' ) , 325 'wp_version' => get_bloginfo( 'version' ) , 326 'asgard_checksum' => ASGARD_CHECKSUM, 327 'asgard_version' => $plugin_info['Version'], 328 ); 329 330 $response = wp_remote_post( ASGARD_API . '/auth', array( 'body' => $body ) ); 331 if ( is_wp_error( $response ) ) { 332 $error_message = $response->get_error_message(); 333 die( "Something went wrong: $error_message" ); 334 } 335 336 if ( $response['response']['code'] != 200 ) { 337 asgard_html_error( 'Auth Error: code=' . $response['response']['code'] ); 338 } 339 340 return json_decode( $response['body'], true ); 341 } 311 312 $result = asgard_api_post( ASGARD_API . '/check?' . $q, $body, 'json' ); 313 return is_array( $result['result'] ) ? $result['result'] : array(); 314 }
Note: See TracChangeset
for help on using the changeset viewer.