winrm 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/soap/winrm_service.rb +30 -16
- data/lib/winrm.rb +6 -0
- data/test/spec/powershell_tests.spec +1 -1
- metadata +11 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/soap/winrm_service.rb
CHANGED
@@ -153,7 +153,9 @@ module WinRM
|
|
153
153
|
# Get the Output of the given shell and command
|
154
154
|
# @param [String] shell_id The shell id on the remote machine. See #open_shell
|
155
155
|
# @param [String] command_id The command id on the remote machine. See #run_command
|
156
|
-
# @return [Hash] :
|
156
|
+
# @return [Hash] Returns a Hash with a key :exitcode and :data. Data is an Array of Hashes where the cooresponding key
|
157
|
+
# is either :stdout or :stderr. The reason it is in an Array so so we can get the output in the order it ocurrs on
|
158
|
+
# the console.
|
157
159
|
def get_command_output(shell_id, command_id)
|
158
160
|
header = {}.merge(resource_uri_cmd).merge(action_receive).merge(selector_shell_id(shell_id))
|
159
161
|
|
@@ -164,15 +166,10 @@ module WinRM
|
|
164
166
|
end
|
165
167
|
end
|
166
168
|
|
167
|
-
|
168
|
-
|
169
|
-
(resp/"//*[@Name='stdout']").each do |n|
|
170
|
-
next if n.to_s.nil?
|
171
|
-
cmd_stdout << Base64.decode64(n.to_s)
|
172
|
-
end
|
173
|
-
(resp/"//*[@Name='stderr']").each do |n|
|
169
|
+
output = {:data => []}
|
170
|
+
(resp/"//#{NS_WIN_SHELL}:Stream").each do |n|
|
174
171
|
next if n.to_s.nil?
|
175
|
-
|
172
|
+
output[:data] << {n['Name'].to_sym => Base64.decode64(n.to_s)}
|
176
173
|
end
|
177
174
|
|
178
175
|
# We may need to get additional output if the stream has not finished.
|
@@ -185,12 +182,13 @@ module WinRM
|
|
185
182
|
# <rsp:ExitCode>0</rsp:ExitCode>
|
186
183
|
# </rsp:CommandState>
|
187
184
|
if((resp/"//#{NS_WIN_SHELL}:ExitCode").empty?)
|
188
|
-
|
189
|
-
|
190
|
-
|
185
|
+
output.merge!(get_command_output(shell_id,command_id)) do |key, old_data, new_data|
|
186
|
+
old_data += new_data
|
187
|
+
end
|
188
|
+
else
|
189
|
+
output[:exitcode] = (resp/"//#{NS_WIN_SHELL}:ExitCode").first.to_i
|
191
190
|
end
|
192
|
-
|
193
|
-
{:stdout => cmd_stdout, :stderr => cmd_stderr}
|
191
|
+
output
|
194
192
|
end
|
195
193
|
|
196
194
|
# Clean-up after a command.
|
@@ -218,13 +216,29 @@ module WinRM
|
|
218
216
|
true
|
219
217
|
end
|
220
218
|
|
219
|
+
# Run a CMD command
|
220
|
+
# @param [String] command The command to run on the remote system
|
221
|
+
# @return [Hash] :stdout and :stderr
|
222
|
+
def run_cmd(command)
|
223
|
+
shell_id = open_shell
|
224
|
+
command_id = run_command(shell_id, command)
|
225
|
+
command_output = get_command_output(shell_id, command_id)
|
226
|
+
cleanup_command(shell_id, command_id)
|
227
|
+
close_shell(shell_id)
|
228
|
+
command_output
|
229
|
+
end
|
230
|
+
|
231
|
+
|
221
232
|
# Run a Powershell script that resides on the local box.
|
222
233
|
# @param [String] script_file The string representing the path to a Powershell script
|
223
234
|
# @return [Hash] :stdout and :stderr
|
224
235
|
def run_powershell_script(script_file)
|
225
236
|
script = File.read(script_file)
|
226
|
-
script = script.chars.to_a.join("\x00").chomp
|
227
|
-
script
|
237
|
+
script = script.chars.to_a.join("\x00").chomp
|
238
|
+
if(defined?(script.encode))
|
239
|
+
script = script.encode('ASCII-8BIT')
|
240
|
+
end
|
241
|
+
script = Base64.encode64(script)
|
228
242
|
|
229
243
|
shell_id = open_shell
|
230
244
|
command_id = run_command(shell_id, "powershell -encodedCommand #{script}")
|
data/lib/winrm.rb
CHANGED
@@ -72,6 +72,12 @@ module WinRM
|
|
72
72
|
@winrm = SOAP::WinRMWebService.new
|
73
73
|
end
|
74
74
|
|
75
|
+
# Run a CMD command
|
76
|
+
# @see WinRM::SOAP::WinRMWebService#run_cmd
|
77
|
+
def cmd(command)
|
78
|
+
@winrm.run_cmd(command)
|
79
|
+
end
|
80
|
+
|
75
81
|
# Run a Powershell script
|
76
82
|
# @see WinRM::SOAP::WinRMWebService#run_powershell_script
|
77
83
|
def powershell(script_file)
|
@@ -18,7 +18,7 @@ describe "Test remote Powershell features via WinRM" do
|
|
18
18
|
it 'should run a test Powershell script' do
|
19
19
|
winrm = WinRM::WinRM.instance
|
20
20
|
output = winrm.powershell('spec/test.ps1')
|
21
|
-
output[:
|
21
|
+
output[:exitcode].should eql(0)
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winrm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Dan Wanek
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-07 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 0
|
30
32
|
version: "0"
|
@@ -38,6 +40,7 @@ dependencies:
|
|
38
40
|
requirements:
|
39
41
|
- - ">="
|
40
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
41
44
|
segments:
|
42
45
|
- 0
|
43
46
|
version: "0"
|
@@ -51,6 +54,7 @@ dependencies:
|
|
51
54
|
requirements:
|
52
55
|
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
54
58
|
segments:
|
55
59
|
- 0
|
56
60
|
version: "0"
|
@@ -64,6 +68,7 @@ dependencies:
|
|
64
68
|
requirements:
|
65
69
|
- - ">="
|
66
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
67
72
|
segments:
|
68
73
|
- 0
|
69
74
|
version: "0"
|
@@ -77,6 +82,7 @@ dependencies:
|
|
77
82
|
requirements:
|
78
83
|
- - ">="
|
79
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
80
86
|
segments:
|
81
87
|
- 0
|
82
88
|
version: "0"
|
@@ -123,6 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
129
|
requirements:
|
124
130
|
- - ">="
|
125
131
|
- !ruby/object:Gem::Version
|
132
|
+
hash: 57
|
126
133
|
segments:
|
127
134
|
- 1
|
128
135
|
- 8
|
@@ -133,6 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
140
|
requirements:
|
134
141
|
- - ">="
|
135
142
|
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
136
144
|
segments:
|
137
145
|
- 0
|
138
146
|
version: "0"
|