rdpcmd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/pry +11 -0
- data/bin/setup +8 -0
- data/exe/rdpcmd +181 -0
- data/lib/rdpcmd.rb +7 -0
- data/lib/rdpcmd/rdpcmd.rb +157 -0
- data/lib/rdpcmd/remmina.rb +96 -0
- data/lib/rdpcmd/version.rb +3 -0
- data/rdpcmd.gemspec +26 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f2c2c1a567e4fe9f503a886f7fccc6369b967345
|
4
|
+
data.tar.gz: ad1b1cfbb534bab4651d11fd18bc6ebb9b5a9cc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97107efeb89b3d31d9baeb8cb70b5bdb63a1c123c2165585cdb1d17a816093aff97cc4fa33249e4e925cc78edc125d24ff8144d961609b7d7030c602a86674fd
|
7
|
+
data.tar.gz: bb076a3d58397c2cbf2953ab1c67a2b6219db7218ba64d83b19be1b4585e04e5e6b74ab43ba96d98d3bb42dd107574e7c848f7b538b1baa2c3e0232e0890a406
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at kost@linux.hr. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Vlatko Kosturjak
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Rdpcmd
|
2
|
+
|
3
|
+
Execute commands on Windows via RDP. Helps if you need to run commands on large number of hosts. It is using remmina and xdotool to execute commands.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Quick installation:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install rdpcmd
|
12
|
+
remmina # just to generate
|
13
|
+
rdpcmd --help # you'll find your way
|
14
|
+
```
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'rdpcmd'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install rdpcmd
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Run whoami on 192.168.1.1 and wait 5 seconds after:
|
33
|
+
|
34
|
+
```
|
35
|
+
rdpcmd -u user -p password -i 192.168.1.1 -c 'whoami' -x 3
|
36
|
+
```
|
37
|
+
|
38
|
+
Enable WinRM on 192.168.1.1 and wait 5 seconds to finish winrm quikconfig before exiting terminal:
|
39
|
+
|
40
|
+
```
|
41
|
+
rdpcmd -u user -p password -i 192.168.1.1 -e -c 'winrm quickconfig -quiet -force' -x 5
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rdpcmd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
59
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rdpcmd"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/pry
ADDED
data/bin/setup
ADDED
data/exe/rdpcmd
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'yaml'
|
6
|
+
require 'optparse'
|
7
|
+
require 'logger'
|
8
|
+
require 'rdpcmd'
|
9
|
+
require 'csv'
|
10
|
+
|
11
|
+
require 'pp'
|
12
|
+
|
13
|
+
$PRGNAME="rdpcmd"
|
14
|
+
$options = {}
|
15
|
+
$options['loglevel'] = 'WARN'
|
16
|
+
$options['logname'] = nil
|
17
|
+
$options['domain'] = ''
|
18
|
+
|
19
|
+
# helpful class for logger
|
20
|
+
class MultiDelegator
|
21
|
+
def initialize(*targets)
|
22
|
+
@targets = targets
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.delegate(*methods)
|
26
|
+
methods.each do |m|
|
27
|
+
define_method(m) do |*args|
|
28
|
+
@targets.map { |t| t.send(m, *args) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
class <<self
|
35
|
+
alias to new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
begin
|
41
|
+
optyaml = YAML::load_file(ENV['HOME']+'/.rdpcmd')
|
42
|
+
rescue # Errno::ENOENT
|
43
|
+
end
|
44
|
+
|
45
|
+
if optyaml != nil then
|
46
|
+
$options.merge!(optyaml)
|
47
|
+
end
|
48
|
+
|
49
|
+
# initialize logger
|
50
|
+
if $options['logname'] != nil then
|
51
|
+
log_file = File.open($options['logname'], 'a')
|
52
|
+
@log = Logger.new MultiDelegator.delegate(:write, :close).to(STDERR, log_file)
|
53
|
+
else
|
54
|
+
@log = Logger.new MultiDelegator.delegate(:write, :close).to(STDERR)
|
55
|
+
end
|
56
|
+
loglevel = Logger.const_get $options['loglevel'] # Logger::INFO # default is ::WARN
|
57
|
+
@log.level = loglevel
|
58
|
+
|
59
|
+
# pp $options
|
60
|
+
|
61
|
+
OptionParser.new do |opts|
|
62
|
+
opts.banner = "Usage: #{$PRGNAME} [options]"
|
63
|
+
|
64
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
65
|
+
$options['verbose'] = v
|
66
|
+
@log.level = Logger::INFO
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.on("-d", "--[no-]debug", "Run in debug mode") do |v|
|
70
|
+
$options['debug'] = v
|
71
|
+
@log.level = Logger::DEBUG
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on("-e", "--[no-]elevated", "run in elevated prompt") do |optarg|
|
75
|
+
$options['elevated'] = optarg
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on("-x", "--exit SECONDS", "close cmd window after SECONDS") do |optarg|
|
79
|
+
$options['exit'] = optarg
|
80
|
+
end
|
81
|
+
|
82
|
+
opts.on("-f", "--file FILE", "get list of IP addresses from file") do |optarg|
|
83
|
+
$options['file'] = optarg
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on("-c", "--cmd CMD", "run command CMD") do |optarg|
|
87
|
+
$options['cmd'] = optarg
|
88
|
+
end
|
89
|
+
|
90
|
+
opts.on("-i", "--ip IP", "run on this IP") do |optarg|
|
91
|
+
$options['ip'] = optarg
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on("-m", "--domain DOMAIN", "run with domain") do |optarg|
|
95
|
+
$options['domain'] = optarg
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on("-u", "--user USER", "run with USER") do |optarg|
|
99
|
+
$options['user'] = optarg
|
100
|
+
end
|
101
|
+
|
102
|
+
opts.on("-p", "--password PASS", "run with PASS") do |optarg|
|
103
|
+
$options['password'] = optarg
|
104
|
+
end
|
105
|
+
|
106
|
+
opts.on("-h", "--help", "Prints this help") do
|
107
|
+
puts opts
|
108
|
+
exit
|
109
|
+
end
|
110
|
+
|
111
|
+
opts.on("-l", "--log FILE", "log to FILE") do |optarg|
|
112
|
+
$options['logname'] = optarg
|
113
|
+
end
|
114
|
+
|
115
|
+
opts.separator ""
|
116
|
+
opts.separator "Example #1: #{$PRGNAME} -u user -p password -i 192.168.1.1 -c 'whoami' -x 3"
|
117
|
+
opts.separator "Example #2: #{$PRGNAME} -u user -p password -i 192.168.1.1 -e -c 'winrm quickconfig -quiet -force' -x 5"
|
118
|
+
end.parse!
|
119
|
+
|
120
|
+
def handle_single(ip,domain,user,password,cmd)
|
121
|
+
rcmd=Rdpcmd::Rdpcmd.new('log'=>@log)
|
122
|
+
|
123
|
+
@log.debug("Connecting to IP: #{ip} with user #{user} and domain #{domain}")
|
124
|
+
unless rcmd.connect('server'=>ip,'username'=>user,'password'=>password,'domain'=>domain) then
|
125
|
+
@log.error("Exiting...")
|
126
|
+
rcmd.terminate()
|
127
|
+
return
|
128
|
+
end
|
129
|
+
|
130
|
+
@log.info("Executing: #{$options["cmd"]}")
|
131
|
+
|
132
|
+
if $options['elevated']
|
133
|
+
rcmd.singleElevated($options["cmd"],$options["exit"].to_i)
|
134
|
+
else
|
135
|
+
rcmd.singleNormal($options["cmd"],$options["exit"].to_i)
|
136
|
+
end
|
137
|
+
|
138
|
+
rcmd.terminate()
|
139
|
+
end
|
140
|
+
|
141
|
+
if $options['ip'] then
|
142
|
+
ip=$options['ip']
|
143
|
+
user=$options['user']
|
144
|
+
password=$options['password']
|
145
|
+
domain=$options['domain'] || ""
|
146
|
+
|
147
|
+
handle_single(ip,domain,user,password,$options["cmd"])
|
148
|
+
end
|
149
|
+
|
150
|
+
pp $options
|
151
|
+
|
152
|
+
if $options['file'] then
|
153
|
+
CSV.foreach($options['file']) do |row|
|
154
|
+
ip=row[0]
|
155
|
+
user=$options['user']
|
156
|
+
password=$options['password']
|
157
|
+
domain=$options['domain'] || ""
|
158
|
+
cmd=$options["cmd"]
|
159
|
+
pp domain
|
160
|
+
pp row.size
|
161
|
+
if row.size>1 then
|
162
|
+
domain=row[1]
|
163
|
+
end
|
164
|
+
if row.size>2 then
|
165
|
+
user=row[2]
|
166
|
+
end
|
167
|
+
if row.size>3 then
|
168
|
+
password=row[3]
|
169
|
+
end
|
170
|
+
if row.size>4 then
|
171
|
+
cmd=row[4]
|
172
|
+
end
|
173
|
+
|
174
|
+
pp row
|
175
|
+
pp ip, domain, user, password, cmd
|
176
|
+
|
177
|
+
handle_single(ip,domain,user,password,cmd)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
data/lib/rdpcmd.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Rdpcmd
|
4
|
+
|
5
|
+
class Rdpcmd
|
6
|
+
def initialize(params={})
|
7
|
+
@log=params.fetch('log','')
|
8
|
+
end
|
9
|
+
|
10
|
+
def wait4window(pid,ip)
|
11
|
+
waitfor=5
|
12
|
+
wid=nil
|
13
|
+
|
14
|
+
waitfor.times do |i|
|
15
|
+
@log.debug("Waiting for Remmina to start: #{i}")
|
16
|
+
f = IO.popen("xdotool search --all --pid #{pid} --name #{ip}")
|
17
|
+
# puts f.readlines
|
18
|
+
idline=''
|
19
|
+
f.each do |line|
|
20
|
+
@log.debug("Parsed xdotool line: #{line}")
|
21
|
+
idline=line
|
22
|
+
end
|
23
|
+
unless idline.to_s.strip.empty? then
|
24
|
+
wid=idline.chomp
|
25
|
+
@log.debug("Taking wid: #{wid}")
|
26
|
+
f.close
|
27
|
+
break
|
28
|
+
end
|
29
|
+
f.close
|
30
|
+
sleep(1)
|
31
|
+
end
|
32
|
+
@wid=wid
|
33
|
+
return wid
|
34
|
+
end
|
35
|
+
|
36
|
+
def systeml(str)
|
37
|
+
@log.debug(str)
|
38
|
+
system(str)
|
39
|
+
end
|
40
|
+
|
41
|
+
def connect (opts={})
|
42
|
+
rem=Remmina.new
|
43
|
+
rem.readconfig
|
44
|
+
|
45
|
+
@log.debug("Connecting to IP: #{opts['server']} with user #{opts['username']} and domain #{opts['domain']}")
|
46
|
+
tempconfig=rem.genconfig(opts)
|
47
|
+
|
48
|
+
@t = Tempfile.new(["rdpcmd",".remmina"])
|
49
|
+
@t.write(tempconfig)
|
50
|
+
@t.close
|
51
|
+
|
52
|
+
cmdspawn="remmina -c #{@t.path}"
|
53
|
+
@log.debug("Spawning Remmina with cmdline: #{cmdspawn}")
|
54
|
+
|
55
|
+
@pid=Process.spawn(cmdspawn)
|
56
|
+
|
57
|
+
@log.debug("Spawned Remmina with PID: #{@pid}")
|
58
|
+
|
59
|
+
sleepfor=3
|
60
|
+
@log.debug("Sleeping for #{sleepfor}")
|
61
|
+
sleep(sleepfor)
|
62
|
+
|
63
|
+
wait4window(@pid,opts['server'])
|
64
|
+
if @wid.nil? then
|
65
|
+
@log.error("Cannot find Remmina window, is Remmina and xdotool installed? Connection problem.")
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
|
69
|
+
@log.debug("Remmina contacted, window ID: #{@wid}")
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def terminate()
|
74
|
+
@t.unlink
|
75
|
+
@log.debug("Killing Remmina with PID: #{@pid}")
|
76
|
+
Process.kill("KILL", @pid)
|
77
|
+
end
|
78
|
+
|
79
|
+
def prepareremmina()
|
80
|
+
systeml("xdotool windowactivate --sync #{@wid} key --clearmodifiers 'Control_R'")
|
81
|
+
end
|
82
|
+
|
83
|
+
def startrun(cmd)
|
84
|
+
systeml("xdotool windowactivate --sync #{@wid} key 'Super+r' sleep 2 type '#{cmd}'")
|
85
|
+
systeml('xdotool key --clearmodifiers "Return"')
|
86
|
+
end
|
87
|
+
|
88
|
+
def startrunele(sleepfor=4)
|
89
|
+
startrun("powershell Start-Process cmd -Verb runAs")
|
90
|
+
systeml("xdotool sleep 3 key 'Alt+y' sleep #{sleepfor}")
|
91
|
+
end
|
92
|
+
|
93
|
+
def closecmd(sleepfor)
|
94
|
+
@log.debug("Sleeping for final things to settle")
|
95
|
+
sleep sleepfor
|
96
|
+
systeml("xdotool type 'exit'")
|
97
|
+
systeml('xdotool key --clearmodifiers "Return"')
|
98
|
+
end
|
99
|
+
|
100
|
+
def cleanupremmina()
|
101
|
+
systeml("xdotool windowactivate --sync #{@wid} key --clearmodifiers 'Control_R'")
|
102
|
+
@log.debug("Sleeping for final things to settle")
|
103
|
+
sleep 1
|
104
|
+
end
|
105
|
+
|
106
|
+
def sendline(cmd)
|
107
|
+
systeml("xdotool type '#{cmd}'")
|
108
|
+
systeml('xdotool key --clearmodifiers "Return"')
|
109
|
+
end
|
110
|
+
|
111
|
+
def sendkeys(keys,clearmod=false)
|
112
|
+
opts=''
|
113
|
+
if clearmod then
|
114
|
+
opts << " --clearmodifiers "
|
115
|
+
end
|
116
|
+
systeml("xdotool key #{opts} #{keys}")
|
117
|
+
end
|
118
|
+
|
119
|
+
def sendfile(file, sleepfor=0.5)
|
120
|
+
input= File.new(file, "r")
|
121
|
+
input.each do |line|
|
122
|
+
sendline(line)
|
123
|
+
sleep(sleepfor)
|
124
|
+
end
|
125
|
+
input.close
|
126
|
+
end
|
127
|
+
|
128
|
+
def copyfile(src,dest,sleepfor=0.5)
|
129
|
+
sendline("copy con #{dest}")
|
130
|
+
sleep(sleepfor)
|
131
|
+
sendfile(src, sleepfor)
|
132
|
+
sleep(sleepfor)
|
133
|
+
systeml('xdotool key --clearmodifiers "Ctrl+Z" "Return"')
|
134
|
+
end
|
135
|
+
|
136
|
+
def singleElevated(cmd,toexit=0)
|
137
|
+
prepareremmina()
|
138
|
+
startrunele()
|
139
|
+
sendline(cmd)
|
140
|
+
if toexit > 0 then
|
141
|
+
closecmd(toexit)
|
142
|
+
end
|
143
|
+
cleanupremmina()
|
144
|
+
end
|
145
|
+
|
146
|
+
def singleNormal(cmd,toexit=0)
|
147
|
+
prepareremmina()
|
148
|
+
startrun('cmd.exe')
|
149
|
+
sendline(cmd)
|
150
|
+
if toexit > 0 then
|
151
|
+
closecmd(toexit)
|
152
|
+
end
|
153
|
+
cleanupremmina()
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module Rdpcmd
|
7
|
+
|
8
|
+
class Remmina
|
9
|
+
def genconfig(opts={})
|
10
|
+
conf=templateconfig
|
11
|
+
conf.gsub!("{{server}}",opts.fetch('server','127.0.0.1'))
|
12
|
+
conf.gsub!("{{username}}",opts.fetch('username','user'))
|
13
|
+
conf.gsub!("{{domain}}",opts.fetch('domain',''))
|
14
|
+
|
15
|
+
password=opts.fetch('password','')
|
16
|
+
conf.gsub!("{{password}}",encrypt_password(password))
|
17
|
+
|
18
|
+
return conf
|
19
|
+
end
|
20
|
+
|
21
|
+
def templateconfig()
|
22
|
+
<<-HEREDOC
|
23
|
+
[remmina]
|
24
|
+
disableclipboard=0
|
25
|
+
ssh_auth=0
|
26
|
+
clientname=
|
27
|
+
quality=0
|
28
|
+
ssh_charset=
|
29
|
+
ssh_privatekey=
|
30
|
+
sharesmartcard=0
|
31
|
+
resolution=1024x768
|
32
|
+
group=
|
33
|
+
password={{password}}
|
34
|
+
name={{server}}
|
35
|
+
ssh_loopback=0
|
36
|
+
shareprinter=0
|
37
|
+
ssh_username=
|
38
|
+
ssh_server=
|
39
|
+
security=
|
40
|
+
protocol=RDP
|
41
|
+
execpath=
|
42
|
+
sound=off
|
43
|
+
exec=
|
44
|
+
ssh_enabled=0
|
45
|
+
username={{username}}
|
46
|
+
sharefolder=
|
47
|
+
console=0
|
48
|
+
domain={{domain}}
|
49
|
+
server={{server}}
|
50
|
+
colordepth=8
|
51
|
+
window_maximize=0
|
52
|
+
window_height=1041
|
53
|
+
window_width=956
|
54
|
+
viewmode=1
|
55
|
+
HEREDOC
|
56
|
+
end
|
57
|
+
|
58
|
+
def readconfig()
|
59
|
+
confdir=ENV['HOME']+"/"+'.remmina/'
|
60
|
+
conffile=confdir+'remmina.pref'
|
61
|
+
secret=nil
|
62
|
+
|
63
|
+
input= File.new(conffile, "r")
|
64
|
+
|
65
|
+
input.each do |line|
|
66
|
+
if (line =~ /^secret=/) then
|
67
|
+
secini=line.split("=",2)
|
68
|
+
secret=secini[1]
|
69
|
+
break
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
input.close
|
74
|
+
|
75
|
+
unless secret.nil? then
|
76
|
+
secret64=Base64.decode64(secret)
|
77
|
+
@key=secret64[0..23]
|
78
|
+
@iv=secret64[24..48]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def encrypt_password (password)
|
83
|
+
cipher = OpenSSL::Cipher::Cipher.new('DES3')
|
84
|
+
cipher.encrypt
|
85
|
+
cipher.iv=@iv
|
86
|
+
cipher.key=@key
|
87
|
+
cipher.padding=0
|
88
|
+
strpad=password+"\0"*(8-password.length%8)
|
89
|
+
str=strpad.encode("ascii")
|
90
|
+
enc=cipher.update(str)+cipher.final
|
91
|
+
b64=Base64.encode64(enc)
|
92
|
+
return b64.chomp
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/rdpcmd.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rdpcmd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rdpcmd"
|
8
|
+
spec.version = Rdpcmd::VERSION
|
9
|
+
spec.authors = ["Vlatko Kosturjak"]
|
10
|
+
spec.email = ["vlatko.kosturjak@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Execute commands on Windows via RDP.}
|
13
|
+
spec.description = %q{Execute commands on Windows via RDP. Helps if you need to run commands on large number of hosts. It is using remmina and xdotool to execute commands.}
|
14
|
+
spec.homepage = "https://github.com/kost/rdpcmd-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "pry", "> 0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdpcmd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vlatko Kosturjak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Execute commands on Windows via RDP. Helps if you need to run commands
|
70
|
+
on large number of hosts. It is using remmina and xdotool to execute commands.
|
71
|
+
email:
|
72
|
+
- vlatko.kosturjak@gmail.com
|
73
|
+
executables:
|
74
|
+
- rdpcmd
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/pry
|
88
|
+
- bin/setup
|
89
|
+
- exe/rdpcmd
|
90
|
+
- lib/rdpcmd.rb
|
91
|
+
- lib/rdpcmd/rdpcmd.rb
|
92
|
+
- lib/rdpcmd/remmina.rb
|
93
|
+
- lib/rdpcmd/version.rb
|
94
|
+
- rdpcmd.gemspec
|
95
|
+
homepage: https://github.com/kost/rdpcmd-ruby
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.5.2.1
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Execute commands on Windows via RDP.
|
119
|
+
test_files: []
|