// Form errors.
     echo $login_welcome;
     pb_backupbuddy::alert(implode('<br>', $settings_result['errors']));
     $credentials_form->display_settings('Submit');
     $pb_hide_test = true;
     $pb_hide_save = true;
     return;
 } else {
     // No form errors; process!
     $pb_hide_test = true;
     $pb_hide_save = true;
     require_once dirname(__FILE__) . '/class.itx_helper2.php';
     global $wp_version;
     $itxapi_username = strtolower($settings_result['data']['itxapi_username']);
     $password_hash = iThemes_Credentials::get_password_hash($itxapi_username, $settings_result['data']['itxapi_password_raw']);
     $access_token = ITXAPI_Helper2::get_access_token($itxapi_username, $password_hash, site_url(), $wp_version);
     $settings = array('itxapi_username' => $itxapi_username, 'itxapi_password' => $access_token);
     $response = pb_backupbuddy_destination_stash2::stashAPI($settings, 'connect');
     if (!is_array($response)) {
         // Error message.
         pb_backupbuddy::alert('Error #23333: Unexpected server response. Check your login and try again. Detailed response: `' . print_r($response, true) . '`.');
         $credentials_form->display_settings('Submit');
     } else {
         if (isset($response['error'])) {
             pb_backupbuddy::alert('Error: ' . $response['error']['message']);
             $credentials_form->display_settings('Submit');
         } else {
             if (isset($response['token'])) {
                 $itxapi_token = $response['token'];
             } else {
                 pb_backupbuddy::alert('Error #382383232: Unexpected server response. Token missing. Check your login and try again. Detailed response: `' . print_r($response, true) . '`.');
Example #2
0
        break;
    }
}
// Handle disconnect.
if ('disconnect' == pb_backupbuddy::_GET('live_action') && false !== $liveDestinationID) {
    // If disconnecting and not already disconnected.
    $disconnected = false;
    require_once pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php';
    require_once pb_backupbuddy::plugin_path() . '/destinations/stash2/class.itx_helper2.php';
    $destination_settings = backupbuddy_live_periodic::get_destination_settings();
    if ('yes' == pb_backupbuddy::_POST('disconnect')) {
        pb_backupbuddy::verify_nonce();
        // Pass itxapi_password to disconnect.
        global $wp_version;
        $password_hash = iThemes_Credentials::get_password_hash($destination_settings['itxapi_username'], pb_backupbuddy::_POST('password'));
        $access_token = ITXAPI_Helper2::get_access_token($destination_settings['itxapi_username'], $password_hash, site_url(), $wp_version);
        $settings = array('itxapi_username' => $destination_settings['itxapi_username'], 'itxapi_password' => $access_token, 'itxapi_token' => $destination_settings['itxapi_token']);
        $response = pb_backupbuddy_destination_live::stashAPI($settings, 'disconnect');
        if (!is_array($response)) {
            pb_backupbuddy::alert('Error Disconnecting: ' . $response);
        } elseif (!isset($response['success']) || '1' != $response['success']) {
            pb_backupbuddy::alert('Error #483948944. Unexpected response disconnecting: `' . print_r($response, true) . '`.');
        } else {
            $disconnected = true;
            // Clear destination settings.
            unset(pb_backupbuddy::$options['remote_destinations'][$liveDestinationID]);
            pb_backupbuddy::save();
            // Clear cached Live credentials.
            require_once pb_backupbuddy::plugin_path() . '/destinations/live/init.php';
            delete_transient(pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME);
            pb_backupbuddy::disalert('', 'You have disconnected from Stash Live.');