get_error_message(); return $error; } if (absint($ripe_response['response']['code']) != 200) { $error = 'WHOIS: '.$ripe_response['response']['message'].' / '.$ripe_response['response']['code']; set_transient( $key, $error , RIPE_ERR_EXPIRE ); //return $error; return ''; // don't blow user mind } $ripe = $ripe_response; $ripe['body'] = json_decode($ripe_response['body']); if (JSON_ERROR_NONE != json_last_error()) { $error = 'WHOIS: '.json_last_error_msg(); set_transient( $key, $error , RIPE_ERR_EXPIRE ); return $error; } $ripe['abuse-email'] = ripe_find_abuse_contact($ripe['body'],$ip); set_transient( $key, serialize( $ripe ), RIPE_OK_EXPIRE ); } else { $ripe = unserialize($ripe); } //$ripe['abuse-email'] = ripe_get_abuse_contact($ripe['body'],$ip); return $ripe; } /* * Retrieve abuse email from response, rollback to direct request to the API * @since 2.7 * */ function ripe_find_abuse_contact($ripe_body, $ip){ //http://rest.db.ripe.net/abuse-contact $email = ''; foreach ($ripe_body->objects->object as $object) { foreach ($object->attributes->attribute as $att){ if ($att->name == 'abuse-mailbox' && is_email($att->value)){ $email = $att->value; break; } } } if (!$email) { // make an API request $args = array(); $args['headers']['Accept'] = 'application/json'; $ripe_response = wp_remote_get( RIPE_HOST.'abuse-contact/' . $ip, $args ); if ( is_wp_error( $ripe_response ) ) { return $ripe_response->get_error_message(); } $abuse = json_decode($ripe_response['body']); $abuse = get_object_vars($abuse); if (is_email($abuse['abuse-contacts']->email)) $email = $abuse['abuse-contacts']->email; } return $email; } /* * Get and parse RIPE response to human readable view * @since 2.7 * */ function ripe_readable_info($ip){ $ripe = ripe_search($ip); if (!is_array($ripe)) { if (!$ripe) return array('error' => 'RIPE error'); return array('whois' => $ripe); } $ret = array(); $body = $ripe['body']; if ($body->service->name != 'search') return $ret; // only for RIPE search requests & responses $info = ''; foreach ($body->objects->object as $object) { $info.=''; foreach ($object->attributes->attribute as $att){ $ret['data'][$att->name] = $att->value; if (is_email($att->value)) $value = ''.$att->value.''; elseif (strtolower($att->name) == 'country') { $value = cerber_get_flag_html($att->value) . '' . cerber_country_name($att->value) . ' (' . $att->value . ')'; $ret['country'] = $value; } else $value = $att->value; $info.=''; } $info.='
'.strtoupper($object->type).'
'.$att->name.''.$value.'
'; } if (!empty($ripe['abuse-email']) && is_email($ripe['abuse-email'])) { $ret['data']['abuse-mailbox'] = $ripe['abuse-email']; } // Network if (!empty($ret['data']['inetnum'])) { $ret['data']['network'] = $ret['data']['inetnum']; } $ret['whois'] = $info; return $ret; }