Sha256: e72a799f3f4be1cf2fc4c276247395fcdcb11811a7b3a1dcdfc36d5b4b2863a3

Contents?: true

Size: 1.92 KB

Versions: 20

Compression:

Stored size: 1.92 KB

Contents

require "vagrant/util/which"

module VagrantPlugins
  module HostLinux
    module Cap
      class RDP
        def self.rdp_client(env, rdp_info)
          # Detect if an RDP client is available.
          # Prefer xfreerdp as it supports newer versions of RDP.
          rdp_client =
            if Vagrant::Util::Which.which("xfreerdp")
              "xfreerdp"
            elsif Vagrant::Util::Which.which("rdesktop")
              "rdesktop"
            else
              if Vagrant::Util::Platform.wsl?
                "mstsc.exe"
              else
                raise Vagrant::Errors::LinuxRDPClientNotFound
              end
            end

          args = []

          # Build appropriate arguments for the RDP client.
          case rdp_client
          when "xfreerdp"
            args << "/u:#{rdp_info[:username]}"
            args << "/p:#{rdp_info[:password]}" if rdp_info[:password]
            args << "/v:#{rdp_info[:host]}:#{rdp_info[:port]}"
            args += rdp_info[:extra_args] if rdp_info[:extra_args]
          when "rdesktop"
            args << "-u" << rdp_info[:username]
            args << "-p" << rdp_info[:password] if rdp_info[:password]
            args += rdp_info[:extra_args] if rdp_info[:extra_args]
            args << "#{rdp_info[:host]}:#{rdp_info[:port]}"
          when "mstsc.exe"
            # Setup password
            cmdKeyArgs = [
              "/add:#{rdp_info[:host]}:#{rdp_info[:port]}",
              "/user:#{rdp_info[:username]}",
              "/pass:#{rdp_info[:password]}",
            ]
            Vagrant::Util::Subprocess.execute("cmdkey.exe", *cmdKeyArgs)

            args = ["/v:#{rdp_info[:host]}:#{rdp_info[:port]}"]
            args += rdp_info[:extra_args] if rdp_info[:extra_args]
          end

          # Finally, run the client.
          Vagrant::Util::Subprocess.execute(rdp_client, *args)
        end
      end
    end
  end
end

Version data entries

20 entries across 16 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.9.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.8.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.7.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.6.2 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.6.1 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.6.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.5.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.4.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.3.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.2.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.2.0.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.1.4.0 plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.1.2.0 plugins/hosts/linux/cap/rdp.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/hosts/linux/cap/rdp.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/hosts/linux/cap/rdp.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/hosts/linux/cap/rdp.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/hosts/linux/cap/rdp.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/hosts/linux/cap/rdp.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/hosts/linux/cap/rdp.rb
vagrant-unbundled-2.1.1.0 plugins/hosts/linux/cap/rdp.rb