From 577754dce5b037d05fb8d1477a2c754ec822fdca Mon Sep 17 00:00:00 2001 From: Kevin Shenk Date: Fri, 14 Jul 2023 17:06:24 -0400 Subject: [PATCH] Use the IP from the Server Post if available Instead of loading the provider API, the IP address can be called directly from the post meta in most cases. --- .../wordpress-app/class-wordpress-ssh.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/includes/core/apps/wordpress-app/class-wordpress-ssh.php b/includes/core/apps/wordpress-app/class-wordpress-ssh.php index 5bf52ad4..93f0b5fd 100644 --- a/includes/core/apps/wordpress-app/class-wordpress-ssh.php +++ b/includes/core/apps/wordpress-app/class-wordpress-ssh.php @@ -113,17 +113,20 @@ public function get_ssh_key_details( $attributes ) { $ssh_private_key_encrypted = wpcd_get_option( 'vpn_' . $attributes['provider'] . '_sshkey' ); // We don't decrypt the private key itself.... } - // Get some other data elements... - $instance = WPCD()->get_provider_api( $attributes['provider'] )->call( 'details', $attributes ); + // Grab the ip address. + if (metadata_exists('post', $post_id, 'wpcd_server_ipv4')) { // we use the ip from the server post if it's available + $ip = get_post_meta($post_id, 'wpcd_server_ipv4', true); + } else { // otherwise we get it from the provider. + $instance = WPCD()->get_provider_api($attributes['provider'])->call('details', $attributes); + + // Make sure the $instance var is valid otherwise return false. + if (is_wp_error($instance) || empty($instance)) { + return false; + } - // Make sure the $instance var is valid otherwise return false. - if ( is_wp_error( $instance ) || empty( $instance ) ) { - return false; + $ip = $instance['ip']; } - // Grab the ip address. - $ip = $instance['ip']; - // At this point we better have some key data! $key = array( 'passwd' => $ssh_private_key_password, // decrypted.