2014-05-21 02:58:12 +00:00
|
|
|
require "vagrant/util/which"
|
|
|
|
|
2014-05-21 02:55:36 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module HostLinux
|
|
|
|
module Cap
|
|
|
|
class RDP
|
|
|
|
def self.rdp_client(env, rdp_info)
|
2015-11-03 07:39:06 +00:00
|
|
|
# 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
|
2018-05-02 13:21:47 +00:00
|
|
|
if Vagrant::Util::Platform.wsl?
|
|
|
|
"mstsc.exe"
|
|
|
|
else
|
|
|
|
raise Vagrant::Errors::LinuxRDPClientNotFound
|
|
|
|
end
|
2015-11-03 07:39:06 +00:00
|
|
|
end
|
2014-05-21 02:58:12 +00:00
|
|
|
|
2014-05-21 02:55:36 +00:00
|
|
|
args = []
|
|
|
|
|
2015-11-03 07:39:06 +00:00
|
|
|
# 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]}"
|
2018-05-02 13:21:47 +00:00
|
|
|
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]
|
2015-11-03 07:39:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Finally, run the client.
|
|
|
|
Vagrant::Util::Subprocess.execute(rdp_client, *args)
|
2014-05-21 02:55:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|