OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33
Information System : Linux apprendre2 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Disable Function : get_error_message();
}
if ( absint( $ripe_response['response']['code'] ) != 200 ) {
$error = 'WHOIS ERROR: ' . $ripe_response['response']['message'] . ' / ' . $ripe_response['response']['code'];
set_transient( $key, json_encode( array( 'ripe_error' => $error ) ), RIPE_ERR_EXPIRE );
return $error;
}
$ret = array();
$ret['body'] = json_decode( $ripe_response['body'], true );
if ( JSON_ERROR_NONE != json_last_error() ) {
$error = 'WHOIS ERROR: ' . json_last_error_msg();
set_transient( $key, json_encode( array( 'ripe_error' => $error ) ), RIPE_ERR_EXPIRE );
return $error;
}
$ret['abuse_email'] = ripe_find_abuse_contact( $ret['body'], $ip );
set_transient( $key, json_encode( $ret ), RIPE_OK_EXPIRE );
}
else {
$ret = json_decode( $ripe, true );
if ( ! empty( $ret['ripe_error'] ) ) {
return $ret['ripe_error'];
}
}
return $ret;
}
/*
* 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 ( crb_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 ) ) { // Error
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 .= '
';
}
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;
}
';
foreach ( $object['attributes']['attribute'] as $att ) {
$value = $att['value'];
$ret['data'][ $att['name'] ] = $att['value'];
if ( is_email( $value ) ) {
$value = '' . $value . '';
}
elseif ( strtolower( $att['name'] ) == 'country' ) {
$value = cerber_get_flag_html( $value, '' . cerber_country_name( $value ) . ' (' . $value . ')' );
$ret['country'] = $value;
}
$info .= '' . strtoupper( $object['type'] ) . ' ';
}
$info .= '' . $att['name'] . ' ' . $value . '