winrm-elevated 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2940150c1108b6135ff4712c64ad169d70fcffa2
4
- data.tar.gz: 42efa9e3662deda528e95fd9136de461a5549d6f
3
+ metadata.gz: a0420d9b98e357f1cf14dbd04f4955b7ae22fc4e
4
+ data.tar.gz: a90fd7ad69ebd4a66061d06ffa44559ed42c3729
5
5
  SHA512:
6
- metadata.gz: 1cbcd05d2a81bde6948710277eeb585a3056025be7937654e986e8e75bd778812c8e4ad293dd91cd0e344e70b4ae7874e409774f7326912248458c7a8966a364
7
- data.tar.gz: 66cf31d2b965d1ff95390e1439008e120032712cc612196c48e4d34c84d12225f0e513d0cb4c4b7d55d490974c4c7706085c422793a9659eb738be9afd1b6b47
6
+ metadata.gz: 1430d0e0c73f91c58b0235079bd94ddb2dea3a206eb2adae5154c3bdbd258e5abec7b9e86ffc4cb6492cb51188fcb297c08c96b0a613ce5293c8e910d54a724e
7
+ data.tar.gz: 0e80a6e1d4110639c9bb9529d16c782c49092c924ea70f97c78b605b9d193f0b8ba69562752eab7bdec617ad031b5979442bc7517034515b1396ca984971d448
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Runs PowerShell commands as elevated over Windows Remote Management (WinRM) via a scheduled task
2
2
  [![Gem Version](https://badge.fury.io/rb/winrm-elevated.svg)](http://badge.fury.io/rb/winrm-elevated)
3
3
 
4
+ This gem allows you to break out of the magical WinRM constraints thus allowing to reach out to network shares and even install Windows updates, .NET, SQL Server etc.
5
+
4
6
  ## Running commands elevated
5
7
  ```ruby
6
8
  require 'winrm'
@@ -12,6 +14,16 @@ result = elevated_runner.powershell_elevated('dir', 'Administrator', 'password')
12
14
  puts "Std out: #{result.output}"
13
15
  ```
14
16
 
17
+ ## How does it work?
18
+
19
+ The gem works by creating a new logon session local to the Windows box by using a scheduled task. After this point WinRM is just used to read output from the scheduled task via a log file.
20
+
21
+ 1. The command you'd like to run outside the WinRM context is encoded and placed inside the PowerShell script elevated_shell.ps1.
22
+ 2. The script is uploaded to the machine over WinRM.
23
+ 3. The script is executed over WinRM and the script does the following:
24
+ 1. Scheduled task is created which will execute your command and redirect stdout and stderr to a location known by elevated_shell.ps1.
25
+ 2. The scheduled task is executed.
26
+ 3. elevated_shell.ps1 polls the stdout and stderr log files and writes them back to WinRM. The script continues in this loop until the scheduled task is complete.
15
27
 
16
28
  ## Troubleshooting
17
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/changelog.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # WinRM-Elevated Gem Changelog
2
2
 
3
+ # 0.2.0
4
+ - [Only upload the elevated runner script once per winrm session](https://github.com/WinRb/winrm-elevated/pull/3)
5
+ - Bump WinRM (1.5) and WinRM-fs (0.3.0) gem constraints
6
+
3
7
  # 0.1.0
4
8
  - Initial Release
5
-
@@ -27,6 +27,7 @@ module WinRM
27
27
  @winrm_service = winrm_service
28
28
  @winrm_file_manager = WinRM::FS::FileManager.new(winrm_service)
29
29
  @elevated_shell_path = 'c:/windows/temp/winrm-elevated-shell.ps1'
30
+ @uploaded = nil
30
31
  end
31
32
 
32
33
  # Run a command or PowerShell script elevated without any of the
@@ -49,18 +50,24 @@ module WinRM
49
50
  private
50
51
 
51
52
  def upload_elevated_shell_wrapper_script
52
- file = Tempfile.new(['winrm-elevated-shell', 'ps1'])
53
- begin
54
- file.write(elevated_shell_script_content)
55
- file.fsync
56
- file.close
57
- @winrm_file_manager.upload(file.path, @elevated_shell_path)
58
- ensure
59
- file.close
60
- file.unlink
53
+ return if @uploaded
54
+ with_temp_file do |temp_file|
55
+ @winrm_file_manager.upload(temp_file, @elevated_shell_path)
56
+ @uploaded = true
61
57
  end
62
58
  end
63
59
 
60
+ def with_temp_file
61
+ file = Tempfile.new(['winrm-elevated-shell', 'ps1'])
62
+ file.write(elevated_shell_script_content)
63
+ file.fsync
64
+ file.close
65
+ yield file.path
66
+ ensure
67
+ file.close
68
+ file.unlink
69
+ end
70
+
64
71
  def elevated_shell_script_content
65
72
  IO.read(File.expand_path('../scripts/elevated_shell.ps1', __FILE__))
66
73
  end
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
25
25
  s.extra_rdoc_files = %w(README.md LICENSE)
26
26
 
27
27
  s.required_ruby_version = '>= 1.9.0'
28
- s.add_runtime_dependency 'winrm', '~> 1.3'
29
- s.add_runtime_dependency 'winrm-fs', '~> 0.2.2'
28
+ s.add_runtime_dependency 'winrm', '~> 1.5'
29
+ s.add_runtime_dependency 'winrm-fs', '~> 0.3.0'
30
30
  s.add_development_dependency 'rspec', '~> 3.2'
31
31
  s.add_development_dependency 'rake', '~> 10.3'
32
32
  s.add_development_dependency 'rubocop', '~> 0.28'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm-elevated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Neal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: winrm
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: winrm-fs
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.2
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.2
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.5
135
+ rubygems_version: 2.5.2
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Ruby library for running commands as elevated