Class: Rdpcmd::Remmina

Inherits:
Object
  • Object
show all
Defined in:
lib/rdpcmd/remmina.rb

Instance Method Summary collapse

Instance Method Details

#encrypt_password(password) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rdpcmd/remmina.rb', line 82

def encrypt_password (password)
	cipher = OpenSSL::Cipher::Cipher.new('DES3')
	cipher.encrypt
	cipher.iv=@iv
	cipher.key=@key
	cipher.padding=0
	strpad=password+"\0"*(8-password.length%8)
	str=strpad.encode("ascii")
	enc=cipher.update(str)+cipher.final
	b64=Base64.encode64(enc)
	return b64.chomp
end

#genconfig(opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rdpcmd/remmina.rb', line 9

def genconfig(opts={})
	conf=templateconfig
	conf.gsub!("{{server}}",opts.fetch('server','127.0.0.1'))
	conf.gsub!("{{username}}",opts.fetch('username','user'))
	conf.gsub!("{{domain}}",opts.fetch('domain',''))

	password=opts.fetch('password','')
	conf.gsub!("{{password}}",encrypt_password(password))

	return conf
end

#readconfigObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rdpcmd/remmina.rb', line 58

def readconfig()
	confdir=ENV['HOME']+"/"+'.remmina/'
	conffile=confdir+'remmina.pref'
	secret=nil

	input= File.new(conffile, "r")

	input.each do |line|
		if (line =~ /^secret=/)  then
			secini=line.split("=",2)
			secret=secini[1]
			break
		end
	end

	input.close

	unless secret.nil? then
		secret64=Base64.decode64(secret)
		@key=secret64[0..23]
		@iv=secret64[24..48]
	end
end

#templateconfigObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rdpcmd/remmina.rb', line 21

def templateconfig()
	<<-HEREDOC
[remmina]
disableclipboard=0
ssh_auth=0
clientname=
quality=0
ssh_charset=
ssh_privatekey=
sharesmartcard=0
resolution=1024x768
group=
password={{password}}
name={{server}}
ssh_loopback=0
shareprinter=0
ssh_username=
ssh_server=
security=
protocol=RDP
execpath=
sound=off
exec=
ssh_enabled=0
username={{username}}
sharefolder=
console=0
domain={{domain}}
server={{server}}
colordepth=8
window_maximize=0
window_height=1041
window_width=956
viewmode=1
HEREDOC
end